File indexing completed on 2025-05-11 08:23:05
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 #include <assert.h>
0029
0030 #include <bsp/irq.h>
0031 #include <bsp/arm-pl050.h>
0032
0033 static volatile pl050 *pl050_get_regs(rtems_termios_device_context *base)
0034 {
0035 arm_pl050_context *ctx = (arm_pl050_context *) base;
0036
0037 return ctx->regs;
0038 }
0039
0040 static void pl050_interrupt(void *arg)
0041 {
0042 rtems_termios_tty *tty = arg;
0043 rtems_termios_device_context *base = rtems_termios_get_device_context(tty);
0044 volatile pl050 *regs = pl050_get_regs(base);
0045 uint32_t kmiir_rx = PL050_KMIIR_KMIRXINTR;
0046 uint32_t kmiir_tx = (regs->kmicr & PL050_KMICR_KMITXINTREN) != 0 ?
0047 PL050_KMIIR_KMITXINTR : 0;
0048 uint32_t kmiir = regs->kmiir;
0049
0050 if ((kmiir & kmiir_rx) != 0) {
0051 char c = (char) PL050_KMIDATA_KMIDATA_GET(regs->kmidata);
0052
0053 rtems_termios_enqueue_raw_characters(tty, &c, 1);
0054 }
0055
0056 if ((kmiir & kmiir_tx) != 0) {
0057 rtems_termios_dequeue_characters(tty, 1);
0058 }
0059 }
0060
0061 static bool pl050_first_open(
0062 struct rtems_termios_tty *tty,
0063 rtems_termios_device_context *base,
0064 struct termios *term,
0065 rtems_libio_open_close_args_t *args
0066 )
0067 {
0068 arm_pl050_context *ctx = (arm_pl050_context *) base;
0069 volatile pl050 *regs = pl050_get_regs(base);
0070 rtems_status_code sc;
0071
0072 rtems_termios_set_initial_baud(tty, ctx->initial_baud);
0073
0074 regs->kmicr = PL050_KMICR_KMIEN | PL050_KMICR_KMIRXINTREN;
0075
0076 sc = rtems_interrupt_handler_install(
0077 ctx->irq,
0078 "PL050",
0079 RTEMS_INTERRUPT_UNIQUE,
0080 pl050_interrupt,
0081 tty
0082 );
0083 assert(sc == RTEMS_SUCCESSFUL);
0084
0085 return true;
0086 }
0087
0088 static void pl050_last_close(
0089 struct rtems_termios_tty *tty,
0090 rtems_termios_device_context *base,
0091 rtems_libio_open_close_args_t *args
0092 )
0093 {
0094 arm_pl050_context *ctx = (arm_pl050_context *) base;
0095 volatile pl050 *regs = pl050_get_regs(base);
0096 rtems_status_code sc;
0097
0098 regs->kmicr = 0;
0099
0100 sc = rtems_interrupt_handler_remove(
0101 ctx->irq,
0102 pl050_interrupt,
0103 tty
0104 );
0105 assert(sc == RTEMS_SUCCESSFUL);
0106 }
0107
0108 static void pl050_write_support(
0109 rtems_termios_device_context *base,
0110 const char *s,
0111 size_t n
0112 )
0113 {
0114 volatile pl050 *regs = pl050_get_regs(base);
0115
0116 if (n > 0) {
0117 regs->kmidata = PL050_KMIDATA_KMIDATA(s[0]);
0118 regs->kmicr |= PL050_KMICR_KMITXINTREN;
0119 } else {
0120 regs->kmicr &= ~PL050_KMICR_KMITXINTREN;
0121 }
0122 }
0123
0124 const rtems_termios_device_handler arm_pl050_fns = {
0125 .first_open = pl050_first_open,
0126 .last_close = pl050_last_close,
0127 .write = pl050_write_support,
0128 .mode = TERMIOS_IRQ_DRIVEN
0129 };