[PATCH] [RPI BSP] mailbox

QIAO YANG yangqiao0505 at me.com
Fri Apr 24 21:40:52 UTC 2015


On Apr 23, 2015, at 10:20 AM, Alan Cudmore <alan.cudmore at gmail.com> wrote:

> Hi Qiao,
> Functionally, this code looks good to me. It builds without warnings for the Pi and Pi2, and I was able to make the calls to init the frame buffer on the Pi B+. 
>
> When you did the frame buffer test, what was your MMU table entry for the mailbox/framebuffer?
 
In fact, I've got questions with the MMU table set up. It seems that the memory is enabled by page because I've found that I can also access to the address out of the range that I've set up.

Here is what I've added.

{
    .begin = 0xC11F4C8,
    .end =   0xC11F4C8 + 0x1000,
    .flags = ARMV7_MMU_DATA_READ_WRITE
  }

The fb buffer in my case appears to around 0xC11F4C8,  and the size is not the actual size. But it works. I know it's not proper, I just use this for tests.

If we've enabled l2 cache, the memory mapping would be 0x40000000, while the mapping would be 0xC0000000 instead if l2 cache disabled. Normally it can be configured in the config.txt file. What do you think is a better way to find it out whether l2 cache is enabled in order to use the proper mapping?

I've read through the video core processor's available properties settings.
Here's what we can use for framebuffer:

allocate/release buffer
set blank screen
get/set/test display size
get/set/test buffer size
get/set/test depth
get/set/test pixel order
get/set/test alpha mode
get pitch
get/set/test virtual offset
get/set/test overscan
get/set/test palette
set cursor info
set cursor state

As I've already got a fb_init which works and we can get the pointer with ioctrl correctly and draw something,  what else should be implemented for fb?  The other bsps' palettes are hard coded, I wonder if I should also setup the palette and allow users to adjust it by ioctrl. What about other properties? I'm not sure where to go from here.

I tried to compile gtk for it. The libpng etc can be installed and I'm working on some samples to test them. Only the nxlib failed because we haven't yet the keyboard support (mouse support can be switch off, but I can't find out how to build the lib without keyboard).
>
> Thanks,
> Alan
>
>
>> On Apr 19, 2015, at 3:17 PM, QIAO YANG <yangqiao0505 at me.com> wrote:
>>
>> Here is a modified patch for mailbox.  If there's still anything against the convention, please point it out and I'll correct it immediately. The mailbox implementation might also be needed by other rpi bsp developpers.
>>
>> ----------------------
>>
>> diff --git a/c/src/lib/libbsp/arm/raspberrypi/Makefile.am b/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
>> index c6133df..70bc01d 100644
>> --- a/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
>> +++ b/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
>> @@ -43,6 +43,7 @@ include_bsp_HEADERS += ../shared/include/arm-release-id.h
>>  include_bsp_HEADERS += include/irq.h
>>  include_bsp_HEADERS += include/mmu.h
>>  include_bsp_HEADERS += include/usart.h
>> +include_bsp_HEADERS += include/mailbox.h
>>  include_bsp_HEADERS += include/raspberrypi.h
>>  
>>  include_libcpu_HEADERS = ../../../libcpu/arm/shared/include/cache_.h \
>> @@ -123,6 +124,9 @@ libbsp_a_SOURCES += misc/timer.c
>>  
>>  # I2C
>>  
>> +# Mailbox
>> +libbsp_a_SOURCES += misc/mailbox.c
>> +
>>  # Cache
>>  libbsp_a_SOURCES += ../../../libcpu/shared/src/cache_manager.c
>>  libbsp_a_SOURCES += ../../../libcpu/arm/shared/include/cache_.h
>> diff --git a/c/src/lib/libbsp/arm/raspberrypi/include/mailbox.h b/c/src/lib/libbsp/arm/raspberrypi/include/mailbox.h
>> new file mode 100644
>> index 0000000..fa6a0c2
>> --- /dev/null
>> +++ b/c/src/lib/libbsp/arm/raspberrypi/include/mailbox.h
>> @@ -0,0 +1,33 @@
>> +/**
>> + * @file
>> + *
>> + * @ingroup raspberrypi
>> + *
>> + * @brief mailbox 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 LIBBSP_ARM_RASPBERRYPI_MAILBOX_H
>> +#define LIBBSP_ARM_RASPBERRYPI_MAILBOX_H
>> +
>> +#ifdef __cplusplus
>> +extern "C" {
>> +#endif /* __cplusplus */
>> +
>> +extern unsigned int  raspberrypi_mailbox_read(unsigned int channel);
>> +extern void raspberrypi_mailbox_write(unsigned int channel, unsigned int data);
>> +
>> +#ifdef __cplusplus
>> +}
>> +#endif /* __cplusplus */
>> +
>> +#endif  /* LIBBSP_ARM_RASPBERRYPI_MAILBOX_H */
>> diff --git a/c/src/lib/libbsp/arm/raspberrypi/include/raspberrypi.h b/c/src/lib/libbsp/arm/raspberrypi/include/raspberrypi.h
>> index c33e22a..3240404 100644
>> --- a/c/src/lib/libbsp/arm/raspberrypi/include/raspberrypi.h
>> +++ b/c/src/lib/libbsp/arm/raspberrypi/include/raspberrypi.h
>> @@ -208,6 +208,55 @@
>>  
>>  /** @} */
>>  
>> + /**
>> + * @name Mailbox Registers
>> + *
>> + * @{
>> + */
>> +
>> +#define BCM2835_MBOX_BASE (RPI_PERIPHERAL_BASE+0xB880)
>> +
>> +#define BCM2835_MBOX_PEEK (BCM2835_MBOX_BASE+0x10)
>> +#define BCM2835_MBOX_READ (BCM2835_MBOX_BASE+0x00)
>> +#define BCM2835_MBOX_WRITE (BCM2835_MBOX_BASE+0x20)
>> +#define BCM2835_MBOX_STATUS (BCM2835_MBOX_BASE+0x18)
>> +#define BCM2835_MBOX_SENDER (BCM2835_MBOX_BASE+0x14)
>> +#define BCM2835_MBOX_CONFIG (BCM2835_MBOX_BASE+0x1C)
>> +
>> +#define BCM2835_MBOX_SUCCESS (BCM2835_MBOX_BASE+0x80000000)
>> +#define BCM2835_MBOX_FULL (BCM2835_MBOX_BASE+0x80000000)
>> +#define BCM2835_MBOX_EMPTY (BCM2835_MBOX_BASE+0x40000000)
>> +
>> +/**
>> +* @name Mailbox Channels
>> +*
>> +* @{
>> +*/
>> +
>> +/* Power Manager channel */
>> +#define BCM2835_MBOX_CHANNEL_PM         0
>> +/* Framebuffer channel */
>> +#define BCM2835_MBOX_CHANNEL_FB         1
>> + /* Virtual UART channel */
>> +#define BCM2835_MBOX_CHANNEL_VUART      2
>> + /* VCHIQ channel */
>> +#define BCM2835_MBOX_CHANNEL_VCHIQ      3
>> + /* LEDs channel */
>> +#define BCM2835_MBOX_CHANNEL_LED        4
>> + /* Button channel */
>> +#define BCM2835_MBOX_CHANNEL_BUTTON     5
>> + /* Touch screen channel */
>> +#define BCM2835_MBOX_CHANNEL_TOUCHS     6
>> +/* Property tags (ARM <-> VC) channel */
>> +#define BCM2835_MBOX_CHANNEL_PROP_AVC   8
>> + /* Property tags (VC <-> ARM) channel */
>> +#define BCM2835_MBOX_CHANNEL_PROP_VCA   9
>> +
>> +/** @} */
>> +
>> +
>> +/** @} */
>> +
>>  
>>  /** @} */
>>  
>> diff --git a/c/src/lib/libbsp/arm/raspberrypi/misc/mailbox.c b/c/src/lib/libbsp/arm/raspberrypi/misc/mailbox.c
>> new file mode 100644
>> index 0000000..2a63a41
>> --- /dev/null
>> +++ b/c/src/lib/libbsp/arm/raspberrypi/misc/mailbox.c
>> @@ -0,0 +1,44 @@
>> +/**
>> + * @file
>> + *
>> + * @ingroup raspberrypi
>> + *
>> + * @brief mailbox 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 <stdint.h>
>> +#include <bsp/raspberrypi.h>
>> +#include <bsp/mailbox.h>
>> +
>> +unsigned int raspberrypi_mailbox_read (unsigned int channel)
>> +{
>> +  unsigned int data;
>> +  unsigned int read_channel;
>> +
>> +  while ( 1 )
>> +  {
>> +    while (BCM2835_REG (BCM2835_MBOX_STATUS ) & BCM2835_MBOX_EMPTY);
>> +    data = BCM2835_REG (BCM2835_MBOX_READ );
>> +    read_channel = (unsigned int) (data & 0xF );
>> +    if (read_channel == channel)
>> +      return (data & 0xFFFFFFF0);
>> +  }
>> +}
>> +
>> +void raspberrypi_mailbox_write(unsigned int channel, unsigned int data)
>> +{
>> +  while (BCM2835_REG(BCM2835_MBOX_STATUS) & BCM2835_MBOX_FULL);
>> +  BCM2835_REG(BCM2835_MBOX_WRITE) =
>> +    (data & 0xFFFFFFF0) |
>> +    (unsigned int) (channel & 0xF);
>> +}
>> diff --git a/c/src/lib/libbsp/arm/raspberrypi/preinstall.am b/c/src/lib/libbsp/arm/raspberrypi/preinstall.am
>> index 70259e2..4cb7ed6 100644
>> --- a/c/src/lib/libbsp/arm/raspberrypi/preinstall.am
>> +++ b/c/src/lib/libbsp/arm/raspberrypi/preinstall.am
>> @@ -126,6 +126,10 @@ $(PROJECT_INCLUDE)/bsp/usart.h: include/usart.h $(PROJECT_INCLUDE)/bsp/$(dirstam
>>      $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/usart.h
>>  PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/usart.h
>>  
>> +$(PROJECT_INCLUDE)/bsp/mailbox.h: include/mailbox.h $(PROJECT_INCLUDE)/bsp/$(dirstamp)
>> +    $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/mailbox.h
>> +PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/mailbox.h
>> +
>>  $(PROJECT_INCLUDE)/bsp/raspberrypi.h: include/raspberrypi.h $(PROJECT_INCLUDE)/bsp/$(dirstamp)
>>      $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/raspberrypi.h
>>  PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/raspberrypi.h
>>
>>
>> On Apr 16, 2015, at 11:20 PM, Gedare Bloom <gedare at rtems.org> wrote:
>>
>>> Are you working to make the corrections I mentioned?
>>>
>>> On Tue, Apr 7, 2015 at 10:05 AM, Gedare Bloom <gedare at rtems.org> wrote:
>>>> On Mon, Apr 6, 2015 at 5:12 PM, QIAO YANG <yangqiao0505 at me.com> wrote:
>>>>> -----
>>>>>
>>>>> diff --git a/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
>>>>> b/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
>>>>> index c6133df..70bc01d 100644
>>>>> --- a/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
>>>>> +++ b/c/src/lib/libbsp/arm/raspberrypi/Makefile.am
>>>>> @@ -43,6 +43,7 @@ include_bsp_HEADERS += ../shared/include/arm-release-id.h
>>>>> include_bsp_HEADERS += include/irq.h
>>>>> include_bsp_HEADERS += include/mmu.h
>>>>> include_bsp_HEADERS += include/usart.h
>>>>> +include_bsp_HEADERS += include/mailbox.h
>>>>> include_bsp_HEADERS += include/raspberrypi.h
>>>>>
>>>>> include_libcpu_HEADERS = ../../../libcpu/arm/shared/include/cache_.h \
>>>>> @@ -123,6 +124,9 @@ libbsp_a_SOURCES += misc/timer.c
>>>>>
>>>>> # I2C
>>>>>
>>>>> +# Mailbox
>>>>> +libbsp_a_SOURCES += misc/mailbox.c
>>>>> +
>>>>> # Cache
>>>>> libbsp_a_SOURCES += ../../../libcpu/shared/src/cache_manager.c
>>>>> libbsp_a_SOURCES += ../../../libcpu/arm/shared/include/cache_.h
>>>>> diff --git a/c/src/lib/libbsp/arm/raspberrypi/include/mailbox.h
>>>>> b/c/src/lib/libbsp/arm/raspberrypi/include/mailbox.h
>>>>> new file mode 100644
>>>>> index 0000000..abdb258
>>>>> --- /dev/null
>>>>> +++ b/c/src/lib/libbsp/arm/raspberrypi/include/mailbox.h
>>>>> @@ -0,0 +1,7 @@
>>>> Need file header documentation. Please see
>>>> https://devel.rtems.org/wiki/Developer/Coding/Conventions
>>>>  
>>>>> +#ifndef MAILBOX_H
>>>>> +#define MAILBOX_H
>>>>> +
>>>>> +extern unsigned int readmailbox(unsigned int channel);
>>>>> +extern void writemailbox(unsigned int channel, unsigned int data);
>>>>> +
>>>> Please use function names with a "namespace". the usual convention in
>>>> RTEMS is to use Package_Class_Method like raspberrypi_mailbox_read()
>>>> and raspberrypi_mailbox_write().
>>>>
>>>>> +#endif /* MAILBOX_H */
>>>>> \ No newline at end of file
>>>>> diff --git a/c/src/lib/libbsp/arm/raspberrypi/include/raspberrypi.h
>>>>> b/c/src/lib/libbsp/arm/raspberrypi/include/raspberrypi.h
>>>>> index c33e22a..e4ce18f 100644
>>>>> --- a/c/src/lib/libbsp/arm/raspberrypi/include/raspberrypi.h
>>>>> +++ b/c/src/lib/libbsp/arm/raspberrypi/include/raspberrypi.h
>>>>> @@ -208,6 +208,52 @@
>>>>>
>>>>> /** @} */
>>>>>
>>>>> + /**
>>>>> + * @name Mailbox Registers
>>>>> + *
>>>>> + * @{
>>>>> + */
>>>>> +
>>>>> +/**
>>>>> + * NOTE:
>>>>> + */
>>>>> +#define BCM2835_MBOX_BASE (RPI_PERIPHERAL_BASE+0xB880)
>>>>> +
>>>>> +#define BCM2835_MBOX_PEEK (BCM2835_MBOX_BASE+0x10)
>>>>> +#define BCM2835_MBOX_READ (BCM2835_MBOX_BASE+0x00)
>>>>> +#define BCM2835_MBOX_WRITE (BCM2835_MBOX_BASE+0x20)
>>>>> +#define BCM2835_MBOX_STATUS (BCM2835_MBOX_BASE+0x18)
>>>>> +#define BCM2835_MBOX_SENDER (BCM2835_MBOX_BASE+0x14)
>>>>> +#define BCM2835_MBOX_CONFIG (BCM2835_MBOX_BASE+0x1C)
>>>>> +
>>>>> +/* Power Manager channel */
>>>>> +#define BCM2835_MBOX_CHANNEL_PM 0
>>>>> +/* Framebuffer channel */
>>>>> +#define BCM2835_MBOX_CHANNEL_FB 1
>>>>> + /* Virtual UART channel */
>>>>> +#define BCM2835_MBOX_CHANNEL_VUART 2
>>>>> + /* VCHIQ channel */
>>>>> +#define BCM2835_MBOX_CHANNEL_VCHIQ 3
>>>>> + /* LEDs channel */
>>>>> +#define BCM2835_MBOX_CHANNEL_LED 4
>>>>> + /* Button channel */
>>>>> +#define BCM2835_MBOX_CHANNEL_BUTTON 5
>>>>> + /* Touch screen channel */
>>>>> +#define BCM2835_MBOX_CHANNEL_TOUCHS 6
>>>>> +/* Property tags (ARM <-> Video Core) channel */
>>>>> +#define BCM2835_MBOX_CHANNEL_PROP_AVC 8
>>>>> + /* Property tags (Video Core <-> ARM) channel */
>>>>> +#define BCM2835_MBOX_CHANNEL_PROP_VCA 9
>>>>> +
>>>>> +#define BCM2835_MBOX_SUCCESS (BCM2835_MBOX_BASE+0x80000000)
>>>>> +
>>>>> +#define BCM2835_MBOX_FULL (BCM2835_MBOX_BASE+0x80000000)
>>>>> +#define BCM2835_MBOX_EMPTY (BCM2835_MBOX_BASE+0x40000000)
>>>>> +
>>>>> +
>>>>> +
>>>>> +/** @} */
>>>>> +
>>>>>
>>>>> /** @} */
>>>>>
>>>>> diff --git a/c/src/lib/libbsp/arm/raspberrypi/misc/mailbox.c
>>>>> b/c/src/lib/libbsp/arm/raspberrypi/misc/mailbox.c
>>>>> new file mode 100644
>>>>> index 0000000..7bfb7e3
>>>>> --- /dev/null
>>>>> +++ b/c/src/lib/libbsp/arm/raspberrypi/misc/mailbox.c
>>>>> @@ -0,0 +1,22 @@
>>>> Need file header documentation
>>>>> +#include <stdint.h>
>>>>> +#include <bsp/raspberrypi.h>
>>>>> +#include <bsp/mailbox.h>
>>>>> +unsigned int readmailbox ( unsigned int channel )
>>>>> +{
>>>>> + unsigned int data;
>>>>> + unsigned int read_channel;
>>>>> +
>>>>> + while ( 1 )
>>>>> + {
>>>>> + while ( BCM2835_REG ( BCM2835_MBOX_STATUS ) &
>>>>> BCM2835_MBOX_EMPTY );
>>>>> + data = BCM2835_REG ( BCM2835_MBOX_READ );
>>>>> + read_channel = ( unsigned int ) ( data & 0xF );
>>>>> + if ( read_channel == channel )
>>>>> + return ( data & 0xFFFFFFF0 );
>>>>> + }
>>>> The white spaces look wrong here. Are they tabs? Or 8 blank spaces?
>>>> Please check the style rules in the Coding Conventions page.
>>>>
>>>>> +}
>>>>> +void writemailbox( unsigned int channel, unsigned int data )
>>>>> +{
>>>>> + while ( BCM2835_REG ( BCM2835_MBOX_STATUS ) & BCM2835_MBOX_FULL );
>>>>> + BCM2835_REG (BCM2835_MBOX_WRITE) = ( data & 0xFFFFFFF0 ) | (unsigned
>>>>> int) ( channel & 0xF );
>>>>> +}
>>>>> \ No newline at end of file
>>>>> diff --git a/c/src/lib/libbsp/arm/raspberrypi/preinstall.am
>>>>> b/c/src/lib/libbsp/arm/raspberrypi/preinstall.am
>>>>> index 70259e2..4cb7ed6 100644
>>>>> --- a/c/src/lib/libbsp/arm/raspberrypi/preinstall.am
>>>>> +++ b/c/src/lib/libbsp/arm/raspberrypi/preinstall.am
>>>>> @@ -126,6 +126,10 @@ $(PROJECT_INCLUDE)/bsp/usart.h: include/usart.h
>>>>> $(PROJECT_INCLUDE)/bsp/$(dirstam
>>>>> $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/usart.h
>>>>> PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/usart.h
>>>>>
>>>>> +$(PROJECT_INCLUDE)/bsp/mailbox.h: include/mailbox.h
>>>>> $(PROJECT_INCLUDE)/bsp/$(dirstamp)
>>>>> + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/mailbox.h
>>>>> +PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/mailbox.h
>>>>> +
>>>>> $(PROJECT_INCLUDE)/bsp/raspberrypi.h: include/raspberrypi.h
>>>>> $(PROJECT_INCLUDE)/bsp/$(dirstamp)
>>>>> $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/raspberrypi.h
>>>>> PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/raspberrypi.h
>>>>>
>>>>>
>>>>> -----
>>>>>
>>>>> Here is a patch for rpi bsp which include the operation and chanel
>>>>> defininitions for mailbox and its implementations.
>>>>>
>>>>> I've only tested the framebuffer with it and it works well : set the screen
>>>>> size and get the informations.
>>>>> Andre used it for sd card reading. I've checked it out and added full
>>>>> channel definitions.
>>>>> Please point it out if further tests should be done.
>>>>>
>>>>> YANG QIAO
>>>>>
>>>>> _______________________________________________
>>>>> devel mailing list
>>>>> devel at rtems.org
>>>>>  
>>>>> http://lists.rtems.org/mailman/listinfo/devel
>>>>>  
>> <mailbox_19_04_2015.patch>_______________________________________________
>> devel mailing list
>> devel at rtems.org
>> http://lists.rtems.org/mailman/listinfo/devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20150424/88160816/attachment-0002.html>


More information about the devel mailing list