]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
env var fmon (F_CPU)
authorLeo C <erbl259-lmu@yahoo.de>
Tue, 2 Oct 2018 21:59:43 +0000 (23:59 +0200)
committerLeo C <erbl259-lmu@yahoo.de>
Tue, 2 Oct 2018 21:59:43 +0000 (23:59 +0200)
avr/cmd_cpu.c
avr/env.c
avr/serial.c
include/config.h

index f3438852afb6bae8707360206cf11eaf3c18d380..745c68a97dabe6368c596f9c2729715015ec9ffe 100644 (file)
 
 #include "z80-if.h"
 #include "con-utils.h"
-//#include "env.h"
+#include "env.h"
 #include "eval_arg.h"
 #include "timer.h"
 #include "getopt-min.h"
-//#include "debug.h"
+#include "debug.h"
 
 /* hack to get Z180 loadfile into flash memory */
 #define const const FLASH
@@ -114,7 +114,7 @@ static int32_t z80_measure_phi(uint8_t cycles, uint16_t wait_ms)
                uint32_t x_cnt = x_freq;
                x_freq *= cycles;
 
-               x_freq = ((uint64_t) x_freq * F_CPU + (ref_cnt / 2))/ ref_cnt;
+               x_freq = ((uint64_t) x_freq * getenv_ulong(PSTR(ENV_FMON), 10, F_CPU) + (ref_cnt / 2))/ ref_cnt;
 
                debug("ref_start: %6u, ref_stop: %6u, ref_ovfl: %4u, ref_cnt: %9lu\n"
                                          "    TCNT3: %6u,    x_cnt: %6lu, cycles: %3u, xfreq: %9lu\n",
@@ -332,17 +332,18 @@ command_ret_t do_busack_test(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED,
 }
 
 static const FLASH uint8_t loop_code[] = {
-       /* 0000 */  0x01,0x36,0x00,             /* ld   bc,00*256+RCR                           */
+       /* 0000 */  0x01,0x36,0x00,             /* ld   bc,00*256+RCR ; no refresh cycles       */
        /* 0003 */  0xAF,                       /* xor  a                                       */
        /* 0004 */  0xED,0x79,          /* out  (c),a                                   */
-       /* 0006 */  0xD3,0x40,          /* out  (040H),a                                */
+       /* 0006 */  0xD3,0x40,          /* out  (040H),a      ; ready                   */
+       /*      */                              /*                                                                                              */
        /*      */                              /*                                      ;Z80    Z180(0W) Z180(MaxW) */
        /* 0008 */                              /* loop:                        ;-------------------------- */
-       /* 0008 */  0xDB,0x50           /* in   a,(050h)        ;11       10     +3*3  19   */
+       /* 0008 */  0xDB,0x50,          /* in   a,(050h)        ;11       10     +3*3  19   */
        /* 000A */  0xC3,0x08,0x00      /* jp   loop            ;10                9     +3*3  18   */
                                                                        /*                                      ;-------------------------- */
                                                                        /*                                      ;21       19           37   */
-}
+};
 
 command_ret_t do_cpu_freq(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, char * const argv[])
 {
@@ -416,7 +417,7 @@ command_ret_t do_cpu_freq(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int
 
        int32_t cpu_freq;
        if (!err)
-               cpu_freq = z80_measure_phi(lcycles, false, timeout);
+               cpu_freq = z80_measure_phi(lcycles, timeout);
 
        z80_bus_cmd(Reset);
        if (options & O_UNLOAD_LOOP) {
index 3bb04c28fbd64a46e771b916dd1568bb1804feab..8896004c8effb9729732fe451c01fa842caaab39 100644 (file)
--- a/avr/env.c
+++ b/avr/env.c
@@ -14,7 +14,7 @@
 
 #define DEBUG_ENV      0       /* set to 1 to debug */
 
-#define debug_env(fmt, args...)                                                              \
+#define debug_env(fmt, args...)                                                \
        debug_cond(DEBUG_ENV, fmt, ##args)
 
 
 #define DELIM          "\0"
 
 const FLASH char default_env[] = {
-       ENV_BAUDRATE      "=" "115200" DELIM
-       ENV_BOOTDELAY     "=" "3" DELIM
+       ENV_BAUDRATE      "=" stringify(CONFIG_BAUDRATE) DELIM
+       ENV_BOOTDELAY     "=" stringify(CONFIG_BOOTDELAY) DELIM
        ENV_BOOTCMD               "=" "pin ${pins};loadcpm3;go ${startaddress}" DELIM
        ENV_CPM3_SYSFILE  "=" CONFIG_CPM3_SYSFILE DELIM
        ENV_PINALIAS      "=" "0:PG5,1:PG4,2:PB4,3:PB5,4:PB6,5:PB7,"
                                                  "6:PG3,7:PG2,8:PG1,9:PG0,10:PE7" DELIM
-       //ENV_STARTADDRESS  "=" "0" DELIM
        "pins"                    "=" "2,8 low 9 high 3 2" DELIM
        DELIM
 };
index adbc3c430e91f0aaa01ce7bf18b433ff298976a1..d3aeb4ea90511d97f4530e98dcd5203cd1a77a78 100644 (file)
@@ -45,15 +45,14 @@ void usart0_setup(unsigned long baud) {
 
                PRR0 &= ~_BV(PRUSART0);
                UCSR0B = 0;
+               UCSR0A = 0;
+               UBRR0  = (F_CPU + (baud/2) + 8) / baud / 16 - 1;
+               UCSR0B = _BV(RXCIE0) | _BV(RXEN0) | _BV(TXEN0);
+               UCSR0C = 3 << UCSZ00;
 
                /* Initialize ring buffers. */
                ring_init(&rx_ring, rx_ring_buffer, BUFFER_SIZE);
                ring_init(&tx_ring, tx_ring_buffer, BUFFER_SIZE);
-
-               UCSR0A = 0;
-               UBRR0  = F_CPU / baud / 16 - 1;
-               UCSR0B = _BV(RXCIE0) | _BV(RXEN0) | _BV(TXEN0);
-               UCSR0C = 3 << UCSZ00;
        };
 }
 
index 6640e67144d64b1435b7a12817fb616c871e3791..fab20a9bd0a038578951f63492b29870c020d913 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ * (C) Copyright 2014-2018 Leo C. <erbl259-lmu@yahoo.de>
  *
  * SPDX-License-Identifier:    GPL-2.0
  */
@@ -12,6 +12,7 @@
 
 /* Environment variables */
 
+#define ENV_FMON                                       "fmon"
 #define ENV_BAUDRATE                           "baudrate"
 #define ENV_BOOTDELAY                          "bootdelay"
 #define ENV_BOOTCMD                                    "bootcmd"
 #define CONFIG_ENV_OFFSET                      0
 #define CONFIG_ENVVAR_MAX                      40
 
-#define CONFIG_BAUDRATE                                115200L
+#define CONFIG_BAUDRATE                                115200
 #define CONFIG_PWRON_DELAY                     2000    /* ms to wait after power on */
 #define CONFIG_BOOTDELAY                       4
-//#define CONFIG_ZERO_BOOTDELAY_CHECK  1
 
 #define CONFIG_CPM3_SYSFILE                    "0:/cpm3.sys"
 #define CONFIG_CPM3_COMMON_BASE                0xF000