summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-02-18 18:02:17 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-02-18 18:02:17 +0000
commit8951e208d178ae12913a1598d887555d736da978 (patch)
treec6b9efa35239f3abb1c443c27564efd708fd525f
parentd31ab327ab91ab0b09749ef03b39b82af979c27a (diff)
downloadnuttx-8951e208d178ae12913a1598d887555d736da978.tar.gz
nuttx-8951e208d178ae12913a1598d887555d736da978.tar.bz2
nuttx-8951e208d178ae12913a1598d887555d736da978.zip
Fix z8 UART initialization
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@708 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--nuttx/arch/z80/src/common/up_initialize.c4
-rw-r--r--nuttx/arch/z80/src/common/up_internal.h8
-rw-r--r--nuttx/arch/z80/src/z8/Make.defs4
-rw-r--r--nuttx/arch/z80/src/z8/switch.h6
-rw-r--r--[-rwxr-xr-x]nuttx/arch/z80/src/z8/z8_lowuart.c (renamed from nuttx/arch/z80/src/z8/z8_lowuart.S)194
5 files changed, 101 insertions, 115 deletions
diff --git a/nuttx/arch/z80/src/common/up_initialize.c b/nuttx/arch/z80/src/common/up_initialize.c
index 583359e4e..47c1e456e 100644
--- a/nuttx/arch/z80/src/common/up_initialize.c
+++ b/nuttx/arch/z80/src/common/up_initialize.c
@@ -154,6 +154,10 @@ void up_initialize(void)
/* Initialize the serial device driver */
+#ifdef CONFIG_USE_LOWUARTINIT
+ up_lowuartinit();
+#endif
+
#ifdef CONFIG_USE_SERIALDRIVER
up_serialinit();
#elif defined(CONFIG_DEV_LOWCONSOLE)
diff --git a/nuttx/arch/z80/src/common/up_internal.h b/nuttx/arch/z80/src/common/up_internal.h
index b16a10cd6..15da824c3 100644
--- a/nuttx/arch/z80/src/common/up_internal.h
+++ b/nuttx/arch/z80/src/common/up_internal.h
@@ -96,8 +96,10 @@ extern "C" {
EXTERN void up_irqinitialize(void);
EXTERN int up_timerisr(int irq, FAR chipreg_t *regs);
-EXTERN void up_lowputc(char ch) naked_function;
-EXTERN char up_lowgetc(void) naked_function;
+
+#ifdef CONFIG_USE_LOWUARTINIT
+EXTERN void up_lowuartinit(void);
+#endif
/* Defined in up_doirq.c */
@@ -123,6 +125,8 @@ EXTERN void up_serialinit(void);
# define up_serialinit()
#endif
+/* Defined in drivers/lowconsole.c */
+
#ifdef CONFIG_DEV_LOWCONSOLE
EXTERN void lowconsole_init(void);
#else
diff --git a/nuttx/arch/z80/src/z8/Make.defs b/nuttx/arch/z80/src/z8/Make.defs
index c1df518c4..a44b029ff 100644
--- a/nuttx/arch/z80/src/z8/Make.defs
+++ b/nuttx/arch/z80/src/z8/Make.defs
@@ -42,8 +42,8 @@ CMN_CSRCS = up_initialize.c up_allocateheap.c up_createstack.c \
up_reprioritizertr.c up_idle.c up_assert.c up_doirq.c \
up_mdelay.c up_udelay.c up_usestack.c
-CHIP_SSRCS = z8_lowuart.S z8_vector.S z8_saveusercontext.S z8_restorecontext.S
+CHIP_SSRCS = z8_vector.S z8_saveusercontext.S z8_restorecontext.S
CHIP_CSRCS = z8_initialstate.c z8_irq.c z8_saveirqcontext.c \
z8_schedulesigaction.c z8_sigdeliver.c z8_timerisr.c \
- z8_serial.c z8_registerdump.c
+ z8_lowuart.c z8_serial.c z8_registerdump.c
diff --git a/nuttx/arch/z80/src/z8/switch.h b/nuttx/arch/z80/src/z8/switch.h
index 96038c9b7..073eff57d 100644
--- a/nuttx/arch/z80/src/z8/switch.h
+++ b/nuttx/arch/z80/src/z8/switch.h
@@ -118,7 +118,7 @@
do { \
g_z8irqstate.state = Z8_IRQSTATE_ENTRY; \
g_z8irqstate.regs = (regs); \
- up_maskask_irq(irq); \
+ up_maskack_irq(irq); \
} while (0)
/* The following macro is used when the system exits interrupt handling logic */
@@ -216,6 +216,10 @@ extern "C" {
#define EXTERN extern
#endif
+/* Defined in z8_irq.c */
+
+EXTERN void up_maskack_irq(int irq);
+
/* Defined in z8_saveusercontext.asm */
EXTERN int z8_saveusercontext(FAR chipreg_t *regs);
diff --git a/nuttx/arch/z80/src/z8/z8_lowuart.S b/nuttx/arch/z80/src/z8/z8_lowuart.c
index 152748b96..bfcb26aae 100755..100644
--- a/nuttx/arch/z80/src/z8/z8_lowuart.S
+++ b/nuttx/arch/z80/src/z8/z8_lowuart.c
@@ -1,6 +1,5 @@
-/*************************************************************************
- * arch/z80/src/z8/z8_lowuart.asm
- * ez8 UART management
+/****************************************************************************
+ * arch/z80/src/z8/z8_loweruart.c
*
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
@@ -24,7 +23,7 @@
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSeqUENTIAL DAMAGES (INCLUDING,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
@@ -32,125 +31,100 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- *************************************************************************/
+ ****************************************************************************/
-/*************************************************************************
+/****************************************************************************
* Included Files
- *************************************************************************/
+ ****************************************************************************/
#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <string.h>
+#include <ez8.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/sched.h>
+
#include "chip/chip.h"
#include "common/up_internal.h"
#ifdef CONFIG_USE_LOWUARTINIT
-/*************************************************************************
- * External References / External Definitions
- *************************************************************************/
+extern uint32 get_freq(void);
- xdef _z8_lowuartinit
-#ifdef CONFIG_Z80_LOWPUTC
- xdef _up_lowputc
-#endif
-#ifdef CONFIG_Z80_LOWGETC
- xdef _up_lowgetc
-#endif
+/****************************************************************************
+ * Private Definitions
+ ****************************************************************************/
-/*************************************************************************
- * Data Allocation
- *************************************************************************/
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
- define CODESEG, SPACE=ROM
- segment CODESEG
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
-/*************************************************************************
- * Code
- *************************************************************************/
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
-/*************************************************************************
+/****************************************************************************
* Name: z8_lowuartinit
- *
- * Description:
- * Initialize UART0 or UART1
- *
- * Parameters:
- * None
- *
- *************************************************************************/
-
-_z8_lowuartinit:
-#endif /* CONFIG_USE_LOWUARTINIT */
-
-/*************************************************************************
- * Name: _up_lowputc
- *
- * Description:
- * Send one character to the selected serial console
- *
- * Parmeters:
- * r1 = character
- *
- * Return:
- * None
- *
- * Modifies r0 (and maybe r1)
- *
- *************************************************************************/
-
-#ifdef CONFIG_Z80_LOWPUTC
-_up_lowputc:
- /* Check if the character to output is a linefeed */
-
-
- /* Output a carriage return before the linefeed */
-
-
-/*************************************************************************
- * Name: _z8_xmitc
- *
- * Description:
- * Send one character on the selected port (really a part of up_lowputc)
- *
- * Parameters:
- * r1 = character
- *
- * Return:
- * None
- *
- * Modifies r0
- *
- *************************************************************************/
-
-_z8_xmitc:
-_z8_xmitc1:
-#ifdef CONFIG_UART1_SERIAL_CONSOLE
-#else
-#endif
- ret /* Return */
-
-#endif /* CONFIG_Z80_LOWPUTC */
-
-/*************************************************************************
- * Name: _up_lowgetc
- *
- * Description:
- * Get a character from the serial port
- *
- * Parmeters:
- * None
- *
- * Return
- * R0 = Character read
- *
- *************************************************************************/
-
-#ifdef CONFIG_Z80_LOWGETC
-_up_lowgetc:
-_up_lowgetc1:
-#ifdef CONFIG_UART1_SERIAL_CONSOLE
-#else
-#endif
+ ****************************************************************************/
+
+void up_lowuartinit(void)
+{
+ uint32 freq = get_freq();
+ uint16 brg;
+ ubyte val;
+
+#ifdef CONFIG_UART0_SERIAL_CONSOLE
+
+ brg = (freq +(uint32)CONFIG_UART0_BAUD * 8) /((uint32)CONFIG_UART0_BAUD * 16) ;
+
+ /* Set the baudrate */
+
+ putreg8(brg >> 8, U0BRH);
+ putreg8(brg & 0xff, U0BRL);
+
+ /* Configure GPIO Port A pins 4 & 5 for alternate function */
+
+ putreg8(0x02, PAADDR);
+ val = getreg8(PACTL) | 0x30; /* Set bits in alternate function register */
+ putreg8(val, PACTL);
+ putreg8(0x07, PAADDR);
+ val = getreg8(PACTL) & 0xcf; /* Reset bits in alternate function set-1 register */
+ putreg8(val, PACTL);
+ putreg8(0x08, PAADDR);
+ val = getreg8(PACTL) & 0xcf; /* Reset bits in alternate function set-2 register */
+ putreg8(val, PACTL);
+ putreg8(0x00, PAADDR);
+
+ putreg8(0x00, U0CTL1); /* no multi-processor operation mode */
+ putreg8(0x00, U0CTL0); /* Transmit enable, Receive enable, no Parity, 1 Stop bit */
+
+#elif defined(EZ8_UART1) && defined(CONFIG_UART1_SERIAL_CONSOLE)
+ /* Set the baudrate */
+
+ putreg8(brg >> 8, U1BRH);
+ putreg8(brg & 0xff, U1BRL);
+
+ /* Configure GPIO Port D pins 4 & 5 for alternate function */
+
+ putreg8(0x02, PAADDR);
+ val = getreg8(PDCTL) | 0x30; /* Set bits in alternate function register */
+ putreg8(val, PDCTL);
+ putreg8(0x07, PDADDR);
+ val = getreg8(PDCTL) & 0xcf; /* Reset bits in alternate function set-1 register */
+ putreg8(val, PDCTL);
+ putreg8(0x08, PDADDR);
+ val = getreg8(PDCTL) & 0xcf; /* Reset bits in alternate function set-2 register */
+ putreg8(val, PDCTL);
+ putreg8(0x00, PDADDR);
+
+ putreg8(0x00, U1CTL1); /* no multi-processor operation mode */
+ putreg8(0x00, U1CTL0); /* Transmit enable, Receive enable, no Parity, 1 Stop bit */
#endif
-
- end
-
+}
+#endif /* CONFIG_USE_LOWUARTINIT */ \ No newline at end of file