RKH
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rkhtim.h
Go to the documentation of this file.
1 /*
2  * --------------------------------------------------------------------------
3  *
4  * Framework RKH
5  * -------------
6  *
7  * State-machine framework for reactive embedded systems
8  *
9  * Copyright (C) 2010 Leandro Francucci.
10  * All rights reserved. Protected by international copyright laws.
11  *
12  *
13  * RKH is free software: you can redistribute it and/or modify it under the
14  * terms of the GNU General Public License as published by the Free Software
15  * Foundation, either version 3 of the License, or (at your option) any
16  * later version.
17  *
18  * RKH is distributed in the hope that it will be useful, but WITHOUT ANY
19  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21  * more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with RKH, see copying.txt file.
25  *
26  * Contact information:
27  * RKH web site: http://sourceforge.net/projects/rkh-reactivesys/
28  * e-mail: francuccilea@gmail.com
29  * ---------------------------------------------------------------------------
30  */
31 
46 /* -------------------------- Development history -------------------------- */
47 /*
48  * 2015.10.24 LeFr v2.4.05 Initial version
49  */
50 
51 /* -------------------------------- Authors -------------------------------- */
52 /*
53  * LeFr Leandro Francucci francuccilea@gmail.com
54  */
55 
56 /* --------------------------------- Notes --------------------------------- */
57 /* --------------------------------- Module -------------------------------- */
58 #ifndef __RKHTIM_H__
59 #define __RKHTIM_H__
60 
61 /* ----------------------------- Include files ----------------------------- */
62 #include "rkhevt.h"
63 
64 /* ---------------------- External C language linkage ---------------------- */
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
68 
69 /* --------------------------------- Macros -------------------------------- */
111 #if RKH_CFG_TMR_HOOK_EN == RKH_ENABLED
112  #define RKH_TMR_INIT(t_, e_, th_) \
113  rkh_tmr_init_((t_), (e_), (th_))
114 #else
115  #define RKH_TMR_INIT(t_, e_, th_) \
116  rkh_tmr_init_((t_), (e_))
117 #endif
118 
149 #define RKH_TMR_ONESHOT(t, sma, itick) \
150  (t)->period = 0; \
151  rkh_tmr_start(t, sma, itick)
152 
188 #define RKH_TMR_PERIODIC(t, sma, itick, per) \
189  (t)->period = (per); \
190  rkh_tmr_start((t), (sma), (itick))
191 
192 /* -------------------------------- Constants ------------------------------ */
193 /* ------------------------------- Data types ------------------------------ */
200 typedef void (*RKH_THK_T)(void *t);
201 
210 #if RKH_CFG_TMR_SIZEOF_NTIMER == 8
211 typedef rui8_t RKH_TNT_T;
212 #elif RKH_CFG_TMR_SIZEOF_NTIMER == 16
213 typedef rui16_t RKH_TNT_T;
214 #elif RKH_CFG_TMR_SIZEOF_NTIMER == 32
215 typedef rui32_t RKH_TNT_T;
216 #else
217 typedef rui8_t RKH_TNT_T;
218 #endif
219 
231 typedef struct RKH_TINFO_T
232 {
233  rui16_t nexp;
234  rui16_t nstart;
235  rui16_t nstop;
236 } RKH_TINFO_T;
237 
238 typedef struct RKH_TMR_T RKH_TMR_T;
239 
269 struct RKH_TMR_T
270 {
275 
280 
286  const struct RKH_SMA_T *sma;
287 
292  RKH_TNT_T ntick;
293 
300  RKH_TNT_T period;
301 
305  rui8_t used;
306 
312 #if RKH_CFG_TMR_HOOK_EN == RKH_ENABLED
314 #endif
315 
320 #if RKH_CFG_TMR_GET_INFO_EN == RKH_ENABLED
322 #endif
323 };
324 
325 /* -------------------------- External variables --------------------------- */
326 /* -------------------------- Function prototypes -------------------------- */
327 #if RKH_CFG_TMR_HOOK_EN == RKH_ENABLED
328 
332  void rkh_tmr_init_(RKH_TMR_T *t, const RKH_EVT_T *e, RKH_THK_T thk);
333 #else
334  void rkh_tmr_init_(RKH_TMR_T *t, const RKH_EVT_T *e);
335 #endif
336 
352 void rkh_tmr_start(RKH_TMR_T *t, const struct RKH_SMA_T *sma,
353  RKH_TNT_T itick);
354 
367 void rkh_tmr_stop(RKH_TMR_T *t);
368 
391 void rkh_tmr_get_info(RKH_TMR_T *t, RKH_TINFO_T *info);
392 
407 
408 /* -------------------- External C language linkage end -------------------- */
409 #ifdef __cplusplus
410 }
411 #endif
412 
413 /* ------------------------------ Module end ------------------------------- */
414 #endif
415 
416 /* ------------------------------ End of file ------------------------------ */
void rkh_tmr_start(RKH_TMR_T *t, const struct RKH_SMA_T *sma, RKH_TNT_T itick)
Start a timer.
void(* RKH_THK_T)(void *t)
The prototype of callback function (hook) to call when the timer expires.
Definition: rkhtim.h:200
void rkh_tmr_clear_info(RKH_TMR_T *t)
Clear performance information for a particular software timer.
Describes the SMA (active object in UML).
Definition: rkhitl.h:2930
rui8_t used
Definition: rkhtim.h:305
void rkh_tmr_init_(RKH_TMR_T *t, const RKH_EVT_T *e, RKH_THK_T thk)
Initializes the previously allocated timer structure RKH_TMR_T.
Represents events without parameters.
Definition: rkhevt.h:161
RKH_TMR_T * tnext
Definition: rkhtim.h:279
Event data type and other related macros.This header file must be included in all modules(*...
Defines the data structure into which the performance information for software timers is stored...
Definition: rkhtim.h:231
Defines the data structure used to maintain information that allows the timer-handling facility to up...
Definition: rkhtim.h:269
RKH_TINFO_T info
Definition: rkhtim.h:321
rui16_t nstart
Definition: rkhtim.h:234
void rkh_tmr_get_info(RKH_TMR_T *t, RKH_TINFO_T *info)
Retrieves performance information for a particular software timer.
RKH_TNT_T ntick
Tick down-counter.
Definition: rkhtim.h:292
rui16_t nstop
Definition: rkhtim.h:235
RKH_EVT_T * evt
Definition: rkhtim.h:274
RKH_THK_T timhk
Definition: rkhtim.h:313
void rkh_tmr_stop(RKH_TMR_T *t)
Stops a running timer.
RKH_TNT_T period
Number of ticks for all timer expirations after the first (expiration period). A zero for this parame...
Definition: rkhtim.h:300
rui8_t RKH_TNT_T
This data type defines the dynamic range of the time delays measured in clock ticks (maximum number o...
Definition: rkhtim.h:211
const struct RKH_SMA_T * sma
State machine application (a.k.a Active Object) that receives the timer event.
Definition: rkhtim.h:286