diff options
Diffstat (limited to 'src/mailbox.h')
| -rw-r--r-- | src/mailbox.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/mailbox.h b/src/mailbox.h new file mode 100644 index 0000000..e96a4ed --- /dev/null +++ b/src/mailbox.h | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <stdint.h> | ||
| 4 | |||
| 5 | // The channel takes the lower 4 bits; the data pointer the upper 28. So a mail | ||
| 6 | // must be aligned to a 16-byte boundary. | ||
| 7 | #define MAIL_ALIGN 16 | ||
| 8 | |||
| 9 | enum | ||
| 10 | { | ||
| 11 | PROPERTY_CHANNEL = 8, | ||
| 12 | }; | ||
| 13 | |||
| 14 | typedef struct Tag { | ||
| 15 | union { | ||
| 16 | uint32_t all; | ||
| 17 | struct { | ||
| 18 | uint16_t command : 12; // Command. | ||
| 19 | uint8_t type : 4; // Command type. | ||
| 20 | uint8_t device : 4; // Hardware device. | ||
| 21 | uint16_t zeroes : 12; // Reserved. | ||
| 22 | } id; | ||
| 23 | }; | ||
| 24 | uint32_t size; // Buffer size. | ||
| 25 | uint32_t code; // Request/response code. | ||
| 26 | uint32_t data[1]; // Buffer data. | ||
| 27 | } Tag; | ||
| 28 | |||
| 29 | typedef struct __attribute__((aligned(MAIL_ALIGN))) Mail { | ||
| 30 | uint32_t size; // Buffer size. | ||
| 31 | uint32_t code; // Request/response code. | ||
| 32 | Tag tags[1]; // Variable quantity. | ||
| 33 | } Mail; | ||
| 34 | |||
| 35 | void mbox_init(); | ||
| 36 | const Mail* mbox_read(uint8_t channel); | ||
| 37 | void mbox_write(uint8_t channel, const void* mail); | ||
| 38 | |||
