Blame

ebe99f Bob Green 2026-03-19 08:31:29
1
# Machine Library
2
3
I've created a library targeting the hardware specific aspects of programming the Sbc-3. I believe that it should work with the other boards from [Mega Micros](https://mega-micros.co.uk/index.htm), but since I don't have access to anything but the Sbc-3, can't confirm that.
4
5
To use the library, just include the following in your C sourcecode:
6
```c
7
#include <machine.h>
8
```
2a20d4 Bob Green 2026-03-21 15:03:23
9
10
## Serial I/O
11
b26e81 Bob Green 2026-03-21 15:10:58
12
```C
13
int _char_available(void);
14
char _getchar(void);
15
void _putchar(char c);
16
```
17
2a20d4 Bob Green 2026-03-21 15:03:23
18
## LED Control
19
There's a block of 10 leds (LD7 on the SBC3-b3), and six of them can be used for anything you like. Led1 is furthest from the cpu:
d90362 Bob Green 2026-03-21 15:03:37
20
2a20d4 Bob Green 2026-03-21 15:03:23
21
| LED # | Used for |
22
|:------|:---------|
23
| 1 | Indicates that the board is being powered via an external 5v supply. |
24
| 2 | Indicated that the board is being powered via the ATX power connector. |
25
| 3 | Connected to the ~RTS pin on the duart channel B. |
26
| 4 | Connected to the ~RTS pin on the duart channel A. |
27
| 5 | Available to user. |
28
| 6 | Available to user. |
29
| 7 | Available to user. |
30
| 8 | Available to user. |
31
| 9 | Available to user. |
32
| 10 | Available to user. |
91e139 Bob Green 2026-03-21 15:06:40
33
34
Two functions are provided, one to turn on a led, and another to turn it off.
35
36
```C
37
void set_led(int lednum);
38
void clear_led(int lednum);
39
```
40
Where `lednum` is an integer in the range of 5 through to 10, as per the table above. Any other value will be silently ignored.
0c5486 Bob Green 2026-03-24 15:10:57
41
b69dc8 Bob Green 2026-03-24 15:11:57
42
## PI/T
43
44
```C
45
void _pit_reset(void);
46
unsigned int _pit_get_counter(void);
47
unsigned int _pit_set_counter(unsigned int);
48
```
49
0c5486 Bob Green 2026-03-24 15:10:57
50
## Compact Flash
51
52
```C
53
void _cf_wait_busy(void);
54
void _cf_wait_data(void);
55
void cf_init(void);
56
int cf_read(uint8_t drive_num, uint32_t sector, uint8_t *buffer);
57
58
```
d83b67 Bob Green 2026-03-24 15:21:18
59
60
## Vectors and Interrupts
61
62
```C
9463ec Bob Green 2026-03-24 15:22:39
63
unsigned int *_get_vectors_base(void);
fc90ec Bob Green 2026-03-29 13:27:43
64
unsigned int get_isr_handler(int vector_number);
65
unsigned int set_isr_handler(int vector_number, void isr(void));
d83b67 Bob Green 2026-03-24 15:21:18
66
```
633040 Bob Green 2026-03-24 15:33:07
67
f01b84 Bob Green 2026-03-24 15:41:57
68
## `$I^2c$` Bus
633040 Bob Green 2026-03-24 15:33:07
69
70
```C
71
```