]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/main.c
move sys timer setup from main to timer.c
[z180-stamp.git] / avr / main.c
index 423b48a7806e8a11ad7f528fdf99152af3c8f83b..0a49a1fb7cd901283be6eb9ba01f902cab73a440 100644 (file)
@@ -24,6 +24,8 @@
 #include "time.h"
 #include "rtc.h"
 #include "debug.h"
+#include "cmd_fat.h"
+
 
 uint8_t mcusr __attribute__ ((section (".noinit")));
 
@@ -65,15 +67,17 @@ void print_reset_reason(void)
        uint8_t r = mcusr & 0x1f;
        const FLASH char * const FLASH *p = rreasons;
 
-       printf_P(PSTR("### Reset reason(s): %s"), r ? "" : "none");
+       my_puts_P(PSTR("### Reset reason(s): "));
+       if (r == 0)
+               my_puts_P(PSTR("none"));
        for ( ; r; p++, r >>= 1) {
                if (r & 1) {
                        my_puts_P(*p);
                        if (r & ~1)
-                               printf_P(PSTR(", "));
+                               my_puts_P(PSTR(", "));
                }
        }
-       printf_P(PSTR(".\n"));
+       my_puts_P(PSTR(".\n"));
 }
 
 #endif
@@ -106,7 +110,7 @@ void setup_avr(void)
                _BV(PRUSART3) | _BV(PRUSART2) | _BV(PRUSART1);
 
 
-       /* disable analog comparator */
+       /* Disable analog comparator */
        ACSR = _BV(ACD);
        /* Ports */
 
@@ -114,11 +118,8 @@ void setup_avr(void)
        CLKPR = _BV(CLKPCE);
        CLKPR = 0;
 
-       /* Timer */
-       PRR1 &= ~_BV(PRTIM4);
-       OCR4A = F_CPU / 1000 - 1;       /* Timer4: 1000Hz interval */
-       TCCR4B = (0b00<<WGM42)|(0b001<<CS40); /* Normal Mode, Prescaler 1 */
-       TIMSK4 = _BV(OCIE4A);           /* Enable Output Compare A interrupt */
+       /* System timer */
+       setup_timer();
 
        /* INT5, INT6: falling edge */
        EICRB = (EICRB & ~((0b11 << ISC50) | (0b11 << ISC60))) |
@@ -146,16 +147,6 @@ void setup_system_time(void)
 }
 
 
-
-static void setup_fatfs(void)
-{
-       static FATFS FatFs0;
-       static FATFS FatFs1;
-
-       f_mount(&FatFs0, "0:", 0);
-       f_mount(&FatFs1, "1:", 0);
-}
-
 /*--------------------------------------------------------------------------*/
 
 /* Stored value of bootdelay, used by autoboot_command() */
@@ -223,7 +214,7 @@ const char *bootdelay_process(void)
        debug("### main_loop entered: bootdelay=%d\n\n", bootdelay);
        _delay_ms(20);
 
-       s = getenv_char(PSTR(ENV_BOOTCMD));
+       s = getenv_str(PSTR(ENV_BOOTCMD));
        stored_bootdelay = bootdelay;
        return s;
 }
@@ -231,7 +222,7 @@ const char *bootdelay_process(void)
 static
 void autoboot_command(const char *s)
 {
-       debug("### main_loop: bootcmd=\"%s\"\n", s ? s : "<UNDEFINED>");
+       debug("### main_loop: bootcmd=\"%s\"\n", s ? s : "");
        _delay_ms(20);
 
        if (stored_bootdelay != -1 && s && !abortboot(stored_bootdelay)) {
@@ -254,6 +245,7 @@ int main(void)
 {
        extern void setup_mmc(void);
 
+       __malloc_margin = CONFIG_SYS_MALLOC_MARGIN;
        setup_avr();
        for (int i = 0; i < GPIO_MAX; i++)
                gpio_config(i, INPUT_PULLUP);