From a8a39ba24e36119dce48a01c2139e0e5a25674e1 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Tue, 25 Feb 2025 19:29:33 -0800 Subject: Add mailbox. --- src/mailbox.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/mailbox.h (limited to 'src/mailbox.h') 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 @@ +#pragma once + +#include + +// The channel takes the lower 4 bits; the data pointer the upper 28. So a mail +// must be aligned to a 16-byte boundary. +#define MAIL_ALIGN 16 + +enum +{ + PROPERTY_CHANNEL = 8, +}; + +typedef struct Tag { + union { + uint32_t all; + struct { + uint16_t command : 12; // Command. + uint8_t type : 4; // Command type. + uint8_t device : 4; // Hardware device. + uint16_t zeroes : 12; // Reserved. + } id; + }; + uint32_t size; // Buffer size. + uint32_t code; // Request/response code. + uint32_t data[1]; // Buffer data. +} Tag; + +typedef struct __attribute__((aligned(MAIL_ALIGN))) Mail { + uint32_t size; // Buffer size. + uint32_t code; // Request/response code. + Tag tags[1]; // Variable quantity. +} Mail; + +void mbox_init(); +const Mail* mbox_read(uint8_t channel); +void mbox_write(uint8_t channel, const void* mail); + -- cgit v1.2.3