The program below compiles and runs, the LED 16 turns on/off when card is inserted, and removed. The part that does not work, 'int CSset'. The use of CSset does not cause an error, but it also does not light up LED 23 when it is used in main(). I guess their is something that I am missing with the workings of pthread, or the understanding of global variables.
You need to put the pin 23 logic in the while(1) loop. Don't you also want to set it low if CSset == 0? And you may need to declare CSset as volatile so the compiler doesn't optimize the test of CSset out of the loop. So your code should look something like this
volatile int CSset;
...
while (1)
{
if (CSset)
high(23);
else
low(23);
}
I just noticed something, I commented out <unistd.h>, and I am still using sleep() in the CheckCS(), but I am not getting any compiler complaints. So, where else does sleep() reside?
You need braces after the "else" in the earlier version of the CheckCS routine. The "CSset = 0" statement is always being executed in the loop independent of the value of the CD signal. BTW, Shouldn't your routine be called CheckCD instead of checkCS, and CSset should be CDset. It's a bit confusing using CS instead of CD.
The function prototype for sleep is in unistd.h, or more precisely, it is in sys/unistd.h, ;which is included by unistd.h. You won't get a warning if the function prototype is missing unless you specify the -Wall compiler flag when you compile.
Comments
Ray
Ray
Ray
The function prototype for sleep is in unistd.h, or more precisely, it is in sys/unistd.h, ;which is included by unistd.h. You won't get a warning if the function prototype is missing unless you specify the -Wall compiler flag when you compile.