bugblat / pif

FPGA on a Raspberry Pi
http://www.bugblat.com/products/pif
24 stars 8 forks source link

Compiling the software on gcc 4.7.2 #1

Closed ghost closed 10 years ago

ghost commented 10 years ago

I am using the pif-board on my raspberry with archlinux as an operating system. Surely, there are some incompatibilities to expect, and here they are.

Compiling the software for the pif fails with the following compiler error:

pif.cpp: In member function 'bool Tpif::progDone()':
pif.cpp:249:61: error: taking address of temporary array
pif.cpp: In member function 'bool Tpif::refresh()':
pif.cpp:258:59: error: taking address of temporary array
pif.cpp: In member function 'bool Tpif::enableCfgInterfaceOffline()':
pif.cpp:279:59: error: taking address of temporary array
pif.cpp: In member function 'bool Tpif::enableCfgInterfaceTransparent()':
pif.cpp:285:59: error: taking address of temporary array
pif.cpp: In member function 'bool Tpif::_progPage(int, const uint8_t*)':
pif.cpp:312:61: error: taking address of temporary array
pif.cpp: In member function 'bool Tpif::setUsercode(uint8_t*)':
pif.cpp:390:61: error: taking address of temporary array
makefile:17: recipe for target 'pif.o' failed
make: *** [pif.o] Error 1

I checked the source code, and found the calls to the nanosleep() function:

nanosleep((struct timespec[]){{0, (200 * MICROSEC)}}, NULL);

This creates a temporary array of timespec with one entry, and passes it to the const struct timespec* array in the nanosleep() function.

g++ allowed this in versions before 4.6, although passing a temporary object to a non-const reference is, iirc, illegal in C++. Newer versions of g++ throw the above error.

I circumvented this problem by making the temporary array const itself.

nanosleep((const struct timespec[]){{0, (200 * MICROSEC)}}, NULL);

This may not be the most elegant solution, but it should work on all compiler versions.

Kind regards, Jali

b15hop commented 10 years ago

Did you find out why this doesn't work? I also have arch with a PIF. I have both the 1200 and 7000 models on a Revision B raspberry pi.

bugblat commented 10 years ago

Thanks. The nanosleep call is too clever. I should not have been seduced by it. A better wrapper would be

void myNanoSleep(uint32_t ns) {
  struct timespec tim;
  tim.tv_sec = 0;
  tim.tv_nsec = (long)ns;
  nanosleep(&tim, NULL);
  }

I will submit an appropriate fix. Tim