1 /*------------------------------------------------------------------------------------------------*/
2 /* UNICENS V2.1.0-3491 */
3 /* Copyright (c) 2017 Microchip Technology Germany II GmbH & Co. KG. */
5 /* This program is free software: you can redistribute it and/or modify */
6 /* it under the terms of the GNU General Public License as published by */
7 /* the Free Software Foundation, either version 2 of the License, or */
8 /* (at your option) any later version. */
10 /* This program is distributed in the hope that it will be useful, */
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
13 /* GNU General Public License for more details. */
15 /* You should have received a copy of the GNU General Public License */
16 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 /* You may also obtain this software under a propriety license from Microchip. */
19 /* Please contact Microchip for further information. */
20 /*------------------------------------------------------------------------------------------------*/
24 * \brief Internal header file of the timer management module.
26 * \cond UCS_INTERNAL_DOC
34 /*------------------------------------------------------------------------------------------------*/
36 /*------------------------------------------------------------------------------------------------*/
37 #include "ucs_rules.h"
39 #include "ucs_scheduler.h"
46 /*------------------------------------------------------------------------------------------------*/
48 /*------------------------------------------------------------------------------------------------*/
49 /*! \brief Function signature used for timer handler
50 * \param args Void pointer to optional data
52 typedef void (*Tm_Handler_t)(void *args);
54 /*------------------------------------------------------------------------------------------------*/
56 /*------------------------------------------------------------------------------------------------*/
57 /*! \brief Initialization structure of the timer management module. */
58 typedef struct Tm_InitData_
60 /*! \brief Observer used to request current tick count value */
61 CSingleObserver *get_tick_count_obs_ptr;
62 /*! \brief Observer used to start application timer for delayed TM service calls */
63 CSingleObserver *set_application_timer_obs_ptr;
64 /*! \brief UNICENS instance ID */
65 /*uint8_t ucs_inst_id;*/
69 /*! \brief Class structure of the a timer object. */
70 typedef struct CTimer_
72 /*! \brief Node of the doubly linked (timer-) list */
74 /*! \brief Handler function which is invoked when the timer expires */
75 Tm_Handler_t handler_fptr;
76 /*! \brief Reference to optional parameter */
78 /*! \brief The Timeout value before the timer expires for the first time, in milliseconds */
80 /*! \brief The period of the timer, in milliseconds */
82 /*! \brief Delta time related to next timer in list */
84 /*! \brief Flag which signals that the timer is in use */
86 /*! \brief Flag to check if timer object has changed within timer handler callback function */
91 /*! \brief Class structure of the timer management */
92 typedef struct CTimerManagement_
94 /*! \brief Doubly linked list to manage the active timers */
96 /*! \brief Subject to request current tick count */
97 CSingleSubject get_tick_count_subject;
98 /*! \brief Subject to start the application timer which triggers a UCS service call */
99 CSingleSubject set_application_timer_subject;
100 /*! \brief Service instance to add the timer management to the scheduler */
102 /*! \brief Last tick count value (saved at TM service) */
103 uint16_t last_tick_count;
104 /*! \brief Signals that the application timer callbacks are used */
105 bool delayed_tm_service_enabled;
106 /*! \brief Indicates that the application timer must be started */
107 bool set_service_timer;
108 /*! \brief UNICENS instance ID */
113 /*------------------------------------------------------------------------------------------------*/
114 /* Prototypes of class CTimerManagement */
115 /*------------------------------------------------------------------------------------------------*/
116 extern void Tm_Ctor(CTimerManagement *self, CScheduler *scd, const Tm_InitData_t *init_ptr, void * ucs_user_ptr);
117 extern void Tm_SetTimer(CTimerManagement *self, CTimer *timer_ptr, Tm_Handler_t handler_fptr,
118 void *args_ptr, uint16_t elapse, uint16_t period);
119 extern void Tm_ClearTimer(CTimerManagement *self, CTimer *timer_ptr);
120 extern void Tm_CheckForNextService(CTimerManagement *self);
121 extern void Tm_TriggerService(CTimerManagement *self);
122 extern void Tm_StopService(CTimerManagement *self);
124 /*------------------------------------------------------------------------------------------------*/
125 /* Prototypes of class CTimer */
126 /*------------------------------------------------------------------------------------------------*/
127 extern void T_Ctor(CTimer *self);
128 extern bool T_IsTimerInUse(CTimer *self);
134 #endif /* #ifndef UCS_TIMER_H */
141 /*------------------------------------------------------------------------------------------------*/
143 /*------------------------------------------------------------------------------------------------*/