text:
/****************************************************************************
 * os/arch/arm/src/imxrt/imxrt_serial.c
 *
 *   Copyright (C) 2018 Gregory Nutt. All rights reserved.
 *   Author: Ivan Ucherdzhiev <ivanucherdjiev@gmail.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 <tinyara/config.h>

#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
#include <unistd.h>
#include <semaphore.h>
#include <string.h>
#include <errno.h>
#include <debug.h>

#ifdef CONFIG_SERIAL_TERMIOS
#include <termios.h>
#endif

#include <tinyara/irq.h>
#include <tinyara/arch.h>
#include <tinyara/init.h>
#include <tinyara/pm/pm.h>
#include <tinyara/serial/serial.h>

#include <arch/serial.h>
#include <arch/board/board.h>

#include "chip.h"
#include "up_arch.h"
#include "up_internal.h"

#include "chip/imxrt_lpuart.h"
#include "imxrt_gpio.h"
#include "chip/imxrt_pinmux.h"
#include "imxrt_config.h"
#include "imxrt_lowputc.h"
#include "imxrt_serial.h"

#ifdef USE_SERIALDRIVER

/****************************************************************************
 * Pre-processor Definitions
 ****************************************************************************/
/* Which LPUART with be tty0/console and which tty1-7?  The console will
 * always be ttyS0.  If there is no console then will use the lowest
 * numbered UART.
 */

/* First pick the console and ttys0.  This could be any of LPUART1-8 */

#if defined(CONFIG_LPUART1_SERIAL_CONSOLE)
#define CONSOLE_DEV         g_uart1port	/* LPUART1 is console */
#define TTYS0_DEV           g_uart1port	/* LPUART1 is ttyS0 */
#define UART1_ASSIGNED      1
#define HAVE_SERIAL_CONSOLE 1
#elif defined(CONFIG_LPUART2_SERIAL_CONSOLE)
#define CONSOLE_DEV         g_uart2port	/* LPUART2 is console */
#define TTYS0_DEV           g_uart2port	/* LPUART2 is ttyS0 */
#define UART2_ASSIGNED      1
#define HAVE_SERIAL_CONSOLE 1
#elif defined(CONFIG_LPUART3_SERIAL_CONSOLE)
#define CONSOLE_DEV         g_uart3port	/* LPUART3 is console */
#define TTYS0_DEV           g_uart3port	/* LPUART3 is ttyS0 */
#define UART3_ASSIGNED      1
#define HAVE_SERIAL_CONSOLE 1
#elif defined(CONFIG_LPUART4_SERIAL_CONSOLE)
#define CONSOLE_DEV         g_uart4port	/* LPUART4 is console */
#define TTYS0_DEV           g_uart4port	/* LPUART4 is ttyS0 */
#define UART4_ASSIGNED      1
#define HAVE_SERIAL_CONSOLE 1
#elif defined(CONFIG_LPUART5_SERIAL_CONSOLE)
#define CONSOLE_DEV         g_uart5port	/* LPUART5 is console */
#define TTYS0_DEV           g_uart5port /* LPUART5 is ttyS0 */
#define UART5_ASSIGNED      1
#define HAVE_SERIAL_CONSOLE 1
#elif defined(CONFIG_LPUART6_SERIAL_CONSOLE)
#define CONSOLE_DEV         g_uart6port	/* LPUART6 is console */
#define TTYS0_DEV           g_uart6port /* LPUART6 is ttyS0 */
#define UART6_ASSIGNED      1
#define HAVE_SERIAL_CONSOLE 1
#elif defined(CONFIG_LPUART7_SERIAL_CONSOLE)
#define CONSOLE_DEV         g_uart7port	/* LPUART7 is console */
#define TTYS0_DEV           g_uart7port /* LPUART7 is ttyS0 */
#define UART7_ASSIGNED      1
#define HAVE_SERIAL_CONSOLE 1
#elif defined(CONFIG_LPUART8_SERIAL_CONSOLE)
#define CONSOLE_DEV         g_uart8port	/* LPUART8 is console */
#define TTYS0_DEV           g_uart8port /* LPUART8 is ttyS0 */
#define UART8_ASSIGNED      1
#define HAVE_SERIAL_CONSOLE 1
#else
#undef CONSOLE_DEV				/* No console */
#if defined(CONFIG_IMXRT_LPUART1)
#define TTYS0_DEV         g_uart1port	/* LPUART1 is ttyS0 */
#define UART1_ASSIGNED    1
#elif defined(CONFIG_IMXRT_LPUART2)
#define TTYS0_DEV         g_uart2port	/* LPUART2 is ttyS0 */
#define UART2_ASSIGNED    1
#elif defined(CONFIG_IMXRT_LPUART3)
#define TTYS0_DEV         g_uart3port	/* LPUART3 is ttyS0 */
#define UART3_ASSIGNED    1
#elif defined(CONFIG_IMXRT_LPUART4)
#define TTYS0_DEV         g_uart4port	/* LPUART4 is ttyS0 */
#define UART4_ASSIGNED    1
#elif defined(CONFIG_IMXRT_LPUART5)
#define TTYS0_DEV         g_uart5port	/* LPUART5 is ttyS0 */
#define UART5_ASSIGNED    1
#elif defined(CONFIG_IMXRT_LPUART6)
#define TTYS0_DEV         g_uart6port	/* LPUART6 is ttyS0 */
#define UART6_ASSIGNED    1
#elif defined(CONFIG_IMXRT_LPUART7)
#define TTYS0_DEV         g_uart7port	/* LPUART7 is ttyS0 */
#define UART7_ASSIGNED    1
#elif defined(CONFIG_IMXRT_LPUART8)
#define TTYS0_DEV         g_uart8port	/* LPUART8 is ttyS0 */
#define UART8_ASSIGNED    1
#endif
#endif

/* Pick ttys1.  This could be any of UART1-8 excluding the console UART.
 * One of UART1-8 could be the console; one of UART1-8 has already been
 * assigned to ttys0.
 */

#if defined(CONFIG_IMXRT_LPUART1) && !defined(UART1_ASSIGNED)
#define TTYS1_DEV           g_uart1port	/* LPUART1 is ttyS1 */
#define UART1_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART2) && !defined(UART2_ASSIGNED)
#define TTYS1_DEV           g_uart2port	/* LPUART2 is ttyS1 */
#define UART2_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART3) && !defined(UART3_ASSIGNED)
#define TTYS1_DEV           g_uart3port	/* LPUART3 is ttyS1 */
#define UART3_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART4) && !defined(UART4_ASSIGNED)
#define TTYS1_DEV           g_uart4port	/* LPUART4 is ttyS1 */
#define UART4_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART5) && !defined(UART5_ASSIGNED)
#define TTYS1_DEV           g_uart5port	/* LPUART5 is ttyS1 */
#define UART5_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART6) && !defined(UART6_ASSIGNED)
#define TTYS1_DEV           g_uart6port	/* LPUART6 is ttyS1 */
#define UART6_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART7) && !defined(UART7_ASSIGNED)
#define TTYS1_DEV           g_uart7port	/* LPUART7 is ttyS1 */
#define UART7_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART8) && !defined(UART8_ASSIGNED)
#define TTYS1_DEV           g_uart8port	/* LPUART8 is ttyS1 */
#define UART8_ASSIGNED      1
#endif

/* Pick ttys2.  This could be one of UART2-8. It can't be UART1 because that
 * was either assigned as ttyS0 or ttys1.  One of UART 1-8 could be the
 * console.  One of UART2-8 has already been assigned to ttys0 or ttyS1.
 */

#if defined(CONFIG_IMXRT_LPUART2) && !defined(UART2_ASSIGNED)
#define TTYS2_DEV           g_uart2port	/* LPUART2 is ttyS2 */
#define UART2_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART3) && !defined(UART3_ASSIGNED)
#define TTYS2_DEV           g_uart3port	/* LPUART3 is ttyS2 */
#define UART3_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART4) && !defined(UART4_ASSIGNED)
#define TTYS2_DEV           g_uart4port	/* LPUART4 is ttyS2 */
#define UART4_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART5) && !defined(UART5_ASSIGNED)
#define TTYS2_DEV           g_uart5port	/* LPUART5 is ttyS2 */
#define UART5_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART6) && !defined(UART6_ASSIGNED)
#define TTYS2_DEV           g_uart6port	/* LPUART6 is ttyS2 */
#define UART6_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART7) && !defined(UART7_ASSIGNED)
#define TTYS2_DEV           g_uart7port	/* LPUART7 is ttyS2 */
#define UART7_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART8) && !defined(UART8_ASSIGNED)
#define TTYS2_DEV           g_uart8port	/* LPUART8 is ttyS2 */
#define UART8_ASSIGNED      1
#endif

/* Pick ttys3. This could be one of UART3-8. It can't be UART1-2 because
 * those have already been assigned to ttsyS0, 1, or 2.  One of
 * UART3-8 could also be the console.  One of UART3-8 has already
 * been assigned to ttys0, 1, or 3.
 */

#if defined(CONFIG_IMXRT_LPUART3) && !defined(UART3_ASSIGNED)
#define TTYS3_DEV           g_uart3port	/* LPUART3 is ttyS3 */
#define UART3_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART4) && !defined(UART4_ASSIGNED)
#define TTYS3_DEV           g_uart4port	/* LPUART4 is ttyS3 */
#define UART4_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART5) && !defined(UART5_ASSIGNED)
#define TTYS3_DEV           g_uart5port	/* LPUART5 is ttyS3 */
#define UART5_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART6) && !defined(UART6_ASSIGNED)
#define TTYS3_DEV           g_uart6port	/* LPUART6 is ttyS3 */
#define UART6_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART7) && !defined(UART7_ASSIGNED)
#define TTYS3_DEV           g_uart7port	/* LPUART7 is ttyS3 */
#define UART7_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART8) && !defined(UART8_ASSIGNED)
#define TTYS3_DEV           g_uart8port	/* LPUART8 is ttyS3 */
#define UART8_ASSIGNED      1
#endif

/* Pick ttys4. This could be one of UART4-8. It can't be UART1-3 because
 * those have already been assigned to ttsyS0, 1, 2 or 3.  One of
 * UART 4-8 could be the console.  One of UART4-8 has already been
 * assigned to ttys0, 1, 3, or 4.
 */

#if defined(CONFIG_IMXRT_LPUART4) && !defined(UART4_ASSIGNED)
#define TTYS4_DEV           g_uart4port	/* LPUART4 is ttyS4 */
#define UART4_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART5) && !defined(UART5_ASSIGNED)
#define TTYS4_DEV           g_uart5port	/* LPUART5 is ttyS4 */
#define UART5_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART6) && !defined(UART6_ASSIGNED)
#define TTYS4_DEV           g_uart6port	/* LPUART6 is ttyS4 */
#define UART6_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART7) && !defined(UART7_ASSIGNED)
#define TTYS4_DEV           g_uart7port	/* LPUART7 is ttyS4 */
#define UART7_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART8) && !defined(UART8_ASSIGNED)
#define TTYS4_DEV           g_uart8port	/* LPUART8 is ttyS4 */
#define UART8_ASSIGNED      1
#endif

/* Pick ttys5. This could be one of UART5-8. It can't be UART1-4 because
 * those have already been assigned to ttsyS0, 1, 2, 3 or 4.  One of
 * UART 5-8 could be the console.  One of UART5-8 has already been
 * assigned to ttys0, 1, 2, 3, or 4.
 */
#if defined(CONFIG_IMXRT_LPUART5) && !defined(UART5_ASSIGNED)
#define TTYS5_DEV           g_uart5port	/* LPUART5 is ttyS5 */
#define UART5_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART6) && !defined(UART6_ASSIGNED)
#define TTYS5_DEV           g_uart6port	/* LPUART6 is ttyS5 */
#define UART6_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART7) && !defined(UART7_ASSIGNED)
#define TTYS5_DEV           g_uart7port	/* LPUART7 is ttyS5 */
#define UART7_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART8) && !defined(UART8_ASSIGNED)
#define TTYS5_DEV           g_uart8port	/* LPUART8 is ttyS5 */
#define UART8_ASSIGNED      1
#endif

/* Pick ttys6. This could be one of UART6-8. It can't be UART1-5 because
 * those have already been assigned to ttsyS0, 1, 2, 3, 4 or 5.  One of
 * UART 6-8 could be the console.  One of UART6-8 has already been
 * assigned to ttys0, 1, 2, 3, 4 or 5.
 */

#if defined(CONFIG_IMXRT_LPUART6) && !defined(UART6_ASSIGNED)
#define TTYS6_DEV           g_uart6port	/* LPUART6 is ttyS5 */
#define UART6_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART7) && !defined(UART7_ASSIGNED)
#define TTYS6_DEV           g_uart7port	/* LPUART7 is ttyS5 */
#define UART7_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART8) && !defined(UART8_ASSIGNED)
#define TTYS6_DEV           g_uart8port	/* LPUART8 is ttyS5 */
#define UART8_ASSIGNED      1
#endif

/* Pick ttys7. This could be one of UART7-8. It can't be UART1-6 because
 * those have already been assigned to ttsyS0, 1, 2, 3, 4, 5 or 6.  One of
 * UART 7-8 could be the console.  One of UART7-8 has already been
 * assigned to ttys0, 1, 2, 3, 4, 5 or 6.
 */

#if defined(CONFIG_IMXRT_LPUART7) && !defined(UART7_ASSIGNED)
#define TTYS7_DEV           g_uart7port	/* LPUART7 is ttyS5 */
#define UART7_ASSIGNED      1
#elif defined(CONFIG_IMXRT_LPUART8) && !defined(UART8_ASSIGNED)
#define TTYS7_DEV           g_uart8port	/* LPUART8 is ttyS5 */
#define UART8_ASSIGNED      1
#endif

/* UART, if available, should have been assigned to ttyS0-7. */

/* Power management definitions */

#if defined(CONFIG_PM) && !defined(CONFIG_IMXRT_PM_SERIAL_ACTIVITY)
#define CONFIG_IMXRT_PM_SERIAL_ACTIVITY 10
#endif

#if defined(CONFIG_PM)
#define PM_IDLE_DOMAIN      0	/* Revisit */
#endif

#ifdef CONFIG_SERIAL_IFLOWCONTROL
#define IFLOW  1
#else
#define IFLOW  0
#endif

#ifdef CONFIG_SERIAL_OFLOWCONTROL
#define OFLOW  1
#else
#define OFLOW  0
#endif

/****************************************************************************
 * Private Types
 ****************************************************************************/

struct imxrt_uart_s {
	uint32_t uartbase;			/* Base address of UART registers */
	uint32_t baud;				/* Configured baud */
	uint32_t ie;				/* Saved enabled interrupts */
	uint8_t irq;				/* IRQ associated with this UART */
	uint8_t parity;				/* 0=none, 1=odd, 2=even */
	uint8_t bits;				/* Number of bits (7 or 8) */
#ifdef CONFIG_SERIAL_IFLOWCONTROL
	const uint32_t rts_gpio;  /* U[S]ART RTS GPIO pin configuration */
#endif
#ifdef CONFIG_SERIAL_OFLOWCONTROL
	const uint32_t cts_gpio;  /* U[S]ART CTS GPIO pin configuration */
#endif

	uint8_t  stopbits2:1; /* 1: Configure with 2 stop bits vs 1 */
#ifdef CONFIG_SERIAL_IFLOWCONTROL
	uint8_t  iflow:1;     /* input flow control (RTS) enabled */
#endif
#ifdef CONFIG_SERIAL_OFLOWCONTROL
	uint8_t  oflow:1;     /* output flow control (CTS) enabled */
#endif
	uint8_t  reserved:(7 - IFLOW + OFLOW);
};

/****************************************************************************
 * Private Function Prototypes
 ****************************************************************************/

static inline uint32_t imxrt_serialin(struct imxrt_uart_s *priv, uint32_t offset);
static inline void imxrt_serialout(struct imxrt_uart_s *priv, uint32_t offset, uint32_t value);
static inline void imxrt_disableuartint(struct imxrt_uart_s *priv, uint32_t *ie);
static inline void imxrt_restoreuartint(struct imxrt_uart_s *priv, uint32_t ie);

static int imxrt_setup(struct uart_dev_s *dev);
static void imxrt_shutdown(struct uart_dev_s *dev);
static int imxrt_attach(struct uart_dev_s *dev);
static void imxrt_detach(struct uart_dev_s *dev);
static int imxrt_interrupt(int irq, void *context, FAR void *arg);
static int imxrt_ioctl(struct file *filep, int cmd, unsigned long arg);
static int imxrt_receive(struct uart_dev_s *dev, uint32_t *status);
static void imxrt_rxint(struct uart_dev_s *dev, bool enable);
static bool imxrt_rxavailable(struct uart_dev_s *dev);
static void imxrt_send(struct uart_dev_s *dev, int ch);
static void imxrt_txint(struct uart_dev_s *dev, bool enable);
static bool imxrt_txready(struct uart_dev_s *dev);
static bool imxrt_txempty(struct uart_dev_s *dev);

#ifdef CONFIG_PM
static void up_pm_notify(struct pm_callback_s *cb, int dowmin, enum pm_state_e pmstate);
static int up_pm_prepare(struct pm_callback_s *cb, int domain, enum pm_state_e pmstate);
#endif

/****************************************************************************
 * Private Data
 ****************************************************************************/

/* Serial driver UART operations */

static const struct uart_ops_s g_uart_ops = {
	.setup = imxrt_setup,
	.shutdown = imxrt_shutdown,
	.attach = imxrt_attach,
	.detach = imxrt_detach,
	.ioctl = imxrt_ioctl,
	.receive = imxrt_receive,
	.rxint = imxrt_rxint,
	.rxavailable = imxrt_rxavailable,
#ifdef CONFIG_SERIAL_IFLOWCONTROL
	.rxflowcontrol = NULL,
#endif
	.send = imxrt_send,
	.txint = imxrt_txint,
	.txready = imxrt_txready,
	.txempty = imxrt_txempty,
};

/* I/O buffers */

#ifdef CONFIG_IMXRT_LPUART1
static char g_uart1rxbuffer[CONFIG_LPUART1_RXBUFSIZE];
static char g_uart1txbuffer[CONFIG_LPUART1_TXBUFSIZE];
#endif

#ifdef CONFIG_IMXRT_LPUART2
static char g_uart2rxbuffer[CONFIG_LPUART2_RXBUFSIZE];
static char g_uart2txbuffer[CONFIG_LPUART2_TXBUFSIZE];
#endif

#ifdef CONFIG_IMXRT_LPUART3
static char g_uart3rxbuffer[CONFIG_LPUART3_RXBUFSIZE];
static char g_uart3txbuffer[CONFIG_LPUART3_TXBUFSIZE];
#endif

#ifdef CONFIG_IMXRT_LPUART4
static char g_uart4rxbuffer[CONFIG_LPUART4_RXBUFSIZE];
static char g_uart4txbuffer[CONFIG_LPUART4_TXBUFSIZE];
#endif

#ifdef CONFIG_IMXRT_LPUART5
static char g_uart5rxbuffer[CONFIG_LPUART5_RXBUFSIZE];
static char g_uart5txbuffer[CONFIG_LPUART5_TXBUFSIZE];
#endif

#ifdef CONFIG_IMXRT_LPUART6
static char g_uart6rxbuffer[CONFIG_LPUART6_RXBUFSIZE];
static char g_uart6txbuffer[CONFIG_LPUART6_TXBUFSIZE];
#endif

#ifdef CONFIG_IMXRT_LPUART7
static char g_uart7rxbuffer[CONFIG_LPUART7_RXBUFSIZE];
static char g_uart7txbuffer[CONFIG_LPUART7_TXBUFSIZE];
#endif

#ifdef CONFIG_IMXRT_LPUART8
static char g_uart8rxbuffer[CONFIG_LPUART8_RXBUFSIZE];
static char g_uart8txbuffer[CONFIG_LPUART8_TXBUFSIZE];
#endif

/* This describes the state of the IMXRT lpuart1 port. */

#ifdef CONFIG_IMXRT_LPUART1
static struct imxrt_uart_s g_uart1priv = {
	.uartbase = IMXRT_LPUART1_BASE,
	.baud = CONFIG_LPUART1_BAUD,
	.irq = IMXRT_IRQ_LPUART1,
	.parity = CONFIG_LPUART1_PARITY,
	.bits = CONFIG_LPUART1_BITS,
	.stopbits2 = CONFIG_LPUART1_2STOP,
#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_LPUART1_OFLOWCONTROL)
	.oflow        = 1,
	.cts_gpio     = GPIO_LPUART1_CTS,
#endif
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_LPUART1_IFLOWCONTROL)
	.iflow        = 1,
	.rts_gpio     = GPIO_LPUART1_RTS,
#endif
};

static struct uart_dev_s g_uart1port = {
	.recv = {
		.size = CONFIG_LPUART1_RXBUFSIZE,
		.buffer = g_uart1rxbuffer,
	},
	.xmit = {
		.size = CONFIG_LPUART1_TXBUFSIZE,
		.buffer = g_uart1txbuffer,
	},
	.ops = &g_uart_ops,
	.priv = &g_uart1priv,
};
#endif

/* This describes the state of the IMXRT lpuart2 port. */

#ifdef CONFIG_IMXRT_LPUART2
static struct imxrt_uart_s g_uart2priv = {
	.uartbase = IMXRT_LPUART2_BASE,
	.baud = CONFIG_LPUART2_BAUD,
	.irq = IMXRT_IRQ_LPUART2,
	.parity = CONFIG_LPUART2_PARITY,
	.bits = CONFIG_LPUART2_BITS,
	.stopbits2 = CONFIG_LPUART2_2STOP,
#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_LPUART2_OFLOWCONTROL)
	.oflow        = 1,
	.cts_gpio     = GPIO_LPUART2_CTS,
#endif
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_LPUART2_IFLOWCONTROL)
	.iflow        = 1,
	.rts_gpio     = GPIO_LPUART2_RTS,
#endif
};

static struct uart_dev_s g_uart2port = {
	.recv = {
		.size = CONFIG_LPUART2_RXBUFSIZE,
		.buffer = g_uart2rxbuffer,
	},
	.xmit = {
		.size = CONFIG_LPUART2_TXBUFSIZE,
		.buffer = g_uart2txbuffer,
	},
	.ops = &g_uart_ops,
	.priv = &g_uart2priv,
};
#endif

#ifdef CONFIG_IMXRT_LPUART3
static struct imxrt_uart_s g_uart3priv = {
	.uartbase = IMXRT_LPUART3_BASE,
	.baud = CONFIG_LPUART3_BAUD,
	.irq = IMXRT_IRQ_LPUART3,
	.parity = CONFIG_LPUART3_PARITY,
	.bits = CONFIG_LPUART3_BITS,
	.stopbits2 = CONFIG_LPUART3_2STOP,
#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_LPUART3_OFLOWCONTROL)
	.oflow        = 1,
	.cts_gpio     = GPIO_LPUART3_CTS,
#endif
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_LPUART3_IFLOWCONTROL)
	.iflow        = 1,
	.rts_gpio     = GPIO_LPUART3_RTS,
#endif
};

static struct uart_dev_s g_uart3port = {
	.recv = {
		.size = CONFIG_LPUART3_RXBUFSIZE,
		.buffer = g_uart3rxbuffer,
	},
	.xmit = {
		.size = CONFIG_LPUART3_TXBUFSIZE,
		.buffer = g_uart3txbuffer,
	},
	.ops = &g_uart_ops,
	.priv = &g_uart3priv,
};
#endif

#ifdef CONFIG_IMXRT_LPUART4
static struct imxrt_uart_s g_uart4priv = {
	.uartbase = IMXRT_LPUART4_BASE,
	.baud = CONFIG_LPUART4_BAUD,
	.irq = IMXRT_IRQ_LPUART4,
	.parity = CONFIG_LPUART4_PARITY,
	.bits = CONFIG_LPUART4_BITS,
	.stopbits2 = CONFIG_LPUART4_2STOP,
#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_LPUART4_OFLOWCONTROL)
	.oflow        = 1,
	.cts_gpio     = GPIO_LPUART4_CTS,
#endif
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_LPUART4_IFLOWCONTROL)
	.iflow        = 1,
	.rts_gpio     = GPIO_LPUART4_RTS,
#endif
};

static struct uart_dev_s g_uart4port = {
	.recv = {
		.size = CONFIG_LPUART4_RXBUFSIZE,
		.buffer = g_uart4rxbuffer,
	},
	.xmit = {
		.size = CONFIG_LPUART4_TXBUFSIZE,
		.buffer = g_uart4txbuffer,
	},
	.ops = &g_uart_ops,
	.priv = &g_uart4priv,
};
#endif

#ifdef CONFIG_IMXRT_LPUART5
static struct imxrt_uart_s g_uart5priv = {
	.uartbase = IMXRT_LPUART5_BASE,
	.baud = CONFIG_LPUART5_BAUD,
	.irq = IMXRT_IRQ_LPUART5,
	.parity = CONFIG_LPUART5_PARITY,
	.bits = CONFIG_LPUART5_BITS,
	.stopbits2 = CONFIG_LPUART5_2STOP,
#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_LPUART5_OFLOWCONTROL)
	.oflow        = 1,
	.cts_gpio     = GPIO_LPUART5_CTS,
#endif
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_LPUART5_IFLOWCONTROL)
	.iflow        = 1,
	.rts_gpio     = GPIO_LPUART5_RTS,
#endif
};

static struct uart_dev_s g_uart5port = {
	.recv = {
		.size = CONFIG_LPUART5_RXBUFSIZE,
		.buffer = g_uart5rxbuffer,
	},
	.xmit = {
		.size = CONFIG_LPUART5_TXBUFSIZE,
		.buffer = g_uart5txbuffer,
	},
	.ops = &g_uart_ops,
	.priv = &g_uart5priv,
};
#endif

#ifdef CONFIG_IMXRT_LPUART6
static struct imxrt_uart_s g_uart6priv = {
	.uartbase = IMXRT_LPUART6_BASE,
	.baud = CONFIG_LPUART6_BAUD,
	.irq = IMXRT_IRQ_LPUART6,
	.parity = CONFIG_LPUART6_PARITY,
	.bits = CONFIG_LPUART6_BITS,
	.stopbits2 = CONFIG_LPUART6_2STOP,
#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_LPUART6_OFLOWCONTROL)
	.oflow        = 1,
	.cts_gpio     = GPIO_LPUART6_CTS,
#endif
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_LPUART6_IFLOWCONTROL)
	.iflow        = 1,
	.rts_gpio     = GPIO_LPUART6_RTS,
#endif
};

static struct uart_dev_s g_uart6port = {
	.recv = {
		.size = CONFIG_LPUART6_RXBUFSIZE,
		.buffer = g_uart6rxbuffer,
	},
	.xmit = {
		.size = CONFIG_LPUART6_TXBUFSIZE,
		.buffer = g_uart6txbuffer,
	},
	.ops = &g_uart_ops,
	.priv = &g_uart6priv,
};
#endif

#ifdef CONFIG_IMXRT_LPUART7
static struct imxrt_uart_s g_uart7priv = {
	.uartbase = IMXRT_LPUART7_BASE,
	.baud = CONFIG_LPUART7_BAUD,
	.irq = IMXRT_IRQ_LPUART7,
	.parity = CONFIG_LPUART7_PARITY,
	.bits = CONFIG_LPUART7_BITS,
	.stopbits2 = CONFIG_LPUART7_2STOP,
#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_LPUART7_OFLOWCONTROL)
	.oflow        = 1,
	.cts_gpio     = GPIO_LPUART7_CTS,
#endif
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_LPUART7_IFLOWCONTROL)
	.iflow        = 1,
	.rts_gpio     = GPIO_LPUART7_RTS,
#endif
};

static struct uart_dev_s g_uart7port = {
	.recv = {
		.size = CONFIG_LPUART7_RXBUFSIZE,
		.buffer = g_uart7rxbuffer,
	},
	.xmit = {
		.size = CONFIG_LPUART7_TXBUFSIZE,
		.buffer = g_uart7txbuffer,
	},
	.ops = &g_uart_ops,
	.priv = &g_uart7priv,
};
#endif

#ifdef CONFIG_IMXRT_LPUART8
static struct imxrt_uart_s g_uart8priv = {
	.uartbase = IMXRT_LPUART8_BASE,
	.baud = CONFIG_LPUART8_BAUD,
	.irq = IMXRT_IRQ_LPUART8,
	.parity = CONFIG_LPUART8_PARITY,
	.bits = CONFIG_LPUART8_BITS,
	.stopbits2 = CONFIG_LPUART8_2STOP,
#if defined(CONFIG_SERIAL_OFLOWCONTROL) && defined(CONFIG_LPUART8_OFLOWCONTROL)
	.oflow        = 1,
	.cts_gpio     = GPIO_LPUART8_CTS,
#endif
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && defined(CONFIG_LPUART8_IFLOWCONTROL)
	.iflow        = 1,
	.rts_gpio     = GPIO_LPUART8_RTS,
#endif
};

static struct uart_dev_s g_uart8port = {
	.recv = {
		.size = CONFIG_LPUART8_RXBUFSIZE,
		.buffer = g_uart8rxbuffer,
	},
	.xmit = {
		.size = CONFIG_LPUART8_TXBUFSIZE,
		.buffer = g_uart8txbuffer,
	},
	.ops = &g_uart_ops,
	.priv = &g_uart8priv,
};
#endif

#ifdef CONFIG_PM
static struct pm_callback_s g_serial_pmcb = {
	.notify = up_pm_notify,
	.prepare = up_pm_prepare,
};
#endif

/****************************************************************************
 * Private Functions
 ****************************************************************************/

/****************************************************************************
 * Name: imxrt_serialin
 ****************************************************************************/

static inline uint32_t imxrt_serialin(struct imxrt_uart_s *priv, uint32_t offset)
{
	return getreg32(priv->uartbase + offset);
}

/****************************************************************************
 * Name: imxrt_serialout
 ****************************************************************************/

static inline void imxrt_serialout(struct imxrt_uart_s *priv, uint32_t offset, uint32_t value)
{
	putreg32(value, priv->uartbase + offset);
}

/****************************************************************************
 * Name: imxrt_disableuartint
 ****************************************************************************/

static inline void imxrt_disableuartint(struct imxrt_uart_s *priv, uint32_t *ie)
{
	irqstate_t flags;
	uint32_t regval;

	flags = irqsave();
	regval = imxrt_serialin(priv, IMXRT_LPUART_CTRL_OFFSET);

	/* Return the current Rx and Tx interrupt state */

	if (ie != NULL) {
		*ie = regval & LPUART_ALL_INTS;
	}

	regval &= ~LPUART_ALL_INTS;
	imxrt_serialout(priv, IMXRT_LPUART_CTRL_OFFSET, regval);
	irqrestore(flags);
}

/****************************************************************************
 * Name: imxrt_restoreuartint
 ****************************************************************************/

static inline void imxrt_restoreuartint(struct imxrt_uart_s *priv, uint32_t ie)
{
	irqstate_t flags;
	uint32_t regval;

	/* Enable/disable any interrupts that are currently disabled but should be
	 * enabled/disabled.
	 */

	flags = irqsave();
	regval = imxrt_serialin(priv, IMXRT_LPUART_CTRL_OFFSET);
	regval &= ~LPUART_ALL_INTS;
	regval |= ie;
	imxrt_serialout(priv, IMXRT_LPUART_CTRL_OFFSET, regval);
	irqrestore(flags);
}

/****************************************************************************
 * Name: imxrt_setup
 *
 * Description:
 *   Configure the UART baud, bits, parity, fifos, etc. This
 *   method is called the first time that the serial port is
 *   opened.
 *
 ****************************************************************************/

static int imxrt_setup(struct uart_dev_s *dev)
{
	struct imxrt_uart_s *priv = (struct imxrt_uart_s *)dev->priv;
#ifndef CONFIG_SUPPRESS_LPUART_CONFIG
	struct uart_config_s config;
	int ret;

	/* Configure the UART */

	config.baud = priv->baud;	/* Configured baud */
	config.parity = priv->parity;	/* 0=none, 1=odd, 2=even */
	config.bits = priv->bits;	/* Number of bits (5-9) */
	config.stopbits2 = priv->stopbits2;	/* true: Configure with 2 stop bits instead of 1 */

	ret = imxrt_lpuart_configure(priv->uartbase, &config);

	priv->ie = imxrt_serialin(priv, IMXRT_LPUART_CTRL_OFFSET) & LPUART_ALL_INTS;
	return ret;

#else
	priv->ie = imxrt_serialin(priv, IMXRT_LPUART_CTRL_OFFSET) & LPUART_ALL_INTS;
	return OK;
#endif
}

/****************************************************************************
 * Name: imxrt_shutdown
 *
 * Description:
 *   Disable the UART.  This method is called when the serial
 *   port is closed
 *
 ****************************************************************************/

static void imxrt_shutdown(struct uart_dev_s *dev)
{
	struct imxrt_uart_s *priv = (struct imxrt_uart_s *)dev->priv;

	/* Disable the UART */

	imxrt_serialout(priv, IMXRT_LPUART_GLOBAL_OFFSET, LPUART_GLOBAL_RST(1U));
}

/****************************************************************************
 * Name: imxrt_attach
 *
 * Description:
 *   Configure the UART to operation in interrupt driven mode.  This method
 *   is called when the serial port is opened.  Normally, this is just after
 *   the setup() method is called, however, the serial console may operate
 *   in a non-interrupt driven mode during the boot phase.
 *
 *   RX and TX interrupts are not enabled when by the attach method (unless
 *   the hardware supports multiple levels of interrupt enabling).  The RX
 *   and TX interrupts are not enabled until the txint() and rxint() methods
 *   are called.
 *
 ****************************************************************************/

static int imxrt_attach(struct uart_dev_s *dev)
{
	struct imxrt_uart_s *priv = (struct imxrt_uart_s *)dev->priv;
	int ret;

	/* Attach and enable the IRQ */

	ret = irq_attach(priv->irq, imxrt_interrupt, dev);
	if (ret == OK) {
		/* Enable the interrupt (RX and TX interrupts are still disabled
		 * in the UART
		 */

		up_enable_irq(priv->irq);
	}

	return ret;
}

/****************************************************************************
 * Name: imxrt_detach
 *
 * Description:
 *   Detach UART interrupts.  This method is called when the serial port is
 *   closed normally just before the shutdown method is called.  The
 *   exception is the serial console which is never shutdown.
 *
 ****************************************************************************/

static void imxrt_detach(struct uart_dev_s *dev)
{
	struct imxrt_uart_s *priv = (struct imxrt_uart_s *)dev->priv;

	up_disable_irq(priv->irq);
	irq_detach(priv->irq);
}

/****************************************************************************
 * Name: imxrt_interrupt (and front-ends)
 *
 * Description:
 *   This is the common UART interrupt handler.  It should cal
 *   uart_transmitchars or uart_receivechar to perform the appropriate data
 *   transfers.
 *
 ****************************************************************************/

static int imxrt_interrupt(int irq, void *context, FAR void *arg)
{
	struct uart_dev_s *dev = (struct uart_dev_s *)arg;
	struct imxrt_uart_s *priv;
	uint32_t usr;
	int passes = 0;
	bool handled;

	DEBUGASSERT(dev != NULL && dev->priv != NULL);
	priv = (struct imxrt_uart_s *)dev->priv;

#if defined(CONFIG_PM) && CONFIG_IMXRT_PM_SERIAL_ACTIVITY > 0
	/* Report serial activity to the power management logic */

	pm_activity(PM_IDLE_DOMAIN, CONFIG_IMXRT_PM_SERIAL_ACTIVITY);
#endif

	/* Loop until there are no characters to be transferred or,
	 * until we have been looping for a long time.
	 */

	handled = true;
	for (passes = 0; passes < 256 && handled; passes++) {
		handled = false;

		/* Get the current UART status and check for loop
		 * termination conditions
		 */

		usr = imxrt_serialin(priv, IMXRT_LPUART_STAT_OFFSET);
		usr &= (LPUART_STAT_RDRF(1U) | LPUART_STAT_TC(1U) | LPUART_STAT_OR(1U) | LPUART_STAT_FE(1U));

		/* Clear serial overrun and framing errors */

		if ((usr & LPUART_STAT_OR(1U)) != 0) {
			imxrt_serialout(priv, IMXRT_LPUART_STAT_OFFSET, LPUART_STAT_OR(1U));
		}

		if ((usr & LPUART_STAT_FE(1U)) != 0) {
			imxrt_serialout(priv, IMXRT_LPUART_STAT_OFFSET, LPUART_STAT_FE(1U));
		}

		/* Handle incoming, receive bytes */

		if ((usr & LPUART_STAT_RDRF(1U)) != 0 && (priv->ie & LPUART_CTRL_RIE(1U)) != 0) {
			uart_recvchars(dev);
			handled = true;
		}

		/* Handle outgoing, transmit bytes */

		if ((usr & LPUART_STAT_TC(1U)) != 0 && (priv->ie & LPUART_CTRL_TCIE(1U)) != 0) {
			uart_xmitchars(dev);
			handled = true;
		}
	}

	return OK;
}

/****************************************************************************
 * Name: imxrt_ioctl
 *
 * Description:
 *   All ioctl calls will be routed through this method
 *
 ****************************************************************************/

static int imxrt_ioctl(struct file *filep, int cmd, unsigned long arg)
{
#if defined(CONFIG_SERIAL_TIOCSERGSTRUCT) || defined(CONFIG_SERIAL_TERMIOS)
	struct inode *inode = filep->f_inode;
	struct uart_dev_s *dev = inode->i_private;
#endif
	int ret = OK;

	switch (cmd) {
#ifdef CONFIG_SERIAL_TIOCSERGSTRUCT
	case TIOCSERGSTRUCT: {
		struct imxrt_uart_s *user = (struct imxrt_uart_s *)arg;
		if (!user) {
			ret = -EINVAL;
		} else {
			memcpy(user, dev, sizeof(struct imxrt_uart_s));
		}
	}
	break;
#endif

#ifdef CONFIG_SERIAL_TERMIOS
	case TCGETS: {
		struct termios *termiosp = (struct termios *)arg;
		struct imxrt_uart_s *priv = (struct imxrt_uart_s *)dev->priv;

		if (!termiosp) {
			ret = -EINVAL;
			break;
		}

		/* Return baud */

		cfsetispeed(termiosp, priv->baud);

		/* Return parity */

		termiosp->c_cflag = ((priv->parity != 0) ? PARENB : 0) | ((priv->parity == 1) ? PARODD : 0);

		/* Return stop bits */

		termiosp->c_cflag |= (priv->stopbits2) ? CSTOPB : 0;

		/* Return flow control */

#ifdef CONFIG_SERIAL_OFLOWCONTROL
		termiosp->c_cflag |= ((priv->oflow) ? CCTS_OFLOW : 0);
#endif
#ifdef CONFIG_SERIAL_IFLOWCONTROL
		termiosp->c_cflag |= ((priv->iflow) ? CRTS_IFLOW : 0);
#endif
		/* Return number of bits */

		switch (priv->bits) {
		case 5:
			termiosp->c_cflag |= CS5;
			break;

		case 6:
			termiosp->c_cflag |= CS6;
			break;

		case 7:
			termiosp->c_cflag |= CS7;
			break;

		default:
		case 8:
			termiosp->c_cflag |= CS8;
			break;

		case 9:
			termiosp->c_cflag |= CS8 /* CS9 */ ;
			break;
		}
	}
	break;

	case TCSETS: {
		struct termios *termiosp = (struct termios *)arg;
		struct imxrt_uart_s *priv = (struct imxrt_uart_s *)dev->priv;
		uint32_t baud;
		uint32_t ie;
		uint8_t parity;
		uint8_t nbits;
		bool stop2;

		if ((!termiosp)
#ifdef CONFIG_SERIAL_OFLOWCONTROL
			|| ((termiosp->c_cflag & CCTS_OFLOW) && (priv->cts_gpio == 0))
#endif
#ifdef CONFIG_SERIAL_IFLOWCONTROL
			|| ((termiosp->c_cflag & CRTS_IFLOW) && (priv->rts_gpio == 0))
#endif
		) {
			ret = -EINVAL;
			break;
		}

		/* Decode baud. */

		ret = OK;
		baud = cfgetispeed(termiosp);

		/* Decode number of bits */

		switch (termiosp->c_cflag & CSIZE) {
		case CS5:
			nbits = 5;
			break;

		case CS6:
			nbits = 6;
			break;

		case CS7:
			nbits = 7;
			break;

		case CS8:
			nbits = 8;
			break;
#if 0
		case CS9:
			nbits = 9;
			break;
#endif
		default:
			ret = -EINVAL;
			break;
		}

		/* Decode parity */

		if ((termiosp->c_cflag & PARENB) != 0) {
			parity = (termiosp->c_cflag & PARODD) ? 1 : 2;
		} else {
			parity = 0;
		}

		/* Decode stop bits */

		stop2 = (termiosp->c_cflag & CSTOPB) != 0;

		/* Verify that all settings are valid before committing */

		if (ret == OK) {
			/* Commit */

			priv->baud = baud;
			priv->parity = parity;
			priv->bits = nbits;
			priv->stopbits2 = stop2;
#ifdef CONFIG_SERIAL_OFLOWCONTROL
			priv->oflow     = (termiosp->c_cflag & CCTS_OFLOW) != 0;
#endif
#ifdef CONFIG_SERIAL_IFLOWCONTROL
			priv->iflow     = (termiosp->c_cflag & CRTS_IFLOW) != 0;
#endif
			/* effect the changes immediately - note that we do not
			 * implement TCSADRAIN / TCSAFLUSH
			 */

			imxrt_disableuartint(priv, &ie);
			ret = imxrt_setup(dev);

			/* Restore the interrupt state */

			imxrt_restoreuartint(priv, ie);
			priv->ie = ie;
		}
	}
	break;
#endif							/* CONFIG_SERIAL_TERMIOS */

	case TIOCSBRK:				/* BSD compatibility: Turn break on, unconditionally */
	case TIOCCBRK:				/* BSD compatibility: Turn break off, unconditionally */
	default:
		ret = -ENOTTY;
		break;
	}

	return ret;
}

/****************************************************************************
 * Name: imxrt_receive
 *
 * Description:
 *   Called (usually) from the interrupt level to receive one
 *   character from the UART.  Error bits associated with the
 *   receipt are provided in the return 'status'.
 *
 ****************************************************************************/

static int imxrt_receive(struct uart_dev_s *dev, uint32_t *status)
{
	struct imxrt_uart_s *priv = (struct imxrt_uart_s *)dev->priv;
	uint32_t rxd;

	rxd = imxrt_serialin(priv, IMXRT_LPUART_DATA_OFFSET);
	*status = rxd >> LPUART_DATA_STATUS_SHIFT;
	return (rxd & LPUART_DATA_MASK) >> LPUART_DATA_SHIFT;
}

/****************************************************************************
 * Name: imxrt_rxint
 *
 * Description:
 *   Call to enable or disable RX interrupts
 *
 ****************************************************************************/

static void imxrt_rxint(struct uart_dev_s *dev, bool enable)
{
	struct imxrt_uart_s *priv = (struct imxrt_uart_s *)dev->priv;
	irqstate_t flags;
	uint32_t regval;

	/* Enable interrupts for data available at Rx */

	flags = irqsave();
	if (enable) {
#ifndef CONFIG_SUPPRESS_SERIAL_INTS
		priv->ie |= LPUART_CTRL_RIE(1U) | LPUART_CTRL_FEIE(1U) | LPUART_CTRL_ORIE(1U);
#endif
	} else {
		priv->ie &= ~(LPUART_CTRL_RIE(1U) | LPUART_CTRL_FEIE(1U) | LPUART_CTRL_ORIE(1U));
	}

	regval = imxrt_serialin(priv, IMXRT_LPUART_CTRL_OFFSET);
	regval &= ~LPUART_ALL_INTS;
	regval |= priv->ie;
	imxrt_serialout(priv, IMXRT_LPUART_CTRL_OFFSET, regval);
	irqrestore(flags);
}

/****************************************************************************
 * Name: imxrt_rxavailable
 *
 * Description:
 *   Return true if the receive fifo is not empty
 *
 ****************************************************************************/

static bool imxrt_rxavailable(struct uart_dev_s *dev)
{
	struct imxrt_uart_s *priv = (struct imxrt_uart_s *)dev->priv;
	uint32_t regval;

	/* Return true is data is ready in the Rx FIFO */

	regval = imxrt_serialin(priv, IMXRT_LPUART_STAT_OFFSET);
	return ((regval & LPUART_STAT_RDRF(1U)) != 0);
}

/****************************************************************************
 * Name: imxrt_send
 *
 * Description:
 *   This method will send one byte on the UART
 *
 ****************************************************************************/

static void imxrt_send(struct uart_dev_s *dev, int ch)
{
	struct imxrt_uart_s *priv = (struct imxrt_uart_s *)dev->priv;
	imxrt_serialout(priv, IMXRT_LPUART_DATA_OFFSET, (uint32_t)ch);
}

/****************************************************************************
 * Name: imxrt_txint
 *
 * Description:
 *   Call to enable or disable TX interrupts
 *
 ****************************************************************************/

static void imxrt_txint(struct uart_dev_s *dev, bool enable)
{
	struct imxrt_uart_s *priv = (struct imxrt_uart_s *)dev->priv;
	irqstate_t flags;
	uint32_t regval;

	/* Enable interrupt for TX complete */

	flags = irqsave();
	if (enable) {
#ifndef CONFIG_SUPPRESS_SERIAL_INTS
		priv->ie |= LPUART_CTRL_TCIE(1U);
#endif
	} else {
		priv->ie &= ~LPUART_CTRL_TCIE(1U);
	}

	regval = imxrt_serialin(priv, IMXRT_LPUART_CTRL_OFFSET);
	regval &= ~LPUART_ALL_INTS;
	regval |= priv->ie;
	imxrt_serialout(priv, IMXRT_LPUART_CTRL_OFFSET, regval);
	irqrestore(flags);
}

/****************************************************************************
 * Name: imxrt_txready
 *
 * Description:
 *   Return true if the transmit is completed
 *
 ****************************************************************************/

static bool imxrt_txready(struct uart_dev_s *dev)
{
	struct imxrt_uart_s *priv = (struct imxrt_uart_s *)dev->priv;
	uint32_t regval;

	regval = imxrt_serialin(priv, IMXRT_LPUART_STAT_OFFSET);
	return ((regval & LPUART_STAT_TC(1U)) != 0);
}

/****************************************************************************
 * Name: imxrt_txempty
 *
 * Description:
 *   Return true if the transmit reg is empty
 *
 ****************************************************************************/

static bool imxrt_txempty(struct uart_dev_s *dev)
{
	struct imxrt_uart_s *priv = (struct imxrt_uart_s *)dev->priv;
	uint32_t regval;

	regval = imxrt_serialin(priv, IMXRT_LPUART_STAT_OFFSET);
	return ((regval & LPUART_STAT_TDRE(1U)) != 0);
}

/****************************************************************************
 * Name: up_pm_notify
 *
 * Description:
 *   Notify the driver of new power state. This callback is  called after
 *   all drivers have had the opportunity to prepare for the new power state.
 *
 * Input Parameters:
 *
 *    cb - Returned to the driver. The driver version of the callback
 *         structure may include additional, driver-specific state data at
 *         the end of the structure.
 *
 *    pmstate - Identifies the new PM state
 *
 * Returned Value:
 *   None - The driver already agreed to transition to the low power
 *   consumption state when when it returned OK to the prepare() call.
 *
 ****************************************************************************/

#ifdef CONFIG_PM
static void up_pm_notify(struct pm_callback_s *cb, int domain, enum pm_state_e pmstate)
{
	switch (pmstate) {
	case (PM_NORMAL): {
			/* Logic for PM_NORMAL goes here */

		}
		break;

	case (PM_IDLE): {
		/* Logic for PM_IDLE goes here */

	}
	break;

	case (PM_STANDBY): {
		/* Logic for PM_STANDBY goes here */

	}
	break;

	case (PM_SLEEP): {
		/* Logic for PM_SLEEP goes here */

	}
	break;

	default:
		/* Should not get here */
		break;
	}
}
#endif

/****************************************************************************
 * Name: up_pm_prepare
 *
 * Description:
 *   Request the driver to prepare for a new power state. This is a warning
 *   that the system is about to enter into a new power state. The driver
 *   should begin whatever operations that may be required to enter power
 *   state. The driver may abort the state change mode by returning a
 *   non-zero value from the callback function.
 *
 * Input Parameters:
 *
 *    cb - Returned to the driver. The driver version of the callback
 *         structure may include additional, driver-specific state data at
 *         the end of the structure.
 *
 *    pmstate - Identifies the new PM state
 *
 * Returned Value:
 *   Zero - (OK) means the event was successfully processed and that the
 *          driver is prepared for the PM state change.
 *
 *   Non-zero - means that the driver is not prepared to perform the tasks
 *              needed achieve this power setting and will cause the state
 *              change to be aborted. NOTE: The prepare() method will also
 *              be called when reverting from lower back to higher power
 *              consumption modes (say because another driver refused a
 *              lower power state change). Drivers are not permitted to
 *              return non-zero values when reverting back to higher power
 *              consumption modes!
 *
 *
 ****************************************************************************/

#ifdef CONFIG_PM
static int up_pm_prepare(struct pm_callback_s *cb, int domain, enum pm_state_e pmstate)
{
	/* Logic to prepare for a reduced power state goes here. */

	return OK;
}
#endif

/****************************************************************************
 * Public Functions
 ****************************************************************************/

/****************************************************************************
 * Name: imxrt_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.
 *
 ****************************************************************************/

void up_earlyserialinit(void)
{
	/* NOTE: This function assumes that low level hardware configuration
	 * -- including all clocking and pin configuration -- was performed by the
	 * function imxrt_lowsetup() earlier in the boot sequence.
	 */

	/* Enable the console UART.  The other UARTs will be initialized if and
	 * when they are first opened.
	 */

#ifdef CONSOLE_DEV
	CONSOLE_DEV.isconsole = true;
	CONSOLE_DEV.ops->setup(&CONSOLE_DEV);
#endif
}

/****************************************************************************
 * Name: up_serialinit
 *
 * Description:
 *   Register serial console and serial ports.  This assumes
 *   that imxrt_earlyserialinit was called previously.
 *
 ****************************************************************************/

void up_serialinit(void)
{
#ifdef CONFIG_PM
	int ret;

	/* Register to receive power management callbacks */

	ret = pm_register(&g_serial_pmcb);
	DEBUGASSERT(ret == OK);
	UNUSED(ret);
#endif

#ifdef CONSOLE_DEV
	(void)uart_register("/dev/console", &CONSOLE_DEV);
#endif

	/* Register all UARTs */

	(void)uart_register("/dev/ttyS0", &TTYS0_DEV);
#ifdef TTYS1_DEV
	(void)uart_register("/dev/ttyS1", &TTYS1_DEV);
#endif
#ifdef TTYS2_DEV
	(void)uart_register("/dev/ttyS2", &TTYS2_DEV);
#endif
#ifdef TTYS3_DEV
	(void)uart_register("/dev/ttyS3", &TTYS3_DEV);
#endif
#ifdef TTYS4_DEV
	(void)uart_register("/dev/ttyS4", &TTYS4_DEV);
#endif
#ifdef TTYS5_DEV
	(void)uart_register("/dev/ttyS5", &TTYS5_DEV);
#endif
#ifdef TTYS6_DEV
	(void)uart_register("/dev/ttyS6", &TTYS6_DEV);
#endif
#ifdef TTYS7_DEV
	(void)uart_register("/dev/ttyS7", &TTYS7_DEV);
#endif
}

/****************************************************************************
 * Name: up_putc
 *
 * Description:
 *   Provide priority, low-level access to support OS debug  writes
 *
 ****************************************************************************/

int up_putc(int ch)
{
#ifdef HAVE_SERIAL_CONSOLE
	struct imxrt_uart_s *priv = CONSOLE_DEV.priv;
	uint32_t ie;

	imxrt_disableuartint(priv, &ie);

	/* Check for LF */

	if (ch == '\n') {
		/* Add CR */
		imxrt_lowputc('\r');
	}

	imxrt_lowputc(ch);
	imxrt_restoreuartint(priv, ie);
#endif

	return ch;
}

#else							/* USE_SERIALDRIVER */

/****************************************************************************
 * Name: up_putc
 *
 * Description:
 *   Provide priority, low-level access to support OS debug writes
 *
 ****************************************************************************/

int up_putc(int ch)
{
#if CONSOLE_LPUART > 0
	/* Check for LF */

	if (ch == '\n') {
		/* Add CR */

		up_lowputc('\r');
	}

	up_lowputc(ch);
#endif

	return ch;
}

#endif							/* USE_SERIALDRIVER */


text:
Searchisko configuration - configuration of normalizations for "Normalization REST API"
======================================================================================

**[configuration API](http://docs.jbossorg.apiary.io/#managementapiconfiguration) id:** `normalizations`

This configuration document contains definition of normalizations which can be performed using
Searchisko 'Normalization API' `normalization` operation. It contains JSON object structure where key is
name of normalization (used to call it over REST API) and value is structure containing the normalization definition.
Definition MUST contain these fields:

* `description` - contains description of normalization for users. Is returned from "Normalization REST API" discovery method.
* `preprocessors` - contains chain of [preprocessors](https://github.com/searchisko/structured-content-tools)
  used to perform given normalization when called over REST API. We have few [Searchisko specific
  preprocessors](https://github.com/searchisko/searchisko/tree/master/api/src/main/java/org/searchisko/tools/content) also to
  ease configurations for Project and Contributor mappings etc.

Data passed to this preprocessor chain contain `input_id` field, which contains identifier passed over REST API to perform normalization for.
Everything preprocessors add to the data is returned in REST API response for given normalization.
Output may contain `warnings` field also, which contains warnings produced by preprocessors.

Example:

````
{
  "contributor_id_by_username" : {
    "description" : "This normalization takes username as input value, and returns contributor code",
    "preprocessors" : [
      {
        "name"     : "username to Contributor code mapper",
        "class"    : "org.jboss.elasticsearch.tools.content.ESLookupValuePreprocessor",
        "settings" : {
          "index_name"       : "sys_contributors",
          "index_type"       : "contributor",
          "source_field"     : "input_id",
          "idx_search_field" : "type_specific_code.username",
          "result_mapping"   : [{
            "idx_result_field" : "code",
            "target_field"     : "sys_contributor"
          }]
        }
      }
    ]
  },
  "contributor_profile_by_email" : {
    "description" : "This normalization takes email address as input value, and returns contributor code and basic contributor profile informations (full name, profile URL, thumbnail image URL)",
    "preprocessors" : [
      {
        "name"     : "email to Contributor code mapper",
        "class"    : "org.jboss.elasticsearch.tools.content.ESLookupValuePreprocessor",
        "settings" : {
          "index_name"       : "sys_contributors",
          "index_type"       : "contributor",
          "source_field"     : "input_id",
          "idx_search_field" : "email",
          "result_mapping"   : [{
            "idx_result_field" : "code",
            "target_field"     : "sys_contributor"
          }]
        }
      },{
        "name"     : "Profile by Contributor code loader",
        "class"    : "org.jboss.elasticsearch.tools.content.ESLookupValuePreprocessor",
        "settings" : {
          "index_name"       : "data_contributor_profile",
          "index_type"       : "jbossorg_contributor_profile",
          "source_field"     : "sys_contributor",
          "idx_search_field" : "sys_contributors",
          "result_mapping"   : [{
              "idx_result_field" : "sys_title",
              "target_field"     : "contributor_profile.sys_title"
            },{
              "idx_result_field" : "sys_url_view",
              "target_field"     : "contributor_profile.sys_url_view"
            },{
              "idx_result_field" : "thumbnailUrl",
              "target_field"     : "contributor_profile.thumbnailUrl"
          }]
        }
      }
    ]
  }
  ````

redpajama_set_name: RedPajamaGithub


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<title>Source code</title>
<link rel="stylesheet" type="text/css" href="../../stylesheet.css" title="Style">

001package squidpony;
002
003import java.awt.AWTException;
004import java.awt.BorderLayout;
005import java.awt.Color;
006import java.awt.Dimension;
007import java.awt.FlowLayout;
008import java.awt.Graphics;
009import java.awt.Rectangle;
010import java.awt.Robot;
011import java.awt.event.MouseEvent;
012import java.util.TreeMap;
013import javax.swing.DefaultComboBoxModel;
014import javax.swing.Icon;
015import javax.swing.JComboBox;
016import javax.swing.JPanel;
017import javax.swing.JScrollPane;
018import javax.swing.JTextField;
019import javax.swing.Scrollable;
020import javax.swing.SwingConstants;
021import javax.swing.colorchooser.AbstractColorChooserPanel;
022import javax.swing.event.MouseInputListener;
023
024/**
025 * This class provides a way to interact with the pre-defined SColor constants
026 * in a Swing GUI.
027 *
028 * @author Eben Howard - http://squidpony.com - howard@squidpony.com
029 */
030public class SColorChooserPanel extends AbstractColorChooserPanel {
031
032    private SColor[] colors = SColor.FULL_PALLET;
033    private TreeMap<String, SColor[]> colorMap = new TreeMap<>();
034    private int colorHeight = 20;
035    private int colorWidth = 40;
036    private ColorPanel displayPanel = new ColorPanel();
037    private JScrollPane scrollPane = new JScrollPane();
038    private JComboBox colorComboBox = new JComboBox();
039    private JTextField colorName = new JTextField();
040    private boolean initialized = false;
041
042    @Override
043    public void updateChooser() {
044    }
045
046    @Override
047    protected void buildChooser() {
048
049        scrollPane.setViewportView(displayPanel);
050        displayPanel.addMouseListener(displayPanel);
051        displayPanel.addMouseMotionListener(displayPanel);
052        colorComboBox.addActionListener(new java.awt.event.ActionListener() {
053            @Override
054            public void actionPerformed(java.awt.event.ActionEvent evt) {
055                colorComboBoxActionPerformed(evt);
056            }
057        });
058
059        colorMap.put("Achromatic Series", SColor.ACHROMATIC_SERIES);
060        colorMap.put("Blue Green Series", SColor.BLUE_GREEN_SERIES);
061        colorMap.put("Blue Violet Series", SColor.BLUE_VIOLET_SERIES);
062        colorMap.put("Full Pallet", SColor.FULL_PALLET);
063        colorMap.put("Rainbow", SColor.RAINBOW);
064        colorMap.put("Red Series", SColor.RED_SERIES);
065        colorMap.put("Red Violet Series", SColor.RED_VIOLET_SERIES);
066        colorMap.put("Violet Series", SColor.VIOLET_SERIES);
067        colorMap.put("Yellow Green Series", SColor.YELLOW_GREEN_SERIES);
068        colorMap.put("Yellow Red Series", SColor.YELLOW_RED_SERIES);
069        colorMap.put("Yellow Series", SColor.YELLOW_SERIES);
070
071        colorComboBox.setModel(new DefaultComboBoxModel(colorMap.keySet().toArray()));
072        setLayout(new BorderLayout());
073        add(colorComboBox, BorderLayout.NORTH);
074        add(scrollPane, BorderLayout.CENTER);
075        colorName.setEditable(false);
076        colorName.setHorizontalAlignment(JTextField.CENTER);
077        add(colorName, BorderLayout.SOUTH);
078
079        initialized = true;
080    }
081
082    private void refreshPanel() {
083        scrollPane.getViewport().setViewSize(displayPanel.getPreferredScrollableViewportSize());
084        scrollPane.getViewport().revalidate();
085        repaint();
086    }
087
088    private void colorComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
089        colors = colorMap.get((String) colorComboBox.getSelectedItem());
090        refreshPanel();
091    }
092
093    private void displayPanelMouseMoved(java.awt.event.MouseEvent evt) {
094        int index = evt.getY() / 20;
095        if (index < colors.length) {
096            String text = "";
097            switch (evt.getX() / colorWidth) {
098                case 0:
099                    text += "Fully Desaturated ";
100                    break;
101                case 1:
102                    text += "80% Desaturated ";
103                    break;
104                case 2:
105                    text += "Lightest ";
106                    break;
107                case 3:
108                    text += "Lighter ";
109                    break;
110                case 4:
111                    text += "Light ";
112                    break;
113                case 6:
114                    text += "Dim ";
115                    break;
116                case 7:
117                    text += "Dimmer ";
118                    break;
119                case 8:
120                    text += "Dimmest ";
121                    break;
122            }
123            text += colors[index].getName();
124//            displayPanel.setToolTipText(text);//don't need the tooltip with the display area
125            colorName.setText(text);
126        }
127    }
128
129    @Override
130    public String getDisplayName() {
131        return "SColor";
132    }
133
134    @Override
135    public Icon getSmallDisplayIcon() {
136        return null;
137    }
138
139    @Override
140    public Icon getLargeDisplayIcon() {
141        return null;
142    }
143
144    @Override
145    public void setBackground(Color bg) {
146        super.setBackground(bg);
147        if (initialized) {
148            displayPanel.setBackground(bg);
149            scrollPane.setBackground(bg);
150            colorComboBox.setBackground(bg);
151            colorName.setBackground(bg);
152        }
153    }
154
155    private class ColorPanel extends JPanel implements Scrollable, MouseInputListener {
156
157        ColorPanel() {
158            super(new FlowLayout());
159        }
160
161        @Override
162        public void setBackground(Color bg) {
163            super.setBackground(bg);
164        }
165
166        @Override
167        public Dimension getPreferredSize() {
168            return new Dimension(colorWidth * 9, colorHeight * colors.length);
169        }
170
171        @Override
172        public void paintComponent(Graphics g) {
173            super.paintComponent(g);
174            int x = 0;
175            int y = 0;
176
177            g.setColor(SColor.WHITE);
178            g.fillRect(0, 0, getWidth(), colorHeight);
179
180            for (int i = 0; i < colors.length; i++) {
181                SColor color = colors[i];
182
183                g.setColor(SColorFactory.desaturated(color));
184                g.fillRect(x, y, colorWidth, colorHeight);
185                x += colorWidth;
186
187                g.setColor(SColorFactory.desaturate(color, 0.8));
188                g.fillRect(x, y, colorWidth, colorHeight);
189                x += colorWidth;
190
191                g.setColor(SColorFactory.lightest(color));
192                g.fillRect(x, y, colorWidth, colorHeight);
193                x += colorWidth;
194
195                g.setColor(SColorFactory.lighter(color));
196                g.fillRect(x, y, colorWidth, colorHeight);
197                x += colorWidth;
198
199                g.setColor(SColorFactory.light(color));
200                g.fillRect(x, y, colorWidth, colorHeight);
201                x += colorWidth;
202
203                g.setColor(color);
204                g.fillRect(x, y, colorWidth, colorHeight);
205                x += colorWidth;
206
207                g.setColor(SColorFactory.dim(color));
208                g.fillRect(x, y, colorWidth, colorHeight);
209                x += colorWidth;
210
211                g.setColor(SColorFactory.dimmer(color));
212                g.fillRect(x, y, colorWidth, colorHeight);
213                x += colorWidth;
214
215                g.setColor(SColorFactory.dimmest(color));
216                g.fillRect(x, y, getWidth() - x, colorHeight);//last column fills out the rest of the space
217
218                x = 0;
219                y += colorHeight;
220            }
221        }
222
223        @Override
224        public Dimension getPreferredScrollableViewportSize() {
225            return new Dimension(colorWidth * 9, Math.min(400, colorHeight * colors.length));
226        }
227
228        @Override
229        public int getScrollableUnitIncrement(Rectangle rctngl, int i, int i1) {
230            if (i == SwingConstants.VERTICAL) {
231                return colorHeight;
232            } else {
233                return colorWidth;
234            }
235        }
236
237        @Override
238        public int getScrollableBlockIncrement(Rectangle rctngl, int i, int i1) {
239            if (i == SwingConstants.VERTICAL) {
240                return colorHeight * 5;
241            } else {
242                return colorWidth * 3;
243            }
244        }
245
246        @Override
247        public boolean getScrollableTracksViewportWidth() {
248            return false;
249        }
250
251        @Override
252        public boolean getScrollableTracksViewportHeight() {
253            return false;
254        }
255
256        @Override
257        public void mouseClicked(MouseEvent e) {
258            try {
259                Robot robot = new Robot();
260                getColorSelectionModel().setSelectedColor(robot.getPixelColor(e.getXOnScreen(), e.getYOnScreen()));
261            } catch (AWTException ex) {
262            }
263        }
264
265        @Override
266        public void mousePressed(MouseEvent e) {
267        }
268
269        @Override
270        public void mouseReleased(MouseEvent e) {
271        }
272
273        @Override
274        public void mouseEntered(MouseEvent e) {
275        }
276
277        @Override
278        public void mouseExited(MouseEvent e) {
279        }
280
281        @Override
282        public void mouseDragged(MouseEvent e) {
283        }
284
285        @Override
286        public void mouseMoved(MouseEvent e) {
287            displayPanelMouseMoved(e);
288        }
289    }
290}


text:
/* Stand alone funtions for QSpan Tundra support.
 */
#include <linux/types.h>
#include <linux/pci.h>
#include <asm/mpc8xx.h>

extern void puthex(unsigned long val);
extern void puts(const char *);

/* To map PCI devices, you first write 0xffffffff into the device
 * base address registers.  When the register is read back, the
 * number of most significant '1' bits describes the amount of address
 * space needed for mapping.  If the most significant bit is not set,
 * either the device does not use that address register, or it has
 * a fixed address that we can't change.  After the address is assigned,
 * the command register has to be written to enable the card.
 */
typedef struct {
	u_char	pci_bus;
	u_char	pci_devfn;
	ushort	pci_command;
	uint	pci_addrs[6];
} pci_map_t;

/* We should probably dynamically allocate these structures.
*/
#define MAX_PCI_DEVS	32
int	pci_dev_cnt;
pci_map_t	pci_map[MAX_PCI_DEVS];

void pci_conf_write(int bus, int device, int func, int reg, uint writeval);
void pci_conf_read(int bus, int device, int func, int reg, void *readval);
void probe_addresses(int bus, int devfn);
void map_pci_addrs(void);

extern int
qs_pci_read_config_byte(unsigned char bus, unsigned char dev_fn,
			unsigned char offset, unsigned char *val);
extern int
qs_pci_read_config_word(unsigned char bus, unsigned char dev_fn,
			unsigned char offset, unsigned short *val);
extern int
qs_pci_read_config_dword(unsigned char bus, unsigned char dev_fn,
			 unsigned char offset, unsigned int *val);
extern int
qs_pci_write_config_byte(unsigned char bus, unsigned char dev_fn,
			 unsigned char offset, unsigned char val);
extern int
qs_pci_write_config_word(unsigned char bus, unsigned char dev_fn,
			 unsigned char offset, unsigned short val);
extern int
qs_pci_write_config_dword(unsigned char bus, unsigned char dev_fn,
			  unsigned char offset, unsigned int val);

/* This is a really stripped version of PCI bus scan.  All we are
 * looking for are devices that exist.
 */
void
pci_scanner(int addr_probe)
{
	unsigned int devfn, l, class, bus_number;
	unsigned char hdr_type, is_multi;

	is_multi = 0;
	bus_number = 0;
	for (devfn = 0; devfn < 0xff; ++devfn) {
		/* The device numbers are comprised of upper 5 bits of
		 * device number and lower 3 bits of multi-function number.
		 */
		if ((devfn & 7) && !is_multi) {
			/* Don't scan multifunction addresses if this is
			 * not a multifunction device.
			 */
			continue;
		}

		/* Read the header to determine card type.
		*/
		qs_pci_read_config_byte(bus_number, devfn, PCI_HEADER_TYPE,
								&hdr_type);

		/* If this is a base device number, check the header to
		 * determine if it is mulifunction.
		 */
		if ((devfn & 7) == 0)
			is_multi = hdr_type & 0x80;

		/* Check to see if the board is really in the slot.
		*/
		qs_pci_read_config_dword(bus_number, devfn, PCI_VENDOR_ID, &l);
		/* some broken boards return 0 if a slot is empty: */
		if (l == 0xffffffff || l == 0x00000000 || l == 0x0000ffff ||
							l == 0xffff0000) {
			/* Nothing there.
			*/
			is_multi = 0;
			continue;
		}

		/* If we are not performing an address probe,
		 * just simply print out some information.
		 */
		if (!addr_probe) {
			qs_pci_read_config_dword(bus_number, devfn,
						PCI_CLASS_REVISION, &class);

			class >>= 8;	    /* upper 3 bytes */

#if 0
			printf("Found (%3d:%d): vendor 0x%04x, device 0x%04x, class 0x%06x\n",
				(devfn >> 3), (devfn & 7),
				(l & 0xffff),  (l >> 16) & 0xffff, class);
#else
			puts("Found ("); puthex(devfn >> 3);
			puts(":"); puthex(devfn & 7);
			puts("): vendor "); puthex(l & 0xffff);
			puts(", device "); puthex((l >> 16) & 0xffff);
			puts(", class "); puthex(class); puts("\n");
#endif
		}
		else {
			/* If this is a "normal" device, build address list.
			*/
			if ((hdr_type & 0x7f) == PCI_HEADER_TYPE_NORMAL)
				probe_addresses(bus_number, devfn);
		}
	}

	/* Now map the boards.
	*/
	if (addr_probe)
		map_pci_addrs();
}

/* Probe addresses for the specified device.  This is a destructive
 * operation because it writes the registers.
 */
void
probe_addresses(bus, devfn)
{
	int	i;
	uint	pciaddr;
	ushort	pcicmd;
	pci_map_t	*pm;

	if (pci_dev_cnt >= MAX_PCI_DEVS) {
		puts("Too many PCI devices\n");
		return;
	}

	pm = &pci_map[pci_dev_cnt++];

	pm->pci_bus = bus;
	pm->pci_devfn = devfn;

	for (i=0; i<6; i++) {
		qs_pci_write_config_dword(bus, devfn, PCI_BASE_ADDRESS_0 + (i * 4), -1);
		qs_pci_read_config_dword(bus, devfn, PCI_BASE_ADDRESS_0 + (i * 4),
								&pciaddr);
		pm->pci_addrs[i] = pciaddr;
		qs_pci_read_config_word(bus, devfn, PCI_COMMAND, &pcicmd);
		pm->pci_command = pcicmd;
	}
}

/* Map the cards into the PCI space.  The PCI has separate memory
 * and I/O spaces.  In addition, some memory devices require mapping
 * below 1M.  The least significant 4 bits of the address register
 * provide information.  If this is an I/O device, only the LS bit
 * is used to indicate that, so I/O devices can be mapped to a two byte
 * boundard.  Memory addresses can be mapped to a 32 byte boundary.
 * The QSpan implementations usually have a 1Gbyte space for each
 * memory and I/O spaces.
 *
 * This isn't a terribly fancy algorithm.  I just map the spaces from
 * the top starting with the largest address space.  When finished,
 * the registers are written and the card enabled.
 *
 * While the Tundra can map a large address space on most boards, we
 * need to be careful because it may overlap other devices (like IMMR).
 */
#define MEMORY_SPACE_SIZE	0x20000000
#define IO_SPACE_SIZE		0x20000000

void
map_pci_addrs()
{
	uint	pci_mem_top, pci_mem_low;
	uint	pci_io_top;
	uint	addr_mask, reg_addr, space;
	int	i, j;
	pci_map_t *pm;

	pci_mem_top = MEMORY_SPACE_SIZE;
	pci_io_top = IO_SPACE_SIZE;
	pci_mem_low = (1 * 1024 * 1024);	/* Below one meg addresses */

	/* We can't map anything more than the maximum space, but test
	 * for it anyway to catch devices out of range.
	 */
	addr_mask = 0x80000000;

	do {
		space = (~addr_mask) + 1;	/* Size of the space */
		for (i=0; i<pci_dev_cnt; i++) {
			pm = &pci_map[i];
			for (j=0; j<6; j++) {
				/* If the MS bit is not set, this has either
				 * already been mapped, or is not used.
				 */
				reg_addr = pm->pci_addrs[j];
				if ((reg_addr & 0x80000000) == 0)
					continue;
				if (reg_addr & PCI_BASE_ADDRESS_SPACE_IO) {
					if ((reg_addr & PCI_BASE_ADDRESS_IO_MASK) != addr_mask)
						continue;
					if (pci_io_top < space) {
						puts("Out of PCI I/O space\n");
					}
					else {
						pci_io_top -= space;
						pm->pci_addrs[j] = pci_io_top;
						pm->pci_command |= PCI_COMMAND_IO;
					}
				}
				else {
					if ((reg_addr & PCI_BASE_ADDRESS_MEM_MASK) != addr_mask)
						continue;

					/* Memory space.  Test if below 1M.
					*/
					if (reg_addr & PCI_BASE_ADDRESS_MEM_TYPE_1M) {
						if (pci_mem_low < space) {
							puts("Out of PCI 1M space\n");
						}
						else {
							pci_mem_low -= space;
							pm->pci_addrs[j] = pci_mem_low;
						}
					}
					else {
						if (pci_mem_top < space) {
							puts("Out of PCI Mem space\n");
						}
						else {
							pci_mem_top -= space;
							pm->pci_addrs[j] = pci_mem_top;
						}
					}
					pm->pci_command |= PCI_COMMAND_MEMORY;
				}
			}
		}
		addr_mask >>= 1;
		addr_mask |= 0x80000000;
	} while (addr_mask != 0xfffffffe);

	/* Now, run the list one more time and map everything.
	*/
	for (i=0; i<pci_dev_cnt; i++) {
		pm = &pci_map[i];
		for (j=0; j<6; j++) {
			qs_pci_write_config_dword(pm->pci_bus, pm->pci_devfn,
				PCI_BASE_ADDRESS_0 + (j * 4), pm->pci_addrs[j]);
		}

		/* Enable memory or address mapping.
		*/
		qs_pci_write_config_word(pm->pci_bus, pm->pci_devfn, PCI_COMMAND,
			pm->pci_command);
	}
}


text:
package org.usfirst.frc.team334.robot.components;

import edu.wpi.first.wpilibj.I2C;
import edu.wpi.first.wpilibj.command.Subsystem;
import org.usfirst.frc.team334.robot.controls.Constants;

import java.nio.ByteBuffer;

public class LedRing extends Subsystem {

    // Hook up pins A4 to SCL on RoboRio, A5 to SDA on RoboRio, and GND to ground on RoboRio
    private I2C ringWriter = new I2C(I2C.Port.kOnboard, Constants.LED_RINGS);

    // sendRGB method requires led start and stop positions, red, green, blue and values
    public void sendRGB(int start, int stop, int r, int g, int b) {
        // ByteBuffer needed to send values to RioDuino
        int bufSize = 5;
        ByteBuffer buf = ByteBuffer.allocateDirect(bufSize);

        int[] message = {start, stop, r, g, b};

        // Converts int to byte and puts it in the buffer to be sent
        LedControl.writeBytesToBuffer(buf, message);

        // Transfers bytes to RioDuino
        ringWriter.writeBulk(buf, bufSize);
    }

    @Override
    protected void initDefaultCommand() {

    }

}


text:
require 'sinatra'

module Fabes
  class Admin < Sinatra::Base
    dir = File.dirname File.expand_path __FILE__
    set :views, dir + '/admin/views'
    set :public_folder, dir + '/admin/public'
    set :static, true

    get '/' do
      @experiments = Fabes::Experiment.all
      haml :index
    end
  end
end


text:
using namespace gpos;
using namespace gpdxl;

//---------------------------------------------------------------------------
//	@function:
//		CDXLLogicalConstTable::CDXLLogicalConstTable
//
//	@doc:
//		Constructor
//
//---------------------------------------------------------------------------
CDXLLogicalConstTable::CDXLLogicalConstTable
	(
	IMemoryPool *pmp,
	DrgPdxlcd *pdrgpdxlcd,
	DrgPdrgPdxldatum *pdrgpdrgpdxldatum
	)
	:
	CDXLLogical(pmp),
	m_pdrgpdxlcd(pdrgpdxlcd),
	m_pdrgpdrgpdxldatum(pdrgpdrgpdxldatum)
{
	GPOS_ASSERT(NULL != pdrgpdxlcd);
	GPOS_ASSERT(NULL != pdrgpdrgpdxldatum);

#ifdef GPOS_DEBUG
	const ULONG ulLen = pdrgpdrgpdxldatum->UlLength();
	for (ULONG ul = 0; ul < ulLen; ul++)
	{
		DrgPdxldatum *pdrgpdxldatum = (*pdrgpdrgpdxldatum)[ul];
		GPOS_ASSERT(pdrgpdxldatum->UlLength() == pdrgpdxlcd->UlLength());
	}
#endif
}

//---------------------------------------------------------------------------
//	@function:
//		CDXLLogicalConstTable::~CDXLLogicalConstTable
//
//	@doc:
//		Destructor
//
//---------------------------------------------------------------------------
CDXLLogicalConstTable::~CDXLLogicalConstTable()
{
	m_pdrgpdxlcd->Release();
	m_pdrgpdrgpdxldatum->Release();
}

//---------------------------------------------------------------------------
//	@function:
//		CDXLLogicalConstTable::Edxlop
//
//	@doc:
//		Operator type
//
//---------------------------------------------------------------------------
Edxlopid
CDXLLogicalConstTable::Edxlop() const
{
	return EdxlopLogicalConstTable;
}

//---------------------------------------------------------------------------
//	@function:
//		CDXLLogicalConstTable::PstrOpName
//
//	@doc:
//		Operator name
//
//---------------------------------------------------------------------------
const CWStringConst *
CDXLLogicalConstTable::PstrOpName() const
{
	return CDXLTokens::PstrToken(EdxltokenLogicalConstTable);
}

//---------------------------------------------------------------------------
//	@function:
//		CDXLLogicalConstTable::Pdxlcd
//
//	@doc:
//		Type of const table element at given position
//
//---------------------------------------------------------------------------
CDXLColDescr *
CDXLLogicalConstTable::Pdxlcd
	(
	ULONG ul
	)
	const
{
	GPOS_ASSERT(m_pdrgpdxlcd->UlLength() > ul);
	return (*m_pdrgpdxlcd)[ul];
}

//---------------------------------------------------------------------------
//	@function:
//		CDXLLogicalConstTable::UlArity
//
//	@doc:
//		Const table arity
//
//---------------------------------------------------------------------------
ULONG
CDXLLogicalConstTable::UlArity() const
{
	return m_pdrgpdxlcd->UlLength();
}

//---------------------------------------------------------------------------
//	@function:
//		CDXLLogicalConstTable::SerializeToDXL
//
//	@doc:
//		Serialize operator in DXL format
//
//---------------------------------------------------------------------------
void
CDXLLogicalConstTable::SerializeToDXL
	(
	CXMLSerializer *pxmlser,
	const CDXLNode *//pdxln
	)
	const
{
	const CWStringConst *pstrElemName = PstrOpName();

	pxmlser->OpenElement(CDXLTokens::PstrToken(EdxltokenNamespacePrefix), pstrElemName);

	// serialize columns
	pxmlser->OpenElement(CDXLTokens::PstrToken(EdxltokenNamespacePrefix), CDXLTokens::PstrToken(EdxltokenColumns));

	for (ULONG i = 0; i < UlArity(); i++)
	{
		CDXLColDescr *pdxlcd = (*m_pdrgpdxlcd)[i];
		pdxlcd->SerializeToDXL(pxmlser);
	}

	pxmlser->CloseElement(CDXLTokens::PstrToken(EdxltokenNamespacePrefix), CDXLTokens::PstrToken(EdxltokenColumns));

	const CWStringConst *pstrElemNameConstTuple = CDXLTokens::PstrToken(EdxltokenConstTuple);
	const CWStringConst *pstrElemNameDatum = CDXLTokens::PstrToken(EdxltokenDatum);

	const ULONG ulTuples = m_pdrgpdrgpdxldatum->UlLength();
	for (ULONG ulTuplePos = 0; ulTuplePos < ulTuples; ulTuplePos++)
	{
		// serialize a const tuple
		pxmlser->OpenElement(CDXLTokens::PstrToken(EdxltokenNamespacePrefix), pstrElemNameConstTuple);
		DrgPdxldatum *pdrgpdxldatum = (*m_pdrgpdrgpdxldatum)[ulTuplePos];

		const ULONG ulCols = pdrgpdxldatum->UlLength();
		for (ULONG ulColPos = 0; ulColPos < ulCols; ulColPos++)
		{
			CDXLDatum *pdxldatum = (*pdrgpdxldatum)[ulColPos];
			pdxldatum->Serialize(pxmlser, pstrElemNameDatum);
		}

		pxmlser->CloseElement(CDXLTokens::PstrToken(EdxltokenNamespacePrefix), pstrElemNameConstTuple);
	}

	pxmlser->CloseElement(CDXLTokens::PstrToken(EdxltokenNamespacePrefix), pstrElemName);
}

//---------------------------------------------------------------------------
//	@function:
//		CDXLLogicalConstTable::FDefinesColumn
//
//	@doc:
//		Check if given column is defined by operator
//
//---------------------------------------------------------------------------
BOOL
CDXLLogicalConstTable::FDefinesColumn
	(
	ULONG ulColId
	)
	const
{
	const ULONG ulSize = UlArity();
	for (ULONG ulDescr = 0; ulDescr < ulSize; ulDescr++)
	{
		ULONG ulId = Pdxlcd(ulDescr)->UlID();
		if (ulId == ulColId)
		{
			return true;
		}
	}

	return false;
}

#ifdef GPOS_DEBUG
//---------------------------------------------------------------------------
//	@function:
//		CDXLLogicalConstTable::AssertValid
//
//	@doc:
//		Checks whether operator node is well-structured
//
//---------------------------------------------------------------------------
void
CDXLLogicalConstTable::AssertValid
	(
	const CDXLNode *pdxln,
	BOOL //fValidateChildren
	) const
{
	// assert validity of col descr
	GPOS_ASSERT(m_pdrgpdxlcd != NULL);
	GPOS_ASSERT(0 < m_pdrgpdxlcd->UlLength());
	GPOS_ASSERT(0 == pdxln->UlArity());
}
#endif // GPOS_DEBUG

// EOF


text:
package org.jboss.weld.environment.servlet.test.discovery.alternatives;

import jakarta.enterprise.context.Dependent;
import jakarta.enterprise.inject.Alternative;

import org.jboss.weld.environment.servlet.test.discovery.Tree;

@Alternative
@Dependent
public class AlternativeTree extends Tree {

}


text:
import copy

class BubbleSort:

    def sort(self, to_sort, steps=[]):
        for i in range(len(to_sort) - 1):
            if to_sort[i] > to_sort[i + 1]:
                to_sort[i], to_sort[i + 1] = to_sort[i + 1], to_sort[i]
                steps.append(copy.copy(to_sort))
                self.sort(to_sort, steps)
        return to_sort

    def sort_steps(self, to_sort):
        steps = []
        self.sort(to_sort, steps)
        return steps

    def compare(self, to_sort, given):
        actual = self.sort_steps(to_sort)
        return actual == given


text:
<!DOCTYPE html>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Klondike - NuGet Package Repository</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    {{content-for 'head'}}

    <link rel="stylesheet" href="assets/vendor.css">
    <link rel="stylesheet" href="assets/klondike.css">

    {{content-for 'head-footer'}}

    {{content-for 'body'}}

          Welcome to Klondike, the NuGet repository
          for caching public packages and storing your private packages privately.

Getting Started

To use this repository from Visual Studio, add a new Package Source using this URL:

Alternatively, you can add the package source from the command line as follows:

Wait, What is this Thing?

          Do you know what the .NET Framework is?
          Do you know what NuGet is? No? If not, you can probably stop reading now. Instead perhaps do some
          research on
          monkeys riding dogs.

          Klondike is similar to the NuGet.Server project
          that lets you host a package feed on your own private network. Klondike is different because it's
          faster. Way faster. The problem with NuGet.Server is that it slows down to a crawl after you add around
          100 packages. Klondike uses Lucene.Net.Linq
          to index your projects to give you all the searchy goodness of Lucene along with super fast package
          retrieval.

You Should Use Klondike if...

You develop software with Microsoft.NET or the Mono Framework

You use NuGet

You don't want your build to break when nuget.org goes down, or

You create packages for private consumption, or

You want a place to push packages to test them before releasing to nuget.org

          You should not use Klondike if you are not awesome.

    {{content-for 'body-footer'}}


text:
using System;
using System.Diagnostics;
using System.Globalization;

namespace Octokit
{
    [DebuggerDisplay("{DebuggerDisplay,nq}")]
    public class LdapSyncResponse
    {
        public LdapSyncResponse() { }

        public LdapSyncResponse(string status)
        {
            Status = status;
        }

        public string Status
        {
            get;
            private set;
        }

        internal string DebuggerDisplay
        {
            get
            {
                return String.Format(CultureInfo.InvariantCulture, "Status: {0}", Status);
            }
        }
    }
}


text:
using System.Text.Json;
using Azure.Core;

namespace Azure.ResourceManager.FrontDoor.Models
{
    public partial class FrontDoorValidateCustomDomainContent : IUtf8JsonSerializable
    {
        void IUtf8JsonSerializable.Write(Utf8JsonWriter writer)
        {
            writer.WriteStartObject();
            writer.WritePropertyName("hostName");
            writer.WriteStringValue(HostName);
            writer.WriteEndObject();
        }
    }
}


text:
package com.amazonaws.services.backup.model;

import java.io.Serializable;
import javax.annotation.Generated;

/**
 *
 * @see AWS
 *      API Documentation
 */
@Generated("com.amazonaws:aws-java-sdk-code-generator")
public class GetBackupPlanFromTemplateResult extends com.amazonaws.AmazonWebServiceResult<com.amazonaws.ResponseMetadata> implements Serializable, Cloneable {

    /**
     *

     * Returns the body of a backup plan based on the target template, including the name, rules, and backup vault of
     * the plan.
     *

     */
    private BackupPlan backupPlanDocument;

    /**
     *

     * Returns the body of a backup plan based on the target template, including the name, rules, and backup vault of
     * the plan.
     *

     *
     * @param backupPlanDocument
     *        Returns the body of a backup plan based on the target template, including the name, rules, and backup
     *        vault of the plan.
     */

    public void setBackupPlanDocument(BackupPlan backupPlanDocument) {
        this.backupPlanDocument = backupPlanDocument;
    }

    /**
     *

     * Returns the body of a backup plan based on the target template, including the name, rules, and backup vault of
     * the plan.
     *

     *
     * @return Returns the body of a backup plan based on the target template, including the name, rules, and backup
     *         vault of the plan.
     */

    public BackupPlan getBackupPlanDocument() {
        return this.backupPlanDocument;
    }

    /**
     *

     * Returns the body of a backup plan based on the target template, including the name, rules, and backup vault of
     * the plan.
     *

     *
     * @param backupPlanDocument
     *        Returns the body of a backup plan based on the target template, including the name, rules, and backup
     *        vault of the plan.
     * @return Returns a reference to this object so that method calls can be chained together.
     */

    public GetBackupPlanFromTemplateResult withBackupPlanDocument(BackupPlan backupPlanDocument) {
        setBackupPlanDocument(backupPlanDocument);
        return this;
    }

    /**
     * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be
     * redacted from this string using a placeholder value.
     *
     * @return A string representation of this object.
     *
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("{");
        if (getBackupPlanDocument() != null)
            sb.append("BackupPlanDocument: ").append(getBackupPlanDocument());
        sb.append("}");
        return sb.toString();
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;

        if (obj instanceof GetBackupPlanFromTemplateResult == false)
            return false;
        GetBackupPlanFromTemplateResult other = (GetBackupPlanFromTemplateResult) obj;
        if (other.getBackupPlanDocument() == null ^ this.getBackupPlanDocument() == null)
            return false;
        if (other.getBackupPlanDocument() != null && other.getBackupPlanDocument().equals(this.getBackupPlanDocument()) == false)
            return false;
        return true;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int hashCode = 1;

        hashCode = prime * hashCode + ((getBackupPlanDocument() == null) ? 0 : getBackupPlanDocument().hashCode());
        return hashCode;
    }

    @Override
    public GetBackupPlanFromTemplateResult clone() {
        try {
            return (GetBackupPlanFromTemplateResult) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new IllegalStateException("Got a CloneNotSupportedException from Object.clone() " + "even though we're Cloneable!", e);
        }
    }

}


text:
require 'redmine'
# encoding: utf-8
module WikiPagePatch
	def self.included(base) # :nodoc:
		base.send(:include, InstanceMethods)
		base.class_eval do
			alias_method_chain :diff, :decryption
			alias_method_chain :annotate, :decryption
		end
  	end

  module InstanceMethods
    $key = Digest::SHA256.hexdigest(Redmine::Configuration['database_cipher_key'].to_s.strip)

    def decrypt(encodedContent)

		e = OpenSSL::Cipher.new 'DES-EDE3-CBC'
		e.decrypt $key
		s = encodedContent.to_a.pack("H*").unpack("C*").pack("c*")
		s = e.update s
		decoded = s << e.final
		return decoded
	end

    def decodeContentWithTags(originalText)
		begin
			if Redmine::Configuration['database_cipher_key'].to_s.strip != ''
				matches = originalText.scan(/\{\{coded\_start\}\}.*?\{\{coded\_stop\}\}/m)
				matches.each do |m|
					tagContent = m.gsub('{{coded_start}}','').gsub('{{coded_stop}}','').strip
					decoded = decrypt(tagContent)
					decoded = '{{cipher}}'+decoded+'{{cipher}}'
					originalText = originalText.gsub(m.strip.force_encoding("UTF-8"), decoded.strip.force_encoding("UTF-8"))
				end
			end
		rescue
			#originalText = l("redmine_wikicipher.bad_decrypt")
		end
		return originalText
	end

    def decodeContent(originalText)
	begin
		matches = originalText.scan(/\{\{history\_coded\_start\}\}.*?\{\{history\_coded\_stop\}\}/m)
		matches.each do |m|
			tagContent = m.gsub('{{history_coded_start}}','').gsub('{{history_coded_stop}}','').strip
			decoded = decrypt(tagContent)
			decoded = ''+decoded+''
			originalText = originalText.gsub(m.strip.force_encoding("UTF-8"), decoded.strip.force_encoding("UTF-8"))
		end
		originalText = decodeContentWithTags(originalText)
	rescue
		#originalText = l("redmine_wikicipher.bad_decrypt")
	end
	return originalText
    end

    def annotate_with_decryption(version=nil)

    version = version ? version.to_i : self.content.version
    logger.warn('annotate version:'+version.to_s)
    c = content.versions.find_by_version(version)
    if c
	wa = WikiAnnotate.new(c)
        wa.lines.each do |line|
            logger.warn(line)
            #line[2] = decodeContent(line[2])

	end
        wa
    else
	nil
    end
  end

    def diff_with_decryption(version_to=nil, version_from=nil)
	version_to = version_to ? version_to.to_i : self.content.version
    	version_from = version_from ? version_from.to_i : version_to - 1
    version_to, version_from = version_from, version_to unless version_from < version_to

    content_to = content.versions.find_by_version(version_to)
    content_from = content.versions.find_by_version(version_from)
    tempTo = WikiContent.new
    tempFrom = WikiContent.new
    tempTo.text = content_to.text
    tempTo.author = content_to.author
    tempFrom.text = content_from.text
    tempFrom.author = content_from.author
    tempFrom.id = content_from.id
    tempTo.id = content_to.id
    tempTo.page_id = content_to.page_id
    tempFrom.page_id = content_from.page_id
    tempTo.author_id = content_to.author_id
    tempFrom.author_id = content_from.author_id
    tempTo.comments = content_to.comments
    tempFrom.comments = content_from.comments
    tempTo.updated_on = content_to.updated_on
    tempFrom.updated_on = content_from.updated_on

    if(tempTo.text.strip.match(/^\{\{history\_coded\_start\}\}/m) && tempTo.text.strip.match(/\{\{history\_coded\_stop\}\}$/m))
	tempTo.text=decodeContent(tempTo.text)
    else
	tempTo.text=decodeContentWithTags(tempTo.text)
    end
    if(tempFrom.text.strip.match(/^\{\{history\_coded\_start\}\}/m) && tempFrom.text.strip.match(/\{\{history\_coded\_stop\}\}$/m))
	tempFrom.text=decodeContent(tempFrom.text)
    else
        tempFrom.text=decodeContentWithTags(tempFrom.text)
    end
    tempTo.version= content_to.version
    tempFrom.version=content_from.version
    (tempTo && tempFrom) ? WikiDiff.new(tempTo, tempFrom) : nil
    end
  end
end


text:
package br.com.souzacar.model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;

import org.springframework.stereotype.Component;

//Modelos

@Entity
@Component
public class Models {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	private String name;
	@ManyToOne
	private Brand brand;

	public Models() {
		super();
		// TODO Auto-generated constructor stub
	}

	public Models(Long id, String name, Brand brand) {
		super();
		this.id = id;
		this.name = name;
		this.brand = brand;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Brand getBrand() {
		return brand;
	}

	public void setBrand(Brand brand) {
		this.brand = brand;
	}
}


text:
package io.datarouter.client.mysql.test.client.imp.mysql.test;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.Guice;

import io.datarouter.client.mysql.DatarouterMysqlTestNgModuleFactory;
import io.datarouter.client.mysql.test.DatarouterMysqlTestClientids;
import io.datarouter.client.mysql.test.client.txn.test.BaseTxnIntegrationTests;

@Guice(moduleFactory = DatarouterMysqlTestNgModuleFactory.class)
public class MysqlTxnIntegrationTests extends BaseTxnIntegrationTests{

	@BeforeClass
	public void beforeClass(){
		setup(DatarouterMysqlTestClientids.MYSQL);
		resetTable();
	}
}