/
main.c
269 lines (238 loc) · 7.59 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
//Nguyen Ngo
//Section A03
// 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"
#include "uart.h"
#include "uart_if.h"
// Common interface includes
#include "gpio_if.h"
#include "pin_mux_config.h"
#define APPLICATION_VERSION "1.1.1"
//*****************************************************************************
// GLOBAL VARIABLES -- Start
//*****************************************************************************
#if defined(ccs)
extern void (* const g_pfnVectors[])(void);
#endif
#if defined(ewarm)
extern uVectorEntry __vector_table;
#endif
int g_bCount = 0;
//*****************************************************************************
// GLOBAL VARIABLES -- End
//*****************************************************************************
//*****************************************************************************
// LOCAL FUNCTION PROTOTYPES
//*****************************************************************************
void LEDBlinkyRoutine();
static void BoardInit(void);
//*****************************************************************************
// LOCAL FUNCTION DEFINITIONS
//*****************************************************************************
//*****************************************************************************
//
//! Configures the pins as GPIOs and peroidically toggles the lines
//!
//! \param None
//!
//! This function
//! 1. Configures 3 lines connected to LEDs as GPIO
//! 2. Sets up the GPIO pins as output
//! 3. Periodically toggles each LED one by one by toggling the GPIO line
//!
//! \return None
//
//*****************************************************************************
void LEDBlinkyRoutine()
{
//
// Toggle the lines initially to turn off the LEDs.
// The values driven are as required by the LEDs on the LP.
//
GPIO_IF_LedOff(MCU_ALL_LED_IND);
//setting initial state
int state = 0;
while(1){
switch(state){
case 0:
//set Pin 18 output low
GPIOPinWrite(GPIOA3_BASE, 0x10, 0x00);
//turn on green led
GPIO_IF_LedOn(MCU_GREEN_LED_GPIO);
if(!GPIOPinRead(GPIOA1_BASE, 0x20) && GPIOPinRead(GPIOA2_BASE, 0x40)){
//sw3 not pressed, sw2 pressed
state = 1;
}else if(GPIOPinRead(GPIOA1_BASE, 0x20) && GPIOPinRead(GPIOA2_BASE, 0x40)){
//sw3 pressed and sw2 pressed
state = 4;
}else if(GPIOPinRead(GPIOA1_BASE, 0x20) && !GPIOPinRead(GPIOA2_BASE, 0x40)){
//sw3 pressed and sw2 not pressed
state = 4;
}
break;
case 1:
//set Pin 18 output low
GPIOPinWrite(GPIOA3_BASE, 0x10, 0x00);
//turn off green led
GPIO_IF_LedOff(MCU_GREEN_LED_GPIO);
//turn on orange led
GPIO_IF_LedOn(MCU_ORANGE_LED_GPIO);
if(GPIOPinRead(GPIOA1_BASE, 0x20) && GPIOPinRead(GPIOA2_BASE, 0x40)) {
//sw3 pressed and sw2 pressed
state = 2;
}else if(!GPIOPinRead(GPIOA1_BASE, 0x20) && !GPIOPinRead(GPIOA2_BASE, 0x40)){
//sw3 not pressed and sw2 not pressed
state = 4;
}else if(GPIOPinRead(GPIOA1_BASE, 0x20) && !GPIOPinRead(GPIOA2_BASE, 0x40)){
//sw3 pressed and sw2 not pressed
state = 4;
}
break;
case 2:
//set Pin 18 output low
GPIOPinWrite(GPIOA3_BASE, 0x10, 0x00);
//turn on green led
GPIO_IF_LedOn(MCU_GREEN_LED_GPIO);
if(GPIOPinRead(GPIOA1_BASE, 0x20) && !GPIOPinRead(GPIOA2_BASE, 0x40)){
//sw3 pressed, sw2 not pressed
state = 3;
}else if(!GPIOPinRead(GPIOA1_BASE, 0x20) && !GPIOPinRead(GPIOA2_BASE, 0x40)){
//sw3 not pressed, sw2 not presed
state = 4;
}else if(!GPIOPinRead(GPIOA1_BASE, 0x20) && GPIOPinRead(GPIOA2_BASE, 0x40)){
//sw3 not pressed, sw2 pressed
state = 4;
}
break;
case 3:
//turn on red led
GPIO_IF_LedOn(MCU_RED_LED_GPIO);
//toggles pin 18 at rate of about 5 hz
//MAP_UtilsDelay
//param ulCount in MAP_UtilsDelay is the number of delay loop iterations to perform.
//The loop takes 3 cycles/loop from ROM, and 5 cycles/loop from RAM
//rate of 5 hz = 5 blinks per sec
//clock tick is at 80MHz
//1 sec = 16000000. So .2 sec = 3200000
//dividing by 2 for on and off = 1600000
while(1){
MAP_UtilsDelay(1600000);
GPIOPinWrite(GPIOA3_BASE, 0x10, 0xFF);
MAP_UtilsDelay(1600000);
GPIOPinWrite(GPIOA3_BASE, 0x10, 0x00);
}
//break;
case 4:
//set Pin 18 output low
GPIOPinWrite(GPIOA3_BASE, 0x10, 0x00);
//set all led lights on
GPIO_IF_LedOff(MCU_GREEN_LED_GPIO);
GPIO_IF_LedOff(MCU_ORANGE_LED_GPIO);
GPIO_IF_LedOn(MCU_RED_LED_GPIO);
break;
}
}
}
//*****************************************************************************
//
//! Board Initialization & Configuration
//!
//! \param None
//!
//! \return None
//
//*****************************************************************************
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)
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();
}
DisplayBanner(char * AppName)
{
Report("\n\n\n\r");
Report("\t\t *************************************************\n\r");
Report("\t\t CC3200 %s Application \n\r", AppName);
Report("\t\t *************************************************\n\r");
Report("\n\n\n\r");
}
//****************************************************************************
//
//! Main function
//!
//! \param none
//!
//! This function
//! 1. Invokes the LEDBlinkyTask
//!
//! \return None.
//
//****************************************************************************
int
main()
{
//
// Initialize Board configurations
//
BoardInit();
//
// Power on the corresponding GPIO port B for 9,10,11.
// Set up the GPIO lines to mode 0 (GPIO)
//
PinMuxConfig();
#ifndef NOTERM
//
// Configuring UART
//
InitTerm();
#endif
DisplayBanner("Lab 0");
Message("\t\t****************************************************\n\r");
Message("\t\t\t CC3200 UART Echo Usage \n\r");
Message("\t\t To get to state 3, the user must press and hold SW2 \n\r");
Message("\t\t then press SW3 without releasing SW2 \n\r");
Message("\t\t and then release SW2 while continuing to press SW3\n\r");
Message("\n\n\n\r");
GPIO_IF_LedConfigure(LED1|LED2|LED3);
GPIO_IF_LedOff(MCU_ALL_LED_IND);
//
// Start the LEDBlinkyRoutine
//
LEDBlinkyRoutine();
return 0;
}
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************