-
Notifications
You must be signed in to change notification settings - Fork 6
/
microbian.h
147 lines (114 loc) · 3.87 KB
/
microbian.h
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* microbian.h */
/* Copyright (c) 2018 J. M. Spivey */
typedef unsigned char byte;
#define NULL ((void *) 0)
/* Standard pids */
#define HARDWARE -1
#define IDLE 0
/* Common message types */
#define INTERRUPT 1
#define REPLY 2
#define TIMEOUT 3
#define REGISTER 4
#define PING 5
#define REQUEST 6
#define READ 7
#define WRITE 8
#define OK 9
#define ERR 10
#define SEND 11
#define RECEIVE 12
#define ANY -1
/* Possible priorities */
#define P_HANDLER 0 /* Interrupt handler */
#define P_HIGH 1 /* Responsive */
#define P_LOW 2 /* Normal */
#define P_IDLE 3 /* The idle process */
#define NPRIO 3 /* Number of non-idle priorities */
typedef struct { /* 16 bytes */
unsigned short type; /* Type of message */
unsigned short sender; /* PID of sender */
union { /* An integer, a pointer, or four bytes */
int int1; void *ptr1;
struct { byte byte1, byte2, byte3, byte4; };
};
union { int int2; void *ptr2; }; /* Another integer or pointer */
union { int int3; void *ptr3; }; /* A third integer or pointer */
} message;
/* microbian.c */
/* start -- create process that will run when init returns; return PID */
int start(char *name, void (*body)(int), int arg, int stksize);
#define STACK 1024 /* Default stack size */
/* SYSTEM CALLS */
/* yield -- voluntarily allow other processes to run */
void yield(void);
/* send -- send a message */
void send(int dst, message *msg);
void send_msg(int dst, int type);
void send_int(int dst, int type, int val);
void send_ptr(int dst, int type, void *ptr);
/* receive -- receive a message */
void receive(int type, message *msg);
/* receive_t -- receive a message with timeout */
void receive_t(int type, message *msg, int timeout);
/* sendrec -- send followed by receive */
void sendrec(int dst, message *msg);
/* connect -- register to receive interrupt messages */
void connect(int irq);
/* priority -- set process priority */
void priority(int p);
/* exit -- terminate current process */
void exit(void);
/* dump -- print table of process states (called from serial) */
void dump(void);
/* tick -- process clock tick for timeouts */
void tick(int ms);
/* interrupt -- send interrupt message from handler */
void interrupt(int pid);
/* kprintf -- print message on console without using serial task */
void kprintf(char *fmt, ...);
/* panic -- crash with message and show seven stars */
void panic(char *fmt, ...);
/* badmesg -- panic after receiving unexpected message */
void badmesg(int type);
/* assert -- check assertion and panic if false */
#define assert(p) \
if (!(p)) panic("File %s, line %d: assertion %s failed", \
__FILE__, __LINE__, #p)
/* spin -- flash the seven stars of death forever */
void spin(void);
/* serial.c */
void serial_putc(char ch);
char serial_getc(void);
void serial_init(void);
/* timer.c */
void timer_delay(int msec);
void timer_pulse(int msec);
void timer_wait(void);
unsigned timer_now(void);
unsigned timer_micros(void);
void timer_init(void);
/* i2c.c */
int i2c_probe(int chan, int addr);
int i2c_read_reg(int chan, int addr, int cmd);
void i2c_write_reg(int chan, int addr, int cmd, int val);
void i2c_read_bytes(int chan, int addr, int cmd, byte *buf, int n);
void i2c_write_bytes(int chan, int addr, int cmd, byte *buf, int n);
int i2c_xfer(int chan, int kind, int addr,
byte *buf1, int n1, byte *buf2, int n2);
void i2c_init(int chan);
/* radio.c */
#define RADIO_PACKET 128
void radio_group(int group);
void radio_send(void *buf, int n);
int radio_receive(void *buf);
void radio_init(void);
/* display.c */
void display_show(const unsigned *img);
void display_init(void);
extern const unsigned blank[];
void image_clear(unsigned *img);
void image_set(int x, int y, unsigned *img);
/* adc.c */
int adc_reading(int pin);
void adc_init(void);