File indexing completed on 2025-05-11 08:24:08
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 #include <bsp.h>
0043 #include <bsp/leon3.h>
0044 #include <rtems/bspIo.h>
0045 #include <rtems/sysinit.h>
0046 #include <grlib/apbuart.h>
0047 #include <grlib/io.h>
0048
0049 #if !defined(LEON3_APBUART_BASE)
0050 #include <grlib/ambapp.h>
0051
0052 int leon3_debug_uart_index __attribute__((weak)) = 0;
0053
0054 apbuart *leon3_debug_uart = NULL;
0055 #endif
0056
0057 static void bsp_debug_uart_init(void);
0058
0059 static void apbuart_enable_receive_and_transmit(apbuart *regs)
0060 {
0061 uint32_t ctrl;
0062
0063 ctrl = grlib_load_32(®s->ctrl);
0064 ctrl |= APBUART_CTRL_RE | APBUART_CTRL_TE;
0065 grlib_store_32(®s->ctrl, ctrl);
0066 grlib_store_32(®s->status, 0);
0067 }
0068
0069 static void bsp_debug_uart_output_char(char c)
0070 {
0071 apbuart_outbyte_polled(leon3_debug_uart, c);
0072 apbuart_outbyte_wait(leon3_debug_uart);
0073 }
0074
0075 static int bsp_debug_uart_poll_char(void)
0076 {
0077 return apbuart_inbyte_nonblocking(leon3_debug_uart);
0078 }
0079
0080 static void bsp_debug_uart_pre_init_out(char c)
0081 {
0082 bsp_debug_uart_init();
0083 (*BSP_output_char)(c);
0084 }
0085
0086 #if defined(LEON3_APBUART_BASE)
0087
0088 static void bsp_debug_uart_init(void)
0089 {
0090 apbuart_enable_receive_and_transmit(leon3_debug_uart);
0091 BSP_poll_char = bsp_debug_uart_poll_char;
0092 BSP_output_char = bsp_debug_uart_output_char;
0093 }
0094
0095 #else
0096
0097 static void bsp_debug_uart_discard(char c)
0098 {
0099 (void) c;
0100 }
0101
0102
0103
0104
0105 static void bsp_debug_uart_init(void)
0106 {
0107 int i;
0108 struct ambapp_dev *adev;
0109
0110 if ( BSP_output_char != bsp_debug_uart_pre_init_out ) {
0111 return;
0112 }
0113
0114 BSP_output_char = bsp_debug_uart_discard;
0115
0116
0117
0118
0119
0120
0121
0122 if (leon3_debug_uart_index == 0) {
0123 #if defined(RTEMS_MULTIPROCESSING)
0124 leon3_debug_uart_index = LEON3_Cpu_Index;
0125 #else
0126 leon3_debug_uart_index = 0;
0127 #endif
0128 } else {
0129 leon3_debug_uart_index--;
0130 }
0131
0132
0133 i = leon3_debug_uart_index;
0134 adev = (void *)ambapp_for_each(ambapp_plb(), (OPTIONS_ALL|OPTIONS_APB_SLVS),
0135 VENDOR_GAISLER, GAISLER_APBUART,
0136 ambapp_find_by_idx, (void *)&i);
0137 if (adev != NULL) {
0138 struct ambapp_apb_info *apb;
0139
0140
0141
0142
0143
0144 apb = (struct ambapp_apb_info *)adev->devinfo;
0145 leon3_debug_uart = (apbuart *)apb->start;
0146 apbuart_enable_receive_and_transmit(leon3_debug_uart);
0147
0148 BSP_poll_char = bsp_debug_uart_poll_char;
0149 BSP_output_char = bsp_debug_uart_output_char;
0150 }
0151 }
0152
0153 #endif
0154
0155 RTEMS_SYSINIT_ITEM(
0156 bsp_debug_uart_init,
0157 RTEMS_SYSINIT_BSP_START,
0158 RTEMS_SYSINIT_ORDER_FOURTH
0159 );
0160
0161 BSP_output_char_function_type BSP_output_char = bsp_debug_uart_pre_init_out;
0162
0163 BSP_polling_getchar_function_type BSP_poll_char;