EE445M RTOS
Taken at the University of Texas Spring 2015
test-os.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 
9 /* TI Includes */
10 #include "inc/hw_ints.h"
11 #include "inc/hw_memmap.h"
12 
13 /* Driverlib Includes */
14 #include "driverlib/debug.h"
15 #include "driverlib/gpio.h"
16 #include "driverlib/interrupt.h"
17 #include "driverlib/pin_map.h"
18 #include "driverlib/sysctl.h"
19 #include "driverlib/systick.h"
20 #include "driverlib/uart.h"
21 
22 #define HEARTBEAT_MODAL
23 
24 #include "libos/os.h"
25 #include "libheart/heartbeat.h"
26 #include "libhw/hardware.h"
27 #include "libstd/nexus.h"
28 
29 #include <sys/stat.h>
30 
31 #define UART_FIFO_SIZE 0x7f
32 #define PIDWORK_BUFFER_SIZE 0x7f
33 
34 volatile uint32_t pidwork;
35 volatile uint32_t highest_pidwork;
36 volatile uint32_t lowest_pidwork;
37 volatile uint32_t pidwork_idx;
38 volatile uint32_t* pidwork_buffer;
39 
40 volatile uint32_t uart_producer_idx;
41 volatile uint32_t uart_consumer_idx;
42 volatile char* uart_fifo;
43 volatile uint32_t uart_dropped_chars;
44 
46 void Thread1(void){
47  while(1) {
48  /* BEGIN CRITICAL SECTION */
49  atomic (
50  ++pidwork;
51  );
52  /* END CRITICAL SECTION */
55  /* os_surrender_context(); */
56  }
57 }
58 
60 void Thread2(void){
61  while(1) {
64  if (pidwork != 0) {
65  if (highest_pidwork < pidwork) {
67  }
68  if (lowest_pidwork > pidwork) {
70  }
73  }
74  pidwork = 0;
75  /* os_surrender_context(); */
76  }
77 }
78 
79 void uart_consumer(void) {
80 
81  while (1) {
83 
88  }
89  }
90 }
91 
93 int main() {
94 
95  char uart_fifo_raw[UART_FIFO_SIZE];
96  uint32_t pidwork_buffer_raw[PIDWORK_BUFFER_SIZE];
97 
100 
102 
103  /* Initialize global variables */
104  pidwork = 0;
105  highest_pidwork = 0;
106  lowest_pidwork = (uint32_t)(-1);
107  pidwork_buffer = pidwork_buffer_raw;
108  pidwork_idx = 0;
109 
110  /* Enable the UART */
113  GPIOPinConfigure(GPIO_PA0_U0RX);
114  GPIOPinConfigure(GPIO_PA1_U0TX);
119 
120  /* Enable the UART interrupt. */
121 
122  /* IntEnable(INT_UART0); */
123  /* UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); */
124  /* uart_fifo = uart_fifo_raw; */
125  /* uart_producer_idx = 0; */
126  /* uart_consumer_idx = UART_FIFO_SIZE - 1; */
127 
128  os_threading_init(100 Hz);
131  /* os_add_thread(hw_daemon, OS_SYSTEM_POOL); */
132 
133  heart_init();
134  heart_init_(GPIO_PORTF_BASE, GPIO_PIN_1);
135  heart_init_(GPIO_PORTF_BASE, GPIO_PIN_2);
136  heart_init_(GPIO_PORTF_BASE, GPIO_PIN_3);
137 
138  /* os_trap_ */
139  os_launch();
140 
141  /* PONDER: why do interrupts fire without this? */
142  IntMasterEnable();
143  postpone_death();
144 }
tcb_t * os_add_thread(task_t task)
Definition: os.c:72
void GPIOPinWrite(uint32_t ui32Port, uint8_t ui8Pins, uint8_t ui8Val)
Definition: gpio.c:1038
void GPIOPinTypeUART(uint32_t ui32Port, uint8_t ui8Pins)
Definition: gpio.c:2031
int main()
Definition: test-os.c:93
#define GPIO_PIN_0
Definition: gpio.h:60
void UARTConfigSetExpClk(uint32_t ui32Base, uint32_t ui32UARTClk, uint32_t ui32Baud, uint32_t ui32Config)
Definition: uart.c:368
#define PIDWORK_BUFFER_SIZE
Definition: test-os.c:32
#define SYSCTL_OSC_MAIN
Definition: sysctl.h:378
volatile uint32_t pidwork_idx
Definition: test-os.c:37
volatile uint32_t uart_producer_idx
Definition: test-os.c:40
#define SYSCTL_USE_OSC
Definition: sysctl.h:350
#define GPIO_PIN_2
Definition: gpio.h:62
uint32_t SysCtlClockGet(void)
Definition: sysctl.c:2727
#define SYSCTL_XTAL_16MHZ
Definition: sysctl.h:372
#define GPIO_PIN_1
Definition: gpio.h:61
#define SYSCTL_PERIPH_UART0
Definition: sysctl.h:122
void os_threading_init()
Definition: os.c:34
#define UART_CONFIG_STOP_ONE
Definition: uart.h:90
volatile uint32_t lowest_pidwork
Definition: test-os.c:36
#define UART_CONFIG_WLEN_8
Definition: uart.h:85
#define SYSCTL_PERIPH_GPIOA
Definition: sysctl.h:71
#define atomic(x)
Definition: nexus.h:32
void heart_init()
Initialize for visible transformation.
Definition: heartbeat.h:49
#define GPIO_PORTA_BASE
Definition: hw_memmap.h:53
void Thread1(void)
Definition: test-os.c:46
void os_launch()
Definition: os.c:161
#define postpone_death()
Definition: nexus.h:40
volatile uint32_t pidwork
Definition: test-os.c:34
#define OS_INTERACTIVE_POOL
Definition: os.h:32
bool IntMasterDisable(void)
Definition: interrupt.c:249
void SysCtlPeripheralEnable(uint32_t ui32Peripheral)
Definition: sysctl.c:841
#define GPIO_PIN_3
Definition: gpio.h:63
void uart_consumer(void)
Definition: test-os.c:79
bool IntMasterEnable(void)
volatile uint32_t * pidwork_buffer
Definition: test-os.c:38
volatile char * uart_fifo
Definition: test-os.c:42
void GPIOPinConfigure(uint32_t ui32PinConfig)
Definition: gpio.c:2509
#define UART_FIFO_SIZE
Definition: test-os.c:31
volatile uint32_t uart_consumer_idx
Definition: test-os.c:41
void Thread2(void)
Definition: test-os.c:60
#define Hz
Definition: nexus.h:45
#define UART0_BASE
Definition: hw_memmap.h:61
volatile uint32_t highest_pidwork
Definition: test-os.c:35
#define SYSCTL_SYSDIV_1
Definition: sysctl.h:221
void UARTCharPut(uint32_t ui32Base, unsigned char ucData)
Definition: uart.c:1268
void SysCtlClockSet(uint32_t ui32Config)
Definition: sysctl.c:2532
int32_t GPIOPinRead(uint32_t ui32Port, uint8_t ui8Pins)
Definition: gpio.c:1006
volatile uint32_t uart_dropped_chars
Definition: test-os.c:43
#define UART_CONFIG_PAR_NONE
Definition: uart.h:93
#define GPIO_PORTF_BASE
Definition: hw_memmap.h:74