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 web site: http://sourceforge.net/projects/rkh-reactivesys/
28  * e-mail: francuccilea@gmail.com
29  * ---------------------------------------------------------------------------
30  */
31 
44 /* -------------------------- Development history -------------------------- */
45 /*
46  * 2015.10.24 LeFr v2.4.05 Initial version
47  */
48 
49 /* -------------------------------- Authors -------------------------------- */
50 /*
51  * LeFr Leandro Francucci francuccilea@gmail.com
52  */
53 
54 /* --------------------------------- Notes --------------------------------- */
55 /* --------------------------------- Module -------------------------------- */
56 #ifndef __RKHTMR_H__
57 #define __RKHTMR_H__
58 
59 /* ----------------------------- Include files ----------------------------- */
60 #include "rkhitl.h"
61 
62 /* ---------------------- External C language linkage ---------------------- */
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66 
67 /* --------------------------------- Macros -------------------------------- */
68 #if defined(RKH_USE_TRC_SENDER)
69 
87  #define RKH_TIM_TICK(_sender) rkh_tmr_tick(_sender)
88 #else
89  #define RKH_TIM_TICK(dummy_) rkh_tmr_tick()
90 #endif
91 
133 #if RKH_CFG_TMR_HOOK_EN == RKH_ENABLED
134  #define RKH_TMR_INIT(t_, e_, th_) \
135  rkh_tmr_init_((t_), (e_), (th_))
136 #else
137  #define RKH_TMR_INIT(t_, e_, th_) \
138  rkh_tmr_init_((t_), (e_))
139 #endif
140 
171 #define RKH_TMR_ONESHOT(t, sma, itick) \
172  (t)->period = 0; \
173  rkh_tmr_start(t, sma, itick)
174 
210 #define RKH_TMR_PERIODIC(t, sma, itick, per) \
211  (t)->period = (per); \
212  rkh_tmr_start((t), (sma), (itick))
213 
214 /* -------------------------------- Constants ------------------------------ */
215 /* ------------------------------- Data types ------------------------------ */
222 typedef void (*RKH_THK_T)(void *t);
223 
232 #if RKH_CFG_TMR_SIZEOF_NTIMER == 8
233 typedef rui8_t RKH_TNT_T;
234 #elif RKH_CFG_TMR_SIZEOF_NTIMER == 16
235 typedef rui16_t RKH_TNT_T;
236 #elif RKH_CFG_TMR_SIZEOF_NTIMER == 32
237 typedef rui32_t RKH_TNT_T;
238 #else
239 typedef rui8_t RKH_TNT_T;
240 #endif
241 
253 typedef struct RKH_TINFO_T
254 {
255  rui16_t nexp;
256  rui16_t nstart;
257  rui16_t nstop;
258 } RKH_TINFO_T;
259 
260 typedef struct RKH_TMR_T RKH_TMR_T;
261 
291 struct RKH_TMR_T
292 {
297 
302 
308  const struct RKH_SMA_T *sma;
309 
314  RKH_TNT_T ntick;
315 
322  RKH_TNT_T period;
323 
327  rui8_t used;
328 
334 #if RKH_CFG_TMR_HOOK_EN == RKH_ENABLED
336 #endif
337 
342 #if RKH_CFG_TMR_GET_INFO_EN == RKH_ENABLED
344 #endif
345 };
346 
347 /* -------------------------- External variables --------------------------- */
348 /* -------------------------- Function prototypes -------------------------- */
349 #if RKH_CFG_TMR_HOOK_EN == RKH_ENABLED
350 
354  void rkh_tmr_init_(RKH_TMR_T *t, const RKH_EVT_T *e, RKH_THK_T thk);
355 #else
356  void rkh_tmr_init_(RKH_TMR_T *t, const RKH_EVT_T *e);
357 #endif
358 
374 void rkh_tmr_start(RKH_TMR_T *t, const struct RKH_SMA_T *sma,
375  RKH_TNT_T itick);
376 
389 void rkh_tmr_stop(RKH_TMR_T *t);
390 
413 void rkh_tmr_get_info(RKH_TMR_T *t, RKH_TINFO_T *info);
414 
429 
430 #if defined(RKH_USE_TRC_SENDER)
431 
450 void rkh_tmr_tick(const void *const sender);
451 #else
452 void rkh_tmr_tick(void);
453 #endif
454 
455 /* -------------------- External C language linkage end -------------------- */
456 #ifdef __cplusplus
457 }
458 #endif
459 
460 /* ------------------------------ Module end ------------------------------- */
461 #endif
462 
463 /* ------------------------------ 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_tmr_clear_info(RKH_TMR_T *t)
Clear performance information for a particular software timer.
void rkh_tmr_tick(const void *const sender)
Keep tracks and updates the started timers.
Describes the SMA (active object in UML).
Definition: rkhsma.h:748
rui8_t used
Definition: rkhtmr.h:327
Represents events without parameters.
Definition: rkhevt.h:167
RKH_TMR_T * tnext
Definition: rkhtmr.h:301
Defines the data structure into which the performance information for software timers is stored...
Definition: rkhtmr.h:253
Defines the data structure used to maintain information that allows the timer-handling facility to up...
Definition: rkhtmr.h:291
RKH engine interface.This header file is directly included in RKH interface file, rkh...
RKH_TINFO_T info
Definition: rkhtmr.h:343
rui16_t nstart
Definition: rkhtmr.h:256
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:233
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: rkhtmr.h:314
rui16_t nstop
Definition: rkhtmr.h:257
RKH_EVT_T * evt
Definition: rkhtmr.h:296
RKH_THK_T timhk
Definition: rkhtmr.h:335
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.
void rkh_tmr_stop(RKH_TMR_T *t)
Stops a running timer.
void(* RKH_THK_T)(void *t)
The prototype of callback function (hook) to call when the timer expires.
Definition: rkhtmr.h:222
RKH_TNT_T period
Number of ticks for all timer expirations after the first (expiration period). A zero for this parame...
Definition: rkhtmr.h:322
const struct RKH_SMA_T * sma
State machine application (a.k.a Active Object) that receives the timer event.
Definition: rkhtmr.h:308