130 lines
4.8 KiB
C
130 lines
4.8 KiB
C
/**************************************************************************
|
|
* arch/arm/src/kl/kl_lowgetc.c
|
|
*
|
|
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
*
|
|
* 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 <arch/irq.h>
|
|
#include <arch/board/board.h>
|
|
|
|
#include "up_internal.h"
|
|
#include "up_arch.h"
|
|
|
|
#include "kl_config.h"
|
|
#include "kl_lowgetc.h"
|
|
|
|
#include "chip/kl_uart.h"
|
|
|
|
/**************************************************************************
|
|
* Private Definitions
|
|
**************************************************************************/
|
|
/* Select UART parameters for the selected console */
|
|
|
|
#if defined(CONFIG_UART0_SERIAL_CONSOLE)
|
|
# define CONSOLE_BASE KL_UART0_BASE
|
|
# define CONSOLE_FREQ BOARD_CORECLK_FREQ
|
|
# define CONSOLE_BAUD CONFIG_UART0_BAUD
|
|
# define CONSOLE_BITS CONFIG_UART0_BITS
|
|
# define CONSOLE_PARITY CONFIG_UART0_PARITY
|
|
#elif defined(CONFIG_UART1_SERIAL_CONSOLE)
|
|
# define CONSOLE_BASE KL_UART1_BASE
|
|
# define CONSOLE_FREQ BOARD_BUSCLK_FREQ
|
|
# define CONSOLE_BAUD CONFIG_UART1_BAUD
|
|
# define CONSOLE_BITS CONFIG_UART1_BITS
|
|
# define CONSOLE_PARITY CONFIG_UART1_PARITY
|
|
#elif defined(CONFIG_UART2_SERIAL_CONSOLE)
|
|
# define CONSOLE_BASE KL_UART2_BASE
|
|
# define CONSOLE_FREQ BOARD_BUSCLK_FREQ
|
|
# define CONSOLE_BAUD CONFIG_UART2_BAUD
|
|
# define CONSOLE_BITS CONFIG_UART2_BITS
|
|
# define CONSOLE_PARITY CONFIG_UART2_PARITY
|
|
#endif
|
|
|
|
/**************************************************************************
|
|
* Private Types
|
|
**************************************************************************/
|
|
|
|
/**************************************************************************
|
|
* Private Function Prototypes
|
|
**************************************************************************/
|
|
|
|
/**************************************************************************
|
|
* Global Variables
|
|
**************************************************************************/
|
|
|
|
/**************************************************************************
|
|
* Private Variables
|
|
**************************************************************************/
|
|
|
|
/**************************************************************************
|
|
* Private Functions
|
|
**************************************************************************/
|
|
|
|
/**************************************************************************
|
|
* Public Functions
|
|
**************************************************************************/
|
|
|
|
/**************************************************************************
|
|
* Name: up_lowgetc
|
|
*
|
|
* Description:
|
|
* Input one byte from the serial console
|
|
*
|
|
**************************************************************************/
|
|
|
|
int kl_lowgetc(void)
|
|
{
|
|
uint8_t ch = 0;
|
|
|
|
#if defined HAVE_UART_DEVICE && defined HAVE_SERIAL_CONSOLE
|
|
/* Wait while the receiver data buffer is "empty" (RDRF) to assure that
|
|
* we have data in the buffer to read.
|
|
*/
|
|
|
|
while ((getreg8(CONSOLE_BASE+KL_UART_S1_OFFSET) & UART_S1_RDRF) == 0);
|
|
|
|
/* Then read a character from the UART data register */
|
|
|
|
ch = getreg8(CONSOLE_BASE+KL_UART_D_OFFSET);
|
|
#endif
|
|
|
|
return (int)ch;
|
|
}
|