[PATCH v2] Raspberrypi: updated the console interface.
Niteesh
gsnb.gn at gmail.com
Sun Dec 29 06:09:23 UTC 2019
Is there any way to test and debug this? Maybe using GDB to
see if a proper node is getting selected or not?
My plan is to remove console_select.c and usart.c files. And do all of the
initialization in
the console-config.c. I looked at some of the device files from FreeBSD,
the address for the
peripheral's are the virtual address or the bus address, so I will convert
them to arm physical
addresses, using a macro, which subtracts an offset to get the physical
address.
For finding the UART ports, we could traverse through the alias node. For
rpi1 and rpi2 there should be just one(uart0), but
for newer models, there would two (uart0 and uart1). And then read the
stdout-path to find the serial that has to be used.
And in console_initialize function, we should also parse the cmdline to
find if FB is to be used. And link the appropriate
driver to /dev/console. But how to handle the different types of device
instances? for all the bsp's that I used as reference,
all the uart devices were of same type, but here we have 3 different serial
devices.
My idea is manually intialize the devices, that is to traverse the alias
node, and intialize uart0 to pl011 and uart1 to aux if
it is available. and then seperately intialize the FB, Is there any better
way to do it?
On Sun, Dec 29, 2019 at 2:11 AM Christian Mauderer <list at c-mauderer.de>
wrote:
> On 28/12/2019 20:03, Niteesh wrote:
> > I will start working on a patch that uses FDT. Instead of merging this
> > I create a patch v3 that uses FDT. Shall I remove some files, I will be
> > heavily using
> > the imx and other FDT based drivers as a reference.
>
> You can remove everything that is no longer used. I expect that it will
> be mainly the files containing the table based selection and console
> selection code.
>
> >
> > On Sun, Dec 29, 2019 at 12:27 AM Christian Mauderer <list at c-mauderer.de
> > <mailto:list at c-mauderer.de>> wrote:
> >
> > On 28/12/2019 19:48, Niteesh wrote:
> > > Is bsp_console_select legacy? And the new way will be by linking
> > > the correct serial device to /dev/console in
> > console_initialization, right?
> > > If so, shall I add one?
> >
> > The function is only called from legacy-console.c. So yes: This
> function
> > can be removed. The logic on the other hand should move to somewhere
> > else.
> >
> > The console-termios-init.c creates a link named CONSOLE_DEVICE_NAME.
> So
> > you can't use that code and create your link manually. If you use the
> > table based approach (which is OK as a first step) you can't really
> > select the console.
> >
> > I would suggest to either clean that patch up so it can be merged and
> > move to a fdt based approach simmilar to imx in a second patch. In
> that
> > case the console_initialize() function from console-termios-init.c
> will
> > be replaced by a custom function that searches the FDT for the
> devices.
> > The FDT will make it simpler to adapt to RPi3. Or if you prefere it
> you
> > can do that right now and create a patch v3 that directly uses FDT.
> >
> > >
> > > On Sat, Dec 28, 2019 at 11:50 PM Niteesh <gsnb.gn at gmail.com
> > <mailto:gsnb.gn at gmail.com>
> > > <mailto:gsnb.gn at gmail.com <mailto:gsnb.gn at gmail.com>>> wrote:
> > >
> > > I am sorry if this question sounds silly, but how can I access
> the
> > > output_char_fb if it
> > > is marked as static in console-select.c, currently the fb
> > context is
> > > in console-config.c
> > > Should I move the BSP_select_function to console-config? for
> > shall I
> > > remove the static qualifier
> > > from the function?
> > >
> > > Currently, the console_select has 2 functions,
> > bsp_Is_Available and
> > > bsp_console_select.
> > >
> > > On Sat, Dec 28, 2019 at 11:30 PM Niteesh <gsnb.gn at gmail.com
> > <mailto:gsnb.gn at gmail.com>
> > > <mailto:gsnb.gn at gmail.com <mailto:gsnb.gn at gmail.com>>> wrote:
> > >
> > > On Sat, Dec 28, 2019 at 11:12 PM 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:
> > >
> > > On 28/12/2019 17:22, Niteesh wrote:
> > > > I think you misunderstood, I was talking about the
> > casting
> > > in the
> > > > rtems_termios_device_handler
> > >
> > > Yes, I misunderstood you there.
> > >
> > > > const rtems_termios_device_handler fbcons_fns =
> > > > {
> > > > .first_open = fbcons_open,
> > > > .last_close = fbcons_close,
> > > > .poll_read = fbcons_inbyte_nonblocking_polled,
> > > > .write = (void (*)(rtems_termios_device_context *,
> > const
> > > char *,
> > > > size_t))fbcons_write_support_polled,
> > > > .set_attributes = fbcons_set_attributes,
> > > > .mode = TERMIOS_POLLED
> > > > };
> > > >
> > > > the write requires a function type of
> > > > *void (*write)(
> > > > rtems_termios_device_context *context,
> > > > const char *buf,
> > > > size_t len
> > > > );*
> > > >
> > > > but the fbcons function is of type
> > > > *static ssize_t fbcons_write_support_polled(
> > > > rtems_termios_device_context *base,
> > > > const char *buf,
> > > > size_t len
> > > > )*
> > > >
> > > > Well, if the above cast in the device handler causes
> a
> > > problem, can you
> > > > elaborate more on
> > > > what kind of a problem would it be?
> > >
> > > In that case it should work. But why do you need to
> > cast it
> > > there?
> > > Wouldn't it be simpler to just change the
> > > fbcons_write_support_polled
> > > function? It isn't used anywhere else or did I miss
> > something?
> > >
> > > No, it is not used anywhere. I'll change the function.
> > >
> > > >
> > > > And for the BSP_output_char function, I used a
> function
> > > pointer. The
> > > > console_select assigns the
> > > > appropriate function to the function pointer and the
> > > output_char call's
> > > > it by providing the context.
> > > > static void output_char(char c)
> > > > {
> > > > const console_device *dev =
> > > &console_device_table[console_select];
> > > > rtems_termios_device_context *con = dev->context;
> > > > console_instance(con, c);
> > > > }
> > > > console_instance is the function pointer, which is
> > assigned to
> > > > arm_pl011_write_polled by
> > > > default, or to fbcons_write_polled, if frame buffer
> is
> > > decided to be used.
> > >
> > >
> > > Yes it will work and it's resonable performant. We are
> > > talking about a
> > > slow serial interface in an exception case. But anyway
> I'm
> > > not entirely
> > > happy.
> > >
> > > The compiler should make something like the following
> > out of it:
> > >
> > > - Look up and call the value of BSP_output_char
> > > - Load the context (start of table + console_select +
> > fixed
> > > offset) into
> > > "con"
> > > - Look up and call the value of console_instance
> > >
> > > If you use the way I suggested below you will have
> > about the
> > > following:
> > >
> > > - Look up and call the value of BSP_output_char (one
> > of the
> > > wrappers)
> > > - Call the right function with a fixed parameter
> > >
> > > So it's a bit shorter and beneath that you save a
> global
> > > variable.
> > >
> > > Sure, will change it.
> > >
> > > >
> > > > On Sat, Dec 28, 2019 at 8:50 PM 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>>
> > > > <mailto:list at c-mauderer.de
> > <mailto:list at c-mauderer.de> <mailto:list at c-mauderer.de
> > <mailto:list at c-mauderer.de>>>>
> > > wrote:
> > > >
> > > > On 28/12/2019 14:10, 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 function's signatures
> where
> > > also changed
> > > > > to accommodate with interface update.
> > > > > Update #3034
> > > > > ---
> > > > > bsps/arm/raspberrypi/console/console-config.c
> > | 62
> > > ++++----
> > > > > bsps/arm/raspberrypi/console/console_select.c
> > | 68
> > > ++-------
> > > > > bsps/arm/raspberrypi/console/fbcons.c
> > | 71
> > > ++++-----
> > > > > bsps/arm/raspberrypi/console/usart.c
> > | 142
> > > > ------------------
> > > > > bsps/arm/raspberrypi/include/bsp/fbcons.h
> > | 19 ++-
> > > > > .../arm/raspberrypi/include/bsp/raspberrypi.h
> > | 70
> > > +++++----
> > > > > bsps/arm/raspberrypi/include/bsp/usart.h
> > | 5 +-
> > > > > c/src/lib/libbsp/arm/raspberrypi/Makefile.am
> > | 5 +-
> > > > > 8 files changed, 136 insertions(+), 306
> > deletions(-)
> > > > >
> > > > > diff --git
> > > a/bsps/arm/raspberrypi/console/console-config.c
> > > > b/bsps/arm/raspberrypi/console/console-config.c
> > > > > index d2186c918b..f479e19d99 100644
> > > > > ---
> > a/bsps/arm/raspberrypi/console/console-config.c
> > > > > +++
> > b/bsps/arm/raspberrypi/console/console-config.c
> > > > > @@ -22,45 +22,47 @@
> > > > >
> > > > > #include <libchip/serial.h>
> > > > >
> > > > > -#include <bspopts.h>
> > > > > -#include <bsp/irq.h>
> > > > > -#include <bsp/usart.h>
> > > > > +#include <bsp.h>
> > > > > #include <bsp/raspberrypi.h>
> > > > > +#include <bsp/usart.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")
> > > > > +};
> > > > > +
> > > > > +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",
> > > > > + .probe = fbcons_probe,
> > > > > + .handler = &fbcons_fns,
> > > > > + .context = &fb_context.base
> > > > > + }
> > > > > +};
> > > > >
> > > > > -unsigned long Console_Configuration_Count =
> > PORT_COUNT;
> > > > > +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);
> > > > > + const console_device *dev =
> > > &console_device_table[console_select];
> > > > > + rtems_termios_device_context *con =
> > dev->context;
> > > > > + console_instance(con, c);
> > > > > }
> > > >
> > > > I'm still not happy with that. What I had in
> > mind was
> > > more or less:
> > > >
> > > >
> > > > static void output_char_serial(char c)
> > > > {
> > > > arm_pl011_write_polled(&pl011_context.base, c);
> > > > }
> > > >
> > > > static void output_char_fb(char c)
> > > > {
> > > > fbcons_write_polled(&fb_context.base, c);
> > > > }
> > > >
> > > > BSP_output_char_function_type BSP_output_char =
> > > output_char_serial;
> > > >
> > > >
> > > > And if you decide that the frame buffer should
> > be used
> > > in the select
> > > > function you do a
> > > >
> > > > BSP_output_char = output_char_fb;
> > > >
> > > > >
> > > > > 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..ea3325266f 100644
> > > > > ---
> > a/bsps/arm/raspberrypi/console/console_select.c
> > > > > +++
> > b/bsps/arm/raspberrypi/console/console_select.c
> > > > > @@ -15,69 +15,40 @@
> > > > > * http://www.rtems.org/license/LICENSE
> > > > > *
> > > > > */
> > > > > -
> > > > > #include <bsp.h>
> > > > > +#include <bsp/raspberrypi.h>
> > > > > +#include <bsp/arm-pl011.h>
> > > > > +#include <bsp/fbcons.h>
> > > > > +#include <bsp/rpi-fb.h>
> > > > > #include <bsp/fatal.h>
> > > > > +#include <bsp/console-termios.h>
> > > > > +
> > > > > #include <rtems/libio.h>
> > > > > #include <stdlib.h>
> > > > > #include <string.h>
> > > > > #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;
> > > > > +int console_select = PL011;
> > > > > +console console_instance =
> > arm_pl011_write_polled;
> > > > >
> > > > > -/*
> > > > > - * Method to return true if the device
> associated
> > > with the
> > > > > - * minor number probs available.
> > > > > - */
> > > > > -static bool bsp_Is_Available(
> > > rtems_device_minor_number minor )
> > > > > +static bool bsp_Is_Available( int index )
> > > > > {
> > > > > - console_tbl *cptr = Console_Port_Tbl[ minor
> ];
> > > > > -
> > > > > + const console_device *dev =
> > > &console_device_table[index];
> > > > > + rtems_termios_device_context *con =
> > dev->context;
> > > > > /*
> > > > > * First perform the configuration dependent
> > > probe, then the
> > > > > * device dependent probe
> > > > > */
> > > > > - if ( ( !cptr->deviceProbe ||
> cptr->deviceProbe(
> > > minor ) ) &&
> > > > > - cptr->pDeviceFns->deviceProbe( minor )
> ) {
> > > > > + if ( ( !dev->probe || dev->probe( con ) ) ){
> > > > > 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 )
> > > > > {
> > > > > /*
> > > > > @@ -90,25 +61,18 @@ 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;
> > > > > + console_select = FB;
> > > > > + console_instance =
> fbcons_write_polled;
> > > > > }
> > > > > }
> > > > > }
> > > > >
> > > > > - /*
> > > > > - * 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();
> > > > > + if( !bsp_Is_Available( console_select ) ){
> > > > > + bsp_fatal( BSP_FATAL_CONSOLE_NO_DEV );
> > > > > }
> > > > > }
> > > > > diff --git
> a/bsps/arm/raspberrypi/console/fbcons.c
> > > > b/bsps/arm/raspberrypi/console/fbcons.c
> > > > > index 3669ba458d..6e710e252d 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>
> > > > >
> > > > > @@ -29,15 +30,6 @@
> > > > > #include <bsp/vc.h>
> > > > > #include <bsp/rpi-fb.h>
> > > > >
> > > > > -/*
> > > > > - * fbcons_init
> > > > > - *
> > > > > - * This function initializes the fb console
> to a
> > > quiecsent state.
> > > > > - */
> > > > > -static void fbcons_init( int minor )
> > > > > -{
> > > > > -}
> > > > > -
> > > > > /*
> > > > > * fbcons_open
> > > > > *
> > > > > @@ -45,13 +37,14 @@ 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
> > > > > +static bool fbcons_open(
> > > > > + struct rtems_termios_tty *tty,
> > > > > + rtems_termios_device_context *base,
> > > > > + struct termios *term,
> > > > > + rtems_libio_open_close_args_t *args
> > > > > )
> > > > > {
> > > > > - return RTEMS_SUCCESSFUL;
> > > > > + return true;
> > > > > }
> > > > >
> > > > > /*
> > > > > @@ -59,13 +52,12 @@ static int fbcons_open(
> > > > > *
> > > > > * This function shuts down the requested
> port.
> > > > > */
> > > > > -static int fbcons_close(
> > > > > - int major,
> > > > > - int minor,
> > > > > - void *arg
> > > > > +static void fbcons_close(
> > > > > + struct rtems_termios_tty *tty,
> > > > > + rtems_termios_device_context *base,
> > > > > + rtems_libio_open_close_args_t *args
> > > > > )
> > > > > {
> > > > > - return ( RTEMS_SUCCESSFUL );
> > > > > }
> > > > >
> > > > > /*
> > > > > @@ -73,8 +65,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 +83,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 +94,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 +109,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();
> > > > > @@ -133,15 +127,17 @@ static int
> > > fbcons_inbyte_nonblocking_polled(
> > > > int minor )
> > > > > * This function sets the UART channel to
> > reflect
> > > the requested
> > > > termios
> > > > > * port settings.
> > > > > */
> > > > > -static int fbcons_set_attributes(
> > > > > - int minor,
> > > > > +static bool fbcons_set_attributes(
> > > > > + rtems_termios_device_context *base,
> > > > > const struct termios *t
> > > > > )
> > > > > {
> > > > > - return 0;
> > > > > + return true;
> > > > > }
> > > > >
> > > > > -bool fbcons_probe( int minor )
> > > > > +bool fbcons_probe(
> > > > > + rtems_termios_device_context *context
> > > > > +)
> > > > > {
> > > > > // rtems_status_code status;
> > > > > static bool firstTime = true;
> > > > > @@ -163,15 +159,12 @@ 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 = (void
> (*)(rtems_termios_device_context
> > > *, const char
> > > > *, size_t))fbcons_write_support_polled,
> > > > > + .set_attributes = fbcons_set_attributes,
> > > > > + .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..e3d9e69ff5 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..2ccc49846c 100644
> > > > > ---
> > a/bsps/arm/raspberrypi/include/bsp/raspberrypi.h
> > > > > +++
> > b/bsps/arm/raspberrypi/include/bsp/raspberrypi.h
> > > > > @@ -24,6 +24,7 @@
> > > > > #include <bspopts.h>
> > > > > #include <stdint.h>
> > > > > #include <bsp/utility.h>
> > > > > +#include <rtems/termiostypes.h>
> > > > >
> > > > > /**
> > > > > * @defgroup raspberrypi_reg Register
> Definitions
> > > > > @@ -60,6 +61,39 @@
> > > > >
> > > > > #define RPI_PERIPHERAL_SIZE 0x01000000
> > > > >
> > > > > +/**
> > > > > + * @name Console select definitions
> > > > > + *
> > > > > + * @{
> > > > > + */
> > > > > +
> > > > > +#define PL011 0
> > > > > +#define FB 1
> > > > > +
> > > > > +/** @} */
> > > > > +
> > > > > +/**
> > > > > + * @name Console select
> > > > > + *
> > > > > + * @{
> > > > > + */
> > > > > +
> > > > > +extern int console_select;
> > > > > +
> > > > > +/** @} */
> > > > > +
> > > > > +/**
> > > > > + * @name Console select
> > > > > + *
> > > > > + * @{
> > > > > + */
> > > > > +
> > > > > +typedef void
> > > (*console)(rtems_termios_device_context *, char c);
> > > > > +extern console console_instance;
> > > > > +
> > > > > +/** @} */
> > > > > +
> > > > > +/** @} */
> > > > > /**
> > > > > * @name Internal ARM Timer Registers
> > > > > *
> > > > > @@ -184,42 +218,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
> > > > >
> > > >
> > >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20191229/389b24f3/attachment-0001.html>
More information about the devel
mailing list