Kinetis:Define uart and lpuart versions of [early]serialinit

Add serial init to centralize UART/LPUART management
   Use kinetis_ not up_ where arch specific
   Defined kinetis_[lp]uart_[early]serialinit to facilitate
    bring up both UARTs and LPUARTs as devices and a console

   Support ordering and merging of serial devices names.
This commit is contained in:
David Sidrane 2017-02-27 11:06:46 -10:00
parent b9dcedf289
commit 0b637ddfb3
7 changed files with 292 additions and 30 deletions

View File

@ -1067,3 +1067,22 @@ config NO_LPUART_SERIAL_CONSOLE
the serial console the serial console
endchoice # Kinetis LPUART Serial Console endchoice # Kinetis LPUART Serial Console
config KINETIS_MERGE_TTY
bool "Kinetis Merge TTY names for LPUARTS"
default n
depends on KINETIS_LPUART
---help---
Enable the merging of the TTY names when both LPUARTs and UARTs
are defined. When enabled, all both LPUARTS and UART types will be
listed as dev/ttySn. When disabled, LPUARTS willbe listed as
/dev/ttyLPn and UARTs as /dev/ttySn see also (KINETS_LPUART_LOWEST)
config KINETS_LPUART_LOWEST
bool "Kinetis Order ttySn LPUARTs before UARTS"
default n
depends on KINETIS_LPUART && KINETIS_UART
depends on KINETIS_MERGE_TTY
---help---
Used with KINETIS_MERGE_TTY, will set the order of ttySn assignments
Enabled will order the LPUART's before the UARTS.

View File

@ -113,7 +113,8 @@ CHIP_ASRCS =
CHIP_CSRCS = kinetis_allocateheap.c kinetis_clockconfig.c CHIP_CSRCS = kinetis_allocateheap.c kinetis_clockconfig.c
CHIP_CSRCS += kinetis_clrpend.c kinetis_idle.c kinetis_irq.c CHIP_CSRCS += kinetis_clrpend.c kinetis_idle.c kinetis_irq.c
CHIP_CSRCS += kinetis_lowputc.c kinetis_pin.c kinetis_pingpio.c CHIP_CSRCS += kinetis_lowputc.c kinetis_pin.c kinetis_pingpio.c
CHIP_CSRCS += kinetis_serial.c kinetis_start.c kinetis_uid.c kinetis_wdog.c CHIP_CSRCS += kinetis_serialinit.c kinetis_serial.c
CHIP_CSRCS += kinetis_start.c kinetis_uid.c kinetis_wdog.c
CHIP_CSRCS += kinetis_cfmconfig.c CHIP_CSRCS += kinetis_cfmconfig.c
# Configuration-dependent Kinetis files # Configuration-dependent Kinetis files

View File

@ -341,6 +341,48 @@ extern "C"
void kinetis_clockconfig(void); void kinetis_clockconfig(void);
/****************************************************************************
* Name: kinetis_earlyserialinit
*
* Description:
* Performs the low level UART/LPUART initialization early in debug so that
* the serial console will be available during bootup. This must be called
* before up_serialinit.
*
****************************************************************************/
#ifdef USE_EARLYSERIALINIT
void kinetis_earlyserialinit(void);
#endif
/****************************************************************************
* Name: kinetis_uart_earlyserialinit
*
* Description:
* Performs the low level UART initialization early in debug so that the
* serial console will be available during bootup. This must be called
* before up_serialinit.
*
****************************************************************************/
#ifdef USE_EARLYSERIALINIT
void kinetis_uart_earlyserialinit(void);
#endif
/****************************************************************************
* Name: kinetis_lpuart_earlyserialinit
*
* Description:
* Performs the low level LPUART initialization early in debug so that the
* serial console will be available during bootup. This must be called
* before up_serialinit.
*
****************************************************************************/
#ifdef USE_EARLYSERIALINIT
void kinetis_lpuart_earlyserialinit(void);
#endif
/************************************************************************************ /************************************************************************************
* Name: kinetis_lowsetup * Name: kinetis_lowsetup
* *
@ -353,6 +395,44 @@ void kinetis_clockconfig(void);
void kinetis_lowsetup(void); void kinetis_lowsetup(void);
/****************************************************************************
* Name: kinetis_uart_serialinit
*
* Description:
* Register all UART based serial console and serial ports. This assumes
* that kinetis_earlyserialinit was called previously.
*
* Input Parameters:
* first: - First TTY number to assign
*
* Returns Value:
* The next TTY number available for assignment
*
****************************************************************************/
#ifdef HAVE_UART_DEVICE
unsigned int kinetis_uart_serialinit(unsigned int first);
#endif
/****************************************************************************
* Name: kinetis_lpuart_serialinit
*
* Description:
* Register all LPUART based serial console and serial ports. This assumes
* that kinetis_earlyserialinit was called previously.
*
* Input Parameters:
* first: - First TTY number to assign
*
* Returns Value:
* The next TTY number available for assignment
*
****************************************************************************/
#ifdef HAVE_LPUART_DEVICE
unsigned int kinetis_lpuart_serialinit(unsigned int first);
#endif
/**************************************************************************** /****************************************************************************
* Name: kinetis_uartreset * Name: kinetis_uartreset
* *
@ -432,7 +512,7 @@ int kinetis_pinconfig(uint32_t cfgset);
* Configure the digital filter associated with a port. The digital filter * Configure the digital filter associated with a port. The digital filter
* capabilities of the PORT module are available in all digital pin muxing modes. * capabilities of the PORT module are available in all digital pin muxing modes.
* *
* Input parmeters: * Input Parameters:
* port - See KINETIS_PORTn definitions in kinetis_port.h * port - See KINETIS_PORTn definitions in kinetis_port.h
* lpo - true: Digital Filters are clocked by the bus clock * lpo - true: Digital Filters are clocked by the bus clock
* false: Digital Filters are clocked by the 1 kHz LPO clock * false: Digital Filters are clocked by the 1 kHz LPO clock
@ -487,11 +567,11 @@ void kinetis_pinirqinitialize(void);
* 2. Call kinetis_pinirqattach() to attach the pin interrupt handling function. * 2. Call kinetis_pinirqattach() to attach the pin interrupt handling function.
* 3. Call kinetis_pinirqenable() to enable interrupts on the pin. * 3. Call kinetis_pinirqenable() to enable interrupts on the pin.
* *
* Parameters: * Input Parameters:
* - pinset: Pin configuration * pinset - Pin configuration
* - pinisr: Pin interrupt service routine * pinisr - Pin interrupt service routine
* *
* Returns: * Return Value:
* The previous value of the interrupt handler function pointer. This value may, * The previous value of the interrupt handler function pointer. This value may,
* for example, be used to restore the previous handler when multiple handlers are * for example, be used to restore the previous handler when multiple handlers are
* used. * used.
@ -583,7 +663,7 @@ void kinetis_clrpend(int irq);
* Description: * Description:
* Initialize SDIO for operation. * Initialize SDIO for operation.
* *
* Input Parameters: * Input parameters:
* slotno - Not used. * slotno - Not used.
* *
* Returned Values: * Returned Values:

View File

@ -78,7 +78,7 @@
* provide some minimal implementation of up_putc. * provide some minimal implementation of up_putc.
*/ */
#ifdef USE_SERIALDRIVER #if defined(HAVE_LPUART_DEVICE) && defined(USE_SERIALDRIVER)
/* Which LPUART with be tty0/console and which tty1? The console will always /* Which LPUART with be tty0/console and which tty1? The console will always
* be ttyS0. If there is no console then will use the lowest numbered LPUART. * be ttyS0. If there is no console then will use the lowest numbered LPUART.
@ -790,7 +790,7 @@ static bool kinetis_txready(struct uart_dev_s *dev)
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: up_earlyserialinit * Name: kinetis_lpuart_earlyserialinit
* *
* Description: * Description:
* Performs the low level LPUART initialization early in debug so that the * Performs the low level LPUART initialization early in debug so that the
@ -801,7 +801,7 @@ static bool kinetis_txready(struct uart_dev_s *dev)
* *
****************************************************************************/ ****************************************************************************/
void up_earlyserialinit(void) void kinetis_lpuart_earlyserialinit(void)
{ {
/* Disable interrupts from all LPUARTS. The console is enabled in /* Disable interrupts from all LPUARTS. The console is enabled in
* kinetis_setup() * kinetis_setup()
@ -821,28 +821,47 @@ void up_earlyserialinit(void)
} }
/**************************************************************************** /****************************************************************************
* Name: up_serialinit * Name: kinetis_lpuart_serialinit
* *
* Description: * Description:
* Register serial console and serial ports. This assumes * Register serial console and serial ports. This assumes
* that up_earlyserialinit was called previously. * that up_earlyserialinit was called previously.
* *
* Input Parameters:
* first: - First TTY number to assign
*
* Returns Value:
* The next TTY number available for assignment
*
****************************************************************************/ ****************************************************************************/
void up_serialinit(void) unsigned int kinetis_lpuart_serialinit(unsigned int first)
{ {
/* Register the console */ #if defined(CONFIG_KINETIS_MERGE_TTY)
char devname[] = "/dev/ttySx";
#endif
/* Register the console */
#ifdef HAVE_LPUART_CONSOLE #ifdef HAVE_LPUART_CONSOLE
(void)uart_register("/dev/console", &CONSOLE_DEV); (void)uart_register("/dev/console", &CONSOLE_DEV);
#endif #endif
#if !defined(CONFIG_KINETIS_MERGE_TTY)
/* Register all LPUARTs */ /* Register all LPUARTs as LPn devices */
(void)uart_register("/dev/ttyLP0", &TTYS0_DEV); (void)uart_register("/dev/ttyLP0", &TTYS0_DEV);
#ifdef TTYS1_DEV # ifdef TTYS1_DEV
(void)uart_register("/dev/ttyLP1", &TTYS1_DEV); (void)uart_register("/dev/ttyLP1", &TTYS1_DEV);
# endif
#else
devname[(sizeof(devname)/sizeof(devname[0]))-2] = '0' + first++;
(void)uart_register(devname, &TTYS0_DEV);
# ifdef TTYS1_DEV
devname[(sizeof(devname)/sizeof(devname[0]))-2] = '0' + first++;
(void)uart_register(devname, &TTYS1_DEV);
# endif
#endif #endif
return first;
} }
/**************************************************************************** /****************************************************************************
@ -907,4 +926,4 @@ int up_putc(int ch)
} }
#endif #endif
#endif /* USE_SERIALDRIVER */ #endif /* HAVE_LPUART_DEVICE && USE_SERIALDRIVER) */

View File

@ -77,7 +77,7 @@
* provide some minimal implementation of up_putc. * provide some minimal implementation of up_putc.
*/ */
#ifdef USE_SERIALDRIVER #if defined(HAVE_UART_DEVICE) && defined(USE_SERIALDRIVER)
/* Which UART with be tty0/console and which tty1-4? The console will always /* Which UART with be tty0/console and which tty1-4? The console will always
* be ttyS0. If there is no console then will use the lowest numbered UART. * be ttyS0. If there is no console then will use the lowest numbered UART.
@ -1228,7 +1228,7 @@ static bool up_txempty(struct uart_dev_s *dev)
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: up_earlyserialinit * Name: kinetis_uart_earlyserialinit
* *
* Description: * Description:
* Performs the low level UART initialization early in debug so that the * Performs the low level UART initialization early in debug so that the
@ -1239,7 +1239,8 @@ static bool up_txempty(struct uart_dev_s *dev)
* *
****************************************************************************/ ****************************************************************************/
void up_earlyserialinit(void) #if defined(USE_EARLYSERIALINIT)
void kinetis_uart_earlyserialinit(void)
{ {
/* Disable interrupts from all UARTS. The console is enabled in /* Disable interrupts from all UARTS. The console is enabled in
* pic32mx_consoleinit() * pic32mx_consoleinit()
@ -1269,18 +1270,27 @@ void up_earlyserialinit(void)
up_setup(&CONSOLE_DEV); up_setup(&CONSOLE_DEV);
#endif #endif
} }
#endif
/**************************************************************************** /****************************************************************************
* Name: up_serialinit * Name: kinetis_uart_serialinit
* *
* Description: * Description:
* Register serial console and serial ports. This assumes * Register serial console and serial ports. This assumes
* that up_earlyserialinit was called previously. * that up_earlyserialinit was called previously.
* *
* Input Parameters:
* first: - First TTY number to assign
*
* Returns Value:
* The next TTY number available for assignment
*
****************************************************************************/ ****************************************************************************/
void up_serialinit(void) unsigned int kinetis_uart_serialinit(unsigned int first)
{ {
char devname[] = "/dev/ttySx";
/* Register the console */ /* Register the console */
#ifdef HAVE_UART_CONSOLE #ifdef HAVE_UART_CONSOLE
@ -1289,22 +1299,29 @@ void up_serialinit(void)
/* Register all UARTs */ /* Register all UARTs */
(void)uart_register("/dev/ttyS0", &TTYS0_DEV); devname[(sizeof(devname)/sizeof(devname[0]))-2] = '0' + first++;
(void)uart_register(devname, &TTYS0_DEV);
#ifdef TTYS1_DEV #ifdef TTYS1_DEV
(void)uart_register("/dev/ttyS1", &TTYS1_DEV); devname[(sizeof(devname)/sizeof(devname[0]))-2] = '0' + first++;
(void)uart_register(devname, &TTYS1_DEV);
#endif #endif
#ifdef TTYS2_DEV #ifdef TTYS2_DEV
(void)uart_register("/dev/ttyS2", &TTYS2_DEV); devname[(sizeof(devname)/sizeof(devname[0]))-2] = '0' + first++;
(void)uart_register(devname, &TTYS2_DEV);
#endif #endif
#ifdef TTYS3_DEV #ifdef TTYS3_DEV
(void)uart_register("/dev/ttyS3", &TTYS3_DEV); devname[(sizeof(devname)/sizeof(devname[0]))-2] = '0' + first++;
(void)uart_register(devname, &TTYS3_DEV);
#endif #endif
#ifdef TTYS4_DEV #ifdef TTYS4_DEV
(void)uart_register("/dev/ttyS4", &TTYS4_DEV); devname[(sizeof(devname)/sizeof(devname[0]))-2] = '0' + first++;
(void)uart_register(devname, &TTYS4_DEV);
#endif #endif
#ifdef TTYS5_DEV #ifdef TTYS5_DEV
(void)uart_register("/dev/ttyS5", &TTYS5_DEV); devname[(sizeof(devname)/sizeof(devname[0]))-2] = '0' + first++;
(void)uart_register(devname, &TTYS5_DEV);
#endif #endif
return first;
} }
/**************************************************************************** /****************************************************************************
@ -1369,5 +1386,5 @@ int up_putc(int ch)
} }
#endif #endif
#endif /* USE_SERIALDRIVER */ #endif /* HAVE_UART_DEVICE && USE_SERIALDRIVER) */

View File

@ -0,0 +1,126 @@
/****************************************************************************
* arch/arm/src/kinetis/kinetis_serialinit.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Authors: Gregory Nutt <gnutt@nuttx.org>
* David Sidrane <david_s5@nscdg.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* 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,
* 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
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* 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 <stdint.h>
#include "kinetis_config.h"
#include "kinetis.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#if !defined(HAVE_UART_DEVICE) && !defined(HAVE_LPUART_DEVICE)
# undef CONFIG_KINETS_LPUART_LOWEST
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: kinetis_earlyserialinit
*
* Description:
* Performs the low level UART and LPUART initialization early in debug
* so that the serial console will be available during bootup. This must
* be called before up_serialinit. NOTE: This function depends on GPIO
* pin configuration performed in up_consoleinit() and main clock
* initialization performed in up_clkinitialize().
*
****************************************************************************/
void kinetis_earlyserialinit(void)
{
#if defined(HAVE_UART_DEVICE)
/* Initialize UART drivers */
kinetis_uart_earlyserialinit();
#endif
#if defined(HAVE_LPUART_DEVICE)
/* Initialize LPUART drivers */
kinetis_lpuart_earlyserialinit();
#endif
}
#ifdef USE_SERIALDRIVER
/****************************************************************************
* Name: up_serialinit
*
* Description:
* Register all the serial console and serial ports. This assumes
* that kinetis_earlyserialinit was called previously.
*
****************************************************************************/
void up_serialinit(void)
{
#if defined(HAVE_UART_DEVICE) ||defined(HAVE_LUART_DEVICE)
uint32_t start = 0;
#endif
/* Register the console and drivers */
#if defined(HAVE_LPUART_DEVICE) && defined(CONFIG_KINETS_LPUART_LOWEST)
/* Register LPUART drivers in starting positions */
start = kinetis_lpuart_serialinit(start);
#endif
#if defined(HAVE_UART_DEVICE)
/* Register UART drivers */
start = kinetis_uart_serialinit(start);
#endif
#if defined(HAVE_LPUART_DEVICE) && !defined(CONFIG_KINETS_LPUART_LOWEST)
/* Register LPUART drivers in last positions */
start = kinetis_lpuart_serialinit(start);
#endif
}
#endif /* USE_SERIALDRIVER */

View File

@ -330,7 +330,7 @@ void __start(void)
kinetis_fpuconfig(); kinetis_fpuconfig();
kinetis_lowsetup(); kinetis_lowsetup();
#ifdef USE_EARLYSERIALINIT #ifdef USE_EARLYSERIALINIT
up_earlyserialinit(); kinetis_earlyserialinit();
#endif #endif
/* For the case of the separate user-/kernel-space build, perform whatever /* For the case of the separate user-/kernel-space build, perform whatever