Fix z8 UART initialization
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@708 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
28366b75d0
commit
cb2cc8c22e
@ -154,6 +154,10 @@ void up_initialize(void)
|
|||||||
|
|
||||||
/* Initialize the serial device driver */
|
/* Initialize the serial device driver */
|
||||||
|
|
||||||
|
#ifdef CONFIG_USE_LOWUARTINIT
|
||||||
|
up_lowuartinit();
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_USE_SERIALDRIVER
|
#ifdef CONFIG_USE_SERIALDRIVER
|
||||||
up_serialinit();
|
up_serialinit();
|
||||||
#elif defined(CONFIG_DEV_LOWCONSOLE)
|
#elif defined(CONFIG_DEV_LOWCONSOLE)
|
||||||
|
@ -96,8 +96,10 @@ extern "C" {
|
|||||||
|
|
||||||
EXTERN void up_irqinitialize(void);
|
EXTERN void up_irqinitialize(void);
|
||||||
EXTERN int up_timerisr(int irq, FAR chipreg_t *regs);
|
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 */
|
/* Defined in up_doirq.c */
|
||||||
|
|
||||||
@ -123,6 +125,8 @@ EXTERN void up_serialinit(void);
|
|||||||
# define up_serialinit()
|
# define up_serialinit()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Defined in drivers/lowconsole.c */
|
||||||
|
|
||||||
#ifdef CONFIG_DEV_LOWCONSOLE
|
#ifdef CONFIG_DEV_LOWCONSOLE
|
||||||
EXTERN void lowconsole_init(void);
|
EXTERN void lowconsole_init(void);
|
||||||
#else
|
#else
|
||||||
|
@ -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_reprioritizertr.c up_idle.c up_assert.c up_doirq.c \
|
||||||
up_mdelay.c up_udelay.c up_usestack.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 \
|
CHIP_CSRCS = z8_initialstate.c z8_irq.c z8_saveirqcontext.c \
|
||||||
z8_schedulesigaction.c z8_sigdeliver.c z8_timerisr.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
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@
|
|||||||
do { \
|
do { \
|
||||||
g_z8irqstate.state = Z8_IRQSTATE_ENTRY; \
|
g_z8irqstate.state = Z8_IRQSTATE_ENTRY; \
|
||||||
g_z8irqstate.regs = (regs); \
|
g_z8irqstate.regs = (regs); \
|
||||||
up_maskask_irq(irq); \
|
up_maskack_irq(irq); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/* The following macro is used when the system exits interrupt handling logic */
|
/* The following macro is used when the system exits interrupt handling logic */
|
||||||
@ -216,6 +216,10 @@ extern "C" {
|
|||||||
#define EXTERN extern
|
#define EXTERN extern
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Defined in z8_irq.c */
|
||||||
|
|
||||||
|
EXTERN void up_maskack_irq(int irq);
|
||||||
|
|
||||||
/* Defined in z8_saveusercontext.asm */
|
/* Defined in z8_saveusercontext.asm */
|
||||||
|
|
||||||
EXTERN int z8_saveusercontext(FAR chipreg_t *regs);
|
EXTERN int z8_saveusercontext(FAR chipreg_t *regs);
|
||||||
|
178
arch/z80/src/z8/z8_lowuart.S → arch/z80/src/z8/z8_lowuart.c
Executable file → Normal file
178
arch/z80/src/z8/z8_lowuart.S → arch/z80/src/z8/z8_lowuart.c
Executable file → Normal file
@ -1,6 +1,5 @@
|
|||||||
/*************************************************************************
|
/****************************************************************************
|
||||||
* arch/z80/src/z8/z8_lowuart.asm
|
* arch/z80/src/z8/z8_loweruart.c
|
||||||
* ez8 UART management
|
|
||||||
*
|
*
|
||||||
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2008 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
@ -24,7 +23,7 @@
|
|||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
* 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
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
* 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
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
*************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/*************************************************************************
|
/****************************************************************************
|
||||||
* Included Files
|
* Included Files
|
||||||
*************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
#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 "chip/chip.h"
|
||||||
#include "common/up_internal.h"
|
#include "common/up_internal.h"
|
||||||
|
|
||||||
#ifdef CONFIG_USE_LOWUARTINIT
|
#ifdef CONFIG_USE_LOWUARTINIT
|
||||||
|
|
||||||
/*************************************************************************
|
extern uint32 get_freq(void);
|
||||||
* External References / External Definitions
|
|
||||||
*************************************************************************/
|
|
||||||
|
|
||||||
xdef _z8_lowuartinit
|
/****************************************************************************
|
||||||
#ifdef CONFIG_Z80_LOWPUTC
|
* Private Definitions
|
||||||
xdef _up_lowputc
|
****************************************************************************/
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_Z80_LOWGETC
|
|
||||||
xdef _up_lowgetc
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*************************************************************************
|
/****************************************************************************
|
||||||
* Data Allocation
|
* Private Data
|
||||||
*************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
define CODESEG, SPACE=ROM
|
/****************************************************************************
|
||||||
segment CODESEG
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
/*************************************************************************
|
/****************************************************************************
|
||||||
* Code
|
* Public Functions
|
||||||
*************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/*************************************************************************
|
/****************************************************************************
|
||||||
* Name: z8_lowuartinit
|
* Name: z8_lowuartinit
|
||||||
*
|
****************************************************************************/
|
||||||
* Description:
|
|
||||||
* Initialize UART0 or UART1
|
|
||||||
*
|
|
||||||
* Parameters:
|
|
||||||
* None
|
|
||||||
*
|
|
||||||
*************************************************************************/
|
|
||||||
|
|
||||||
_z8_lowuartinit:
|
void up_lowuartinit(void)
|
||||||
#endif /* CONFIG_USE_LOWUARTINIT */
|
{
|
||||||
|
uint32 freq = get_freq();
|
||||||
|
uint16 brg;
|
||||||
|
ubyte val;
|
||||||
|
|
||||||
/*************************************************************************
|
#ifdef CONFIG_UART0_SERIAL_CONSOLE
|
||||||
* 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
|
brg = (freq +(uint32)CONFIG_UART0_BAUD * 8) /((uint32)CONFIG_UART0_BAUD * 16) ;
|
||||||
_up_lowputc:
|
|
||||||
/* Check if the character to output is a linefeed */
|
|
||||||
|
|
||||||
|
/* 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 */
|
||||||
|
|
||||||
/*************************************************************************
|
putreg8(0x02, PAADDR);
|
||||||
* Name: _z8_xmitc
|
val = getreg8(PACTL) | 0x30; /* Set bits in alternate function register */
|
||||||
*
|
putreg8(val, PACTL);
|
||||||
* Description:
|
putreg8(0x07, PAADDR);
|
||||||
* Send one character on the selected port (really a part of up_lowputc)
|
val = getreg8(PACTL) & 0xcf; /* Reset bits in alternate function set-1 register */
|
||||||
*
|
putreg8(val, PACTL);
|
||||||
* Parameters:
|
putreg8(0x08, PAADDR);
|
||||||
* r1 = character
|
val = getreg8(PACTL) & 0xcf; /* Reset bits in alternate function set-2 register */
|
||||||
*
|
putreg8(val, PACTL);
|
||||||
* Return:
|
putreg8(0x00, PAADDR);
|
||||||
* None
|
|
||||||
*
|
|
||||||
* Modifies r0
|
|
||||||
*
|
|
||||||
*************************************************************************/
|
|
||||||
|
|
||||||
_z8_xmitc:
|
putreg8(0x00, U0CTL1); /* no multi-processor operation mode */
|
||||||
_z8_xmitc1:
|
putreg8(0x00, U0CTL0); /* Transmit enable, Receive enable, no Parity, 1 Stop bit */
|
||||||
#ifdef CONFIG_UART1_SERIAL_CONSOLE
|
|
||||||
#else
|
#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
|
#endif
|
||||||
ret /* Return */
|
}
|
||||||
|
#endif /* CONFIG_USE_LOWUARTINIT */
|
||||||
#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
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user