MPLAB -X中PIC32中的常规异常处理程序,软件知道何时抛出? [英] General Exception Handler in PIC32 in MPLAB -X , How does software know when to throw this?

查看:561
本文介绍了MPLAB -X中PIC32中的常规异常处理程序,软件知道何时抛出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我的代码似乎正在陷入陷阱,我几乎没有问题为什么它从我的代码中调用有效的函数到这里,或者更好的问题不断困扰我,处理器如何知道有违反。

My code seems to be getting in this trap and I have few questions to figure out why it get here from calling valid functions in my code or the better question that keeps bothering me is how does the processor know there has been a violation.

1)当我在调试器中观看窗口时,导致显示我地址0xA0007EC0 值0x10800C1C 状态显示我地址0xA0007EC4 值为0x00100003 。如何从这些地址和价值信息中找出异常的原因和状态?
2)处理器如何知道有异常故障?

1) When I look in the watch window in the debugger, the cause shows me Address 0xA0007EC0 and the value 0x10800C1C and the status shows me address 0xA0007EC4 and value is 0x00100003. How can I, From these Address and value information figure out the cause and status of the exception? 2) How does the processor know that there has been an exception fault?

推荐答案

我有一个问题,原来是微芯片代码中的错误:

I had an issue that turned out to be a bug in microchip's code:

sprintf(foo_str, "%f", NAN)

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

would (and will) throw a bus error exception... (bug in their "_fconvert" function) To debug/identify that I modified my exception handler to print out (product was already had an ASCII UART connection to its host) what the exception was, what the violating address was and then it will reset itself. The reset portion was hard to find, it is in one of the many Microchip docs for the PIC32MX. This replaces the Harmony (1.10) generated "_general_exception_handler()", not sure if it's compatible with Harmony 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被调用...

I did have to play with it a bit to ensure that the message got thru the output FIFO before the reset was invoked...

这篇关于MPLAB -X中PIC32中的常规异常处理程序,软件知道何时抛出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆