Trackdown the exceptions in MQX

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Trackdown the exceptions in MQX

Trackdown the exceptions in MQX

When working on Cortex-M4 platform, an exception which has not been expected (an interrupt without ISR, an access to an illegal address, etc).

The code below shows how to implement it.

static void expt_frm_dump(pointer ext_frm_ptr)

{

  static char *expt_name[] = {

    "None",

    "Reset",

    "NMI",

    "HardFault",

    "MemManage",

    "BusFault",

    "UsageFault",

    "Rsvd",

    "Rsvd",

    "Rsvd",

    "SVCall",

    "Debug Monitor",

    "Rsvd",

    "PendSV",

    "SysTick"

  };

  uint_32 excpt_num = __get_PSR() & 0x1FF;

  printf("Opps, bad thing happened.\n");

  if(excpt_num < 16){

    printf("The exception [%s] invoked in TASK 0x%x\n",

         expt_name[excpt_num] , _task_get_id());

    printf("Dump the exception frame as :\n");

    printf("R0:\t0x%08x\n", *((uint_32 *)ext_frm_ptr));

    printf("R1:\t0x%08x\n", *((uint_32 *)ext_frm_ptr + 1));

    printf("R2:\t0x%08x\n", *((uint_32 *)ext_frm_ptr + 2));

    printf("R3:\t0x%08x\n", *((uint_32 *)ext_frm_ptr + 3));

    printf("R12:\t0x%08x\n", *((uint_32 *)ext_frm_ptr + 4));

    printf("LR:\t0x%08x\n", *((uint_32 *)ext_frm_ptr + 5));

    printf("PC:\t0x%08x\n", *((uint_32 *)ext_frm_ptr + 6));

    printf("PSR:\t0x%08x\n", *((uint_32 *)ext_frm_ptr + 7));

  }else{

    printf("The external interrupt %d occured while no handler to serve it.\n");

  }

}

void  task_exception_handler(_mqx_uint para, pointer stack_ptr)

{

    pointer expt_frm_ptr = (pointer)__get_PSP();

    expt_frm_dump(expt_frm_ptr);

}

void test_task(unsigned long para)

{

  unsigned int *p_bad = (unsigned int *)0;

  printf("Install the _int_exception_isr to replace the _int_default_isr\n");

  _int_install_exception_isr();

  /* Set the exception handler of the task */

  _task_set_exception_handler(_task_get_id(), task_exception_handler);

  *p_bad = 0;     // an access to address 0

   _task_block();

}

No ratings
Version history
Last update:
‎09-10-2020 02:53 AM
Updated by: