From 7f8c50aa51ac31db3ea15abfd1cfb5396a6d7aa1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 22 Jan 2014 13:46:42 -0600 Subject: [PATCH] 16Z: Some early bring-up fixes --- arch/z16/src/z16f/z16f_clkinit.c | 149 +++++++++++------- arch/z16/src/z16f/z16f_lowuart.S | 2 +- configs/16z/README.txt | 25 --- configs/16z/include/board.h | 8 + configs/16z/nsh/nsh.linkcmd | 6 +- configs/16z/ostest/ostest.linkcmd | 4 +- configs/z16f2800100zcog/include/board.h | 10 +- configs/z16f2800100zcog/nsh/nsh.linkcmd | 2 +- configs/z16f2800100zcog/ostest/ostest.linkcmd | 4 +- .../z16f2800100zcog/pashello/pashello.linkcmd | 4 +- 10 files changed, 116 insertions(+), 98 deletions(-) diff --git a/arch/z16/src/z16f/z16f_clkinit.c b/arch/z16/src/z16f/z16f_clkinit.c index 9aa80ec505..3fd001b0b8 100644 --- a/arch/z16/src/z16f/z16f_clkinit.c +++ b/arch/z16/src/z16f/z16f_clkinit.c @@ -98,72 +98,95 @@ Z16F_FLOPTION3 = (Z16F_FLOPTION3_RESVD|Z16F_FLOPTION3_NORMAL); * ***************************************************************************/ -static void z16f_sysclkinit(void) +static void z16f_sysclkinit(int clockid, uint32_t frequency) { int count; int temp_oscdiv; /* _DEFSRC (SCKSEL Bits 1,0) is passed to program view the .linkcmd file */ - if ((getreg8(Z16F_OSC_CTL) & 0x03) != _DEFSRC) + if ((getreg8(Z16F_OSC_CTL) & 0x03) != clockid) { - if (_DEFSRC == 0) + switch (clockid) { - /* Enable 5.6 MHz clock RESET DEFAULT*/ + /* 0: Internal precision oscillator functions as system clock at 5.6 MHz */ - putreg8(0xe7, Z16F_OSC_CTL); - putreg8(0x18, Z16F_OSC_CTL); - putreg8(0xa0, Z16F_OSC_CTL); + case 0: + { + /* Enable 5.6 MHz clock RESET DEFAULT*/ - /* Wait for oscillator to stabilize */ + putreg8(0xe7, Z16F_OSC_CTL); /* Unlock the crystal oscillator */ + putreg8(0x18, Z16F_OSC_CTL); + putreg8(0xa0, Z16F_OSC_CTL); - for (count = 0; count < 10000; count++); + /* Wait for oscillator to stabilize */ - /* Select 5.6 MHz clock (SCKSEL=0) */ + for (count = 0; count < 10000; count++); - putreg8(0xe7, Z16F_OSC_CTL); - putreg8(0x18, Z16F_OSC_CTL); - putreg8(0xa0, Z16F_OSC_CTL); - } - else if (_DEFSRC == 1) - { - /* Enable (reserved) clock */ - } - else if (_DEFSRC == 2 ) - { - /* Enable external oscillator */ + /* Select 5.6 MHz clock (SCKSEL=0) */ - putreg8(0xe7, Z16F_OSC_CTL); - putreg8(0x18, Z16F_OSC_CTL); - putreg8(0xe0, Z16F_OSC_CTL); + putreg8(0xe7, Z16F_OSC_CTL); /* Unlock the crystal oscillator */ + putreg8(0x18, Z16F_OSC_CTL); + putreg8(0xa0, Z16F_OSC_CTL); + } + break; - /* Wait for oscillator to stabilize */ + /* 1: Crystal oscillator or external clock driver functions as system clock */ - for (count = 0; count < 10000; count++); + case 1: + { + /* No divider for the oscillator */ - /* select external oscillator (SCKSEL=2) */ + putreg8(0x00, Z16F_OSC_DIV); - putreg8(0xe7, Z16F_OSC_CTL); - putreg8(0x18, Z16F_OSC_CTL); - putreg8(0xe0 | 2, Z16F_OSC_CTL); - } - else if (_DEFSRC == 3) - { - /* Enable watchdog timer clock */ + /* Enable external oscillator */ - putreg8(0xe7, Z16F_OSC_CTL); - putreg8(0x18, Z16F_OSC_CTL); - putreg8(0xb0, Z16F_OSC_CTL); + putreg8(0xe7, Z16F_OSC_CTL); /* Unlock the crystal oscillator */ + putreg8(0x18, Z16F_OSC_CTL); + putreg8(0xe0, Z16F_OSC_CTL); /* INTEN+XTLEN+WDTEN */ - /* Wait for oscillator to stabilize */ + /* Wait for oscillator to stabilize */ - for (count = 0; count < 10000; count++); + for (count = 0; count < 10000; count++); - /* Select watch dog timer clock (SKCSEL=3) */ + /* select external oscillator (SCKSEL=2) */ - putreg8(0xe7, Z16F_OSC_CTL); - putreg8(0x18, Z16F_OSC_CTL); - putreg8(0xb0 | 3, Z16F_OSC_CTL); + putreg8(0xe7, Z16F_OSC_CTL); /* Unlock the crystal oscillator */ + putreg8(0x18, Z16F_OSC_CTL); + putreg8(0xe0 | 1, Z16F_OSC_CTL); + } + break; + + /* 2: Reserved */ + + default: + case 2: + { + /* Reserved */ + } + break; + + /* Watchdog Timer oscillator functions as system clock. */ + + case 3: + { + /* Enable watchdog timer clock */ + + putreg8(0xe7, Z16F_OSC_CTL); /* Unlock the crystal oscillator */ + putreg8(0x18, Z16F_OSC_CTL); + putreg8(0xb0, Z16F_OSC_CTL); + + /* Wait for oscillator to stabilize */ + + for (count = 0; count < 10000; count++); + + /* Select watch dog timer clock (SKCSEL=3) */ + + putreg8(0xe7, Z16F_OSC_CTL); /* Unlock the crystal oscillator */ + putreg8(0x18, Z16F_OSC_CTL); + putreg8(0xb0 | 3, Z16F_OSC_CTL); + } + break; } } @@ -171,22 +194,22 @@ static void z16f_sysclkinit(void) * divide the clock if the user has selected the OTHER option for frequency. */ - if (((_DEFSRC == 0) && (_DEFCLK < 3000000ul)) || - ((_DEFSRC == 2) && (_DEFCLK <= 10000000ul))) + if (((clockid == 0) && (frequency < 3000000ul)) || + ((clockid == 1) && (frequency <= 10000000ul))) { - if ( _DEFSRC == 0 ) + if ( clockid == 0 ) { - temp_oscdiv = ( 5526000ul / (_DEFCLK +1) ); + temp_oscdiv = (5526000ul / (frequency + 1)); /* Example @ 32 KHz: 0xAC (172 decimal)*/ } else { - temp_oscdiv = (( 20000000ul / (_DEFCLK +1) ) + 1 ); + temp_oscdiv = ((20000000ul / (frequency +1)) + 1); } /* Unlock and Set the Oscillator Division Register (Z16F_OSC_DIV) */ - putreg8(0xE7, Z16F_OSC_CTL); + putreg8(0xe7, Z16F_OSC_CTL); /* Unlock the crystal oscillator */ putreg8(0x18, Z16F_OSC_CTL); putreg8(temp_oscdiv, Z16F_OSC_DIV); } @@ -206,32 +229,35 @@ static void z16f_sysclkinit(void) * stabilize. ***************************************************************************/ -static void z16f_sysclkinit(void) +static void z16f_sysclkinit(int clockid, uint32_t frequency) { int count; - /* - * _DEFSRC (SCKSEL Bits 1,0) is passed to program from Target Settings Dialog. - * I.E. extern _Erom unsigned long SYS_CLK_SRC; + /* In this configuration, we support only the external oscillator/clock + * the the source of the system clock (__DEFCLK is ignored). */ - if ((getreg8(Z16F_OSC_CTL) & 0x03) != _DEFSRC) + if ((getreg8(Z16F_OSC_CTL) & 0x03) != 1) { + /* No divider for the oscillator */ + + putreg8(0x00, Z16F_OSC_DIV); + /* Enable external oscillator */ - putreg8(0xe7, Z16F_OSC_CTL); + putreg8(0xe7, Z16F_OSC_CTL); /* Unlock the crystal oscillator */ putreg8(0x18, Z16F_OSC_CTL); - putreg8(0xe0, Z16F_OSC_CTL); + putreg8(0xe0, Z16F_OSC_CTL); /* INTEN+XTLEN+WDTEN */ /* Wait for oscillator to stabilize */ for (count = 0; count < 10000; count++); - /* Select external oscillator (SCLKSEL=2) */ + /* Select external oscillator (SCLKSEL=1) */ - putreg8(0xe7, Z16F_OSC_CTL); + putreg8(0xe7, Z16F_OSC_CTL); /* Unlock the crystal oscillator */ putreg8(0x18, Z16F_OSC_CTL); - putreg8(0xe0 | 2, Z16F_OSC_CTL); + putreg8(0xe0 | 1, Z16F_OSC_CTL); /* Use the external osc/clock as system clock */ } } #endif /* CONFIG_DEBUG */ @@ -246,6 +272,7 @@ static void z16f_sysclkinit(void) void z16f_clkinit(void) { - z16f_sysclkinit(); -} + /* _DEFSRC (SCKSEL Bits 1,0) is passed to program view the .linkcmd file */ + z16f_sysclkinit(_DEFSRC, _DEFCLK); +} diff --git a/arch/z16/src/z16f/z16f_lowuart.S b/arch/z16/src/z16f/z16f_lowuart.S index b511f9a105..9b804a243f 100755 --- a/arch/z16/src/z16f/z16f_lowuart.S +++ b/arch/z16/src/z16f/z16f_lowuart.S @@ -2,7 +2,7 @@ * arch/z16/src/z16f/z16f_lowuart.asm * Z16F UART management * - * Copyright (C) 2008, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2008, 2012, 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without diff --git a/configs/16z/README.txt b/configs/16z/README.txt index fe3df18898..4f9d2d397e 100644 --- a/configs/16z/README.txt +++ b/configs/16z/README.txt @@ -398,29 +398,4 @@ ostest trailing bad characters are manually eliminated, then the build will succeed on the next try. -pashello --------- - - Configures to use examples/pashello for execution from FLASH - See examples/README.txt for information about pashello. - - NOTES: - - 1. This configuration uses the mconf-based configuration tool. To - change this configuration using that tool, you should: - - a. Build and install the kconfig-mconf tool. See nuttx/README.txt - and misc/tools/ - - b. Execute 'make menuconfig' in nuttx/ in order to start the - reconfiguration process. - - 2. The last time I tried building this configuration, there were - a few undefined symbols from the PCODE logic. It might require - a little TLC to get this all working again. - - 3. The native windows build has not been tried with this configuration - but should, in principle, work (see notes for the ostest configuration - above). - Check out any README.txt files in these s. diff --git a/configs/16z/include/board.h b/configs/16z/include/board.h index 595a768b90..b76c528946 100644 --- a/configs/16z/include/board.h +++ b/configs/16z/include/board.h @@ -44,6 +44,14 @@ * Definitions ****************************************************************************/ +/* The 16Z board has a 19.6608MHz crystal. The ZNEO clocking will be + * configured to use this crystal frequency directly as the clock source + */ + +#define BOARD_XTAL_FREQUENCY 19660800 /* 19.6608MHz */ +#define BOARD_CLKSRC 1 /* Clock source = external crystal */ +#define BOARD_SYSTEM_FREQUENCY BOARD_XTAL_FREQUENCY + /* LEDs * * The 16z board has 7 LEDs, five of which are controllable via software: diff --git a/configs/16z/nsh/nsh.linkcmd b/configs/16z/nsh/nsh.linkcmd index 03ca01583c..1c60431f07 100755 --- a/configs/16z/nsh/nsh.linkcmd +++ b/configs/16z/nsh/nsh.linkcmd @@ -1,5 +1,5 @@ /****************************************************************************/ -/* configs/16z/nsh/nsh.linkcmd */ +/* configs/16z/nsh/nsh.linkcmd */ /* */ /* Copyright (C) 2014 Gregory Nutt. All rights reserved. */ /* Author: Gregory Nutt */ @@ -69,8 +69,8 @@ define _near_stack = highaddr of RAM define _near_heapbot = top of RAM define _far_heapbot = top of ERAM -define _SYS_CLK_SRC = 2 -define _SYS_CLK_FREQ = 20000000 +define _SYS_CLK_SRC = 1 +define _SYS_CLK_FREQ = 19660800 define __EXTCT_INIT_PARAM = $40 define __EXTCS0_INIT_PARAM = $9001 diff --git a/configs/16z/ostest/ostest.linkcmd b/configs/16z/ostest/ostest.linkcmd index fa62efede6..a80efe2cca 100755 --- a/configs/16z/ostest/ostest.linkcmd +++ b/configs/16z/ostest/ostest.linkcmd @@ -69,8 +69,8 @@ define _near_stack = highaddr of RAM define _near_heapbot = top of RAM define _far_heapbot = top of ERAM -define _SYS_CLK_SRC = 2 -define _SYS_CLK_FREQ = 20000000 +define _SYS_CLK_SRC = 1 +define _SYS_CLK_FREQ = 19660800 define __EXTCT_INIT_PARAM = $40 define __EXTCS0_INIT_PARAM = $9001 diff --git a/configs/z16f2800100zcog/include/board.h b/configs/z16f2800100zcog/include/board.h index e9b37d85d9..61cfa46d8a 100644 --- a/configs/z16f2800100zcog/include/board.h +++ b/configs/z16f2800100zcog/include/board.h @@ -1,7 +1,7 @@ /**************************************************************************** * board/board.h * - * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2008, 2014 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -43,6 +43,14 @@ /**************************************************************************** * Definitions ****************************************************************************/ +/* The 16Z board has a 20MHz crystal. The ZNEO clocking will be configured + * to use this crystal frequency directly as the clock source + */ + +#define BOARD_XTAL_FREQUENCY 20000000 /* 20MHz */ +#define BOARD_CLKSRC 1 /* Clock source = external crystal */ +#define BOARD_SYSTEM_FREQUENCY BOARD_XTAL_FREQUENCY + /* LED pattern definitions * diff --git a/configs/z16f2800100zcog/nsh/nsh.linkcmd b/configs/z16f2800100zcog/nsh/nsh.linkcmd index 8113bfd35f..db03f480cf 100755 --- a/configs/z16f2800100zcog/nsh/nsh.linkcmd +++ b/configs/z16f2800100zcog/nsh/nsh.linkcmd @@ -69,7 +69,7 @@ define _near_stack = highaddr of RAM define _near_heapbot = top of RAM define _far_heapbot = top of ERAM -define _SYS_CLK_SRC = 2 +define _SYS_CLK_SRC = 1 define _SYS_CLK_FREQ = 20000000 define __EXTCT_INIT_PARAM = $80 diff --git a/configs/z16f2800100zcog/ostest/ostest.linkcmd b/configs/z16f2800100zcog/ostest/ostest.linkcmd index 85e9dc1570..f3e83f31f1 100755 --- a/configs/z16f2800100zcog/ostest/ostest.linkcmd +++ b/configs/z16f2800100zcog/ostest/ostest.linkcmd @@ -1,7 +1,7 @@ /****************************************************************************/ /* configs/z16f2800100zcog/ostest/ostest.linkcmd */ /* */ -/* Copyright (C) 2008 Gregory Nutt. All rights reserved. */ +/* Copyright (C) 2008, 2014 Gregory Nutt. All rights reserved. */ /* Author: Gregory Nutt */ /* */ /* Redistribution and use in source and binary forms, with or without */ @@ -69,7 +69,7 @@ define _near_stack = highaddr of RAM define _near_heapbot = top of RAM define _far_heapbot = top of ERAM -define _SYS_CLK_SRC = 2 +define _SYS_CLK_SRC = 1 define _SYS_CLK_FREQ = 20000000 define __EXTCT_INIT_PARAM = $80 diff --git a/configs/z16f2800100zcog/pashello/pashello.linkcmd b/configs/z16f2800100zcog/pashello/pashello.linkcmd index 84cf3e0e04..a5b893a3b8 100755 --- a/configs/z16f2800100zcog/pashello/pashello.linkcmd +++ b/configs/z16f2800100zcog/pashello/pashello.linkcmd @@ -1,7 +1,7 @@ /****************************************************************************/ /* configs/z16f2800100zcog/pashello/pashello.linkcmd */ /* */ -/* Copyright (C) 2008 Gregory Nutt. All rights reserved. */ +/* Copyright (C) 2008, 2014 Gregory Nutt. All rights reserved. */ /* Author: Gregory Nutt */ /* */ /* Redistribution and use in source and binary forms, with or without */ @@ -69,7 +69,7 @@ define _near_stack = highaddr of RAM define _near_heapbot = top of RAM define _far_heapbot = top of ERAM -define _SYS_CLK_SRC = 2 +define _SYS_CLK_SRC = 1 define _SYS_CLK_FREQ = 20000000 define __EXTCT_INIT_PARAM = $80