EE445M RTOS
Taken at the University of Texas Spring 2015
move-main.cpp File Reference
#include "adcpp.hpp"
#include "blinker.hpp"
#include "uartpp.hpp"
#include "shellpp.hpp"
#include "semaphorepp.hpp"
#include "motorpp.hpp"
#include "drivepp.hpp"
#include "canpp.hpp"
#include "ctlsysctl.hpp"
#include "switchpp.hpp"
#include "libos/os.h"
#include "libschedule/schedule.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "driverlib/adc.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/uart.h"
#include "driverlib/pwm.h"
Include dependency graph for move-main.cpp:

Go to the source code of this file.

Macros

#define thread(x)
 
#define can_data_length   10
 
#define UART0_RX_BUFFER_SIZE   8
 
#define BLINK_RED_WAIT_FOR_SEM   1
 
#define BLINK_BLUE_WAIT_FOR_SEM   1
 
#define BLINK_GREEN_WAIT_FOR_SEM   1
 

Functions

void thread_blink_red ()
 
void thread_blink_blue ()
 
void thread_blink_green ()
 
void thread_uart_update ()
 
void __cxa_pure_virtual ()
 
void UART0_Handler (void)
 
void CAN0_Handler (void)
 
void GPIOPortE_Handler ()
 
void switch_responder ()
 
void can_handler (void)
 
void shell_handler ()
 
void motor_control (void)
 
void Timer1A_Handler ()
 
void Timer0A_Handler ()
 
void driver (void)
 
int main (void)
 

Variables

blinker blink
 
uart uart0
 
shell shell0
 
uint16_t sens_ir_left
 
uint16_t sens_ir_left_front
 
uint16_t sens_ir_right
 
uint16_t sens_ir_right_front
 
uint16_t sens_ping_front
 
lswitch switch0
 
semaphore sem_switch
 
timer countdown_timer
 
semaphore motor_start
 
semaphore motor_stop
 
motor motor0
 
motor motor1
 
drive drive0
 
const uint32_t can_msg_id = 1
 
const bool can_sender = false
 
can can0
 
uint8_t can_data [10]
 
static semaphore UART0_RX_SEM
 
static buffer< char, 8 > UART0_RX_BUFFER
 
uint32_t blink_count_red = 0
 
uint32_t blink_count_green = 0
 
uint32_t blink_count_blue = 0
 
semaphore sem_blink_red
 
semaphore sem_blink_blue
 
semaphore sem_blink_green
 

Macro Definition Documentation

#define BLINK_BLUE_WAIT_FOR_SEM   1

Definition at line 75 of file move-main.cpp.

#define BLINK_GREEN_WAIT_FOR_SEM   1

Definition at line 76 of file move-main.cpp.

#define BLINK_RED_WAIT_FOR_SEM   1

Definition at line 74 of file move-main.cpp.

#define can_data_length   10

Definition at line 56 of file move-main.cpp.

Referenced by main().

#define thread (   x)
Value:
do { \
x; \
os_surrender_context(); \
} while(true)

Definition at line 32 of file move-main.cpp.

Referenced by thread_uart_update().

#define UART0_RX_BUFFER_SIZE   8

Definition at line 62 of file move-main.cpp.

Function Documentation

void __cxa_pure_virtual ( )

Definition at line 131 of file move-main.cpp.

131 { while (1) {} }
void CAN0_Handler ( void  )

Definition at line 164 of file move-main.cpp.

References can::ack(), can::error_tx(), semaphore::post(), and can::recv_sem.

164  {
165 
166  uint32_t message_id = can0.ack();
167 
168  switch(message_id) {
169  case 1:
170  can0.recv_sem.post();
171  break;
172  default:
173  can0.error_tx();
174  break;
175  }
176 }
can can0
Definition: move-main.cpp:59
void post(void)
Definition: semaphorepp.cpp:45
virtual uint32_t ack(void)
Definition: canpp.cpp:146
semaphore recv_sem
Definition: canpp.hpp:69
void error_tx(void)
Definition: canpp.cpp:97

Here is the call graph for this function:

void can_handler ( void  )

Definition at line 213 of file move-main.cpp.

References uart::atomic_printf(), can_data, can_msg_id, can::get(), semaphore::guard(), PIN_BLUE, can::recv_sem, sens_ir_left, sens_ir_left_front, sens_ir_right, sens_ir_right_front, sens_ping_front, and blinker::toggle().

Referenced by main().

213  {
214 
215  uint16_t can_msg_id;
216 
217  while(1) {
218  if(can0.recv_sem.guard()) {
219 
220  can0.get(can_data);
222 
223  can_msg_id = (can_data[1] << 8) | (can_data[0]);
224 
225  if (can_msg_id == 0) {
226  sens_ir_left = (can_data[3] << 8) | (can_data[2]);
227  sens_ir_left_front = (can_data[5] << 8) | (can_data[4]);
228  sens_ir_right = (can_data[7] << 8) | (can_data[4]);
229  } else {
230  sens_ir_right_front = (can_data[3] << 8) | (can_data[2]);
231  sens_ping_front = (can_data[5] << 8) | (can_data[4]);
232  }
233 
234  uart0.atomic_printf(" \r");
235  uart0.atomic_printf("l: %u lf: %u r: %u rf: %u pf: %u\r",
239 
240  /* uart0.atomic_printf("Received CAN data: %0X %0X %0X %0X %0X %0X %0X %0X \n", */
241  /* can_data[0], can_data[1], can_data[2], can_data[3], */
242  /* can_data[4], can_data[5], can_data[6], can_data[7]); */
243  }
244  os_surrender_context();
245  }
246 }
can can0
Definition: move-main.cpp:59
bool guard(void)
Definition: semaphorepp.cpp:57
void atomic_printf(const char *pcString,...)
Definition: uartpp.cpp:348
const pin_t PIN_BLUE
Definition: blinker.hpp:20
uint16_t sens_ir_left
Definition: move-main.cpp:42
semaphore recv_sem
Definition: canpp.hpp:69
uint16_t sens_ir_right_front
Definition: move-main.cpp:45
const uint32_t can_msg_id
Definition: move-main.cpp:57
uint16_t sens_ir_left_front
Definition: move-main.cpp:43
uint8_t can_data[10]
Definition: move-main.cpp:60
blinker blink
Definition: move-main.cpp:38
uint16_t sens_ping_front
Definition: move-main.cpp:46
virtual void toggle(pin_t pin)
Definition: blinker.cpp:34
uart uart0
Definition: move-main.cpp:39
void get(uint8_t *data)
Definition: canpp.cpp:102
uint16_t sens_ir_right
Definition: move-main.cpp:44

Here is the call graph for this function:

Here is the caller graph for this function:

void driver ( void  )

Definition at line 287 of file move-main.cpp.

References sens_ir_left, sens_ir_left_front, sens_ir_right, sens_ir_right_front, sens_ping_front, and drive::steer().

Referenced by main().

287  {
288 
289  while(1) {
292  os_surrender_context();
293  }
294 }
uint16_t sens_ir_left
Definition: move-main.cpp:42
void steer(uint32_t left_sens, uint32_t left_front_sens, uint32_t right_sens, uint32_t right_front_sens, uint32_t front_sens)
Definition: drivepp.cpp:50
uint16_t sens_ir_right_front
Definition: move-main.cpp:45
drive drive0
Definition: move-main.cpp:54
uint16_t sens_ir_left_front
Definition: move-main.cpp:43
uint16_t sens_ping_front
Definition: move-main.cpp:46
uint16_t sens_ir_right
Definition: move-main.cpp:44

Here is the call graph for this function:

Here is the caller graph for this function:

void GPIOPortE_Handler ( )

Definition at line 178 of file move-main.cpp.

References lswitch::ack(), and lswitch::debounce().

178  {
179 
180  switch0.ack();
181  switch0.debounce();
182 }
virtual uint32_t ack(void)
Definition: switchpp.cpp:83
lswitch switch0
Definition: move-main.cpp:48
void debounce(void)
Definition: switchpp.cpp:65

Here is the call graph for this function:

int main ( void  )

Definition at line 296 of file move-main.cpp.

References can_data_length, can_handler(), can_sender, driver(), motor_control(), ctlsys::set_clock(), shell_handler(), switch_responder(), thread_blink_blue(), thread_blink_green(), thread_blink_red(), and UART0_RX_SEM.

296  {
297 
299  IntMasterDisable();
300 
301  blink = blinker(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
302 
306 
308  uart0 = uart(UART0_BASE, INT_UART0);
309 
310  can0 = can(CAN0_BASE, INT_CAN0, can_sender, can_data_length);
311 
313  motor_stop = semaphore();
314  shell0 = shell(&uart0, &motor_start, &motor_stop);
315  motor0 = motor(GPIO_PORTA_BASE, GPIO_PIN_6, PWM0_BASE, PWM_GEN_0, PWM_OUT_0);
316  motor1 = motor(GPIO_PORTA_BASE, GPIO_PIN_7, PWM0_BASE, PWM_GEN_0, PWM_OUT_1);
317  drive0 = drive(&motor0, &motor1, 50);
318  countdown_timer = timer(0, TIMER_BOTH, TIMER_CFG_ONE_SHOT, SysCtlClockGet()*180,
319  TIMER_TIMA_TIMEOUT, true);
320  switch0 = lswitch(GPIO_PORTE_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3,
321  &sem_switch, 1, TIMER_A, GPIO_BOTH_EDGES,
322  INT_GPIOE_TM4C123, true);
323 
324  os_threading_init();
325  schedule(motor_control, 200);
326  schedule(thread_blink_red, 200);
327  schedule(thread_blink_blue, 200);
328  schedule(thread_blink_green, 200);
329  schedule(shell_handler, 200);
330  /* schedule(thread_uart_update, 200); */
331  schedule(switch_responder, 200);
332  schedule(driver, 200);
333  schedule(can_handler, 200);
334  os_launch();
335 }
can can0
Definition: move-main.cpp:59
static semaphore UART0_RX_SEM
Definition: move-main.cpp:63
Definition: uartpp.hpp:28
void thread_blink_red()
Definition: move-main.cpp:78
semaphore sem_blink_red
Definition: move-main.cpp:70
semaphore sem_blink_green
Definition: move-main.cpp:72
void can_handler(void)
Definition: move-main.cpp:213
void thread_blink_blue()
Definition: move-main.cpp:93
void switch_responder()
Definition: move-main.cpp:184
drive drive0
Definition: move-main.cpp:54
motor motor0
Definition: move-main.cpp:53
const bool can_sender
Definition: move-main.cpp:58
blinker blink
Definition: move-main.cpp:38
semaphore motor_start
Definition: move-main.cpp:52
static buffer< char, 8 > UART0_RX_BUFFER
Definition: move-main.cpp:64
void motor_control(void)
Definition: move-main.cpp:263
#define can_data_length
Definition: move-main.cpp:56
Definition: canpp.hpp:21
lswitch switch0
Definition: move-main.cpp:48
void driver(void)
Definition: move-main.cpp:287
motor motor1
Definition: move-main.cpp:53
semaphore sem_blink_blue
Definition: move-main.cpp:71
static void set_clock(void)
Definition: ctlsysctl.hpp:109
shell shell0
Definition: move-main.cpp:40
void thread_blink_green()
Definition: move-main.cpp:108
timer countdown_timer
Definition: move-main.cpp:50
semaphore sem_switch
Definition: move-main.cpp:49
semaphore motor_stop
Definition: move-main.cpp:52
void shell_handler()
Definition: move-main.cpp:248
uart uart0
Definition: move-main.cpp:39

Here is the call graph for this function:

void motor_control ( void  )

Allows motor control from shell

Definition at line 263 of file move-main.cpp.

References semaphore::guard(), drive::start(), and drive::stop().

Referenced by main().

263  {
264 
265  while(1) {
266  if(motor_start.guard()) {
267  drive0.start();
268  }
269  if(motor_stop.guard()) {
270  drive0.stop();
271  }
272  os_surrender_context();
273  }
274 }
bool guard(void)
Definition: semaphorepp.cpp:57
drive drive0
Definition: move-main.cpp:54
semaphore motor_start
Definition: move-main.cpp:52
void stop(void)
Definition: drivepp.cpp:20
void start(void)
Definition: drivepp.cpp:26
semaphore motor_stop
Definition: move-main.cpp:52

Here is the call graph for this function:

Here is the caller graph for this function:

void shell_handler ( )

Definition at line 248 of file move-main.cpp.

References shell::accept(), buffer< T, N >::get(), and semaphore::guard().

Referenced by main().

248  {
249 
250  while(1) {
251  if(UART0_RX_SEM.guard()) {
252 
253  bool ok;
254  char recv = UART0_RX_BUFFER.get(ok);
255 
256  if(ok) { shell0.accept(recv); }
257  }
258  os_surrender_context();
259  }
260 }
static semaphore UART0_RX_SEM
Definition: move-main.cpp:63
bool guard(void)
Definition: semaphorepp.cpp:57
static buffer< char, 8 > UART0_RX_BUFFER
Definition: move-main.cpp:64
void accept(char ch)
Definition: shellpp.cpp:174
shell shell0
Definition: move-main.cpp:40

Here is the call graph for this function:

Here is the caller graph for this function:

void switch_responder ( )

Definition at line 184 of file move-main.cpp.

References lswitch::debounced_data, semaphore::guard(), drive::reset_history(), and motor::reverse().

Referenced by main().

184  {
185 
186  const uint32_t counter_max = SysCtlClockGet()/25;
187  uint32_t pins, counter;
188  percent_t left_speed, right_speed;
189 
190  while(1) {
192  counter = 0;
193 
194  if(switch0.debounced_data & GPIO_PIN_1) {
195  left_speed = 100;
196  right_speed = 0;
197  } else if(switch0.debounced_data & GPIO_PIN_2) {
198  left_speed = 0;
199  right_speed = 100;
200  }
201 
202  motor0.reverse();
203  motor1.reverse();
204  while (++counter < counter_max) { }
205  motor0.reverse();
206  motor1.reverse();
208  }
209  os_surrender_context();
210  }
211 }
bool guard(void)
Definition: semaphorepp.cpp:57
int32_t percent_t
Definition: motorpp.hpp:15
drive drive0
Definition: move-main.cpp:54
motor motor0
Definition: move-main.cpp:53
uint32_t debounced_data
Definition: switchpp.hpp:40
void reverse(void)
Definition: motorpp.cpp:136
lswitch switch0
Definition: move-main.cpp:48
motor motor1
Definition: move-main.cpp:53
void reset_history()
Definition: drivepp.cpp:122
semaphore sem_switch
Definition: move-main.cpp:49

Here is the call graph for this function:

Here is the caller graph for this function:

void thread_blink_blue ( )

Definition at line 93 of file move-main.cpp.

References blink_count_blue, semaphore::guard(), PIN_BLUE, and blinker::toggle().

Referenced by main().

93  {
94 
95  while(1) {
96 #if BLINK_BLUE_WAIT_FOR_SEM == 1
97  if (sem_blink_blue.guard()) {
98 #endif
101 #if BLINK_BLUE_WAIT_FOR_SEM == 1
102  }
103 #endif
104  os_surrender_context();
105  }
106 }
bool guard(void)
Definition: semaphorepp.cpp:57
const pin_t PIN_BLUE
Definition: blinker.hpp:20
blinker blink
Definition: move-main.cpp:38
uint32_t blink_count_blue
Definition: move-main.cpp:68
semaphore sem_blink_blue
Definition: move-main.cpp:71
virtual void toggle(pin_t pin)
Definition: blinker.cpp:34

Here is the call graph for this function:

Here is the caller graph for this function:

void thread_blink_green ( )

Definition at line 108 of file move-main.cpp.

References blink_count_green, semaphore::guard(), PIN_GREEN, and blinker::toggle().

Referenced by main().

108  {
109 
110  while(1) {
111 #if BLINK_GREEN_WAIT_FOR_SEM == 1
112  if (sem_blink_green.guard()) {
113 #endif
116 #if BLINK_GREEN_WAIT_FOR_SEM == 1
117  }
118 #endif
119  os_surrender_context();
120  }
121 }
bool guard(void)
Definition: semaphorepp.cpp:57
semaphore sem_blink_green
Definition: move-main.cpp:72
blinker blink
Definition: move-main.cpp:38
uint32_t blink_count_green
Definition: move-main.cpp:67
virtual void toggle(pin_t pin)
Definition: blinker.cpp:34
const pin_t PIN_GREEN
Definition: blinker.hpp:19

Here is the call graph for this function:

Here is the caller graph for this function:

void thread_blink_red ( )

Definition at line 78 of file move-main.cpp.

References blink_count_red, semaphore::guard(), PIN_RED, and blinker::toggle().

Referenced by main().

78  {
79 
80  while(1) {
81 #if BLINK_RED_WAIT_FOR_SEM == 1
82  if (sem_blink_red.guard()) {
83 #endif
86 #if BLINK_RED_WAIT_FOR_SEM == 1
87  }
88 #endif
89  os_surrender_context();
90  }
91 }
bool guard(void)
Definition: semaphorepp.cpp:57
semaphore sem_blink_red
Definition: move-main.cpp:70
blinker blink
Definition: move-main.cpp:38
const pin_t PIN_RED
Definition: blinker.hpp:18
virtual void toggle(pin_t pin)
Definition: blinker.cpp:34
uint32_t blink_count_red
Definition: move-main.cpp:66

Here is the call graph for this function:

Here is the caller graph for this function:

void thread_uart_update ( )

Definition at line 123 of file move-main.cpp.

References uart::atomic_printf(), blink_count_blue, blink_count_green, blink_count_red, and thread.

123  {
124 
125  thread (
126  uart0.atomic_printf("%x %x %x\n\r", blink_count_red,
128  );
129 }
void atomic_printf(const char *pcString,...)
Definition: uartpp.cpp:348
#define thread(x)
Definition: move-main.cpp:32
uint32_t blink_count_blue
Definition: move-main.cpp:68
uint32_t blink_count_green
Definition: move-main.cpp:67
uint32_t blink_count_red
Definition: move-main.cpp:66
uart uart0
Definition: move-main.cpp:39

Here is the call graph for this function:

void Timer0A_Handler ( )

Definition at line 281 of file move-main.cpp.

References timer::ack(), and drive::stop().

281  {
282 
284  drive0.stop();
285 }
drive drive0
Definition: move-main.cpp:54
virtual uint32_t ack()
Definition: timerpp.cpp:74
void stop(void)
Definition: drivepp.cpp:20
timer countdown_timer
Definition: move-main.cpp:50

Here is the call graph for this function:

void Timer1A_Handler ( )

Definition at line 276 of file move-main.cpp.

References lswitch::end_debounce().

276  {
277 
279 }
uint32_t end_debounce(void)
Definition: switchpp.cpp:74
lswitch switch0
Definition: move-main.cpp:48

Here is the call graph for this function:

void UART0_Handler ( void  )

Definition at line 133 of file move-main.cpp.

References uart::ack(), blinker::blink(), uart::get_char(), uart::LAST_WAS_CR, buffer< T, N >::notify(), and PIN_RED.

133  {
134 
135  if(!(uart0.ack() & (UART_INT_RX | UART_INT_RT))) {
136  return;
137  }
138 
139  while(UARTCharsAvail(UART0_BASE)) {
140  char recv = uart0.get_char();
141 
142  /* Regardless of newline received, our convention is to
143  * mark end-of-lines in a buffer with the CR character. */
144  switch(recv) {
145  case '\n':
146  if (uart::LAST_WAS_CR) {
147  uart::LAST_WAS_CR = false;
148  continue;
149  }
150  break;
151  case '\r':
152  uart::LAST_WAS_CR = true;
153  break;
154  case 0x1b:
155  recv = '\r';
156  break;
157  default: break;
158  }
159  UART0_RX_BUFFER.notify((const int8_t) recv);
161  }
162 }
char get_char(void)
Definition: uartpp.cpp:381
blinker blink
Definition: move-main.cpp:38
static bool LAST_WAS_CR
Definition: uartpp.hpp:38
static buffer< char, 8 > UART0_RX_BUFFER
Definition: move-main.cpp:64
const pin_t PIN_RED
Definition: blinker.hpp:18
virtual uint32_t ack(void)
Definition: uartpp.cpp:386
virtual void blink(pin_t pin)
Definition: blinker.cpp:38
uart uart0
Definition: move-main.cpp:39

Here is the call graph for this function:

Variable Documentation

blinker blink

Definition at line 38 of file move-main.cpp.

Referenced by shell::doctor(), shell::jester(), and shell::witch().

uint32_t blink_count_blue = 0

Definition at line 68 of file move-main.cpp.

Referenced by thread_blink_blue(), and thread_uart_update().

uint32_t blink_count_green = 0

Definition at line 67 of file move-main.cpp.

Referenced by thread_blink_green(), and thread_uart_update().

uint32_t blink_count_red = 0

Definition at line 66 of file move-main.cpp.

Referenced by thread_blink_red(), and thread_uart_update().

can can0

Definition at line 59 of file move-main.cpp.

uint8_t can_data[10]

Definition at line 60 of file move-main.cpp.

Referenced by can_handler().

const uint32_t can_msg_id = 1

Definition at line 57 of file move-main.cpp.

Referenced by can_handler().

const bool can_sender = false

Definition at line 58 of file move-main.cpp.

Referenced by can::can(), and main().

timer countdown_timer

Definition at line 50 of file move-main.cpp.

drive drive0

Definition at line 54 of file move-main.cpp.

motor motor0

Definition at line 53 of file move-main.cpp.

motor motor1

Definition at line 53 of file move-main.cpp.

semaphore motor_start

Definition at line 52 of file move-main.cpp.

semaphore motor_stop

Definition at line 52 of file move-main.cpp.

semaphore sem_blink_blue

Definition at line 71 of file move-main.cpp.

semaphore sem_blink_green

Definition at line 72 of file move-main.cpp.

semaphore sem_blink_red

Definition at line 70 of file move-main.cpp.

semaphore sem_switch

Definition at line 49 of file move-main.cpp.

uint16_t sens_ir_left

Definition at line 42 of file move-main.cpp.

Referenced by can_handler(), can_transmitter(), and driver().

uint16_t sens_ir_left_front

Definition at line 43 of file move-main.cpp.

Referenced by can_handler(), can_transmitter(), and driver().

uint16_t sens_ir_right

Definition at line 44 of file move-main.cpp.

Referenced by can_handler(), can_transmitter(), and driver().

uint16_t sens_ir_right_front

Definition at line 45 of file move-main.cpp.

Referenced by can_handler(), can_transmitter(), and driver().

uint16_t sens_ping_front

Definition at line 46 of file move-main.cpp.

Referenced by can_handler(), can_transmitter(), and driver().

shell shell0

Definition at line 40 of file move-main.cpp.

lswitch switch0

Definition at line 48 of file move-main.cpp.

uart uart0

Definition at line 39 of file move-main.cpp.

buffer<char, 8 > UART0_RX_BUFFER
static

Definition at line 64 of file move-main.cpp.

semaphore UART0_RX_SEM
static

Definition at line 63 of file move-main.cpp.

Referenced by main().