I want to write a code so, that i can know in run time which task is having unhand led interrupt . so,that i can restart that task again.
I am using MQX 3.5.
Thanks,
netra
Solved! Go to Solution.
MQX has a way to figure that issue out. You can use _task_set_exception_handler to install a exception handler to capture what you want.Please refer the demo code below.
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() & 0x1F;
printf("Opps, bad thing happened.\n");
if(excpt_num < 16){
printf("The exception [%s] throw by 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)
{
#if 0
__asm (
"push {lr} \n"
"mrs r0, psp \n"
"bl expt_frm_dump \n"
"pop {pc} \n"
);
#endif
pointer expt_frm_ptr = (pointer)__get_PSP();
expt_frm_dump(expt_frm_ptr);
}
void hello_task(unsigned long para)
{
unsigned int *p_bad = (unsigned int *)0;
printf("Hello, MQX\n");
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 = 0; //This will issue a HardFault exception
_task_block();
}
BTW, unhandeld interrupt should be definely avoided.
EDIT: Use C++ code highlight in the Advanced editor. Thanks! Message was edited by: Martin Kojtal
Hello netra,
I am wondering about your intention. Could you please explain us why would you restart the task which causes an unhandled interrupt?
Regards,
0xc0170
I was having a similar issue with a task that was aborting due to "unhandeld interrupt". I put a counter into the while(1) loop and waited for the exception to occur. The counter was always stopped at 4. So I cycled through 4 times and single stepped until it crashed. I kept my eye on any changes to file handles and discovered that an essential file handle was being changed .
I then used the watchpoint feature to see when the memory location was being changed. It ended up being another task that was writing the bad data.
MQX has a way to figure that issue out. You can use _task_set_exception_handler to install a exception handler to capture what you want.Please refer the demo code below.
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() & 0x1F;
printf("Opps, bad thing happened.\n");
if(excpt_num < 16){
printf("The exception [%s] throw by 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)
{
#if 0
__asm (
"push {lr} \n"
"mrs r0, psp \n"
"bl expt_frm_dump \n"
"pop {pc} \n"
);
#endif
pointer expt_frm_ptr = (pointer)__get_PSP();
expt_frm_dump(expt_frm_ptr);
}
void hello_task(unsigned long para)
{
unsigned int *p_bad = (unsigned int *)0;
printf("Hello, MQX\n");
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 = 0; //This will issue a HardFault exception
_task_block();
}
BTW, unhandeld interrupt should be definely avoided.
EDIT: Use C++ code highlight in the Advanced editor. Thanks! Message was edited by: Martin Kojtal