-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactory_Controller.c
More file actions
170 lines (139 loc) · 3.56 KB
/
Factory_Controller.c
File metadata and controls
170 lines (139 loc) · 3.56 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
#include <stdbool.h>
#include <stdint.h>
#include <time.h>
#include <string.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#include "utils/ustdlib.h"
#include "inc/hw_hibernate.h"
#include "driverlib/hibernate.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "semphr.h"
#include "rtc.h"
#include "outlet.h"
//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
//*****************************************************************************
//
// This hook is called by FreeRTOS when a stack overflow error is detected.
//
//*****************************************************************************
void
vApplicationStackOverflowHook( xTaskHandle *pxTask, char *pcTaskName )
{
//
// This function can not return, so loop forever. Interrupts are disabled
// on entry to this function, so no processor interrupts will interrupt
// this loop.
//
while(1)
{
}
}
//*****************************************************************************
//
// 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);
}
int
main(void)
{
struct tm calendar;
Outlet_Schedule_t Schedule;
char buffer[20];
//
// Set the clocking to run at 80 MHz from the PLL.
//
SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
//
// Initialize the UART.
//
ConfigureUART();
Outlet_Init();
Rtc_Init();
calendar.tm_hour = 15;
calendar.tm_min = 32;
calendar.tm_sec = 0;
calendar.tm_mday = 27;
calendar.tm_mon = 3-1;
calendar.tm_year = 2017 - 1900;
//
// preset test schedule
//
Schedule.hrOn = 15;
Schedule.minOn = 32;
Schedule.hrOff = 15;
Schedule.minOff = 34;
// load the hibernation counter register with the values set in calendar
Rtc_SetDate( &calendar );
Outlet_Set_Schedule( 0, &Schedule );
while(1)
{
Outlet_Check_Schedule();
//Get date from register
Rtc_GetDate( &calendar );
//Convert decimal time to ascii format
strftime( buffer, 32, "%X %x\n", &calendar );
//Display date and time
UARTprintf("%s", buffer);
//Display outlet status
int i;
for(i=0;i<OUTLET_SIZE;++i)
{
if( Outlet_Get_Status(i) )
{
UARTprintf("ON ");
}
else
{
UARTprintf("OFF ");
}
}
UARTprintf("\n\n");
//Delay 1 second
SysCtlDelay( SysCtlClockGet() / 6 );
}
}