EE445M RTOS
Taken at the University of Texas Spring 2015
hardware.h
Go to the documentation of this file.
1 /* -*- mode: c; c-basic-offset: 4; -*- */
2 #ifndef __HARDWARE__
3 #define __HARDWARE__
4 
5 #include <stdbool.h>
6 #include "libnotify/notify.h"
7 #include "libstd/nexus.h"
8 #include "libos/semaphore.h"
9 
10 /* TODO: Expand this for all devices */
11 static volatile semaphore_t HW_SEM_UART0;
12 
13 uint32_t* get_adc_samples();
14 /* Note to developers:
15  *
16  * Why did the authors create structs that contain only an array?
17  * Wouldn't it be easier to simply refer to the array instead of
18  * unwrapping it from the context of the struct each time it is
19  * invoked? You could even use a typedef to further shorten each invocation!
20  *
21  * Wisdom, thrown down from the mountain:
22  * http://stackoverflow.com/a/4523537 [quoted below]
23  *
24  * [An unwrapped array with a typedef for convenience] is probably a
25  * very bad idea, because the resulting type is an array type, but
26  * users of it won't see that it's an array type. If used as a
27  * function argument, it will be passed by reference, not by value,
28  * and the sizeof for it will then be wrong.
29  */
30 
31 /* A note about this library:
32  *
33  * This hardware driver interfaces between userspace programs and
34  * peripheral drivers. Users should never touch drivers directly but
35  * instead rely on libhw's notification system.
36  *
37  * todo for developers: update this after the impending redesign
38  */
39 
46 typedef enum {
51 } HW_TYPE;
52 
54 typedef struct {
55  uint32_t baud_rate;
57  uint32_t interrupt;
59 
60 /* todo: add union for timer_frequency or timer_period */
62 typedef struct {
65  uint32_t interrupt;
66  uint32_t periodic; /* TIMER_CFG_PERIODIC or TIMER_CFG_ONE_SHOT */
68 
70 typedef struct {
71  /* NOTE: base will be used in the future when we have buttons on
72  different ports */
75  uint32_t interrupt;
77 
78 typedef union {
81 
83 typedef struct {
84  /* NOTE: base will be used in the future when we have adcs on
85  different ports */
87  uint32_t trigger_source;
88  uint32_t sample_sequence;
89  uint32_t channel;
93 
96 typedef union {
101 } hw_metadata;
102 
105 typedef uint8_t hw_iterator;
106 
109 /* typedef void (*isr_t)(notification note); */
110 
112 #define HW_DRIVER_MAX_CHANNELS 8
113 
116 #define HW_DRIVER_MAX_SUBSCRIPTIONS 8
117 
124  void (*slot)(notification);
127 };
128 
130 typedef struct {
134 } hw_channel;
135 
137 typedef struct {
139 } hw_driver;
140 
143 #define hw_init(type, metadata) \
144  hw_driver_init(type, metadata); \
145  hw_channel_init(type, metadata)
146 
149 #define hw_init_and_subscribe(type, metadata, pseudo_isr) \
150  hw_init(type, metadata); \
151  hw_subscribe(type, metadata, pseudo_isr)
152 
154 void hw_init_daemon();
155 
161 
170 
178 #define hw_subscribe(type, metadata, isr) \
179  _hw_subscribe(type, metadata, isr, false)
180 
190 #define hw_subscribe_single_shot(type, metadata, isr) \
191  _hw_subscribe(type, metadata, isr, true)
192 
200 void _hw_subscribe(HW_TYPE, hw_metadata, void (*isr)(notification note), bool);
201 
209 void hw_unsubscribe(HW_TYPE, hw_metadata, void (*isr)(notification note));
210 
220 
227 
239 
244 void hw_notify_uart(hw_metadata uart_metadata);
245 
246 /* TODO: Doxygenize */
247 void hw_daemon(void);
248 
249 #endif
250 
uint32_t interrupt
Definition: hardware.h:57
uint32_t sample_sequence
Definition: hardware.h:88
static volatile semaphore_t HW_SEM_UART0
Definition: hardware.h:11
bool single_shot_subscription
Definition: hardware.h:123
memory_address_t base
Definition: hardware.h:86
void hw_notify(HW_TYPE, hw_metadata, notification)
Definition: hardware.c:149
adc_trigger_metadata trigger_metadata
Definition: hardware.h:91
void hw_init_daemon()
Definition: hardware.c:54
int8_t semaphore_t
hw_uart_metadata uart
Definition: hardware.h:97
hw_channel * _hw_get_channel(HW_TYPE, hw_metadata)
Definition: hardware.c:203
uint8_t hw_iterator
Definition: hardware.h:105
void(* slot)(notification)
Definition: hardware.h:124
memory_address_t channel
Definition: hardware.h:56
uint32_t * get_adc_samples()
uint32_t interrupt
Definition: hardware.h:75
_isr_subscription * prev
Definition: hardware.h:126
hw_timer_metadata timer
Definition: hardware.h:79
frequency_t frequency
Definition: hardware.h:64
_isr_subscription * next
Definition: hardware.h:125
void hw_notify_uart(hw_metadata uart_metadata)
Definition: hardware.c:189
uint32_t trigger_source
Definition: hardware.h:87
uint32_t interrupt
Definition: hardware.h:65
hw_button_metadata button
Definition: hardware.h:99
void hw_unsubscribe(HW_TYPE, hw_metadata, void(*isr)(notification note))
Definition: hardware.c:137
hw_driver * hw_driver_singleton(HW_TYPE)
Definition: hardware.c:220
memory_address_t pin
Definition: hardware.h:74
_isr_subscription * free_slots
Definition: hardware.h:132
memory_address_t base
Definition: hardware.h:63
#define HW_DRIVER_MAX_SUBSCRIPTIONS
Definition: hardware.h:116
hw_timer_metadata timer
Definition: hardware.h:98
uint32_t periodic
Definition: hardware.h:66
uint32_t channel
Definition: hardware.h:89
hw_adc_metadata adc
Definition: hardware.h:100
_isr_subscription * full_slots
Definition: hardware.h:133
HW_TYPE
Definition: hardware.h:46
void hw_driver_init(HW_TYPE, hw_metadata)
Definition: hardware.c:62
#define HW_DRIVER_MAX_CHANNELS
Definition: hardware.h:112
void hw_daemon(void)
Definition: hardware.c:172
void hw_channel_init(HW_TYPE, hw_metadata)
Definition: hardware.c:94
memory_address_t base
Definition: hardware.h:73
int32_t frequency_t
Definition: defines.h:24
int32_t memory_address_t
Definition: nexus.h:48
uint32_t channel_configuration
Definition: hardware.h:90
uint32_t baud_rate
Definition: hardware.h:55
void _hw_subscribe(HW_TYPE, hw_metadata, void(*isr)(notification note), bool)
Definition: hardware.c:121