From 2c60e1dc26e1f424d9673541aebe778601070838 Mon Sep 17 00:00:00 2001 From: Leo C Date: Tue, 2 Oct 2018 23:59:43 +0200 Subject: env var fmon (F_CPU) --- avr/cmd_cpu.c | 17 +++++++++-------- avr/env.c | 7 +++---- avr/serial.c | 9 ++++----- include/config.h | 6 +++--- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/avr/cmd_cpu.c b/avr/cmd_cpu.c index f343885..745c68a 100644 --- a/avr/cmd_cpu.c +++ b/avr/cmd_cpu.c @@ -10,11 +10,11 @@ #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) { diff --git a/avr/env.c b/avr/env.c index 3bb04c2..8896004 100644 --- 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) @@ -25,13 +25,12 @@ #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 }; diff --git a/avr/serial.c b/avr/serial.c index adbc3c4..d3aeb4e 100644 --- a/avr/serial.c +++ b/avr/serial.c @@ -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; }; } diff --git a/include/config.h b/include/config.h index 6640e67..fab20a9 100644 --- a/include/config.h +++ b/include/config.h @@ -1,5 +1,5 @@ /* - * (C) Copyright 2014 Leo C. + * (C) Copyright 2014-2018 Leo C. * * 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" @@ -32,10 +33,9 @@ #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 -- cgit v1.2.3