watchdog-timer-checkpoint-freertos  2.1.0
watchdog-timer-checkpoint-freertos
Macros | Functions
watchdog_timer_freertos.h File Reference

WATCHDOG TIMER FreeRTOS scheduler checkpoint CCO header file. More...

#include <stdint.h>

Go to the source code of this file.

Macros

#define CHECKPOINT_FREERTOS_OK   0
 Error codes constants. More...
 
#define CHECKPOINT_FREERTOS_ERROR   -1
 

Functions

int32_t watchdog_timer_freertos_scheduler_checkpoint_start (void)
 Starts the FreeRTOS scheduler checkpoint. More...
 
int32_t watchdog_timer_freertos_scheduler_checkpoint_stop (void)
 Stops the FreeRTOS scheduler checkpoint. More...
 
void watchdog_timer_freertos_print_tasks_state (void)
 Prints the current FreeRTOS tasks state. More...
 

Detailed Description

WATCHDOG TIMER FreeRTOS scheduler checkpoint CCO header file.

Author
MicroEJ Developer Team
Version
2.1.0
Date
29 April 2022

Definition in file watchdog_timer_freertos.h.

Macro Definition Documentation

§ CHECKPOINT_FREERTOS_ERROR

#define CHECKPOINT_FREERTOS_ERROR   -1

Error code returned on failure.

Definition at line 31 of file watchdog_timer_freertos.h.

§ CHECKPOINT_FREERTOS_OK

#define CHECKPOINT_FREERTOS_OK   0

Error codes constants.

Error code returned on success.

Definition at line 30 of file watchdog_timer_freertos.h.

Function Documentation

§ watchdog_timer_freertos_print_tasks_state()

void watchdog_timer_freertos_print_tasks_state ( void  )

Prints the current FreeRTOS tasks state.

Note
The macros configUSE_TRACE_FACILITY and configUSE_STATS_FORMATTING_FUNCTIONS need to be defined and set to 1 in FreeRTOSConfig.h otherwise no task state will be printed.

Definition at line 131 of file watchdog_timer_checkpoint_freertos.c.

131  {
132 #if (configUSE_TRACE_FACILITY == 1) && (configUSE_STATS_FORMATTING_FUNCTIONS == 1)
133  char* tasks_log_buffer;
134  uint16_t number_of_tasks = 0;
135  /* Take a snapshot of the number of tasks in case it changes while this
136  function is executing. */
137  number_of_tasks = uxTaskGetNumberOfTasks();
138 
139  if(0 < number_of_tasks){
140  /* Allocate a 50 bytes for each task to print data. */
141  tasks_log_buffer = pvPortMalloc(number_of_tasks * 50 * sizeof(char));
142  vTaskList(tasks_log_buffer);
143  printf("******************************************\n");
144  printf("Task \t State Prio Stack Num\n");
145  printf("******************************************\n");
146  printf("%s \n", tasks_log_buffer);
147  printf("******************************************\n");
148  printf("X-runnning, B–Blocked, R–Ready, D–Deleted, S–Suspended\n");
149  /* The array is no longer needed, free the memory it consumes. */
150  vPortFree(tasks_log_buffer);
151  } else {
152  LLWATCHDOG_TIMER_DEBUG_TRACE("No tasks retrieved with uxTaskGetNumberOfTasks()\n");
153  }
154 #endif
155 }

§ watchdog_timer_freertos_scheduler_checkpoint_start()

int32_t watchdog_timer_freertos_scheduler_checkpoint_start ( void  )

Starts the FreeRTOS scheduler checkpoint.

This function creates a FreeRTOS software timer and registers a watchdog checkpoint for the FreeRTOS scheduler activity. Each time the timer expires, it calls LLWATCHDOG_TIMER_IMPL_checkpoint(unt32_t checkpointId) with the recorded ID to attest the FreeRTOS scheduler activity.

Returns
  • CHECKPOINT_FREERTOS_OK on success.
  • CHECKPOINT_FREERTOS_ERROR if an error occurs.
Note
This function does nothing if the checkpoint is already started.

Definition at line 67 of file watchdog_timer_checkpoint_freertos.c.

67  {
68  if (NULL != wtd_rtos_timer && WATCHDOG_TIMER_ERROR != checkpoint_id_rtos_scheduler) {
69  LLWATCHDOG_TIMER_DEBUG_TRACE("Watchdog FreeRTOS scheduler checkpoint already started.\n");
71  }
72 
73  if (NULL == wtd_rtos_timer && WATCHDOG_TIMER_ERROR == checkpoint_id_rtos_scheduler){
74  wtd_rtos_timer = xTimerCreate(
75  "watchdog_timer_rtos_check", /* name */
76  pdMS_TO_TICKS(FREERTOS_TIMER_PERIOD_MS), /* period in ms */
77  pdTRUE, /* set auto reload */
78  (void*)0, /* timer ID = 0 */
79  watchdog_timer_freertos_check_callback); /* callback function pointer */
80 
81  if (NULL == wtd_rtos_timer) {
82  LLWATCHDOG_TIMER_DEBUG_TRACE("Watchdog FreeRTOS SW timer creation failed\n");
84  }
85 
86  if(pdFAIL == xTimerStart( wtd_rtos_timer, 0 )){
87  LLWATCHDOG_TIMER_DEBUG_TRACE("Fail to start Watchdog FreeRTOS SW timer\n");
88  xTimerDelete( wtd_rtos_timer, 0 );
89  wtd_rtos_timer = NULL;
91  }else{
92  checkpoint_id_rtos_scheduler = LLWATCHDOG_TIMER_IMPL_registerCheckpoint();
93  if(WATCHDOG_TIMER_ERROR == checkpoint_id_rtos_scheduler){
94  LLWATCHDOG_TIMER_DEBUG_TRACE("Fail to register a checkpoint for Watchdog FreeRTOS scheduler activity\n");
95  xTimerDelete( wtd_rtos_timer, 0 );
96  wtd_rtos_timer = NULL;
98  }
100  }
101  }
102 
103  // Here, the timer is null (was deleted in stop function) and the checkpoint is still valid (not unregistered)
104  // This may be caused by a failure of a previous call of watchdog_timer_freertos_scheduler_checkpoint_stop() function.
105  // We cannot restart the scheduler checkpoint when it was not correctly stopped.
106  LLWATCHDOG_TIMER_DEBUG_TRACE("Cannot restart the scheduler checkpoint when it was not correctly stopped.\n");
108 }
#define CHECKPOINT_FREERTOS_OK
Error codes constants.
#define CHECKPOINT_FREERTOS_ERROR
#define FREERTOS_TIMER_PERIOD_MS
Period (in milliseconds) of the FreeRTOS timer that will attest the FreeRTOS scheduler activity...

§ watchdog_timer_freertos_scheduler_checkpoint_stop()

int32_t watchdog_timer_freertos_scheduler_checkpoint_stop ( void  )

Stops the FreeRTOS scheduler checkpoint.

This function stops the software timer and then unregisters the FreeRTOS scheduler checkpoint created in watchdog_timer_freertos_scheduler_checkpoint_start(void).

Returns
  • CHECKPOINT_FREERTOS_OK on success.
  • CHECKPOINT_FREERTOS_ERROR if an error occurs.
Note
If this function fails when attempting to unregister the checkpoint ID, the software timer that has been stopped can no longer attest the scheduler activity and this may trigger the watchdog.

Definition at line 110 of file watchdog_timer_checkpoint_freertos.c.

110  {
111  if(NULL != wtd_rtos_timer){
112  if(pdFAIL == xTimerStop( wtd_rtos_timer, 0 )){
113  LLWATCHDOG_TIMER_DEBUG_TRACE("Watchdog FreeRTOS fails to stop the SW timer\n");
115  }else{
116  xTimerDelete( wtd_rtos_timer, 0 );
117  wtd_rtos_timer = NULL;
118  }
119  }
120  if(WATCHDOG_TIMER_ERROR != checkpoint_id_rtos_scheduler){
121  if(WATCHDOG_TIMER_ERROR == LLWATCHDOG_TIMER_IMPL_unregisterCheckpoint(checkpoint_id_rtos_scheduler)){
122  LLWATCHDOG_TIMER_DEBUG_TRACE("Fail to unregister the FreeRTOS scheduler checkpoint!\n");
124  }
125  checkpoint_id_rtos_scheduler = WATCHDOG_TIMER_ERROR;
126  }
127 
128  return CHECKPOINT_FREERTOS_OK;
129 }
#define CHECKPOINT_FREERTOS_OK
Error codes constants.
#define CHECKPOINT_FREERTOS_ERROR