X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=romdev;a=blobdiff_plain;f=fw%2Fsrc%2Fmain.c;h=1d248f29e9acfc12272e0f155131f096c48ec9b7;hp=c07b34e99258d3fd7fe3ea032c32369f6bf10e96;hb=a8c29255c8b1aefb89a67ea777ad06ad5ea42676;hpb=0d51712984ed7c2f32e29e325f93dd5d97fa3ce0 diff --git a/fw/src/main.c b/fw/src/main.c index c07b34e..1d248f2 100644 --- a/fw/src/main.c +++ b/fw/src/main.c @@ -34,6 +34,7 @@ static void end_prog(void); static void write_ram(uint16_t addr, uint8_t val); static uint8_t read_ram(uint16_t addr); static void set_data_bus(unsigned char val); +static void release_data_bus(void); static void set_addr_bus(uint16_t addr); static void sys_reset(void); static inline void iodelay(void); @@ -48,12 +49,12 @@ static unsigned char inp_cidx; int main(void) { - /* SPI (SS/MOSI/SCK) are outputs, as are the low 2 data bus bits */ - DDRB = PB_SS | PB_MOSI | PB_SCK | 3; + /* SPI (SS/MOSI/SCK) are outputs */ + DDRB = PB_SS | PB_MOSI | PB_SCK; PORTB = PB_SS; /* drive SS high when not in programming mode */ DDRC = 0xff; /* control signals are all outputs */ PORTC = PC_CS | PC_WE | PC_OE | PC_SYSRST; - DDRD = 0xff; /* always drive the (high bits of the) data bus */ + DDRD = 0; /* tri-state the data bus by default (high 6 bits, low 2 are in DDRB) */ PORTD = 0; /* disable all pullups */ @@ -184,6 +185,7 @@ static void write_ram(uint16_t addr, uint8_t val) iodelay(); PORTC |= PC_CS; PORTC |= PC_WE; + release_data_bus(); } static uint8_t read_ram(uint16_t addr) @@ -193,15 +195,24 @@ static uint8_t read_ram(uint16_t addr) PORTC |= PC_WE; PORTC &= ~(PC_CS | PC_OE); iodelay(); - val = (PORTD & 0xfe) | (PORTB & 3); + val = (PIND & 0xfc) | (PINB & 3); PORTC |= PC_CS | PC_OE; return val; } static void set_data_bus(unsigned char val) { - PORTB = (PORTB & 0xfe) | (val & 3); - PORTC = val; + /* drive the data bus */ + DDRD = 0xff; + DDRB |= 3; + PORTB = (PORTB & 0xfc) | (val & 3); + PORTD = val; +} + +static void release_data_bus(void) +{ + DDRD = 0; + DDRB &= 0xfc; } static void set_addr_bus(uint16_t addr)