Message Integrity Checking
[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         volatile u8 a; \
15         extern inline void set_##a(u8 b) { a = b; _##a = b; } \
16         extern inline void bset_##a(const u8 m) { bset((void*)&a, m); _##a = a; } \
17         extern inline void bclr_##a(const u8 m) { bclr((void*)&a, m); _##a = a; }
18
19 buffered_addr(changer_output);
20 buffered_addr(misc_output);
21
22 extern volatile u8 _switch_input;
23 #define switch_input _switch_input
24 extern volatile u8 _misc_input;
25 #define misc_input _misc_input
26 extern volatile u8 _home_sensors;
27 #define home_sensors _home_sensors
28
29 #define is_standalone() (misc_input & 0x01) /* DIP sw 1 */
30 #define must_verify()   !(misc_input & 0x02) /* DIP sw 2 */
31
32 extern u16 _stack;
33 extern char _nvram[]; /* 2048 bytes of nvram! */
34 // uncomment for testing. char _nvram[20]; /* 2048 bytes of nvram! */
35 /* NVRAM map:
36  *
37  * START LEN
38  * 0x800 0x02  mic.h - current challenge
39  * 0x802 0x10  mic.h - current secret password
40  * 0x812
41  *
42  */
43
44 /******* from helpers.c *******/
45 void delay(u16 ms);
46 void my_strncpy(char* dst, char* src, u8 max_size); /* for null-term strings */
47 bool my_strncmp(char* a, char* b, u8 len);
48 void my_memcpy(char* dst, char* src, u8 size);
49 void my_memset(char* dst, u8 val, u16 count);
50 char* u82hex(u8 a);
51 u8 hex2u8(char msb, char lsb);
52 char nibble2hexchar(u8 b);
53 u8 hexchar2u8(char b);
54
55 /******** Some meaningful bits ******/
56 #define PORTA_CHIME         0x10 /* chime is on when set */
57 #define PORTA_MOTOR_CLOCK   0x20
58 #define PORTA_MOTOR_COL_DISABLE 0x40
59 #define PORTA_DISP_RESET    0x80 /* active low */
60
61 #define PORTD_KEYPAD_ROW    0x20 /* clear for row 0, set for row 1 */
62
63 #define PORTE_MOTOR_NOT_OVERCURRENT 0x01
64 #define PORTE_MOTOR_OVERVOLTAGE 0x02
65
66 /* Address 1800 bits */
67 #define A1800_DOOR_OPEN     0x20
68
69 /* Address 3000 bits */
70 #define A3000_MOTOR_ROW_DISABLE 0x80
71
72 /* Address 3800 bits */
73 #define A3800_KEYPAD_STROBE 0x04
74 #define A3800_DISPLAY_WRITE  0x08
75 #define A3800_MOTOR_DATA        0x10
76 #define A3800_MOTOR_COL8_ENABLE 0x20
77 #define A3800_MOTOR_COL9_ENABLE 0x40
78
79 /******* from main.c *******/
80 int __attribute__((noreturn)) main (void);
81 void __attribute__((interrupt)) rti (void);
82 void __attribute__((interrupt)) sci_interrupt_serial (void);
83 void __attribute__((interrupt)) sci_interrupt_coinmech (void);
84 void __attribute__((interrupt)) uart_interrupt (void);
85
86 /* other one liners */
87 extern inline bool door_open() { return switch_input & A1800_DOOR_OPEN; }
88 extern inline void spi_enable()  { bset((void*)&_io_ports[M6811_SPCR], M6811_SPE); }
89 extern inline void spi_disable() { bclr((void*)&_io_ports[M6811_SPCR], M6811_SPE); }
90
91 #endif /* _VEND_H_ */

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