EE445M RTOS
Taken at the University of Texas Spring 2015
test-ping.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset: 4; */
2 /* Created by Hershal Bhave and Eric Crosson on <2015-03-15 Sun> */
3 /* Revision History: Look in Git FGT */
4 
5 #include "../common/adcpp.hpp"
6 #include "../common/blinker.hpp"
7 #include "../common/uartpp.hpp"
8 #include "../common/shellpp.hpp"
9 #include "../common/semaphorepp.hpp"
10 #include "../common/motorpp.hpp"
11 #include "../common/drivepp.hpp"
12 #include "../common/canpp.hpp"
13 #include "../common/ctlsysctl.hpp"
14 #include "../common/switchpp.hpp"
15 #include "../common/pingpp.hpp"
16 
17 #include "libos/os.h"
18 #include "libschedule/schedule.h"
19 
20 #include <stdint.h>
21 #include <stdlib.h>
22 #include <stdbool.h>
23 
24 #include "inc/hw_memmap.h"
25 
26 #include "driverlib/adc.h"
27 #include "driverlib/sysctl.h"
28 #include "driverlib/gpio.h"
29 #include "driverlib/interrupt.h"
30 #include "driverlib/uart.h"
31 
36 
37 #define UART0_RX_BUFFER_SIZE 8
40 
41 void ping_handler() {
42 
43  ping0.start();
44 
45  while(1){
46  if (ping0_sem->guard()) {
47  ping0.sample();
48  uart0.printf("ping: %u\n", ping0.average());
49  }
50  os_surrender_context();
51  }
52 }
53 
54 int main(void) {
55 
57  IntMasterDisable();
58 
60  uart0 = uart(UART0_BASE, INT_UART0);
61 
62  blink = blinker(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
63  ping0 = ping(GPIO_PORTD_BASE, GPIO_PIN_3, 1, TIMER_A);
64  ping0_sem = ping0.get_sem();
65 
66  os_threading_init();
67  schedule(ping_handler, 200);
68  os_launch();
69 }
70 
71 extern "C" void Timer1A_Handler() {
72  ping0.handle_timer();
73 }
74 
75 extern "C" void GPIOPortD_Handler() {
76  ping0.handle_gpio();
77 }
78 
79 extern "C" void __cxa_pure_virtual() { while (1) {} }
semaphore * get_sem(void)
Definition: pingpp.cpp:130
uart uart0
Definition: test-ping.cpp:33
void __cxa_pure_virtual()
Definition: test-ping.cpp:79
void GPIOPortD_Handler()
Definition: test-ping.cpp:75
Definition: uartpp.hpp:28
bool guard(void)
Definition: semaphorepp.cpp:57
ping ping0
Definition: test-ping.cpp:34
int main(void)
Definition: test-ping.cpp:54
void printf(const char *pcString,...)
Definition: uartpp.cpp:360
int32_t average(void)
Definition: pingpp.cpp:135
void Timer1A_Handler()
Definition: test-ping.cpp:71
void sample(void)
Definition: pingpp.cpp:45
static semaphore UART0_RX_SEM
Definition: test-ping.cpp:38
static void set_clock(void)
Definition: ctlsysctl.hpp:109
static buffer< char, 8 > UART0_RX_BUFFER
Definition: test-ping.cpp:39
uint32_t handle_timer(void)
Definition: pingpp.cpp:85
Definition: pingpp.hpp:28
semaphore * ping0_sem
Definition: test-ping.cpp:35
void ping_handler()
Definition: test-ping.cpp:41
virtual void start(void)
Definition: pingpp.cpp:74
uint32_t handle_gpio(void)
Definition: pingpp.cpp:107
blinker blink
Definition: test-ping.cpp:32