File indexing completed on 2025-05-11 08:23:04
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 #include <libchip/ns16550.h>
0037
0038 #include <bsp.h>
0039 #include <bsp/lpc32xx.h>
0040 #include <bsp/irq.h>
0041 #include <bsp/hsu.h>
0042 #include <bsp/console-termios.h>
0043
0044 static uint8_t lpc32xx_uart_get_register(uintptr_t addr, uint8_t i)
0045 {
0046 volatile uint32_t *reg = (volatile uint32_t *) addr;
0047
0048 return (uint8_t) reg [i];
0049 }
0050
0051 static void lpc32xx_uart_set_register(uintptr_t addr, uint8_t i, uint8_t val)
0052 {
0053 volatile uint32_t *reg = (volatile uint32_t *) addr;
0054
0055 reg [i] = val;
0056 }
0057
0058 #ifdef LPC32XX_UART_3_BAUD
0059 static bool lpc32xx_uart_probe_3(rtems_termios_device_context *context)
0060 {
0061 LPC32XX_UARTCLK_CTRL |= BSP_BIT32(0);
0062 LPC32XX_U3CLK = LPC32XX_CONFIG_U3CLK;
0063 LPC32XX_UART_CLKMODE = BSP_FLD32SET(LPC32XX_UART_CLKMODE, 0x2, 4, 5);
0064
0065 return ns16550_probe(context);
0066 }
0067 #endif
0068
0069 #ifdef LPC32XX_UART_4_BAUD
0070 static bool lpc32xx_uart_probe_4(rtems_termios_device_context *context)
0071 {
0072 volatile lpc32xx_gpio *gpio = &lpc32xx.gpio;
0073
0074
0075
0076
0077
0078 gpio->p2_mux_set = BSP_BIT32(2);
0079
0080 LPC32XX_UARTCLK_CTRL |= BSP_BIT32(1);
0081 LPC32XX_U4CLK = LPC32XX_CONFIG_U4CLK;
0082 LPC32XX_UART_CLKMODE = BSP_FLD32SET(LPC32XX_UART_CLKMODE, 0x2, 6, 7);
0083
0084 return ns16550_probe(context);
0085 }
0086 #endif
0087
0088 #ifdef LPC32XX_UART_6_BAUD
0089 static bool lpc32xx_uart_probe_6(rtems_termios_device_context *context)
0090 {
0091
0092 LPC32XX_UART_CTRL |= BSP_BIT32(5);
0093
0094 LPC32XX_UARTCLK_CTRL |= BSP_BIT32(3);
0095 LPC32XX_U6CLK = LPC32XX_CONFIG_U6CLK;
0096 LPC32XX_UART_CLKMODE = BSP_FLD32SET(LPC32XX_UART_CLKMODE, 0x2, 10, 11);
0097
0098 return ns16550_probe(context);
0099 }
0100 #endif
0101
0102
0103
0104 #ifdef LPC32XX_UART_5_BAUD
0105 static ns16550_context lpc32xx_uart_context_5 = {
0106 .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 5"),
0107 .get_reg = lpc32xx_uart_get_register,
0108 .set_reg = lpc32xx_uart_set_register,
0109 .port = LPC32XX_BASE_UART_5,
0110 .irq = LPC32XX_IRQ_UART_5,
0111 .clock = 16 * LPC32XX_UART_5_BAUD,
0112 .initial_baud = LPC32XX_UART_5_BAUD
0113 };
0114 #endif
0115
0116 #ifdef LPC32XX_UART_3_BAUD
0117 static ns16550_context lpc32xx_uart_context_3 = {
0118 .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 3"),
0119 .get_reg = lpc32xx_uart_get_register,
0120 .set_reg = lpc32xx_uart_set_register,
0121 .port = LPC32XX_BASE_UART_3,
0122 .irq = LPC32XX_IRQ_UART_3,
0123 .clock = 16 * LPC32XX_UART_3_BAUD,
0124 .initial_baud = LPC32XX_UART_3_BAUD
0125 };
0126 #endif
0127
0128 #ifdef LPC32XX_UART_4_BAUD
0129 static ns16550_context lpc32xx_uart_context_4 = {
0130 .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 4"),
0131 .get_reg = lpc32xx_uart_get_register,
0132 .set_reg = lpc32xx_uart_set_register,
0133 .port = LPC32XX_BASE_UART_4,
0134 .irq = LPC32XX_IRQ_UART_4,
0135 .clock = 16 * LPC32XX_UART_4_BAUD,
0136 .initial_baud = LPC32XX_UART_4_BAUD
0137 };
0138 #endif
0139
0140 #ifdef LPC32XX_UART_6_BAUD
0141 static ns16550_context lpc32xx_uart_context_6 = {
0142 .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 6"),
0143 .get_reg = lpc32xx_uart_get_register,
0144 .set_reg = lpc32xx_uart_set_register,
0145 .port = LPC32XX_BASE_UART_6,
0146 .irq = LPC32XX_IRQ_UART_6,
0147 .clock = 16 * LPC32XX_UART_6_BAUD,
0148 .initial_baud = LPC32XX_UART_6_BAUD
0149 };
0150 #endif
0151
0152 #ifdef LPC32XX_UART_1_BAUD
0153 static lpc32xx_hsu_context lpc32xx_uart_context_1 = {
0154 .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 1"),
0155 .hsu = (volatile lpc32xx_hsu *) LPC32XX_BASE_UART_1,
0156 .irq = LPC32XX_IRQ_UART_1,
0157 .initial_baud = LPC32XX_UART_1_BAUD
0158 };
0159 #endif
0160
0161 #ifdef LPC32XX_UART_2_BAUD
0162 static lpc32xx_hsu_context lpc32xx_uart_context_2 = {
0163 .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 2"),
0164 .hsu = (volatile lpc32xx_hsu *) LPC32XX_BASE_UART_2,
0165 .irq = LPC32XX_IRQ_UART_2,
0166 .initial_baud = LPC32XX_UART_2_BAUD
0167 };
0168 #endif
0169
0170 #ifdef LPC32XX_UART_7_BAUD
0171 static lpc32xx_hsu_context lpc32xx_uart_context_7 = {
0172 .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 7"),
0173 .hsu = (volatile lpc32xx_hsu *) LPC32XX_BASE_UART_7,
0174 .irq = LPC32XX_IRQ_UART_7,
0175 .initial_baud = LPC32XX_UART_7_BAUD
0176 };
0177 #endif
0178
0179 const console_device console_device_table[] = {
0180 #ifdef LPC32XX_UART_5_BAUD
0181 {
0182 .device_file = "/dev/ttyS5",
0183 .probe = console_device_probe_default,
0184 .handler = &ns16550_handler_interrupt,
0185 .context = &lpc32xx_uart_context_5.base
0186 },
0187 #endif
0188 #ifdef LPC32XX_UART_3_BAUD
0189 {
0190 .device_file = "/dev/ttyS3",
0191 .probe = lpc32xx_uart_probe_3,
0192 .handler = &ns16550_handler_interrupt,
0193 .context = &lpc32xx_uart_context_3.base
0194 },
0195 #endif
0196 #ifdef LPC32XX_UART_4_BAUD
0197 {
0198 .device_file = "/dev/ttyS4",
0199 .probe = lpc32xx_uart_probe_4,
0200 .handler = &ns16550_handler_interrupt,
0201 .context = &lpc32xx_uart_context_4.base
0202 },
0203 #endif
0204 #ifdef LPC32XX_UART_6_BAUD
0205 {
0206 .device_file = "/dev/ttyS6",
0207 .probe = lpc32xx_uart_probe_6,
0208 .handler = &ns16550_handler_interrupt,
0209 .context = &lpc32xx_uart_context_6.base
0210 },
0211 #endif
0212 #ifdef LPC32XX_UART_1_BAUD
0213 {
0214 .device_file = "/dev/ttyS1",
0215 .probe = lpc32xx_hsu_probe,
0216 .handler = &lpc32xx_hsu_fns,
0217 .context = &lpc32xx_uart_context_1.base
0218 },
0219 #endif
0220 #ifdef LPC32XX_UART_2_BAUD
0221 {
0222 .device_file = "/dev/ttyS2",
0223 .probe = lpc32xx_hsu_probe,
0224 .handler = &lpc32xx_hsu_fns,
0225 .context = &lpc32xx_uart_context_2.base
0226 },
0227 #endif
0228 #ifdef LPC32XX_UART_7_BAUD
0229 {
0230 .device_file = "/dev/ttyS7",
0231 .probe = lpc32xx_hsu_probe,
0232 .handler = &lpc32xx_hsu_fns,
0233 .context = &lpc32xx_uart_context_7.base
0234 },
0235 #endif
0236 };
0237
0238 const size_t console_device_count = RTEMS_ARRAY_SIZE(console_device_table);