Statistics
| Branch: | Tag: | Revision:

mongoose / examples / PIC32 / mqtt_client / firmware / src / system_config / mx795_CC3100_e16 / system_exceptions.c @ eaef5bd1

History | View | Annotate | Download (5.28 KB)

1
/* clang-format off */
2
/*******************************************************************************
3
  MPLAB Harmony Exceptions Source File
4

5
  File Name:
6
    system_exceptions.c
7

8
  Summary:
9
    This file contains a function which overrides the deafult _weak_ exception 
10
    handler provided by the XC32 compiler.
11

12
  Description:
13
    This file redefines the default _weak_  exception handler with a more debug
14
    friendly one. If an unexpected exception occurs the code will stop in a
15
    while(1) loop.  The debugger can be halted and two variables _excep_code and
16
    _except_addr can be examined to determine the cause and address where the
17
    exception occured.
18
 *******************************************************************************/
19

    
20
// DOM-IGNORE-BEGIN
21
/*******************************************************************************
22
Copyright (c) 2013-2015 released Microchip Technology Inc.  All rights reserved.
23

24
Microchip licenses to you the right to use, modify, copy and distribute
25
Software only when embedded on a Microchip microcontroller or digital signal
26
controller that is integrated into your product or third party product
27
(pursuant to the sublicense terms in the accompanying license agreement).
28

29
You should refer to the license agreement accompanying this Software for
30
additional information regarding your rights and obligations.
31

32
SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND,
33
EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
34
MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
35
IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER
36
CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR
37
OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
38
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR
39
CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF
40
SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
41
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
42
 *******************************************************************************/
43
// DOM-IGNORE-END
44

    
45

    
46
#include <xc.h>                 /* Defines special funciton registers, CP0 regs  */
47
#include "system_config.h"
48
#include "system_definitions.h"
49
#include "system/debug/sys_debug.h"
50

    
51

    
52
// *****************************************************************************
53
// *****************************************************************************
54
// Section: Global Data Definitions
55
// *****************************************************************************
56
// *****************************************************************************
57

    
58
/*******************************************************************************
59
  Exception Reason Data
60
  
61
  <editor-fold defaultstate="expanded" desc="Exception Reason Data">
62
  
63
  Remarks:
64
    These global static items are used instead of local variables in the 
65
    _general_exception_handler function because the stack may not be available
66
    if an exception has occured.
67
*/
68

    
69
/* Code identifying the cause of the exception (CP0 Cause register). */
70
static unsigned int _excep_code;
71

    
72
/* Address of instruction that caused the exception. */
73
static unsigned int _excep_addr;
74

    
75
/* Pointer to the string describing the cause of the exception. */
76
static char *_cause_str;
77

    
78
/* Array identifying the cause (indexed by _exception_code). */
79
static char *cause[] = 
80
{
81
    "Interrupt",
82
    "Undefined",
83
    "Undefined",
84
    "Undefined",
85
    "Load/fetch address error",
86
    "Store address error",
87
    "Instruction bus error",
88
    "Data bus error",
89
    "Syscall",
90
    "Breakpoint",
91
    "Reserved instruction",
92
    "Coprocessor unusable",
93
    "Arithmetic overflow",
94
    "Trap",
95
    "Reserved",
96
    "Reserved",
97
    "Reserved",
98
    "Reserved",
99
    "Reserved"
100
};
101

    
102
// </editor-fold>
103

    
104

    
105
// *****************************************************************************
106
// *****************************************************************************
107
// Section: Exception Handling
108
// *****************************************************************************
109
// *****************************************************************************
110

    
111
/*******************************************************************************
112
  Function:
113
    void _general_exception_handler ( void )
114

115
  Summary:
116
    Overrides the XC32 _weak_ _generic_exception_handler.
117
    
118
  Description:
119
    This function overrides the XC32 default _weak_ _generic_exception_handler.
120

121
  Remarks:
122
    Refer to the XC32 User's Guide for additional information.
123
 */
124

    
125
void _general_exception_handler ( void )
126
{
127
    /* Mask off Mask of the ExcCode Field from the Cause Register
128
    Refer to the MIPs Software User's manual */
129
    _excep_code = (_CP0_GET_CAUSE() & 0x0000007C) >> 2;
130
    _excep_addr = _CP0_GET_EPC();
131
    _cause_str  = cause[_excep_code];
132

    
133
    SYS_DEBUG_PRINT(SYS_ERROR_ERROR, "\nGeneral Exception %s (cause=%d, addr=%x).\n", 
134
                    _cause_str, _excep_code, _excep_addr);
135

    
136
    while (1)
137
    {
138
        SYS_DEBUG_BreakPoint();
139
    }
140
}
141

    
142
/*******************************************************************************
143
 End of File
144
*/