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