summaryrefslogtreecommitdiff
path: root/bus.c
diff options
context:
space:
mode:
Diffstat (limited to 'bus.c')
-rw-r--r--bus.c50
1 files changed, 27 insertions, 23 deletions
diff --git a/bus.c b/bus.c
index bcd916f..e733cdf 100644
--- a/bus.c
+++ b/bus.c
@@ -15,6 +15,7 @@
#include <unistd.h>
#include <stdbool.h>
#include <inttypes.h>
+#include "globals.h"
#include "bus.h"
#define GPIO_SYSFSPATH "/sys/class/gpio"
@@ -176,10 +177,6 @@ static void gpmc_printinfo()
static void gpmc_setup(void)
{
- int chipselect = 0;
- int size = GPMC_SIZE_16MB;
- bool enablecs = true;
- int baseaddress = 1;
int CSWROFFTIME = TOTAL_IO_CYCLE;
@@ -201,6 +198,12 @@ static void gpmc_setup(void)
int WRACCESSTIME = DATA_READY;
int config6 = WRACCESSTIME << 24;
+ //uart5 stuff
+ pinmux_configurepin("lcd_data9", BIDIR | PULL_UP | MODE_4);
+ pinmux_configurepin("lcd_data8", MODE_4);
+ pinmux_configurepin("lcd_data14", BIDIR | PULL_UP | MODE_6);
+ pinmux_configurepin("lcd_data15", MODE_6);
+ //
pinmux_configurepin("gpmc_csn0", PULL_UP | MODE_0);
pinmux_configurepin("gpmc_oen_ren", PULL_UP | MODE_0);
@@ -224,11 +227,15 @@ static void gpmc_setup(void)
pinmux_configurepin("lcd_data6", PULL_UP | MODE_1);
pinmux_configurepin("lcd_data7", PULL_UP | MODE_1);
- int displacement = GPMC_CHIPSELECTCONFIGDISPLACEMENT * chipselect;
-
gpmc_mapregisters();
if (registers != MAP_FAILED) {
+ int chipselect = 0;
+ int size = GPMC_SIZE_16MB;
+ bool enablecs = true;
+ int baseaddress = 1;
+ int displacement = GPMC_CHIPSELECTCONFIGDISPLACEMENT * chipselect;
+
// disable before playing with the registers..
*(registers + displacement + GPMC_CONFIG7) = 0x0;
@@ -252,7 +259,7 @@ static int gpio_export(unsigned gpio_pin)
{
FILE* exportfile = fopen(GPIO_SYSFSPATH"/"GPIO_EXPORTNODE, "w");
if (exportfile != NULL) {
- fprintf(exportfile, "%d\n", gpio_pin);
+ fprintf(exportfile, "%u\n", gpio_pin);
fclose(exportfile);
return 0;
}
@@ -267,7 +274,7 @@ static int gpio_unexport(unsigned gpio_pin)
{
FILE* unexportfile = fopen(GPIO_SYSFSPATH"/"GPIO_UNEXPORTNODE, "w");
if (unexportfile != NULL) {
- fprintf(unexportfile, "%d\n", gpio_pin);
+ fprintf(unexportfile, "%u\n", gpio_pin);
fclose(unexportfile);
return 0;
}
@@ -281,7 +288,7 @@ static int gpio_unexport(unsigned gpio_pin)
static int gpio_changedirection(unsigned gpio_pin, bool out)
{
char path[PATHLEN];
- snprintf(path, PATHLEN, GPIO_SYSFSPATH"/gpio%d/"GPIO_DIRECTIONNODE, gpio_pin);
+ snprintf(path, PATHLEN, GPIO_SYSFSPATH"/gpio%u/"GPIO_DIRECTIONNODE, gpio_pin);
FILE* directionfile = fopen(path, "w");
if (directionfile != NULL) {
if (out) {
@@ -298,7 +305,7 @@ static int gpio_changedirection(unsigned gpio_pin, bool out)
static void gpio_getvaluenodepath(unsigned gpio_pin, char* buffer)
{
- snprintf(buffer, PATHLEN, GPIO_SYSFSPATH"/gpio%d/"GPIO_VALUENODE, gpio_pin);
+ snprintf(buffer, PATHLEN, GPIO_SYSFSPATH"/gpio%u/"GPIO_VALUENODE, gpio_pin);
}
/*
@@ -354,18 +361,15 @@ static unsigned gpio_pins[] = { GPIO0_X + 22, // i.e., GPIO0_22
static volatile uint8_t* extbus;
-static bool isbb = false;
void bus_init()
{
- isbb = util_isbeaglebone();
+ globals.HWDetect.beaglebone = util_isbeaglebone();
- if (!isbb) {
+ if (!globals.HWDetect.beaglebone) {
printf("This doesn't seem to be a beaglebone.. bus stuff disabled!\n");
- }
-
- if (isbb) {
+ } else {
gpmc_setup();
extbus = (uint8_t*) util_mapmemoryblock(0x01000000, 0x100);
@@ -380,9 +384,9 @@ void bus_init()
gpio_changedirection(gpio_pins[i], true);
}
- // FIXME: make this more elegant
- //
+ // this could be more elegant -
// the POWER_FAIL pin is an input
+
gpio_changedirection(gpio_pins[POWER_FAIL], false);
}
}
@@ -390,7 +394,7 @@ void bus_init()
int bus_getpin(int pin)
{
- if (isbb) {
+ if (globals.HWDetect.beaglebone) {
return gpio_readvalue(gpio_pins[pin]);
} else {
return 0;
@@ -399,21 +403,21 @@ int bus_getpin(int pin)
void bus_setpin(int pin, int value)
{
- if (isbb) {
+ if (globals.HWDetect.beaglebone) {
gpio_writevalue(gpio_pins[pin], value & 0x1);
}
}
void bus_writebyte(uint8_t address, uint8_t data)
{
- if (isbb) {
+ if (globals.HWDetect.beaglebone) {
*(extbus + address) = data;
}
}
uint8_t bus_readbyte(uint8_t address)
{
- if (isbb) {
+ if (globals.HWDetect.beaglebone) {
return *(extbus + address);
} else {
return 0;
@@ -422,7 +426,7 @@ uint8_t bus_readbyte(uint8_t address)
void bus_shutdown()
{
- if (isbb) {
+ if (globals.HWDetect.beaglebone) {
util_unmapmemoryblock((void*) extbus, 0x100);
int i;
for (i = 0; i < SIZEOFARRAY(gpio_pins); i++) {