2017-07-25 69 views
0
void _general_exception_handler (unsigned caused, unsigned status) 
    { 
     RCON = RCON_EXCEPTION; 

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

我的代码似乎陷入了这个陷阱,我有几个问题想弄清楚为什么它从调用我的代码中的有效函数或更好的问题,继续困扰着我是处理器如何知道已有违规。MPLAB -X中PIC32的一般异常处理程序,软件如何知道何时抛出该错误?

1)当我看到在调试器监视窗口中,cause显示我Address 0xA0007EC0value 0x10800C1Cstatus表明我address 0xA0007EC4value is 0x00100003。我怎么能从这些地址和价值信息中找出异常的原因和状态? 2)处理器如何知道发生异常故障?

Snapshots of Memory

+3

软件不知道。硬件知道。 –

+0

可以将初始化为NULL的指针'static Log_t * pLog = NULL;'引起异常错误,因为它的地址为NULL。例如,如果正在使用'pLog'来从之前读取数据,那么它将被分配一个VALID ADDRESS。由于NULL意味着内存的开始,如果你试图访问禁止部分,它会抛出异常错误? – newb7777

+1

是的。基本上它是硬件本身检测无效条件,比如访问保留的内存位置。您可以查看MCU的存储器映射图,以了解这些保留段的位置。处理器知道调用该异常处理程序,因为当硬件检测到异常时,异常会“向量化”到特定地址。实际上,它意味着如果出现异常,请在此指定地址执行代码,编译器/链接器负责其余部分。更多信息:http://microchipdeveloper.com/faq:82 – mindcruzer

回答

0

这里是处理我通常在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 
0

我有这样的竟然是在微芯片的代码中的错误问题:

sprintf(foo_str, "%f", NAN) 

会(并将)抛出一个总线错误异常......(错误在他们的“_fconvert”函数中)调试/识别我修改了我的异常处理程序来打印出来(产品已经有一个ASCII UART连接到它的主机)什么是例外,违规地址是什么,然后它会自行重置。复位部分很难找到,它位于PIC32MX的许多Microchip文档之一中。这取代了和谐(1.10)生成的“_general_exception_handler()”,不知道这是否与和谐2.x的兼容

void _general_exception_handler (void) 
{ 
    char fail_str[96]; 
    /* Mask off Mask of the ExcCode Field from the Cause Register 
    Refer to the MIPs Software User's manual */ 
    _excep_code = (_CP0_GET_CAUSE() & 0x0000007C) >> 2; 
    _excep_addr = _CP0_GET_EPC(); 
    _cause_str = cause[_excep_code]; 
    sprintf(fail_str, "ERROR,%s,cause=%d,addr=%x,", 
        _cause_str, _excep_code, _excep_addr); 
    //"send_my_string" copies the string to the ring buffer 
    send_my_string(fail_str); 
    //"tx_chars_from_ring_buffer" returns # of chars left in the ring buffer 
    while(tx_chars_from_ring_buffer()); 
    //queue up another set of chars equal to the length of the UART FIFO 
    sprintf(fail_str, "\r\r\r\r\r\r\r\r\r\r"); 
    send_my_string(fail_str); 
    while(tx_chars_from_ring_buffer()); 
#if (__DEBUG) 
    while (1) 
    { 
     SYS_DEBUG_BreakPoint(); 
    } 
#endif 
/* The following code illustrates a software Reset */ 
// assume interrupts are disabled 
// assume the DMA controller is suspended 
// assume the device is locked 
/* perform a system unlock sequence */ 
// starting critical sequence 
SYSKEY = 0x00000000; //write invalid key to force lock 
SYSKEY = 0xAA996655; //write key1 to SYSKEY 
SYSKEY = 0x556699AA; //write key2 to SYSKEY 
// OSCCON is now unlocked 
/* set SWRST bit to arm reset */ 
RSWRSTSET = 1; 
/* read RSWRST register to trigger reset */ 
_excep_code = RSWRST; 
/* prevent any unwanted code execution until reset occurs*/ 
while(1); 
} 

我没有与它玩了一下,以确保该消息得到了直通输出FIFO在复位被调用之前...

相关问题