source: rtems/bsps/arm/shared/serial/arm-pl050.c @ ba619b7f

Last change on this file since ba619b7f was ba619b7f, checked in by Joel Sherrill <joel@…>, on 03/01/22 at 21:38:20

bsps/arm/: Scripted embedded brains header file clean up

Updates #4625.

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 * Copyright (c) 2013-2014 embedded brains GmbH.  All rights reserved.
3 *
4 * The license and distribution terms for this file may be
5 * found in the file LICENSE in this distribution or at
6 * http://www.rtems.org/license/LICENSE.
7 */
8
9#include <assert.h>
10
11#include <bsp/irq.h>
12#include <bsp/arm-pl050.h>
13
14static volatile pl050 *pl050_get_regs(rtems_termios_device_context *base)
15{
16  arm_pl050_context *ctx = (arm_pl050_context *) base;
17
18  return ctx->regs;
19}
20
21static void pl050_interrupt(void *arg)
22{
23  rtems_termios_tty *tty = arg;
24  rtems_termios_device_context *base = rtems_termios_get_device_context(tty);
25  volatile pl050 *regs = pl050_get_regs(base);
26  uint32_t kmiir_rx = PL050_KMIIR_KMIRXINTR;
27  uint32_t kmiir_tx = (regs->kmicr & PL050_KMICR_KMITXINTREN) != 0 ?
28    PL050_KMIIR_KMITXINTR : 0;
29  uint32_t kmiir = regs->kmiir;
30
31  if ((kmiir & kmiir_rx) != 0) {
32    char c = (char) PL050_KMIDATA_KMIDATA_GET(regs->kmidata);
33
34    rtems_termios_enqueue_raw_characters(tty, &c, 1);
35  }
36
37  if ((kmiir & kmiir_tx) != 0) {
38    rtems_termios_dequeue_characters(tty, 1);
39  }
40}
41
42static bool pl050_first_open(
43  struct rtems_termios_tty *tty,
44  rtems_termios_device_context *base,
45  struct termios *term,
46  rtems_libio_open_close_args_t *args
47)
48{
49  arm_pl050_context *ctx = (arm_pl050_context *) base;
50  volatile pl050 *regs = pl050_get_regs(base);
51  rtems_status_code sc;
52
53  rtems_termios_set_initial_baud(tty, ctx->initial_baud);
54
55  regs->kmicr = PL050_KMICR_KMIEN | PL050_KMICR_KMIRXINTREN;
56
57  sc = rtems_interrupt_handler_install(
58    ctx->irq,
59    "PL050",
60    RTEMS_INTERRUPT_UNIQUE,
61    pl050_interrupt,
62    tty
63  );
64  assert(sc == RTEMS_SUCCESSFUL);
65
66  return true;
67}
68
69static void pl050_last_close(
70  struct rtems_termios_tty *tty,
71  rtems_termios_device_context *base,
72  rtems_libio_open_close_args_t *args
73)
74{
75  arm_pl050_context *ctx = (arm_pl050_context *) base;
76  volatile pl050 *regs = pl050_get_regs(base);
77  rtems_status_code sc;
78
79  regs->kmicr = 0;
80
81  sc = rtems_interrupt_handler_remove(
82    ctx->irq,
83    pl050_interrupt,
84    tty
85  );
86  assert(sc == RTEMS_SUCCESSFUL);
87}
88
89static void pl050_write_support(
90  rtems_termios_device_context *base,
91  const char *s,
92  size_t n
93)
94{
95  volatile pl050 *regs = pl050_get_regs(base);
96
97  if (n > 0) {
98    regs->kmidata = PL050_KMIDATA_KMIDATA(s[0]);
99    regs->kmicr |= PL050_KMICR_KMITXINTREN;
100  } else {
101    regs->kmicr &= ~PL050_KMICR_KMITXINTREN;
102  }
103}
104
105const rtems_termios_device_handler arm_pl050_fns = {
106  .first_open = pl050_first_open,
107  .last_close = pl050_last_close,
108  .write = pl050_write_support,
109  .mode = TERMIOS_IRQ_DRIVEN
110};
Note: See TracBrowser for help on using the repository browser.