my code is as follows
framebuffer.c
- Code: Select all
#include "framebuffer.h"
#include "console.h"
#include <mailbox.h>
#include <stdint.h>
struct FramebufferRequest {
uint32 width;
uint32 height;
uint32 vwidth;
uint32 vheight;
uint32 pitch;
uint32 depth;
uint32 x;
uint32 y;
uint32 pointer;
uint32 size;
} FBRequest __attribute__((aligned(4)));
const unsigned int FramebufferMailboxChannel = 1;
void FramebufferInitialize() {
ConsoleWrite("Constructing a framebuffer request\n");
FBRequest.width = 800;
FBRequest.height = 600;
FBRequest.vwidth = 800;
FBRequest.vheight = 600;
FBRequest.pitch = 0;
FBRequest.depth = 0;
FBRequest.x = 0;
FBRequest.y = 0;
FBRequest.pointer = 0;
FBRequest.size = 0;
ConsoleWrite("Sending mailbox request\n");
MailboxWrite(1, &FBRequest);
ConsoleWrite("Reading mailbox response\n");
uint32 response = MailboxRead(1);
if (response != 0) {
ConsoleWrite("Framebuffer failed to initialize\n");
}
}
and mailbox.c
- Code: Select all
#include "mailbox.h"
#include <console.h>
const static uint32* MailboxReadRegister = (unsigned int*) 0x2000B880;
const static uint32* MailboxWriteRegister = (unsigned int*) 0x2000B8A0;
const static uint32* MailboxStatusRegister = (unsigned int*) 0x2000B898;
const static uint32 MailFullFlag = 0x80000000;
const static uint32 MailEmptyFlag = 0x40000000;
uint32 MBReadRegister(uint32* address) {
return *address;
}
void MBWriteRegister(uint32* address, uint32 data) {
*address = data;
}
uint32 MailboxRead(uint8 channel) {
//Loop until found for channel
for (;;) {
while ((MBReadRegister(MailboxStatusRegister) & MailEmptyFlag) != 0) {
//Wait until there is data to read
ConsoleWrite("Wait-Read\n");
}
uint32 data = MBReadRegister(MailboxReadRegister);
uint8 readChannel = data & 0xF;
data >>= 4;
if (channel == readChannel) {
return data;
}
}
}
void MailboxWrite(uint8 channel, uint32 data) {
while ((MBReadRegister(MailboxStatusRegister) & MailFullFlag) != 0) {
//Wait until there is space to read
ConsoleWrite("Wait-Write\n");
}
MBWriteRegister(MailboxWriteRegister, (data << 4) & channel);
ConsoleWrite("MB-Write\n");
}
however this code gives the output blake@ubuntu:~/Dropbox/Current/PiOS$ sh emulate.sh
Initializing PiOS
Constructing a framebuffer request
Sending mailbox request
MB-Write
Reading mailbox response
before it hangs, getting stuck on the MailboxRead function as there is never any message from channel 1 ( Debugging the readchannel shows that the lower 4 bits of the data received are always 0 )
Does anybody have any advice as to what the problem is? Thanks