I am writing a linux daemon in C that gets values from ADC using the SPI interface (ioctl). SPI (spidev - userland) seems a little unstable and freezes the daemon at arbitrary points in time.
I need to better control the calls of functions that receive values, and I thought about making it a thread that I could wait to finish and get the return value, and if it expires, suppose it freezes and kills it without this new thread filming the demon himself. Then I could apply measures such as resetting ADC before restarting. Is it possible?
A pseudo example of what I want to achieve:
( int get_adc_value function (int adc_channel, float * value) )
- pid = thread (get_adc_value (1, & value); // makes the thread calling the function
- wait_until_finish (pid, timeout); // waiting for the function to complete / timesout
- if (timeout) kill pid, start over // if the stream does not return at the specified time, kill it (it is frozen)
- else, if the return value is sane, continue // if successful, process the return value of the variable and continue
Thanks for any contribution to the case, examples are highly appreciated!
Einar source
share