EE445M RTOS
Taken at the University of Texas Spring 2015
heartbeat.h
Go to the documentation of this file.
1 /* -*- mode: c; c-basic-offset: 4; -*- */
2 /* Created by Eric Crosson 2015-02-10
3  * Note that this function looks gnarly with the #defines so the
4  * client code doesn't. */
5 #ifndef __HEARTBEAT__
6 #define __HEARTBEAT__
7 
8 /* Standard Libs */
9 #include <stdint.h>
10 #include <stdbool.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 
14 /* TI Includes */
15 #include "inc/hw_ints.h"
16 #include "inc/hw_memmap.h"
17 
18 /* Driverlib Includes */
19 #include "driverlib/debug.h"
20 #include "driverlib/fpu.h"
21 #include "driverlib/gpio.h"
22 #include "driverlib/interrupt.h"
23 #include "driverlib/pin_map.h"
24 #include "driverlib/sysctl.h"
25 #include "driverlib/timer.h"
26 #include "driverlib/rom.h"
27 
30 #define HEART_RED GPIO_PIN_1
31 #define HEART_BLUE GPIO_PIN_2
32 #define HEART_GREEN GPIO_PIN_3
33 
37 #define THORACIC_CAVITY GPIO_PORTF_BASE
38 
39 /*--------------------------------------------------------------*
40  * Begin non-modal API -- implicit subject is \HEART_BLUE. *
41  *--------------------------------------------------------------*/
42 
48 inline
49 void heart_init() {
50 
51 #if !(defined(PROFILING_DISABLE))
52  /* Enable the GPIO port that is used for the on-board LED. */
54 
55  /* Enable the GPIO pins for the LED (PF2). */
57 #endif
58 }
59 
65 inline
66 int32_t heart_status() {
67 
68 #if !(defined(PROFILING_DISABLE))
70 #endif
71 }
72 
78 inline
79 void heart_off() {
80 
81 #if !(defined(PROFILING_DISABLE))
83 #endif
84 }
85 
91 inline
92 void heart_on() {
93 
94 #if !(defined(PROFILING_DISABLE))
96 #endif
97 }
98 
105 inline
106 void heart_toggle() {
107 
108 #if !(defined(PROFILING_DISABLE))
110 #endif
111 }
112 
119 inline
120 void heart_beat() {
121 
122 #if !(defined(PROFILING_DISABLE))
125 #endif
126 }
127 
132 #define heart_wrap(x) \
133  heart_beat(); \
134  x \
135  heart_toggle(); \
136 
137 /*--------------------------------------------------------------*
138  * Begin GPIO API -- concentrate on a muscle and pump it baby *
139  * One day, this section desires to be fully modal *
140  *--------------------------------------------------------------*/
141 
142 /* TODO: determine how to document the HEARTBEAT_MODAL switch in
143  * Doxygen. */
144 #ifdef HEARTBEAT_MODAL
145 
146 #include "../libos/os.h"
147 
152 #define heart_wrap_(x) \
153  heart_beat_(); \
154  x \
155  heart_toggle_(); \
156 
157 
158 #define heart_pump_(a, b) heart_init_(a, b)
159 
161 typedef int32_t memory_address_t;
162 
165 typedef struct muscle_t {
166  memory_address_t base;
167  memory_address_t pin;
168 } muscle_t;
169 
170 static muscle_t HEART_MODAL_METADATA[SCHEDULER_MAX_THREADS];
171 
181 inline
182 void heart_init_(memory_address_t base, memory_address_t pin) {
183 
184 #if !(defined(PROFILING_DISABLE))
185  /* Enable the GPIO port that is used for \HEART_ANCILLARY_MUSCLE. */
186  switch(base) {
196  }
197 
198  /* Enable the GPIO pins for \HEART_ANCILLARY_MUSCLE. */
199  GPIOPinTypeGPIOOutput(base, pin);
200 
201  /* Save metadata allowing for modal use of this library */
202  HEART_MODAL_METADATA[os_running_thread_id()].base = base;
203  HEART_MODAL_METADATA[os_running_thread_id()].pin = pin;
204 #endif
205 }
206 
208 inline
209 int32_t heart_status_modal(muscle_t* ancillary_muscle) {
210 
211 #if !(defined(PROFILING_DISABLE))
212  GPIOPinRead(ancillary_muscle->base, ancillary_muscle->pin);
213 #endif
214 }
215 
222 inline
223 int32_t heart_status_() {
224 
225 #if !(defined(PROFILING_DISABLE))
226  heart_status_modal(&HEART_MODAL_METADATA[os_running_thread_id()]);
227 #endif
228 }
229 
231 inline
232 void heart_off_modal(muscle_t* ancillary_muscle) {
233 
234 #if !(defined(PROFILING_DISABLE))
235  GPIOPinWrite(ancillary_muscle->base, ancillary_muscle->pin, 0);
236 #endif
237 }
238 
245 inline
246 void heart_off_() {
247 
248 #if !(defined(PROFILING_DISABLE))
249  heart_off_modal(&HEART_MODAL_METADATA[os_running_thread_id()]);
250 #endif
251 }
252 
254 inline
255 void heart_on_modal(muscle_t* ancillary_muscle) {
256 
257 #if !(defined(PROFILING_DISABLE))
258  GPIOPinWrite(ancillary_muscle->base, ancillary_muscle->pin, 1);
259 #endif
260 }
261 
268 inline
269 void heart_on_() {
270 
271 #if !(defined(PROFILING_DISABLE))
272  heart_on_modal(&HEART_MODAL_METADATA[os_running_thread_id()]);
273 #endif
274 }
275 
277 inline
278 void heart_toggle_modal(muscle_t* ancillary_muscle) {
279 
280 #if !(defined(PROFILING_DISABLE))
281  GPIOPinWrite(ancillary_muscle->base, ancillary_muscle->pin,
282  heart_status_(ancillary_muscle->base,
283  ancillary_muscle->pin) ^ ancillary_muscle->pin);
284 #endif
285 }
286 
294 inline
295 void heart_toggle_() {
296 
297 #if !(defined(PROFILING_DISABLE))
298  heart_toggle_modal(&HEART_MODAL_METADATA[os_running_thread_id()]);
299 #endif
300 }
301 
303 inline
304 void heart_beat_modal(muscle_t* ancillary_muscle) {
305 
306 #if !(defined(PROFILING_DISABLE))
307  GPIOPinWrite(ancillary_muscle->base, ancillary_muscle->pin,
308  heart_status_(ancillary_muscle->base,
309  ancillary_muscle->pin) ^ ancillary_muscle->pin);
310  GPIOPinWrite(ancillary_muscle->base, ancillary_muscle->pin,
311  heart_status_(ancillary_muscle->base,
312  ancillary_muscle->pin) ^ ancillary_muscle->pin);
313 #endif
314 }
315 
323 inline
324 void heart_beat_() {
325 
326 #if !(defined(PROFILING_DISABLE))
327  heart_beat_modal(&HEART_MODAL_METADATA[os_running_thread_id()]);
328 #endif
329 }
330 
331 /*--------------------------------------------------------------*
332  * End GPIO API *
333  *--------------------------------------------------------------*/
334 
349 #define heart_hew_muscle(a, b, c) \
350  muscle_t a; \
351  heart_hew_muscle_(&a, b, c)
352 
361 inline
362 muscle_t* heart_hew_muscle_(muscle_t* muscle,
363  memory_address_t base,
364  memory_address_t pin) {
365 
366 #if !(defined(PROFILING_DISABLE))
367  /* Initialize the muscle_t data structure */
368  muscle->base = base;
369  muscle->pin = pin;
370  /* Ensure this peripheral is initialized properly */
371  heart_init_(base, pin);
372  /* A convenience for the client developer */
373  return muscle;
374 #endif
375 }
376 #endif /* HEARTBEAT_MODAL */
377 
378 #endif
#define SYSCTL_PERIPH_GPIOJ
Definition: sysctl.h:79
#define SYSCTL_PERIPH_GPIOG
Definition: sysctl.h:77
#define GPIO_PORTG_BASE
Definition: hw_memmap.h:75
void GPIOPinWrite(uint32_t ui32Port, uint8_t ui8Pins, uint8_t ui8Val)
Definition: gpio.c:1038
#define SYSCTL_PERIPH_GPIOH
Definition: sysctl.h:78
#define SYSCTL_PERIPH_GPIOB
Definition: sysctl.h:72
#define GPIO_PORTB_BASE
Definition: hw_memmap.h:54
#define GPIO_PORTE_BASE
Definition: hw_memmap.h:73
#define SYSCTL_PERIPH_GPIOF
Definition: sysctl.h:76
void heart_beat()
Toggle twice.
Definition: heartbeat.h:120
void heart_toggle()
Toggle once.
Definition: heartbeat.h:106
#define GPIO_PORTH_BASE
Definition: hw_memmap.h:76
#define SYSCTL_PERIPH_GPIOA
Definition: sysctl.h:71
void heart_init()
Initialize for visible transformation.
Definition: heartbeat.h:49
#define GPIO_PORTJ_BASE
Definition: hw_memmap.h:92
#define GPIO_PORTA_BASE
Definition: hw_memmap.h:53
#define SYSCTL_PERIPH_GPIOC
Definition: sysctl.h:73
void heart_on()
Turn on.
Definition: heartbeat.h:92
void SysCtlPeripheralEnable(uint32_t ui32Peripheral)
Definition: sysctl.c:841
#define GPIO_PORTC_BASE
Definition: hw_memmap.h:55
void GPIOPinTypeGPIOOutput(uint32_t ui32Port, uint8_t ui8Pins)
Definition: gpio.c:1427
#define SYSCTL_PERIPH_GPIOE
Definition: sysctl.h:75
int32_t heart_status()
Return the status of .
Definition: heartbeat.h:66
#define SCHEDULER_MAX_THREADS
void heart_off()
Turn off.
Definition: heartbeat.h:79
#define SYSCTL_PERIPH_GPIOD
Definition: sysctl.h:74
#define HEART_BLUE
Definition: heartbeat.h:31
#define GPIO_PORTD_BASE
Definition: hw_memmap.h:56
int32_t memory_address_t
Definition: nexus.h:48
int32_t os_running_thread_id()
Definition: os.c:142
int32_t GPIOPinRead(uint32_t ui32Port, uint8_t ui8Pins)
Definition: gpio.c:1006
#define THORACIC_CAVITY
Definition: heartbeat.h:37
#define GPIO_PORTF_BASE
Definition: hw_memmap.h:74