diff --git a/wspr.c b/wspr.c index a25f18c..c139a58 100644 --- a/wspr.c +++ b/wspr.c @@ -19,9 +19,159 @@ Encoding process is in 5 steps: #include #include #include +#include +#include +#include +#include +#include +#include +#include + +#include + #include "wspr.h" // wspr definitions and functions +#define BCM2708_PERI_BASE 0x20000000 +#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */ +#define PAGE_SIZE (4*1024) +#define BLOCK_SIZE (4*1024) + +int mem_fd; +char *gpio_mem, *gpio_map; +char *spi0_mem, *spi0_map; + + +// I/O access +volatile unsigned *gpio; +volatile unsigned *allof7e; + +// GPIO setup macros. Always use INP_GPIO(x) before using OUT_GPIO(x) or SET_GPIO_ALT(x,y) +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3)) +#define OUT_GPIO(g) *(gpio+((g)/10)) |= (1<<(((g)%10)*3)) +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3)) + +#define GPIO_SET *(gpio+7) // sets bits which are 1 ignores bits which are 0 +#define GPIO_CLR *(gpio+10) // clears bits which are 1 ignores bits which are 0 +#define GPIO_GET *(gpio+13) // sets bits which are 1 ignores bits which are 0 + +#define ACCESS(base) *(volatile int*)((int)allof7e+base-0x7e000000) +#define SETBIT(base, bit) ACCESS(base) |= 1<