1
0
mirror of git://projects.qi-hardware.com/antorcha.git synced 2024-11-01 09:24:05 +02:00

tornado/fw/ben/: add cross-platform testing with the Ben (untested)

This commit is contained in:
Werner Almesberger 2012-12-04 22:39:38 -03:00
parent 4064698884
commit 1e29171a26
4 changed files with 157 additions and 0 deletions

17
tornado/fw/ben/Makefile Normal file
View File

@ -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

49
tornado/fw/ben/ben-io.h Normal file
View File

@ -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 <stdint.h>
#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 */

73
tornado/fw/ben/ben.c Normal file
View File

@ -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 <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/mman.h>
#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;
}

View File

@ -13,10 +13,28 @@
#include <stdint.h>
#ifdef AVR
#define F_CPU 8000000UL
#include <util/delay.h>
#include "io.h"
#else /* AVR */
#include <unistd.h>
#include "ben-io.h"
static inline void _delay_ms(int ms)
{
usleep(1000*ms);
}
#endif /* !AVR */
#include "mmc-hw.h"