1 | /* |
---|
2 | * This file implements simple console IO via JTAG UART. |
---|
3 | * |
---|
4 | * Based on no_cpu/console.c |
---|
5 | * COPYRIGHT (c) 1989-1999. |
---|
6 | * On-Line Applications Research Corporation (OAR). |
---|
7 | * |
---|
8 | * Altera-specific code is |
---|
9 | * COPYRIGHT (c) 2005-2006 Kolja Waschk, rtemsdev/ixo.de |
---|
10 | * |
---|
11 | * The license and distribution terms for this file may be |
---|
12 | * found in the file LICENSE in this distribution or at |
---|
13 | * http://www.rtems.org/license/LICENSE. |
---|
14 | */ |
---|
15 | |
---|
16 | #define NO_BSP_INIT |
---|
17 | |
---|
18 | #include <bsp.h> |
---|
19 | #include <rtems/libio.h> |
---|
20 | |
---|
21 | /* #define JTAG_UART_REGS ((altera_avalon_jtag_uart_regs*)NIOS2_IO_BASE(JTAG_UART_BASE)) */ |
---|
22 | |
---|
23 | /* is_character_ready |
---|
24 | * |
---|
25 | * If a character is available, this routine reads it and stores |
---|
26 | * it in |
---|
27 | * reads the character and stores |
---|
28 | * |
---|
29 | * Input parameters: NONE |
---|
30 | * |
---|
31 | * Output parameters: NONE |
---|
32 | * |
---|
33 | * Return values: |
---|
34 | */ |
---|
35 | |
---|
36 | bool is_character_ready( |
---|
37 | char *ch |
---|
38 | ) |
---|
39 | { |
---|
40 | altera_avalon_jtag_uart_regs *ajur = NIOS2_IO_BASE(JTAG_UART_BASE); |
---|
41 | unsigned int data = ajur->data; |
---|
42 | |
---|
43 | if (data & ALTERA_AVALON_JTAG_UART_DATA_RVALID_MSK) |
---|
44 | { |
---|
45 | *ch = (data & ALTERA_AVALON_JTAG_UART_DATA_DATA_MSK) |
---|
46 | >> ALTERA_AVALON_JTAG_UART_DATA_DATA_OFST; |
---|
47 | return true; |
---|
48 | }; |
---|
49 | |
---|
50 | return false; |
---|
51 | } |
---|
52 | |
---|
53 | void console_initialize_hardware(void) |
---|
54 | { |
---|
55 | } |
---|
56 | |
---|
57 | /* |
---|
58 | * This routine reads a character from the SOURCE. |
---|
59 | * |
---|
60 | * Input parameters: NONE |
---|
61 | * |
---|
62 | * Output parameters: NONE |
---|
63 | * |
---|
64 | * Return values: |
---|
65 | * character read from SOURCE |
---|
66 | */ |
---|
67 | |
---|
68 | int console_inbyte_nonblocking( |
---|
69 | int port |
---|
70 | ) |
---|
71 | { |
---|
72 | char ch; |
---|
73 | /* |
---|
74 | * Wait until a character is available. |
---|
75 | */ |
---|
76 | |
---|
77 | if (is_character_ready(&ch)) |
---|
78 | return ch; |
---|
79 | return -1; |
---|
80 | } |
---|
81 | |
---|
82 | /* |
---|
83 | * This routine transmits a character out the SOURCE. It may support |
---|
84 | * XON/XOFF flow control. |
---|
85 | * |
---|
86 | * Input parameters: |
---|
87 | * ch - character to be transmitted |
---|
88 | * |
---|
89 | * Output parameters: NONE |
---|
90 | */ |
---|
91 | |
---|
92 | void console_outbyte_polled( |
---|
93 | int port, |
---|
94 | char ch |
---|
95 | ) |
---|
96 | { |
---|
97 | altera_avalon_jtag_uart_regs *ajur = NIOS2_IO_BASE(JTAG_UART_BASE); |
---|
98 | /* |
---|
99 | * Wait for the transmitter to be ready. |
---|
100 | * Check for flow control requests and process. |
---|
101 | * Then output the character. |
---|
102 | */ |
---|
103 | |
---|
104 | while ((ajur->control & ALTERA_AVALON_JTAG_UART_CONTROL_WSPACE_MSK) == 0); |
---|
105 | |
---|
106 | ajur->data = ch; |
---|
107 | } |
---|
108 | |
---|
109 | /* |
---|
110 | * To support printk |
---|
111 | */ |
---|
112 | |
---|
113 | #include <rtems/bspIo.h> |
---|
114 | |
---|
115 | |
---|
116 | void ISS_output_char(char c) { console_outbyte_polled( 0, c ); } |
---|
117 | |
---|
118 | BSP_output_char_function_type BSP_output_char = ISS_output_char; |
---|
119 | BSP_polling_getchar_function_type BSP_poll_char = NULL; |
---|
120 | |
---|