9
0
Fork 0

Fix z8 UART initialization

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@708 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2008-02-18 18:02:17 +00:00
parent 0dc4e7e68e
commit 7dcf33c19d
5 changed files with 93 additions and 107 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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 */
void up_lowuartinit(void)
{
uint32 freq = get_freq();
uint16 brg;
ubyte val;
/*************************************************************************
* Name: _up_lowputc
*
* Description:
* Send one character to the selected serial console
*
* Parmeters:
* r1 = character
*
* Return:
* None
*
* Modifies r0 (and maybe r1)
*
*************************************************************************/
#ifdef CONFIG_UART0_SERIAL_CONSOLE
#ifdef CONFIG_Z80_LOWPUTC
_up_lowputc:
/* Check if the character to output is a linefeed */
brg = (freq +(uint32)CONFIG_UART0_BAUD * 8) /((uint32)CONFIG_UART0_BAUD * 16) ;
/* Set the baudrate */
/* Output a carriage return before the linefeed */
putreg8(brg >> 8, U0BRH);
putreg8(brg & 0xff, U0BRL);
/* Configure GPIO Port A pins 4 & 5 for alternate function */
/*************************************************************************
* Name: _z8_xmitc
*
* Description:
* Send one character on the selected port (really a part of up_lowputc)
*
* Parameters:
* r1 = character
*
* Return:
* None
*
* Modifies r0
*
*************************************************************************/
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);
_z8_xmitc:
_z8_xmitc1:
#ifdef CONFIG_UART1_SERIAL_CONSOLE
#else
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
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
#endif
end
}
#endif /* CONFIG_USE_LOWUARTINIT */