Blame
|
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 | ::: info |
||||||
|
6 | Note. if compiling for the 68000, you'll need to change the target cpu in `src/stdenv.mk` and `src/lib/Makefile` by changing the **CPU** macro. |
||||||
|
7 | ::: |
||||||
|
8 | To use the library, just include the following in your C sourcecode: |
||||||
| 9 | ```c |
|||||||
| 10 | #include <machine.h> |
|||||||
| 11 | ``` |
|||||||
|
12 | |||||||
| 13 | ## Serial I/O |
|||||||
| 14 | ||||||||
|
15 | ```C |
||||||
| 16 | int _char_available(void); |
|||||||
| 17 | char _getchar(void); |
|||||||
| 18 | void _putchar(char c); |
|||||||
| 19 | ``` |
|||||||
| 20 | ||||||||
|
21 | ## LED Control |
||||||
| 22 | 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: |
|||||||
|
23 | |||||||
|
24 | | LED # | Used for | |
||||||
| 25 | |:------|:---------| |
|||||||
| 26 | | 1 | Indicates that the board is being powered via an external 5v supply. | |
|||||||
| 27 | | 2 | Indicated that the board is being powered via the ATX power connector. | |
|||||||
| 28 | | 3 | Connected to the ~RTS pin on the duart channel B. | |
|||||||
| 29 | | 4 | Connected to the ~RTS pin on the duart channel A. | |
|||||||
| 30 | | 5 | Available to user. | |
|||||||
| 31 | | 6 | Available to user. | |
|||||||
| 32 | | 7 | Available to user. | |
|||||||
| 33 | | 8 | Available to user. | |
|||||||
| 34 | | 9 | Available to user. | |
|||||||
| 35 | | 10 | Available to user. | |
|||||||
|
36 | |||||||
| 37 | Two functions are provided, one to turn on a led, and another to turn it off. |
|||||||
| 38 | ||||||||
| 39 | ```C |
|||||||
| 40 | void set_led(int lednum); |
|||||||
| 41 | void clear_led(int lednum); |
|||||||
| 42 | ``` |
|||||||
| 43 | 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. |
|||||||
|
44 | |||||||
|
45 | ## PI/T |
||||||
| 46 | ||||||||
| 47 | ```C |
|||||||
| 48 | void _pit_reset(void); |
|||||||
| 49 | unsigned int _pit_get_counter(void); |
|||||||
| 50 | unsigned int _pit_set_counter(unsigned int); |
|||||||
| 51 | ``` |
|||||||
| 52 | ||||||||
|
53 | ## Compact Flash |
||||||
| 54 | ||||||||
| 55 | ```C |
|||||||
| 56 | void _cf_wait_busy(void); |
|||||||
| 57 | void _cf_wait_data(void); |
|||||||
| 58 | void cf_init(void); |
|||||||
| 59 | int cf_read(uint8_t drive_num, uint32_t sector, uint8_t *buffer); |
|||||||
| 60 | ||||||||
| 61 | ``` |
|||||||
|
62 | |||||||
| 63 | ## Vectors and Interrupts |
|||||||
| 64 | ||||||||
| 65 | ```C |
|||||||
|
66 | unsigned int *_get_vectors_base(void); |
||||||
|
67 | unsigned int get_isr_handler(int vector_number); |
||||||
| 68 | unsigned int set_isr_handler(int vector_number, void isr(void)); |
|||||||
|
69 | ``` |
||||||
|
70 | `_get_vectors_base()` return the contents of the `ivr` register on the 68030 or 0 on the 68000. |
||||||
|
71 | |||||||
|
72 | `get_isr_handler` returns the address of the handler currently configured to handle the exception specified by `vector_number`. |
||||||
|
73 | |||||||
|
74 | `set_isr_handler()` sets a handler for the exception specified by `vector_number`. It returns the address of the handler that it replaced. |
||||||
|
75 | |||||||
|
76 | ## `$I^2c$` Bus |
||||||
|
77 | |||||||
| 78 | ```C |
|||||||
| 79 | ``` |
|||||||
|
80 | |||||||
| 81 | ## Safe Memory Access |
|||||||
| 82 | ||||||||
| 83 | ```C |
|||||||
| 84 | int peek(uint8_t *addr); |
|||||||
| 85 | int poke(uint8_t *addr, uint8_t val); |
|||||||
| 86 | ``` |
|||||||
| 87 | `peek()` attempts to read a byte from memory, returning the value read, or -1 if the read failed due to a Bus Error. Similarly, `poke()` attempts to write a byte to memory, returning -1 on a Bus Error. |
|||||||