From 55bcdf37342d782c723166de54ff031d09b1281f Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Wed, 15 Oct 2025 19:32:21 -0700 Subject: Clear framebuffer to pink --- src/mailbox.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/mailbox.c') diff --git a/src/mailbox.c b/src/mailbox.c index 310b2b1..fcad179 100644 --- a/src/mailbox.c +++ b/src/mailbox.c @@ -7,7 +7,9 @@ enum { - MAILBOX = 0xB880 // Mailbox address relative to MMIO base address. + MAILBOX = 0xB880, // Mailbox address relative to MMIO base address. + STATUS_EMPTY = 0x40000000, // Empty bit. + STATUS_FULL = 0x80000000, // Full bit. }; typedef uint32_t Message; @@ -21,7 +23,7 @@ static inline Message msg_make(uint8_t channel, volatile const void* data) { } typedef struct Mailbox { - Message inbox; // 0x00 + Message inbox; // 0x00 uint32_t unused_1; // 0x04 uint32_t unused_2; // 0x08 uint32_t unused_3; // 0x0C @@ -29,15 +31,15 @@ typedef struct Mailbox { uint32_t unused_5; // 0x14 uint32_t status; // 0x18 uint32_t unused_6; // 0x1C - Message outbox; // 0x20 + Message outbox; // 0x20 } Mailbox; static inline bool inbox_empty(const volatile Mailbox* pMailbox) { - return (pMailbox->status & 0x40000000) != 0; + return (pMailbox->status & STATUS_EMPTY) != 0; } static inline bool outbox_full(const volatile Mailbox* pMailbox) { - return (pMailbox->status & 0x80000000) != 0; + return (pMailbox->status & STATUS_FULL) != 0; } static volatile Mailbox* pMailbox; @@ -59,10 +61,15 @@ const Mail* mbox_read(uint8_t channel) { return (const Mail*)((uintptr_t)msg & ~0xf); } -void mbox_write(uint8_t channel, volatile const void* mail) { +uint32_t mbox_write(uint8_t channel, volatile const void* mail) { // Wait until the outbox is clear. while (outbox_full(pMailbox)); // Send the mail. pMailbox->outbox = msg_make(channel, mail); + // Wait for the response. + // Mailbox messages cannot be streamed anyway, so wait here so that the API + // does not allow the caller to write two messages in a row without waiting. + const Mail* response = mbox_read(channel); + return response->code; } -- cgit v1.2.3