Browse Source

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.
pull/22/head
Gordon Henderson 12 years ago
parent
commit
c82fb8735d
3 changed files with 56 additions and 80 deletions
  1. +6
    -0
      People
  2. +42
    -13
      build
  3. +8
    -67
      wiringPi/wiringPi.c

+ 6
- 0
People View File

@@ -13,3 +13,9 @@ Chris McSweeny
inside the dealyMicrosecondsHard() function. inside the dealyMicrosecondsHard() function.
And spotting a couple of schoolboy errors in the (experimental) And spotting a couple of schoolboy errors in the (experimental)
softServo code, prompting me to completely re-write it. 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()

+ 42
- 13
build View File

@@ -1,5 +1,34 @@
#!/bin/bash #!/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 if [ x$1 = "xclean" ]; then
echo Cleaning echo Cleaning
echo echo
@@ -23,32 +52,32 @@ elif [ x$1 = "xuninstall" ]; then
cd .. cd ..
else else
echo wiringPi Build script - please wait... echo wiringPi Build script - please wait...

echo echo

# Check for I2C being installed...

if [ ! -f /usr/include/linux/i2c-dev.h ]; then 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 fi


echo "WiringPi library" echo "WiringPi library"
cd wiringPi cd wiringPi
sudo make uninstall sudo make uninstall
make
make
check-make-ok
sudo make install sudo make install
check-make-ok
echo echo
echo "GPIO Utility" echo "GPIO Utility"
cd ../gpio cd ../gpio
make make
check-make-ok
sudo make install sudo make install
check-make-ok
echo echo
echo "Examples" echo "Examples"
cd ../examples cd ../examples


+ 8
- 67
wiringPi/wiringPi.c View File

@@ -1161,7 +1161,7 @@ int wiringPiSetup (void)
{ {
int fd ; int fd ;
int boardRev ; int boardRev ;
uint8_t *gpioMem, *pwmMem, *clkMem, *padsMem, *timerMem ;
//uint8_t *gpioMem, *pwmMem, *clkMem, *padsMem, *timerMem ;
struct timeval tv ; struct timeval tv ;


if (geteuid () != 0) if (geteuid () != 0)
@@ -1210,23 +1210,8 @@ int wiringPiSetup (void)


// GPIO: // 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) if (wiringPiDebug)
fprintf (stderr, "wiringPiSetup: mmap failed: %s\n", strerror (errno)) ; fprintf (stderr, "wiringPiSetup: mmap failed: %s\n", strerror (errno)) ;
@@ -1235,19 +1220,8 @@ int wiringPiSetup (void)


// PWM // 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) if (wiringPiDebug)
fprintf (stderr, "wiringPiSetup: mmap failed (pwm): %s\n", strerror (errno)) ; fprintf (stderr, "wiringPiSetup: mmap failed (pwm): %s\n", strerror (errno)) ;
@@ -1256,18 +1230,7 @@ int wiringPiSetup (void)
// Clock control (needed for PWM) // 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 ((int32_t)clk < 0)
{ {
if (wiringPiDebug) if (wiringPiDebug)
@@ -1277,18 +1240,7 @@ int wiringPiSetup (void)
// The drive pads // 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 ((int32_t)pads < 0)
{ {
if (wiringPiDebug) if (wiringPiDebug)
@@ -1303,18 +1255,7 @@ int wiringPiSetup (void)


// The system timer // 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 ((int32_t)timer < 0)
{ {
if (wiringPiDebug) if (wiringPiDebug)


Loading…
Cancel
Save