mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 23:03:27 +08:00
Fix wait loop and void cast (#24)
* Simplify EINTR/ECANCEL error handling 1. Add semaphore uninterruptible wait function 2 .Replace semaphore wait loop with a single uninterruptible wait 3. Replace all sem_xxx to nxsem_xxx * Unify the void cast usage 1. Remove void cast for function because many place ignore the returned value witout cast 2. Replace void cast for variable with UNUSED macro
This commit is contained in:
+7
-27
@@ -373,12 +373,7 @@ static int tsc2007_waitsample(FAR struct tsc2007_dev_s *priv,
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
/* If we are awakened by a signal, then we need to return
|
||||
* the failure now.
|
||||
*/
|
||||
|
||||
ierr("ERROR: nxsem_wait failed: %d\n", ret);
|
||||
DEBUGASSERT(ret == -EINTR || ret == -ECANCELED);
|
||||
goto errout;
|
||||
}
|
||||
}
|
||||
@@ -433,7 +428,7 @@ static int tsc2007_activate(FAR struct tsc2007_dev_s *priv, uint8_t cmd)
|
||||
|
||||
/* Ignore errors from the setup command (because it is not ACKed) */
|
||||
|
||||
(void)I2C_TRANSFER(priv->i2c, &msg, 1);
|
||||
I2C_TRANSFER(priv->i2c, &msg, 1);
|
||||
|
||||
/* Now activate the A/D converter */
|
||||
|
||||
@@ -620,7 +615,7 @@ static void tsc2007_worker(FAR void *arg)
|
||||
* in the cases previously listed."
|
||||
*/
|
||||
|
||||
(void)tsc2007_activate(priv, TSC2007_ACTIVATE_X);
|
||||
tsc2007_activate(priv, TSC2007_ACTIVATE_X);
|
||||
y = tsc2007_transfer(priv, TSC2007_MEASURE_Y);
|
||||
|
||||
|
||||
@@ -629,7 +624,7 @@ static void tsc2007_worker(FAR void *arg)
|
||||
* process provides the X and Y coordinates to the associated processor."
|
||||
*/
|
||||
|
||||
(void)tsc2007_activate(priv, TSC2007_ACTIVATE_Y);
|
||||
tsc2007_activate(priv, TSC2007_ACTIVATE_Y);
|
||||
x = tsc2007_transfer(priv, TSC2007_MEASURE_X);
|
||||
|
||||
/* "... To determine pen or finger touch, the pressure of the touch must be
|
||||
@@ -648,14 +643,14 @@ static void tsc2007_worker(FAR void *arg)
|
||||
* Read Z1 and Z2 values.
|
||||
*/
|
||||
|
||||
(void)tsc2007_activate(priv, TSC2007_ACTIVATE_Z);
|
||||
tsc2007_activate(priv, TSC2007_ACTIVATE_Z);
|
||||
z1 = tsc2007_transfer(priv, TSC2007_MEASURE_Z1);
|
||||
(void)tsc2007_activate(priv, TSC2007_ACTIVATE_Z);
|
||||
tsc2007_activate(priv, TSC2007_ACTIVATE_Z);
|
||||
z2 = tsc2007_transfer(priv, TSC2007_MEASURE_Z2);
|
||||
|
||||
/* Power down ADC and enable PENIRQ */
|
||||
|
||||
(void)tsc2007_transfer(priv, TSC2007_ENABLE_PENIRQ);
|
||||
tsc2007_transfer(priv, TSC2007_ENABLE_PENIRQ);
|
||||
|
||||
/* Now calculate the pressure using the first method, reduced to:
|
||||
*
|
||||
@@ -809,10 +804,7 @@ static int tsc2007_open(FAR struct file *filep)
|
||||
ret = nxsem_wait(&priv->devsem);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* This should only happen if the wait was cancelled by an signal */
|
||||
|
||||
ierr("ERROR: nxsem_wait failed: %d\n", ret);
|
||||
DEBUGASSERT(ret == -EINTR || ret == -ECANCELED);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -865,10 +857,7 @@ static int tsc2007_close(FAR struct file *filep)
|
||||
ret = nxsem_wait(&priv->devsem);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* This should only happen if the wait was cancelled by an signal */
|
||||
|
||||
ierr("ERROR: nxsem_wait failed: %d\n", ret);
|
||||
DEBUGASSERT(ret == -EINTR || ret == -ECANCELED);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -923,10 +912,7 @@ static ssize_t tsc2007_read(FAR struct file *filep, FAR char *buffer, size_t len
|
||||
ret = nxsem_wait(&priv->devsem);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* This should only happen if the wait was cancelled by an signal */
|
||||
|
||||
ierr("ERROR: nxsem_wait failed: %d\n", ret);
|
||||
DEBUGASSERT(ret == -EINTR || ret == -ECANCELED);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1040,10 +1026,7 @@ static int tsc2007_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
ret = nxsem_wait(&priv->devsem);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* This should only happen if the wait was cancelled by an signal */
|
||||
|
||||
ierr("ERROR: nxsem_wait failed: %d\n", ret);
|
||||
DEBUGASSERT(ret == -EINTR || ret == -ECANCELED);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1116,10 +1099,7 @@ static int tsc2007_poll(FAR struct file *filep, FAR struct pollfd *fds,
|
||||
ret = nxsem_wait(&priv->devsem);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* This should only happen if the wait was cancelled by an signal */
|
||||
|
||||
ierr("ERROR: nxsem_wait failed: %d\n", ret);
|
||||
DEBUGASSERT(ret == -EINTR || ret == -ECANCELED);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1282,7 +1262,7 @@ int tsc2007_register(FAR struct i2c_master_s *dev,
|
||||
|
||||
/* Register the device as an input device */
|
||||
|
||||
(void)snprintf(devname, DEV_NAMELEN, DEV_FORMAT, minor);
|
||||
snprintf(devname, DEV_NAMELEN, DEV_FORMAT, minor);
|
||||
iinfo("Registering %s\n", devname);
|
||||
|
||||
ret = register_driver(devname, &tsc2007_fops, 0666, priv);
|
||||
|
||||
Reference in New Issue
Block a user