can anyone supply an example which uses the firmware.
e.g. ask the firmware for revision info, cpu temerature...
thnx,
sf
Code: Select all
/*--------------------------------------------------------------------------}
;{ RASPBERRY PI MAILBOX HARRDWARE REGISTERS }
;{-------------------------------------------------------------------------*/
struct __attribute__((__packed__, aligned(4))) MailBoxRegisters {
const uint32_t Read0; // 0x00 Read data from VC to ARM
uint32_t Unused[3]; // 0x04-0x0F
uint32_t Peek0; // 0x10
uint32_t Sender0; // 0x14
uint32_t Status0; // 0x18 Status of VC to ARM
uint32_t Config0; // 0x1C
uint32_t Write1; // 0x20 Write data from ARM to VC
uint32_t Unused2[3]; // 0x24-0x2F
uint32_t Peek1; // 0x30
uint32_t Sender1; // 0x34
uint32_t Status1; // 0x38 Status of ARM to VC
uint32_t Config1; // 0x3C
};
#define MAILBOX ((volatile __attribute__((aligned(4))) struct MailBoxRegisters*)(uintptr_t)(RPi_IO_Base_Addr + 0xB880));
Code: Select all
/*--------------------------------------------------------------------------}
{ ENUMERATED MAILBOX CHANNELS }
{ https://github.com/raspberrypi/firmware/wiki/Mailboxes }
{--------------------------------------------------------------------------*/
typedef enum {
MB_CHANNEL_POWER = 0x0, // Mailbox Channel 0: Power Management Interface
MB_CHANNEL_FB = 0x1, // Mailbox Channel 1: Frame Buffer
MB_CHANNEL_VUART = 0x2, // Mailbox Channel 2: Virtual UART
MB_CHANNEL_VCHIQ = 0x3, // Mailbox Channel 3: VCHIQ Interface
MB_CHANNEL_LEDS = 0x4, // Mailbox Channel 4: LEDs Interface
MB_CHANNEL_BUTTONS = 0x5, // Mailbox Channel 5: Buttons Interface
MB_CHANNEL_TOUCH = 0x6, // Mailbox Channel 6: Touchscreen Interface
MB_CHANNEL_COUNT = 0x7, // Mailbox Channel 7: Counter
MB_CHANNEL_TAGS = 0x8, // Mailbox Channel 8: Tags (ARM to VC)
MB_CHANNEL_GPU = 0x9, // Mailbox Channel 9: GPU (VC to ARM)
} MAILBOX_CHANNEL;
Code: Select all
#define MAIL_FULL 0x80000000 /* Mailbox Status Register: Mailbox Full */
/*-[mailbox_write]----------------------------------------------------------}
. This will execute the sending of the given data block message thru the
. mailbox system on the given channel.
. RETURN: True for success, False for failure.
.--------------------------------------------------------------------------*/
bool mailbox_write (MAILBOX_CHANNEL channel, uint32_t message)
{
uint32_t value; // Temporary read value
if (channel > MB_CHANNEL_GPU) return false; // Channel error
message &= ~(0xF); // Make sure 4 low channel bits are clear
message |= channel; // OR the channel bits to the value
do {
value = MAILBOX->Status1; // Read mailbox1 status from GPU
} while ((value & MAIL_FULL) != 0); // Make sure arm mailbox is not full
MAILBOX->Write1 = message; // Write value to mailbox
return true; // Write success
}
Code: Select all
#define MAIL_EMPTY 0x40000000 /* Mailbox Status Register: Mailbox Empty */
/*-[mailbox_read]-----------------------------------------------------------}
. This will read any pending data on the mailbox system on the given channel.
. RETURN: The read value for success, 0xFEEDDEAD for failure.
.--------------------------------------------------------------------------*/
uint32_t mailbox_read (MAILBOX_CHANNEL channel)
{
uint32_t value; // Temporary read value
if (channel > MB_CHANNEL_GPU) return 0xFEEDDEAD; // Channel error
do {
do {
value = MAILBOX->Status0; // Read mailbox0 status
} while ((value & MAIL_EMPTY) != 0); // Wait for data in mailbox
value = MAILBOX->Read0; // Read the mailbox
} while ((value & 0xF) != channel); // We have response back
value &= ~(0xF); // Lower 4 low channel bits are not part of message
return value; // Return the value
}
Code: Select all
uint32_t ReadCPUSpeed(void){
/* message must be align 16 */
uint32_t __attribute__((aligned(16))) message[8] =
{
sizeof(message), /* size of message */
0x0, /* response */
0x00030002, /* mailbox get clock rates */
8, /* request is 8 bytes long */
8, /* response expects 8 bytes back */
3, /* clock ID = 3 .. ARM CPU */
0, /* empty data field */
0 /* structure terminator*/
};
mailbox_write(MB_CHANNEL_TAGS, (uint32_t)&message[0]); // Send the message
mailbox_read(MB_CHANNEL_TAGS); // Clear the response
if (message[1] == 0x80000000) { // Message success
return(message[6]); // Message[6] was zero will have ARM CPU speed
}
return 0; // Failed
}
Code: Select all
int main (void) {
printf("CPU speed = %u\r\n", ReadCPUSpeed());
}
https://github.com/raspberrypi/linux/bl ... firmware.h is the definitive list of mailbox calls.rudiratlos wrote: ↑Thu Feb 15, 2018 2:15 pmthanks,
https://github.com/6by9/rpi3-gpiovirtbuf
thats exactly what I'm looking for.
but I couldn't find a tag for mac addr of wlan adapter, gpu temperature ...
from where can I get these missing infos?
querying from the os like
/opt/vc/bin/vcgencmd measure_temp|awk -F "=" '{print $2}'
is to time consuming.
takes 2000 times longer
Code: Select all
RPI_FIRMWARE_GET_BOARD_MAC_ADDRESS
Code: Select all
RPI_FIRMWARE_GET_TEMPERATURE
Why not use the built in command vcgencmd measure_temp or simply read it from cat /sys/devices/virtual/thermal/thermal_zone0/temprudiratlos wrote: ↑Fri Mar 23, 2018 2:54 pmcan someone so kind, to write a small c program (similar to LDB's), that retrieves the mailbox with SoC Temperature Tag. so I can run it on my rpi3 for further investigation.
Where is, or how would I find the source for vcgencmd? I'd be interested in extracting some configuration/settings stuff for display on a small OLED, and rather than executing another command, would like to include the functionality in my own code.DougieLawson wrote: ↑Sat Apr 07, 2018 6:09 pm
You get the source code for that vcgencmd program and it must have a mailbox call in it to retrieve the CPU temperature.
https://github.com/raspberrypi/userland ... d/gencmd.c for the appSteveSpencer wrote: ↑Tue Apr 10, 2018 8:34 amWhere is, or how would I find the source for vcgencmd? I'd be interested in extracting some configuration/settings stuff for display on a small OLED, and rather than executing another command, would like to include the functionality in my own code.DougieLawson wrote: ↑Sat Apr 07, 2018 6:09 pm
You get the source code for that vcgencmd program and it must have a mailbox call in it to retrieve the CPU temperature.
I have it running using vcgencmd, but would prefer to speed it up a little.