Re: [PATCH v2 2/2] iio: proximity: add support for PulsedLight LIDAR

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Aug 04, 2015 at 06:45:22PM -0700, Matt Ranostay wrote:
> On Tue, Aug 4, 2015 at 1:35 PM, Tristan Lelong <tristan@xxxxxxxxxx> wrote:
> > On Mon, Aug 03, 2015 at 01:21:08AM -0700, Matt Ranostay wrote:
> >> On Sun, Aug 2, 2015 at 11:48 PM, Peter Meerwald <pmeerw@xxxxxxxxxx> wrote:
> >> > On Sun, 2 Aug 2015, Matt Ranostay wrote:
> >> >
> >> >> +
> >> >> +static int lidar_get_measurement(struct lidar_data *data, u16 *reg)
> >> >> +{
> >> >> +     struct i2c_client *client = data->client;
> >> >> +     int tries = 10;
> >> >> +     int ret;
> >> >> +
> >> >> +     /* start sample */
> >> >> +     ret = lidar_write_control(data, LIDAR_REG_CONTROL_ACQUIRE);
> >> >> +     if (ret < 0) {
> >> >> +             dev_err(&client->dev, "cannot send start measurement command");
> >> >> +             return ret;
> >> >> +     }
> >> >> +
> >> >> +     while (tries--) {
> >> >> +             usleep_range(1000, 2000);
> >> >> +
> >> >> +             ret = lidar_read_byte(data, LIDAR_REG_STATUS);
> >> >> +             if (ret < 0)
> >> >> +                     break;
> >> >> +
> >> >> +             /* return 0 since laser is likely pointed out of range */
> >> >> +             if (ret & LIDAR_REG_STATUS_INVALID) {
> >> >> +                     *reg = 0;
> >> >> +                     ret = 0;
> >> >> +                     break;
> >> >> +             }
> >> >> +
> >> >> +             /* sample ready to read */
> >> >> +             if (!(ret & LIDAR_REG_STATUS_READY)) {
> >> >> +                     ret = lidar_read_measurement(data, reg);
> >> >> +                     break;
> >> >> +             }
> >> >> +     }
> >> >> +
> >> >
> >> > what happens when the timeout occurs?
> >> > no error code is set
> >>
> >> Ah yes it should return an error code.  Would a -EIO be a logical choice?
> >>
> >
> > I would think -ETIMEDOUT to make more sense here.
> 
> Isn't that more applicable for a networking driver to use?

IMHO this error code is generic and should be used when a certain operation doesn't provide any result after a determined period of time. 
In your case, no measurement is available after 10 to 20 msec.

It is used in other iio drivers on similar use cases,
Although it often comes after wait_for_completion_timeout, the scenario is pretty similar:
- start measurement
- wait for measure to be ready

Regards
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux