]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4_SimpleLink_CC3220SF_CCS/ti/devices/cc32xx/driverlib/systick.c
Add SimpleLink CC3220SF demo.
[freertos] / FreeRTOS / Demo / CORTEX_M4_SimpleLink_CC3220SF_CCS / ti / devices / cc32xx / driverlib / systick.c
1 /*
2  * -------------------------------------------
3  *    CC3220 SDK - v0.10.00.00 
4  * -------------------------------------------
5  *
6  *  Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/ 
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  */
37 //*****************************************************************************
38 //
39 //  systick.c
40 //
41 //  Driver for the SysTick timer in NVIC.
42 //
43 //*****************************************************************************
44
45 //*****************************************************************************
46 //
47 //! \addtogroup systick_api
48 //! @{
49 //
50 //*****************************************************************************
51
52 #include "inc/hw_ints.h"
53 #include "inc/hw_nvic.h"
54 #include "inc/hw_types.h"
55 #include "debug.h"
56 #include "interrupt.h"
57 #include "systick.h"
58
59 //*****************************************************************************
60 //
61 //! Enables the SysTick counter.
62 //!
63 //! This function starts the SysTick counter.  If an interrupt handler has been
64 //! registered, it is called when the SysTick counter rolls over.
65 //!
66 //! \note Calling this function causes the SysTick counter to (re)commence
67 //! counting from its current value.  The counter is not automatically reloaded
68 //! with the period as specified in a previous call to SysTickPeriodSet().  If
69 //! an immediate reload is required, the \b NVIC_ST_CURRENT register must be
70 //! written to force the reload.  Any write to this register clears the SysTick
71 //! counter to 0 and causes a reload with the supplied period on the next
72 //! clock.
73 //!
74 //! \return None.
75 //
76 //*****************************************************************************
77 void
78 SysTickEnable(void)
79 {
80     //
81     // Enable SysTick.
82     //
83     HWREG(NVIC_ST_CTRL) |= NVIC_ST_CTRL_CLK_SRC | NVIC_ST_CTRL_ENABLE;
84 }
85
86 //*****************************************************************************
87 //
88 //! Disables the SysTick counter.
89 //!
90 //! This function stops the SysTick counter.  If an interrupt handler has been
91 //! registered, it is not called until SysTick is restarted.
92 //!
93 //! \return None.
94 //
95 //*****************************************************************************
96 void
97 SysTickDisable(void)
98 {
99     //
100     // Disable SysTick.
101     //
102     HWREG(NVIC_ST_CTRL) &= ~(NVIC_ST_CTRL_ENABLE);
103 }
104
105 //*****************************************************************************
106 //
107 //! Registers an interrupt handler for the SysTick interrupt.
108 //!
109 //! \param pfnHandler is a pointer to the function to be called when the
110 //! SysTick interrupt occurs.
111 //!
112 //! This function registers the handler to be called when a SysTick interrupt
113 //! occurs.
114 //!
115 //! \sa IntRegister() for important information about registering interrupt
116 //! handlers.
117 //!
118 //! \return None.
119 //
120 //*****************************************************************************
121 void
122 SysTickIntRegister(void (*pfnHandler)(void))
123 {
124     //
125     // Register the interrupt handler, returning an error if an error occurs.
126     //
127     IntRegister(FAULT_SYSTICK, pfnHandler);
128
129     //
130     // Enable the SysTick interrupt.
131     //
132     HWREG(NVIC_ST_CTRL) |= NVIC_ST_CTRL_INTEN;
133 }
134
135 //*****************************************************************************
136 //
137 //! Unregisters the interrupt handler for the SysTick interrupt.
138 //!
139 //! This function unregisters the handler to be called when a SysTick interrupt
140 //! occurs.
141 //!
142 //! \sa IntRegister() for important information about registering interrupt
143 //! handlers.
144 //!
145 //! \return None.
146 //
147 //*****************************************************************************
148 void
149 SysTickIntUnregister(void)
150 {
151     //
152     // Disable the SysTick interrupt.
153     //
154     HWREG(NVIC_ST_CTRL) &= ~(NVIC_ST_CTRL_INTEN);
155
156     //
157     // Unregister the interrupt handler.
158     //
159     IntUnregister(FAULT_SYSTICK);
160 }
161
162 //*****************************************************************************
163 //
164 //! Enables the SysTick interrupt.
165 //!
166 //! This function enables the SysTick interrupt, allowing it to be
167 //! reflected to the processor.
168 //!
169 //! \note The SysTick interrupt handler is not required to clear the SysTick
170 //! interrupt source because it is cleared automatically by the NVIC when the
171 //! interrupt handler is called.
172 //!
173 //! \return None.
174 //
175 //*****************************************************************************
176 void
177 SysTickIntEnable(void)
178 {
179     //
180     // Enable the SysTick interrupt.
181     //
182     HWREG(NVIC_ST_CTRL) |= NVIC_ST_CTRL_INTEN;
183 }
184
185 //*****************************************************************************
186 //
187 //! Disables the SysTick interrupt.
188 //!
189 //! This function disables the SysTick interrupt, preventing it from being
190 //! reflected to the processor.
191 //!
192 //! \return None.
193 //
194 //*****************************************************************************
195 void
196 SysTickIntDisable(void)
197 {
198     //
199     // Disable the SysTick interrupt.
200     //
201     HWREG(NVIC_ST_CTRL) &= ~(NVIC_ST_CTRL_INTEN);
202 }
203
204 //*****************************************************************************
205 //
206 //! Sets the period of the SysTick counter.
207 //!
208 //! \param ulPeriod is the number of clock ticks in each period of the SysTick
209 //! counter and must be between 1 and 16,777,216, inclusive.
210 //!
211 //! This function sets the rate at which the SysTick counter wraps, which
212 //! equates to the number of processor clocks between interrupts.
213 //!
214 //! \note Calling this function does not cause the SysTick counter to reload
215 //! immediately.  If an immediate reload is required, the \b NVIC_ST_CURRENT
216 //! register must be written.  Any write to this register clears the SysTick
217 //! counter to 0 and causes a reload with the \e ulPeriod supplied here on
218 //! the next clock after SysTick is enabled.
219 //!
220 //! \return None.
221 //
222 //*****************************************************************************
223 void
224 SysTickPeriodSet(unsigned long ulPeriod)
225 {
226     //
227     // Check the arguments.
228     //
229     ASSERT((ulPeriod > 0) && (ulPeriod <= 16777216));
230
231     //
232     // Set the period of the SysTick counter.
233     //
234     HWREG(NVIC_ST_RELOAD) = ulPeriod - 1;
235 }
236
237 //*****************************************************************************
238 //
239 //! Gets the period of the SysTick counter.
240 //!
241 //! This function returns the rate at which the SysTick counter wraps, which
242 //! equates to the number of processor clocks between interrupts.
243 //!
244 //! \return Returns the period of the SysTick counter.
245 //
246 //*****************************************************************************
247 unsigned long
248 SysTickPeriodGet(void)
249 {
250     //
251     // Return the period of the SysTick counter.
252     //
253     return(HWREG(NVIC_ST_RELOAD) + 1);
254 }
255
256 //*****************************************************************************
257 //
258 //! Gets the current value of the SysTick counter.
259 //!
260 //! This function returns the current value of the SysTick counter, which is
261 //! a value between the period - 1 and zero, inclusive.
262 //!
263 //! \return Returns the current value of the SysTick counter.
264 //
265 //*****************************************************************************
266 unsigned long
267 SysTickValueGet(void)
268 {
269     //
270     // Return the current value of the SysTick counter.
271     //
272     return(HWREG(NVIC_ST_CURRENT));
273 }
274
275 //*****************************************************************************
276 //
277 // Close the Doxygen group.
278 //! @}
279 //
280 //*****************************************************************************