diff --git a/bcm2835.c b/bcm2835.c index aeebab6..0dd317d 100755 --- a/bcm2835.c +++ b/bcm2835.c @@ -8,6 +8,7 @@ struct bcm2835_peripheral gpio = {GPIO_BASE, 0}; struct bcm2835_peripheral bsc0 = {BSC0_BASE, 0}; +struct bcm2835_peripheral bsc1 = {BSC1_BASE, 0}; struct bcm2835_peripheral timer_arm = {TIMER_ARM_BASE, 0}; // Exposes the physical address defined in the passed structure using mmap on /dev/mem @@ -57,7 +58,7 @@ // Function to wait for the I2C transaction to complete void wait_i2c_done() { - while((!((BSC0_S) & BSC_S_DONE))) { + while((!((BSC1_S) & BSC_S_DONE))) { usleep(100); } } @@ -68,15 +69,15 @@ int idx; - BSC0_A = dev_addr; - BSC0_DLEN = len + 1; // one byte for the register address, plus the buffer length + BSC1_A = dev_addr; + BSC1_DLEN = len + 1; // one byte for the register address, plus the buffer length - BSC0_FIFO = reg_addr; // start register address + BSC1_FIFO = reg_addr; // start register address for(idx=0; idx < len; idx++) - BSC0_FIFO = buf[idx]; + BSC1_FIFO = buf[idx]; - BSC0_S = CLEAR_STATUS; // Reset status bits (see #define) - BSC0_C = START_WRITE; // Start Write (see #define) + BSC1_S = CLEAR_STATUS; // Reset status bits (see #define) + BSC1_C = START_WRITE; // Start Write (see #define) wait_i2c_done(); @@ -91,24 +92,24 @@ memset(buf, 0, len); // clear the buffer - BSC0_DLEN = len; - BSC0_S = CLEAR_STATUS; // Reset status bits (see #define) - BSC0_C = START_READ; // Start Read after clearing FIFO (see #define) + BSC1_DLEN = len; + BSC1_S = CLEAR_STATUS; // Reset status bits (see #define) + BSC1_C = START_READ; // Start Read after clearing FIFO (see #define) do { // Wait for some data to appear in the FIFO - while((BSC0_S & BSC_S_TA) && !(BSC0_S & BSC_S_RXD)); + while((BSC1_S & BSC_S_TA) && !(BSC1_S & BSC_S_RXD)); // Consume the FIFO - while((BSC0_S & BSC_S_RXD) && (bufidx < len)) { - buf[bufidx++] = BSC0_FIFO; + while((BSC1_S & BSC_S_RXD) && (bufidx < len)) { + buf[bufidx++] = BSC1_FIFO; } - } while((!(BSC0_S & BSC_S_DONE))); + } while((!(BSC1_S & BSC_S_DONE))); } void dump_bsc_status() { - unsigned int s = BSC0_S; + unsigned int s = BSC1_S; printf("BSC0_S: ERR=%d RXF=%d TXE=%d RXD=%d TXD=%d RXR=%d TXW=%d DONE=%d TA=%d\n", (s & BSC_S_ERR) != 0, diff --git a/bcm2835.h b/bcm2835.h index 3de837f..6a0c273 100755 --- a/bcm2835.h +++ b/bcm2835.h @@ -5,6 +5,7 @@ #define GPIO_BASE (IOBASE + 0x200000) #define BSC0_BASE (IOBASE + 0x205000) +#define BSC1_BASE (IOBASE + 0x804000) #define TIMER_ARM_BASE (IOBASE + 0x00B000) @@ -48,6 +49,12 @@ #define BSC0_A *(bsc0.addr + 0x03) #define BSC0_FIFO *(bsc0.addr + 0x04) +#define BSC1_C *(bsc1.addr + 0x00) +#define BSC1_S *(bsc1.addr + 0x01) +#define BSC1_DLEN *(bsc1.addr + 0x02) +#define BSC1_A *(bsc1.addr + 0x03) +#define BSC1_FIFO *(bsc1.addr + 0x04) + #define BSC_C_I2CEN (1 << 15) #define BSC_C_INTR (1 << 10) #define BSC_C_INTT (1 << 9) @@ -84,6 +91,7 @@ extern struct bcm2835_peripheral gpio; extern struct bcm2835_peripheral bsc0; +extern struct bcm2835_peripheral bsc1; extern struct bcm2835_peripheral timer_arm; extern void wait_i2c_done(); diff --git a/bmp085.c b/bmp085.c index 5941db5..384a5ee 100755 --- a/bmp085.c +++ b/bmp085.c @@ -36,8 +36,9 @@ printf("Failed to map the physical GPIO registers into the virtual memory space.\n"); return -1; } - if(map_peripheral(&bsc0) == -1) { - printf("Failed to map the physical BSC0 (I2C) registers into the virtual memory space.\n"); + //if(map_peripheral(&bsc0) == -1) { + if(map_peripheral(&bsc1) == -1) { + printf("Failed to map the physical BSC1 (I2C) registers into the virtual memory space.\n"); return -1; } diff --git a/wh1080_rf.h b/wh1080_rf.h index 3371cff..71808e6 100755 --- a/wh1080_rf.h +++ b/wh1080_rf.h @@ -1,5 +1,5 @@ -//#define USE_BMP085 +#define USE_BMP085 //#define ALTITUDE_M 210.0f #define ALTITUDE_M 6.0f diff --git a/wunderground.c b/wunderground.c index 0e277fa..c64a3b1 100644 --- a/wunderground.c +++ b/wunderground.c @@ -30,9 +30,13 @@ void ) { - // fixme - read station id and password from credentials file - strcpy(gStationId, "IHORNSEA3"); - strcpy(gPassword, "LIA80RvnuUY8WpO3peGC"); + // read in credentials + FILE *fp = fopen(CREDENTIALS, "r"); + fgets(gStationId, STATIONIDLENGTH, fp); + strtok(gStationId, "\n"); + fgets(gPassword, PASSWORDLENGTH, fp); + strtok(gPassword, "\n"); + fclose(fp); } // submits an observation