]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_LM3S811_GCC/hw_include/systick.c
Add FreeRTOS-Plus directory.
[freertos] / FreeRTOS / Demo / CORTEX_LM3S811_GCC / hw_include / systick.c
1 //*****************************************************************************\r
2 //\r
3 // systick.c - Driver for the SysTick timer in NVIC.\r
4 //\r
5 // Copyright (c) 2005,2006 Luminary Micro, Inc.  All rights reserved.\r
6 //\r
7 // Software License Agreement\r
8 //\r
9 // Luminary Micro, Inc. (LMI) is supplying this software for use solely and\r
10 // exclusively on LMI's Stellaris Family of microcontroller products.\r
11 //\r
12 // The software is owned by LMI and/or its suppliers, and is protected under\r
13 // applicable copyright laws.  All rights are reserved.  Any use in violation\r
14 // of the foregoing restrictions may subject the user to criminal sanctions\r
15 // under applicable laws, as well as to civil liability for the breach of the\r
16 // terms and conditions of this license.\r
17 //\r
18 // THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED\r
19 // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF\r
20 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.\r
21 // LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR\r
22 // CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.\r
23 //\r
24 // This is part of revision 991 of the Stellaris Driver Library.\r
25 //\r
26 //*****************************************************************************\r
27 \r
28 //*****************************************************************************\r
29 //\r
30 //! \addtogroup systick_api\r
31 //! @{\r
32 //\r
33 //*****************************************************************************\r
34 \r
35 #include "../hw_ints.h"\r
36 #include "../hw_nvic.h"\r
37 #include "../hw_types.h"\r
38 #include "debug.h"\r
39 #include "interrupt.h"\r
40 #include "systick.h"\r
41 \r
42 //*****************************************************************************\r
43 //\r
44 //! Enables the SysTick counter.\r
45 //!\r
46 //! This will start the SysTick counter.  If an interrupt handler has been\r
47 //! registered, it will be called when the SysTick counter rolls over.\r
48 //!\r
49 //! \return None.\r
50 //\r
51 //*****************************************************************************\r
52 #if defined(GROUP_enable) || defined(BUILD_ALL) || defined(DOXYGEN)\r
53 void\r
54 SysTickEnable(void)\r
55 {\r
56     //\r
57     // Enable SysTick.\r
58     //\r
59     HWREG(NVIC_ST_CTRL) |= NVIC_ST_CTRL_CLK_SRC | NVIC_ST_CTRL_ENABLE;\r
60 }\r
61 #endif\r
62 \r
63 //*****************************************************************************\r
64 //\r
65 //! Disables the SysTick counter.\r
66 //!\r
67 //! This will stop the SysTick counter.  If an interrupt handler has been\r
68 //! registered, it will no longer be called until SysTick is restarted.\r
69 //!\r
70 //! \return None.\r
71 //\r
72 //*****************************************************************************\r
73 #if defined(GROUP_disable) || defined(BUILD_ALL) || defined(DOXYGEN)\r
74 void\r
75 SysTickDisable(void)\r
76 {\r
77     //\r
78     // Disable SysTick.\r
79     //\r
80     HWREG(NVIC_ST_CTRL) &= ~(NVIC_ST_CTRL_ENABLE);\r
81 }\r
82 #endif\r
83 \r
84 //*****************************************************************************\r
85 //\r
86 //! Registers an interrupt handler for the SysTick interrupt.\r
87 //!\r
88 //! \param pfnHandler is a pointer to the function to be called when the\r
89 //! SysTick interrupt occurs.\r
90 //!\r
91 //! This sets the handler to be called when a SysTick interrupt occurs.\r
92 //!\r
93 //! \sa IntRegister() for important information about registering interrupt\r
94 //! handlers.\r
95 //!\r
96 //! \return None.\r
97 //\r
98 //*****************************************************************************\r
99 #if defined(GROUP_intregister) || defined(BUILD_ALL) || defined(DOXYGEN)\r
100 void\r
101 SysTickIntRegister(void (*pfnHandler)(void))\r
102 {\r
103     //\r
104     // Register the interrupt handler, returning an error if an error occurs.\r
105     //\r
106     IntRegister(FAULT_SYSTICK, pfnHandler);\r
107 \r
108     //\r
109     // Enable the SysTick interrupt.\r
110     //\r
111     HWREG(NVIC_ST_CTRL) |= NVIC_ST_CTRL_INTEN;\r
112 }\r
113 #endif\r
114 \r
115 //*****************************************************************************\r
116 //\r
117 //! Unregisters the interrupt handler for the SysTick interrupt.\r
118 //!\r
119 //! This function will clear the handler to be called when a SysTick interrupt\r
120 //! occurs.\r
121 //!\r
122 //! \sa IntRegister() for important information about registering interrupt\r
123 //! handlers.\r
124 //!\r
125 //! \return None.\r
126 //\r
127 //*****************************************************************************\r
128 #if defined(GROUP_intunregister) || defined(BUILD_ALL) || defined(DOXYGEN)\r
129 void\r
130 SysTickIntUnregister(void)\r
131 {\r
132     //\r
133     // Disable the SysTick interrupt.\r
134     //\r
135     HWREG(NVIC_ST_CTRL) &= ~(NVIC_ST_CTRL_INTEN);\r
136 \r
137     //\r
138     // Unregister the interrupt handler.\r
139     //\r
140     IntUnregister(FAULT_SYSTICK);\r
141 }\r
142 #endif\r
143 \r
144 //*****************************************************************************\r
145 //\r
146 //! Enables the SysTick interrupt.\r
147 //!\r
148 //! This function will enable the SysTick interrupt, allowing it to be\r
149 //! reflected to the processor.\r
150 //!\r
151 //! \return None.\r
152 //\r
153 //*****************************************************************************\r
154 #if defined(GROUP_intenable) || defined(BUILD_ALL) || defined(DOXYGEN)\r
155 void\r
156 SysTickIntEnable(void)\r
157 {\r
158     //\r
159     // Enable the SysTick interrupt.\r
160     //\r
161     HWREG(NVIC_ST_CTRL) |= NVIC_ST_CTRL_INTEN;\r
162 }\r
163 #endif\r
164 \r
165 //*****************************************************************************\r
166 //\r
167 //! Disables the SysTick interrupt.\r
168 //!\r
169 //! This function will disable the SysTick interrupt, preventing it from being\r
170 //! reflected to the processor.\r
171 //!\r
172 //! \return None.\r
173 //\r
174 //*****************************************************************************\r
175 #if defined(GROUP_intdisable) || defined(BUILD_ALL) || defined(DOXYGEN)\r
176 void\r
177 SysTickIntDisable(void)\r
178 {\r
179     //\r
180     // Disable the SysTick interrupt.\r
181     //\r
182     HWREG(NVIC_ST_CTRL) &= ~(NVIC_ST_CTRL_INTEN);\r
183 }\r
184 #endif\r
185 \r
186 //*****************************************************************************\r
187 //\r
188 //! Sets the period of the SysTick counter.\r
189 //!\r
190 //! \param ulPeriod is the number of clock ticks in each period of the SysTick\r
191 //! counter; must be between 1 and 16,777,216, inclusive.\r
192 //!\r
193 //! This function sets the rate at which the SysTick counter wraps; this\r
194 //! equates to the number of processor clocks between interrupts.\r
195 //!\r
196 //! \return None.\r
197 //\r
198 //*****************************************************************************\r
199 #if defined(GROUP_periodset) || defined(BUILD_ALL) || defined(DOXYGEN)\r
200 void\r
201 SysTickPeriodSet(unsigned long ulPeriod)\r
202 {\r
203     //\r
204     // Check the arguments.\r
205     //\r
206     ASSERT((ulPeriod > 0) && (ulPeriod <= 16777216));\r
207 \r
208     //\r
209     // Set the period of the SysTick counter.\r
210     //\r
211     HWREG(NVIC_ST_RELOAD) = ulPeriod - 1;\r
212 }\r
213 #endif\r
214 \r
215 //*****************************************************************************\r
216 //\r
217 //! Gets the period of the SysTick counter.\r
218 //!\r
219 //! This function returns the rate at which the SysTick counter wraps; this\r
220 //! equates to the number of processor clocks between interrupts.\r
221 //!\r
222 //! \return Returns the period of the SysTick counter.\r
223 //\r
224 //*****************************************************************************\r
225 #if defined(GROUP_periodget) || defined(BUILD_ALL) || defined(DOXYGEN)\r
226 unsigned long\r
227 SysTickPeriodGet(void)\r
228 {\r
229     //\r
230     // Return the period of the SysTick counter.\r
231     //\r
232     return(HWREG(NVIC_ST_RELOAD) + 1);\r
233 }\r
234 #endif\r
235 \r
236 //*****************************************************************************\r
237 //\r
238 //! Gets the current value of the SysTick counter.\r
239 //!\r
240 //! This function returns the current value of the SysTick counter; this will\r
241 //! be a value between the period - 1 and zero, inclusive.\r
242 //!\r
243 //! \return Returns the current value of the SysTick counter.\r
244 //\r
245 //*****************************************************************************\r
246 #if defined(GROUP_valueget) || defined(BUILD_ALL) || defined(DOXYGEN)\r
247 unsigned long\r
248 SysTickValueGet(void)\r
249 {\r
250     //\r
251     // Return the current value of the SysTick counter.\r
252     //\r
253     return(HWREG(NVIC_ST_CURRENT));\r
254 }\r
255 #endif\r
256 \r
257 //*****************************************************************************\r
258 //\r
259 // Close the Doxygen group.\r
260 //! @}\r
261 //\r
262 //*****************************************************************************\r