[PATCH] Raspberrypi: updated the console interface.

Christian Mauderer list at c-mauderer.de
Sat Dec 28 15:15:47 UTC 2019


On 28/12/2019 13:41, Niteesh wrote:
> On Sat, Dec 28, 2019 at 3:20 PM Christian Mauderer <list at c-mauderer.de
> <mailto:list at c-mauderer.de>> wrote:
> 
>     Missed your question further below in my first mail.
> 
>     On 28/12/2019 10:45, Christian Mauderer wrote:
>     > On 28/12/2019 09:38, Niteesh wrote:
>     >> I didn't get any of these warnings, which command did you use?
>     >
>     > Just the usual make in the build directory. I configured with the
>     > following line:
>     >
>     > /home/christian/rtems/rtems-bbb/build/..//libs/rtems/configure
>     > --target=arm-rtems5
>     > --prefix=/home/christian/rtems/rtems-bbb/build/..//install/rtems/5/
>     > --enable-rtemsbsp=raspberrypi --enable-maintainer-mode
>     > --enable-tests=samples --disable-networking
>     >
>     > Don't let the "bbb" irritate you: I hacked my normal beagle build
>     > environment for use with the raspberry.
>     >
>     > There are quite a lot of messages. So the warnings might are a bit
>     > hidden. Also note that you only get them if the file is recompiled. So
>     > either you have to change something or remove the console-config.o and
>     > fbcons.o object file to trigger them on a re-make.
>     >
>     >>
>     >> On Sat, Dec 28, 2019 at 3:48 AM Christian Mauderer
>     <list at c-mauderer.de <mailto:list at c-mauderer.de>
>     >> <mailto:list at c-mauderer.de <mailto:list at c-mauderer.de>>> wrote:
>     >>
>     >>     Hello,
>     >>
>     >>     git complained about some whitespaces when applying the patch:
>     >>
>     >>     ````````````
>     >>     git am \[PATCH\]\ Raspberrypi:\ updated\ the\ console\
>     interface..eml
>     >>     Applying: Raspberrypi: updated the console interface.
>     >>   
>      /home/christian/rtems/rtems-bbb/.git/modules/rtems/rebase-apply/patch:96:
>     >>     trailing
>     >>     whitespace.
>     >>
>     >>   
>      /home/christian/rtems/rtems-bbb/.git/modules/rtems/rebase-apply/patch:304:
>     >>     trailing whitespace.
>     >>     const rtems_termios_device_handler fbcons_fns =
>     >>   
>      /home/christian/rtems/rtems-bbb/.git/modules/rtems/rebase-apply/patch:481:
>     >>     trailing whitespace.
>     >>     bool fbcons_probe(
>     >>   
>      /home/christian/rtems/rtems-bbb/.git/modules/rtems/rebase-apply/patch:515:
>     >>     trailing whitespace.
>     >>      * @name Current Serial Device
>     >>     warning: 4 lines add whitespace errors.
>     >>     ````````````
>     >>
>     >> Fixed all the whitespace erros. 
>     >>
>     >>     When compiling I get some warnings like
>     >>
>     >>     ````````````
>     >>   
>      /home/christian/rtems/rtems-bbb/build/..//libs/rtems/c/src/lib/libbsp/arm/raspberrypi/../../../../../../bsps/arm/raspberrypi/console/console-config.c:
>     >>     In function 'output_char':
>     >>   
>      /home/christian/rtems/rtems-bbb/build/..//libs/rtems/c/src/lib/libbsp/arm/raspberrypi/../../../../../../bsps/arm/raspberrypi/console/console-config.c:64:3:
>     >>     warning: enumeration value 'AUX_UART' not handled in switch
>     [-Wswitch]
>     >>        switch(SERIAL){
>     >>        ^~~~~~
>     >>     ````````````
>     >>
>     >>     and
>     >>
>     >>     ````````````
>     >>   
>      /home/christian/rtems/rtems-bbb/build/..//libs/rtems/c/src/lib/libbsp/arm/raspberrypi/../../../../../../bsps/arm/raspberrypi/console/fbcons.c:174:17:
>     >>     warning: initialization from incompatible pointer type
>     >>     [-Wincompatible-pointer-types]
>     >>        .first_open = fbcons_open,
>     >>                      ^~~~~~~~~~~
>     >>     ````````````
>     >>
>     >>     Please fix these. I'm not entirely sure about the first
>     warning. That
>     >>     might has been there before. If possible it would be nice if
>     you could
>     >>     fix it anyway. In that case maybe in an extra commit.
>     >>
>     >>     At least the PL011 works on a Pi2 on real hardware too. I
>     haven't tested
>     >>     the framebuffer yet. I'm still trying to find out how to
>     select it
>     >>     before or after the patch.
>     >>
>     >>     Please see my notes in the patch below regarding some points.
>     >>
>     >>     Best regards
>     >>
>     >>     Christian
>     >>
>     >>     On 27/12/2019 12:08, G S Niteesh wrote:
>     >>     > The patch updates the older console interface used by the BSP,
>     >>     > to newer one. It also replaces the custom usart(PL011) driver
>     >>     > with arm-pl011. The fb functions signatures where also changed
>     >>     > to accommodate with interface update.
>     >>     > ---
>     >>     >  bsps/arm/raspberrypi/console/console-config.c |  67 +++++----
>     >>     >  bsps/arm/raspberrypi/console/console_select.c |  65 +-------
>     >>     >  bsps/arm/raspberrypi/console/fbcons.c         |  50 +++---
>     >>     >  bsps/arm/raspberrypi/console/usart.c          | 142
>     >>     ------------------
>     >>     >  bsps/arm/raspberrypi/include/bsp/fbcons.h     |  19 ++-
>     >>     >  .../arm/raspberrypi/include/bsp/raspberrypi.h |  52 ++-----
>     >>     >  bsps/arm/raspberrypi/include/bsp/usart.h      |   5 +-
>     >>     >  c/src/lib/libbsp/arm/raspberrypi/Makefile.am  |   5 +-
>     >>     >  8 files changed, 105 insertions(+), 300 deletions(-)
>     >>     >
>     >>     > diff --git a/bsps/arm/raspberrypi/console/console-config.c
>     >>     b/bsps/arm/raspberrypi/console/console-config.c
>     >>     > index d2186c918b..1f6dec384a 100644
>     >>     > --- a/bsps/arm/raspberrypi/console/console-config.c
>     >>     > +++ b/bsps/arm/raspberrypi/console/console-config.c
>     >>     > @@ -22,45 +22,54 @@
>     >>     > 
>     >>     >  #include <libchip/serial.h>
>     >>     > 
>     >>     > -#include <bspopts.h>
>     >>     > -#include <bsp/irq.h>
>     >>     > +#include <bsp.h>
>     >>     >  #include <bsp/usart.h>
>     >>     >  #include <bsp/raspberrypi.h>
>     >>     > +#include <bsp/arm-pl011.h>
>     >>     >  #include <bsp/fbcons.h>
>     >>     > +#include <bsp/console-termios.h>
>     >>     > +
>     >>     > +#include <bspopts.h>
>     >>     > 
>     >>     > -console_tbl Console_Configuration_Ports [] = {
>     >>     > -    {
>     >>     > -      .sDeviceName = "/dev/ttyS0",
>     >>     > -      .deviceType = SERIAL_CUSTOM,
>     >>     > -      .pDeviceFns = &bcm2835_usart_fns,
>     >>     > -      .deviceProbe = NULL,
>     >>     > -      .pDeviceFlow = NULL,
>     >>     > -      .ulCtrlPort1 = BCM2835_UART0_BASE,
>     >>     > -      .ulCtrlPort2 = 0,
>     >>     > -      .ulClock = USART0_DEFAULT_BAUD,
>     >>     > -      .ulIntVector = BCM2835_IRQ_ID_UART
>     >>     > -    },
>     >>     > -    {
>     >>     > -      .sDeviceName ="/dev/fbcons",
>     >>     > -      .deviceType = SERIAL_CUSTOM,
>     >>     > -      .pDeviceFns = &fbcons_fns,
>     >>     > -      .deviceProbe = fbcons_probe,
>     >>     > -      .pDeviceFlow = NULL,
>     >>     > -    },
>     >>     > +arm_pl011_context pl011_context = {
>     >>     > +  .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("PL011"),
>     >>     > +  .regs = (volatile pl011 *) BCM2835_PL011_BASE,
>     >>     > +  .initial_baud = PL011_DEFAULT_BAUD
>     >>     >  };
>     >>     > 
>     >>     > -#define PORT_COUNT \
>     >>     > -  (sizeof(Console_Configuration_Ports) \
>     >>     > -    / sizeof(Console_Configuration_Ports [0]))
>     >>     > +rpi_fb_context fb_context = {
>     >>     > +  .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("FB")
>     >>     > +};
>     >>     > 
>     >>     > -unsigned long Console_Configuration_Count = PORT_COUNT;
>     >>     > +const console_device console_device_table[] = {
>     >>     > +  {
>     >>     > +    .device_file = "/dev/ttyS0",
>     >>     > +    .probe = console_device_probe_default,
>     >>     > +    .handler = &arm_pl011_fns,
>     >>     > +    .context = &pl011_context.base
>     >>     > +  },
>     >>     > +  {
>     >>     > +    .device_file = "/dev/fbcons",
>     >>     > +    // Should be changed to fbcons_probe (but it still use old
>     >>     interface)
>     >>
>     >>     What do you mean with that comment?
>     >>
>     >> I am sorry, I actually forgot to remove the comment. Previously I was
>     >> using default
>     >> probe function. But then changed it to fbcons_probe.
>     >>
>     >>      
>     >>
>     >>     > +    .probe = fbcons_probe,
>     >>     > +    .handler = &fbcons_fns,
>     >>     > +    .context = &fb_context.base
>     >>     > +  }
>     >>     > +};
>     >>     > +
>     >>     > +const size_t console_device_count =
>     >>     RTEMS_ARRAY_SIZE(console_device_table);
>     >>     > 
>     >>     >  static void output_char(char c)
>     >>     >  {
>     >>     > -  const console_fns *con =
>     >>     > -    Console_Configuration_Ports
>     [Console_Port_Minor].pDeviceFns;
>     >>     > -
>     >>     > -  con->deviceWritePolled((int) Console_Port_Minor, c);
>     >>     > +  switch(SERIAL){
>     >>     > +    case FB:
>     >>     > +      fbcons_write_polled(&fb_context.base, c);
>     >>     > +      break;
>     >>     > +    case PL011:
>     >>     > +      arm_pl011_write_polled(&pl011_context.base, c);
>     >>     > +      break;
>     >>
>     >>     I don't like that selection method.
>     >>
>     >>     1. I'm not happy with that naming. It's a variable so please
>     write it in
>     >>     lower case. Same is true for the type CURRENT_SERIAL. It
>     should be a
>     >>     lower case name.
>     >>
>     >>     2. There is no default case.
>     >>
>     >>     3. This adds lot's of overhead. It means that for every
>     character a
>     >>     switch case has to be evaluated. BSP_output_char is a pointer
>     so you can
>     >>     just change it's value to point to one of two functions.
>     >>
>     >> Fixed this also. Removed the enum and switch, added a function
>     pointer
>     >> to the poll function, which is then called
>     >> from outputchar by providing the right context.
>     >>
>     >> I modified and added the is_bsp_available, which check's if the
>     current
>     >> serial is
>     >> available, if not throws BSP_FATAL_CONSOLE_NO_DEV.
>     >>
>     >> I was getting many warnings regarding incompatible pointer for
>     eg: the
>     >> write function in the device handler
>     >> expects a void function, so I modified the
>     fbcons_write_support_polled
>     >> to void, which was previously returning
>     >> the size of bytes written. Is that fine?
> 
>     If it isn't used anywhere else, it's OK. But isn't that function used
>     for termios too?
> 
> What do you mean by termios? I am talking about the 
> rterms_termios_device_handler,  this is responsible for termios right?
> And as per the doc
> the write function returns void. 

Maybe I misunderstood:

We talked about the BSP_output_char function, right? In the original
version of the patch you used the following one:

    static void output_char(char c)
    {
      switch(SERIAL){
        case FB:
          fbcons_write_polled(&fb_context.base, c);
          break;
        case PL011:
          arm_pl011_write_polled(&pl011_context.base, c);
          break;
      }
    }

    BSP_output_char_function_type BSP_output_char = output_char;

You either call the fbcons_write_polled or the arm_pl011_write_polled.

Basically the BSP_output_char is a shortcut. It uses an interface
without the termios layer. But both functions are also called via
termios. In both cases via a ..._write_support_polled function. So you
can't just change the function prototype.

> 
>     You can also write a small wrapper function if you have to adapt
>     something. That adds very few overhead. If the parameters match and only
>     the return type should be ignored, a cast would be an alternative.
> 
> I will go with the cast. 

I had a more detailled look: Most likely the cast won't work. For the
two ..._write_polled functions you need a context parameter.
BSP_output_char doesn't support one. So you would be missing a parameter.

> 
>     >>
>     >> How should I now apply this modified patch?
> 
>     Add the changes to your previous patch ("git commit --amend" or "git
>     rebase -i") and create a version 2 ("git format-patch -v2 HEAD^") and
>     send that just like before with "git send-email". That will give you the
>     [PATCH v2] headers that you find on our mailing list.
> 
>     >>
>     >>     > +  }
>     >>     > + 
>     >>     >  }
>     >>     > 
>     >>     >  BSP_output_char_function_type BSP_output_char = output_char;
>     >>     > diff --git a/bsps/arm/raspberrypi/console/console_select.c
>     >>     b/bsps/arm/raspberrypi/console/console_select.c
>     >>     > index bd246ca868..a7bd844bb0 100644
>     >>     > --- a/bsps/arm/raspberrypi/console/console_select.c
>     >>     > +++ b/bsps/arm/raspberrypi/console/console_select.c
>     >>     > @@ -15,7 +15,7 @@
>     >>     >   *  http://www.rtems.org/license/LICENSE
>     >>     >   *
>     >>     >   */
>     >>     > -
>     >>     > +#include <bsp/raspberrypi.h>
>     >>     >  #include <bsp.h>
>     >>     >  #include <bsp/fatal.h>
>     >>     >  #include <rtems/libio.h>
>     >>     > @@ -24,59 +24,12 @@
>     >>     >  #include <assert.h>
>     >>     >  #include <termios.h>
>     >>     > 
>     >>     > -#include <rtems/termiostypes.h>
>     >>     >  #include <libchip/serial.h>
>     >>     >  #include "../../shared/dev/serial/legacy-console.h"
>     >>     >  #include <bsp/rpi-fb.h>
>     >>     > 
>     >>     >  rtems_device_minor_number BSPPrintkPort = 0;
>     >>     > -
>     >>     > -/*
>     >>     > - * Method to return true if the device associated with the
>     >>     > - * minor number probs available.
>     >>     > - */
>     >>     > -static bool bsp_Is_Available( rtems_device_minor_number
>     minor )
>     >>     > -{
>     >>     > -  console_tbl *cptr = Console_Port_Tbl[ minor ];
>     >>     > -
>     >>     > -  /*
>     >>     > -   * First perform the configuration dependent probe, then the
>     >>     > -   * device dependent probe
>     >>     > -   */
>     >>     > -  if ( ( !cptr->deviceProbe || cptr->deviceProbe( minor ) ) &&
>     >>     > -       cptr->pDeviceFns->deviceProbe( minor ) ) {
>     >>     > -    return true;
>     >>     > -  }
>     >>     > -
>     >>     > -  return false;
>     >>     > -}
>     >>     > -
>     >>     > -/*
>     >>     > - * Method to return the first available device.
>     >>     > - */
>     >>     > -static rtems_device_minor_number
>     bsp_First_Available_Device( void )
>     >>     > -{
>     >>     > -  rtems_device_minor_number minor;
>     >>     > -
>     >>     > -  for ( minor = 0; minor < Console_Port_Count; minor++ ) {
>     >>     > -    console_tbl *cptr = Console_Port_Tbl[ minor ];
>     >>     > -
>     >>     > -    /*
>     >>     > -     * First perform the configuration dependent probe,
>     then the
>     >>     > -     * device dependent probe
>     >>     > -     */
>     >>     > -
>     >>     > -    if ( ( !cptr->deviceProbe || cptr->deviceProbe( minor
>     ) ) &&
>     >>     > -         cptr->pDeviceFns->deviceProbe( minor ) ) {
>     >>     > -      return minor;
>     >>     > -    }
>     >>     > -  }
>     >>     > -
>     >>     > -  /*
>     >>     > -   *  Error No devices were found.  We will want to bail here.
>     >>     > -   */
>     >>     > -  bsp_fatal( BSP_FATAL_CONSOLE_NO_DEV );
>     >>     > -}
>     >>     > +CURRENT_SERIAL SERIAL = PL011;>
>     >>     >  void bsp_console_select( void )
>     >>     >  {
>     >>     > @@ -90,25 +43,13 @@ void bsp_console_select( void )
>     >>     >     */
>     >>     >    const char *opt;
>     >>     > 
>     >>     > -  Console_Port_Minor = BSP_CONSOLE_UART0;
>     >>     > -  BSPPrintkPort = BSP_CONSOLE_UART0;
>     >>     > -
>     >>     >    opt = rpi_cmdline_get_arg( "--console=" );
>     >>     > 
>     >>     >    if ( opt ) {
>     >>     >      if ( strncmp( opt, "fbcons", sizeof( "fbcons" ) - 1 )
>     == 0 ) {
>     >>     >        if ( rpi_video_is_initialized() > 0 ) {
>     >>     > -        Console_Port_Minor = BSP_CONSOLE_FB;
>     >>     > -        BSPPrintkPort = BSP_CONSOLE_FB;
>     >>     > +        SERIAL = FB;
>     >>     >        }
>     >>     >      }
>     >>     >    }
>     >>     > -
>     >>     > -  /*
>     >>     > -   * If the device that was selected isn't available then
>     >>     > -   * let the user know and select the first available device.
>     >>     > -   */
>     >>     > -  if ( !bsp_Is_Available( Console_Port_Minor ) ) {
>     >>     > -    Console_Port_Minor = bsp_First_Available_Device();
>     >>     > -  }
>     >>     >  }
>     >>     > diff --git a/bsps/arm/raspberrypi/console/fbcons.c
>     >>     b/bsps/arm/raspberrypi/console/fbcons.c
>     >>     > index 3669ba458d..99f2ab1aff 100644
>     >>     > --- a/bsps/arm/raspberrypi/console/fbcons.c
>     >>     > +++ b/bsps/arm/raspberrypi/console/fbcons.c
>     >>     > @@ -18,6 +18,7 @@
>     >>     > 
>     >>     >  #include <rtems.h>
>     >>     >  #include <rtems/libio.h>
>     >>     > +#include <rtems/termiostypes.h>
>     >>     > 
>     >>     >  #include <stdlib.h>
>     >>     > 
>     >>     > @@ -46,9 +47,10 @@ static void fbcons_init( int minor )
>     >>     >   *  Default state is 9600 baud, 8 bits, No parity, and 1
>     stop bit.
>     >>     >   */
>     >>     >  static int fbcons_open(
>     >>     > -  int   major,
>     >>     > -  int   minor,
>     >>     > -  void *arg
>     >>     > +  struct rtems_termios_tty *tty,
>     >>     > +  rtems_termios_device_context *base,
>     >>     > +  struct termios *term,
>     >>     > +  rtems_libio_open_close_args_t *args
>     >>     >  )
>     >>     >  {
>     >>     >    return RTEMS_SUCCESSFUL;
>     >>     > @@ -60,9 +62,9 @@ static int fbcons_open(
>     >>     >   *  This function shuts down the requested port.
>     >>     >   */
>     >>     >  static int fbcons_close(
>     >>     > -  int   major,
>     >>     > -  int   minor,
>     >>     > -  void *arg
>     >>     > +  struct rtems_termios_tty *tty,
>     >>     > +  rtems_termios_device_context *base,
>     >>     > +  rtems_libio_open_close_args_t *args
>     >>     >  )
>     >>     >  {
>     >>     >    return ( RTEMS_SUCCESSFUL );
>     >>     > @@ -73,8 +75,8 @@ static int fbcons_close(
>     >>     >   *
>     >>     >   *  This routine polls out the requested character.
>     >>     >   */
>     >>     > -static void fbcons_write_polled(
>     >>     > -  int  minor,
>     >>     > +void fbcons_write_polled(
>     >>     > +  rtems_termios_device_context *base,
>     >>     >    char c
>     >>     >  )
>     >>     >  {
>     >>     > @@ -91,7 +93,7 @@ static void fbcons_write_polled(
>     >>     >   *
>     >>     >   */
>     >>     >  static ssize_t fbcons_write_support_polled(
>     >>     > -  int         minor,
>     >>     > +  rtems_termios_device_context *base,
>     >>     >    const char *buf,
>     >>     >    size_t      len
>     >>     >  )
>     >>     > @@ -102,7 +104,7 @@ static ssize_t fbcons_write_support_polled(
>     >>     >     * poll each byte in the string out of the port.
>     >>     >     */
>     >>     >    while ( nwrite < len ) {
>     >>     > -    fbcons_write_polled( minor, *buf++ );
>     >>     > +    fbcons_write_polled( base, *buf++ );
>     >>     >      nwrite++;
>     >>     >    }
>     >>     > 
>     >>     > @@ -117,7 +119,9 @@ static ssize_t fbcons_write_support_polled(
>     >>     >   *
>     >>     >   *  Console Termios polling input entry point.
>     >>     >   */
>     >>     > -static int fbcons_inbyte_nonblocking_polled( int minor )
>     >>     > +int fbcons_inbyte_nonblocking_polled(
>     >>     > +  rtems_termios_device_context *base
>     >>     > +)
>     >>     >  {
>     >>     >    // if( rtems_kbpoll() ) {
>     >>     >    //   int c = getch();
>     >>     > @@ -134,14 +138,16 @@ static int
>     fbcons_inbyte_nonblocking_polled(
>     >>     int minor )
>     >>     >   *  port settings.
>     >>     >   */
>     >>     >  static int fbcons_set_attributes(
>     >>     > -  int                   minor,
>     >>     > +  rtems_termios_device_context *base,
>     >>     >    const struct termios *t
>     >>     >  )
>     >>     >  {
>     >>     >    return 0;
>     >>     >  }
>     >>     > 
>     >>     > -bool fbcons_probe( int minor )
>     >>     > +bool fbcons_probe(
>     >>     > +  rtems_termios_device_context *base
>     >>     > +)
>     >>     >  {
>     >>     >    // rtems_status_code status;
>     >>     >    static bool firstTime = true;
>     >>     > @@ -163,15 +169,11 @@ bool fbcons_probe( int minor )
>     >>     >    return ret;
>     >>     >  }
>     >>     > 
>     >>     > -const console_fns fbcons_fns =
>     >>     > +const rtems_termios_device_handler fbcons_fns =
>     >>     >  {
>     >>     > -  .deviceProbe = libchip_serial_default_probe,     /*
>     deviceProbe */
>     >>     > -  .deviceFirstOpen = fbcons_open,                 /*
>     >>     deviceFirstOpen */
>     >>     > -  .deviceLastClose = fbcons_close,                /*
>     >>     deviceLastClose */
>     >>     > -  .deviceRead = fbcons_inbyte_nonblocking_polled, /*
>     deviceRead */
>     >>     > -  .deviceWrite = fbcons_write_support_polled,     /*
>     deviceWrite */
>     >>     > -  .deviceInitialize = fbcons_init,                /*
>     >>     deviceInitialize */
>     >>     > -  .deviceWritePolled = fbcons_write_polled,       /*
>     >>     deviceWritePolled */
>     >>     > -  .deviceSetAttributes = fbcons_set_attributes,   /*
>     >>     deviceSetAttributes */
>     >>     > -  .deviceOutputUsesInterrupts = FALSE,           /*
>     >>     deviceOutputUsesInterrupts*/
>     >>     > -};
>     >>     > +  .first_open = fbcons_open,
>     >>     > +  .last_close = fbcons_close,
>     >>     > +  .poll_read = fbcons_inbyte_nonblocking_polled,
>     >>     > +  .write = fbcons_write_support_polled,
>     >>     > +  .mode = TERMIOS_POLLED
>     >>     > +};
>     >>     > \ No newline at end of file
>     >>     > diff --git a/bsps/arm/raspberrypi/console/usart.c
>     >>     b/bsps/arm/raspberrypi/console/usart.c
>     >>     > index 25fb523621..471d0c553f 100644
>     >>     > --- a/bsps/arm/raspberrypi/console/usart.c
>     >>     > +++ b/bsps/arm/raspberrypi/console/usart.c
>     >>     > @@ -23,145 +23,3 @@
>     >>     >  #include <bsp/usart.h>
>     >>     >  #include <bsp/raspberrypi.h>
>     >>     >  #include <rtems/bspIo.h>
>     >>     > -
>     >>     > -static void usart_delay(uint32_t n)
>     >>     > -{
>     >>     > - volatile uint32_t i = 0;
>     >>     > -
>     >>     > - for(i = 0; i < n; i++)
>     >>     > -   ;
>     >>     > -}
>     >>     > -
>     >>     > -#if 0
>     >>     > -/*
>     >>     > - *  These will be useful when the driver supports interrupt
>     >>     driven IO.
>     >>     > - */
>     >>     > -static rtems_vector_number usart_get_irq_number(const
>     console_tbl
>     >>     *ct)
>     >>     > -{
>     >>     > -  return ct->ulIntVector;
>     >>     > -}
>     >>     > -
>     >>     > -static uint32_t usart_get_baud(const console_tbl *ct)
>     >>     > -{
>     >>     > -  return ct->ulClock;
>     >>     > -}
>     >>     > -#endif
>     >>     > -
>     >>     > -static void usart_set_baud(int minor, int baud)
>     >>     > -{
>     >>     > - /*
>     >>     > -  * Nothing for now
>     >>     > -  */
>     >>     > - return;
>     >>     > -}
>     >>     > -
>     >>     > -static void usart_initialize(int minor)
>     >>     > -{
>     >>     > -  unsigned int gpio_reg;
>     >>     > -
>     >>     > -  /*
>     >>     > -  ** Program GPIO pins for UART 0
>     >>     > -  */
>     >>     > -  gpio_reg = BCM2835_REG(BCM2835_GPIO_GPFSEL1);
>     >>     > -  gpio_reg &= ~(7<<12);    /* gpio14 */
>     >>     > -  gpio_reg |=  (4<<12);    /* alt0   */
>     >>     > -  gpio_reg &= ~(7<<15);    /* gpio15 */
>     >>     > -  gpio_reg |=  (4<<15);    /* alt0   */
>     >>     > -  BCM2835_REG(BCM2835_GPIO_GPFSEL1) = gpio_reg;
>     >>     > -
>     >>     > -  BCM2835_REG(BCM2835_GPIO_GPPUD) = 0;
>     >>     > -  usart_delay(150);
>     >>     > -  BCM2835_REG(BCM2835_GPIO_GPPUDCLK0) = (1<<14)|(1<<15);
>     >>     > -  usart_delay(150);
>     >>     > -  BCM2835_REG(BCM2835_GPIO_GPPUDCLK0) = 0;
>     >>     > -
>     >>     > -  /*
>     >>     > -  ** Init the PL011 UART
>     >>     > -  */
>     >>     > -  BCM2835_REG(BCM2835_UART0_CR)   = 0;
>     >>     > -  BCM2835_REG(BCM2835_UART0_ICR)  = 0x7FF;
>     >>     > -  BCM2835_REG(BCM2835_UART0_IMSC) = 0;
>     >>     > -  BCM2835_REG(BCM2835_UART0_IBRD) = 1;
>     >>     > -  BCM2835_REG(BCM2835_UART0_FBRD) = 40;
>     >>     > -  BCM2835_REG(BCM2835_UART0_LCRH) = 0x70;
>     >>     > -  BCM2835_REG(BCM2835_UART0_RSRECR) =  0;
>     >>     > -
>     >>     > -  BCM2835_REG(BCM2835_UART0_CR)   = 0x301;
>     >>     > -
>     >>     > -  BCM2835_REG(BCM2835_UART0_IMSC) = BCM2835_UART0_IMSC_RX;
>     >>     > -
>     >>     > -  usart_set_baud(minor, 115000);
>     >>     > -}
>     >>     > -
>     >>     > -static int usart_first_open(int major, int minor, void *arg)
>     >>     > -{
>     >>     > -  rtems_libio_open_close_args_t *oc =
>     >>     (rtems_libio_open_close_args_t *) arg;
>     >>     > -  struct rtems_termios_tty *tty = (struct rtems_termios_tty *)
>     >>     oc->iop->data1;
>     >>     > -  const console_tbl *ct = Console_Port_Tbl [minor];
>     >>     > -  console_data *cd = &Console_Port_Data [minor];
>     >>     > -
>     >>     > -  cd->termios_data = tty;
>     >>     > -  rtems_termios_set_initial_baud(tty, ct->ulClock);
>     >>     > -
>     >>     > -  return 0;
>     >>     > -}
>     >>     > -
>     >>     > -static int usart_last_close(int major, int minor, void *arg)
>     >>     > -{
>     >>     > -  return 0;
>     >>     > -}
>     >>     > -
>     >>     > -static int usart_read_polled(int minor)
>     >>     > -{
>     >>     > -  if (minor == 0) {
>     >>     > -    if (((BCM2835_REG(BCM2835_UART0_FR)) &
>     BCM2835_UART0_FR_RXFE)
>     >>     == 0) {
>     >>     > -       return((BCM2835_REG(BCM2835_UART0_DR)) & 0xFF );
>     >>     > -    } else {
>     >>     > -      return -1;
>     >>     > -    }
>     >>     > -  } else {
>     >>     > -    printk("Unknown console minor number: %d\n", minor);
>     >>     > -    return -1;
>     >>     > -  }
>     >>     > -}
>     >>     > -
>     >>     > -static void usart_write_polled(int minor, char c)
>     >>     > -{
>     >>     > -   while (1) {
>     >>     > -     if ((BCM2835_REG(BCM2835_UART0_FR) &
>     BCM2835_UART0_FR_TXFF)
>     >>     == 0)
>     >>     > -       break;
>     >>     > -   }
>     >>     > -   BCM2835_REG(BCM2835_UART0_DR) = c;
>     >>     > -}
>     >>     > -
>     >>     > -static ssize_t usart_write_support_polled(
>     >>     > -  int minor,
>     >>     > -  const char *s,
>     >>     > -  size_t n
>     >>     > -)
>     >>     > -{
>     >>     > -  ssize_t i = 0;
>     >>     > -
>     >>     > -  for (i = 0; i < n; ++i) {
>     >>     > -    usart_write_polled(minor, s [i]);
>     >>     > -  }
>     >>     > -
>     >>     > -  return n;
>     >>     > -}
>     >>     > -
>     >>     > -static int usart_set_attributes(int minor, const struct
>     termios
>     >>     *term)
>     >>     > -{
>     >>     > -  return -1;
>     >>     > -}
>     >>     > -
>     >>     > -const console_fns bcm2835_usart_fns = {
>     >>     > -  .deviceProbe = libchip_serial_default_probe,
>     >>     > -  .deviceFirstOpen = usart_first_open,
>     >>     > -  .deviceLastClose = usart_last_close,
>     >>     > -  .deviceRead = usart_read_polled,
>     >>     > -  .deviceWrite = usart_write_support_polled,
>     >>     > -  .deviceInitialize = usart_initialize,
>     >>     > -  .deviceWritePolled = usart_write_polled,
>     >>     > -  .deviceSetAttributes = usart_set_attributes,
>     >>     > -  .deviceOutputUsesInterrupts = false
>     >>     > -};
>     >>     > diff --git a/bsps/arm/raspberrypi/include/bsp/fbcons.h
>     >>     b/bsps/arm/raspberrypi/include/bsp/fbcons.h
>     >>     > index d0e126699a..85b16fafe9 100644
>     >>     > --- a/bsps/arm/raspberrypi/include/bsp/fbcons.h
>     >>     > +++ b/bsps/arm/raspberrypi/include/bsp/fbcons.h
>     >>     > @@ -33,12 +33,27 @@ extern "C" {
>     >>     > 
>     >>     >  #define FB_CONSOLE 0x50492835
>     >>     > 
>     >>     > -bool fbcons_probe( int minor );
>     >>     > +bool fbcons_probe(
>     >>     > +  rtems_termios_device_context *base
>     >>     > + );
>     >>     > +
>     >>     > +void fbcons_write_polled(
>     >>     > +  rtems_termios_device_context *base,
>     >>     > +  char c
>     >>     > +);
>     >>     > +
>     >>     > +int fbcons_inbyte_nonblocking_polled(
>     >>     > +  rtems_termios_device_context *base
>     >>     > +);
>     >>     > +
>     >>     > +typedef struct {
>     >>     > +    rtems_termios_device_context base;
>     >>     > +} rpi_fb_context ;
>     >>     > 
>     >>     >  /*
>     >>     >   * Driver function table
>     >>     >   */
>     >>     > -extern const console_fns fbcons_fns;
>     >>     > +extern const rtems_termios_device_handler fbcons_fns;
>     >>     > 
>     >>     >  #ifdef __cplusplus
>     >>     >  }
>     >>     > diff --git a/bsps/arm/raspberrypi/include/bsp/raspberrypi.h
>     >>     b/bsps/arm/raspberrypi/include/bsp/raspberrypi.h
>     >>     > index 40c80cf408..4e5c84c741 100644
>     >>     > --- a/bsps/arm/raspberrypi/include/bsp/raspberrypi.h
>     >>     > +++ b/bsps/arm/raspberrypi/include/bsp/raspberrypi.h
>     >>     > @@ -60,6 +60,22 @@
>     >>     > 
>     >>     >  #define RPI_PERIPHERAL_SIZE         0x01000000
>     >>     > 
>     >>     > +/**
>     >>     > + * @name Current Serial Device
>     >>     > + *
>     >>     > + * @{
>     >>     > + */
>     >>     > +
>     >>     > +typedef enum {
>     >>     > +  PL011 = 0,
>     >>     > +  AUX_UART,
>     >>     > +  FB
>     >>     > +}CURRENT_SERIAL;
>     >>     > +
>     >>     > +extern CURRENT_SERIAL SERIAL;
>     >>     > +
>     >>     > +/** @} */
>     >>     > +
>     >>     >  /**
>     >>     >   * @name Internal ARM Timer Registers
>     >>     >   *
>     >>     > @@ -184,42 +200,6 @@
>     >>     > 
>     >>     >  /** @} */
>     >>     > 
>     >>     > -/**
>     >>     > - * @name UART 0 (PL011) Registers
>     >>     > - *
>     >>     > - * @{
>     >>     > - */
>     >>     > -
>     >>     > -#define BCM2835_UART0_BASE       (RPI_PERIPHERAL_BASE +
>     0x201000)
>     >>     > -
>     >>     > -#define BCM2835_UART0_DR         (BCM2835_UART0_BASE + 0x00)
>     >>     > -#define BCM2835_UART0_RSRECR     (BCM2835_UART0_BASE + 0x04)
>     >>     > -#define BCM2835_UART0_FR         (BCM2835_UART0_BASE + 0x18)
>     >>     > -#define BCM2835_UART0_ILPR       (BCM2835_UART0_BASE + 0x20)
>     >>     > -#define BCM2835_UART0_IBRD       (BCM2835_UART0_BASE + 0x24)
>     >>     > -#define BCM2835_UART0_FBRD       (BCM2835_UART0_BASE + 0x28)
>     >>     > -#define BCM2835_UART0_LCRH       (BCM2835_UART0_BASE + 0x2C)
>     >>     > -#define BCM2835_UART0_CR         (BCM2835_UART0_BASE + 0x30)
>     >>     > -#define BCM2835_UART0_IFLS       (BCM2835_UART0_BASE + 0x34)
>     >>     > -#define BCM2835_UART0_IMSC       (BCM2835_UART0_BASE + 0x38)
>     >>     > -#define BCM2835_UART0_RIS        (BCM2835_UART0_BASE + 0x3C)
>     >>     > -#define BCM2835_UART0_MIS        (BCM2835_UART0_BASE + 0x40)
>     >>     > -#define BCM2835_UART0_ICR        (BCM2835_UART0_BASE + 0x44)
>     >>     > -#define BCM2835_UART0_DMACR      (BCM2835_UART0_BASE + 0x48)
>     >>     > -#define BCM2835_UART0_ITCR       (BCM2835_UART0_BASE + 0x80)
>     >>     > -#define BCM2835_UART0_ITIP       (BCM2835_UART0_BASE + 0x84)
>     >>     > -#define BCM2835_UART0_ITOP       (BCM2835_UART0_BASE + 0x88)
>     >>     > -#define BCM2835_UART0_TDR        (BCM2835_UART0_BASE + 0x8C)
>     >>     > -
>     >>     > -#define BCM2835_UART0_MIS_RX    0x10
>     >>     > -#define BCM2835_UART0_MIS_TX    0x20
>     >>     > -#define BCM2835_UART0_IMSC_RX   0x10
>     >>     > -#define BCM2835_UART0_IMSC_TX   0x20
>     >>     > -#define BCM2835_UART0_FR_RXFE   0x10
>     >>     > -#define BCM2835_UART0_FR_TXFF   0x20
>     >>     > -#define BCM2835_UART0_ICR_RX    0x10
>     >>     > -#define BCM2835_UART0_ICR_TX    0x20
>     >>     > -
>     >>     >  /** @} */
>     >>     > 
>     >>     >  /**
>     >>     > diff --git a/bsps/arm/raspberrypi/include/bsp/usart.h
>     >>     b/bsps/arm/raspberrypi/include/bsp/usart.h
>     >>     > index d3e710c5e9..abbf53626c 100644
>     >>     > --- a/bsps/arm/raspberrypi/include/bsp/usart.h
>     >>     > +++ b/bsps/arm/raspberrypi/include/bsp/usart.h
>     >>     > @@ -32,9 +32,8 @@
>     >>     >  extern "C" {
>     >>     >  #endif /* __cplusplus */
>     >>     > 
>     >>     > -#define USART0_DEFAULT_BAUD 115000
>     >>     > -
>     >>     > -extern const console_fns bcm2835_usart_fns;
>     >>     > +#define PL011_DEFAULT_BAUD 115000
>     >>     > +#define BCM2835_PL011_BASE (RPI_PERIPHERAL_BASE + 0x201000)
>     >>     > 
>     >>     >  #ifdef __cplusplus
>     >>     >  }
>     >>     > diff --git a/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
>     >>     b/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
>     >>     > index 11a22f89e3..ce91527f92 100644
>     >>     > --- a/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
>     >>     > +++ b/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
>     >>     > @@ -63,14 +63,15 @@ librtemsbsp_a_SOURCES +=
>     >>     ../../../../../../bsps/arm/shared/cp15/arm-cp15-set-exc
>     >>     >  librtemsbsp_a_SOURCES +=
>     >>     ../../../../../../bsps/arm/raspberrypi/irq/irq.c
>     >>     > 
>     >>     >  # Console
>     >>     > -librtemsbsp_a_SOURCES +=
>     >>     ../../../../../../bsps/shared/dev/serial/legacy-console.c
>     >>     > -librtemsbsp_a_SOURCES +=
>     >>     ../../../../../../bsps/shared/dev/serial/legacy-console-control.c
>     >>     >  librtemsbsp_a_SOURCES +=
>     >>     ../../../../../../bsps/arm/raspberrypi/console/console-config.c
>     >>     >  librtemsbsp_a_SOURCES +=
>     >>     ../../../../../../bsps/arm/raspberrypi/console/console_select.c
>     >>     >  librtemsbsp_a_SOURCES +=
>     >>     ../../../../../../bsps/arm/raspberrypi/console/usart.c
>     >>     >  librtemsbsp_a_SOURCES +=
>     >>     ../../../../../../bsps/arm/raspberrypi/console/fb.c
>     >>     >  librtemsbsp_a_SOURCES +=
>     >>     ../../../../../../bsps/arm/raspberrypi/console/fbcons.c
>     >>     >  librtemsbsp_a_SOURCES +=
>     >>     ../../../../../../bsps/arm/raspberrypi/console/outch.c
>     >>     > +librtemsbsp_a_SOURCES +=
>     >>     ../../../../../../bsps/shared/dev/serial/console-termios.c
>     >>     > +librtemsbsp_a_SOURCES +=
>     >>     ../../../../../../bsps/shared/dev/serial/console-termios-init.c
>     >>     > +librtemsbsp_a_SOURCES +=
>     >>     ../../../../../../bsps/arm/shared/serial/arm-pl011.c
>     >>     > 
>     >>     >  # Mailbox
>     >>     >  librtemsbsp_a_SOURCES +=
>     >>     ../../../../../../bsps/arm/raspberrypi/start/mailbox.c
>     >>     >
>     >>
>     > _______________________________________________
>     > devel mailing list
>     > devel at rtems.org <mailto:devel at rtems.org>
>     > http://lists.rtems.org/mailman/listinfo/devel
>     >
> 


More information about the devel mailing list