Here's the eigth post in the Build-a-Driver series for MCP9808.
(If this post seems out of context, please refer to "Build-a-Driver Introduction" post.)
The driver needs to delay after changing integration times so that it does not report a temperature in the previous resolution. This fixes a problem found during testing and noted in this post.
I referenced the kernel documentation timers-howto.txt
where I found the RightWay (TM) for adding delays to drivers. It says that if you are sleeping for larger MSECS which it defines as 10ms+, msleep() is the appropriate choice.
We are operating in continuous mode, so we'll use the conversion times as the delay.
Those conversion times range from 30-250 MSECS, so msleep() is the way to go.
From the MCP9808 Data Sheet:
- add the include file linux/delay.h to get access to msleep()
- add the above conversion times to the mcp9808_int_time array
- call msleep() with conversion time plucked out of array whenever we change it; we are already indexed into the array at the correct position to grab the conversion time
This version mcp9808-delay.c
To view complete revision history go here.
Labels: Build-a-Driver, MCP9808