On Sun, 2005-07-03 at 20:17 +0200, Jesper Juhl wrote:
> while (1) {
....
> } else if (time_before(jiffies, wait_until)) {
> set_current_state(TASK_INTERRUPTIBLE);
> schedule_timeout(HZ);
> } else {
Please don't do the manual task state setting. It's preferable to just
use msleep_interruptable(). jiffies and HZ can change with each kernel
configuration, and are not dependable.
I've attached an untested patch that cleans up the init function a bit
(I think).
-- Dave
--- accelerometer.c-0.1.orig 2005-07-03 12:28:28.000000000 -0700
+++ accelerometer.c 2005-07-03 12:33:39.000000000 -0700
@@ -158,45 +158,49 @@
}
/* initialize the accelerometer, wait up to `timeout' seconds for success */
-int accelerometer_init(unsigned int timeout)
+int accelerometer_init(unsigned int timeout_secs)
{
- unsigned long wait_until = jiffies + timeout * HZ;
+ unsigned long total_wait_msecs = timeout_secs * 1000;
+ unsinged msec_per_wait = 10;
+ unsigned long msecs_waited = 0;
+ int ret = -EIO;
outb(0x13, 0x1610);
outb(0x01, 0x161f);
if (!wait_latch(0x00, 0x161f))
- return -EIO;
+ return ret;
if (!wait_latch(0x03, 0x1611))
- return -EIO;
+ return ret;
outb(0x17, 0x1610);
outb(0x81, 0x1611);
outb(0x01, 0x161f);
if (!wait_latch(0x00, 0x161f))
- return -EIO;
+ return ret;
if (!wait_latch(0x00, 0x1611))
- return -EIO;
+ return ret;
if (!wait_latch(0x60, 0x1612))
- return -EIO;
+ return ret;
if (!wait_latch(0x00, 0x1613))
- return -EIO;
+ return ret;
outb(0x14, 0x1610);
outb(0x01, 0x1611);
outb(0x01, 0x161f);
if (!wait_latch(0x00, 0x161f))
- return -EIO;
+ return ret;
outb(0x10, 0x1610);
outb(0xc8, 0x1611);
outb(0x00, 0x1612);
outb(0x02, 0x1613);
outb(0x01, 0x161f);
if (!wait_latch(0x00, 0x161f))
- return -EIO;
+ return ret;
if (!request_refresh(REFRESH_SYNC))
- return -EIO;
+ return ret;
if (!wait_latch(0x00, 0x1611))
- return -EIO;
+ return ret;
- while (1) {
+ ret = -ENXIO;
+ while (msecs_waited <= total_wait_msecs) {
if (wait_latch(0x02, 0x1611)) {
struct hdaps_accel_data data;
/*
@@ -204,15 +208,13 @@
* return success.
*/
accelerometer_read(&data);
- return 0;
- } else if (time_before(jiffies, wait_until)) {
- set_current_state(TASK_INTERRUPTIBLE);
- schedule_timeout(HZ);
- } else {
- /* we timed out, return failure */
- return -ENXIO;
+ ret = 0;
+ break;
}
+ msleep(msecs_per_wait);
+ msecs_waited += msecs_per_wait;
}
+ return ret;
}
static int ibm_hdaps_init(void)
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
|
|