diff options
Diffstat (limited to 'avr')
-rw-r--r-- | avr/cmd_sd.c | 8 | ||||
-rw-r--r-- | avr/gpio.c | 55 | ||||
-rw-r--r-- | avr/main.c | 15 | ||||
-rw-r--r-- | avr/mmc.c | 135 |
4 files changed, 118 insertions, 95 deletions
diff --git a/avr/cmd_sd.c b/avr/cmd_sd.c index f43725a..46dbcfd 100644 --- a/avr/cmd_sd.c +++ b/avr/cmd_sd.c @@ -330,18 +330,18 @@ CMD_TBL_ITEM( ), CMD_TBL_ITEM( dump, CONFIG_SYS_MAXARGS, 1, do_dump, - "Dump sector", - "" + "Dump sector(s)", + "<drive> [sector [count ]]" ), CMD_TBL_ITEM( read, 2, 1, do_read, "Read disk sector(s) into meomory", - "drive [sector [count [memaddr]]]" + "<drive> [sector [count [memaddr]]]" ), CMD_TBL_ITEM( write, 2, 1, do_write, "Write sector(s) from meomory to disk", - "drive [sector [count [memaddr]]]" + "<drive> [sector [count [memaddr]]]" ), CMD_TBL_ITEM( sync, 2, 1, do_ioctl_sync, @@ -7,36 +7,35 @@ /* -Pin Name Port Timer Mode max div max div min f [Hz] ----------------------------------------------------------------------------------- -0 PG5 OC0B PWM (2**8)*1024 262144 70.31 -1 PG4 -2 CLK2 PB4 OC2A Toggle (2**8)*1024*2 524288 35.16 -3 ZCLK PB5 OC1A PWM (2**16)*1024 67108864 0.2746 -4 PB6 OC1B PWM (2**16)*1024 67108864 0.2746 -5 PB7 OC0A Toggle (2**8)*1024*2 524288 35.16 -6 PG3 -7 PG2 -8 PG1 -9 PG0 -10 CLKO PE7 - - -pre Timer0 Timer1 Timer2 +Pin Name Port Timer Mode max div max div min f [Hz] +-------------------------------------------------------------------------------- +0 PG5 OC0B PWM (2**8)*1024 262144 70.31 +1 PG4 +2 CLK2 PB4 OC2A Toggle (2**8)*1024*2 524288 35.16 +3 ZCLK PB5 OC1A PWM (2**16)*1024 67108864 0.2746 +4 PB6 OC1B PWM (2**16)*1024 67108864 0.2746 +5 PB7 OC0A Toggle (2**8)*1024*2 524288 35.16 +6 PG3 +7 PG2 +8 PG1 +9 PG0 +10 CLKO PE7 +-------------------------------------------------------------------------------- + + +pre Timer0 Timer1 Timer2 -------------------------------------------------- -0 0 0 0 -1 1 1 1 -2 8 x8 8 x8 8 x8 -3 64 x8 64 x8 32 x4 -4 256 x4 256 x4 64 x2 -5 1024 x4 1024 x4 128 x2 -6 256 x2 -7 1024 x4 +0 0 0 0 +1 1 1 1 +2 8 x8 8 x8 8 x8 +3 64 x8 64 x8 32 x4 +4 256 x4 256 x4 64 x2 +5 1024 x4 1024 x4 128 x2 +6 256 x2 +7 1024 x4 -------------------------------------------------- - */ - #define PWMTOGGLE 0b01 #define PWMPOS 0b10 #define PWMNEG 0b11 @@ -312,7 +311,7 @@ int gpio_clockdiv_set(int pin, unsigned long divider) top = ltop - 1; - PING |= _BV(0); /* Debug */ +// PING |= _BV(0); /* Debug */ switch (timertype & TIMER) { case TIMER0: @@ -363,7 +362,7 @@ int gpio_clockdiv_set(int pin, unsigned long divider) break; } - PING |= _BV(0); /* Debug */ +// PING |= _BV(0); /* Debug */ gpio_config(pin, OUTPUT_TIMER); @@ -18,7 +18,6 @@ #include "cli.h" #include "env.h" #include "z180-serv.h" -#include "spi.h" #include "gpio.h" #include "time.h" #include "rtc.h" @@ -112,13 +111,6 @@ void setup_avr(void) TCCR3B = (0b01<<WGM32)|(0b001<<CS30); /* CTC Mode, Prescaler 1 */ TIMSK3 = _BV(OCIE3A); /* Enable TC2.oca interrupt */ - /* SPI as master */ - PRR0 &= ~_BV(PRSPI); - SPI_DDR = (SPI_DDR & ~_BV(SPI_MISO)) - | _BV(SPI_MOSI) | _BV(SPI_SCK) | _BV(SPI_SS); - SPI_PORT = (SPI_PORT & ~(_BV(SPI_MOSI) | _BV(SPI_SCK))) - | _BV(SPI_SS); - /* INT5, INT6: falling edge */ EICRB = (EICRB & ~((0b11 << ISC50) | (0b11 << ISC60))) | (0b10 << ISC50) | (0b10 << ISC60); @@ -240,10 +232,13 @@ void main_loop(void) int main(void) { - setup_avr(); - z80_setup_bus(); + extern void setup_mmc(void); + for (int i = 0; i < GPIO_MAX; i++) gpio_config(i, INPUT_PULLUP); + setup_avr(); + setup_mmc(); + z80_setup_bus(); env_init(); if (reset_reason_is_power_on()) @@ -17,25 +17,28 @@ /* Port Controls (Platform dependent) */ /* SD card socket connections */ -//#define SD_CD_0 SBIT(PORT,) /* Card detect switch */ +/* TODO: config.h cofig macros */ + +//#define SD_CD_0 SBIT(PORT,) /* Card detect switch */ //#define SD_CD_0_IN SBIT(PIN,) //#define SD_CD_0_DDR SBIT(DDR,) -//#define SD_WP_0 SBIT(PORT,) /* Write protect switch */ +//#define SD_WP_0 SBIT(PORT,) /* Write protect switch */ //#define SD_WP_0_IN SBIT(PIN,) //#define SD_WP_0_DDR SBIT(DDR,) -#define SD_CS_0 SBIT(PORTB,0) /* Chip select pin */ +#define SD_CS_0 SBIT(PORTB,0) /* Chip select pin */ #define SD_CS_0_IN SBIT(PINB,0) #define SD_CS_0_DDR SBIT(DDRB,0) -//#define SD_CD_1 SBIT(PORTG,3) /* Card detect switch */ + +//#define SD_CD_1 SBIT(PORTG,3) /* Card detect switch */ //#define SD_CD_1_IN SBIT(PING,3) //#define SD_CD_1_DDR SBIT(DDRG,3) -//#define SD_WP_1 SBIT(PORTG,5) /* Write protect switch */ -#define SD_WP_1_IN SBIT(PING,5) -#define SD_WP_1_DDR SBIT(DDRG,5) +//#define SD_WP_1 SBIT(PORTG,5) /* Write protect switch */ +//#define SD_WP_1_IN SBIT(PING,5) +//#define SD_WP_1_DDR SBIT(DDRG,5) #define SD_CS_1 SBIT(PORTG,4) /* Chip select pin */ #define SD_CS_1_IN SBIT(PING,4) @@ -43,7 +46,7 @@ #define SPI_CLK_SLOW() SPISetMMCInitClock() /* Set slow clock (100k-400k) */ -#define SPI_CLK_FAST() SPISetFastClock() /* Set fast clock (depends on the CSD) */ +#define SPI_CLK_FAST() SPISetFastClock() /* Set fast clock (depends on the CSD) */ /*-------------------------------------------------------------------------- Definitions for MMC/SDC command @@ -189,50 +192,18 @@ void power_on(BYTE drv) if (drv == 0) { #ifdef SD_PWR_0 - SD_PWR_0_DDR = 1; /* Turns on PWR pin as output */ SD_PWR_0 = 0; /* Drives PWR pin high */ - - for (uint32_t to = get_timer(0); get_timer(to) < 30;) - ; /* Wait for 30ms */ #endif -#ifdef SD_WP_0 - SD_WP_0_DDR = 0; - SD_WP_0 = 1; -#endif -#ifdef SD_CD_0 - /* Card detect, input with pullup */ - SD_CD_0_DDR = 0; - SD_CD_0 = 1; -#endif - SD_CS_0 = 1; - SD_CS_0_DDR = 1; } else { #ifdef SD_PWR_1 - SD_PWR_1_DDR = 1; /* Turns on PWR pin as output */ SD_PWR_1 = 0; /* Drives PWR pin high */ - +#endif + } +#if defined SD_PWR_0 || defined SD_PWR_1 for (uint32_t to = get_timer(0); get_timer(to) < 30;) ; /* Wait for 30ms */ #endif - -#ifdef SD_WP_1 - SD_WP_1_DDR = 0; - SD_WP_1 = 1; -#endif -#ifdef SD_CD_1 - /* Card detect, input with pullup */ - SD_CD_1_DDR = 0; - SD_CD_1 = 1; - SD_CS_1 = 1; - SD_CS_1_DDR = 1; -#else - /* Input, no pullup */ - SD_CS_1 = 0; - SD_CS_1_DDR = 0; -#endif - } - //debug("*** exit power_on()\n"); } @@ -410,6 +381,55 @@ BYTE send_cmd ( /* Returns R1 resp (bit7==1:Send failed) */ ---------------------------------------------------------------------------*/ +void setup_mmc(void) +{ +#ifdef SD_PWR_0 + SD_PWR_1 = 1; /* Drives PWR pin low */ + SD_PWR_0_DDR = 1; /* Turns on PWR pin as output */ +#endif +#ifdef SD_WP_0 + SD_WP_0_DDR = 0; + SD_WP_0 = 1; /* Pullup */ +#endif + +#ifdef SD_PWR_1 + SD_PWR_1 = 1; /* Drives PWR pin low */ + SD_PWR_1_DDR = 1; /* Turns on PWR pin as output */ +#endif +#ifdef SD_WP_1 + SD_WP_1_DDR = 0; + SD_WP_1 = 1; /* Pullup */ +#endif + + /* SPI as master */ + PRR0 &= ~_BV(PRSPI); + SPI_DDR = (SPI_DDR & ~(_BV(SPI_MISO) | _BV(SPI_SS))) + | _BV(SPI_MOSI) | _BV(SPI_SCK); + SPI_PORT = SPI_PORT & ~(_BV(SPI_MOSI) | _BV(SPI_SCK)); + +#if defined SD_CD_0 + SD_CD_0_DDR = 0; + SD_CD_0 = 1; +#elif defined SD_CS_0_IN + SD_CS_0_DDR = 0; + SD_CS_0 = 0; +#else + SD_CS_0_DDR = 1; + SD_CS_0 = 1; +#endif + +#if defined SD_CD_1 + SD_CD_1_DDR = 0; + SD_CD_1 = 1; +#elif defined SD_CS_1_IN + SD_CS_1_DDR = 0; + SD_CS_1 = 0; +#else + SD_CS_1_DDR = 1; + SD_CS_1 = 1; +#endif +} + /*-----------------------------------------------------------------------*/ /* Initialize Disk Drive */ /*-----------------------------------------------------------------------*/ @@ -715,34 +735,43 @@ void disk_timerproc (void) #ifdef SD_WP_0 if (SD_WP_0_IN == 0) /* Write protected */ s |= STA_PROTECT; - else /* Write enabled */ + else /* Write enabled */ s &= ~STA_PROTECT; #endif -#ifdef SD_CD_0 + +#if defined SD_CD_0 if (SD_CD_0_IN == 0) /* Card inserted */ s &= ~STA_NODISK; - else /* Socket empty */ + else /* Socket empty */ s |= (STA_NODISK | STA_NOINIT); +#elif defined SD_CS_0_IN + if (SD_CS_0_DDR == 0) { + if (SD_CS_0_IN == 1) /* Card inserted */ + s &= ~STA_NODISK; + else /* Socket empty */ + s |= (STA_NODISK | STA_NOINIT); + } #endif - socket[0].stat = s; /* Update MMC status */ + socket[0].stat = s; /* Update MMC status */ s = socket[1].stat; #ifdef SD_WP_1 if (SD_WP_1_IN == 0) /* Write protected */ s |= STA_PROTECT; - else /* Write enabled */ + else /* Write enabled */ s &= ~STA_PROTECT; #endif -#ifdef SD_CD_1 + +#if defined SD_CD_1 if (SD_CD_1_IN == 0) /* Card inserted */ s &= ~STA_NODISK; - else /* Socket empty */ + else /* Socket empty */ s |= (STA_NODISK | STA_NOINIT); -#else +#elif defined SD_CS_1_IN if (SD_CS_1_DDR == 0) { - if (SD_CS_1_IN == 1) /* Card inserted */ + if (SD_CS_1_IN == 1) /* Card inserted */ s &= ~STA_NODISK; - else /* Socket empty */ + else /* Socket empty */ s |= (STA_NODISK | STA_NOINIT); } #endif |