1 //*****************************************************************************
3 // systick.c - Driver for the SysTick timer in NVIC.
5 // Copyright (c) 2005,2006 Luminary Micro, Inc. All rights reserved.
7 // Software License Agreement
9 // Luminary Micro, Inc. (LMI) is supplying this software for use solely and
10 // exclusively on LMI's Stellaris Family of microcontroller products.
12 // The software is owned by LMI and/or its suppliers, and is protected under
13 // applicable copyright laws. All rights are reserved. Any use in violation
14 // of the foregoing restrictions may subject the user to criminal sanctions
15 // under applicable laws, as well as to civil liability for the breach of the
16 // terms and conditions of this license.
18 // THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
19 // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
20 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
21 // LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
22 // CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
24 // This is part of revision 991 of the Stellaris Driver Library.
26 //*****************************************************************************
28 //*****************************************************************************
30 //! \addtogroup systick_api
33 //*****************************************************************************
35 #include "../hw_ints.h"
36 #include "../hw_nvic.h"
37 #include "../hw_types.h"
39 #include "interrupt.h"
42 //*****************************************************************************
44 //! Enables the SysTick counter.
46 //! This will start the SysTick counter. If an interrupt handler has been
47 //! registered, it will be called when the SysTick counter rolls over.
51 //*****************************************************************************
52 #if defined(GROUP_enable) || defined(BUILD_ALL) || defined(DOXYGEN)
59 HWREG(NVIC_ST_CTRL) |= NVIC_ST_CTRL_CLK_SRC | NVIC_ST_CTRL_ENABLE;
63 //*****************************************************************************
65 //! Disables the SysTick counter.
67 //! This will stop the SysTick counter. If an interrupt handler has been
68 //! registered, it will no longer be called until SysTick is restarted.
72 //*****************************************************************************
73 #if defined(GROUP_disable) || defined(BUILD_ALL) || defined(DOXYGEN)
80 HWREG(NVIC_ST_CTRL) &= ~(NVIC_ST_CTRL_ENABLE);
84 //*****************************************************************************
86 //! Registers an interrupt handler for the SysTick interrupt.
88 //! \param pfnHandler is a pointer to the function to be called when the
89 //! SysTick interrupt occurs.
91 //! This sets the handler to be called when a SysTick interrupt occurs.
93 //! \sa IntRegister() for important information about registering interrupt
98 //*****************************************************************************
99 #if defined(GROUP_intregister) || defined(BUILD_ALL) || defined(DOXYGEN)
101 SysTickIntRegister(void (*pfnHandler)(void))
104 // Register the interrupt handler, returning an error if an error occurs.
106 IntRegister(FAULT_SYSTICK, pfnHandler);
109 // Enable the SysTick interrupt.
111 HWREG(NVIC_ST_CTRL) |= NVIC_ST_CTRL_INTEN;
115 //*****************************************************************************
117 //! Unregisters the interrupt handler for the SysTick interrupt.
119 //! This function will clear the handler to be called when a SysTick interrupt
122 //! \sa IntRegister() for important information about registering interrupt
127 //*****************************************************************************
128 #if defined(GROUP_intunregister) || defined(BUILD_ALL) || defined(DOXYGEN)
130 SysTickIntUnregister(void)
133 // Disable the SysTick interrupt.
135 HWREG(NVIC_ST_CTRL) &= ~(NVIC_ST_CTRL_INTEN);
138 // Unregister the interrupt handler.
140 IntUnregister(FAULT_SYSTICK);
144 //*****************************************************************************
146 //! Enables the SysTick interrupt.
148 //! This function will enable the SysTick interrupt, allowing it to be
149 //! reflected to the processor.
153 //*****************************************************************************
154 #if defined(GROUP_intenable) || defined(BUILD_ALL) || defined(DOXYGEN)
156 SysTickIntEnable(void)
159 // Enable the SysTick interrupt.
161 HWREG(NVIC_ST_CTRL) |= NVIC_ST_CTRL_INTEN;
165 //*****************************************************************************
167 //! Disables the SysTick interrupt.
169 //! This function will disable the SysTick interrupt, preventing it from being
170 //! reflected to the processor.
174 //*****************************************************************************
175 #if defined(GROUP_intdisable) || defined(BUILD_ALL) || defined(DOXYGEN)
177 SysTickIntDisable(void)
180 // Disable the SysTick interrupt.
182 HWREG(NVIC_ST_CTRL) &= ~(NVIC_ST_CTRL_INTEN);
186 //*****************************************************************************
188 //! Sets the period of the SysTick counter.
190 //! \param ulPeriod is the number of clock ticks in each period of the SysTick
191 //! counter; must be between 1 and 16,777,216, inclusive.
193 //! This function sets the rate at which the SysTick counter wraps; this
194 //! equates to the number of processor clocks between interrupts.
198 //*****************************************************************************
199 #if defined(GROUP_periodset) || defined(BUILD_ALL) || defined(DOXYGEN)
201 SysTickPeriodSet(unsigned long ulPeriod)
204 // Check the arguments.
206 ASSERT((ulPeriod > 0) && (ulPeriod <= 16777216));
209 // Set the period of the SysTick counter.
211 HWREG(NVIC_ST_RELOAD) = ulPeriod - 1;
215 //*****************************************************************************
217 //! Gets the period of the SysTick counter.
219 //! This function returns the rate at which the SysTick counter wraps; this
220 //! equates to the number of processor clocks between interrupts.
222 //! \return Returns the period of the SysTick counter.
224 //*****************************************************************************
225 #if defined(GROUP_periodget) || defined(BUILD_ALL) || defined(DOXYGEN)
227 SysTickPeriodGet(void)
230 // Return the period of the SysTick counter.
232 return(HWREG(NVIC_ST_RELOAD) + 1);
236 //*****************************************************************************
238 //! Gets the current value of the SysTick counter.
240 //! This function returns the current value of the SysTick counter; this will
241 //! be a value between the period - 1 and zero, inclusive.
243 //! \return Returns the current value of the SysTick counter.
245 //*****************************************************************************
246 #if defined(GROUP_valueget) || defined(BUILD_ALL) || defined(DOXYGEN)
248 SysTickValueGet(void)
251 // Return the current value of the SysTick counter.
253 return(HWREG(NVIC_ST_CURRENT));
257 //*****************************************************************************
259 // Close the Doxygen group.
262 //*****************************************************************************