1 //*****************************************************************************
2 //
3 // sysexc.c - Routines for the System Exception Module.
4 //
5 // Copyright (c) 2011 Texas Instruments Incorporated.  All rights reserved.
6 // Software License Agreement
7 //
8 // Texas Instruments (TI) is supplying this software for use solely and
9 // exclusively on TI's microcontroller products. The software is owned by
10 // TI and/or its suppliers, and is protected under applicable copyright
11 // laws. You may not combine this software with "viral" open-source
12 // software in order to form a larger program.
13 //
14 // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
15 // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
16 // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
18 // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
19 // DAMAGES, FOR ANY REASON WHATSOEVER.
20 //
21 // This is part of revision 8264 of the Stellaris Peripheral Driver Library.
22 //
23 //*****************************************************************************
24 
25 //*****************************************************************************
26 //
27 //! \addtogroup sysexc_api
28 //! @{
29 //
30 //*****************************************************************************
31 
32 #include "inc/hw_ints.h"
33 #include "inc/hw_sysexc.h"
34 #include "inc/hw_types.h"
35 #include "interrupt.h"
36 
37 //*****************************************************************************
38 //
39 //! Registers an interrupt handler for the system exception interrupt.
40 //!
41 //! \param pfnHandler is a pointer to the function to be called when the system
42 //! exception interrupt occurs.
43 //!
44 //! This function places the address of the system exception interrupt handler
45 //! into the interrupt vector table in SRAM.  This function also enables the
46 //! global interrupt in the interrupt controller; specific system exception
47 //! interrupts must be enabled via SysExcIntEnable().  It is the interrupt
48 //! handler's responsibility to clear the interrupt source.
49 //!
50 //! \sa IntRegister() for important information about registering interrupt
51 //! handlers.
52 //!
53 //! \return None.
54 //
55 //*****************************************************************************
56 void
SysExcIntRegister(void (* pfnHandler)(void))57 SysExcIntRegister(void (*pfnHandler)(void))
58 {
59     //
60     // Register the interrupt handler.
61     //
62     IntRegister(INT_SYSEXC, pfnHandler);
63 
64     //
65     // Enable the system exception interrupt.
66     //
67     IntEnable(INT_SYSEXC);
68 }
69 
70 //*****************************************************************************
71 //
72 //! Unregisters the system exception interrupt handler.
73 //!
74 //! This function removes the system exception interrupt handler from the
75 //! vector table in SRAM.  This function also masks off the system exception
76 //! interrupt in the interrupt controller so that the interrupt handler is no
77 //! longer called.
78 //!
79 //! \sa IntRegister() for important information about registering interrupt
80 //! handlers.
81 //!
82 //! \return None.
83 //
84 //*****************************************************************************
85 void
SysExcIntUnregister(void)86 SysExcIntUnregister(void)
87 {
88     //
89     // Disable the system exception interrupt.
90     //
91     IntDisable(INT_SYSEXC);
92 
93     //
94     // Unregister the system exception interrupt handler.
95     //
96     IntUnregister(INT_SYSEXC);
97 }
98 
99 //*****************************************************************************
100 //
101 //! Enables individual system exception interrupt sources.
102 //!
103 //! \param ulIntFlags is the bit mask of the interrupt sources to be enabled.
104 //!
105 //! This function enables the indicated system exception interrupt sources.
106 //! Only the sources that are enabled can be reflected to the processor
107 //! interrupt; disabled sources have no effect on the processor.
108 //!
109 //! The \e ulIntFlags parameter is the logical OR of any of the following:
110 //!
111 //! - \b SYSEXC_INT_FP_IXC - Floating-point inexact exception interrupt
112 //! - \b SYSEXC_INT_FP_OFC - Floating-point overflow exception interrupt
113 //! - \b SYSEXC_INT_FP_UFC - Floating-point underflow exception interrupt
114 //! - \b SYSEXC_INT_FP_IOC - Floating-point invalid operation interrupt
115 //! - \b SYSEXC_INT_FP_DZC - Floating-point divide by zero exception interrupt
116 //! - \b SYSEXC_INT_FP_IDC - Floating-point input denormal exception interrupt
117 //!
118 //! \return None.
119 //
120 //*****************************************************************************
121 void
SysExcIntEnable(unsigned long ulIntFlags)122 SysExcIntEnable(unsigned long ulIntFlags)
123 {
124     //
125     // Enable the specified interrupts.
126     //
127     HWREG(SYSEXC_IM) |= ulIntFlags;
128 }
129 
130 //*****************************************************************************
131 //
132 //! Disables individual system exception interrupt sources.
133 //!
134 //! \param ulIntFlags is the bit mask of the interrupt sources to be disabled.
135 //!
136 //! This function disables the indicated system exception interrupt sources.
137 //! Only sources that are enabled can be reflected to the processor interrupt;
138 //! disabled sources have no effect on the processor.
139 //!
140 //! The \e ulIntFlags parameter is the logical OR of any of the following:
141 //!
142 //! - \b SYSEXC_INT_FP_IXC - Floating-point inexact exception interrupt
143 //! - \b SYSEXC_INT_FP_OFC - Floating-point overflow exception interrupt
144 //! - \b SYSEXC_INT_FP_UFC - Floating-point underflow exception interrupt
145 //! - \b SYSEXC_INT_FP_IOC - Floating-point invalid operation interrupt
146 //! - \b SYSEXC_INT_FP_DZC - Floating-point divide by zero exception interrupt
147 //! - \b SYSEXC_INT_FP_IDC - Floating-point input denormal exception interrupt
148 //!
149 //! \return None.
150 //
151 //*****************************************************************************
152 void
SysExcIntDisable(unsigned long ulIntFlags)153 SysExcIntDisable(unsigned long ulIntFlags)
154 {
155     //
156     // Disable the specified interrupts.
157     //
158     HWREG(SYSEXC_IM) &= ~(ulIntFlags);
159 }
160 
161 //*****************************************************************************
162 //
163 //! Gets the current system exception interrupt status.
164 //!
165 //! \param bMasked is \b false if the raw interrupt status is required and
166 //! \b true if the masked interrupt status is required.
167 //!
168 //! This function returns the system exception interrupt status.  Either the
169 //! raw interrupt status or the status of interrupts that are allowed to
170 //! reflect to the processor can be returned.
171 //!
172 //! \return Returns the current system exception interrupt status, enumerated
173 //! as the logical OR of \b SYSEXC_INT_FP_IXC, \b SYSEXC_INT_FP_OFC,
174 //! \b SYSEXC_INT_FP_UFC, \b SYSEXC_INT_FP_IOC, \b SYSEXC_INT_FP_DZC, and
175 //! \b SYSEXC_INT_FP_IDC.
176 //
177 //*****************************************************************************
178 unsigned long
SysExcIntStatus(tBoolean bMasked)179 SysExcIntStatus(tBoolean bMasked)
180 {
181     //
182     // Return either the interrupt status or the raw interrupt status as
183     // requested.
184     //
185     if(bMasked)
186     {
187         return(HWREG(SYSEXC_MIS));
188     }
189     else
190     {
191         return(HWREG(SYSEXC_RIS));
192     }
193 }
194 
195 //*****************************************************************************
196 //
197 //! Clears system exception interrupt sources.
198 //!
199 //! \param ulIntFlags is a bit mask of the interrupt sources to be cleared.
200 //!
201 //! This function clears the specified system exception interrupt sources, so
202 //! that they no longer assert.  This function must be called in the interrupt
203 //! handler to keep the interrupt from being recognized again immediately upon
204 //! exit.
205 //!
206 //! The \e ulIntFlags parameter is the logical OR of any of the following:
207 //!
208 //! - \b SYSEXC_INT_FP_IXC - Floating-point inexact exception interrupt
209 //! - \b SYSEXC_INT_FP_OFC - Floating-point overflow exception interrupt
210 //! - \b SYSEXC_INT_FP_UFC - Floating-point underflow exception interrupt
211 //! - \b SYSEXC_INT_FP_IOC - Floating-point invalid operation interrupt
212 //! - \b SYSEXC_INT_FP_DZC - Floating-point divide by zero exception interrupt
213 //! - \b SYSEXC_INT_FP_IDC - Floating-point input denormal exception interrupt
214 //!
215 //! \note Because there is a write buffer in the Cortex-M processor, it may
216 //! take several clock cycles before the interrupt source is actually cleared.
217 //! Therefore, it is recommended that the interrupt source be cleared early in
218 //! the interrupt handler (as opposed to the very last action) to avoid
219 //! returning from the interrupt handler before the interrupt source is
220 //! actually cleared.  Failure to do so may result in the interrupt handler
221 //! being immediately reentered (because the interrupt controller still sees
222 //! the interrupt source asserted).
223 //!
224 //! \return None.
225 //
226 //*****************************************************************************
227 void
SysExcIntClear(unsigned long ulIntFlags)228 SysExcIntClear(unsigned long ulIntFlags)
229 {
230     //
231     // Clear the requested interrupt sources.
232     //
233     HWREG(SYSEXC_IC) = ulIntFlags;
234 }
235 
236 //*****************************************************************************
237 //
238 // Close the Doxygen group.
239 //! @}
240 //
241 //*****************************************************************************
242