/
freertos_hooks.c
65 lines (47 loc) · 1.47 KB
/
freertos_hooks.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Makebed -- A Makerbot control firmware for the mbed
* (C) 2011 Jonathan Heathcote, University of Manchester
*/
#include "freertos_hooks.h"
/* The time between cycles of the 'check' functionality (defined within the
tick hook. */
#define CHECK_DELAY ( ( portTickType ) 5000 / portTICK_RATE_MS )
void
vApplicationTickHook(void)
{
static unsigned long ulTicksSinceLastDisplay = 0;
// Have enough ticks passed to make it time to perform our health status
// check again?
ulTicksSinceLastDisplay++;
if( ulTicksSinceLastDisplay >= CHECK_DELAY ) {
ulTicksSinceLastDisplay = 0;
// TODO: Do something here...
}
}
void
vApplicationStackOverflowHook(xTaskHandle *pxTask, signed char *pcTaskName)
{
( void ) pxTask;
( void ) pcTaskName;
// TODO: Do something more informative than infiniloop
for( ;; );
}
void
vConfigureTimerForRunTimeStats(void)
{
const unsigned long TCR_COUNT_RESET = 2;
const unsigned long CTCR_CTM_TIMER = 0x00;
const unsigned long TCR_COUNT_ENABLE = 0x01;
/* Power up and feed the timer. */
LPC_SC->PCONP |= 0x02UL;
LPC_SC->PCLKSEL0 = (LPC_SC->PCLKSEL0 & (~(0x3<<2))) | (0x01 << 2);
/* Reset Timer 0 */
LPC_TIM0->TCR = TCR_COUNT_RESET;
/* Just count up. */
LPC_TIM0->CTCR = CTCR_CTM_TIMER;
/* Prescale to a frequency that is good enough to get a decent resolution,
but not too fast so as to overflow all the time. */
LPC_TIM0->PR = ( configCPU_CLOCK_HZ / 10000UL ) - 1UL;
/* Start the counter. */
LPC_TIM0->TCR = TCR_COUNT_ENABLE;
}