RKH
rkhtmr.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 site: http://vortexmakes.com/que-es/
28  * RKH GitHub: https://github.com/vortexmakes/RKH
29  * RKH Sourceforge: https://sourceforge.net/projects/rkh-reactivesys/
30  * e-mail: lf@vortexmakes.com
31  * ---------------------------------------------------------------------------
32  */
33 
46 /* -------------------------- Development history -------------------------- */
47 /*
48  * 2015.10.24 LeFr v2.4.05 Initial version
49  */
50 
51 /* -------------------------------- Authors -------------------------------- */
52 /*
53  * LeFr Leandro Francucci lf@vortexmakes.com
54  */
55 
56 /* --------------------------------- Notes --------------------------------- */
57 /* --------------------------------- Module -------------------------------- */
58 #ifndef __RKHTMR_H__
59 #define __RKHTMR_H__
60 
61 /* ----------------------------- Include files ----------------------------- */
62 #include "rkhitl.h"
63 
64 /* ---------------------- External C language linkage ---------------------- */
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
68 
69 /* --------------------------------- Macros -------------------------------- */
70 #if defined(RKH_USE_TRC_SENDER)
89  #define RKH_TIM_TICK(_sender) rkh_tmr_tick(_sender)
90 #else
91  #define RKH_TIM_TICK(dummy_) rkh_tmr_tick()
92 #endif
93 
142 #if RKH_CFG_TMR_HOOK_EN == RKH_ENABLED
143  #define RKH_TMR_INIT(t_, e_, th_) \
144  rkh_tmr_init_((t_), (e_), (th_))
145 #else
146  #define RKH_TMR_INIT(t_, e_, th_) \
147  rkh_tmr_init_((t_), (e_))
148 #endif
149 
187 #define RKH_TMR_ONESHOT(t, sma, itick) \
188  rkh_tmr_start(t, sma, itick, 0)
189 
234 #define RKH_TMR_PERIODIC(t, sma, itick, per) \
235  rkh_tmr_start((t), (sma), (itick), (per))
236 
237 /* -------------------------------- Constants ------------------------------ */
238 /* ------------------------------- Data types ------------------------------ */
245 typedef void (*RKH_THK_T)(void *t);
246 
255 #if RKH_CFG_TMR_SIZEOF_NTIMER == 8
256 typedef rui8_t RKH_TNT_T;
257 #elif RKH_CFG_TMR_SIZEOF_NTIMER == 16
258 typedef rui16_t RKH_TNT_T;
259 #elif RKH_CFG_TMR_SIZEOF_NTIMER == 32
260 typedef rui32_t RKH_TNT_T;
261 #else
262 typedef rui8_t RKH_TNT_T;
263 #endif
264 
276 typedef struct RKH_TINFO_T
277 {
278  rui16_t nexp;
279  rui16_t nstart;
280  rui16_t nstop;
281 } RKH_TINFO_T;
282 
283 typedef struct RKH_TMR_T RKH_TMR_T;
284 
314 struct RKH_TMR_T
315 {
320 
325 
331  const struct RKH_SMA_T *sma;
332 
338 
346 
350  rui8_t used;
351 
357 #if RKH_CFG_TMR_HOOK_EN == RKH_ENABLED
359 #endif
360 
365 #if RKH_CFG_TMR_GET_INFO_EN == RKH_ENABLED
367 #endif
368 };
369 
370 typedef struct RKHTmEvt RKHTmEvt;
371 
408 struct RKHTmEvt
409 {
410  RKH_EVT_T evt;
412 };
413 
414 /* -------------------------- External variables --------------------------- */
415 /* -------------------------- Function prototypes -------------------------- */
416 #if RKH_CFG_TMR_HOOK_EN == RKH_ENABLED
421  void rkh_tmr_init_(RKH_TMR_T *t, const RKH_EVT_T *e, RKH_THK_T thk);
422 #else
423  void rkh_tmr_init_(RKH_TMR_T *t, const RKH_EVT_T *e);
424 #endif
425 
445 void rkh_tmr_start(RKH_TMR_T *t, const struct RKH_SMA_T *sma,
446  RKH_TNT_T itick, RKH_TNT_T per);
447 
467 
477 void rkh_tmr_init(void);
478 
502 
517 
518 #if defined(RKH_USE_TRC_SENDER)
538 void rkh_tmr_tick(const void *const sender);
539 #else
540 void rkh_tmr_tick(void);
541 #endif
542 
543 /* -------------------- External C language linkage end -------------------- */
544 #ifdef __cplusplus
545 }
546 #endif
547 
548 /* ------------------------------ Module end ------------------------------- */
549 #endif
550 
551 /* ------------------------------ End of file ------------------------------ */
void rkh_tmr_init(void)
Initializes the timer module.
void rkh_tmr_start(RKH_TMR_T *t, const struct RKH_SMA_T *sma, RKH_TNT_T itick, RKH_TNT_T per)
Start a timer.
void rkh_tmr_get_info(RKH_TMR_T *t, RKH_TINFO_T *info)
Retrieves performance information for a particular software timer.
void rkh_tmr_clear_info(RKH_TMR_T *t)
Clear performance information for a particular software timer.
rbool_t rkh_tmr_stop(RKH_TMR_T *t)
Stops a running timer.
RKH engine interface.This header file is directly included in RKH interface file, rkh....
void rkh_tmr_tick(const void *const sender)
Keep tracks and updates the started timers.
void(* RKH_THK_T)(void *t)
The prototype of callback function (hook) to call when the timer expires.
Definition: rkhtmr.h:245
rui8_t RKH_TNT_T
This data type defines the dynamic range of the time delays measured in clock ticks (maximum number o...
Definition: rkhtmr.h:256
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:170
Describes the SMA (active object in UML).
Definition: rkhsma.h:772
Defines the data structure into which the performance information for software timers is stored.
Definition: rkhtmr.h:277
rui16_t nstart
Definition: rkhtmr.h:279
rui16_t nstop
Definition: rkhtmr.h:280
Defines the data structure used to maintain information that allows the timer-handling facility to up...
Definition: rkhtmr.h:315
RKH_THK_T timhk
Definition: rkhtmr.h:358
RKH_TNT_T period
Number of ticks for all timer expirations after the first (expiration period). A zero for this parame...
Definition: rkhtmr.h:345
RKH_TMR_T * tnext
Definition: rkhtmr.h:324
const struct RKH_SMA_T * sma
State machine application (a.k.a Active Object) that receives the timer event.
Definition: rkhtmr.h:331
rui8_t used
Definition: rkhtmr.h:350
RKH_TINFO_T info
Definition: rkhtmr.h:366
RKH_TNT_T ntick
Tick down-counter.
Definition: rkhtmr.h:337
RKH_EVT_T * evt
Definition: rkhtmr.h:319
It defines a time event that occurs at a specific duration.
Definition: rkhtmr.h:409
RKH_TMR_T tmr
Definition: rkhtmr.h:411