diff options
Diffstat (limited to 'avr')
-rw-r--r-- | avr/Tupfile | 2 | ||||
-rw-r--r-- | avr/cmd_date.c | 35 | ||||
-rw-r--r-- | avr/i2c.c | 32 | ||||
-rw-r--r-- | avr/main.c | 8 | ||||
-rw-r--r-- | avr/pcf8583.c | 22 | ||||
-rw-r--r-- | avr/serial.c | 8 |
6 files changed, 45 insertions, 62 deletions
diff --git a/avr/Tupfile b/avr/Tupfile index d0bed48..61cb577 100644 --- a/avr/Tupfile +++ b/avr/Tupfile @@ -14,7 +14,7 @@ SRC_Z = ../z180/hdrom.c MCU_TARGET = atmega1281 F_CPU = 18432000UL -DEFS = -DF_CPU=$(F_CPU) -DBAUD=115200UL +DEFS = -DF_CPU=$(F_CPU) INCLUDES += -I$(TOP)/include diff --git a/avr/cmd_date.c b/avr/cmd_date.c index bc93efc..2396783 100644 --- a/avr/cmd_date.c +++ b/avr/cmd_date.c @@ -31,26 +31,21 @@ command_ret_t do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) switch (argc) { case 2: /* set date & time */ - if (strcmp_P(argv[1],PSTR("reset")) == 0) { - my_puts_P(PSTR("Reset RTC...\n")); - rtc_reset (); - } else { - /* initialize tm with current time */ - rcode = rtc_get (&tm); - - if(!rcode) { - /* insert new date & time */ - if (mk_date (argv[1], &tm) != 0) { - my_puts_P(PSTR("## Bad date format\n")); - break; - } - /* and write to RTC */ - rcode = rtc_set (&tm); - if(rcode) - my_puts_P(PSTR("## Set date failed\n")); - } else { - my_puts_P(PSTR("## Get date failed\n")); + /* initialize tm with current time */ + rcode = rtc_get (&tm); + + if(!rcode) { + /* insert new date & time */ + if (mk_date (argv[1], &tm) != 0) { + my_puts_P(PSTR("## Bad date format\n")); + break; } + /* and write to RTC */ + rcode = rtc_set (&tm); + if(rcode) + my_puts_P(PSTR("## Set date failed\n")); + } else { + my_puts_P(PSTR("## Get date failed\n")); } /* FALL TROUGH */ case 1: /* get date & time */ @@ -60,7 +55,7 @@ command_ret_t do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) my_puts_P(PSTR("## Get date failed\n")); break; } - /* TODO: flash */ + /* TODO: put weekdays[] in flash */ printf_P(PSTR("Date: %4d-%02d-%02d (%sday) Time: %2d:%02d:%02d\n"), tm.tm_year, tm.tm_mon, tm.tm_mday, (tm.tm_wday<0 || tm.tm_wday>6) ? @@ -13,9 +13,11 @@ #include "debug.h" #include "i2c.h" -#ifdef DEBUG -//# define DEBUG_I2C -#endif +#define DEBUG_I2C 0 + +#define debug_i2c(fmt, args...) \ + debug_cond(DEBUG_I2C, fmt, ##args) + /* General TWI Master status codes */ #define TWI_START 0x08 /* START has been transmitted */ @@ -205,9 +207,7 @@ ISR(TWI_vect) xmit.stat = tmp_stat; xmit.idx = tmp_idx; -#ifdef DEBUG_I2C - debug("|%02x", twsr); -#endif + debug_i2c("|%02x", twsr); TWCR = next_twcr; } @@ -226,7 +226,7 @@ static void _init(void) /* (Reset TWI hardware state machine.) */ TWCR = TWI_C_DISABLE; _delay_us(5); -#ifdef DEBUG_I2C +#if DEBUG_I2C memset((void *) xmit.buf, 0xdf, sizeof(xmit.buf)); #endif @@ -248,10 +248,6 @@ void i2c_init(uint32_t speed) debug_cond((twps > 3), "*** TWCLK too low: %lu Hz\n", speed); twbr = (uint8_t) tmp_twbr; - - debug("*** i2c_init: i2c_speed: %lu, twbr: %u, twps: %u\n", - speed, twbr, twps); - _init(); } @@ -270,14 +266,14 @@ int_fast8_t i2c_waitready(void) xmit.stat |= timeout; -#ifdef DEBUG_I2C +#if DEBUG_I2C dump_ram((uint8_t *) &xmit, 4, "=== i2c_wait ready: (done)"); _delay_ms(30); #endif return xmit.stat; } -//static +static int i2c_send(uint8_t chip, uint16_t addr, uint8_t alen, uint8_t *buffer, int8_t len) { uint8_t i, n; @@ -297,7 +293,7 @@ int i2c_send(uint8_t chip, uint16_t addr, uint8_t alen, uint8_t *buffer, int8_t xmit.buf[i] = *buffer++; xmit.len = i; -#ifdef DEBUG_I2C +#if DEBUG_I2C dump_ram((uint8_t *) &xmit, 0x20, "=== i2c_send"); _delay_ms(30); #endif @@ -309,7 +305,7 @@ int i2c_send(uint8_t chip, uint16_t addr, uint8_t alen, uint8_t *buffer, int8_t return rc; } -//static +static int i2c_recv(uint8_t chip, uint8_t *buffer, int8_t len) { uint8_t rc; @@ -322,7 +318,7 @@ int i2c_recv(uint8_t chip, uint8_t *buffer, int8_t len) xmit.len = len + 1; xmit.buf[0] = (chip<<1) | 1; -#ifdef DEBUG_I2C +#if DEBUG_I2C dump_ram((uint8_t *) &xmit, 0x20, "=== i2c_recv: before start"); _delay_ms(30); #endif @@ -330,7 +326,7 @@ int i2c_recv(uint8_t chip, uint8_t *buffer, int8_t len) TWCR = (1<<TWEN)|(1<<TWIE)|(1<<TWINT)|(1<<TWSTA); rc = i2c_waitready(); -#ifdef DEBUG_I2C +#if DEBUG_I2C dump_ram((uint8_t *) &xmit, 0x20, "=== i2c_recv: after completion"); _delay_ms(30); #endif @@ -369,7 +365,6 @@ int i2c_write(uint8_t chip, unsigned int addr, uint_fast8_t alen, i2c_send(chip, addr, alen, buffer, len); rc = i2c_waitready(); - debug("** i2c_write: result=0x%02x\n",rc); return (rc & XMIT_DONE) != 0; } @@ -389,7 +384,6 @@ int i2c_read(uint8_t chip, unsigned int addr, uint_fast8_t alen, i2c_send(chip, addr, alen, NULL, 0); } rc = i2c_recv(chip, buffer, len); - debug("** i2c_read: result=0x%02x\n",rc); return !((rc & (XMIT_DONE|DATA_ACK)) == (XMIT_DONE|DATA_ACK)); } @@ -203,10 +203,12 @@ int main(void) setup_avr(); z80_setup_bus(); + env_init(); + if (reset_reason_is_power_on()) - _delay_ms(CONFIG_POWRON_DELAY); + _delay_ms(CONFIG_PWRON_DELAY); - serial_setup(); + serial_setup(getenv_ulong("baudrate", 10, CONFIG_BAUDRATE)); sei(); #if DEBUG @@ -214,8 +216,6 @@ int main(void) print_reset_reason(); #endif - env_init(); - #if DEBUG unsigned long i_speed = getenv_ulong("i2c_clock", 10, CONFIG_SYS_I2C_CLOCK); debug("### Setting I2C clock Frequency to %lu Hz.\n", i_speed); diff --git a/avr/pcf8583.c b/avr/pcf8583.c index d33c9b0..af1331d 100644 --- a/avr/pcf8583.c +++ b/avr/pcf8583.c @@ -2,8 +2,6 @@ * Date & Time support for Philips PCF8583 RTC */ -/* #define DEBUG */ - #include "common.h" #include <stdlib.h> #include "debug.h" @@ -11,6 +9,11 @@ #include "rtc.h" #include "i2c.h" +#define DEBUG_RTC 0 + +#define debug_rtc(fmt, args...) \ + debug_cond(DEBUG_RTC, fmt, ##args) + #define REG_CS 0x00 /* control/status */ #define REG_CSEC 0x01 /* hundredth of a second */ #define REG_SEC 0x02 /* seconds */ @@ -45,7 +48,7 @@ int rtc_get (struct rtc_time *tmp) i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, rtcbuf, NR_OF_REGS); i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0x10, 1, (uint8_t *) &year, 2); - debug("Get RTC year: %u, year/date: %02x, wdays/month: %02x, " + debug_rtc("Get RTC year: %u, year/date: %02x, wdays/month: %02x, " "hour: %02x, min: %02x, sec: %02x, (stat: %02x)\n", year, rtcbuf[6], rtcbuf[5], rtcbuf[4], rtcbuf[3], rtcbuf[2], rtcbuf[0]); @@ -64,7 +67,7 @@ int rtc_get (struct rtc_time *tmp) tmp->tm_isdst= 0; - debug ( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", + debug_rtc( "Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); @@ -75,7 +78,7 @@ int rtc_set (struct rtc_time *tmp) { uint8_t rtcbuf[NR_OF_REGS]; - debug ( "Set DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", + debug_rtc("Set DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n", tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_wday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); @@ -95,12 +98,3 @@ int rtc_set (struct rtc_time *tmp) return 0; } - -void rtc_reset (void) -{ - uint8_t c = 0; - - i2c_write(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, &c, 1); -} - - diff --git a/avr/serial.c b/avr/serial.c index b2fea51..a5e2846 100644 --- a/avr/serial.c +++ b/avr/serial.c @@ -36,7 +36,7 @@ uint8_t tx_ring_buffer[BUFFER_SIZE]; /* Initialize UART */ -void usart0_setup(void) { +void usart0_setup(unsigned long baud) { ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { @@ -48,7 +48,7 @@ void usart0_setup(void) { ring_init(&tx_ring, tx_ring_buffer, BUFFER_SIZE); UCSR0A = 0; - UBRR0 = F_CPU / BAUD / 16 - 1; + UBRR0 = F_CPU / baud / 16 - 1; UCSR0B = _BV(RXCIE0) | _BV(RXEN0) | _BV(TXEN0); UCSR0C = 3 << UCSZ00; }; @@ -82,10 +82,10 @@ ISR(USART0_UDRE_vect) /*--------------------------------------------------------------------------*/ -void serial_setup(void) +void serial_setup(unsigned long baud) { stdout = &mystdout; - usart0_setup(); + usart0_setup(baud); } /*--------------------------------------------------------------------------*/ |