EE445M RTOS
Taken at the University of Texas Spring 2015
test-debounce.c
Go to the documentation of this file.
1 /* -*- mode: c; c-basic-offset: 4; -*- */
2 /* Created by Hershal Bhave and Eric Crosson on 2015-01-24 */
3 /* Revision History: Look in Git FGT */
4 
5 /* Standard Libs */
6 #include <stdint.h>
7 #include <stdbool.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 
11 /* TI Includes */
12 #include "inc/hw_ints.h"
13 #include "inc/hw_gpio.h"
14 #include "inc/hw_memmap.h"
15 
16 /* Driverlib Includes */
17 #include "driverlib/debug.h"
18 #include "driverlib/gpio.h"
19 #include "driverlib/interrupt.h"
20 #include "driverlib/pin_map.h"
21 #include "driverlib/sysctl.h"
22 #include "driverlib/systick.h"
23 #include "driverlib/timer.h"
24 #include "driverlib/adc.h"
25 
26 #define HEARTBEAT_MODAL
27 
28 #include "libos/os.h"
29 #include "libos/jitter.h"
30 #include "libheart/heartbeat.h"
31 #include "libbutton/button.h"
32 #include "libtimer/timer.h"
33 #include "libhw/hardware.h"
34 #include "libos/semaphore.h"
35 /* #include "libdisplay/ST7735.h" */
36 #include "libadc/adc.h"
37 #include "libuart/uart.h"
38 #include "libshell/shell.h"
39 
40 volatile uint32_t button_left_pressed;
41 volatile uint32_t button_right_pressed;
42 
43 volatile uint32_t button_debounced_mailbox;
44 volatile uint32_t button_debounced_wtf;
45 
47 
48 uint32_t red_work = 0;
49 uint32_t blue_work = 0;
50 uint32_t green_work = 0;
51 
52 void button_debounce_end(notification button_notification) {
53 
56 }
57 
58 /* what the btn handler calls */
59 void button_debounce_start(notification button_notification) {
60 
63  hw_channel_init(HW_TIMER, timer_metadata);
64  hw_subscribe_single_shot(HW_TIMER, timer_metadata,
66 }
67 
68 void led_blink_red() {
69  while (1) {
70  ++red_work;
74  }
75 }
76 
78  /* while (1) { */
79  ++green_work;
82  /* os_surrender_context(); */
83  /* } */
84 }
85 
87  /* while (1) { */
88  ++blue_work;
91  /* os_surrender_context(); */
92  /* } */
93 }
94 
96 
97  while (1) {
101  led_blink_blue();
103  }
105  led_blink_green();
107  }
108  }
109  }
110 }
111 
112 int main() {
113 
116 
118 
119  /* begin heartbeat init */
120  heart_init();
121  heart_init_(GPIO_PORTF_BASE, GPIO_PIN_1);
122  heart_init_(GPIO_PORTF_BASE, GPIO_PIN_2);
123  heart_init_(GPIO_PORTF_BASE, GPIO_PIN_3);
124  /* end heartbeat init */
125 
126  /* begin timer init */
128  hw_driver_init(HW_TIMER, timer_metadata);
129  /* end timer init */
130 
131  /* button init */
136 
138 
139  hw_init(HW_BUTTON, button_metadata);
140  hw_subscribe(HW_BUTTON, button_metadata, button_debounce_start);
141  /* end button init */
142 
145 
146  IntMasterEnable();
147  os_launch();
148 
149  while (1) {}
150 }
#define TIMER_CFG_ONE_SHOT
Definition: timer.h:59
#define TIMER0_BASE
Definition: hw_memmap.h:81
#define button_metadata_init(_base, _pin, _interrupt)
Definition: button.h:23
#define hw_subscribe_single_shot(type, metadata, isr)
Definition: hardware.h:190
void GPIOPinWrite(uint32_t ui32Port, uint8_t ui8Pins, uint8_t ui8Val)
Definition: gpio.c:1038
#define GPIO_BOTH_EDGES
Definition: gpio.h:87
int8_t semaphore_t
#define sem_post(sem)
#define SYSCTL_OSC_MAIN
Definition: sysctl.h:378
#define hw_subscribe(type, metadata, isr)
Definition: hardware.h:178
#define SYSCTL_USE_OSC
Definition: sysctl.h:350
volatile uint32_t button_right_pressed
Definition: test-debounce.c:41
#define GPIO_PIN_2
Definition: gpio.h:62
volatile uint32_t button_left_pressed
Definition: test-debounce.c:40
int main()
#define SYSCTL_XTAL_16MHZ
Definition: sysctl.h:372
#define hw_init(type, metadata)
Definition: hardware.h:143
#define GPIO_PIN_1
Definition: gpio.h:61
void os_threading_init()
Definition: os.c:34
uint32_t blue_work
Definition: test-debounce.c:49
void schedule(task_t task, frequency_t frequency, DEADLINE_TYPE seriousness)
Definition: os.c:386
volatile uint32_t button_debounced_wtf
Definition: test-debounce.c:44
void led_blink_red()
Definition: test-debounce.c:68
void postpone_suicide()
Definition: test-debounce.c:95
#define BUTTONS_BOTH
Definition: button.h:28
#define sem_take(sem)
void heart_init()
Initialize for visible transformation.
Definition: heartbeat.h:49
uint32_t green_work
Definition: test-debounce.c:50
void os_launch()
Definition: os.c:161
void hw_driver_init(HW_TYPE type, hw_metadata metadata)
Definition: hardware.c:62
volatile semaphore_t button_debounced_new_data
Definition: test-debounce.c:46
bool IntMasterDisable(void)
Definition: interrupt.c:249
#define BUTTON_LEFT
Definition: button.h:26
#define GPIO_PIN_3
Definition: gpio.h:63
bool IntMasterEnable(void)
#define BUTTON_RIGHT
Definition: button.h:27
void button_debounce_start(notification button_notification)
Definition: test-debounce.c:59
#define sem_guard(sem)
volatile uint32_t button_debounced_mailbox
Definition: test-debounce.c:43
void led_blink_blue()
Definition: test-debounce.c:86
#define timer_metadata_init(_base, _frequency, _interrupt, _periodic)
Definition: timer.h:21
#define os_surrender_context()
Definition: os.h:142
#define Hz
Definition: nexus.h:45
void button_debounce_end(notification button_notification)
Definition: test-debounce.c:52
#define SYSCTL_SYSDIV_1
Definition: sysctl.h:221
void SysCtlClockSet(uint32_t ui32Config)
Definition: sysctl.c:2532
void hw_channel_init(HW_TYPE type, hw_metadata metadata)
Definition: hardware.c:94
int32_t GPIOPinRead(uint32_t ui32Port, uint8_t ui8Pins)
Definition: gpio.c:1006
#define INT_TIMER0A
Definition: hw_ints.h:435
#define sem_init(sem)
void led_blink_green()
Definition: test-debounce.c:77
uint32_t red_work
Definition: test-debounce.c:48
#define GPIO_PORTF_BASE
Definition: hw_memmap.h:74