include/timers.h
changeset 801 32d146b64a35
parent 561 f9be4262c68d
equal deleted inserted replaced
800:f0d16976e46e 801:32d146b64a35
       
     1 /*
       
     2 This file is part of CanFestival, a library implementing CanOpen Stack.
       
     3 
       
     4 Copyright (C): Edouard TISSERANT and Francis DUPIN
       
     5 
       
     6 See COPYING file for copyrights details.
       
     7 
       
     8 This library is free software; you can redistribute it and/or
       
     9 modify it under the terms of the GNU Lesser General Public
       
    10 License as published by the Free Software Foundation; either
       
    11 version 2.1 of the License, or (at your option) any later version.
       
    12 
       
    13 This library is distributed in the hope that it will be useful,
       
    14 but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    16 Lesser General Public License for more details.
       
    17 
       
    18 You should have received a copy of the GNU Lesser General Public
       
    19 License along with this library; if not, write to the Free Software
       
    20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
       
    21 */
       
    22 
       
    23 #ifndef __timers_h__
       
    24 #define __timers_h__
       
    25 
       
    26 #include <timerscfg.h>
       
    27 #include <applicfg.h>
       
    28 
       
    29 #define TIMER_HANDLE INTEGER16
       
    30 
       
    31 #include "data.h"
       
    32 
       
    33 /* --------- types and constants definitions --------- */
       
    34 #define TIMER_FREE 0
       
    35 #define TIMER_ARMED 1
       
    36 #define TIMER_TRIG 2
       
    37 #define TIMER_TRIG_PERIOD 3
       
    38 
       
    39 #define TIMER_NONE -1
       
    40 
       
    41 typedef void (*TimerCallback_t)(CO_Data* d, UNS32 id);
       
    42 
       
    43 struct struct_s_timer_entry {
       
    44 	UNS8 state;
       
    45 	CO_Data* d;
       
    46 	TimerCallback_t callback; /* The callback func. */
       
    47 	UNS32 id; /* The callback func. */
       
    48 	TIMEVAL val;
       
    49 	TIMEVAL interval; /* Periodicity */
       
    50 };
       
    51 
       
    52 typedef struct struct_s_timer_entry s_timer_entry;
       
    53 
       
    54 /* ---------  prototypes --------- */
       
    55 /*#define SetAlarm(d, id, callback, value, period) printf("%s, %d, SetAlarm(%s, %s, %s, %s, %s)\n",__FILE__, __LINE__, #d, #id, #callback, #value, #period); _SetAlarm(d, id, callback, value, period)*/
       
    56 /**
       
    57  * @ingroup timer
       
    58  * @brief Set an alarm to execute a callback function when expired.
       
    59  * @param *d Pointer to a CAN object data structure
       
    60  * @param id The alarm Id
       
    61  * @param callback A callback function
       
    62  * @param value Call the callback function at current time + value
       
    63  * @param period Call periodically the callback function
       
    64  * @return handle The timer handle
       
    65  */
       
    66 TIMER_HANDLE SetAlarm(CO_Data* d, UNS32 id, TimerCallback_t callback, TIMEVAL value, TIMEVAL period);
       
    67 
       
    68 /**
       
    69  * @ingroup timer
       
    70  * @brief Delete an alarm before expiring.
       
    71  * @param handle A timer handle
       
    72  * @return The timer handle
       
    73  */
       
    74 TIMER_HANDLE DelAlarm(TIMER_HANDLE handle);
       
    75 
       
    76 void TimeDispatch(void);
       
    77 
       
    78 /**
       
    79  * @ingroup timer
       
    80  * @brief Set a timerfor a given time.
       
    81  * @param value The time value.
       
    82  */
       
    83 void setTimer(TIMEVAL value);
       
    84 
       
    85 /**
       
    86  * @ingroup timer
       
    87  * @brief Get the time elapsed since latest timer occurence.
       
    88  * @return time elapsed since latest timer occurence
       
    89  */
       
    90 TIMEVAL getElapsedTime(void);
       
    91 
       
    92 #endif /* #define __timers_h__ */