Enough wacky little fixes to get motors turning and keypad functional.
[uccvend-snackrom.git] / ROM2 / vend.h
1 #ifndef _VEND_H_
2 #define _VEND_H_
3
4 #include "ports.h"
5 #include "types.h"
6 #include "asm.h"
7
8 /* addresses of these set at link time
9  * to add more addresses, define them here with buffered_addr_h, in helpers.c 
10  * with buffered_addr, and also in LDFLAGS in the Makefile
11  */
12 #define buffered_addr(a) \
13         extern volatile u8 _##a;          \
14         u8 a; \
15         extern inline void set_##a(u8 b) { a = b; _##a = b; } \
16         extern inline void bset_##a(const u8 m) { \
17                 bset(&a, m); \
18                 asm volatile ( "ldab %1\nstab %0\n" \
19                                 : "=m"(_##a) : "m"(a) : "d"); } \
20         extern inline void bclr_##a(const u8 m) { \
21                 bclr(&a, m); \
22                 asm volatile ( "ldab %1\nstab %0\n" \
23                                 : "=m"(_##a) : "m"(a) : "d"); }
24
25 buffered_addr(changer_output);
26 buffered_addr(misc_output);
27
28 extern volatile u8 _switch_input;
29 #define switch_input _switch_input
30 extern volatile u8 _misc_input;
31 #define misc_input _misc_input
32 extern volatile u8 _home_sensors;
33 #define home_sensors _home_sensors
34
35 extern u16 _stack;
36
37 /******* from helpers.c *******/
38 void delay(u16 ms);
39 void my_strncpy(char* dst, char* src, u8 max_size); /* for null-term strings */
40 void my_memcpy(char* dst, char* src, u8 size);
41
42 /******** Some meaningful bits ******/
43 #define PORTA_CHIME         0x10 /* chime is on when set */
44 #define PORTA_MOTOR_CLOCK   0x20
45 #define PORTA_MOTOR_COL_DISABLE 0x40
46 #define PORTA_DISP_RESET    0x80 /* active low */
47
48 #define PORTD_KEYPAD_ROW    0x20 /* clear for row 0, set for row 1 */
49
50 #define PORTE_MOTOR_OVERCURRENT 0x01
51 #define PORTE_MOTOR_OVERVOLTAGE 0x02
52
53 /* Address 1800 bits */
54 #define A1800_DOOR_OPEN     0x20
55
56 /* Address 3000 bits */
57 #define A3000_MOTOR_ROW_DISABLE 0x80
58
59 /* Address 3800 bits */
60 #define A3800_KEYPAD_STROBE 0x04
61 #define A3800_DISPLAY_WRITE  0x08
62 #define A3800_MOTOR_DATA        0x10
63 #define A3800_MOTOR_COL8_ENABLE 0x20
64 #define A3800_MOTOR_COL9_ENABLE 0x40
65
66 /******* from main.c *******/
67 int __attribute__((noreturn)) main (void);
68 void __attribute__((interrupt)) rti (void);
69 void __attribute__((interrupt)) sci_interrupt (void);
70 void __attribute__((interrupt)) uart_interrupt (void);
71
72 /* other one liners */
73 extern inline bool door_open() { return switch_input & A1800_DOOR_OPEN; }
74 extern inline void spi_enable()  { bset((void*)&_io_ports[M6811_SPCR], M6811_SPE); }
75 extern inline void spi_disable() { bclr((void*)&_io_ports[M6811_SPCR], M6811_SPE); }
76
77 #endif /* _VEND_H_ */

UCC git Repository :: git.ucc.asn.au