Changeset 116ef2e9 in rtems for c/src


Ignore:
Timestamp:
Oct 13, 2014, 1:19:12 PM (6 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, 5, master
Children:
6db0f56
Parents:
393e8ea
git-author:
Sebastian Huber <sebastian.huber@…> (10/13/14 13:19:12)
git-committer:
Sebastian Huber <sebastian.huber@…> (10/14/14 06:02:39)
Message:

bsps/arm: Convert PL011 and PL050 console drivers

Use Termios device API.

Location:
c/src/lib/libbsp/arm
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/arm/realview-pbx-a9/Makefile.am

    r393e8ea r116ef2e9  
    109109
    110110# Console
    111 libbsp_a_SOURCES += ../../shared/console.c
    112 libbsp_a_SOURCES += ../../shared/console_control.c
    113 libbsp_a_SOURCES += ../../shared/console_read.c
    114 libbsp_a_SOURCES += ../../shared/console_select.c
    115 libbsp_a_SOURCES += ../../shared/console_write.c
    116 libbsp_a_SOURCES += ../../shared/console-output-char.c
     111libbsp_a_SOURCES += ../../shared/console-termios-init.c
     112libbsp_a_SOURCES += ../../shared/console-termios.c
    117113libbsp_a_SOURCES += ../../shared/get-serial-mouse-ps2.c
    118114libbsp_a_SOURCES += ../shared/arm-pl011.c
  • c/src/lib/libbsp/arm/realview-pbx-a9/console/console-config.c

    r393e8ea r116ef2e9  
    11/*
    2  * Copyright (c) 2013 embedded brains GmbH.  All rights reserved.
     2 * Copyright (c) 2013-2014 embedded brains GmbH.  All rights reserved.
    33 *
    44 *  embedded brains GmbH
     
    1414
    1515#include <rtems/serial_mouse.h>
    16 
    17 #include <libchip/serial.h>
     16#include <rtems/bspIo.h>
    1817
    1918#include <bsp.h>
     
    2120#include <bsp/arm-pl011.h>
    2221#include <bsp/arm-pl050.h>
     22#include <bsp/console-termios.h>
    2323
    24 console_tbl Console_Configuration_Ports[] = {
     24static arm_pl011_context pl011_context = {
     25  .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("PL011"),
     26  .regs = (volatile pl011 *) 0x10009000,
     27  .irq = RVPBXA9_IRQ_UART_0,
     28  .initial_baud = 115200
     29};
     30
     31static arm_pl050_context pl050_context = {
     32  .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("PL050"),
     33  .regs = (volatile pl050 *) 0x10007000,
     34  .irq = RVPBXA9_IRQ_KMI1,
     35  .initial_baud = 115200
     36};
     37
     38static void output_char(char c)
     39{
     40  if (c == '\n') {
     41    arm_pl011_write_polled(&pl011_context.base, '\r');
     42  }
     43
     44  arm_pl011_write_polled(&pl011_context.base, c);
     45}
     46
     47static bool pl011_probe(rtems_termios_device_context *base)
     48{
     49  BSP_output_char = output_char;
     50
     51  return arm_pl011_probe(base);
     52}
     53
     54static void output_char_init(char c)
     55{
     56  pl011_probe(&pl011_context.base);
     57  output_char(c);
     58}
     59
     60BSP_output_char_function_type BSP_output_char = output_char_init;
     61
     62BSP_polling_getchar_function_type BSP_poll_char = NULL;
     63
     64const console_device console_device_table[] = {
    2565  {
    26     .sDeviceName = "/dev/ttyS0",
    27     .deviceType = SERIAL_CUSTOM,
    28     .pDeviceFns = &arm_pl011_fns,
    29     .deviceProbe = NULL,
    30     .pDeviceFlow = NULL,
    31     .ulMargin = 10,
    32     .ulHysteresis = 0,
    33     .pDeviceParams = (void *) 115200,
    34     .ulCtrlPort1 = 0x10009000,
    35     .ulCtrlPort2 = 0,
    36     .ulDataPort = 0,
    37     .getRegister = NULL,
    38     .setRegister = NULL,
    39     .getData = NULL,
    40     .setData = NULL,
    41     .ulClock = 0,
    42     .ulIntVector = RVPBXA9_IRQ_UART_0
     66    .device_file = "/dev/ttyS0",
     67    .probe = pl011_probe,
     68    .handler = &arm_pl011_fns,
     69    .context = &pl011_context.base
    4370  }, {
    44     .sDeviceName = SERIAL_MOUSE_DEVICE_PS2,
    45     .deviceType = SERIAL_CUSTOM,
    46     .pDeviceFns = &arm_pl050_fns,
    47     .deviceProbe = NULL,
    48     .pDeviceFlow = NULL,
    49     .ulMargin = 10,
    50     .ulHysteresis = 0,
    51     .pDeviceParams = (void *) 115200,
    52     .ulCtrlPort1 = 0x10007000,
    53     .ulCtrlPort2 = 0,
    54     .ulDataPort = 0,
    55     .getRegister = NULL,
    56     .setRegister = NULL,
    57     .getData = NULL,
    58     .setData = NULL,
    59     .ulClock = 0,
    60     .ulIntVector = RVPBXA9_IRQ_KMI1
     71    .device_file = SERIAL_MOUSE_DEVICE_PS2,
     72    .probe = console_device_probe_default,
     73    .handler = &arm_pl050_fns,
     74    .context = &pl050_context.base
    6175  }
    6276};
    6377
    64 unsigned long Console_Configuration_Count =
    65   RTEMS_ARRAY_SIZE(Console_Configuration_Ports);
     78const size_t console_device_count = RTEMS_ARRAY_SIZE(console_device_table);
  • c/src/lib/libbsp/arm/shared/arm-pl011.c

    r393e8ea r116ef2e9  
    11/*
    2  * Copyright (c) 2013 embedded brains GmbH.  All rights reserved.
     2 * Copyright (c) 2013-2014 embedded brains GmbH.  All rights reserved.
    33 *
    44 *  embedded brains GmbH
     
    1414
    1515#include <bsp/arm-pl011.h>
    16 #include <bsp/arm-pl011-regs.h>
    1716
    18 #include <libchip/sersupp.h>
     17static volatile pl011 *pl011_get_regs(rtems_termios_device_context *base)
     18{
     19  arm_pl011_context *ctx = (arm_pl011_context *) base;
    1920
    20 static volatile pl011 *pl011_get_regs(int minor)
    21 {
    22   const console_tbl *ct = Console_Port_Tbl != NULL ?
    23     Console_Port_Tbl[minor] : &Console_Configuration_Ports[minor];
    24 
    25   return (volatile pl011 *) ct->ulCtrlPort1;
     21  return ctx->regs;
    2622}
    2723
    28 static void pl011_initialize(int minor)
     24
     25bool arm_pl011_probe(rtems_termios_device_context *base)
    2926{
    30   volatile pl011 *regs = pl011_get_regs(minor);
     27  volatile pl011 *regs = pl011_get_regs(base);
    3128
    3229  regs->uartlcr_h = PL011_UARTLCR_H_WLEN(PL011_UARTLCR_H_WLEN_8);
     
    3431    | PL011_UARTCR_TXE
    3532    | PL011_UARTCR_UARTEN;
     33
     34  return true;
    3635}
    3736
    38 static int pl011_first_open(int major, int minor, void *arg)
     37static bool pl011_first_open(
     38  struct rtems_termios_tty *tty,
     39  rtems_termios_device_context *base,
     40  struct termios *term,
     41  rtems_libio_open_close_args_t *args
     42)
    3943{
    40   rtems_libio_open_close_args_t *oc = (rtems_libio_open_close_args_t *) arg;
    41   struct rtems_termios_tty *tty = (struct rtems_termios_tty *) oc->iop->data1;
    42   console_data *cd = &Console_Port_Data[minor];
    43   const console_tbl *ct = Console_Port_Tbl[minor];
     44  arm_pl011_context *ctx = (arm_pl011_context *) base;
    4445
    45   cd->termios_data = tty;
    46   rtems_termios_set_initial_baud(tty, (rtems_termios_baud_t) ct->pDeviceParams);
     46  rtems_termios_set_initial_baud(tty, ctx->initial_baud);
    4747
    48   return 0;
     48  return true;
    4949}
    5050
    51 static int pl011_last_close(int major, int minor, void *arg)
     51static int pl011_read_polled(rtems_termios_device_context *base)
    5252{
    53   return 0;
    54 }
    55 
    56 static int pl011_read_polled(int minor)
    57 {
    58   volatile pl011 *regs = pl011_get_regs(minor);
     53  volatile pl011 *regs = pl011_get_regs(base);
    5954
    6055  if ((regs->uartfr & PL011_UARTFR_RXFE) != 0) {
     
    6560}
    6661
    67 static void pl011_write_polled(int minor, char c)
     62void arm_pl011_write_polled(rtems_termios_device_context *base, char c)
    6863{
    69   volatile pl011 *regs = pl011_get_regs(minor);
     64  volatile pl011 *regs = pl011_get_regs(base);
    7065
    7166  while ((regs->uartfr & PL011_UARTFR_TXFF) != 0) {
     
    7671}
    7772
    78 static ssize_t pl011_write_support_polled(
    79   int minor,
     73static void pl011_write_support_polled(
     74  rtems_termios_device_context *base,
    8075  const char *s,
    8176  size_t n
    8277)
    8378{
    84   ssize_t i = 0;
     79  size_t i;
    8580
    8681  for (i = 0; i < n; ++i) {
    87     pl011_write_polled(minor, s[i]);
     82    arm_pl011_write_polled(base, s[i]);
    8883  }
    89 
    90   return n;
    9184}
    9285
    93 static int pl011_set_attribues(int minor, const struct termios *term)
    94 {
    95   return -1;
    96 }
    97 
    98 const console_fns arm_pl011_fns = {
    99   .deviceProbe = libchip_serial_default_probe,
    100   .deviceFirstOpen = pl011_first_open,
    101   .deviceLastClose = pl011_last_close,
    102   .deviceRead = pl011_read_polled,
    103   .deviceWrite = pl011_write_support_polled,
    104   .deviceInitialize = pl011_initialize,
    105   .deviceWritePolled = pl011_write_polled,
    106   .deviceSetAttributes = pl011_set_attribues,
    107   .deviceOutputUsesInterrupts = false
     86const rtems_termios_device_handler arm_pl011_fns = {
     87  .first_open = pl011_first_open,
     88  .poll_read = pl011_read_polled,
     89  .write = pl011_write_support_polled,
     90  .mode = TERMIOS_POLLED
    10891};
  • c/src/lib/libbsp/arm/shared/arm-pl050.c

    r393e8ea r116ef2e9  
    11/*
    2  * Copyright (c) 2013 embedded brains GmbH.  All rights reserved.
     2 * Copyright (c) 2013-2014 embedded brains GmbH.  All rights reserved.
    33 *
    44 *  embedded brains GmbH
     
    1717#include <bsp/irq.h>
    1818#include <bsp/arm-pl050.h>
    19 #include <bsp/arm-pl050-regs.h>
    2019
    21 #include <libchip/sersupp.h>
     20static volatile pl050 *pl050_get_regs(rtems_termios_device_context *base)
     21{
     22  arm_pl050_context *ctx = (arm_pl050_context *) base;
    2223
    23 static volatile pl050 *pl050_get_regs(int minor)
    24 {
    25   const console_tbl *ct = Console_Port_Tbl[minor];
    26 
    27   return (volatile pl050 *) ct->ulCtrlPort1;
     24  return ctx->regs;
    2825}
    2926
    3027static void pl050_interrupt(void *arg)
    3128{
    32   int minor = (int) arg;
    33   const console_data *cd = &Console_Port_Data[minor];
    34   volatile pl050 *regs = pl050_get_regs(minor);
     29  rtems_termios_tty *tty = arg;
     30  rtems_termios_device_context *base = rtems_termios_get_device_context(tty);
     31  volatile pl050 *regs = pl050_get_regs(base);
    3532  uint32_t kmiir_rx = PL050_KMIIR_KMIRXINTR;
    3633  uint32_t kmiir_tx = (regs->kmicr & PL050_KMICR_KMITXINTREN) != 0 ?
     
    4138    char c = (char) PL050_KMIDATA_KMIDATA_GET(regs->kmidata);
    4239
    43     rtems_termios_enqueue_raw_characters(cd->termios_data, &c, 1);
     40    rtems_termios_enqueue_raw_characters(tty, &c, 1);
    4441  }
    4542
    4643  if ((kmiir & kmiir_tx) != 0) {
    47     rtems_termios_dequeue_characters(cd->termios_data, 1);
     44    rtems_termios_dequeue_characters(tty, 1);
    4845  }
    4946}
    5047
    51 static void pl050_initialize(int minor)
     48static bool pl050_first_open(
     49  struct rtems_termios_tty *tty,
     50  rtems_termios_device_context *base,
     51  struct termios *term,
     52  rtems_libio_open_close_args_t *args
     53)
    5254{
    53   /* Nothing to do */
    54 }
    55 
    56 static int pl050_first_open(int major, int minor, void *arg)
    57 {
    58   rtems_libio_open_close_args_t *oc = (rtems_libio_open_close_args_t *) arg;
    59   struct rtems_termios_tty *tty = (struct rtems_termios_tty *) oc->iop->data1;
    60   console_data *cd = &Console_Port_Data[minor];
    61   const console_tbl *ct = Console_Port_Tbl[minor];
    62   volatile pl050 *regs = pl050_get_regs(minor);
     55  arm_pl050_context *ctx = (arm_pl050_context *) base;
     56  volatile pl050 *regs = pl050_get_regs(base);
    6357  rtems_status_code sc;
    6458
    65   cd->termios_data = tty;
    66   rtems_termios_set_initial_baud(tty, (rtems_termios_baud_t) ct->pDeviceParams);
     59  rtems_termios_set_initial_baud(tty, ctx->initial_baud);
    6760
    6861  regs->kmicr = PL050_KMICR_KMIEN | PL050_KMICR_KMIRXINTREN;
    6962
    7063  sc = rtems_interrupt_handler_install(
    71     ct->ulIntVector,
    72     ct->sDeviceName,
     64    ctx->irq,
     65    "PL050",
    7366    RTEMS_INTERRUPT_UNIQUE,
    7467    pl050_interrupt,
    75     (void *) minor
     68    tty
    7669  );
    7770  assert(sc == RTEMS_SUCCESSFUL);
    7871
    79   return 0;
     72  return true;
    8073}
    8174
    82 static int pl050_last_close(int major, int minor, void *arg)
     75static void pl050_last_close(
     76  struct rtems_termios_tty *tty,
     77  rtems_termios_device_context *base,
     78  rtems_libio_open_close_args_t *args
     79)
    8380{
    84   const console_tbl *ct = Console_Port_Tbl[minor];
    85   volatile pl050 *regs = pl050_get_regs(minor);
     81  arm_pl050_context *ctx = (arm_pl050_context *) base;
     82  volatile pl050 *regs = pl050_get_regs(base);
    8683  rtems_status_code sc;
    8784
     
    8986
    9087  sc = rtems_interrupt_handler_remove(
    91     ct->ulIntVector,
     88    ctx->irq,
    9289    pl050_interrupt,
    93     (void *) minor
     90    tty
    9491  );
    9592  assert(sc == RTEMS_SUCCESSFUL);
    96 
    97   return 0;
    9893}
    9994
    100 static ssize_t pl050_write_support(
    101   int minor,
     95static void pl050_write_support(
     96  rtems_termios_device_context *base,
    10297  const char *s,
    10398  size_t n
    10499)
    105100{
    106   volatile pl050 *regs = pl050_get_regs(minor);
     101  volatile pl050 *regs = pl050_get_regs(base);
    107102
    108103  if (n > 0) {
     
    112107    regs->kmicr &= ~PL050_KMICR_KMITXINTREN;
    113108  }
    114 
    115   return 0;
    116109}
    117110
    118 static int pl050_set_attribues(int minor, const struct termios *term)
    119 {
    120   return -1;
    121 }
    122 
    123 const console_fns arm_pl050_fns = {
    124   .deviceProbe = libchip_serial_default_probe,
    125   .deviceFirstOpen = pl050_first_open,
    126   .deviceLastClose = pl050_last_close,
    127   .deviceRead = NULL,
    128   .deviceWrite = pl050_write_support,
    129   .deviceInitialize = pl050_initialize,
    130   .deviceWritePolled = NULL,
    131   .deviceSetAttributes = pl050_set_attribues,
    132   .deviceOutputUsesInterrupts = true
     111const rtems_termios_device_handler arm_pl050_fns = {
     112  .first_open = pl050_first_open,
     113  .last_close = pl050_last_close,
     114  .write = pl050_write_support,
     115  .mode = TERMIOS_IRQ_DRIVEN
    133116};
  • c/src/lib/libbsp/arm/shared/include/arm-pl011.h

    r393e8ea r116ef2e9  
    88
    99/*
    10  * Copyright (c) 2013 embedded brains GmbH.  All rights reserved.
     10 * Copyright (c) 2013-2014 embedded brains GmbH.  All rights reserved.
    1111 *
    1212 *  embedded brains GmbH
     
    2424#define LIBBSP_ARM_SHARED_ARM_PL011_H
    2525
    26 #include <libchip/serial.h>
     26#include <rtems/termiostypes.h>
     27
     28#include <bsp/arm-pl011-regs.h>
    2729
    2830#ifdef __cplusplus
     
    3032#endif /* __cplusplus */
    3133
    32 extern const console_fns arm_pl011_fns;
     34typedef struct {
     35  rtems_termios_device_context base;
     36  volatile pl011 *regs;
     37  rtems_vector_number irq;
     38  uint32_t initial_baud;
     39} arm_pl011_context;
     40
     41bool arm_pl011_probe(rtems_termios_device_context *base);
     42
     43void arm_pl011_write_polled(rtems_termios_device_context *base, char c);
     44
     45extern const rtems_termios_device_handler arm_pl011_fns;
    3346
    3447#ifdef __cplusplus
  • c/src/lib/libbsp/arm/shared/include/arm-pl050.h

    r393e8ea r116ef2e9  
    88
    99/*
    10  * Copyright (c) 2013 embedded brains GmbH.  All rights reserved.
     10 * Copyright (c) 2013-2014 embedded brains GmbH.  All rights reserved.
    1111 *
    1212 *  embedded brains GmbH
     
    2424#define LIBBSP_ARM_SHARED_ARM_PL050_H
    2525
    26 #include <libchip/serial.h>
     26#include <rtems/termiostypes.h>
     27
     28#include <bsp/arm-pl050-regs.h>
    2729
    2830#ifdef __cplusplus
     
    3032#endif /* __cplusplus */
    3133
    32 extern const console_fns arm_pl050_fns;
     34typedef struct {
     35  rtems_termios_device_context base;
     36  volatile pl050 *regs;
     37  rtems_vector_number irq;
     38  uint32_t initial_baud;
     39} arm_pl050_context;
     40
     41extern const rtems_termios_device_handler arm_pl050_fns;
    3342
    3443#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.