void _general_exception_handler (unsigned caused, unsigned status)
{
RCON = RCON_EXCEPTION;
// Point of No return.
Kernel_Reset();
}
我的代码似乎陷入了这个陷阱,我几乎没有什么问题可以弄清楚为什么它是通过调用代码中的有效函数到达这里的,或者一直困扰我的更好的问题是处理器如何知道存在违规行为。
1) 当我查看调试器中的监 window 口时,原因
显示了地址 0xA0007EC0
和值 0x10800C1C
以及 状态
显示地址0xA0007EC4
和值是0x00100003
。如何从这些地址和值信息中找出异常的原因和状态?
2)处理器如何知道出现了异常故障?
最佳答案
这是我通常在 PIC32 项目中使用的处理程序:
// Exception handler:
static enum {
EXCEP_IRQ = 0, // interrupt
EXCEP_AdEL = 4, // address error exception (load or ifetch)
EXCEP_AdES, // address error exception (store)
EXCEP_IBE, // bus error (ifetch)
EXCEP_DBE, // bus error (load/store)
EXCEP_Sys, // syscall
EXCEP_Bp, // breakpoint
EXCEP_RI, // reserved instruction
EXCEP_CpU, // coprocessor unusable
EXCEP_Overflow, // arithmetic overflow
EXCEP_Trap, // trap (possible divide by zero)
EXCEP_IS1 = 16, // implementation specfic 1
EXCEP_CEU, // CorExtend Unuseable
EXCEP_C2E // coprocessor 2
} _excep_code;
static unsigned int _epc_code;
static unsigned int _excep_addr;
// this function overrides the normal _weak_ generic handler
void _general_exception_handler(void)
{
asm volatile("mfc0 %0,$13" : "=r" (_excep_code));
asm volatile("mfc0 %0,$14" : "=r" (_excep_addr));
_excep_code = (_excep_code & 0x0000007C) >> 2;
while (1) {
// Examine _excep_code to identify the type of exception
// Examine _excep_addr to find the address that caused the
exception
Nop();
Nop();
Nop();
}
}// End of exception handler
关于c - MPLAB -X 中 PIC32 中的通用异常处理程序,软件如何知道何时抛出此异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45299750/