summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorOmar Magdy <omar.professional8777@gmail.com>2022-08-22 14:03:01 +0200
committerOmar Magdy <omar.professional8777@gmail.com>2022-08-22 14:03:01 +0200
commit5aa3477c59aec1ebedf2a70d8aebfed0d9d23a77 (patch)
treee37092cb435d7d51927daeb095504acf4c866ad0 /main.c
parentfe2d03c9c7997d647ffb0b2856e766d54090e419 (diff)
downloadTraffic-light-5aa3477c59aec1ebedf2a70d8aebfed0d9d23a77.tar.xz
Traffic-light-5aa3477c59aec1ebedf2a70d8aebfed0d9d23a77.zip
Added initial code + Made the led stay green for 5 seconds then yellow for 2 seconds then red
Diffstat (limited to 'main.c')
-rw-r--r--main.c69
1 files changed, 45 insertions, 24 deletions
diff --git a/main.c b/main.c
index c076e22..7dbc47a 100644
--- a/main.c
+++ b/main.c
@@ -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();
}