From 1577811d579f1aa8213c62f7bfac3e94f500a0d6 Mon Sep 17 00:00:00 2001 From: "Michael J. Chudobiak" Date: Wed, 22 Aug 2012 10:42:05 -0400 Subject: fixes initialization of flash files --- bus.c | 58 +++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 15 deletions(-) (limited to 'bus.c') diff --git a/bus.c b/bus.c index da5243a..29958b0 100644 --- a/bus.c +++ b/bus.c @@ -58,6 +58,14 @@ static int devmemfd = -1; +static bool util_isbeaglebone() +{ + bool ret = false; + int fd = open("/sys/kernel/debug/omap_mux/board/core", O_RDONLY); + close(fd); + return fd > -1; +} + static void* util_mapmemoryblock(off_t offset, size_t len) { devmemfd = open("/dev/mem", O_RDWR | O_SYNC); @@ -192,7 +200,7 @@ static void gpmc_setup(int chipselect, int accesscycles, int size, bool enablecs *(registers + displacement + GPMC_CONFIG3) = 0x0; // not using ADV so we can ignore this guy *(registers + displacement + GPMC_CONFIG4) = (accesscycles << OEOFFTIME); *(registers + displacement + GPMC_CONFIG5) = (accesscycles << RDACCESSTIME) | (accesscycles << WRCYCLETIME) - | (accesscycles << RDCYCLETIME); + | (accesscycles << RDCYCLETIME); *(registers + displacement + GPMC_CONFIG6) = (accesscycles << WRACCESSTIME); *(registers + displacement + GPMC_CONFIG7) = size << 8 | (enablecs ? 1 << 6 : 0) | baseaddress; @@ -296,43 +304,63 @@ static unsigned bases[] = { GPIOPIN0BASE, GPIOPIN1BASE, GPIOPIN2BASE, GPIOPIN3BA static unsigned pins[] = { GPIOPIN0PIN, GPIOPIN1PIN, GPIOPIN2PIN, GPIOPIN3PIN, GPIOPIN4PIN, GPIOPIN5PIN }; static volatile uint8_t* extbus; +static bool isbb = false; void bus_init() { - gpmc_setup(0, GPMCACCESSTIME, GPMC_SIZE_16MB, true, 1); - extbus = (uint8_t*) util_mapmemoryblock(0x01000000, 0x100); + isbb = util_isbeaglebone(); + + if (!isbb) { + printf("This doesn't seem to be a beaglebone.. bus stuff disabled!\n"); + } - //gpmc_printinfo(); + if (isbb) { + gpmc_setup(0, GPMCACCESSTIME, GPMC_SIZE_16MB, true, 1); - int i; - for (i = 0; i < SIZEOFARRAY(bases); i++) { - gpio_export(bases[i], pins[i]); - gpio_changedirection(bases[i], pins[i], true); + extbus = (uint8_t*) util_mapmemoryblock(0x01000000, 0x100); + + //gpmc_printinfo(); + + int i; + for (i = 0; i < SIZEOFARRAY(bases); i++) { + gpio_export(bases[i], pins[i]); + gpio_changedirection(bases[i], pins[i], true); + } } } void bus_setpin(int pin, int value) { - gpio_writevalue(bases[pin], pins[pin], value & 0x1); + if (isbb) { + gpio_writevalue(bases[pin], pins[pin], value & 0x1); + } } void bus_writebyte(uint8_t address, uint8_t data) { - *(extbus + address) = data; + if (isbb) { + *(extbus + address) = data; + } } uint8_t bus_readbyte(uint8_t address) { - return *(extbus + address); + if (isbb) { + return *(extbus + address); + } else { + return 0; + } } void bus_shutdown() { - util_unmapmemoryblock((void*) extbus, 0x100); - int i; - for (i = 0; i < SIZEOFARRAY(bases); i++) { - gpio_unexport(bases[i], pins[i]); + if (isbb) { + util_unmapmemoryblock((void*) extbus, 0x100); + int i; + for (i = 0; i < SIZEOFARRAY(bases); i++) { + gpio_unexport(bases[i], pins[i]); + } } } -- cgit