-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinterface.c
More file actions
218 lines (185 loc) · 5.44 KB
/
Copy pathinterface.c
File metadata and controls
218 lines (185 loc) · 5.44 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
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
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
//#include "inc/hw_hibernate.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
//#include "driverlib/hibernate.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/systick.h"
#include "driverlib/uart.h"
#include "utils/ustdlib.h"
#include "utils/uartstdio.h"
#include "utils/cmdline.h"
#include "drivers/rgb.h"
#include "drivers/buttons.h"
#include "interface.h"
#include "aes.h"
#include "driverlib/i2c.h"
#include "eeprom_24lc08b.h"
#include "commands.h"
//*****************************************************************************
//
// Version Information
//
//*****************************************************************************
const char g_chVersion[] = "0.1";
const char g_chName[] = "sim_ied";
const char g_chVendor[] = "ControlThings I/O";
const char g_chWebsite[] = "https://controlthings.io";
const char g_chAuthor[] = "Don C. Weber (cutaway)";
const char g_chContact[] = "don@cutawaysecurity.com";
//*****************************************************************************
//
// Input buffer for the command line interpreter.
//
//*****************************************************************************
static char g_cInput[APP_INPUT_BUF_SIZE];
//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
//*****************************************************************************
//
// Called by the NVIC as a result of SysTick Timer rollover interrupt flag
//
// Do something here.
//
//*****************************************************************************
void
SysTickIntHandler(void)
{
/*
Reference: https://codeblooms.com/how-to-use-systick-timer-in-tiva-c/
*/
}
//*****************************************************************************
//
// Configure the UART and its pins. This must be called before UARTprintf().
//
//*****************************************************************************
void
ConfigureUART(void)
{
//
// Enable the GPIO Peripheral used by the UART.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//
// Enable UART0
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
//
// Configure GPIO Pins for UART mode.
//
ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
//
// Use the internal 16MHz oscillator as the UART clock source.
//
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
//
// Initialize the UART for console I/O.
//
UARTStdioConfig(0, 115200, 16000000);
}
/**
* main.c
*/
int main(void)
{
//uint32_t ui32Status;
//uint32_t ui32ResetCause;
int32_t i32CommandStatus;
//
// Enable stacking for interrupt handlers. This allows floating-point
// instructions to be used within interrupt handlers, but at the expense of
// extra stack usage.
//
ROM_FPUEnable();
ROM_FPUStackingEnable();
//
// Set the system clock to run at 40Mhz off PLL with external crystal as
// reference.
//
ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
SYSCTL_OSC_MAIN);
//
// Enable and Initialize the UART.
//
ConfigureUART();
//ConfigureI2C1();
ROM_ConfigureI2C1();
//
// Setup EEPROM - this will test to see if the password has been written to
// to the EEPROM. If no password, then reset all EEPROM data.
#ifdef USE_EEPROM
setEEPROMData();
#endif
UARTprintf("\n\nControl Things IED Interface!\n");
//UARTprintf("Type 'help' for a list of commands\n");
//UARTprintf("> ");
//
// spin forever and wait for carriage returns or state changes.
//
while(1)
{
UARTprintf("\n> ");
//
// Peek to see if a full command is ready for processing
//
while(UARTPeek('\r') == -1)
{
//
// millisecond delay. A SysCtlSleep() here would also be OK.
//
SysCtlDelay(SysCtlClockGet() / (1000 / 3));
}
//
// a '\r' was detected get the line of text from the user.
//
UARTgets(g_cInput,sizeof(g_cInput));
//
// Pass the line from the user to the command processor.
// It will be parsed and valid commands executed.
//
i32CommandStatus = CmdLineProcess(g_cInput);
//
// Handle the case of bad command.
//
if(i32CommandStatus == CMDLINE_BAD_CMD)
{
//UARTprintf("Bad command!\n");
UARTprintf("\n\nControl Things IED Interface!\n");
}
//
// Handle the case of too many arguments.
//
else if(i32CommandStatus == CMDLINE_TOO_MANY_ARGS)
{
UARTprintf("Too many arguments for command processor!\n");
}
//
// Echo input back to user
//
//UARTprintf("Thank you for playing: ");
//UARTprintf("%s\n",g_cInput);
}
return 0;
}