]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
use env var 'baudrate'
authorLeo C <erbl259-lmu@yahoo.de>
Sun, 24 Aug 2014 21:22:58 +0000 (23:22 +0200)
committerLeo C <erbl259-lmu@yahoo.de>
Sun, 24 Aug 2014 21:22:58 +0000 (23:22 +0200)
avr/Tupfile
avr/cmd_date.c
avr/i2c.c
avr/main.c
avr/pcf8583.c
avr/serial.c
include/config.h
include/rtc.h
include/serial.h

index d0bed48da3f95ac109844329b4035caeab0d4323..61cb577024655ecfb11b874d5d0c89d741a2280b 100644 (file)
@@ -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
 
index bc93efc33280c2f1db03ee845f79fcaf8a4d2a20..2396783812844c1f4116c4cd1bc083f407829ba7 100644 (file)
@@ -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) ?
index 3ab222aebc50dcbf0d60822738bb80d34c11668f..5d414afc6964079b9b949ac907dca203eb3e76e5 100644 (file)
--- a/avr/i2c.c
+++ b/avr/i2c.c
 #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));
 }
index fb4e35c816a08bcbf5677d1233f572f082c132a0..dc7a6ef50bfc7d1fc33bc98f171bb3506ad151c9 100644 (file)
@@ -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);
index d33c9b0dae5d108a2130c0ee3dc7c1331b7fe21b..af1331dad7a6fcdb82cab02f604830847f24fe7d 100644 (file)
@@ -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);
-}
-
-
index b2fea512c481e773ef0d7aac2a2b0d944efaa5f7..a5e28468e6018e489042c779c9ff390cf0e00fc9 100644 (file)
@@ -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);
 }
 
 /*--------------------------------------------------------------------------*/
index 287a0c5d7a62ec65af4579c07e12e4846ed0b336..396fd598757b069f84cc213cdf437ae362f3b9a7 100644 (file)
@@ -5,7 +5,8 @@
 #define CONFIG_ENV_OFFSET      0
 #define CONFIG_ENVVAR_MAX      20
 
-#define CONFIG_POWRON_DELAY    2000    /* ms to wait after power on */
+#define CONFIG_BAUDRATE                115200L
+#define CONFIG_PWRON_DELAY     2000    /* ms to wait after power on */
 #define CONFIG_BOOTDELAY       4
 //#define CONFIG_ZERO_BOOTDELAY_CHECK  1
 
index 15215a9274afd28955996144fa22fb7f3c5eadbd..51ee4243f1e8d07d52b063c11f04368993ae0de7 100644 (file)
@@ -39,7 +39,6 @@ struct rtc_time {
 
 int rtc_get (struct rtc_time *);
 int rtc_set (struct rtc_time *);
-void rtc_reset (void);
 
 void GregorianDay (struct rtc_time *);
 void to_tm (unsigned long, struct rtc_time *);
index 7414ef17d12a6aeb5ba0eb46640e6061f5166cdd..40ac815695116e07cbecd71e7917d3f347a4f245 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef SERIAL_H
 #define SERIAL_H
 
-void serial_setup(void);
+void serial_setup(unsigned long baud);
 void serial_putc(char);
 int serial_getc(void);
 uint_fast8_t serial_tstc(void);