m2mb API docs  37.00.006.0
m2mb API sets documentation
m2mb_wDog.h
Go to the documentation of this file.
1 /* $version: 372317T2_R1 */
2 /*===============================================================================================*/
3 /* >>> Copyright (C) Telit Communications S.p.A. Italy All Rights Reserved. <<< */
75 #ifndef M2MB_WDOG_H
76 #define M2MB_WDOG_H
77 
78 /* Include ======================================================================================*/
79 
80 
81 /* Global declarations ==========================================================================*/
82 #define M2MB_WDOG_INVALID 0
83 
84 #define M2MB_WDOG_ENABLED TRUE
85 #define M2MB_WDOG_DISABLED FALSE
86 #define M2MB_WDOG_GPIO_ISR_ENABLE TRUE
87 #define M2MB_WDOG_GPIO_ISR_DISABLE FALSE
88 
89 /* Global typedefs ==============================================================================*/
90 /* define the handle for watchdog management */
91 typedef struct M2MB_WDOG_HANDLE_TAG *M2MB_WDOG_HANDLE;
92 
93 /* possible events on watchdog indication callback */
94 typedef enum
95 {
96  M2MB_WDOG_TIMEOUT_IND,
97  ENUM_TO_INT( M2MB_WDOG_IND_E )
98 } M2MB_WDOG_IND_E;
99 
100 /* command selection to be used in m2mb_wdog_getItem: parameters are set instead using proper APIs.
101  Please note that here below sometimes the commands
102  are used in the description as they were the associated parameters values
103  that can be retrieved using the same commands:
104  e.g
105  "after M2MB_WDOG_SELECT_CMD_MAX_TICKS_TO_REBOOT" is intended after the value you can get calling
106  m2mb_wdog_getItem with M2MB_WDOG_SELECT_CMD_MAX_TICKS_TO_REBOOT command
107 */
108 typedef enum
109 {
110  /* general instance control activity counter in ticks, both for task control and ISR
111  depending on handle type
112 */
113  M2MB_WDOG_SELECT_CMD_TICKS,
114  /* reboots the system in case no action is taken after watchdog timeout reached for at least a task.
115  In case instance is managed by ISR, please reboots after M2MB_WDOG_SELECT_CMD_MAX_TICKS_TO_REBOOT.
116  For example, if system is in busy loop, since in this scenario callback could not be invoked,
117  the system is rebooted after M2MB_WDOG_SELECT_CMD_MAX_TICKS_TO_REBOOT if callback is not called
118  */
119  M2MB_WDOG_SELECT_CMD_MAX_TICKS_TO_REBOOT,
120  /* instance counter value: from M2MB_WDOG_SELECT_CMD_TICKS_WAKEUP to 0 */
121  M2MB_WDOG_SELECT_CMD_CNT,
122  /* wake_up means how many control events before actual control, both ISR or task.
123  On ISR, to optimize the performances, it is better to set correctly the HW signal on gpio instead
124  of SW use; basically, it is better to set M2MB_WDOG_SELECT_CMD_TICKS_WAKEUP to 1 for ISR, when possible.
125  On task control, value from M2MB_WDOG_SELECT_CMD_TICK_DURATION_MS can be used to properly adjust
126  M2MB_WDOG_SELECT_CMD_TICKS_WAKEUP
127  */
128  M2MB_WDOG_SELECT_CMD_TICKS_WAKEUP,
129  /* provide status on ISR set: if M2MB_WDOG_GPIO_ISR_ENABLE instance is set as ISR */
130  M2MB_WDOG_SELECT_CMD_ISR,
131  /* M2MB_WDOG_DISABLED if disable or M2MB_WDOG_ENABLED if instance control is enabled */
132  M2MB_WDOG_SELECT_CMD_STATUS,
133  /* meaningful only for wDog in task control type, not in ISR */
134  M2MB_WDOG_SELECT_CMD_TICK_DURATION_MS,
135  /* task counter from M2MB_WDOG_SELECT_CMD_TASK_TIMEOUT to 0 for task in selected instance */
136  M2MB_WDOG_SELECT_CMD_TASK_CNT,
137  M2MB_WDOG_SELECT_CMD_TASK_TIMEOUT,
138  /* M2MB_WDOG_SELECT_CMD_TASK_TIMED_OUT and M2MB_WDOG_SELECT_CMD_NEXT_EXPIRING_TASK,
139  belong to instance, task handle is ignored for these commands selections
140  task handle is the returned value
141  */
142  /* timed out task in the instance, if any; it reports only the first task timed out occurred,
143  while any counter of every other task in the instance, is kept frozen.
144  M2MB_OS_TASK_INVALID in case no timed out task */
145  M2MB_WDOG_SELECT_CMD_TASK_TIMED_OUT,
146  /* next expiring task in the instance */
147  M2MB_WDOG_SELECT_CMD_NEXT_EXPIRING_TASK,
148  ENUM_TO_INT( M2MB_WDOG_SELECT_CMD_E )
149 } M2MB_WDOG_SELECT_CMD_E;
150 
151 /* callback invoked during watchdog event like M2MB_WDOG_TIMEOUT_IND
152  resp_struct is generally a pointer to the response related to each M2MB_WDOG_IND_E event
153  and should be casted to it. resp_size is related to specific undefined field in structure
154  where present or it is the size of structure itself(e.g. data)
155  For M2MB_WDOG_TIMEOUT_IND, event resp_size and resp_struct has not to be used for
156  m2mb_wDog module. Info can be collected like below example
157  void watchdog_callback( M2MB_WDOG_HANDLE hDog, M2MB_WDOG_IND_E wDog_event,
158  UINT16 resp_size, void *resp_struct, void *userdata )
159  {
160  M2MB_OS_TASK_HANDLE hTask;
161  M2MB_RESULT_E m2mbRes;
162  UNUSED_3( resp_size, resp_struct, userdata ); //depending on which input parameters are not used
163 
164  switch( wDog_event )
165  {
166  case M2MB_WDOG_TIMEOUT_IND:
167  m2mbRes = m2mb_wDog_disable( hDog ); //disable if it is desired
168  //get info on which task timed out
169  m2mbRes = m2mb_wDog_getItem( hDog, M2MB_WDOG_SELECT_CMD_TASK_TIMED_OUT, 0, ( MEM_W *)&hTask );
170  //performs some log if needed
171  //performs in case action like restarting the involved application, having previously get the
172  //application handle appMngH
173  m2mb_appMng_restart( appMngH );
174  break;
175 
176  default:
177  break;
178  }
179  }
180 */
181 typedef void ( *M2MB_WDOG_IND_CALLBACK )( M2MB_WDOG_HANDLE h, M2MB_WDOG_IND_E wDog_event,
182  UINT16 resp_size, void *resp_struct, void *userdata );
183 
184 /* Global functions =============================================================================*/
185 
186 /*------------------------------------------------------------------------------------------------*/
219 /*------------------------------------------------------------------------------------------------*/
220 M2MB_RESULT_E m2mb_wDog_init( M2MB_WDOG_HANDLE *h, M2MB_WDOG_IND_CALLBACK wDogCallback, void *userdata );
221 
222 /*------------------------------------------------------------------------------------------------*/
252 /*------------------------------------------------------------------------------------------------*/
253 M2MB_RESULT_E m2mb_wDog_deinit( M2MB_WDOG_HANDLE h );
254 
255 /*------------------------------------------------------------------------------------------------*/
305 /*------------------------------------------------------------------------------------------------*/
306 M2MB_RESULT_E m2mb_wDog_enable( M2MB_WDOG_HANDLE h, MEM_W wDogWakeUpTicks, MEM_W ticksToReboot );
307 
308 /*------------------------------------------------------------------------------------------------*/
338 /*------------------------------------------------------------------------------------------------*/
339 M2MB_RESULT_E m2mb_wDog_disable( M2MB_WDOG_HANDLE h );
340 
341 /*------------------------------------------------------------------------------------------------*/
371 /*------------------------------------------------------------------------------------------------*/
372 M2MB_RESULT_E m2mb_wDog_reset( M2MB_WDOG_HANDLE h );
373 
374 /*------------------------------------------------------------------------------------------------*/
444 /*------------------------------------------------------------------------------------------------*/
445 M2MB_RESULT_E m2mb_wDog_isr( M2MB_WDOG_HANDLE h, const CHAR *gpioPath, M2MB_GPIO_TRIGGER_E edgeTrigger );
446 
447 /*------------------------------------------------------------------------------------------------*/
514 /*------------------------------------------------------------------------------------------------*/
515 M2MB_RESULT_E m2mb_wDog_addTask( M2MB_WDOG_HANDLE h, M2MB_OS_TASK_HANDLE hTask, UINT32 wdTimeout );
516 
517 /*------------------------------------------------------------------------------------------------*/
559 /*------------------------------------------------------------------------------------------------*/
560 M2MB_RESULT_E m2mb_wDog_removeTask( M2MB_WDOG_HANDLE h, M2MB_OS_TASK_HANDLE hTask );
561 
562 /*------------------------------------------------------------------------------------------------*/
663 /*------------------------------------------------------------------------------------------------*/
664 M2MB_RESULT_E m2mb_wDog_kick( M2MB_WDOG_HANDLE h, M2MB_OS_TASK_HANDLE hTask );
665 
666 /*------------------------------------------------------------------------------------------------*/
732 /*------------------------------------------------------------------------------------------------*/
733 M2MB_RESULT_E m2mb_wDog_getItem( M2MB_WDOG_HANDLE h, M2MB_WDOG_SELECT_CMD_E wDogCmd,
734  M2MB_OS_TASK_HANDLE hTask, MEM_W *pOut );
735 
736 
737 /* Global define ================================================================================*/
738 
739 #endif /* M2MB_WDOG_H */
740 
m2mb_wDog_removeTask
M2MB_RESULT_E m2mb_wDog_removeTask(M2MB_WDOG_HANDLE h, M2MB_OS_TASK_HANDLE hTask)
m2mb_wDog_removeTask
m2mb_wDog_init
M2MB_RESULT_E m2mb_wDog_init(M2MB_WDOG_HANDLE *h, M2MB_WDOG_IND_CALLBACK wDogCallback, void *userdata)
m2mb_wDog_init
m2mb_wDog_enable
M2MB_RESULT_E m2mb_wDog_enable(M2MB_WDOG_HANDLE h, MEM_W wDogWakeUpTicks, MEM_W ticksToReboot)
m2mb_wDog_enable
m2mb_wDog_getItem
M2MB_RESULT_E m2mb_wDog_getItem(M2MB_WDOG_HANDLE h, M2MB_WDOG_SELECT_CMD_E wDogCmd, M2MB_OS_TASK_HANDLE hTask, MEM_W *pOut)
m2mb_wDog_getItem
M2MB_GPIO_TRIGGER_E
M2MB_GPIO_TRIGGER_E
Definition: m2mb_gpio.h:107
m2mb_wDog_deinit
M2MB_RESULT_E m2mb_wDog_deinit(M2MB_WDOG_HANDLE h)
m2mb_wDog_deinit
m2mb_wDog_kick
M2MB_RESULT_E m2mb_wDog_kick(M2MB_WDOG_HANDLE h, M2MB_OS_TASK_HANDLE hTask)
m2mb_wDog_kick
m2mb_wDog_addTask
M2MB_RESULT_E m2mb_wDog_addTask(M2MB_WDOG_HANDLE h, M2MB_OS_TASK_HANDLE hTask, UINT32 wdTimeout)
m2mb_wDog_addTask
m2mb_wDog_reset
M2MB_RESULT_E m2mb_wDog_reset(M2MB_WDOG_HANDLE h)
m2mb_wDog_reset
m2mb_wDog_disable
M2MB_RESULT_E m2mb_wDog_disable(M2MB_WDOG_HANDLE h)
m2mb_wDog_disable
m2mb_wDog_isr
M2MB_RESULT_E m2mb_wDog_isr(M2MB_WDOG_HANDLE h, const CHAR *gpioPath, M2MB_GPIO_TRIGGER_E edgeTrigger)
m2mb_wDog_isr