src/C/mpu-handler.c
stack_frame_t* MemManage_Handler(stack_frame_t * frame)
{
    task_t *current;
    current = sched_get_current();

    uint32_t mmsr = *((uint32_t *) r_CORTEX_M_SCB_MMSR);

    /* basic default when no 'current' task */
    if (!current) {
        HANDLERLOG("MPU error: No current task\n");
        dbg_flush();
        while (1) ;
    }

    /* stack errors */
    if (mmsr & SCB_CFSR_MMFSR_MLSPERR_Msk) {
        HANDLERLOG("MPU error: Corrupted Stack\n");
    }

    if (mmsr & SCB_CFSR_MMFSR_DACCVIOL_Msk) {
        HANDLERLOG("MPU error: Instruction access violation\n");
    }
    if (mmsr & SCB_CFSR_MMFSR_DACCVIOL_Msk) {
        HANDLERLOG("MPU error: Data access violation\n");
    }

    HANDLERLOG("mmsr:%x, current:%d (%s), sp:%x, pc:%x\n",
            mmsr, current->id, current->name, frame, frame->pc);

    /* On memory fault, the task is no more scheduled */
    dbg_flush();

    if (current->mode == TASK_MODE_MAINTHREAD) {
        current->state[TASK_MODE_MAINTHREAD] = TASK_STATE_FAULT;
    } else {
        current->state[TASK_MODE_ISRTHREAD] = TASK_STATE_FAULT;
    }

    request_schedule();

    return frame;
}
/*
** This is the classical Memory Fault handler. Can be used in both loader and kernel cases, but
** has to be registered manually if needed (for e.g. by mpu_init() part).
*/
This is the classical Memory Fault handler. Can be used in both loader and kernel cases, but
has to be registered manually if needed (for e.g.
This is the classical Memory Fault handler . Can be used in both loader and kernel cases but has to be registered manually if needed ( for e . g .
stack_frame_t* MemManage_Handler(stack_frame_t * frame)
{
    task_t *current;
    current = sched_get_current();
    uint32_t mmsr = *((uint32_t *) r_CORTEX_M_SCB_MMSR);
    if (!current) {
        HANDLERLOG("MPU error: No current task\n");
        dbg_flush();
        while (1) ;
    }
    if (mmsr & SCB_CFSR_MMFSR_MLSPERR_Msk) {
        HANDLERLOG("MPU error: Corrupted Stack\n");
    }
    if (mmsr & SCB_CFSR_MMFSR_DACCVIOL_Msk) {
        HANDLERLOG("MPU error: Instruction access violation\n");
    }
    if (mmsr & SCB_CFSR_MMFSR_DACCVIOL_Msk) {
        HANDLERLOG("MPU error: Data access violation\n");
    }
    HANDLERLOG("mmsr:%x, current:%d (%s), sp:%x, pc:%x\n",
            mmsr, current->id, current->name, frame, frame->pc);
    dbg_flush();
    if (current->mode == TASK_MODE_MAINTHREAD) {
        current->state[TASK_MODE_MAINTHREAD] = TASK_STATE_FAULT;
    } else {
        current->state[TASK_MODE_ISRTHREAD] = TASK_STATE_FAULT;
    }
    request_schedule();
    return frame;
}
stack_frame_t * MemManage_Handler ( stack_frame_t * frame ) { task_t * current ; current = sched_get_current ( ) ; uint32_t mmsr = * ( ( uint32_t * ) r_CORTEX_M_SCB_MMSR ) ; if ( ! current ) { HANDLERLOG ( " \n " ) ; dbg_flush ( ) ; while ( 1 ) ; } if ( mmsr & SCB_CFSR_MMFSR_MLSPERR_Msk ) { HANDLERLOG ( " \n " ) ; } if ( mmsr & SCB_CFSR_MMFSR_DACCVIOL_Msk ) { HANDLERLOG ( " \n " ) ; } if ( mmsr & SCB_CFSR_MMFSR_DACCVIOL_Msk ) { HANDLERLOG ( " \n " ) ; } HANDLERLOG ( " \n " , mmsr , current -> id , current -> name , frame , frame -> pc ) ; dbg_flush ( ) ; if ( current -> mode == TASK_MODE_MAINTHREAD ) { current -> state [ TASK_MODE_MAINTHREAD ] = TASK_STATE_FAULT ; } else { current -> state [ TASK_MODE_ISRTHREAD ] = TASK_STATE_FAULT ; } request_schedule ( ) ; return frame ; }
This is the classical Memory Fault handler.
This is the classical Memory Fault handler .
/* basic default when no 'current' task */ /* stack errors */ /* On memory fault, the task is no more scheduled */