1 //*****************************************************************************
\r
3 // systick.c - Driver for the SysTick timer in NVIC.
\r
5 // Copyright (c) 2005,2006 Luminary Micro, Inc. All rights reserved.
\r
7 // Software License Agreement
\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
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
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
24 // This is part of revision 991 of the Stellaris Driver Library.
\r
26 //*****************************************************************************
\r
28 //*****************************************************************************
\r
30 //! \addtogroup systick_api
\r
33 //*****************************************************************************
\r
35 #include "../hw_ints.h"
\r
36 #include "../hw_nvic.h"
\r
37 #include "../hw_types.h"
\r
39 #include "interrupt.h"
\r
40 #include "systick.h"
\r
42 //*****************************************************************************
\r
44 //! Enables the SysTick counter.
\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
51 //*****************************************************************************
\r
52 #if defined(GROUP_enable) || defined(BUILD_ALL) || defined(DOXYGEN)
\r
59 HWREG(NVIC_ST_CTRL) |= NVIC_ST_CTRL_CLK_SRC | NVIC_ST_CTRL_ENABLE;
\r
63 //*****************************************************************************
\r
65 //! Disables the SysTick counter.
\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
72 //*****************************************************************************
\r
73 #if defined(GROUP_disable) || defined(BUILD_ALL) || defined(DOXYGEN)
\r
75 SysTickDisable(void)
\r
80 HWREG(NVIC_ST_CTRL) &= ~(NVIC_ST_CTRL_ENABLE);
\r
84 //*****************************************************************************
\r
86 //! Registers an interrupt handler for the SysTick interrupt.
\r
88 //! \param pfnHandler is a pointer to the function to be called when the
\r
89 //! SysTick interrupt occurs.
\r
91 //! This sets the handler to be called when a SysTick interrupt occurs.
\r
93 //! \sa IntRegister() for important information about registering interrupt
\r
98 //*****************************************************************************
\r
99 #if defined(GROUP_intregister) || defined(BUILD_ALL) || defined(DOXYGEN)
\r
101 SysTickIntRegister(void (*pfnHandler)(void))
\r
104 // Register the interrupt handler, returning an error if an error occurs.
\r
106 IntRegister(FAULT_SYSTICK, pfnHandler);
\r
109 // Enable the SysTick interrupt.
\r
111 HWREG(NVIC_ST_CTRL) |= NVIC_ST_CTRL_INTEN;
\r
115 //*****************************************************************************
\r
117 //! Unregisters the interrupt handler for the SysTick interrupt.
\r
119 //! This function will clear the handler to be called when a SysTick interrupt
\r
122 //! \sa IntRegister() for important information about registering interrupt
\r
127 //*****************************************************************************
\r
128 #if defined(GROUP_intunregister) || defined(BUILD_ALL) || defined(DOXYGEN)
\r
130 SysTickIntUnregister(void)
\r
133 // Disable the SysTick interrupt.
\r
135 HWREG(NVIC_ST_CTRL) &= ~(NVIC_ST_CTRL_INTEN);
\r
138 // Unregister the interrupt handler.
\r
140 IntUnregister(FAULT_SYSTICK);
\r
144 //*****************************************************************************
\r
146 //! Enables the SysTick interrupt.
\r
148 //! This function will enable the SysTick interrupt, allowing it to be
\r
149 //! reflected to the processor.
\r
153 //*****************************************************************************
\r
154 #if defined(GROUP_intenable) || defined(BUILD_ALL) || defined(DOXYGEN)
\r
156 SysTickIntEnable(void)
\r
159 // Enable the SysTick interrupt.
\r
161 HWREG(NVIC_ST_CTRL) |= NVIC_ST_CTRL_INTEN;
\r
165 //*****************************************************************************
\r
167 //! Disables the SysTick interrupt.
\r
169 //! This function will disable the SysTick interrupt, preventing it from being
\r
170 //! reflected to the processor.
\r
174 //*****************************************************************************
\r
175 #if defined(GROUP_intdisable) || defined(BUILD_ALL) || defined(DOXYGEN)
\r
177 SysTickIntDisable(void)
\r
180 // Disable the SysTick interrupt.
\r
182 HWREG(NVIC_ST_CTRL) &= ~(NVIC_ST_CTRL_INTEN);
\r
186 //*****************************************************************************
\r
188 //! Sets the period of the SysTick counter.
\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
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
198 //*****************************************************************************
\r
199 #if defined(GROUP_periodset) || defined(BUILD_ALL) || defined(DOXYGEN)
\r
201 SysTickPeriodSet(unsigned long ulPeriod)
\r
204 // Check the arguments.
\r
206 ASSERT((ulPeriod > 0) && (ulPeriod <= 16777216));
\r
209 // Set the period of the SysTick counter.
\r
211 HWREG(NVIC_ST_RELOAD) = ulPeriod - 1;
\r
215 //*****************************************************************************
\r
217 //! Gets the period of the SysTick counter.
\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
222 //! \return Returns the period of the SysTick counter.
\r
224 //*****************************************************************************
\r
225 #if defined(GROUP_periodget) || defined(BUILD_ALL) || defined(DOXYGEN)
\r
227 SysTickPeriodGet(void)
\r
230 // Return the period of the SysTick counter.
\r
232 return(HWREG(NVIC_ST_RELOAD) + 1);
\r
236 //*****************************************************************************
\r
238 //! Gets the current value of the SysTick counter.
\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
243 //! \return Returns the current value of the SysTick counter.
\r
245 //*****************************************************************************
\r
246 #if defined(GROUP_valueget) || defined(BUILD_ALL) || defined(DOXYGEN)
\r
248 SysTickValueGet(void)
\r
251 // Return the current value of the SysTick counter.
\r
253 return(HWREG(NVIC_ST_CURRENT));
\r
257 //*****************************************************************************
\r
259 // Close the Doxygen group.
\r
262 //*****************************************************************************
\r