summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-01-22 13:46:42 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-01-22 13:46:42 -0600
commit9e4b90444e61cfb30b59712704b439d3ad5933c5 (patch)
tree47e7337fa22ec45cc505cd27587a002219370953
parenta63cf27d1fd4cd630244783a8c892021c41e1e19 (diff)
downloadnuttx-9e4b90444e61cfb30b59712704b439d3ad5933c5.tar.gz
nuttx-9e4b90444e61cfb30b59712704b439d3ad5933c5.tar.bz2
nuttx-9e4b90444e61cfb30b59712704b439d3ad5933c5.zip
16Z: Some early bring-up fixes
-rw-r--r--nuttx/arch/z16/src/z16f/z16f_clkinit.c149
-rwxr-xr-xnuttx/arch/z16/src/z16f/z16f_lowuart.S2
-rw-r--r--nuttx/configs/16z/README.txt25
-rw-r--r--nuttx/configs/16z/include/board.h8
-rwxr-xr-xnuttx/configs/16z/nsh/nsh.linkcmd6
-rwxr-xr-xnuttx/configs/16z/ostest/ostest.linkcmd4
-rw-r--r--nuttx/configs/z16f2800100zcog/include/board.h10
-rwxr-xr-xnuttx/configs/z16f2800100zcog/nsh/nsh.linkcmd2
-rwxr-xr-xnuttx/configs/z16f2800100zcog/ostest/ostest.linkcmd4
-rwxr-xr-xnuttx/configs/z16f2800100zcog/pashello/pashello.linkcmd4
10 files changed, 116 insertions, 98 deletions
diff --git a/nuttx/arch/z16/src/z16f/z16f_clkinit.c b/nuttx/arch/z16/src/z16f/z16f_clkinit.c
index 9aa80ec50..3fd001b0b 100644
--- a/nuttx/arch/z16/src/z16f/z16f_clkinit.c
+++ b/nuttx/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); /* Unlock the crystal oscillator */
+ putreg8(0x18, 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 (SCKSEL=2) */
- 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 | 1, Z16F_OSC_CTL);
+ }
+ break;
- /* Wait for oscillator to stabilize */
+ /* 2: Reserved */
- for (count = 0; count < 10000; count++);
+ default:
+ case 2:
+ {
+ /* Reserved */
+ }
+ break;
- /* Select watch dog timer clock (SKCSEL=3) */
+ /* Watchdog Timer oscillator functions as system clock. */
- putreg8(0xe7, Z16F_OSC_CTL);
- putreg8(0x18, Z16F_OSC_CTL);
- putreg8(0xb0 | 3, Z16F_OSC_CTL);
+ 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/nuttx/arch/z16/src/z16f/z16f_lowuart.S b/nuttx/arch/z16/src/z16f/z16f_lowuart.S
index b511f9a10..9b804a243 100755
--- a/nuttx/arch/z16/src/z16f/z16f_lowuart.S
+++ b/nuttx/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 <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
diff --git a/nuttx/configs/16z/README.txt b/nuttx/configs/16z/README.txt
index fe3df1889..4f9d2d397 100644
--- a/nuttx/configs/16z/README.txt
+++ b/nuttx/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 <sub-directory>s.
diff --git a/nuttx/configs/16z/include/board.h b/nuttx/configs/16z/include/board.h
index 595a768b9..b76c52894 100644
--- a/nuttx/configs/16z/include/board.h
+++ b/nuttx/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/nuttx/configs/16z/nsh/nsh.linkcmd b/nuttx/configs/16z/nsh/nsh.linkcmd
index 03ca01583..1c60431f0 100755
--- a/nuttx/configs/16z/nsh/nsh.linkcmd
+++ b/nuttx/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 <gnutt@nuttx.org> */
@@ -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/nuttx/configs/16z/ostest/ostest.linkcmd b/nuttx/configs/16z/ostest/ostest.linkcmd
index fa62efede..a80efe2cc 100755
--- a/nuttx/configs/16z/ostest/ostest.linkcmd
+++ b/nuttx/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/nuttx/configs/z16f2800100zcog/include/board.h b/nuttx/configs/z16f2800100zcog/include/board.h
index e9b37d85d..61cfa46d8 100644
--- a/nuttx/configs/z16f2800100zcog/include/board.h
+++ b/nuttx/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 <gnutt@nuttx.org>
*
* 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/nuttx/configs/z16f2800100zcog/nsh/nsh.linkcmd b/nuttx/configs/z16f2800100zcog/nsh/nsh.linkcmd
index 8113bfd35..db03f480c 100755
--- a/nuttx/configs/z16f2800100zcog/nsh/nsh.linkcmd
+++ b/nuttx/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/nuttx/configs/z16f2800100zcog/ostest/ostest.linkcmd b/nuttx/configs/z16f2800100zcog/ostest/ostest.linkcmd
index 85e9dc157..f3e83f31f 100755
--- a/nuttx/configs/z16f2800100zcog/ostest/ostest.linkcmd
+++ b/nuttx/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 <gnutt@nuttx.org> */
/* */
/* 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/nuttx/configs/z16f2800100zcog/pashello/pashello.linkcmd b/nuttx/configs/z16f2800100zcog/pashello/pashello.linkcmd
index 84cf3e0e0..a5b893a3b 100755
--- a/nuttx/configs/z16f2800100zcog/pashello/pashello.linkcmd
+++ b/nuttx/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 <gnutt@nuttx.org> */
/* */
/* 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