From: joe joe <joe.tijerina@qi...> - 2011-08-10 04:13:38
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?
View this message in context: http://old.nabble.com/Timers-in-linux-tp32231250p32231250.html
Sent from the Gumstix mailing list archive at Nabble.com.
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
o Use gettimeofday() system function to save the current time
o Send the message over SPI
o Use gettimeofday() to find the elapsed time, to calculate how
many microseconds until next message
o Use the usleep() system function to time out for required number
of microseconds, until the next SPI message has to be sent
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 intervals.
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?
Get latest updates about Open Source Projects, Conferences and News.