SAM3S8/SD8 Software Package: libraries/libboard_sam3s-ek2/source/timetick.c Source File

SAM3S8/SD8 Software Package 1.2

# timetick.c

Go to the documentation of this file.

    00001 /* ----------------------------------------------------------------------------
    00002  *         ATMEL Microcontroller Software Support
    00003  * ----------------------------------------------------------------------------
    00004  * Copyright (c) 2009, Atmel Corporation
    00005  *
    00006  * All rights reserved.
    00007  *
    00008  * Redistribution and use in source and binary forms, with or without
    00009  * modification, are permitted provided that the following conditions are met:
    00010  *
    00011  * - Redistributions of source code must retain the above copyright notice,
    00012  * this list of conditions and the disclaimer below.
    00013  *
    00014  * Atmel's name may not be used to endorse or promote products derived from
    00015  * this software without specific prior written permission.
    00016  *
    00017  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
    00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    00019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
    00020  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
    00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    00022  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
    00023  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    00024  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    00025  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    00026  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00027  * ----------------------------------------------------------------------------
    00028  */
    00029
    00030 /**
    00031  *  \file
    00032  *  Implement simple system tick usage.
    00033  */
    00034
    00035 /*----------------------------------------------------------------------------
    00036  *         Headers
    00037  *----------------------------------------------------------------------------*/
    00038
    00039 #include "board.h"
    00040
    00041 /*----------------------------------------------------------------------------
    00042  *         Local variables
    00043  *----------------------------------------------------------------------------*/
    00044
    00045 /** Tick Counter united by ms */
    00046 static volatile uint32_t _dwTickCount=0 ;
    00047
    00048 /*----------------------------------------------------------------------------
    00049  *         Exported Functions
    00050  *----------------------------------------------------------------------------*/
    00051
    00052 /**
    00053  *  \brief Handler for Sytem Tick interrupt.
    00054  */
    00055 extern void TimeTick_Increment( void )
    00056 {
    00057     _dwTickCount++ ;
    00058 }
    00059
    00060 /**
    00061  *  \brief Configures the SAM3 SysTick & reset tickCount.
    00062  *  Systick interrupt handler will generates 1ms interrupt and increase a
    00063  *  tickCount.
    00064  *  \param new_mck  Current master clock.
    00065  */
    00066 extern uint32_t TimeTick_Configure( uint32_t new_mck )
    00067 {
    00068     _dwTickCount = 0 ;
    00069     return SysTick_Config( new_mck/1000 ) ;
    00070 }
    00071
    00072 /**
    00073  *  \brief Get current Tick Count, in ms.
    00074  */
    00075 extern uint32_t GetTickCount( void )
    00076 {
    00077     return _dwTickCount ;
    00078 }
    00079
    00080 /**
    00081  *  \brief Sync Wait for several ms
    00082  */
    00083 extern void Wait( volatile uint32_t dwMs )
    00084 {
    00085     uint32_t dwStart ;
    00086     uint32_t dwCurrent ;
    00087
    00088     dwStart = _dwTickCount ;
    00089     do
    00090     {
    00091         dwCurrent = _dwTickCount ;
    00092     } while ( dwCurrent - dwStart < dwMs ) ;
    00093 }
    00094
    00095 /**
    00096  *  \brief Sync Sleep for several ms
    00097  */
    00098 extern void Sleep( volatile uint32_t dwMs )
    00099 {
    00100     uint32_t dwStart ;
    00101     uint32_t dwCurrent ;
    00102
    00103     dwStart = _dwTickCount ;
    00104
    00105     do
    00106     {
    00107         dwCurrent = _dwTickCount ;
    00108
    00109         if ( dwCurrent - dwStart > dwMs )
    00110         {
    00111             break ;
    00112         }
    00113
    00114         __WFI() ;
    00115     } while( 1 ) ;
    00116 }
    00117

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines