etisserant@0: /* greg@561: This file is part of CanFestival, a library implementing CanOpen Stack. etisserant@0: etisserant@0: Copyright (C): Edouard TISSERANT and Francis DUPIN etisserant@0: etisserant@0: See COPYING file for copyrights details. etisserant@0: etisserant@0: This library is free software; you can redistribute it and/or etisserant@0: modify it under the terms of the GNU Lesser General Public etisserant@0: License as published by the Free Software Foundation; either etisserant@0: version 2.1 of the License, or (at your option) any later version. etisserant@0: etisserant@0: This library is distributed in the hope that it will be useful, etisserant@0: but WITHOUT ANY WARRANTY; without even the implied warranty of etisserant@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU etisserant@0: Lesser General Public License for more details. etisserant@0: etisserant@0: You should have received a copy of the GNU Lesser General Public etisserant@0: License along with this library; if not, write to the Free Software etisserant@0: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA etisserant@0: */ etisserant@0: Edouard@801: #ifndef __timers_h__ Edouard@801: #define __timers_h__ etisserant@0: etisserant@145: #include etisserant@0: #include etisserant@0: etisserant@0: #define TIMER_HANDLE INTEGER16 etisserant@0: etisserant@0: #include "data.h" etisserant@0: frdupin@71: /* --------- types and constants definitions --------- */ etisserant@0: #define TIMER_FREE 0 etisserant@0: #define TIMER_ARMED 1 etisserant@0: #define TIMER_TRIG 2 etisserant@0: #define TIMER_TRIG_PERIOD 3 etisserant@0: etisserant@0: #define TIMER_NONE -1 etisserant@0: etisserant@0: typedef void (*TimerCallback_t)(CO_Data* d, UNS32 id); etisserant@0: etisserant@0: struct struct_s_timer_entry { etisserant@0: UNS8 state; etisserant@0: CO_Data* d; frdupin@71: TimerCallback_t callback; /* The callback func. */ frdupin@71: UNS32 id; /* The callback func. */ etisserant@0: TIMEVAL val; frdupin@71: TIMEVAL interval; /* Periodicity */ etisserant@0: }; etisserant@0: etisserant@0: typedef struct struct_s_timer_entry s_timer_entry; etisserant@0: frdupin@71: /* --------- prototypes --------- */ frdupin@71: /*#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)*/ greg@561: /** greg@561: * @ingroup timer greg@561: * @brief Set an alarm to execute a callback function when expired. greg@561: * @param *d Pointer to a CAN object data structure greg@561: * @param id The alarm Id greg@561: * @param callback A callback function greg@561: * @param value Call the callback function at current time + value greg@561: * @param period Call periodically the callback function greg@561: * @return handle The timer handle greg@561: */ etisserant@0: TIMER_HANDLE SetAlarm(CO_Data* d, UNS32 id, TimerCallback_t callback, TIMEVAL value, TIMEVAL period); greg@561: greg@561: /** greg@561: * @ingroup timer greg@561: * @brief Delete an alarm before expiring. greg@561: * @param handle A timer handle greg@561: * @return The timer handle greg@561: */ etisserant@0: TIMER_HANDLE DelAlarm(TIMER_HANDLE handle); greg@561: etisserant@0: void TimeDispatch(void); etisserant@0: greg@561: /** greg@561: * @ingroup timer greg@561: * @brief Set a timerfor a given time. greg@561: * @param value The time value. greg@561: */ etisserant@0: void setTimer(TIMEVAL value); greg@561: greg@561: /** greg@561: * @ingroup timer greg@561: * @brief Get the time elapsed since latest timer occurence. greg@561: * @return time elapsed since latest timer occurence greg@561: */ etisserant@0: TIMEVAL getElapsedTime(void); etisserant@0: Edouard@801: #endif /* #define __timers_h__ */