summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorOmar Magdy <omar.professional8777@gmail.com>2022-08-23 21:19:38 +0200
committerOmar Magdy <omar.professional8777@gmail.com>2022-08-23 21:19:38 +0200
commiteac8a1b2ee3761ed3107587b36c10c1e26f9d59f (patch)
tree17d3ac75ae58821afe298383ad3a43647aabb781 /main.c
parent291bed5067c1eac811f041c056130135725c8148 (diff)
downloadTraffic-light-eac8a1b2ee3761ed3107587b36c10c1e26f9d59f.tar.xz
Traffic-light-eac8a1b2ee3761ed3107587b36c10c1e26f9d59f.zip
Added switch_handler() function which allows the pedestrian to make the
other traffic lights red and his green and at the same time when his light turns red the other continue where they left off + Moved all code to trafficlight.c and made the main less clutered
Diffstat (limited to 'main.c')
-rw-r--r--main.c86
1 files changed, 5 insertions, 81 deletions
diff --git a/main.c b/main.c
index cf3c931..bf8916d 100644
--- a/main.c
+++ b/main.c
@@ -3,90 +3,14 @@
uint32_t period_1 = RED_PERIOD;
uint32_t period_2 = GREEN_PERIOD;
uint32_t period_3 = RED_PERIOD;
+bool switch_pressed = false;
-Traffic tf1 = {RED , GPIO_PORTF_BASE, 1, 2, 3, 0};
-Traffic tf2 = {YELLOW, GPIO_PORTA_BASE, 2, 3, 4, 0};
-Traffic tf_ped = {RED , GPIO_PORTB_BASE, 5, 0, 1, 0};
-
-void Switch_Handler() {
-
-}
-
-void Timer0_Handler() {
- TimerIntClear(TIMER0_BASE, TIMER_BOTH);
- switch(tf1.cur_color) {
- case RED:
- tf1.cur_color = GREEN;
- set_tf_color(tf1, GREEN);
- TimerLoadSet(TIMER0_BASE, TIMER_BOTH, GREEN_PERIOD);
- break;
- case YELLOW:
- tf1.cur_color = RED;
- set_tf_color(tf1, RED);
- TimerLoadSet(TIMER0_BASE, TIMER_BOTH, RED_PERIOD);
- break;
- case GREEN:
- tf1.cur_color = YELLOW;
- set_tf_color(tf1, YELLOW);
- TimerLoadSet(TIMER0_BASE, TIMER_BOTH, YELLOW_PERIOD);
- break;
- }
-}
-
-void Timer1_Handler() {
- TimerIntClear(TIMER1_BASE, TIMER_BOTH);
- switch(tf2.cur_color) {
- case RED:
- tf2.cur_color = GREEN;
- set_tf_color(tf2, GREEN);
- TimerLoadSet(TIMER1_BASE, TIMER_BOTH, GREEN_PERIOD);
- break;
- case YELLOW:
- tf2.cur_color = RED;
- set_tf_color(tf2, RED);
- TimerLoadSet(TIMER1_BASE, TIMER_BOTH, RED_PERIOD);
- break;
- case GREEN:
- tf2.cur_color = YELLOW;
- set_tf_color(tf2, YELLOW);
- TimerLoadSet(TIMER1_BASE, TIMER_BOTH, YELLOW_PERIOD);
- break;
- }
-}
-
-void Timer2_Handler() {
- TimerIntClear(TIMER2_BASE, TIMER_BOTH);
- switch(tf_ped.cur_color) {
- case RED:
- tf_ped.cur_color = GREEN;
- set_tf_color(tf_ped, GREEN);
- TimerLoadSet(TIMER2_BASE, TIMER_BOTH, GREEN_PERIOD);
- break;
- case YELLOW:
- tf_ped.cur_color = RED;
- set_tf_color(tf_ped, RED);
- TimerLoadSet(TIMER2_BASE, TIMER_BOTH, RED_PERIOD);
- break;
- case GREEN:
- tf_ped.cur_color = YELLOW;
- set_tf_color(tf_ped, YELLOW);
- TimerLoadSet(TIMER2_BASE, TIMER_BOTH, YELLOW_PERIOD);
- break;
- }
-}
+Traffic tf1 = {YELLOW, GPIO_PORTA_BASE, 2, 3, 4, 0};
+Traffic tf2 = {RED , GPIO_PORTF_BASE, 1, 2, 3, 0};
+Traffic tf_ped = {RED , GPIO_PORTB_BASE, 5, 4, 1, 0};
int main()
{
- PortInit(GPIO_PORTF_BASE, SYSCTL_PERIPH_GPIOF); // Initialize portf
- PortInit(GPIO_PORTA_BASE, SYSCTL_PERIPH_GPIOA); // Initialize porta
- PortInit(GPIO_PORTB_BASE, SYSCTL_PERIPH_GPIOB); // Initialize portb
- __asm("CPSID I"); // Disable all interrupts
- TimerInit(TIMER0_BASE, Timer0_Handler, SYSCTL_PERIPH_TIMER0, period_1); // Intialize Timer0 with period_1
- TimerInit(TIMER1_BASE, Timer1_Handler, SYSCTL_PERIPH_TIMER1, period_2); // Intialize Timer1 with period_2
- TimerInit(TIMER2_BASE, Timer2_Handler, SYSCTL_PERIPH_TIMER2, period_3); // Intialize Timer1 with period_2
- __asm("CPSIE I"); // Enable all interrupts
- while(1) {
- __asm("wfi"); // power saving mode
- }
+ TrafficInit();
}