[PATCH 5/5] arm/raspberrypi: add fbcons support for rpi bsp

Gedare Bloom gedare at rtems.org
Sat May 21 13:07:03 UTC 2016


On Sat, May 21, 2016 at 6:54 AM,  <ppisa4lists at pikron.com> wrote:
> From: YANG Qiao <yangqiao0505 at me.com>
>
> ---
>  c/src/lib/libbsp/arm/raspberrypi/Makefile.am       |   4 +-
>  .../arm/raspberrypi/console/console-config.c       |  12 +-
>  .../arm/raspberrypi/console/console_select.c       | 114 +++++++++++++
>  c/src/lib/libbsp/arm/raspberrypi/console/fbcons.c  | 184 +++++++++++++++++++++
>  c/src/lib/libbsp/arm/raspberrypi/console/fbcons.h  |  47 ++++++
>  c/src/lib/libbsp/arm/raspberrypi/include/bsp.h     |   3 +
>  c/src/lib/libbsp/arm/raspberrypi/preinstall.am     |   4 +
>  .../libbsp/arm/raspberrypi/startup/bspstarthooks.c |   4 +
>  8 files changed, 370 insertions(+), 2 deletions(-)
>  create mode 100644 c/src/lib/libbsp/arm/raspberrypi/console/console_select.c
>  create mode 100644 c/src/lib/libbsp/arm/raspberrypi/console/fbcons.c
>  create mode 100644 c/src/lib/libbsp/arm/raspberrypi/console/fbcons.h
>
> diff --git a/c/src/lib/libbsp/arm/raspberrypi/Makefile.am b/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
> index f5b87ab..e115745 100644
> --- a/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
> +++ b/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
> @@ -53,6 +53,7 @@ include_bsp_HEADERS += include/spi.h
>  include_bsp_HEADERS += include/mailbox.h
>  include_bsp_HEADERS += include/vc.h
>  include_bsp_HEADERS += include/rpi-fb.h
> +include_bsp_HEADERS += console/fbcons.h
>
>  include_libcpu_HEADERS = ../../../libcpu/arm/shared/include/cache_.h \
>      ../../../libcpu/arm/shared/include/arm-cp15.h
> @@ -113,11 +114,12 @@ libbsp_a_SOURCES += irq/irq.c
>  libbsp_a_SOURCES += ../../shared/console.c
>  libbsp_a_SOURCES += ../../shared/console_control.c
>  libbsp_a_SOURCES += ../../shared/console_read.c
> -libbsp_a_SOURCES += ../../shared/console_select.c
>  libbsp_a_SOURCES += ../../shared/console_write.c
>  libbsp_a_SOURCES += console/console-config.c
> +libbsp_a_SOURCES += console/console_select.c
>  libbsp_a_SOURCES += console/usart.c
>  libbsp_a_SOURCES += console/fb.c
> +libbsp_a_SOURCES += console/fbcons.c
>  libbsp_a_SOURCES += console/outch.c
>
>  # Mailbox
> diff --git a/c/src/lib/libbsp/arm/raspberrypi/console/console-config.c b/c/src/lib/libbsp/arm/raspberrypi/console/console-config.c
> index b948b77..dfb9826 100644
> --- a/c/src/lib/libbsp/arm/raspberrypi/console/console-config.c
> +++ b/c/src/lib/libbsp/arm/raspberrypi/console/console-config.c
> @@ -7,6 +7,8 @@
>   */
>
>  /*
> + * Copyright (c) 2015 Yang Qiao
> + * based on work by:
>   * Copyright (c) 2013 Alan Cudmore
>   *
>   *  The license and distribution terms for this file may be
> @@ -24,6 +26,7 @@
>  #include <bsp/irq.h>
>  #include <bsp/usart.h>
>  #include <bsp/raspberrypi.h>
> +#include <bsp/fbcons.h>
>
>  console_tbl Console_Configuration_Ports [] = {
>      {
> @@ -36,7 +39,14 @@ console_tbl Console_Configuration_Ports [] = {
>        .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,
> +    },
>  };
>
>  #define PORT_COUNT \
> diff --git a/c/src/lib/libbsp/arm/raspberrypi/console/console_select.c b/c/src/lib/libbsp/arm/raspberrypi/console/console_select.c
> new file mode 100644
> index 0000000..2b5d872
> --- /dev/null
> +++ b/c/src/lib/libbsp/arm/raspberrypi/console/console_select.c
> @@ -0,0 +1,114 @@
> +/**
> + * @file
> + *
> + * @ingroup raspberrypi_console
> + *
> + * @brief console select
> + */
> +
> +/*
> + * Copyright (c) 2015 Yang Qiao
> + *
> + *  The license and distribution terms for this file may be
> + *  found in the file LICENSE in this distribution or at
> + *
> + *  http://www.rtems.org/license/LICENSE
> + *
> + */
> +
> +#include <bsp.h>
> +#include <bsp/fatal.h>
> +#include <rtems/libio.h>
> +#include <stdlib.h>
> +#include <assert.h>
> +#include <termios.h>
> +
> +#include <rtems/termiostypes.h>
> +#include <libchip/serial.h>
> +#include "../../../shared/console_private.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);
> +}
> +
> +void bsp_console_select(void)
> +{
> +
> +  /*
> +   *  Reset Console_Port_Minor and
> +   *  BSPPrintkPort here if desired.
> +   *
> +   *  This default version allows the bsp to set these
> +   *  values at creation and will not touch them again
> +   *  unless the selected port number is not available.
> +   */
> +  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;
> +      }
> +    }
> +  }
> +
> +  /*
> +   * 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/c/src/lib/libbsp/arm/raspberrypi/console/fbcons.c b/c/src/lib/libbsp/arm/raspberrypi/console/fbcons.c
> new file mode 100644
> index 0000000..e69ea82
> --- /dev/null
> +++ b/c/src/lib/libbsp/arm/raspberrypi/console/fbcons.c
> @@ -0,0 +1,184 @@
> +/**
> + * @file
> + *
> + * @ingroup raspberrypi_console
> + *
> + * @brief framebuffer graphic console support.
> + */
> +
> +/*
> + * Copyright (c) 2015 Yang Qiao
> + *
> + *  The license and distribution terms for this file may be
> + *  found in the file LICENSE in this distribution or at
> + *
> + *  http://www.rtems.org/license/LICENSE
> + *
> + */
> +
> +#include <rtems.h>
> +#include <rtems/libio.h>
> +
> +#include <stdlib.h>
> +
> +#include <libchip/serial.h>
> +#include <libchip/sersupp.h>
> +
> +#include <bsp.h>
> +#include <bsp/fbcons.h>
> +#include <bsp/vc.h>
> +
> +/*
> + *  fbcons_init
> + *
> + *  This function initializes the fb console to a quiecsent state.
> + */
> +static void fbcons_init(int minor)
> +{
> +}
> +
> +/*
> + *  fbcons_open
> + *
> + *  This function opens a port for communication.
> + *
> + *  Default state is 9600 baud, 8 bits, No parity, and 1 stop bit.
> + */
> +static int fbcons_open(
> +  int      major,
> +  int      minor,
> +  void    *arg
> +)
> +{
> +  return RTEMS_SUCCESSFUL;
> +}
> +
> +/*
> + *  fbcons_close
> + *
> + *  This function shuts down the requested port.
> + */
> +static int fbcons_close(
> +  int      major,
> +  int      minor,
> +  void    *arg
> +)
> +{
> +  return(RTEMS_SUCCESSFUL);
> +}
> +
> +/*
> + *  fbcons_write_polled
> + *
> + *  This routine polls out the requested character.
> + */
> +static void fbcons_write_polled(
> +  int   minor,
> +  char  c
> +)
> +{
> +  rpi_fb_outch( c );
> +  if( c == '\n')
> +    rpi_fb_outch( '\r' );            /* LF = LF + CR */
> +}
> +
> +/*
> + *  fbcons_write_support_polled
> + *
> + *  Console Termios output entry point when using polled output.
> + *
> + */
> +static ssize_t fbcons_write_support_polled(
> +  int         minor,
> +  const char *buf,
> +  size_t      len
> +)
> +{
> +  int nwrite = 0;
> +
> +  /*
> +   * poll each byte in the string out of the port.
> +   */
> +  while (nwrite < len) {
> +    fbcons_write_polled(minor, *buf++);
> +    nwrite++;
> +  }
> +
> +  /*
> +   * return the number of bytes written.
> +   */
> +  return nwrite;
> +}
> +
> +/*
> + *  fbcons_inbyte_nonblocking_polled
> + *
> + *  Console Termios polling input entry point.
> + */
> +static int fbcons_inbyte_nonblocking_polled(
> +  int minor
> +)
> +{
> +  // if( rtems_kbpoll() ) {
> +  //   int c = getch();
> +  //   return c;
> +  // }
delete unused code

> +
> +  return -1;
> +}
> +
> +/*
> + *  fbcons_set_attributes
> + *
> + *  This function sets the UART channel to reflect the requested termios
> + *  port settings.
> + */
> +static int fbcons_set_attributes(
> +  int minor,
> +  const struct termios *t
> +)
> +{
> +  return 0;
> +}
> +
> +bool fbcons_probe(
> +  int minor
> +)
> +{
> +  // rtems_status_code status;
delete unused code

> +  static bool firstTime = true;
> +  static bool ret = false;
> +
> +  /*
> +   *  keyboard interrupt should be registered when the keyboard is available
> +   */
> +  if ( firstTime )
> +  {
> +    bcm2835_get_display_size_entries entries;
> +    bcm2835_mailbox_get_display_size(&entries);
> +    if(entries.width == 0x290 && entries.height ==0x1A0 )
> +    {
Again with style, but also these hard-coded constants need some
explanation. I don't remember the problem being worked around here
exactly.

> +      ret = false;
> +    }
> +    else
> +    {
> +      ret = true;
> +    }
> +  }
> +  firstTime = false;
> +
> +  return ret;
> +}
> +
> +const console_fns 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*/
> +};
> diff --git a/c/src/lib/libbsp/arm/raspberrypi/console/fbcons.h b/c/src/lib/libbsp/arm/raspberrypi/console/fbcons.h
> new file mode 100644
> index 0000000..f6ce9c4
> --- /dev/null
> +++ b/c/src/lib/libbsp/arm/raspberrypi/console/fbcons.h
> @@ -0,0 +1,47 @@
> +/**
> + * @file
> + *
> + * @ingroup raspberrypi_console
> + *
> + * @brief framebuffer graphic console support.
> + */
> +
> +/*
> + * Copyright (c) 2015 Yang Qiao
> + *
> + *  The license and distribution terms for this file may be
> + *  found in the file LICENSE in this distribution or at
> + *
> + *  http://www.rtems.org/license/LICENSE
> + *
> + */
> +
> +#ifndef _FBCONS_H_
> +#define _FBCONS_H_
> +
> +#include <libchip/serial.h>
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +/*
> + *  This is the ASCII for "PI" in the upper word and 2835
> + *  in the lower which should be unique enough to
> + *  distinguish this type of serial device from others.
> + */
> +
> +#define FB_CONSOLE    0x50492835
> +
> +bool fbcons_probe( int minor );
> +
> +/*
> + * Driver function table
> + */
> +extern const console_fns fbcons_fns;
> +
> +#ifdef __cplusplus
> +}
> +#endif
> +
> +#endif /* _FBCONS_H_ */
> diff --git a/c/src/lib/libbsp/arm/raspberrypi/include/bsp.h b/c/src/lib/libbsp/arm/raspberrypi/include/bsp.h
> index 67df810..5241979 100644
> --- a/c/src/lib/libbsp/arm/raspberrypi/include/bsp.h
> +++ b/c/src/lib/libbsp/arm/raspberrypi/include/bsp.h
> @@ -38,6 +38,9 @@ extern "C" {
>  #define BSP_GPIO_PINS_PER_BANK 32
>  #define BSP_GPIO_PINS_PER_SELECT_BANK 10
>
> +#define BSP_CONSOLE_UART0   0
> +#define BSP_CONSOLE_FB      1
> +
>  void rpi_init_cmdline(void);
>  const char *rpi_cmdline_get_cached(void);
>  const char *rpi_cmdline_get_raw(void);
> diff --git a/c/src/lib/libbsp/arm/raspberrypi/preinstall.am b/c/src/lib/libbsp/arm/raspberrypi/preinstall.am
> index cbfa79f..e6f0ca0 100644
> --- a/c/src/lib/libbsp/arm/raspberrypi/preinstall.am
> +++ b/c/src/lib/libbsp/arm/raspberrypi/preinstall.am
> @@ -158,6 +158,10 @@ $(PROJECT_INCLUDE)/bsp/rpi-fb.h: include/rpi-fb.h $(PROJECT_INCLUDE)/bsp/$(dirst
>         $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/rpi-fb.h
>  PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/rpi-fb.h
>
> +$(PROJECT_INCLUDE)/bsp/fbcons.h: console/fbcons.h $(PROJECT_INCLUDE)/bsp/$(dirstamp)
> +       $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/fbcons.h
> +PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/fbcons.h
> +
>  $(PROJECT_INCLUDE)/libcpu/cache_.h: ../../../libcpu/arm/shared/include/cache_.h $(PROJECT_INCLUDE)/libcpu/$(dirstamp)
>         $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/libcpu/cache_.h
>  PREINSTALL_FILES += $(PROJECT_INCLUDE)/libcpu/cache_.h
> diff --git a/c/src/lib/libbsp/arm/raspberrypi/startup/bspstarthooks.c b/c/src/lib/libbsp/arm/raspberrypi/startup/bspstarthooks.c
> index d44be03..0a90e7a 100644
> --- a/c/src/lib/libbsp/arm/raspberrypi/startup/bspstarthooks.c
> +++ b/c/src/lib/libbsp/arm/raspberrypi/startup/bspstarthooks.c
> @@ -27,6 +27,8 @@
>  #include <bsp/raspberrypi.h>
>  #include <bsp/mm.h>
>  #include <libcpu/arm-cp15.h>
> +#include <bsp.h>
> +
>
>  void BSP_START_TEXT_SECTION bsp_start_hook_0(void)
>  {
> @@ -71,4 +73,6 @@ void BSP_START_TEXT_SECTION bsp_start_hook_1(void)
>    bsp_start_copy_sections();
>    bsp_memory_management_initialize();
>    bsp_start_clear_bss();
> +
> +  rpi_video_init();
>  }
> --
> 1.9.1
>



More information about the devel mailing list