From: Gordon Henderson Date: Tue, 15 Jan 2013 22:38:21 +0000 (+0000) Subject: Updated the build script to better try to detect lack of i2c-dev X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;ds=sidebyside;h=c82fb8735d1563d00903cb69f73f99d0a44998dc;p=wiringPi.git Updated the build script to better try to detect lack of i2c-dev (hopefully!) Also updated all the mmap code in wiringPiSetup() to make it a bit more sane and efficient to a degree. --- diff --git a/People b/People index e0c262c..35f8a4c 100644 --- a/People +++ b/People @@ -13,3 +13,9 @@ Chris McSweeny inside the dealyMicrosecondsHard() function. And spotting a couple of schoolboy errors in the (experimental) softServo code, prompting me to completely re-write it. + +Armin (Via projects website) + Some pointers about the i2c-dev.h files. + +Arno Wagner + Suggestions for the mmap calls in wiringPiSetup() diff --git a/build b/build index ad1eff0..cc6804a 100755 --- a/build +++ b/build @@ -1,5 +1,34 @@ #!/bin/bash +i2c-install() +{ + echo "* wiringPi needs the I2C Development Libraires installing." + echo "" + echo "If using Debian/Raspbian, then type this command:" + echo " sudo apt-get install libi2c-dev" + echo "then run ./build again." + echo "" + echo "If using another Linux distribution, then you will have to" + echo "work out how to install the I2C Developmen Libraries for your" + echo "system. (Sorry - I don't know - do let me know though!)" + echo "" + exit 1 +} + +check-make-ok() +{ + if [ $? != 0 ]; then + echo "" + echo "Make Failed..." + echo "Please check the messages and fix any problems. If you're still stuck," + echo "then please email all the output and as many details as you can to" + echo " projects@drogon.net" + echo "" + exit 1 + fi +} + + if [ x$1 = "xclean" ]; then echo Cleaning echo @@ -23,32 +52,32 @@ elif [ x$1 = "xuninstall" ]; then cd .. else echo wiringPi Build script - please wait... - echo + +# Check for I2C being installed... + if [ ! -f /usr/include/linux/i2c-dev.h ]; then - echo "* wiringPi needs the I2C Development Libraires installing." - echo "" - echo "If using Debian/Raspbian, then type this command:" - echo " sudo apt-get install libi2c-dev" - echo "then run ./build again." - echo "" - echo "If using another Linux distribution, then you will have to" - echo "work out how to install the I2C Developmen Libraries for your" - echo "system." - echo "" - exit 1 + i2c-install + fi + grep -q i2c_smbus_read_byte /usr/include/linux/i2c-dev.h + if [ $? = 1 ]; then + i2c-install fi echo "WiringPi library" cd wiringPi sudo make uninstall - make + make + check-make-ok sudo make install + check-make-ok echo echo "GPIO Utility" cd ../gpio make + check-make-ok sudo make install + check-make-ok echo echo "Examples" cd ../examples diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index 066f842..36c49f5 100644 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -1161,7 +1161,7 @@ int wiringPiSetup (void) { int fd ; int boardRev ; - uint8_t *gpioMem, *pwmMem, *clkMem, *padsMem, *timerMem ; + //uint8_t *gpioMem, *pwmMem, *clkMem, *padsMem, *timerMem ; struct timeval tv ; if (geteuid () != 0) @@ -1210,23 +1210,8 @@ int wiringPiSetup (void) // GPIO: -// Allocate 2 pages - 1 ... - - if ((gpioMem = malloc (BLOCK_SIZE + (PAGE_SIZE-1))) == NULL) - { - if (wiringPiDebug) - fprintf (stderr, "wiringPiSetup: malloc failed: %s\n", strerror (errno)) ; - return -1 ; - } - -// ... presumably to make sure we can round it up to a whole page size - - if (((uint32_t)gpioMem % PAGE_SIZE) != 0) - gpioMem += PAGE_SIZE - ((uint32_t)gpioMem % PAGE_SIZE) ; - - gpio = (uint32_t *)mmap((caddr_t)gpioMem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd, GPIO_BASE) ; - - if ((int32_t)gpio < 0) + gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_BASE) ; + if ((int32_t)gpio == -1) { if (wiringPiDebug) fprintf (stderr, "wiringPiSetup: mmap failed: %s\n", strerror (errno)) ; @@ -1235,19 +1220,8 @@ int wiringPiSetup (void) // PWM - if ((pwmMem = malloc (BLOCK_SIZE + (PAGE_SIZE-1))) == NULL) - { - if (wiringPiDebug) - fprintf (stderr, "wiringPiSetup: pwmMem malloc failed: %s\n", strerror (errno)) ; - return -1 ; - } - - if (((uint32_t)pwmMem % PAGE_SIZE) != 0) - pwmMem += PAGE_SIZE - ((uint32_t)pwmMem % PAGE_SIZE) ; - - pwm = (uint32_t *)mmap(pwmMem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd, GPIO_PWM) ; - - if ((int32_t)pwm < 0) + pwm = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PWM) ; + if ((int32_t)pwm == -1) { if (wiringPiDebug) fprintf (stderr, "wiringPiSetup: mmap failed (pwm): %s\n", strerror (errno)) ; @@ -1256,18 +1230,7 @@ int wiringPiSetup (void) // Clock control (needed for PWM) - if ((clkMem = malloc (BLOCK_SIZE + (PAGE_SIZE-1))) == NULL) - { - if (wiringPiDebug) - fprintf (stderr, "wiringPiSetup: clkMem malloc failed: %s\n", strerror (errno)) ; - return -1 ; - } - - if (((uint32_t)clkMem % PAGE_SIZE) != 0) - clkMem += PAGE_SIZE - ((uint32_t)clkMem % PAGE_SIZE) ; - - clk = (uint32_t *)mmap(clkMem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd, CLOCK_BASE) ; - + clk = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, CLOCK_BASE) ; if ((int32_t)clk < 0) { if (wiringPiDebug) @@ -1277,18 +1240,7 @@ int wiringPiSetup (void) // The drive pads - if ((padsMem = malloc (BLOCK_SIZE + (PAGE_SIZE-1))) == NULL) - { - if (wiringPiDebug) - fprintf (stderr, "wiringPiSetup: padsMem malloc failed: %s\n", strerror (errno)) ; - return -1 ; - } - - if (((uint32_t)padsMem % PAGE_SIZE) != 0) - padsMem += PAGE_SIZE - ((uint32_t)padsMem % PAGE_SIZE) ; - - pads = (uint32_t *)mmap(padsMem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd, GPIO_PADS) ; - + pads = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PADS) ; if ((int32_t)pads < 0) { if (wiringPiDebug) @@ -1303,18 +1255,7 @@ int wiringPiSetup (void) // The system timer - if ((timerMem = malloc (BLOCK_SIZE + (PAGE_SIZE-1))) == NULL) - { - if (wiringPiDebug) - fprintf (stderr, "wiringPiSetup: timerMem malloc failed: %s\n", strerror (errno)) ; - return -1 ; - } - - if (((uint32_t)timerMem % PAGE_SIZE) != 0) - timerMem += PAGE_SIZE - ((uint32_t)timerMem % PAGE_SIZE) ; - - timer = (uint32_t *)mmap(timerMem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd, GPIO_TIMER) ; - + timer = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_TIMER) ; if ((int32_t)timer < 0) { if (wiringPiDebug)