Diego Ostuni / ST25R3911
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers timer1.cpp Source File

timer1.cpp

00001 /******************************************************************************
00002   * @attention
00003   *
00004   * <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
00005   *
00006   * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
00007   * You may not use this file except in compliance with the License.
00008   * You may obtain a copy of the License at:
00009   *
00010   *        http://www.st.com/myliberty
00011   *
00012   * Unless required by applicable law or agreed to in writing, software 
00013   * distributed under the License is distributed on an "AS IS" BASIS, 
00014   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
00015   * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
00016   * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
00017   * See the License for the specific language governing permissions and
00018   * limitations under the License.
00019   *
00020 ******************************************************************************/
00021 /*
00022  *      PROJECT:   ST25R391x firmware
00023  *      $Revision: $
00024  *      LANGUAGE:  ANSI C
00025  */
00026 
00027 /*! \file timer.c
00028  *
00029  *  \brief SW Timer implementation
00030  *
00031  *  \author Gustavo Patricio
00032  *
00033  *   This module makes use of a System Tick in millisconds and provides
00034  *   an abstraction for SW timers
00035  *
00036  */
00037 
00038 /*
00039 ******************************************************************************
00040 * INCLUDES
00041 ******************************************************************************
00042 */
00043 #include "timer1.h"
00044 
00045 
00046 /*
00047 ******************************************************************************
00048 * LOCAL DEFINES
00049 ******************************************************************************
00050 */
00051 
00052 /*
00053 ******************************************************************************
00054 * LOCAL VARIABLES
00055 ******************************************************************************
00056 */
00057 
00058 static uint32_t timerStopwatchTick;
00059 
00060 /*
00061 ******************************************************************************
00062 * GLOBAL FUNCTIONS
00063 ******************************************************************************
00064 */
00065 
00066 
00067 /*******************************************************************************/
00068 uint32_t timerCalculateTimer( uint16_t time )
00069 {  
00070   return (platformGetSysTick() + time);
00071 }
00072 
00073 
00074 /*******************************************************************************/
00075 bool timerIsExpired( uint32_t timer )
00076 {
00077   uint32_t uDiff;
00078   int32_t sDiff;
00079   
00080   uDiff = (timer - platformGetSysTick());   /* Calculate the diff between the timers */
00081   sDiff = uDiff;                            /* Convert the diff to a signed var      */
00082   
00083   /* Check if the given timer has expired already */
00084   if( sDiff < 0 )
00085   {
00086     return true;
00087   }
00088   
00089   return false;
00090 }
00091 
00092 
00093 /*******************************************************************************/
00094 void timerDelay( uint16_t tOut )
00095 {
00096   uint32_t t;
00097   
00098   /* Calculate the timer and wait blocking until is running */
00099   t = timerCalculateTimer( tOut );
00100   while( timerIsRunning(t) );
00101 }
00102 
00103 
00104 /*******************************************************************************/
00105 void timerStopwatchStart( void )
00106 {
00107   timerStopwatchTick = platformGetSysTick();
00108 }
00109 
00110 
00111 /*******************************************************************************/
00112 uint32_t timerStopwatchMeasure( void )
00113 {
00114   return (uint32_t)(platformGetSysTick() - timerStopwatchTick);
00115 }
00116