Beginnings of motor control code.
#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;
* -----+---------
* R8 0 | 1 0
* 1 | 0 1
+ *
+ * equates to even parity?
*/
u8 R8 = (_io_ports[M6811_SCCR1] & M6811_R8)?1:0;
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;
/* 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;
}
void coin_cost(u16 cost) {
item_cost = cost;
+ while(coin_value); /* wait until coin mech cleared */
}
#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. */
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 */
+#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 */
+}
+
#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_ */
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);