jacking/rpi/rpi.c

76 lines
2.0 KiB
C

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
extern void jazelle_main(void);
#define GPFSEL1 (*(volatile uint32_t*)0x20200004)
#define GPSET0 (*(volatile uint32_t*)0x2020001C)
#define GPCLR0 (*(volatile uint32_t*)0x20200028)
#define GPPUD (*(volatile uint32_t*)0x20200094)
#define GPPUDCLK0 (*(volatile uint32_t*)0x20200098)
#define AUX_ENABLES (*(volatile uint32_t*)0x20215004)
#define AUX_MU_IO_REG (*(volatile uint32_t*)0x20215040)
#define AUX_MU_IER_REG (*(volatile uint32_t*)0x20215044)
#define AUX_MU_IIR_REG (*(volatile uint32_t*)0x20215048)
#define AUX_MU_LCR_REG (*(volatile uint32_t*)0x2021504C)
#define AUX_MU_MCR_REG (*(volatile uint32_t*)0x20215050)
#define AUX_MU_LSR_REG (*(volatile uint32_t*)0x20215054)
#define AUX_MU_MSR_REG (*(volatile uint32_t*)0x20215058)
#define AUX_MU_SCRATCH (*(volatile uint32_t*)0x2021505C)
#define AUX_MU_CNTL_REG (*(volatile uint32_t*)0x20215060)
#define AUX_MU_STAT_REG (*(volatile uint32_t*)0x20215064)
#define AUX_MU_BAUD_REG (*(volatile uint32_t*)0x20215068)
void uart_putc(char c) {
while (!(AUX_MU_LSR_REG & 0x20)) asm volatile("nop");
AUX_MU_IO_REG = c;
}
void uart_puts(const char* s) {
for (; s && *s; ++s) {
uart_putc(*s);
}
}
void uart_putdata(const uint8_t* p, size_t size) {
for (size_t i = 0; i < size; ++i) {
uart_putc((char)p[i]);
}
}
int main() {
AUX_ENABLES=1;
AUX_MU_IER_REG=0;
AUX_MU_CNTL_REG=0;
AUX_MU_LCR_REG=3;
AUX_MU_MCR_REG=0;
AUX_MU_IER_REG=0;
AUX_MU_IIR_REG=0xC6;
AUX_MU_BAUD_REG=270;
uint32_t ra = GPFSEL1;
ra&=~(7<<12); //gpio14
ra|=2<<12; //alt5
GPFSEL1=ra;
GPPUD=0;
for (int ra=0;ra<150;ra++) asm volatile("nop");
GPPUDCLK0=(1<<14);
for (int ra=0;ra<150;ra++) asm volatile("nop");
GPPUDCLK0=0;
AUX_MU_CNTL_REG=2;
//uart_putc('A');
jazelle_main();
return 0;
}