diff options
| -rw-r--r-- | color.c | 6 | ||||
| -rw-r--r-- | color.h | 3 | ||||
| -rw-r--r-- | main.c | 69 | ||||
| -rw-r--r-- | tivaware.h | 1 |
4 files changed, 52 insertions, 27 deletions
@@ -1,9 +1,6 @@ #include "color.h"
#include <stdint.h>
-#define LED_RED (1U << 1)
-#define LED_BLUE (1U << 2)
-#define LED_GREEN (1U << 3)
void set_color(uint8_t color) {
switch (color) {
@@ -16,6 +13,9 @@ void set_color(uint8_t color) { case GREEN:
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 0x8);
break;
+ case YELLOW:
+ GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 0xA);
+ break;
case WHITE:
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 0xe);
break;
@@ -1,6 +1,9 @@ #include "tivaware.h"
+#define LED_RED (1U << 1)
+#define LED_BLUE (1U << 2)
+#define LED_GREEN (1U << 3)
#define PORTF GPIO_PORTF_DATA_R
#define INTIAL_COLOR WHITE
#define RED 1
@@ -1,8 +1,37 @@ #include "color.h"
-#include "systick.h"
#include "stdio.h"
+#include <stdint.h>
-int cnt = 0;
+int cnt = 1;
+#define GREEN_PERIOD 80000000
+#define YELLOW_PERIOD 48000000
+#define RED_PERIOD 16000000
+uint8_t cur_color = GREEN;
+uint32_t period = GREEN_PERIOD;
+
+
+
+
+void Timer0_Handler() {
+ TimerIntClear(TIMER0_BASE, TIMER_BOTH);
+ switch(cur_color) {
+ case RED:
+ cur_color = GREEN;
+ set_color(cur_color);
+ TimerLoadSet(TIMER0_BASE, TIMER_BOTH, GREEN_PERIOD);
+ break;
+ case YELLOW:
+ cur_color = RED;
+ set_color(cur_color);
+ TimerLoadSet(TIMER0_BASE, TIMER_BOTH, RED_PERIOD);
+ break;
+ case GREEN:
+ cur_color = YELLOW;
+ set_color(cur_color);
+ TimerLoadSet(TIMER0_BASE, TIMER_BOTH, YELLOW_PERIOD);
+ break;
+ }
+}
void portFInit() {
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
@@ -13,34 +42,26 @@ void portFInit() { GPIOPadConfigSet (GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4,
GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);
}
-
-void toggle_white() {
- if((GPIO_PORTF_DATA_R & 0xe) == 0xe) {
- reset_color();
- } else {
- set_color(WHITE);
- }
-}
-
-void SysTick_Handler() {
- cnt++;
- if(cnt % 5 == 0) {
- toggle_color(WHITE);
- }
-}
-
-void toggle_interrupts() {
+void traffic_delay() {
portFInit();
- SysTickDisable();
- SysTickPeriodSet(PERIOD);
- SysTickIntEnable();
- SysTickEnable();
+ reset_color();
+ SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
+ while(!SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER0)) {}
+ TimerDisable(TIMER0_BASE, TIMER_BOTH);
+ TimerConfigure(TIMER0_BASE, (TIMER_CFG_PERIODIC));
+ TimerLoadSet(TIMER0_BASE, TIMER_BOTH, period);
+ TimerIntUnregister(TIMER0_BASE, TIMER_BOTH);
+ TimerEnable(TIMER0_BASE, TIMER_BOTH);
+ set_color(GREEN);
+ TimerIntRegister(TIMER0_BASE, TIMER_BOTH, (*Timer0_Handler));
+ TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT | TIMER_TIMB_TIMEOUT);
while(1) {
}
+
}
int main()
{
- toggle_interrupts();
+ traffic_delay();
}
@@ -6,6 +6,7 @@ #include "../../ti/TivaWare_C_Series-2.2.0.295/driverlib/gpio.h" #include "../../ti/TivaWare_C_Series-2.2.0.295/driverlib/sysctl.h" #include "../../ti/TivaWare_C_Series-2.2.0.295/driverlib/systick.h" +#include "../../ti/TivaWare_C_Series-2.2.0.295/driverlib/timer.h" #define RIGHT_SWITCH !(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0) != 0) #define LEFT_SWITCH !(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_4) != 0) |
