Changeset cf811a4 in rtems


Ignore:
Timestamp:
07/09/18 11:12:57 (5 years ago)
Author:
Amaan Cheval <amaan.cheval@…>
Branches:
5, master
Children:
6539bea
Parents:
76c03152
git-author:
Amaan Cheval <amaan.cheval@…> (07/09/18 11:12:57)
git-committer:
Joel Sherrill <joel@…> (07/11/18 20:23:43)
Message:

x86_64/console: Add NS16550 polled console driver

This addition allows us to successfully run the sample hello.exe test.

Updates #2898.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • bsps/x86_64/amd64/console/console.c

    r76c03152 rcf811a4  
    2525 */
    2626
     27#include <libchip/ns16550.h>
     28#include <rtems/bspIo.h>
    2729#include <bsp.h>
    28 #include <rtems/bspIo.h>
    29 #include <rtems/libio.h>
     30#include <bsp/console-termios.h>
     31#include <rtems/score/cpuimpl.h>
    3032
    31 /*  console_initialize
    32  *
    33  *  This routine initializes the console IO driver.
    34  *
    35  *  Input parameters: NONE
    36  *
    37  *  Output parameters:  NONE
    38  *
    39  *  Return values:
    40  */
    41 
    42 rtems_device_driver console_initialize(
    43   rtems_device_major_number  major,
    44   rtems_device_minor_number  minor,
    45   void                      *arg
    46 )
     33static uint8_t amd64_uart_get_register(uintptr_t addr, uint8_t i)
    4734{
    48   (void) major;
    49   (void) minor;
    50   (void) arg;
    51   return RTEMS_SUCCESSFUL;
     35  return inport_byte(addr + i);
    5236}
    5337
    54 /*
    55  *  Open entry point
    56  */
    57 
    58 rtems_device_driver console_open(
    59   rtems_device_major_number major,
    60   rtems_device_minor_number minor,
    61   void                    * arg
    62 )
     38static void amd64_uart_set_register(uintptr_t addr, uint8_t i, uint8_t val)
    6339{
    64   (void) major;
    65   (void) minor;
    66   (void) arg;
    67   return RTEMS_SUCCESSFUL;
     40  outport_byte(addr + i, val);
    6841}
    6942
     43static ns16550_context amd64_uart_context = {
     44  .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART"),
     45  .get_reg = amd64_uart_get_register,
     46  .set_reg = amd64_uart_set_register,
     47  .port = (uintptr_t) COM1_BASE_IO,
     48  .initial_baud = COM1_CLOCK_RATE
     49};
     50
    7051/*
    71  *  Close entry point
     52 * XXX: We should use the interrupt based handler once interrupts are supported
    7253 */
     54const console_device console_device_table[] = {
     55  {
     56    .device_file = "/dev/console",
     57    .probe = console_device_probe_default,
     58    .handler = &ns16550_handler_polled,
     59    .context = &amd64_uart_context.base
     60  }
     61};
     62const size_t console_device_count = RTEMS_ARRAY_SIZE(console_device_table);
    7363
    74 rtems_device_driver console_close(
    75   rtems_device_major_number major,
    76   rtems_device_minor_number minor,
    77   void                    * arg
    78 )
     64static void output_char(char c)
    7965{
    80   (void) major;
    81   (void) minor;
    82   (void) arg;
    83   return RTEMS_SUCCESSFUL;
     66  rtems_termios_device_context *ctx = console_device_table[0].context;
     67
     68  ns16550_polled_putchar(ctx, c);
    8469}
    8570
    86 /*
    87  * read bytes from the serial port. We only have stdin.
    88  */
    89 
    90 rtems_device_driver console_read(
    91   rtems_device_major_number major,
    92   rtems_device_minor_number minor,
    93   void                    * arg
    94 )
    95 {
    96   (void) major;
    97   (void) minor;
    98   (void) arg;
    99   return RTEMS_SUCCESSFUL;
    100 }
    101 
    102 /*
    103  * write bytes to the serial port. Stdout and stderr are the same.
    104  */
    105 
    106 rtems_device_driver console_write(
    107   rtems_device_major_number major,
    108   rtems_device_minor_number minor,
    109   void                    * arg
    110 )
    111 {
    112   (void) major;
    113   (void) minor;
    114   (void) arg;
    115   return 0;
    116 }
    117 
    118 /*
    119  *  IO Control entry point
    120  */
    121 
    122 rtems_device_driver console_control(
    123   rtems_device_major_number major,
    124   rtems_device_minor_number minor,
    125   void                    * arg
    126 )
    127 {
    128   (void) major;
    129   (void) minor;
    130   (void) arg;
    131   return RTEMS_SUCCESSFUL;
    132 }
    133 
    134 BSP_output_char_function_type     BSP_output_char = NULL;
    135 BSP_polling_getchar_function_type BSP_poll_char   = NULL;
     71BSP_output_char_function_type BSP_output_char   = output_char;
     72BSP_polling_getchar_function_type BSP_poll_char = NULL;
  • c/src/lib/libbsp/x86_64/amd64/Makefile.am

    r76c03152 rcf811a4  
    3030librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/clock/clock-simidle.c
    3131# console
     32librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/serial/console-termios-init.c
     33librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/serial/console-termios.c
    3234librtemsbsp_a_SOURCES += ../../../../../../bsps/x86_64/amd64/console/console.c
    3335# timer
  • cpukit/score/cpu/x86_64/include/rtems/score/cpuimpl.h

    r76c03152 rcf811a4  
    2929#endif
    3030
     31static inline uint8_t inport_byte(uint16_t port)
     32{
     33  uint8_t ret;
     34  __asm__ volatile ( "inb %1, %0"
     35                     : "=a" (ret)
     36                     : "Nd" (port) );
     37  return ret;
     38}
     39
     40static inline void outport_byte(uint16_t port, uint8_t val)
     41{
     42  __asm__ volatile ( "outb %0, %1" : : "a" (val), "Nd" (port) );
     43}
     44
    3145#ifdef __cplusplus
    3246}
  • cpukit/score/cpu/x86_64/include/rtems/score/x86_64.h

    r76c03152 rcf811a4  
    3535#define CPU_MODEL_NAME "XXX: x86-64 generic"
    3636
     37#define COM1_BASE_IO 0x3F8
     38#define COM1_CLOCK_RATE (115200 * 16)
     39
    3740#ifdef __cplusplus
    3841}
Note: See TracChangeset for help on using the changeset viewer.