-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassert.c
More file actions
147 lines (122 loc) · 3.1 KB
/
assert.c
File metadata and controls
147 lines (122 loc) · 3.1 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include <stdint.h>
#include "inc/tm4c123gh6pm.h"
#include "FreeRTOS.h"
#include "task.h"
#include "assert.h"
#include "utils/uartstdio.h"
int isIntContext(void)
{
int res = 0;
__asm ("mrs r0, iapsr\n\t"
"mov %[result], r0"
: [result]"=r" (res) /* 'result' is output */
: /* No input. */
: "r0" /* r0 was clobbered */
);
return (res & 0x000001ff);
}
void
spinDelayUs(uint32_t us)
{
while(us--)
{
__asm(" nop\n"
" nop\n"
" nop\n"
" nop\n"
" nop\n"
" nop\n"
" nop\n"
" nop\n"
" nop\n"
" nop\n"
" nop\n"
" nop\n");
}
}
void
spinDelayMs(uint32_t ms)
{
while(ms--)
{
spinDelayUs(1000);
}
}
void
_assert_failed (const char *assertion, const char *file, unsigned int line)
{
// Not alot that we can do at the current time so simply blink the
// LED rapidly
//
// Normally an IO would display:
// Assertion failed: expression, file filename, line line number
#ifdef USB_SERIAL_OUTPUT
UARTprintf("\n\nAssertion Failed: (%s) at %s::%d\n", assertion, file, line);
#endif
if ( ! isIntContext() )
{
// disable interrupts and task switching
taskENTER_CRITICAL();
}
taskDISABLE_INTERRUPTS();
// Denergize any outputs
//void motorAllOff(void);
//motorAllOff();
//
// Enable the GPIO port that is used for the on-board LED.
//
SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOF;
//
// Do a dummy read to insert a few cycles after enabling the peripheral.
//
uint32_t ui32Loop = SYSCTL_RCGC2_R;
//
// Enable the GPIO pin for the LED (PF3). Set the direction as output, and
// enable the GPIO pin for digital function.
//
GPIO_PORTF_DIR_R = (1<<1) | (1<<2);
GPIO_PORTF_DEN_R = (1<<1) | (1<<2);
// turn off all the LED's
//
GPIO_PORTF_DATA_R &= ~((1<<2) | (1<<1));
//
// Loop forever.
//
ui32Loop = 700;
while(1)
{
//
// Flash Fast the LED.
//
int cnt=((ui32Loop/2) * (ui32Loop/13) );
while(cnt--)
{
// This block takes about 13.28us
GPIO_PORTF_DATA_R |= (1<<2);
spinDelayUs(10);
GPIO_PORTF_DATA_R &= ~(1<<2);
spinDelayUs(26);
}
cnt=((ui32Loop/2) * (ui32Loop/13) );
while(cnt--)
{
// This block takes about 13.28us
GPIO_PORTF_DATA_R |= (1<<1);
spinDelayUs(2);
GPIO_PORTF_DATA_R &= ~(1<<1);
spinDelayUs(34);
}
}
}
void vApplicationMallocFailedHook( void )
{
assert(0);
for( ;; );
}
void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
{
( void ) pcTaskName;
( void ) pxTask;
assert(0);
for( ;; );
}