2008-10-31 23:39:11 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* arch/arm/src/str71x/str71x_lowputc.c
|
|
|
|
*
|
2009-12-16 21:05:51 +01:00
|
|
|
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
|
2012-09-13 20:32:24 +02:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2008-10-31 23:39:11 +01:00
|
|
|
*
|
|
|
|
* 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>
|
2009-12-16 21:05:51 +01:00
|
|
|
#include <stdint.h>
|
2008-11-01 15:01:05 +01:00
|
|
|
|
2009-12-29 00:35:21 +01:00
|
|
|
#include "chip.h"
|
2008-10-31 23:39:11 +01:00
|
|
|
#include "up_arch.h"
|
2009-12-29 00:35:21 +01:00
|
|
|
#include "up_internal.h"
|
2008-11-02 20:37:20 +01:00
|
|
|
|
|
|
|
#include "str71x_internal.h"
|
2008-10-31 23:39:11 +01:00
|
|
|
|
|
|
|
/**************************************************************************
|
2009-12-16 21:05:51 +01:00
|
|
|
* Pre-procesor Definitions
|
2008-10-31 23:39:11 +01:00
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/* Configuration **********************************************************/
|
|
|
|
|
|
|
|
/* Is there a UART enabled? */
|
|
|
|
|
|
|
|
#if defined(CONFIG_STR71X_UART0) || defined(CONFIG_STR71X_UART1) || \
|
2008-11-01 15:01:05 +01:00
|
|
|
defined(CONFIG_STR71X_UART2) || defined(CONFIG_STR71X_UART3)
|
2008-10-31 23:39:11 +01:00
|
|
|
# define HAVE_UART 1
|
|
|
|
|
|
|
|
/* Is there a serial console? */
|
|
|
|
|
|
|
|
# if defined(CONFIG_UART0_SERIAL_CONSOLE) || defined(CONFIG_UART1_SERIAL_CONSOLE) ||\
|
|
|
|
defined(CONFIG_UART2_SERIAL_CONSOLE) || defined(CONFIG_UART3_SERIAL_CONSOLE)
|
|
|
|
# define HAVE_CONSOLE
|
|
|
|
# else
|
|
|
|
# undef HAVE_CONSOLE
|
|
|
|
# endif
|
|
|
|
|
|
|
|
#else
|
|
|
|
# undef HAVE_UART
|
|
|
|
# undef HAVE_CONSOLE
|
|
|
|
#endif
|
|
|
|
|
2009-06-06 16:05:23 +02:00
|
|
|
/* GPIO0 UART configuration bits. For each enabled UART:
|
|
|
|
*
|
|
|
|
* TX needs to be configured for alternate function, push-pull {1, 1, 1}
|
|
|
|
* RX needs to be configured for input, tristate, cmos {0, 1, 0}
|
|
|
|
*/
|
2008-10-31 23:39:11 +01:00
|
|
|
|
|
|
|
#if CONFIG_STR71X_UART0
|
|
|
|
# define STR71X_UART0_GPIO0_MASK (0x0300) /* P0.8->U0.TX, B0.9->U0.RX */
|
2009-06-06 16:05:23 +02:00
|
|
|
# define STR71X_UART0_GPIO0_PC0BITS (0x0200)
|
|
|
|
# define STR71X_UART0_GPIO0_PC1BITS (0x0300)
|
2008-10-31 23:39:11 +01:00
|
|
|
# define STR71X_UART0_GPIO0_PC2BITS (0x0200)
|
|
|
|
#else
|
|
|
|
# define STR71X_UART0_GPIO0_MASK (0)
|
|
|
|
# define STR71X_UART0_GPIO0_PC0BITS (0)
|
|
|
|
# define STR71X_UART0_GPIO0_PC1BITS (0)
|
|
|
|
# define STR71X_UART0_GPIO0_PC2BITS (0)
|
|
|
|
#endif
|
|
|
|
|
2009-05-12 00:54:50 +02:00
|
|
|
#if CONFIG_STR71X_UART1
|
2008-10-31 23:39:11 +01:00
|
|
|
# define STR71X_UART1_GPIO0_MASK (0x0c00) /* P0,10->U1.RX, P0.11->U1.TX */
|
2009-06-06 16:05:23 +02:00
|
|
|
# define STR71X_UART1_GPIO0_PC0BITS (0x0800)
|
|
|
|
# define STR71X_UART1_GPIO0_PC1BITS (0x0c00)
|
2008-10-31 23:39:11 +01:00
|
|
|
# define STR71X_UART1_GPIO0_PC2BITS (0x0800)
|
|
|
|
#else
|
|
|
|
# define STR71X_UART1_GPIO0_MASK (0)
|
|
|
|
# define STR71X_UART1_GPIO0_PC0BITS (0)
|
|
|
|
# define STR71X_UART1_GPIO0_PC1BITS (0)
|
|
|
|
# define STR71X_UART1_GPIO0_PC2BITS (0)
|
|
|
|
#endif
|
|
|
|
|
2009-05-12 00:54:50 +02:00
|
|
|
#if CONFIG_STR71X_UART2
|
2008-10-31 23:39:11 +01:00
|
|
|
# define STR71X_UART2_GPIO0_MASK (0x6000) /* P0.13->U2.RX, P0.14>U2.TX */
|
2009-06-06 16:05:23 +02:00
|
|
|
# define STR71X_UART2_GPIO0_PC0BITS (0x4000)
|
|
|
|
# define STR71X_UART2_GPIO0_PC1BITS (0x6000)
|
2008-10-31 23:39:11 +01:00
|
|
|
# define STR71X_UART2_GPIO0_PC2BITS (0x4000)
|
|
|
|
#else
|
|
|
|
# define STR71X_UART2_GPIO0_MASK (0)
|
|
|
|
# define STR71X_UART2_GPIO0_PC0BITS (0)
|
|
|
|
# define STR71X_UART2_GPIO0_PC1BITS (0)
|
|
|
|
# define STR71X_UART2_GPIO0_PC2BITS (0)
|
|
|
|
#endif
|
|
|
|
|
2009-05-12 00:54:50 +02:00
|
|
|
#if CONFIG_STR71X_UART3
|
2008-10-31 23:39:11 +01:00
|
|
|
# define STR71X_UART3_GPIO0_MASK (0x0003) /* P0.0->U3.TX, P0.1->U3.RX */
|
2009-06-06 16:05:23 +02:00
|
|
|
# define STR71X_UART3_GPIO0_PC0BITS (0x0001)
|
|
|
|
# define STR71X_UART3_GPIO0_PC1BITS (0x0003)
|
2008-10-31 23:39:11 +01:00
|
|
|
# define STR71X_UART3_GPIO0_PC2BITS (0x0001)
|
|
|
|
#else
|
|
|
|
# define STR71X_UART3_GPIO0_MASK (0)
|
|
|
|
# define STR71X_UART3_GPIO0_PC0BITS (0)
|
|
|
|
# define STR71X_UART3_GPIO0_PC1BITS (0)
|
|
|
|
# define STR71X_UART3_GPIO0_PC2BITS (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define STR71X_UART_GPIO0_MASK (STR71X_UART0_GPIO0_MASK |STR71X_UART1_GPIO0_MASK|\
|
|
|
|
STR71X_UART2_GPIO0_MASK |STR71X_UART3_GPIO0_MASK)
|
|
|
|
#define STR71X_UART_GPIO0_PC0BITS (STR71X_UART0_GPIO0_PC0BITS|STR71X_UART1_GPIO0_PC0BITS|\
|
|
|
|
STR71X_UART2_GPIO0_PC0BITS|STR71X_UART3_GPIO0_PC0BITS)
|
2009-06-06 16:05:23 +02:00
|
|
|
#define STR71X_UART_GPIO0_PC1BITS (STR71X_UART0_GPIO0_PC1BITS|STR71X_UART1_GPIO0_PC1BITS|\
|
|
|
|
STR71X_UART2_GPIO0_PC1BITS|STR71X_UART3_GPIO0_PC1BITS)
|
|
|
|
#define STR71X_UART_GPIO0_PC2BITS (STR71X_UART0_GPIO0_PC2BITS|STR71X_UART1_GPIO0_PC2BITS|\
|
|
|
|
STR71X_UART2_GPIO0_PC2BITS|STR71X_UART3_GPIO0_PC2BITS)
|
2008-10-31 23:39:11 +01:00
|
|
|
|
|
|
|
/* Select UART parameters for the selected console */
|
|
|
|
|
|
|
|
#if defined(CONFIG_UART0_SERIAL_CONSOLE)
|
|
|
|
# define STR71X_UART_BASE STR71X_UART0_BASE
|
|
|
|
# define STR71X_UART_BAUD CONFIG_UART0_BAUD
|
|
|
|
# define STR71X_UART_BITS CONFIG_UART0_BITS
|
|
|
|
# define STR71X_UART_PARITY CONFIG_UART0_PARITY
|
|
|
|
# define STR71X_UART_2STOP CONFIG_UART0_2STOP
|
|
|
|
#elif defined(CONFIG_UART1_SERIAL_CONSOLE)
|
|
|
|
# define STR71X_UART_BASE STR71X_UART1_BASE
|
|
|
|
# define STR71X_UART_BAUD CONFIG_UART1_BAUD
|
|
|
|
# define STR71X_UART_BITS CONFIG_UART1_BITS
|
|
|
|
# define STR71X_UART_PARITY CONFIG_UART1_PARITY
|
|
|
|
# define STR71X_UART_2STOP CONFIG_UART1_2STOP
|
|
|
|
#elif defined(CONFIG_UART2_SERIAL_CONSOLE)
|
|
|
|
# define STR71X_UART_BASE STR71X_UART2_BASE
|
|
|
|
# define STR71X_UART_BAUD CONFIG_UART2_BAUD
|
|
|
|
# define STR71X_UART_BITS CONFIG_UART2_BITS
|
|
|
|
# define STR71X_UART_PARITY CONFIG_UART2_PARITY
|
|
|
|
# define STR71X_UART_2STOP CONFIG_UART2_2STOP
|
|
|
|
#elif defined(CONFIG_UART3_SERIAL_CONSOLE)
|
|
|
|
# define STR71X_UART_BASE STR71X_UART3_BASE
|
|
|
|
# define STR71X_UART_BAUD CONFIG_UART3_BAUD
|
|
|
|
# define STR71X_UART_BITS CONFIG_UART3_BITS
|
|
|
|
# define STR71X_UART_PARITY CONFIG_UART3_PARITY
|
|
|
|
# define STR71X_UART_2STOP CONFIG_UART3_2STOP
|
|
|
|
#else
|
|
|
|
# error "No CONFIG_UARTn_SERIAL_CONSOLE Setting"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Get mode setting */
|
|
|
|
|
|
|
|
#if STR71X_UART_BITS == 7
|
|
|
|
# if STR71X_UART_PARITY == 0
|
|
|
|
# error "7-bits, no parity mode not supported"
|
|
|
|
# else
|
|
|
|
# define STR71X_UARTCR_MODE STR71X_UARTCR_MODE7BITP
|
|
|
|
# endif
|
|
|
|
#elif STR71X_UART_BITS == 8
|
|
|
|
# if STR71X_UART_PARITY == 0
|
|
|
|
# define STR71X_UARTCR_MODE STR71X_UARTCR_MODE8BIT
|
|
|
|
# else
|
|
|
|
# define STR71X_UARTCR_MODE STR71X_UARTCR_MODE8BITP
|
|
|
|
# endif
|
|
|
|
#elif STR71X_UART_BITS == 9
|
|
|
|
# if STR71X_UART_PARITY == 0
|
|
|
|
# define STR71X_UARTCR_MODE STR71X_UARTCR_MODE9BIT
|
|
|
|
# else
|
|
|
|
# error "9-bits with parity not supported"
|
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
# error "Number of bits not supported"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if STR71X_UART_PARITY == 0 || STR71X_UART_PARITY == 2
|
|
|
|
# define STR71X_UARTCR_PARITY (0)
|
|
|
|
#elif STR71X_UART_PARITY == 1
|
|
|
|
# define STR71X_UARTCR_PARITY STR71X_UARTCR_PARITYODD
|
|
|
|
#else
|
|
|
|
# error "Invalid parity selection"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if STR71X_UART_2STOP != 0
|
|
|
|
# define STR71X_UARTCR_STOP STR71X_UARTCR_STOPBIT20
|
|
|
|
#else
|
2009-06-01 21:29:14 +02:00
|
|
|
# define STR71X_UARTCR_STOP STR71X_UARTCR_STOPBIT10
|
2008-10-31 23:39:11 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define STR71X_UARTCR_VALUE (STR71X_UARTCR_MODE|STR71X_UARTCR_PARITY|STR71X_UARTCR_STOP|\
|
|
|
|
STR71X_UARTCR_RUN|STR71X_UARTCR_RXENABLE|STR71X_UARTCR_FIFOENABLE)
|
|
|
|
|
|
|
|
/* Calculate BAUD rate from PCLK1:
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* PCLK1 = 32MHz
|
|
|
|
* STR71X_UART_BAUD = 38,400
|
|
|
|
* UART_BAUDRATE_DIVISOR = 614,400
|
|
|
|
* UART_BAUDRATE = 52.583 (exact) or 52 truncated (1.1% error)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define UART_BAUDDIVISOR (16 * STR71X_UART_BAUD)
|
2009-06-01 21:29:14 +02:00
|
|
|
#define UART_BAUDRATE ((STR71X_PCLK1 + (UART_BAUDDIVISOR/2)) / UART_BAUDDIVISOR)
|
2008-10-31 23:39:11 +01:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Private Types
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Global Variables
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Private Variables
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Name: up_lowputc
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Output one byte on the serial console
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
void up_lowputc(char ch)
|
|
|
|
{
|
2008-11-01 15:01:05 +01:00
|
|
|
#ifdef HAVE_CONSOLE
|
2008-10-31 23:39:11 +01:00
|
|
|
/* Wait until the TX FIFO is not full */
|
|
|
|
|
2008-11-01 15:01:05 +01:00
|
|
|
while ((getreg16(STR71X_UART_SR(STR71X_UART_BASE)) & STR71X_UARTSR_TF) != 0);
|
2008-10-31 23:39:11 +01:00
|
|
|
|
|
|
|
/* Then send the character */
|
|
|
|
|
2009-12-16 21:05:51 +01:00
|
|
|
putreg16((uint16_t)ch, STR71X_UART_TXBUFR(STR71X_UART_BASE));
|
2008-10-31 23:39:11 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Name: up_lowsetup
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This performs basic initialization of the UART used for the serial
|
|
|
|
* console. Its purpose is to get the console output availabe as soon
|
|
|
|
* as possible.
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
void up_lowsetup(void)
|
|
|
|
{
|
2009-05-12 17:43:16 +02:00
|
|
|
#if defined(HAVE_CONSOLE) && !defined(CONFIG_SUPPRESS_UART_CONFIG)
|
|
|
|
|
2009-12-16 21:05:51 +01:00
|
|
|
uint16_t reg16;
|
2008-10-31 23:39:11 +01:00
|
|
|
|
|
|
|
/* Enable the selected console device */
|
|
|
|
/* Set the UART baud rate */
|
|
|
|
|
2009-12-16 21:05:51 +01:00
|
|
|
putreg16((uint16_t)UART_BAUDRATE, STR71X_UART_BR(STR71X_UART_BASE));
|
2008-10-31 23:39:11 +01:00
|
|
|
|
|
|
|
/* Configure the UART control registers */
|
|
|
|
|
|
|
|
putreg16(STR71X_UARTCR_VALUE, STR71X_UART_CR(STR71X_UART_BASE));
|
|
|
|
|
|
|
|
/* Clear FIFOs */
|
|
|
|
|
2008-11-01 15:01:05 +01:00
|
|
|
putreg16(0, STR71X_UART_TXRSTR(STR71X_UART_BASE));
|
|
|
|
putreg16(0, STR71X_UART_RXRSTR(STR71X_UART_BASE));
|
2008-10-31 23:39:11 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Configure GPIO0 pins to enable all UARTs in the configuration
|
2014-04-14 00:22:22 +02:00
|
|
|
* (the serial driver later depends on this configuration)
|
2008-10-31 23:39:11 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#if HAVE_UART
|
2008-11-01 00:28:12 +01:00
|
|
|
reg16 = getreg16(STR71X_GPIO0_PC0);
|
2009-06-06 18:01:38 +02:00
|
|
|
reg16 &= ~STR71X_UART_GPIO0_MASK;
|
2008-11-01 15:01:05 +01:00
|
|
|
reg16 |= STR71X_UART_GPIO0_PC0BITS;
|
2008-11-01 00:28:12 +01:00
|
|
|
putreg16(reg16, STR71X_GPIO0_PC0);
|
2008-10-31 23:39:11 +01:00
|
|
|
|
2008-11-01 00:28:12 +01:00
|
|
|
reg16 = getreg16(STR71X_GPIO0_PC1);
|
2009-06-06 18:01:38 +02:00
|
|
|
reg16 &= ~STR71X_UART_GPIO0_MASK;
|
2008-11-01 15:01:05 +01:00
|
|
|
reg16 |= STR71X_UART_GPIO0_PC1BITS;
|
2008-11-01 00:28:12 +01:00
|
|
|
putreg16(reg16, STR71X_GPIO0_PC1);
|
2008-10-31 23:39:11 +01:00
|
|
|
|
2008-11-01 00:28:12 +01:00
|
|
|
reg16 = getreg16(STR71X_GPIO0_PC2);
|
2009-06-06 18:01:38 +02:00
|
|
|
reg16 &= ~STR71X_UART_GPIO0_MASK;
|
2008-11-01 15:01:05 +01:00
|
|
|
reg16 |= STR71X_UART_GPIO0_PC2BITS;
|
2008-11-01 00:28:12 +01:00
|
|
|
putreg16(reg16, STR71X_GPIO0_PC2);
|
2008-10-31 23:39:11 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|