SatCat5
task.cc
1 // Copyright 2024-2025 The Aerospace Corporation.
3 // This file is a part of SatCat5, licensed under CERN-OHL-W v2 or later.
5 
6 #include <hal_freertos/task.h>
7 
8 // Allocate the task handle in task.cc, marked as extern in task.h
10 
11 // Default hook functions for SatCat5, marked as weak to allow users to override
12 // them. See also:
13 // https://www.freertos.org/Documentation/02-Kernel/02-Kernel-features/12-Hook-functions
14 // https://www.freertos.org/Documentation/02-Kernel/03-Supported-devices/02-Customization#configsupport_static_allocation
15 
16 // Function required for static allocation. Copied from FreeRTOS documentation.
17 extern "C" __attribute__((weak))
18 void vApplicationGetIdleTaskMemory(StaticTask_t** ppxIdleTaskTCBBuffer,
19  StackType_t** ppxIdleTaskStackBuffer, configSTACK_DEPTH_TYPE* pulIdleTaskStackSize)
20 {
21  static StaticTask_t xIdleTaskTCB;
22  static StackType_t uxIdleTaskStack[configMINIMAL_STACK_SIZE];
23  *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
24  *ppxIdleTaskStackBuffer = uxIdleTaskStack;
25  *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
26 }
27 
28 // Function required for static allocation. Copied from FreeRTOS documentation.
29 extern "C" __attribute__((weak))
30 void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer,
31  StackType_t **ppxTimerTaskStackBuffer,
32  configSTACK_DEPTH_TYPE *pulTimerTaskStackSize )
33 {
34  static StaticTask_t xTimerTaskTCB;
35  static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];
36  *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
37  *ppxTimerTaskStackBuffer = uxTimerTaskStack;
38  *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
39 }
40 
41 // Executes from an ISR, notify the timekeeper of the tick then resume.
42 extern "C" __attribute__((weak)) void vApplicationTickHook(void)
43 {
44  satcat5::poll::timekeeper.request_poll();
45  if(satcat5::freertos::satcat_task_handle)
46  xTaskResumeFromISR(satcat5::freertos::satcat_task_handle);
47 }
48 
49 // If dynamic allocation is used, halt execution if malloc() fails.
50 #if (configUSE_MALLOC_FAILED_HOOK == 1)
51 extern "C" __attribute__((weak)) void vApplicationMallocFailedHook(void)
52 {
53  while (1) {} // Busywait forever, should trip watchdog.
54 }
55 #endif // (configUSE_MALLOC_FAILED_HOOK == 1)
56 
57 // If stack overflow checking is enabled, halt execution if detected.
58 #if (configCHECK_FOR_STACK_OVERFLOW > 0)
59 extern "C" __attribute__((weak)) void vApplicationStackOverflowHook(
60  TaskHandle_t xTask, char *pcTaskName)
61 {
62  while (1) {} // Busywait forever, should trip watchdog.
63 }
64 #endif // (configCHECK_FOR_STACK_OVERFLOW > 0)
void request_poll()
Call this method to request polling at a later time.
Definition: polling.cc:208
Provides a FreeRTOS task function and hooks for using SatCat5 as a task inside a larger FreeRTOS proj...
TaskHandle_t satcat_task_handle
Task handle, must be outside StaticTask for access by vApplicationTickHook()
Definition: task.cc:9