support.c 3.27 KB
Newer Older
1
2
3
4
5
6
7
8
/*
 * FreeRTOS support functions
 */

#include "FreeRTOS.h"
#include "task.h"

#include "api/dispatcher.h"
Rahix's avatar
Rahix committed
9
#include "modules/modules.h"
10
#include "modules/log.h"
11

12
13
#include "card10.h"

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
 * This hook is called before FreeRTOS enters tickless idle.
 */
void pre_idle_sleep(TickType_t xExpectedIdleTime)
{
	if (xExpectedIdleTime > 0) {
		/*
		 * WFE because the other core should be able to notify
		 * epicardium if it wants to issue an API call.
		 */

		/*
		 * TODO: Ensure this is actually correct and does not have any
		 * race conditions.
		 */
29
30
31
32
33
		if ((CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) == 0) {
			__asm volatile("dsb" ::: "memory");
			__asm volatile("wfe");
			__asm volatile("isb");
		}
34
35
36
37
38
39
40
41
42
43
44
45
	}
}

/*
 * This hook is called after FreeRTOS exits tickless idle.
 */
void post_idle_sleep(TickType_t xExpectedIdleTime)
{
	/* Check whether a new API call was issued. */
	if (api_dispatcher_poll_once()) {
		xTaskNotifyGive(dispatcher_task_id);
	}
46

Rahix's avatar
Rahix committed
47
48
49
50
51
52
53
	/*
	 * Do card10 house keeping. e.g. polling the i2c devices if they
	 * triggered an interrupt.
	 *
	 * TODO: Do this in a more task focused way (high/low ISR)
	 */
	card10_poll();
54
55
56
}

void vApplicationGetIdleTaskMemory(
Rahix's avatar
Rahix committed
57
58
59
60
	StaticTask_t **ppxIdleTaskTCBBuffer,
	StackType_t **ppxIdleTaskStackBuffer,
	uint32_t *pulIdleTaskStackSize
) {
61
62
63
64
65
66
	/*
	 * If the buffers to be provided to the Idle task are declared inside this
	 * function then they must be declared static - otherwise they will be allocated on
	 * the stack and so not exists after this function exits.
	 */
	static StaticTask_t xIdleTaskTCB;
Rahix's avatar
Rahix committed
67
	static StackType_t uxIdleTaskStack[configMINIMAL_STACK_SIZE];
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

	/*
	 * Pass out a pointer to the StaticTask_t structure in which the Idle task's
	 * ktate will be stored.
	 */
	*ppxIdleTaskTCBBuffer = &xIdleTaskTCB;

	/* Pass out the array that will be used as the Idle task's stack. */
	*ppxIdleTaskStackBuffer = uxIdleTaskStack;

	/*
	 * Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
	 * Note that, as the array is necessarily of type StackType_t,
	 * configMINIMAL_STACK_SIZE is specified in words, not bytes.
	 */
	*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
}
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

void vApplicationGetTimerTaskMemory(
	StaticTask_t **ppxTimerTaskTCBBuffer,
	StackType_t **ppxTimerTaskStackBuffer,
	uint32_t *pulTimerTaskStackSize
) {
	/*
	 * If the buffers to be provided to the Timer task are declared inside
	 * this function then they must be declared static - otherwise they will
	 * be allocated on the stack and so not exists after this function
	 * exits.
	 */
	static StaticTask_t xTimerTaskTCB;
	static StackType_t uxTimerTaskStack[configTIMER_TASK_STACK_DEPTH];

	/*
	 * Pass out a pointer to the StaticTask_t structure in which the Timer
	 * task's state will be stored.
	 */
	*ppxTimerTaskTCBBuffer = &xTimerTaskTCB;

	/* Pass out the array that will be used as the Timer task's stack. */
	*ppxTimerTaskStackBuffer = uxTimerTaskStack;

	/*
	 * Pass out the size of the array pointed to by
	 * *ppxTimerTaskStackBuffer.  Note that, as the array is necessarily of
	 * type StackType_t, configMINIMAL_STACK_SIZE is specified in words, not
	 * bytes.
	 */
	*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
}
117
118
119
120
121

void vApplicationStackOverflowHook(TaskHandle_t xTask, signed char *pcTaskName)
{
	LOG_CRIT("rtos", "Task \"%s\" overflowed stack!", pcTaskName);
}