Skip to content

Instantly share code, notes, and snippets.

@boochow
Last active July 6, 2018 22:49
Show Gist options
  • Save boochow/c63659c2a15d22ed58c62da17fff90d3 to your computer and use it in GitHub Desktop.
Save boochow/c63659c2a15d22ed58c62da17fff90d3 to your computer and use it in GitHub Desktop.
#define IOREG(X) (*(volatile uint32_t *) (X))
#define MAILBOX0_FIFO IOREG(0x2000B880)
#define MAILBOX0_POLL IOREG(0x2000B890)
#define MAILBOX0_SENDER IOREG(0x2000B894)
#define MAILBOX0_STATUS IOREG(0x2000B898)
#define MAILBOX0_CONFIG IOREG(0x2000B89C)
#define MAILBOX1_FIFO IOREG(0x2000B8A0)
#define MAILBOX1_POLL IOREG(0x2000B8B0)
#define MAILBOX1_SENDER IOREG(0x2000B8B4)
#define MAILBOX1_STATUS IOREG(0x2000B8B8)
#define MAILBOX1_CONFIG IOREG(0x2000B8BC)
#define MAIL_FULL 0x80000000
#define MAIL_EMPTY 0x40000000
void mailbox_write(uint8_t chan, uint32_t msg) {
if ((msg & 0xfU) == 0) {
while ((MAILBOX1_STATUS & MAIL_FULL) != 0) {
}
MAILBOX1_FIFO = msg | chan;
}
}
uint32_t mailbox_read(uint8_t chan) {
uint32_t data;
do {
while (MAILBOX0_STATUS & MAIL_EMPTY) {
}
} while (((data = MAILBOX0_FIFO) & 0xfU) != chan);
return data >> 4;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment