diff --git a/tornado/fw/ben/Makefile b/tornado/fw/ben/Makefile new file mode 100644 index 0000000..37353ee --- /dev/null +++ b/tornado/fw/ben/Makefile @@ -0,0 +1,17 @@ +CC = mipsel-openwrt-linux-gcc +CFLAGS = -g -Wall -I.. -I. +OBJS = ben.o mmc.o mmc-hw.o + +.PHONY: all ben clean spotless + +vpath %.c .. + +all: ben + +ben: $(OBJS) + +clean: + rm -f $(OBJS) + +spotless: clean + rm -f ben diff --git a/tornado/fw/ben/ben-io.h b/tornado/fw/ben/ben-io.h new file mode 100644 index 0000000..fee6b21 --- /dev/null +++ b/tornado/fw/ben/ben-io.h @@ -0,0 +1,49 @@ +/* + * ben/ben-io.h - I/O helper macros (for cross-platform testing on the Ben) + * + * Written 2012 by Werner Almesberger + * Copyright 2012 Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#ifndef BEN_IO_H +#define BEN_IO_H + +#include + + +#define CARD_nPWR (1 << 2) /* PD02 */ +#define CARD_DAT2 (1 << 12) /* PD12 */ +#define CARD_DAT3 (1 << 13) /* PD13 */ +#define CARD_CMD (1 << 8) /* PD08 */ +#define CARD_CLK (1 << 9) /* PD09 */ +#define CARD_DAT0 (1 << 10) /* PD10 */ +#define CARD_DAT1 (1 << 11) /* PD11 */ + + +#define REG(n) (*(volatile uint32_t *) (ben_mem+(n))) + +#define GPIO(n) REG(0x10000+(n)) + +#define PDPIN GPIO(0x300) /* port D pin level */ +#define PDDATS GPIO(0x314) /* port D data set */ +#define PDDATC GPIO(0x318) /* port D data clear */ +#define PDFUNS GPIO(0x344) /* port D function set */ +#define PDFUNC GPIO(0x348) /* port D function clear */ +#define PDDIRS GPIO(0x364) /* port D direction set */ +#define PDDIRC GPIO(0x368) /* port D direction clear */ + +#define SET(mask) PDDATS = mask +#define CLR(mask) PDDATC = mask +#define OUT(mask) PDDIRS = mask +#define IN(mask) PDDIRC = mask +#define PIN(mask) (!!(PDPIN & (mask))) + + +extern void *ben_mem; + +#endif /* BEN_IO_H */ diff --git a/tornado/fw/ben/ben.c b/tornado/fw/ben/ben.c new file mode 100644 index 0000000..6d6bcd3 --- /dev/null +++ b/tornado/fw/ben/ben.c @@ -0,0 +1,73 @@ +/* + * ben/ben.c - Cross-platform testing on the Ben Nanonote + * + * Written 2012 by Werner Almesberger + * Copyright 2012 Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include + +#include "../mmc.h" +#include "ben-io.h" + + +#define SOC_BASE 0x10000000 +#define PAGE_SIZE 4096 + + +void *ben_mem; + + +static void io_setup(void) +{ + int fd; + + fd = open("/dev/mem", O_RDWR | O_SYNC); + if (fd < 0) { + perror("/dev/mem"); + exit(1); + } + ben_mem = mmap(NULL, PAGE_SIZE*3*16, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, SOC_BASE); + if (ben_mem == MAP_FAILED) { + perror("mmap"); + exit(1); + } + + PDDATS = CARD_nPWR; + PDDIRS = CARD_nPWR; + PDDIRC = CARD_CMD | CARD_CLK | + CARD_DAT0 | CARD_DAT1 | CARD_DAT2 | CARD_DAT3; + PDFUNC = CARD_nPWR | CARD_CMD | CARD_CLK | + CARD_DAT0 | CARD_DAT1 | CARD_DAT2 | CARD_DAT3; +} + + +int main(void) +{ + int i; + + io_setup(); + + if (!mmc_init()) { + fprintf(stderr, "mmc_init failed\n"); + exit(1); + } + if (!mmc_begin_read(0)) { + fprintf(stderr, "mmc_begin_read failed\n"); + exit(1); + } + for (i = 0; i != MMC_BLOCK; i++) + printf("%02x%c", mmc_read(), (i & 15) == 15 ? '\n' : ' '); + mmc_end_read(); + + return 0; +} diff --git a/tornado/fw/mmc-hw.c b/tornado/fw/mmc-hw.c index f70ffc8..6682423 100644 --- a/tornado/fw/mmc-hw.c +++ b/tornado/fw/mmc-hw.c @@ -13,10 +13,28 @@ #include +#ifdef AVR + #define F_CPU 8000000UL #include #include "io.h" + +#else /* AVR */ + +#include + +#include "ben-io.h" + + +static inline void _delay_ms(int ms) +{ + usleep(1000*ms); +} + + +#endif /* !AVR */ + #include "mmc-hw.h"