Raspberry Pi Bare Bones: Difference between revisions

Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content deleted Content added
mNo edit summary
Line 224: Line 224:
#include <stdint.h>
#include <stdint.h>


static uint32_t MMIO_BASE;
// board type, raspi2

int raspi = 2;
// The MMIO area base address, depends on board type
static inline void mmio_init(int raspi)
{
switch (raspi) {
case 2:
case 3: MMIO_BASE = 0x3F000000; break; // for raspi2 & 3
case 4: MMIO_BASE = 0xFE000000; break; // for raspi4
default: MMIO_BASE = 0x20000000; break; // for raspi1, raspi zero etc.
}
}


// Memory-Mapped I/O output
// Memory-Mapped I/O output
static inline void mmio_write(uint32_t reg, uint32_t data)
static inline void mmio_write(uint32_t reg, uint32_t data)
{
{
*(volatile uint32_t*)reg = data;
*(volatile uint32_t*)(MMIO_BASE + reg) = data;
}
}


Line 236: Line 246:
static inline uint32_t mmio_read(uint32_t reg)
static inline uint32_t mmio_read(uint32_t reg)
{
{
return *(volatile uint32_t*)reg;
return *(volatile uint32_t*)(MMIO_BASE + reg);
}
}


Line 248: Line 258:
enum
enum
{
{
// The MMIO area base address.
//Who the heck put a switch statement in here?
switch (raspi) {
case 2:
case 3: MMIO_BASE = 0x3F000000; break; // for raspi2 & 3
case 4: MMIO_BASE = 0xFE000000; break; // for raspi4
default: MMIO_BASE = 0x20000000; break; // for raspi1, raspi zero etc.
}

// The offsets for reach register.
// The offsets for reach register.
GPIO_BASE = (MMIO_BASE + 0x200000),
GPIO_BASE = 0x200000,


// Controls actuation of pull up/down to ALL GPIO pins.
// Controls actuation of pull up/down to ALL GPIO pins.
Line 290: Line 291:


// The offsets for Mailbox registers
// The offsets for Mailbox registers
MBOX_BASE = (MMIO_BASE + 0xB880),
MBOX_BASE = 0xB880,
MBOX_READ = (MBOX_BASE + 0x00),
MBOX_READ = (MBOX_BASE + 0x00),
MBOX_STATUS = (MBOX_BASE + 0x18),
MBOX_STATUS = (MBOX_BASE + 0x18),
Line 386: Line 387:
#endif
#endif
{
{
// initialize MMIO_BASE address for Raspi2
mmio_init(2);

uart_init();
uart_init();
uart_puts("Hello, kernel World!\r\n");
uart_puts("Hello, kernel World!\r\n");