configs/16z: Add support for 16z board

This commit is contained in:
Gregory Nutt 2014-01-22 11:50:37 -06:00
parent 8794536cf2
commit e44748d1c3
4 changed files with 180 additions and 58 deletions

View File

@ -9,12 +9,12 @@ comment "Z16F Configuration Options"
# UART0/1 always enabled
config Z16F_UART0
bool
bool "UART0"
default y
select ARCH_HAVE_UART0
config Z16F_UART1
bool
bool "UART1"
default y
select ARCH_HAVE_UART1

View File

@ -226,6 +226,22 @@
#define Z16F_SYSEXCP_PRIOSC Z16F_SYSEXCPL_PRIOSC
#define Z16F_SYSEXCP_WDT Z16F_SYSEXCPL_WDT
/* External memory interface ********************************************************/
#define Z16F_EXTCT _HX32(ffffe070) /* External Interface Control */
#define Z16F_EXTCS0H _HX32(ffffe072) /* Chip Select 0 Control High */
#define Z16F_EXTCS0L _HX32(ffffe073) /* Chip Select 0 Control Low */
#define Z16F_EXTCS1H _HX32(ffffe074) /* Chip Select 1 Control High */
#define Z16F_EXTCS1L _HX32(ffffe075) /* Chip Select 1 Control Low */
#define Z16F_EXTCS2H _HX32(ffffe076) /* Chip Select 2 Control High */
#define Z16F_EXTCS2L _HX32(ffffe077) /* Chip Select 2 Control Low */
#define Z16F_EXTCS3H _HX32(ffffe078) /* Chip Select 3 Control High */
#define Z16F_EXTCS3L _HX32(ffffe079) /* Chip Select 3 Control Low */
#define Z16F_EXTCS4H _HX32(ffffe07a) /* Chip Select 4 Control High */
#define Z16F_EXTCS4L _HX32(ffffe07b) /* Chip Select 4 Control Low */
#define Z16F_EXTCS5H _HX32(ffffe07c) /* Chip Select 5 Control High */
#define Z16F_EXTCS5L _HX32(ffffe07d) /* Chip Select 5 Control Low */
/* Oscillator control registers *****************************************************/
#define Z16F_OSC_CTL _HX32(ffffe0A0) /* 8-bit: Oscillator Control */

View File

@ -44,6 +44,22 @@
#ifdef USE_LOWUARTINIT
/*************************************************************************
* Pre-processor Definitions
*************************************************************************/
#ifndef CONFIG_Z16F_UART0
# undef CONFIG_UART0_SERIAL_CONSOLE
#endif
#ifndef CONFIG_Z16F_UART1
# undef CONFIG_UART1_SERIAL_CONSOLE
#endif
#if defined(CONFIG_UART0_SERIAL_CONSOLE) || defined(CONFIG_UART1_SERIAL_CONSOLE)
# define HAVE_Z16F_SERIAL_CONSOLE
#endif
/*************************************************************************
* External References / External Definitions
*************************************************************************/
@ -80,47 +96,54 @@
*************************************************************************/
_z16f_lowuartinit:
#ifdef HAVE_Z16F_SERIAL_CONSOLE
/* Calculate and set the baud rate generation register */
#ifdef CONFIG_UART1_SERIAL_CONSOLE
ld r3, #CONFIG_UART1_BAUD /* r3 = Selected UART1 baud */
ld r3, #CONFIG_UART1_BAUD /* r3 = Selected UART1 baud */
#else
ld r3, #CONFIG_UART0_BAUD /* r3 = Selected UART0 (default) baud */
ld r3, #CONFIG_UART0_BAUD /* r3 = Selected UART0 (default) baud */
#endif
ld r0, r3 /* r0 = baud */
sll r0, #3 /* r0 = baud * 8 */
add r0, #_SYS_CLK_FREQ /* r3 = freq + baud * 8 */
sll r3, #4 /* r3 = baud * 16 */
udiv r0, r3 /* BRG = (freq + baud * 8)/(baud * 16) */
ld r0, r3 /* r0 = baud */
sll r0, #3 /* r0 = baud * 8 */
add r0, #_SYS_CLK_FREQ /* r3 = freq + baud * 8 */
sll r3, #4 /* r3 = baud * 16 */
udiv r0, r3 /* BRG = (freq + baud * 8)/(baud * 16) */
#ifdef CONFIG_UART1_SERIAL_CONSOLE
ld.w Z16F_UART1_BR, r0 /* Z16F_UART1_BR = BRG */
/* Set the GPIO Alternate Function Register Lo (AFL) register */
ld r0, #%30
or.b Z16F_GPIOD_AFL, r0 /* Z16F_GPIOD_AFL |= %30 */
ld r0, #%30
or.b Z16F_GPIOD_AFL, r0 /* Z16F_GPIOD_AFL |= %30 */
/* Enable UART receive (REN) and transmit (TEN) */
clr.b Z16F_UART1_CTL1 /* Z16F_UART1_CTL1 = 0 */
ld r0, #(Z16F_UARTCTL0_TEN|Z16F_UARTCTL0_REN)
ld.b Z16F_UART1_CTL0, r0 /* Z16F_UART1_CTL0 = %c0 */
clr.b Z16F_UART1_CTL1 /* Z16F_UART1_CTL1 = 0 */
ld r0, #(Z16F_UARTCTL0_TEN|Z16F_UARTCTL0_REN)
ld.b Z16F_UART1_CTL0, r0 /* Z16F_UART1_CTL0 = %c0 */
#else
ld.w Z16F_UART0_BR, r0 /* Z16F_UART0_BR = BRG */
ld.w Z16F_UART0_BR, r0 /* Z16F_UART0_BR = BRG */
/* Set the GPIO Alternate Function Register Lo (AFL) register */
ld r0, #%30
or.b Z16F_GPIOA_AFL, r0 /* Z16F_GPIOA_AFL |= %30 */
ld r0, #%30
or.b Z16F_GPIOA_AFL, r0 /* Z16F_GPIOA_AFL |= %30 */
/* Enable UART receive (REN) and transmit (TEN) */
clr.b Z16F_UART0_CTL1 /* Z16F_UART0_CTL1 = 0 */
ld r0, #(Z16F_UARTCTL0_TEN|Z16F_UARTCTL0_REN)
ld.b Z16F_UART0_CTL0, r0 /* Z16F_UART0_CTL0 = %c0 */
clr.b Z16F_UART0_CTL1 /* Z16F_UART0_CTL1 = 0 */
ld r0, #(Z16F_UARTCTL0_TEN|Z16F_UARTCTL0_REN)
ld.b Z16F_UART0_CTL0, r0 /* Z16F_UART0_CTL0 = %c0 */
#endif
ret /* Return */
#endif /* HAVE_Z16F_SERIAL_CONSOLE */
ret /* Return */
#endif /* USE_LOWUARTINIT */
/*************************************************************************
@ -141,18 +164,21 @@ _z16f_lowuartinit:
#ifdef CONFIG_Z16_LOWPUTC
_up_lowputc:
#ifdef HAVE_Z16F_SERIAL_CONSOLE
/* Check if the character to output is a linefeed */
ext.ub r0, r1 /* r0=Character masked to 8-bits */
cp r0, #10 /* Is it a linefeed ('\n') */
jp ne, _z16f_xmitc /* No? Jump to _z16f_xmitc with character in r1 */
ext.ub r0, r1 /* r0=Character masked to 8-bits */
cp r0, #10 /* Is it a linefeed ('\n') */
jp ne, _z16f_xmitc /* No? Jump to _z16f_xmitc with character in r1 */
/* Output a carriage return before the linefeed */
ld r1, #13 /* Output carriage reuturn ('\r') */
call _z16f_xmitc /* Call _z16f_xmitc with r1='\r' */
ld r1, #10 /* Restore r1=linefeed to output */
/* Fall through to _z16f_xmitc with linefeed in r1 */
ld r1, #13 /* Output carriage reuturn ('\r') */
call _z16f_xmitc /* Call _z16f_xmitc with r1='\r' */
ld r1, #10 /* Restore r1=linefeed to output */
/* Fall through to _z16f_xmitc with linefeed in r1 */
#endif /* HAVE_Z16F_SERIAL_CONSOLE */
/*************************************************************************
* Name: _z16f_xmitc
@ -172,17 +198,24 @@ _up_lowputc:
_z16f_xmitc:
_z16f_xmitc1:
ld r0, Z16F_UARTSTAT0_TDRE /* TDRE=Transmitter Data Register Empty */
#ifdef HAVE_Z16F_SERIAL_CONSOLE
ld r0, Z16F_UARTSTAT0_TDRE /* TDRE=Transmitter Data Register Empty */
#ifdef CONFIG_UART1_SERIAL_CONSOLE
tm.b Z16F_UART1_STAT0, r0 /* r0 = Z16F_UART1_STAT0 */
jp eq, _z16f_xmitc1 /* While (!(Z16F_UART1_STAT0 & TDRE)) */
tm.b Z16F_UART1_STAT0, r0 /* r0 = Z16F_UART1_STAT0 */
jp eq, _z16f_xmitc1 /* While (!(Z16F_UART1_STAT0 & TDRE)) */
ld.b Z16F_UART1_TXD, r1 /* Z16F_UART1_TXD = r1 (character) */
#else
tm.b Z16F_UART0_STAT0, r0 /* r0 = Z16F_UART0_STAT1 */
jp eq, _z16f_xmitc1 /* While (!(Z16F_UART0_STAT0 & TDRE)) */
tm.b Z16F_UART0_STAT0, r0 /* r0 = Z16F_UART0_STAT1 */
jp eq, _z16f_xmitc1 /* While (!(Z16F_UART0_STAT0 & TDRE)) */
ld.b Z16F_UART0_TXD, r1 /* Z16F_UART0_TXD = r1 (character) */
#endif
ret /* Return */
#endif /* HAVE_Z16F_SERIAL_CONSOLE */
ret /* Return */
#endif /* CONFIG_Z16_LOWPUTC */
@ -203,26 +236,35 @@ _z16f_xmitc1:
#ifdef CONFIG_Z16_LOWGETC
_up_lowgetc:
_up_lowgetc1:
ld r0, #Z16F_UARTSTAT0_RDA /* RDA=Receive data available */
#ifdef HAVE_Z16F_SERIAL_CONSOLE
ld r0, #Z16F_UARTSTAT0_RDA /* RDA=Receive data available */
#ifdef CONFIG_UART1_SERIAL_CONSOLE
tm.b Z16F_UART1_STAT0, r0
jp eq, _up_lowgetc1 /* While (!Z16F_UART1_STAT0 & RDA)) */
jp eq, _up_lowgetc1 /* While (!Z16F_UART1_STAT0 & RDA)) */
ld.ub r0, Z16F_UART1_RXD /* r0 = Z16F_UART1_RXD */
#else
tm.b Z16F_UART0_STAT0,r0 /* While (!Z16F_UART0_STAT0 & RDA) */
jp eq, _up_lowgetc1
jp eq, _up_lowgetc1
ld.ub r0, Z16F_UART0_RXD /* r0 = Z16F_UART0_RXD */
#endif
cp r0, #%0d /* Test for '\r' */
jp eq, _up_lowgetc2
cp r0, #%0d /* Test \r + high bit */
jp ne, _up_lowgetc3
#endif
cp r0, #%0d /* Test for '\r' */
jp eq, _up_lowgetc2
cp r0, #%0d /* Test \r + high bit */
jp ne, _up_lowgetc3
_up_lowgetc2:
ld r0, #%0a /* Convert '\r' to '\n' */
_up_lowgetc3: /* Return value in r0 */
ret /* Return */
ld r0, #%0a /* Convert '\r' to '\n' */
_up_lowgetc3: /* Return value in r0 */
#endif /* HAVE_Z16F_SERIAL_CONSOLE */
ret /* Return */
#endif
end

View File

@ -1,7 +1,7 @@
/****************************************************************************
* arch/z16/src/z16f/z16f_serial.c
*
* Copyright (C) 2008-2009, 2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2008-2009, 2012, 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -129,12 +129,18 @@ static const struct uart_ops_s g_uart_ops =
/* I/O buffers */
#ifdef CONFIG_Z16F_UART0
static char g_uart0rxbuffer[CONFIG_UART0_RXBUFSIZE];
static char g_uart0txbuffer[CONFIG_UART0_TXBUFSIZE];
#endif
#ifdef CONFIG_Z16F_UART1
static char g_uart1rxbuffer[CONFIG_UART1_RXBUFSIZE];
static char g_uart1txbuffer[CONFIG_UART1_TXBUFSIZE];
#endif
/* This describes the state of the DM320 uart0 port. */
#ifdef CONFIG_Z16F_UART0
/* This describes the state of the ZNEO uart0 port. */
static struct z16f_uart_s g_uart0priv =
{
@ -178,8 +184,10 @@ static uart_dev_t g_uart0port =
&g_uart_ops, /* ops */
&g_uart0priv, /* priv */
};
#endif
/* This describes the state of the DM320 uart1 port. */
#ifdef CONFIG_Z16F_UART1
/* This describes the state of the ZNEO uart1 port. */
static struct z16f_uart_s g_uart1priv =
{
@ -223,17 +231,47 @@ static uart_dev_t g_uart1port =
&g_uart_ops, /* ops */
&g_uart1priv, /* priv */
};
#endif
/* Now, which one with be tty0/console and which tty1? */
#ifdef CONFIG_UART1_SERIAL_CONSOLE
# define CONSOLE_DEV g_uart1port
# define TTYS0_DEV g_uart1port
# define TTYS1_DEV g_uart0port
#ifndef CONFIG_Z16F_UART0
# undef CONFIG_UART0_SERIAL_CONSOLE
#endif
#ifndef CONFIG_Z16F_UART1
# undef CONFIG_UART1_SERIAL_CONSOLE
#endif
/* First pick the console and ttys0. This could be either of UART0-1 */
#if defined(CONFIG_UART0_SERIAL_CONSOLE)
# define CONSOLE_DEV g_uart0port /* UART0 is console */
# define TTYS0_DEV g_uart0port /* UART0 is ttyS0 */
# define UART0_ASSIGNED 1
#elif defined(CONFIG_UART1_SERIAL_CONSOLE)
# define CONSOLE_DEV g_uart1port /* UART1 is console */
# define TTYS0_DEV g_uart1port /* UART1 is ttyS0 */
# define UART1_ASSIGNED 1
#else
# define CONSOLE_DEV g_uart0port
# define TTYS0_DEV g_uart0port
# define TTYS1_DEV g_uart1port
# undef CONSOLE_DEV /* No console */
# if defined(CONFIG_KINETIS_UART0)
# define TTYS0_DEV g_uart0port /* UART0 is ttyS0 */
# define UART0_ASSIGNED 1
# elif defined(CONFIG_KINETIS_UART1)
# define TTYS0_DEV g_uart1port /* UART1 is ttyS0 */
# define UART1_ASSIGNED 1
# endif
#endif
/* Pick ttys1. This could be either of UART0-1 excluding the console UART. */
#if defined(CONFIG_KINETIS_UART0) && !defined(UART0_ASSIGNED)
# define TTYS1_DEV g_uart0port /* UART0 is ttyS1 */
# define UART0_ASSIGNED 1
#elif defined(CONFIG_KINETIS_UART1) && !defined(UART1_ASSIGNED)
# define TTYS1_DEV g_uart1port /* UART1 is ttyS1 */
# define UART1_ASSIGNED 1
#endif
/****************************************************************************
@ -277,6 +315,7 @@ static void z16f_restoreuartirq(struct uart_dev_s *dev, uint8_t state)
* Name: z16f_consoleput
****************************************************************************/
#ifdef CONSOLE_DEV
static void z16f_consoleput(uint8_t ch)
{
struct z16f_uart_s *priv = (struct z16f_uart_s*)CONSOLE_DEV.priv;
@ -292,6 +331,7 @@ static void z16f_consoleput(uint8_t ch)
putreg8(ch, priv->uartbase + Z16F_UART_TXD);
}
#endif
/****************************************************************************
* Name: z16f_setup
@ -434,14 +474,19 @@ static int z16f_rxinterrupt(int irq, void *context)
struct z16f_uart_s *priv;
uint8_t status;
#ifdef CONFIG_Z16F_UART1
if (g_uart1priv.rxirq == irq)
{
dev = &g_uart1port;
}
else if (g_uart0priv.rxirq == irq)
else
#endif
#ifdef CONFIG_Z16F_UART0
if (g_uart0priv.rxirq == irq)
{
dev = &g_uart0port;
}
#endif
else
{
PANIC();
@ -483,14 +528,19 @@ static int z16f_txinterrupt(int irq, void *context)
struct z16f_uart_s *priv;
uint8_t status;
#ifdef CONFIG_Z16F_UART1
if (g_uart1priv.txirq == irq)
{
dev = &g_uart1port;
}
else if (g_uart0priv.txirq == irq)
else
#endif
#ifdef CONFIG_Z16F_UART0
if (g_uart0priv.txirq == irq)
{
dev = &g_uart0port;
}
#endif
else
{
PANIC();
@ -682,11 +732,17 @@ void up_earlyserialinit(void)
{
/* REVISIT: UART GPIO AFL register is not initialized */
#ifdef TTYS0_DEV
(void)z16f_disableuartirq(&TTYS0_DEV);
#endif
#ifdef TTYS1_DEV
(void)z16f_disableuartirq(&TTYS1_DEV);
#endif
#ifdef CONSOLE_DEV
CONSOLE_DEV.isconsole = true;
z16f_setup(&CONSOLE_DEV);
#endif
}
/****************************************************************************
@ -700,9 +756,15 @@ void up_earlyserialinit(void)
void up_serialinit(void)
{
#ifdef CONSOLE_DEV
(void)uart_register("/dev/console", &CONSOLE_DEV);
#endif
#ifdef TTYS0_DEV
(void)uart_register("/dev/ttyS0", &TTYS0_DEV);
#endif
#ifdef TTYS1_DEV
(void)uart_register("/dev/ttyS1", &TTYS1_DEV);
#endif
}
/****************************************************************************
@ -713,6 +775,7 @@ void up_serialinit(void)
*
****************************************************************************/
#ifdef CONSOLE_DEV
int up_putc(int ch)
{
uint8_t state;
@ -744,6 +807,7 @@ int up_putc(int ch)
z16f_restoreuartirq(&CONSOLE_DEV, state);
return ch;
}
#endif
#else /* USE_SERIALDRIVER */