c - MPLAB -X 中 PIC32 中的通用异常处理程序,软件如何知道何时抛出此异常?

标签 c exception pic32

void _general_exception_handler (unsigned caused, unsigned status)
    {
       RCON = RCON_EXCEPTION;

       // Point of No return.
       Kernel_Reset();
    }

我的代码似乎陷入了这个陷阱,我几乎没有什么问题可以弄清楚为什么它是通过调用代码中的有效函数到达这里的,或者一直困扰我的更好的问题是处理器如何知道存在违规行为。

1) 当我查看调试器中的监 window 口时,原因 显示了地址 0xA0007EC0值 0x10800C1C 以及 状态显示地址0xA0007EC4值是0x00100003。如何从这些地址和值信息中找出异常的原因和状态? 2)处理器如何知道出现了异常故障?

Snapshots of Memory

最佳答案

这是我通常在 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/

相关文章:

c - RN42 蓝牙模块 - 从 C 代码进入命令模式

PIC32 中的 C,在 2 个 *.c 文件之间传递结构变量

java - 使用 'if' 语句检查后出现空指针异常

c - 在 C/C++ 代码中寻找 'mock' posix 函数的方法

c - 将字符串传递给C中的函数

c - GCC 在现代处理器上的比较和交换保证是什么

exception - 页面错误、页面短缺或访问冲突?

java - GUI 类中的 StackOverflow

c - MPLab PORTFbits 没有名为 RF0 的成员

c - 如何在c中正确调用另一个函数内的函数?