From cef1445c4f1ebaa38f9e6561b4fd15f164a27dcd Mon Sep 17 00:00:00 2001 From: Bernard Blackham Date: Wed, 6 Aug 2003 09:43:50 +0000 Subject: [PATCH] Reworking of the assembly Start of keypad reading code --- ROM2/Makefile | 2 +- ROM2/asm.h | 35 +++++++++++++++++++---------------- ROM2/display.c | 4 ++-- ROM2/helpers.c | 7 ++++++- ROM2/keypad.c | 43 ++++++++++++++++++++++++++++++++++--------- ROM2/keypad.h | 7 +++++++ ROM2/vend.h | 13 ++++++------- 7 files changed, 75 insertions(+), 36 deletions(-) create mode 100644 ROM2/keypad.h diff --git a/ROM2/Makefile b/ROM2/Makefile index 7a4421e..949e801 100644 --- a/ROM2/Makefile +++ b/ROM2/Makefile @@ -6,7 +6,7 @@ OBJS = \ INCLUDES = vend.h -CFLAGS = -O3 -Wall -m68hc11 -mshort -Wall -Os -g0 \ +CFLAGS = -O3 -m68hc11 -mshort -Wall -Os -g0 \ -msoft-reg-count=0 -ffixed-z LDFLAGS = -m68hc11 -mshort -Wl,-m,m68hc11elfb \ diff --git a/ROM2/asm.h b/ROM2/asm.h index 0c9b7fa..3e8cc09 100644 --- a/ROM2/asm.h +++ b/ROM2/asm.h @@ -3,25 +3,28 @@ #include "types.h" -/* these would be inline functions, but gcc won't believe that mask is a constant - * when passed as a parameter +/* The "g" below really should be an "i", but gcc doesn't believe that it will + * always be an immediate value. Using "g" makes the compiler be quiet, but + * the assembler will fail if the value is not an immediate. */ -#define bset(addr, mask) \ - asm volatile ( \ - "ldx %0\n" \ - "bset 00,x,%1" \ - : /* outputs */ \ - : "p" (addr), "i" (mask) /* inputs */ \ - : "x" /* altered registers */ \ +extern inline void bset(void* addr, u8 mask) { + asm volatile ( + "ldx %0\n" + "bset 00,x,%1" + : /* outputs */ + : "p" (addr), "g" (mask) /* inputs */ + : "x" /* altered registers */ ); +} -#define bclr(addr, mask) \ - asm volatile ( \ - "ldx %0\n" \ - "bclr 00,x,%1" \ - : /* outputs */ \ - : "p" (addr), "i" (mask) /* inputs */ \ - : "x" /* altered registers */ \ +extern inline void bclr(void* addr, u8 mask) { + asm volatile ( + "ldx %0\n" + "bclr 00,x,%1" + : /* outputs */ + : "p" (addr), "g" (mask) /* inputs */ + : "x" /* altered registers */ ); +} #endif /* _ASM_H_ */ diff --git a/ROM2/display.c b/ROM2/display.c index 45b39fc..85582f3 100644 --- a/ROM2/display.c +++ b/ROM2/display.c @@ -50,9 +50,9 @@ void display_send_byte(char c) { #define DISPLAY_DELAY 100 /* ms to delay between ops - could be tweaked */ void display_reset() { /* lower the reset line for a while */ - bclr(&_io_ports[M6811_PORTA], PORTA_DISP_RESET); + bclr((void*)&_io_ports[M6811_PORTA], PORTA_DISP_RESET); delay(DISPLAY_DELAY); - bset(&_io_ports[M6811_PORTA], PORTA_DISP_RESET); + bset((void*)&_io_ports[M6811_PORTA], PORTA_DISP_RESET); spi_enable(); delay(DISPLAY_DELAY); diff --git a/ROM2/helpers.c b/ROM2/helpers.c index b44be32..07ab7f4 100644 --- a/ROM2/helpers.c +++ b/ROM2/helpers.c @@ -1,6 +1,11 @@ #include "vend.h" +#define DELAY_MAGIC 20 /* FIXME: number of loops required for ~ 1 millisecond */ void delay(u16 ms) { - /* FIXME fill me in */ + int i; + for (;ms;ms--) { + for (i=0;i>1, num++); + + return num; } +/* returns a key 0..9 or 11 for reset */ +void keypad_read() { + /* FIXME: need to do debouncing of some sort? */ + int key; + key = keypad_read_row(0); + if (!key) { + key = keypad_read_row(1); + curr_key = keymap0[key]; + } + curr_key = keymap1[key]; + + if (curr_key != last_key) { + last_key = curr_key; + } +} diff --git a/ROM2/keypad.h b/ROM2/keypad.h new file mode 100644 index 0000000..d7a5382 --- /dev/null +++ b/ROM2/keypad.h @@ -0,0 +1,7 @@ +#ifndef _KEYPAD_H_ +#define _KEYPAD_H_ + +extern u8 last_key; +extern u8 curr_key; + +#endif /* _KEYPAD_H_ */ diff --git a/ROM2/vend.h b/ROM2/vend.h index 9e01aaa..a756e25 100644 --- a/ROM2/vend.h +++ b/ROM2/vend.h @@ -5,16 +5,16 @@ #include "types.h" #include "asm.h" -/* addresses of these set at link time */ -/* to add more addresses, define them here with buffered_addr_h, in helpers.c +/* addresses of these set at link time + * to add more addresses, define them here with buffered_addr_h, in helpers.c * with buffered_addr, and also in LDFLAGS in the Makefile */ #define buffered_addr(a) \ extern volatile u8* _##a; \ u8 a; \ extern inline void set_##a(u8 b) { a = *_##a = b; } \ - extern inline void bset_##a(u8 m) { a |= m; *_##a = a; } \ - extern inline void bclr_##a(u8 m) { a &= ~m ; *_##a = a; } + extern inline void bset_##a(const u8 m) { bset(&a, m); *_##a = a; } \ + extern inline void bclr_##a(const u8 m) { bclr(&a, m); *_##a = a; } buffered_addr(switch_input); buffered_addr(misc_input); @@ -22,11 +22,10 @@ buffered_addr(home_sensors); buffered_addr(changer_output); buffered_addr(misc_output); -extern inline void spi_enable() { _io_ports[M6811_SPCR] |= M6811_SPE; } -extern inline void spi_disable() { _io_ports[M6811_SPCR] &= ~M6811_SPE; } +extern inline void spi_enable() { bset((void*)&_io_ports[M6811_SPCR], M6811_SPE); } +extern inline void spi_disable() { bclr((void*)&_io_ports[M6811_SPCR], M6811_SPE); } /******* from helpers.c *******/ - void delay(u16 ms); /******** Some meaningful bits ******/ -- 2.20.1