summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2013-09-30 09:11:54 -0600
committerGregory Nutt <gnutt@nuttx.org>2013-09-30 09:11:54 -0600
commitf5fede8183545412ed7e34798ee132570eee15b5 (patch)
tree8454a390d9ba692d803d9ea1898fc08bd43f30fb
parent711d1b558f9499fe1e5756db1c1847dabe11c618 (diff)
downloadpx4-nuttx-f5fede8183545412ed7e34798ee132570eee15b5.tar.gz
px4-nuttx-f5fede8183545412ed7e34798ee132570eee15b5.tar.bz2
px4-nuttx-f5fede8183545412ed7e34798ee132570eee15b5.zip
KL25Z: Add low-level up_lowgetc function that can be used to provide an NSH console when the file system (and hence the serial driver) is disabled. From Alan Carvalho de Assis
-rw-r--r--nuttx/arch/arm/src/kl/kl_lowgetc.c129
-rw-r--r--nuttx/arch/arm/src/kl/kl_lowgetc.h82
2 files changed, 211 insertions, 0 deletions
diff --git a/nuttx/arch/arm/src/kl/kl_lowgetc.c b/nuttx/arch/arm/src/kl/kl_lowgetc.c
new file mode 100644
index 000000000..b46b184b1
--- /dev/null
+++ b/nuttx/arch/arm/src/kl/kl_lowgetc.c
@@ -0,0 +1,129 @@
+/**************************************************************************
+ * 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_getputc.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
+ *
+ **************************************************************************/
+
+uint32_t 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;
+}
diff --git a/nuttx/arch/arm/src/kl/kl_lowgetc.h b/nuttx/arch/arm/src/kl/kl_lowgetc.h
new file mode 100644
index 000000000..4ed52365a
--- /dev/null
+++ b/nuttx/arch/arm/src/kl/kl_lowgetc.h
@@ -0,0 +1,82 @@
+/************************************************************************************
+ * arch/arm/src/kl/kl_lowgetc.h
+ *
+ * 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.
+ *
+ ************************************************************************************/
+
+#ifndef __ARCH_ARM_SRC_KL_KINETIS_LOWGETC_H
+#define __ARCH_ARM_SRC_KL_KINETIS_LOWGETC_H
+
+/************************************************************************************
+ * Included Files
+ ************************************************************************************/
+
+#include <nuttx/config.h>
+#include "kl_config.h"
+
+/************************************************************************************
+ * Pre-processor Definitions
+ ************************************************************************************/
+
+/************************************************************************************
+ * Public Types
+ ************************************************************************************/
+
+/************************************************************************************
+ * Public Data
+ ************************************************************************************/
+
+#ifndef __ASSEMBLY__
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/************************************************************************************
+ * Public Functions
+ ************************************************************************************/
+
+#ifdef HAVE_SERIAL_CONSOLE
+int kl_lowgetc(void);
+#endif
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+#endif /* __ASSEMBLY__ */
+#endif /* __ARCH_ARM_SRC_KL_KINETIS_LOWGETC_H */