Hi joe joe,
There is more than one way to do it. Below is one simple suggestion.
Depending on how accurate your 1-second timing has to be, it may be
all you need. I am sure that others will contribute other, more
elegant and/or more powerful methods.
- Your thread will basically be an infinite loop
- Inside the loop, the following things need to be done
- Use gettimeofday() system function to save the current time
- Send the message over SPI
- Use gettimeofday() to find the elapsed time, to calculate
how many microseconds until next message
- Use the usleep() system function to time out for required
number of microseconds, until the next SPI message has to be
This method assumes that the SPI writing is synchronous. This is why
the 2nd gettimeofday() is necessary, to find out how long the SPI
write took. I've used this type of code for simple things, and so
far it has served pretty well, but on the other hand I'm not
sensitive to jitter of 10s of microseconds in the 1 second
On 10-Aug-2011 00:13, joe joe wrote:
I'm trying to implement a user-space thread whose only task in life is to
write to send some message via the SPI bus once a second.
I imagine I have to get timers involved for this but have no clue how to go
about starting or accessing one through linux. Does anyone have any
pointers for how to go about doing this?