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