From: Bernard Blackham Date: Sun, 10 Aug 2003 16:22:38 +0000 (+0000) Subject: Lots of fixes. X-Git-Tag: ROMW~79 X-Git-Url: https://git.ucc.asn.au/?p=uccvend-snackrom.git;a=commitdiff_plain;h=c99662693a4d79f65d406473647debbd33ec521e Lots of fixes. Beginnings of motor control code. --- diff --git a/ROM2/coinmech.c b/ROM2/coinmech.c index b52559d..a6c0e51 100644 --- a/ROM2/coinmech.c +++ b/ROM2/coinmech.c @@ -3,15 +3,15 @@ #define COINMECH_ID 0x20 -u8 last_byte; -u8 packet_pos = 0; -u16 value_1 = 0; -u8 value_2 = 0; -u8 dec_point = 0; +volatile u8 last_byte; +volatile u8 packet_pos = 0; +volatile u16 value_1 = 0; +volatile u8 value_2 = 0; +volatile u8 dec_point = 0; -u16 coin_value = 0; +volatile u16 coin_value = 0; u8 item_cost = 0; -bool have_change = 0; +volatile bool have_change = 0; u8 parity_test(u8 c) { u8 parity = 0; @@ -31,6 +31,8 @@ bool parity_good(u8 c) { * -----+--------- * R8 0 | 1 0 * 1 | 0 1 + * + * equates to even parity? */ u8 R8 = (_io_ports[M6811_SCCR1] & M6811_R8)?1:0; @@ -48,12 +50,6 @@ void send_byte(u8 c) { bclr((void*)&_io_ports[M6811_SCCR1], M6811_T8); } -void ask_for_retrans() { - /* sends an 0xff down the line */ - send_byte(0xff); -} - - #define IS_CTRL(x) (x & 0x10) /* true if this packet is a control packet */ void sci_interrupt() { u8 in; @@ -62,7 +58,7 @@ void sci_interrupt() { /* test for framing errors & parity bit */ if (_io_ports[M6811_SCSR] & M6811_FE || !parity_good(in)) { _io_ports[M6811_SCDR]; /* read of register req'd to clear FE */ - ask_for_retrans(); + send_byte(0xff); /* request a retransmit */ return; } @@ -132,4 +128,5 @@ void coin_eat() { void coin_cost(u16 cost) { item_cost = cost; + while(coin_value); /* wait until coin mech cleared */ } diff --git a/ROM2/coinmech.h b/ROM2/coinmech.h index 8e8ad24..41f18ab 100644 --- a/ROM2/coinmech.h +++ b/ROM2/coinmech.h @@ -3,7 +3,7 @@ #include "vend.h" -extern u16 coin_value; +extern volatile u16 coin_value; void coin_eat(); void coin_cost(u16 cost); /* specify the cost of an item. */ diff --git a/ROM2/keypad.c b/ROM2/keypad.c index 433e78c..359e189 100644 --- a/ROM2/keypad.c +++ b/ROM2/keypad.c @@ -13,9 +13,9 @@ const u8 keymap1[3] = {KEY_RESET, KEY_0, KEY_9}; extern inline u8 keypad_read_row(u8 row) { u8 i, num; if (row) - _io_ports[M6811_PORTD] |= PORTD_KEYPAD_ROW; + bset((void*)&_io_ports[M6811_PORTD], PORTD_KEYPAD_ROW); else - _io_ports[M6811_PORTD] &= ~PORTD_KEYPAD_ROW; + bclr((void*)&_io_ports[M6811_PORTD], ~PORTD_KEYPAD_ROW); bclr_misc_output(A3800_DISPLAY_WRITE); /* disable the display clock */ diff --git a/ROM2/motors.c b/ROM2/motors.c index 80a11a7..4bb216b 100644 --- a/ROM2/motors.c +++ b/ROM2/motors.c @@ -1,2 +1,50 @@ +#include "motors.h" #include "vend.h" +void motor_on(u8 slot) { + /* from jump34 */ +} + +void motors_off() { + bset_changer_output(A3000_MOTOR_ROW_ENABLE); /* XXX active low? */ + delay(10); /* XXX cf motors_off */ + bset((void*)&_io_ports[M6811_PORTA], PORTA_MOTOR_COL_DISABLE); + bclr_misc_output(A3800_MOTOR_COL8_ENABLE | A3800_MOTOR_COL9_ENABLE); +} + +bool motor_here(u8 slot) { + int i, c = 0; + motor_on(slot); + for (i=0; i < 8; i++) { + if (_io_ports[M6811_PORTE] & PORTE_MOTOR_OVERVOLTAGE) { + c++; + if (c == 0xff) { + motors_off(); + return 1; + } else + continue; + } + } + motors_off(); + return 0; +} + +bool is_motor(u8 slot) { + /* FIXME */ + return 1; +} + +u8 dispense_motor(u8 slot) { + if (!is_motor(slot)) { + return MOTOR_NOSLOT; + } + + motor_on(slot); + /* FIXME */ + return MOTOR_SUCCESS; +} + +void scan_motors() { + /* FIXME */ +} + diff --git a/ROM2/motors.h b/ROM2/motors.h index c38e908..5598bec 100644 --- a/ROM2/motors.h +++ b/ROM2/motors.h @@ -1,8 +1,28 @@ #ifndef _MOTORS_H_ #define _MOTORS_H_ +#include "vend.h" + +/* error codes for dispense_motor */ +#define MOTOR_SUCCESS 0 +#define MOTOR_NOSLOT 1 + +const u8 motor_lookup[80] = +{ 1,12,23,34,46,57,68,79, + 11,22,33,44,56,67,78,89, + 21,32,43,54,66,77,88,99, + 31,42,53,64,76,87,98, + 9,41,52,63,74,86,97, + 8,19,51,62,73,84,96, + 7,18,29,61,72,83,94, + 6,17,28,39,71,82,93, + 4,16,27,38,49,81,92, + 3,14,26,37,48,59,91, + 2,13,24,36,47,58,69, +}; + bool is_motor(u8 slot); u8 dispense_motor(u8 slot); -bool scan_motors(); +void scan_motors(); #endif /* _MOTORS_H_ */ diff --git a/ROM2/vend.h b/ROM2/vend.h index bb39107..d3e6bf3 100644 --- a/ROM2/vend.h +++ b/ROM2/vend.h @@ -31,15 +31,24 @@ void delay(u16 ms); void print_amount(u16 amt); /******** Some meaningful bits ******/ -#define PORTA_DISP_RESET 0x80 /* active low */ #define PORTA_CHIME 0x10 /* chime is on when set */ +#define PORTA_MOTOR_COL_DISABLE 0x40 +#define PORTA_DISP_RESET 0x80 /* active low */ + #define PORTD_KEYPAD_ROW 0x20 /* clear for row 0, set for row 1 */ +#define PORTE_MOTOR_OVERVOLTAGE 0x02 + +/* Address 3000 bits */ +#define A3000_MOTOR_ROW_ENABLE 0x80 + /* Address 1800 bits */ #define A1800_DOOR_OPEN 0x20 /* Address 3800 bits */ #define A3800_DISPLAY_WRITE 0x04 +#define A3800_MOTOR_COL8_ENABLE 0x20 +#define A3800_MOTOR_COL9_ENABLE 0x40 /******* from main.c *******/ int __attribute__((noreturn)) main (void);