2 * -------------------------------------------
3 * CC3220 SDK - v0.10.00.00
4 * -------------------------------------------
6 * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
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
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.
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.
37 //*****************************************************************************
41 // Driver for the SysTick timer in NVIC.
43 //*****************************************************************************
45 //*****************************************************************************
47 //! \addtogroup systick_api
50 //*****************************************************************************
52 #include "inc/hw_ints.h"
53 #include "inc/hw_nvic.h"
54 #include "inc/hw_types.h"
56 #include "interrupt.h"
59 //*****************************************************************************
61 //! Enables the SysTick counter.
63 //! This function starts the SysTick counter. If an interrupt handler has been
64 //! registered, it is called when the SysTick counter rolls over.
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
76 //*****************************************************************************
83 HWREG(NVIC_ST_CTRL) |= NVIC_ST_CTRL_CLK_SRC | NVIC_ST_CTRL_ENABLE;
86 //*****************************************************************************
88 //! Disables the SysTick counter.
90 //! This function stops the SysTick counter. If an interrupt handler has been
91 //! registered, it is not called until SysTick is restarted.
95 //*****************************************************************************
102 HWREG(NVIC_ST_CTRL) &= ~(NVIC_ST_CTRL_ENABLE);
105 //*****************************************************************************
107 //! Registers an interrupt handler for the SysTick interrupt.
109 //! \param pfnHandler is a pointer to the function to be called when the
110 //! SysTick interrupt occurs.
112 //! This function registers the handler to be called when a SysTick interrupt
115 //! \sa IntRegister() for important information about registering interrupt
120 //*****************************************************************************
122 SysTickIntRegister(void (*pfnHandler)(void))
125 // Register the interrupt handler, returning an error if an error occurs.
127 IntRegister(FAULT_SYSTICK, pfnHandler);
130 // Enable the SysTick interrupt.
132 HWREG(NVIC_ST_CTRL) |= NVIC_ST_CTRL_INTEN;
135 //*****************************************************************************
137 //! Unregisters the interrupt handler for the SysTick interrupt.
139 //! This function unregisters the handler to be called when a SysTick interrupt
142 //! \sa IntRegister() for important information about registering interrupt
147 //*****************************************************************************
149 SysTickIntUnregister(void)
152 // Disable the SysTick interrupt.
154 HWREG(NVIC_ST_CTRL) &= ~(NVIC_ST_CTRL_INTEN);
157 // Unregister the interrupt handler.
159 IntUnregister(FAULT_SYSTICK);
162 //*****************************************************************************
164 //! Enables the SysTick interrupt.
166 //! This function enables the SysTick interrupt, allowing it to be
167 //! reflected to the processor.
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.
175 //*****************************************************************************
177 SysTickIntEnable(void)
180 // Enable the SysTick interrupt.
182 HWREG(NVIC_ST_CTRL) |= NVIC_ST_CTRL_INTEN;
185 //*****************************************************************************
187 //! Disables the SysTick interrupt.
189 //! This function disables the SysTick interrupt, preventing it from being
190 //! reflected to the processor.
194 //*****************************************************************************
196 SysTickIntDisable(void)
199 // Disable the SysTick interrupt.
201 HWREG(NVIC_ST_CTRL) &= ~(NVIC_ST_CTRL_INTEN);
204 //*****************************************************************************
206 //! Sets the period of the SysTick counter.
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.
211 //! This function sets the rate at which the SysTick counter wraps, which
212 //! equates to the number of processor clocks between interrupts.
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.
222 //*****************************************************************************
224 SysTickPeriodSet(unsigned long ulPeriod)
227 // Check the arguments.
229 ASSERT((ulPeriod > 0) && (ulPeriod <= 16777216));
232 // Set the period of the SysTick counter.
234 HWREG(NVIC_ST_RELOAD) = ulPeriod - 1;
237 //*****************************************************************************
239 //! Gets the period of the SysTick counter.
241 //! This function returns the rate at which the SysTick counter wraps, which
242 //! equates to the number of processor clocks between interrupts.
244 //! \return Returns the period of the SysTick counter.
246 //*****************************************************************************
248 SysTickPeriodGet(void)
251 // Return the period of the SysTick counter.
253 return(HWREG(NVIC_ST_RELOAD) + 1);
256 //*****************************************************************************
258 //! Gets the current value of the SysTick counter.
260 //! This function returns the current value of the SysTick counter, which is
261 //! a value between the period - 1 and zero, inclusive.
263 //! \return Returns the current value of the SysTick counter.
265 //*****************************************************************************
267 SysTickValueGet(void)
270 // Return the current value of the SysTick counter.
272 return(HWREG(NVIC_ST_CURRENT));
275 //*****************************************************************************
277 // Close the Doxygen group.
280 //*****************************************************************************