EE445M RTOS
Taken at the University of Texas Spring 2015
hardware.c File Reference
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_nvic.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/rom.h"
#include "libut/utlist.h"
#include "libhw/hardware.h"
#include "libbuffer/buffer.h"
#include "driverlib/uart.h"
#include "driverlib/timer.h"
#include "libuart/uart.h"
#include "libtimer/timer.h"
#include "libbutton/button.h"
Include dependency graph for hardware.c:

Go to the source code of this file.

Functions

void hw_init_daemon ()
 
void hw_driver_init (HW_TYPE type, hw_metadata metadata)
 
void hw_channel_init (HW_TYPE type, hw_metadata metadata)
 
void _hw_subscribe (HW_TYPE type, hw_metadata metadata, void(*isr)(notification note), bool single_shot)
 
void hw_unsubscribe (HW_TYPE type, hw_metadata metadata, void(*isr)(notification note))
 
void hw_notify (HW_TYPE type, hw_metadata metadata, notification note)
 
void hw_daemon (void)
 
void hw_notify_uart (hw_metadata uart_metadata)
 
hw_channel_hw_get_channel (HW_TYPE type, hw_metadata metadata)
 
hw_driverhw_driver_singleton (HW_TYPE type)
 
void GPIOPortF_Handler (void)
 
void UART0_Handler (void)
 
void TIMER0A_Handler (void)
 
void TIMER1A_Handler (void)
 
void TIMER2A_Handler (void)
 
void ADC0Seq0_Handler (void)
 
void ADC0Seq1_Handler (void)
 
void ADC0Seq2_Handler (void)
 
void ADC0Seq3_Handler (void)
 

Variables

static hw_driver HW_UART_DRIVER
 
static hw_driver HW_TIMER_DRIVER
 
static hw_driver HW_BUTTON_DRIVER
 
static uint8_t UART0_RX_BUFFER [BUFFER_MAX_LENGTH]
 
static uint8_t UART0_RX_BUFFER_SIZE = 0
 
static uint8_t UART0_TX_BUFFER [BUFFER_MAX_LENGTH]
 
static uint8_t UART0_TX_BUFFER_SIZE = 0
 
uint32_t ADC0_SEQ0_SAMPLES [4]
 
uint32_t ADC0_SEQ1_SAMPLES [4]
 
uint32_t ADC0_SEQ2_SAMPLES [4]
 
uint32_t ADC0_SEQ3_SAMPLES [4]
 
semaphore_t HW_ADC_SEQ2_SEM
 
uint32_t jitter_begin
 
uint32_t jitter_end
 

Function Documentation

hw_channel* _hw_get_channel ( HW_TYPE  ,
hw_metadata   
)
inline

For internal use only. Take care of the conversion between a memory-mapped (raw) hw address and the index of said peripheral channel in the memory banks of libhw's device-specific data structures.

Parameters
hw_groupThe hardware group in question
raw_hw_channelThe specific channel of
Returns
Index of 'channel in 's data structures

Definition at line 203 of file hardware.c.

References hw_timer_metadata::base, hw_button_metadata::base, hw_metadata::button, hw_uart_metadata::channel, hw_driver::channels, GPIO_PORTE_BASE, HW_BUTTON, hw_driver_singleton(), HW_TIMER, HW_UART, postpone_death, hw_metadata::timer, TIMER0_BASE, hw_metadata::uart, and UART0_BASE.

Referenced by _hw_subscribe(), hw_channel_init(), hw_notify(), and hw_unsubscribe().

203  {
204 
205  memory_address_t idx;
206  switch(type){
207  /* optimize: divide should be a shift */
208  case HW_UART: idx = (metadata.uart.channel - UART0_BASE) / 0x1000; break;
209  case HW_TIMER: idx = (metadata.timer.base - TIMER0_BASE) / 0x1000; break;
210  case HW_BUTTON: idx = (metadata.button.base - GPIO_PORTE_BASE)/ 0x1000; break;
211  /* Note: libhw won't allow for the use of ports higher than
212  * GPIO_PORTE without modification of the above indexing
213  * algorithm */
214  default: postpone_death();
215  }
216  return &(hw_driver_singleton(type)->channels[idx]);
217 }
#define TIMER0_BASE
Definition: hw_memmap.h:81
#define GPIO_PORTE_BASE
Definition: hw_memmap.h:73
hw_uart_metadata uart
Definition: hardware.h:97
memory_address_t channel
Definition: hardware.h:56
hw_button_metadata button
Definition: hardware.h:99
memory_address_t base
Definition: hardware.h:63
#define postpone_death()
Definition: nexus.h:40
hw_timer_metadata timer
Definition: hardware.h:98
hw_driver * hw_driver_singleton(HW_TYPE type)
Definition: hardware.c:220
#define UART0_BASE
Definition: hw_memmap.h:61
memory_address_t base
Definition: hardware.h:73
int32_t memory_address_t
Definition: nexus.h:48
hw_channel channels[8]
Definition: hardware.h:138

Here is the call graph for this function:

Here is the caller graph for this function:

void _hw_subscribe ( HW_TYPE  ,
hw_metadata  ,
void(*)(notification note)  isr,
bool   
)

Subscribe to a hardware interrupt. This is also called connecting a signal (the isr to be notified) to a slot (the hw-triggered driver isr).

Parameters
Thehardware type in question
Metadataabout the device
Thepseudo-isr to be notified by the hardware driver

Definition at line 121 of file hardware.c.

References _hw_get_channel(), CDL_DELETE, CDL_PREPEND, hw_channel::free_slots, hw_channel::full_slots, _isr_subscription::single_shot_subscription, and _isr_subscription::slot.

Referenced by schedule_aperiodic().

124  {
125 
126  hw_iterator i;
127  hw_channel* channel = _hw_get_channel(type, metadata);
128  _isr_subscription* new_subscrip = channel->free_slots;
129 
130  CDL_DELETE(channel->free_slots, new_subscrip);
131  CDL_PREPEND(channel->full_slots, new_subscrip);
132 
133  new_subscrip->single_shot_subscription = single_shot;
134  new_subscrip->slot = isr;
135 }
bool single_shot_subscription
Definition: hardware.h:123
uint8_t hw_iterator
Definition: hardware.h:105
void(* slot)(notification)
Definition: hardware.h:124
_isr_subscription * free_slots
Definition: hardware.h:132
#define CDL_DELETE(head, del)
Definition: utlist.h:705
_isr_subscription * full_slots
Definition: hardware.h:133
hw_channel * _hw_get_channel(HW_TYPE type, hw_metadata metadata)
Definition: hardware.c:203
#define CDL_PREPEND(head, add)
Definition: utlist.h:671

Here is the call graph for this function:

Here is the caller graph for this function:

void ADC0Seq0_Handler ( void  )

Definition at line 378 of file hardware.c.

References ADC0_BASE, ADC0_SEQ3_SAMPLES, ADCIntClear(), and ADCSequenceDataGet().

Referenced by __attribute__().

378  {
379 
382  /* TODO: Conform to Notify */
383 }
#define ADC0_BASE
Definition: hw_memmap.h:89
int32_t ADCSequenceDataGet(uint32_t ui32Base, uint32_t ui32SequenceNum, uint32_t *pui32Buffer)
Definition: adc.c:824
uint32_t ADC0_SEQ3_SAMPLES[4]
Definition: hardware.c:47
void ADCIntClear(uint32_t ui32Base, uint32_t ui32SequenceNum)
Definition: adc.c:363

Here is the call graph for this function:

Here is the caller graph for this function:

void ADC0Seq1_Handler ( void  )

Definition at line 385 of file hardware.c.

References ADC0_BASE, ADC0_SEQ3_SAMPLES, ADCIntClear(), and ADCSequenceDataGet().

Referenced by __attribute__().

385  {
386 
389  /* TODO: Conform to Notify */
390 }
#define ADC0_BASE
Definition: hw_memmap.h:89
int32_t ADCSequenceDataGet(uint32_t ui32Base, uint32_t ui32SequenceNum, uint32_t *pui32Buffer)
Definition: adc.c:824
uint32_t ADC0_SEQ3_SAMPLES[4]
Definition: hardware.c:47
void ADCIntClear(uint32_t ui32Base, uint32_t ui32SequenceNum)
Definition: adc.c:363

Here is the call graph for this function:

Here is the caller graph for this function:

void ADC0Seq2_Handler ( void  )

Definition at line 392 of file hardware.c.

References ADC0_BASE, ADC0_SEQ2_SAMPLES, ADCIntClear(), ADCSequenceDataGet(), HW_ADC_SEQ2_SEM, HWREG, jitter_end, NVIC_ST_CURRENT, and sem_post.

Referenced by __attribute__().

392  {
393 
397  /* GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1) ^ GPIO_PIN_1); */
399  /* TODO: Conform to Notify */
400 }
#define HWREG(x)
Definition: hw_types.h:48
uint32_t jitter_end
Definition: hardware.c:52
#define sem_post(sem)
#define NVIC_ST_CURRENT
Definition: hw_nvic.h:52
#define ADC0_BASE
Definition: hw_memmap.h:89
int32_t ADCSequenceDataGet(uint32_t ui32Base, uint32_t ui32SequenceNum, uint32_t *pui32Buffer)
Definition: adc.c:824
void ADCIntClear(uint32_t ui32Base, uint32_t ui32SequenceNum)
Definition: adc.c:363
uint32_t ADC0_SEQ2_SAMPLES[4]
Definition: hardware.c:46
semaphore_t HW_ADC_SEQ2_SEM
Definition: hardware.c:49

Here is the call graph for this function:

Here is the caller graph for this function:

void ADC0Seq3_Handler ( void  )

Definition at line 402 of file hardware.c.

References ADC0_BASE, ADC0_SEQ3_SAMPLES, ADCIntClear(), and ADCSequenceDataGet().

Referenced by __attribute__().

402  {
403 
406  /* GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1) ^ GPIO_PIN_1); */
407  /* TODO: Conform to Notify */
408 }
#define ADC0_BASE
Definition: hw_memmap.h:89
int32_t ADCSequenceDataGet(uint32_t ui32Base, uint32_t ui32SequenceNum, uint32_t *pui32Buffer)
Definition: adc.c:824
uint32_t ADC0_SEQ3_SAMPLES[4]
Definition: hardware.c:47
void ADCIntClear(uint32_t ui32Base, uint32_t ui32SequenceNum)
Definition: adc.c:363

Here is the call graph for this function:

Here is the caller graph for this function:

void GPIOPortF_Handler ( void  )

GPIO PortF (includes on-board buttons) isr responsible for notifying all subscriptions with information describing the interrupt.

Definition at line 238 of file hardware.c.

References button_metadata_init, BUTTONS_BOTH, GPIO_PORTF_BASE, GPIOIntClear(), GPIOPinRead(), HW_BUTTON, hw_notify(), notification_init, and NULL.

Referenced by __attribute__().

238  {
239 
241 
244  hw_notify(HW_BUTTON, button_metadata, note);
245 }
void hw_notify(HW_TYPE type, hw_metadata metadata, notification note)
Definition: hardware.c:149
#define notification_init(_type, _value)
Definition: notify.h:45
#define button_metadata_init(_base, _pin, _interrupt)
Definition: button.h:23
#define BUTTONS_BOTH
Definition: button.h:28
#define NULL
Definition: defines.h:32
void GPIOIntClear(uint32_t ui32Port, uint32_t ui32IntFlags)
Definition: gpio.c:878
int32_t GPIOPinRead(uint32_t ui32Port, uint8_t ui8Pins)
Definition: gpio.c:1006
#define GPIO_PORTF_BASE
Definition: hw_memmap.h:74

Here is the call graph for this function:

Here is the caller graph for this function:

void hw_channel_init ( HW_TYPE  ,
hw_metadata   
)

This function is responsible for enabling a specific channel on the specified hardware device. Internal libhw datastructures will also be reset.

Parameters
hw_groupThe hardware group in question
raw_channelThe memory-mapped address of the device channel to initialize
metadataInformation about how to initialize the device

Definition at line 94 of file hardware.c.

References _hw_get_channel(), button_set_interrupt(), CDL_PREPEND, hw_channel::free_slots, hw_channel::full_slots, HW_BUTTON, HW_DRIVER_MAX_SUBSCRIPTIONS, HW_TIMER, HW_UART, hw_channel::isr_subscriptions, NULL, postpone_death, timer_add_interrupt(), and uart_init().

Referenced by adc_interrupt_init(), button_debounce_start(), and main().

94  {
95 
96  hw_iterator i;
97  hw_channel* channel = _hw_get_channel(type, metadata);
98  channel->full_slots = NULL;
99  for(i=0; i<HW_DRIVER_MAX_SUBSCRIPTIONS; ++i) {
100  CDL_PREPEND(channel->free_slots, &channel->isr_subscriptions[i]);
101  }
102 
103  switch(type) {
104  case HW_UART:
105  uart_init(metadata);
106  break;
107 
108  case HW_TIMER:
109  timer_add_interrupt(metadata);
110  break;
111 
112  case HW_BUTTON:
113  /* TODO: parametrize */
114  button_set_interrupt(metadata);
115  break;
116 
117  default: postpone_death();
118  }
119 }
uint8_t hw_iterator
Definition: hardware.h:105
_isr_subscription * free_slots
Definition: hardware.h:132
#define HW_DRIVER_MAX_SUBSCRIPTIONS
Definition: hardware.h:116
#define postpone_death()
Definition: nexus.h:40
void timer_add_interrupt(hw_metadata metadata)
Definition: timer.c:18
_isr_subscription * full_slots
Definition: hardware.h:133
void button_set_interrupt(hw_metadata metadata)
Definition: button.c:35
void uart_init(hw_metadata metadata)
Definition: uart.c:39
#define NULL
Definition: defines.h:32
hw_channel * _hw_get_channel(HW_TYPE type, hw_metadata metadata)
Definition: hardware.c:203
_isr_subscription isr_subscriptions[8]
Definition: hardware.h:131
#define CDL_PREPEND(head, add)
Definition: utlist.h:671

Here is the call graph for this function:

Here is the caller graph for this function:

void hw_daemon ( void  )

Definition at line 172 of file hardware.c.

References hw_notify_uart(), HW_SEM_UART0, INT_UART0, os_surrender_context, sem_guard, sem_take, UART0_BASE, UART_DEFAULT_BAUD_RATE, and uart_metadata_init.

Referenced by hw_init_daemon(), and main().

172  {
173  while (1) {
174  /* mind ordering of sem_checks */
175  /* fixme: one thread for each hardware device, so individual
176  * priorities can be assigned to the threads (which will
177  * handle simultaneous interrupts according to priority
178  * scheduler's interpretation of priority) */
181  /* todo: schedule */
183  hw_notify_uart(uart_metadata);
184  }
186  }
187 }
static volatile semaphore_t HW_SEM_UART0
Definition: hardware.h:11
void hw_notify_uart(hw_metadata uart_metadata)
Definition: hardware.c:189
#define UART_DEFAULT_BAUD_RATE
Definition: uart.h:14
#define sem_take(sem)
#define INT_UART0
Definition: hw_ints.h:451
#define uart_metadata_init(_baud_rate, _channel, _interrupt)
Definition: uart.h:29
#define sem_guard(sem)
#define os_surrender_context()
Definition: os.h:142
#define UART0_BASE
Definition: hw_memmap.h:61

Here is the call graph for this function:

Here is the caller graph for this function:

void hw_driver_init ( HW_TYPE  ,
hw_metadata   
)

This function is responsible for enabling the peripherals and internal data strutures used by the specified .

Parameters
hw_groupThe hardware group driver to initialize

Definition at line 62 of file hardware.c.

References hw_timer_metadata::base, button_init(), hw_uart_metadata::channel, HW_BUTTON, HW_TIMER, HW_UART, postpone_death, SYSCTL_PERIPH_GPIOA, SYSCTL_PERIPH_GPIOF, SYSCTL_PERIPH_TIMER0, SYSCTL_PERIPH_UART0, SysCtlPeripheralEnable(), hw_metadata::timer, TIMER0_BASE, hw_metadata::uart, and UART0_BASE.

Referenced by main().

62  {
63 
64  switch(type) {
65  case HW_UART:
67  (metadata.uart.channel - UART0_BASE) / 0x1000);
68  /* todo: parametrize - are they all on A? */
70  break;
71 
72  case HW_TIMER:
74  (metadata.timer.base - TIMER0_BASE) / 0x1000);
75  break;
76 
77  case HW_BUTTON:
78  /* TODO: parametrize to allow other buttons to be driven */
80  /* #need4speed: Buttons on the board are only used for input,
81  * we know how they're going to be used. Break the libhw
82  * convention and initialize these buttons so this code never
83  * has to be run again */
84  button_init(metadata);
85  break;
86 
87  default: postpone_death();
88  }
89 }
#define TIMER0_BASE
Definition: hw_memmap.h:81
hw_uart_metadata uart
Definition: hardware.h:97
#define SYSCTL_PERIPH_GPIOF
Definition: sysctl.h:76
memory_address_t channel
Definition: hardware.h:56
#define SYSCTL_PERIPH_UART0
Definition: sysctl.h:122
memory_address_t base
Definition: hardware.h:63
#define SYSCTL_PERIPH_GPIOA
Definition: sysctl.h:71
#define postpone_death()
Definition: nexus.h:40
hw_timer_metadata timer
Definition: hardware.h:98
#define SYSCTL_PERIPH_TIMER0
Definition: sysctl.h:114
void SysCtlPeripheralEnable(uint32_t ui32Peripheral)
Definition: sysctl.c:841
#define UART0_BASE
Definition: hw_memmap.h:61
void button_init(hw_metadata metadata)
Definition: button.c:22

Here is the call graph for this function:

Here is the caller graph for this function:

hw_driver* hw_driver_singleton ( HW_TYPE  )
inline

Return the one hw_driver per hardware device group in use by the TM4C.

Parameters
Thehardware type to grab a pointer of
Returns
Pointer to the hw_driver data structure managing

Definition at line 220 of file hardware.c.

References HW_BUTTON, HW_BUTTON_DRIVER, HW_TIMER, HW_TIMER_DRIVER, HW_UART, HW_UART_DRIVER, NULL, and postpone_death.

Referenced by _hw_get_channel().

220  {
221 
222  switch(type) {
223  case HW_UART: return &HW_UART_DRIVER;
224  case HW_TIMER: return &HW_TIMER_DRIVER;
225  case HW_BUTTON: return &HW_BUTTON_DRIVER;
226  default: postpone_death();
227  }
228  return NULL;
229 }
static hw_driver HW_TIMER_DRIVER
Definition: hardware.c:35
static hw_driver HW_UART_DRIVER
Definition: hardware.c:34
#define postpone_death()
Definition: nexus.h:40
static hw_driver HW_BUTTON_DRIVER
Definition: hardware.c:36
#define NULL
Definition: defines.h:32

Here is the caller graph for this function:

void hw_init_daemon ( )

Initialize libhw's internal data structures

Definition at line 54 of file hardware.c.

References hw_daemon(), and os_add_thread().

54  {
55 
57 }
tcb_t * os_add_thread(task_t task)
Definition: os.c:72
void hw_daemon(void)
Definition: hardware.c:172

Here is the call graph for this function:

void hw_notify ( HW_TYPE  ,
hw_metadata  ,
notification   
)

Notify threads subscribed to about an incoming hardware event.

Parameters
hw_groupThe hardwawre group that received the incoming hardware event
channelThe channel of that received the incoming hardware event
notificationsThe notification (prepared by NVIC-invoked ISR) containing information regarding the recently-occurring hardware interrupt event

Definition at line 149 of file hardware.c.

References _hw_get_channel(), CDL_DELETE, CDL_PREPEND, hw_channel::free_slots, hw_channel::full_slots, _isr_subscription::next, NULL, _isr_subscription::single_shot_subscription, and _isr_subscription::slot.

Referenced by GPIOPortF_Handler(), hw_notify_uart(), s_Handler(), sA_Handler(), TIMER0A_Handler(), TIMER1A_Handler(), and TIMER2A_Handler().

149  {
150 
151  hw_iterator i=0;
152  hw_channel* channel = _hw_get_channel(type, metadata);
153  _isr_subscription* subscrip = channel->full_slots;
154  _isr_subscription* new_subscrip = NULL;
155 
156  /* TODO: make this a doubly linked list, not circular */
157  /* consider similar changes to os lib also */
158  while(subscrip && subscrip != new_subscrip) {
159  subscrip->slot(note);
160  new_subscrip = subscrip->next;
161  if (subscrip->single_shot_subscription) {
162  /* Cease fire! cease fire! */
163  subscrip->single_shot_subscription = false;
164  CDL_DELETE(channel->full_slots, subscrip);
165  CDL_PREPEND(channel->free_slots, subscrip);
166  }
167  subscrip = new_subscrip;
168  }
169 }
bool single_shot_subscription
Definition: hardware.h:123
uint8_t hw_iterator
Definition: hardware.h:105
void(* slot)(notification)
Definition: hardware.h:124
_isr_subscription * next
Definition: hardware.h:125
_isr_subscription * free_slots
Definition: hardware.h:132
#define CDL_DELETE(head, del)
Definition: utlist.h:705
_isr_subscription * full_slots
Definition: hardware.h:133
#define NULL
Definition: defines.h:32
hw_channel * _hw_get_channel(HW_TYPE type, hw_metadata metadata)
Definition: hardware.c:203
#define CDL_PREPEND(head, add)
Definition: utlist.h:671

Here is the call graph for this function:

Here is the caller graph for this function:

void hw_notify_uart ( hw_metadata  uart_metadata)

Iterate over all chars in the respective uart's RX_FIFO and notify all subscribed tasks.

Parameters
UARTmetadata

Definition at line 189 of file hardware.c.

References notification::_char, buffer_dec, buffer_empty, buffer_last, hw_notify(), HW_UART, and UART0_RX_BUFFER.

Referenced by hw_daemon().

189  {
190 
191  notification note;
192  /* get-it-working: assume the dev knows which buffer to use */
193  uint8_t* buffer = UART0_RX_BUFFER;
194  while(!buffer_empty(UART0_RX_BUFFER)) {
197  hw_notify(HW_UART, uart_metadata, note);
198  }
199 }
void hw_notify(HW_TYPE type, hw_metadata metadata, notification note)
Definition: hardware.c:149
static uint8_t UART0_RX_BUFFER[BUFFER_MAX_LENGTH]
Definition: hardware.c:38
#define buffer_last(buf)
Definition: buffer.h:55
#define buffer_empty(buf)
Definition: buffer.h:63
#define buffer_dec(buf)
Definition: buffer.h:39
char _char
Definition: notify.h:25

Here is the call graph for this function:

Here is the caller graph for this function:

void hw_unsubscribe ( HW_TYPE  ,
hw_metadata  ,
void(*)(notification note)  isr 
)

Unsubscribe from a hardware interrupt. This is also called disconnecting a signal (the isr in question) from a slot (the hw-triggered driver isr).

Parameters
Thehardware type in question
Metadataabout the device
Thepseudo-isr to be notified by the hardware driver

Definition at line 137 of file hardware.c.

References _hw_get_channel(), CDL_DELETE, CDL_PREPEND, hw_channel::free_slots, and hw_channel::full_slots.

Referenced by shell_kill().

139  {
140 
141  hw_channel* channel = _hw_get_channel(type, metadata);
142  _isr_subscription* remove = channel->full_slots;
143 
144  while(remove->slot != isr) {++remove;}
145  CDL_DELETE(channel->full_slots, remove);
146  CDL_PREPEND(channel->free_slots, remove);
147 }
_isr_subscription * free_slots
Definition: hardware.h:132
#define CDL_DELETE(head, del)
Definition: utlist.h:705
_isr_subscription * full_slots
Definition: hardware.h:133
hw_channel * _hw_get_channel(HW_TYPE type, hw_metadata metadata)
Definition: hardware.c:203
#define CDL_PREPEND(head, add)
Definition: utlist.h:671

Here is the call graph for this function:

Here is the caller graph for this function:

void TIMER0A_Handler ( void  )

TIMER0A isr responsible for notifying all subscriptions with information describing the interrupt.

This isr was generated automatically by bin/lisp/rtos-interrupt-generator.el

Definition at line 341 of file hardware.c.

References hw_notify(), HW_TIMER, notification_init, NULL, TIMER0_BASE, timer_metadata_init, TIMER_TIMA_TIMEOUT, and TimerIntClear().

341  {
342 
344  notification_init(int, 1);
346  hw_notify(HW_TIMER, timer_metadata, note);
347 }
void hw_notify(HW_TYPE type, hw_metadata metadata, notification note)
Definition: hardware.c:149
#define notification_init(_type, _value)
Definition: notify.h:45
#define TIMER0_BASE
Definition: hw_memmap.h:81
#define TIMER_TIMA_TIMEOUT
Definition: timer.h:135
void TimerIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
Definition: timer.c:1568
#define timer_metadata_init(_base, _frequency, _interrupt, _periodic)
Definition: timer.h:21
#define NULL
Definition: defines.h:32

Here is the call graph for this function:

void TIMER1A_Handler ( void  )

TIMER1A isr responsible for notifying all subscriptions with information describing the interrupt.

This isr was generated automatically by bin/lisp/rtos-interrupt-generator.el

Definition at line 355 of file hardware.c.

References hw_notify(), HW_TIMER, HWREG, jitter_begin, notification_init, NULL, NVIC_ST_CURRENT, TIMER1_BASE, timer_metadata_init, TIMER_TIMA_TIMEOUT, and TimerIntClear().

Referenced by __attribute__().

355  {
356 
359  notification_init(int, 1);
361  hw_notify(HW_TIMER, timer_metadata, note);
362 }
void hw_notify(HW_TYPE type, hw_metadata metadata, notification note)
Definition: hardware.c:149
#define notification_init(_type, _value)
Definition: notify.h:45
uint32_t jitter_begin
Definition: hardware.c:51
#define HWREG(x)
Definition: hw_types.h:48
#define TIMER_TIMA_TIMEOUT
Definition: timer.h:135
#define NVIC_ST_CURRENT
Definition: hw_nvic.h:52
#define TIMER1_BASE
Definition: hw_memmap.h:82
void TimerIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
Definition: timer.c:1568
#define timer_metadata_init(_base, _frequency, _interrupt, _periodic)
Definition: timer.h:21
#define NULL
Definition: defines.h:32

Here is the call graph for this function:

Here is the caller graph for this function:

void TIMER2A_Handler ( void  )

TIMER2A isr responsible for notifying all subscriptions with information describing the interrupt.

This isr was generated automatically by bin/lisp/rtos-interrupt-generator.el

Definition at line 370 of file hardware.c.

References hw_notify(), HW_TIMER, notification_init, NULL, TIMER2_BASE, timer_metadata_init, TIMER_TIMA_TIMEOUT, and TimerIntClear().

Referenced by __attribute__().

370  {
371 
373  notification_init(int, 1);
375  hw_notify(HW_TIMER, timer_metadata, note);
376 }
void hw_notify(HW_TYPE type, hw_metadata metadata, notification note)
Definition: hardware.c:149
#define notification_init(_type, _value)
Definition: notify.h:45
#define TIMER2_BASE
Definition: hw_memmap.h:83
#define TIMER_TIMA_TIMEOUT
Definition: timer.h:135
void TimerIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
Definition: timer.c:1568
#define timer_metadata_init(_base, _frequency, _interrupt, _periodic)
Definition: timer.h:21
#define NULL
Definition: defines.h:32

Here is the call graph for this function:

Here is the caller graph for this function:

void UART0_Handler ( void  )

UART0 isr responsible for notifying all subscriptions with information describing the interrupt.

Definition at line 254 of file hardware.c.

References buffer_add, buffer_dec, buffer_empty, buffer_full, HW_SEM_UART0, sem_post, UART0_BASE, UART0_RX_BUFFER, UART_INT_RT, UART_INT_RX, UART_INT_TX, UART_LAST_WAS_CR, UARTCharGetNonBlocking(), UARTCharPut(), UARTCharsAvail(), UARTIntClear(), and UARTIntStatus().

Referenced by __attribute__().

254  {
255 
256  bool post;
257  uint8_t recv;
258  /* Get and clear the current interrupt sources */
259  uint32_t interrupts = UARTIntStatus(UART0_BASE, true);
260  UARTIntClear(UART0_BASE, interrupts);
261 
262  /* Are we being interrupted because the TX FIFO has space available? */
263  if(interrupts & UART_INT_TX) {
264  /* Move as many bytes as we can into the transmit FIFO */
265  /* TODO: */
266  /* uart_prime_transmit(UART0_BASE); */
267  }
268 
269  /* Are we being interrupted due to a received character? */
270  if(interrupts & (UART_INT_RX | UART_INT_RT)) {
271  /* Get all available chars from the UART */
272  while(UARTCharsAvail(UART0_BASE)) {
273  recv = (unsigned char) (UARTCharGetNonBlocking(UART0_BASE) & 0xFF);
274 
275  /* optional: check for '@echo_off */
276 
277  /* Handle backspace by erasing the last character in the
278  * buffer */
279  switch(recv) {
280  case 127:
281  case '\b':
282  /* If there are any chars to delete, delete the last text */
284  /* Erase previous characters on the user's terminal */
285  /* UARTCharPut(UART0_BASE, '\b'); */
286  /* UARTCharPut(UART0_BASE, ' '); */
287  /* UARTCharPut(UART0_BASE, '\b'); */
288 
289  /* Decrement the number of chars in the buffer */
291  /* Skip ahead to next buffered char */
292  continue;
293  }
294  /* if it is empty, somebody is watching so pass along
295  * the backspace */
296  break;
297 
298  case '\r':
299  case '\n':
300  if(recv == '\r') {
301  UART_LAST_WAS_CR = true;
302  }
303  else if (UART_LAST_WAS_CR) {
304  UART_LAST_WAS_CR = false;
305  /* Don't react twice to a single newline */
306  continue;
307  }
308  case 0x1b:
309  /* Regardless of the newline received, our convention
310  * is to mark end-of-lines in a buffer with the CR
311  * character. */
312  recv = '\r';
313 
314  /* Echo the received character to the newline */
315  UARTCharPut(UART0_BASE, '\n');
316  break;
317 
318  default: break;
319  }
320 
321  post = !buffer_full(UART0_RX_BUFFER);
322  /* If there is room in the RX FIFO, store the char there,
323  * else dump it. optional: a circular buffer might keep
324  * more up-to-date data, considering this is a RTOS */
325  /* this could be cleaned up with error-catching in the buffer library */
326  if(post) {
329  }
330  }
331  }
332 }
#define UART_INT_RX
Definition: uart.h:69
static volatile semaphore_t HW_SEM_UART0
Definition: hardware.h:11
#define UART_INT_TX
Definition: uart.h:68
bool UARTCharsAvail(uint32_t ui32Base)
Definition: uart.c:1087
#define sem_post(sem)
void UARTIntClear(uint32_t ui32Base, uint32_t ui32IntFlags)
Definition: uart.c:1581
static uint8_t UART0_RX_BUFFER[BUFFER_MAX_LENGTH]
Definition: hardware.c:38
int32_t UARTCharGetNonBlocking(uint32_t ui32Base)
Definition: uart.c:1143
uint32_t UARTIntStatus(uint32_t ui32Base, bool bMasked)
Definition: uart.c:1533
#define buffer_add(buf, elt)
Definition: buffer.h:28
#define buffer_empty(buf)
Definition: buffer.h:63
#define buffer_full(buf)
Definition: buffer.h:59
#define UART0_BASE
Definition: hw_memmap.h:61
#define buffer_dec(buf)
Definition: buffer.h:39
void UARTCharPut(uint32_t ui32Base, unsigned char ucData)
Definition: uart.c:1268
static bool UART_LAST_WAS_CR
Definition: uart.h:17
#define UART_INT_RT
Definition: uart.h:67

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

uint32_t ADC0_SEQ0_SAMPLES[4]

Definition at line 44 of file hardware.c.

uint32_t ADC0_SEQ1_SAMPLES[4]

Definition at line 45 of file hardware.c.

uint32_t ADC0_SEQ2_SAMPLES[4]

Definition at line 46 of file hardware.c.

Referenced by ADC0Seq2_Handler(), display_adc_data_for_checkout(), and main().

uint32_t ADC0_SEQ3_SAMPLES[4]

Definition at line 47 of file hardware.c.

Referenced by ADC0Seq0_Handler(), ADC0Seq1_Handler(), and ADC0Seq3_Handler().

semaphore_t HW_ADC_SEQ2_SEM

Definition at line 49 of file hardware.c.

Referenced by ADC0Seq2_Handler(), display_adc_data_for_checkout(), and led_blink_green().

hw_driver HW_BUTTON_DRIVER
static

Definition at line 36 of file hardware.c.

Referenced by hw_driver_singleton().

hw_driver HW_TIMER_DRIVER
static

Definition at line 35 of file hardware.c.

Referenced by hw_driver_singleton().

hw_driver HW_UART_DRIVER
static

Definition at line 34 of file hardware.c.

Referenced by hw_driver_singleton().

uint32_t jitter_begin

Definition at line 51 of file hardware.c.

Referenced by TIMER1A_Handler().

uint32_t jitter_end

Definition at line 52 of file hardware.c.

Referenced by ADC0Seq2_Handler().

uint8_t UART0_RX_BUFFER[BUFFER_MAX_LENGTH]
static

Definition at line 38 of file hardware.c.

Referenced by hw_notify_uart(), and UART0_Handler().

uint8_t UART0_RX_BUFFER_SIZE = 0
static

Definition at line 39 of file hardware.c.

uint8_t UART0_TX_BUFFER[BUFFER_MAX_LENGTH]
static

Definition at line 41 of file hardware.c.

uint8_t UART0_TX_BUFFER_SIZE = 0
static

Definition at line 42 of file hardware.c.