Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:38

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSBSPsARMTMS570
0007  *
0008  * @brief This source file contains the definition of ::BSP_output_char and
0009  *   ::BSP_poll_char.
0010  */
0011 
0012 /*
0013  * Copyright (C) 2023 embedded brains GmbH & Co. KG
0014  * Copyright (C) 2014 Premysl Houdek <kom541000@gmail.com>
0015  *
0016  * Google Summer of Code 2014 at
0017  * Czech Technical University in Prague
0018  * Zikova 1903/4
0019  * 166 36 Praha 6
0020  * Czech Republic
0021  *
0022  * Redistribution and use in source and binary forms, with or without
0023  * modification, are permitted provided that the following conditions
0024  * are met:
0025  * 1. Redistributions of source code must retain the above copyright
0026  *    notice, this list of conditions and the following disclaimer.
0027  * 2. Redistributions in binary form must reproduce the above copyright
0028  *    notice, this list of conditions and the following disclaimer in the
0029  *    documentation and/or other materials provided with the distribution.
0030  *
0031  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0032  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0033  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0034  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0035  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0036  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0037  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0038  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0039  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0040  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0041  * POSSIBILITY OF SUCH DAMAGE.
0042  */
0043 
0044 #include <rtems/bspIo.h>
0045 #include <rtems/sysinit.h>
0046 #include <stdint.h>
0047 #include <string.h>
0048 #include <bsp/tms570-sci-driver.h>
0049 
0050 #define TMS570_CONSOLE (&driver_context_table[0])
0051 
0052 /**
0053  * @brief Puts chars into peripheral
0054  *
0055  * debug functions always use serial dev 0 peripheral
0056  *
0057  * @retval Void
0058  */
0059 static void tms570_debug_console_out(char ch)
0060 {
0061   tms570_sci_context *ctx = TMS570_CONSOLE;
0062   volatile tms570_sci_t *regs = ctx->regs;
0063 
0064   while ( true ) {
0065     rtems_interrupt_level level;
0066 
0067     while ( ( regs->FLR & TMS570_SCI_FLR_TXRDY ) == 0) {
0068       /* Wait */
0069     }
0070 
0071     rtems_interrupt_disable( level );
0072 
0073     if ( ( regs->FLR & TMS570_SCI_FLR_TXRDY ) != 0) {
0074       regs->TD = ch;
0075       rtems_interrupt_enable( level );
0076 
0077       break;
0078     }
0079 
0080     rtems_interrupt_enable( level );
0081   }
0082 
0083   while ( ( regs->FLR & TMS570_SCI_FLR_TX_EMPTY ) == 0) {
0084     /* Wait */
0085   }
0086 }
0087 
0088 static void tms570_debug_console_init(void)
0089 {
0090   tms570_sci_context *ctx = TMS570_CONSOLE;
0091   struct termios term;
0092 
0093   tms570_sci_initialize(ctx);
0094   memset(&term, 0, sizeof(term));
0095   term.c_ospeed = B115200;
0096   tms570_sci_set_attributes(&ctx->base, &term);
0097   BSP_output_char = tms570_debug_console_out;
0098 }
0099 
0100 static void tms570_debug_console_early_init(char c)
0101 {
0102   tms570_debug_console_init();
0103   tms570_debug_console_out(c);
0104 }
0105 
0106 /**
0107  * @brief debug console input
0108  *
0109  * debug functions always use serial dev 0 peripheral
0110  *
0111  * @retval x Read char
0112  * @retval -1 No input character available
0113  */
0114 static int tms570_debug_console_in( void )
0115 {
0116   tms570_sci_context *ctx = TMS570_CONSOLE;
0117   volatile tms570_sci_t *regs = ctx->regs;
0118   rtems_interrupt_level level;
0119   int c;
0120 
0121   rtems_interrupt_disable(level);
0122 
0123   if ( regs->FLR & TMS570_SCI_FLR_RXRDY ) {
0124       c = (unsigned char) regs->RD;
0125   } else {
0126       c = -1;
0127   }
0128 
0129   rtems_interrupt_enable(level);
0130 
0131   return c;
0132 }
0133 
0134 BSP_output_char_function_type BSP_output_char =
0135   tms570_debug_console_early_init;
0136 
0137 BSP_polling_getchar_function_type BSP_poll_char = tms570_debug_console_in;
0138 
0139 RTEMS_SYSINIT_ITEM(
0140   tms570_debug_console_init,
0141   RTEMS_SYSINIT_BSP_START,
0142   RTEMS_SYSINIT_ORDER_LAST_BUT_5
0143 );