/
main.c
239 lines (202 loc) · 5.13 KB
/
main.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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
// Standard includes
#include <stdio.h>
// Driverlib includes
#include "hw_types.h"
#include "hw_ints.h"
#include "hw_memmap.h"
#include "hw_common_reg.h"
#include "interrupt.h"
#include "hw_apps_rcm.h"
#include "prcm.h"
#include "rom.h"
#include "rom_map.h"
#include "prcm.h"
#include "gpio.h"
#include "utils.h"
// Common interface includes
#include "gpio_if.h"
#include "button_if.h"
#include "pinmux.h"
#include "common.h"
#include "osi.h"
#include "uart_if.h"
//*****************************************************************************
// GLOBAL VARIABLES -- Start
//*****************************************************************************
volatile uint32_t val;
#if defined(ccs) || defined(gcc)
extern void (* const g_pfnVectors[])(void);
#endif
#if defined(ewarm)
extern uVectorEntry __vector_table;
#endif
#define OSI_STACK_SIZE 4096
OsiTaskHandle g_PushButtonTask;
//*****************************************************************************
// GLOBAL VARIABLES -- End
//*****************************************************************************
//*****************************************************************************
// LOCAL FUNCTION DEFINITIONS
//*****************************************************************************
#ifdef USE_FREERTOS
//*****************************************************************************
// FreeRTOS User Hook Functions enabled in FreeRTOSConfig.h
//*****************************************************************************
//*****************************************************************************
//
//! \brief Application defined hook (or callback) function - assert
//!
//! \param[in] pcFile - Pointer to the File Name
//! \param[in] ulLine - Line Number
//!
//! \return none
//!
//*****************************************************************************
void
vAssertCalled( const char *pcFile, unsigned long ulLine )
{
//Handle Assert here
while(1)
{
}
}
//*****************************************************************************
//
//! \brief Application defined idle task hook
//!
//! \param none
//!
//! \return none
//!
//*****************************************************************************
void
vApplicationIdleHook( void)
{
//Handle Idle Hook for Profiling, Power Management etc
}
//*****************************************************************************
//
//! \brief Application defined malloc failed hook
//!
//! \param none
//!
//! \return none
//!
//*****************************************************************************
void vApplicationMallocFailedHook()
{
//Handle Memory Allocation Errors
while(1)
{
}
}
//*****************************************************************************
//
//! \brief Application defined stack overflow hook
//!
//! \param none
//!
//! \return none
//!
//*****************************************************************************
void vApplicationStackOverflowHook( OsiTaskHandle *pxTask,
signed char *pcTaskName)
{
//Handle FreeRTOS Stack Overflow
while(1)
{
}
}
#endif //USE_FREERTOS
static void BoardInit(void) {
/* In case of TI-RTOS vector table is initialize by OS itself */
#ifndef USE_TIRTOS
//
// Set vector table base
//
#if defined(ccs) || defined(gcc)
MAP_IntVTableBaseSet((unsigned long)&g_pfnVectors[0]);
#endif
#if defined(ewarm)
MAP_IntVTableBaseSet((unsigned long)&__vector_table);
#endif
#endif
//
// Enable Processor
//
MAP_IntMasterEnable();
MAP_IntEnable(FAULT_SYSTICK);
PRCMCC3200MCUInit();
}
//Push Button handler task
void PushButtonHandler (void *pvParameters) {
while(1);
}
// Initialize LEDs
void LedInit() {
GPIO_IF_LedConfigure(LED1|LED2|LED3);
GPIO_IF_LedOff(MCU_ALL_LED_IND);
}
// SW2 handler, Increment Global variable
void SW2Handler() {
val--;
//TODO handle critical section
}
//SW3 handler, Decrement global variable
void SW3Handler() {
val++;
//TODO handle critical section
}
//Initialize buttons & interrupt
void ButtonInit() {
Button_IF_Init(SW2Handler,SW3Handler);
Button_IF_EnableInterrupt(SW2|SW3);
}
// main task to loop
void MainLoop(void *pvParameters) {
ButtonInit();
for(;;) {
if (val&1) {
GPIO_IF_LedOn(MCU_RED_LED_GPIO);
} else {
GPIO_IF_LedOff(MCU_RED_LED_GPIO);
}
if (val &(1<<1)) {
GPIO_IF_LedOn(MCU_ORANGE_LED_GPIO);
} else {
GPIO_IF_LedOff(MCU_ORANGE_LED_GPIO);
}
if (val & (1<<2)) {
GPIO_IF_LedOn(MCU_GREEN_LED_GPIO);
} else {
GPIO_IF_LedOff(MCU_GREEN_LED_GPIO);
}
}
}
int main() {
long lRetVal = -1;
val=0;
BoardInit();
PinMuxConfig();
LedInit();
//create OS tasks
lRetVal = osi_TaskCreate(PushButtonHandler,
(signed char*) "PushButtonHandler",
OSI_STACK_SIZE, NULL, 2, &g_PushButtonTask);
if(lRetVal < 0)
{
ERR_PRINT(lRetVal);
LOOP_FOREVER();
}
lRetVal = osi_TaskCreate(MainLoop, (signed char*)"MainLoop",
OSI_STACK_SIZE, NULL, 1, NULL );
if(lRetVal < 0)
{
ERR_PRINT(lRetVal);
LOOP_FOREVER();
}
osi_start();
for(;;) {
}
return 0;
}