summaryrefslogtreecommitdiff
path: root/src/mailbox.h
blob: e96a4ed62baeccb41d15f03566ebe4a1b95c89b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#pragma once

#include <stdint.h>

// 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);