Prevent Linux from switching to another task during execution of a certain function

60 Views Asked by At

I made an implementation of 1-wire protocol for the Raspberry Pi adapted from this book. It uses bit banging to implement the communication protocol. The function bcm2835_delayMicroseconds() from the BCM2835 library is used to produced required delays.

It works quite well, but not completely reliable: sometimes i get no response from the sensor. I used an oscilloscope to trace the problem. Here the oscilloscope screenshot with signal interpretation in green. enter image description here The red marks the fault: the bit starting low pulse got prolonged thus inserting a rogue '0'. This caused the sensor not to recognize the command and not to respond to it (subsequent '1's).

I beleive this happend because the OS preempted (switched to another task/thread/process) during transmission of this bit. So is it possible to tell the Linux not to preempt during the execution of a certain function (for writing and reading of a single bit in this case)? Or perhaps there is another solution to this problem?

0

There are 0 best solutions below