Back to home page

LXR

 
 

    


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

0001 /*
0002  *  This file implements simple console IO via JTAG UART.
0003  */
0004 
0005 /*
0006  *  COPYRIGHT (c) 1989-1999.
0007  *  On-Line Applications Research Corporation (OAR).
0008  *
0009  *  Altera-specific code is
0010  *  COPYRIGHT (c) 2005-2006 Kolja Waschk, rtemsdev/ixo.de
0011  *
0012  *  The license and distribution terms for this file may be
0013  *  found in the file LICENSE in this distribution or at
0014  *  http://www.rtems.org/license/LICENSE.
0015  */
0016 
0017 #define NO_BSP_INIT
0018 
0019 #include <bsp.h>
0020 #include <bsp/console-polled.h>
0021 #include <rtems/libio.h>
0022 
0023 /* #define JTAG_UART_REGS \
0024         ((altera_avalon_jtag_uart_regs*)NIOS2_IO_BASE(JTAG_UART_BASE)) */
0025 
0026 /*  is_character_ready
0027  *
0028  *  If a character is available, this routine reads it and stores
0029  *  it in reads the character and stores
0030  */
0031 static bool is_character_ready(
0032   char *ch
0033 )
0034 {
0035   altera_avalon_jtag_uart_regs *ajur = NIOS2_IO_BASE(JTAG_UART_BASE);
0036   unsigned int data = ajur->data;
0037 
0038   if (data & ALTERA_AVALON_JTAG_UART_DATA_RVALID_MSK) {
0039     *ch = (data & ALTERA_AVALON_JTAG_UART_DATA_DATA_MSK)
0040       >> ALTERA_AVALON_JTAG_UART_DATA_DATA_OFST;
0041     return true;
0042   }
0043 
0044   return false;
0045 }
0046 
0047 void console_initialize_hardware(void)
0048 {
0049 }
0050 
0051 /*
0052  *  This routine reads a character from the SOURCE.
0053  */
0054 int console_inbyte_nonblocking(
0055   int port
0056 )
0057 {
0058   char ch;
0059 
0060   /*
0061    *  Wait until a character is available.
0062    */
0063   if (is_character_ready(&ch))
0064     return ch;
0065   return -1;
0066 }
0067 
0068 /*
0069  *  This routine transmits a character out the SOURCE.
0070  */
0071 void console_outbyte_polled(
0072   int  port,
0073   char ch
0074 )
0075 {
0076   altera_avalon_jtag_uart_regs *ajur = NIOS2_IO_BASE(JTAG_UART_BASE);
0077 
0078   /*
0079    *  Wait for the transmitter to be ready.
0080    *  Check for flow control requests and process.
0081    *  Then output the character.
0082    */
0083   while ((ajur->control & ALTERA_AVALON_JTAG_UART_CONTROL_WSPACE_MSK) == 0);
0084 
0085   ajur->data = ch;
0086 }
0087 
0088 /*
0089  * To support printk
0090  */
0091 
0092 #include <rtems/bspIo.h>
0093 
0094 static void ISS_output_char(char c) { console_outbyte_polled( 0, c ); }
0095 
0096 BSP_output_char_function_type           BSP_output_char = ISS_output_char;
0097 BSP_polling_getchar_function_type       BSP_poll_char = NULL;
0098