123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- //###########################################################################
- //
- // FILE: systick.c
- //
- // TITLE: Stellaris style wrapper driver for C28x CPU Timer 0.
- //
- //###########################################################################
- // $TI Release: F2837xD Support Library v3.05.00.00 $
- // $Release Date: Tue Jun 26 03:15:23 CDT 2018 $
- // $Copyright:
- // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/
- //
- // Redistribution and use in source and binary forms, with or without
- // modification, are permitted provided that the following conditions
- // are met:
- //
- // Redistributions of source code must retain the above copyright
- // notice, this list of conditions and the following disclaimer.
- //
- // Redistributions in binary form must reproduce the above copyright
- // notice, this list of conditions and the following disclaimer in the
- // documentation and/or other materials provided with the
- // distribution.
- //
- // Neither the name of Texas Instruments Incorporated nor the names of
- // its contributors may be used to endorse or promote products derived
- // from this software without specific prior written permission.
- //
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- // $
- //###########################################################################
- //*****************************************************************************
- //
- //! \addtogroup systick_api
- //! @{
- //
- //*****************************************************************************
- #include "F28x_Project.h"
- #include "inc/hw_ints.h"
- #include "inc/hw_types.h"
- #include "driverlib/debug.h"
- #include "driverlib/interrupt.h"
- #include "driverlib/systick.h"
- //*****************************************************************************
- //
- //! Initializes the Timer0 Module to act as a system tick
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- SysTickInit(void)
- {
- // CPU Timer 0
- // Initialize timer period to maximum:
- CpuTimer0Regs.PRD.all = 0xFFFFFFFF;
- // Initialize pre-scale counter to divide by 1 (SYSCLKOUT):
- CpuTimer0Regs.TPR.all = 0;
- CpuTimer0Regs.TPRH.all = 0;
- // Make sure timer is stopped:
- CpuTimer0Regs.TCR.bit.TSS = 1;
- // Reload all counter register with period value:
- CpuTimer0Regs.TCR.bit.TRB = 1;
- }
- //*****************************************************************************
- //
- //! Enables the SysTick counter.
- //!
- //! This will start the SysTick counter. If an interrupt handler has been
- //! registered, it will be called when the SysTick counter rolls over.
- //!
- //! \note Calling this function will cause the SysTick counter to (re)commence
- //! counting from its current value. The counter is not automatically reloaded
- //! with the period as specified in a previous call to SysTickPeriodSet(). If
- //! an immediate reload is required, the \b NVIC_ST_CURRENT register must be
- //! written to force this. Any write to this register clears the SysTick
- //! counter to 0 and will cause a reload with the supplied period on the next
- //! clock.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- SysTickEnable(void)
- {
- //
- // Enable SysTick.
- //
- CpuTimer0Regs.TCR.bit.TRB = 1;
- CpuTimer0Regs.TCR.bit.TSS = 0;
- }
- //*****************************************************************************
- //
- //! Disables the SysTick counter.
- //!
- //! This will stop the SysTick counter. If an interrupt handler has been
- //! registered, it will no longer be called until SysTick is restarted.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- SysTickDisable(void)
- {
- //
- // Disable SysTick.
- //
- StopCpuTimer0();
- }
- //*****************************************************************************
- //
- //! Registers an interrupt handler for the SysTick interrupt.
- //!
- //! \param pfnHandler is a pointer to the function to be called when the
- //! SysTick interrupt occurs.
- //!
- //! This sets the handler to be called when a SysTick interrupt occurs.
- //!
- //! \sa IntRegister() for important information about registering interrupt
- //! handlers.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- SysTickIntRegister(void (*pfnHandler)(void))
- {
- //
- // Register the interrupt handler, returning an error if an error occurs.
- //
- IntRegister(INT_TINT0, pfnHandler);
- //
- // Enable the SysTick interrupt.
- //
- IntEnable(INT_TINT0);
- }
- //*****************************************************************************
- //
- //! Unregisters the interrupt handler for the SysTick interrupt.
- //!
- //! This function will clear the handler to be called when a SysTick interrupt
- //! occurs.
- //!
- //! \sa IntRegister() for important information about registering interrupt
- //! handlers.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- SysTickIntUnregister(void)
- {
- //
- // Disable the SysTick interrupt.
- //
- IntDisable(INT_TINT0);
- //
- // Unregister the interrupt handler.
- //
- IntUnregister(INT_TINT0);
- }
- //*****************************************************************************
- //
- //! Enables the SysTick interrupt.
- //!
- //! This function will enable the SysTick interrupt, allowing it to be
- //! reflected to the processor.
- //!
- //! \note The SysTick interrupt handler does not need to clear the SysTick
- //! interrupt source as this is done automatically by NVIC when the interrupt
- //! handler is called.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- SysTickIntEnable(void)
- {
- //
- // Enable the SysTick interrupt.
- //
- CpuTimer0Regs.TCR.bit.TIE = 1;
- IntEnable(INT_TINT0);
- }
- //*****************************************************************************
- //
- //! Disables the SysTick interrupt.
- //!
- //! This function will disable the SysTick interrupt, preventing it from being
- //! reflected to the processor.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- SysTickIntDisable(void)
- {
- //
- // Disable the SysTick interrupt.
- //
- CpuTimer0Regs.TCR.bit.TIE = 0;
- IntDisable(INT_TINT0);
- }
- //*****************************************************************************
- //
- //! Sets the period of the SysTick counter.
- //!
- //! \param ui32Period is the number of clock ticks in each period of the SysTick
- //! counter; must be between 1 and 16,777,216, inclusive.
- //!
- //! This function sets the rate at which the SysTick counter wraps; this
- //! equates to the number of processor clocks between interrupts.
- //!
- //! \note Calling this function does not cause the SysTick counter to reload
- //! immediately. If an immediate reload is required, the \b NVIC_ST_CURRENT
- //! register must be written. Any write to this register clears the SysTick
- //! counter to 0 and will cause a reload with the \e ui32Period supplied here on
- //! the next clock after the SysTick is enabled.
- //!
- //! \return None.
- //
- //*****************************************************************************
- void
- SysTickPeriodSet(uint32_t ui32Period)
- {
- //
- // Check the arguments.
- //
- ASSERT((ui32Period > 0) && (ui32Period <= 16777216));
- //
- // Set the period of the SysTick counter.
- //
- CpuTimer0Regs.PRD.all = ui32Period;
- }
- //*****************************************************************************
- //
- //! Gets the period of the SysTick counter.
- //!
- //! This function returns the rate at which the SysTick counter wraps; this
- //! equates to the number of processor clocks between interrupts.
- //!
- //! \return Returns the period of the SysTick counter.
- //
- //*****************************************************************************
- uint32_t
- SysTickPeriodGet(void)
- {
- //
- // Return the period of the SysTick counter.
- //
- return(CpuTimer0Regs.PRD.all);
- }
- //*****************************************************************************
- //
- //! Gets the current value of the SysTick counter.
- //!
- //! This function returns the current value of the SysTick counter; this will
- //! be a value between the period - 1 and zero, inclusive.
- //!
- //! \return Returns the current value of the SysTick counter.
- //
- //*****************************************************************************
- uint32_t
- SysTickValueGet(void)
- {
- //
- // Return the current value of the SysTick counter.
- //
- return(CpuTimer0Regs.TIM.all);
- }
- //*****************************************************************************
- //
- // Close the Doxygen group.
- //! @}
- //
- //*****************************************************************************
|