Replace nxsem API when used as a lock with nxmutex API

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
anjiahao
2022-09-06 14:18:45 +08:00
committed by Masayuki Ishikawa
parent 0dfd1f004d
commit d1d46335df
710 changed files with 7503 additions and 14852 deletions
+20 -31
View File
@@ -381,7 +381,7 @@ static int ads7843e_waitsample(FAR struct ads7843e_dev_s *priv,
* run, but they cannot run yet because pre-emption is disabled.
*/
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
/* Try to get the a sample... if we cannot, then wait on the semaphore
* that is posted when new sample data is available.
@@ -410,7 +410,7 @@ static int ads7843e_waitsample(FAR struct ads7843e_dev_s *priv,
* sample. Interrupts and pre-emption will be re-enabled while we wait.
*/
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
errout:
/* Then re-enable interrupts. We might get interrupt here and there
@@ -498,7 +498,6 @@ static void ads7843e_worker(FAR void *arg)
uint16_t xdiff;
uint16_t ydiff;
bool pendown;
int ret;
DEBUGASSERT(priv != NULL);
@@ -521,17 +520,7 @@ static void ads7843e_worker(FAR void *arg)
/* Get exclusive access to the driver data structure */
do
{
ret = nxsem_wait_uninterruptible(&priv->devsem);
/* This would only fail if something canceled the worker thread?
* That is not expected.
*/
DEBUGASSERT(ret == OK || ret == -ECANCELED);
}
while (ret < 0);
nxmutex_lock(&priv->devlock);
/* Check for pen up or down by reading the PENIRQ GPIO. */
@@ -677,7 +666,7 @@ ignored:
/* Release our lock on the state structure and unlock the SPI bus */
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
ads7843e_unlock(priv->spi);
}
@@ -742,7 +731,7 @@ static int ads7843e_open(FAR struct file *filep)
/* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -756,7 +745,7 @@ static int ads7843e_open(FAR struct file *filep)
/* More than 255 opens; uint8_t overflows to zero */
ret = -EMFILE;
goto errout_with_sem;
goto errout_with_lock;
}
/* When the reference increments to 1, this is the first open event
@@ -767,8 +756,8 @@ static int ads7843e_open(FAR struct file *filep)
priv->crefs = tmp;
errout_with_sem:
nxsem_post(&priv->devsem);
errout_with_lock:
nxmutex_unlock(&priv->devlock);
return ret;
#else
iinfo("Opening\n");
@@ -796,7 +785,7 @@ static int ads7843e_close(FAR struct file *filep)
/* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -812,7 +801,7 @@ static int ads7843e_close(FAR struct file *filep)
priv->crefs--;
}
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
#endif
iinfo("Closing\n");
return OK;
@@ -854,7 +843,7 @@ static ssize_t ads7843e_read(FAR struct file *filep, FAR char *buffer,
/* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
ierr("ERROR: nxsem_wait: %d\n", ret);
@@ -943,7 +932,7 @@ static ssize_t ads7843e_read(FAR struct file *filep, FAR char *buffer,
ret = SIZEOF_TOUCH_SAMPLE_S(1);
errout:
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
iinfo("Returning: %d\n", ret);
return ret;
}
@@ -967,7 +956,7 @@ static int ads7843e_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
/* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -998,7 +987,7 @@ static int ads7843e_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
break;
}
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return ret;
}
@@ -1023,7 +1012,7 @@ static int ads7843e_poll(FAR struct file *filep, FAR struct pollfd *fds,
/* Are we setting up the poll? Or tearing it down? */
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -1085,7 +1074,7 @@ static int ads7843e_poll(FAR struct file *filep, FAR struct pollfd *fds,
}
errout:
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return ret;
}
@@ -1150,10 +1139,10 @@ int ads7843e_register(FAR struct spi_dev_s *spi,
priv->threshx = INVALID_THRESHOLD; /* Initialize thresholding logic */
priv->threshy = INVALID_THRESHOLD; /* Initialize thresholding logic */
/* Initialize semaphores */
/* Initialize mutex & semaphores */
nxsem_init(&priv->devsem, 0, 1); /* Initialize device structure semaphore */
nxsem_init(&priv->waitsem, 0, 0); /* Initialize pen event wait semaphore */
nxmutex_init(&priv->devlock); /* Initialize device structure mutex */
nxsem_init(&priv->waitsem, 0, 0); /* Initialize pen event wait semaphore */
/* The pen event semaphore is used for signaling and, hence, should not
* have priority inheritance enabled.
@@ -1230,7 +1219,7 @@ int ads7843e_register(FAR struct spi_dev_s *spi,
return OK;
errout_with_priv:
nxsem_destroy(&priv->devsem);
nxmutex_destroy(&priv->devlock);
#ifdef CONFIG_ADS7843E_MULTIPLE
kmm_free(priv);
#endif
+2 -1
View File
@@ -44,6 +44,7 @@
#include <nuttx/wdog.h>
#include <nuttx/clock.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <nuttx/spi/spi.h>
#include <nuttx/input/ads7843e.h>
@@ -134,7 +135,7 @@ struct ads7843e_dev_s
volatile bool penchange; /* An unreported event is buffered */
uint16_t threshx; /* Thresholding X value */
uint16_t threshy; /* Thresholding Y value */
sem_t devsem; /* Manages exclusive access to this structure */
mutex_t devlock; /* Manages exclusive access to this structure */
sem_t waitsem; /* Used to wait for the availability of data */
FAR struct ads7843e_config_s *config; /* Board configuration data */
+16 -17
View File
@@ -191,7 +191,7 @@ struct mbr3108_dev_s
struct mbr3108_board_s *board;
const struct mbr3108_sensor_conf_s *sensor_conf;
sem_t devsem;
mutex_t devlock;
uint8_t cref;
struct mbr3108_debug_conf_s debug_conf;
bool int_pending;
@@ -743,7 +743,7 @@ static ssize_t mbr3108_read(FAR struct file *filep, FAR char *buffer,
DEBUGASSERT(inode && inode->i_private);
priv = inode->i_private;
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -772,7 +772,7 @@ static ssize_t mbr3108_read(FAR struct file *filep, FAR char *buffer,
priv->int_pending = false;
leave_critical_section(flags);
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return ret < 0 ? ret : outlen;
}
@@ -795,7 +795,7 @@ static ssize_t mbr3108_write(FAR struct file *filep, FAR const char *buffer,
return -EINVAL;
}
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -853,7 +853,7 @@ static ssize_t mbr3108_write(FAR struct file *filep, FAR const char *buffer,
}
out:
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return ret < 0 ? ret : buflen;
}
@@ -871,7 +871,7 @@ static int mbr3108_open(FAR struct file *filep)
DEBUGASSERT(inode && inode->i_private);
priv = inode->i_private;
ret = nxsem_wait_uninterruptible(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -885,7 +885,7 @@ static int mbr3108_open(FAR struct file *filep)
ret = priv->board->set_power(priv->board, true);
if (ret < 0)
{
goto out_sem;
goto out_lock;
}
/* Let chip to power up before probing */
@@ -900,7 +900,7 @@ static int mbr3108_open(FAR struct file *filep)
/* No such device. Power off the switch. */
priv->board->set_power(priv->board, false);
goto out_sem;
goto out_lock;
}
if (priv->sensor_conf)
@@ -913,7 +913,7 @@ static int mbr3108_open(FAR struct file *filep)
/* Configuration failed. Power off the switch. */
priv->board->set_power(priv->board, false);
goto out_sem;
goto out_lock;
}
}
@@ -927,8 +927,8 @@ static int mbr3108_open(FAR struct file *filep)
ret = 0;
}
out_sem:
nxsem_post(&priv->devsem);
out_lock:
nxmutex_unlock(&priv->devlock);
return ret;
}
@@ -945,7 +945,7 @@ static int mbr3108_close(FAR struct file *filep)
DEBUGASSERT(inode && inode->i_private);
priv = inode->i_private;
ret = nxsem_wait_uninterruptible(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -976,8 +976,7 @@ static int mbr3108_close(FAR struct file *filep)
priv->cref = use_count;
}
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return 0;
}
@@ -996,7 +995,7 @@ static int mbr3108_poll(FAR struct file *filep, FAR struct pollfd *fds,
DEBUGASSERT(inode && inode->i_private);
priv = (FAR struct mbr3108_dev_s *)inode->i_private;
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -1060,7 +1059,7 @@ static int mbr3108_poll(FAR struct file *filep, FAR struct pollfd *fds,
}
out:
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return ret;
}
@@ -1108,7 +1107,7 @@ int cypress_mbr3108_register(FAR const char *devpath,
priv->board = board_config;
priv->sensor_conf = sensor_conf;
nxsem_init(&priv->devsem, 0, 1);
nxmutex_init(&priv->devlock);
ret = register_driver(devpath, &g_mbr3108_fileops, 0666, priv);
if (ret < 0)
+26 -35
View File
@@ -55,6 +55,7 @@
#include <nuttx/arch.h>
#include <nuttx/fs/fs.h>
#include <nuttx/i2c/i2c_master.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <nuttx/wqueue.h>
#include <nuttx/wdog.h>
@@ -106,7 +107,7 @@ struct ft5x06_dev_s
int16_t lastx; /* Last reported X position */
int16_t lasty; /* Last reported Y position */
#endif
sem_t devsem; /* Manages exclusive access to
mutex_t devlock; /* Manages exclusive access to
* this structure */
sem_t waitsem; /* Used to wait for the
* availability of data */
@@ -245,17 +246,7 @@ static void ft5x06_data_worker(FAR void *arg)
* corrupt any read operation that is in place.
*/
do
{
ret = nxsem_wait_uninterruptible(&priv->devsem);
/* This would only fail if something canceled the worker thread?
* That is not expected.
*/
DEBUGASSERT(ret == OK || ret == -ECANCELED);
}
while (ret < 0);
nxmutex_lock(&priv->devlock);
/* Read touch data */
@@ -340,7 +331,7 @@ static void ft5x06_data_worker(FAR void *arg)
config->enable(config, true);
#endif
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
}
/****************************************************************************
@@ -627,7 +618,7 @@ static ssize_t ft5x06_waitsample(FAR struct ft5x06_dev_s *priv,
* run, but they cannot run yet because pre-emption is disabled.
*/
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
/* Try to get the a sample... if we cannot, then wait on the semaphore
* that is posted when new sample data is available.
@@ -656,7 +647,7 @@ static ssize_t ft5x06_waitsample(FAR struct ft5x06_dev_s *priv,
* sample. Interrupts and pre-emption will be re-enabled while we wait.
*/
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret >= 0)
{
/* Now sample the data.
@@ -763,10 +754,10 @@ static int ft5x06_open(FAR struct file *filep)
/* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
ierr("ERROR: nxsem_wait failed: %d\n", ret);
ierr("ERROR: nxmutex_lock failed: %d\n", ret);
return ret;
}
@@ -778,7 +769,7 @@ static int ft5x06_open(FAR struct file *filep)
/* More than 255 opens; uint8_t overflows to zero */
ret = -EMFILE;
goto errout_with_sem;
goto errout_with_lock;
}
/* When the reference increments to 1, this is the first open event
@@ -791,7 +782,7 @@ static int ft5x06_open(FAR struct file *filep)
if (ret < 0)
{
ierr("ERROR: ft5x06_bringup failed: %d\n", ret);
goto errout_with_sem;
goto errout_with_lock;
}
}
@@ -799,8 +790,8 @@ static int ft5x06_open(FAR struct file *filep)
priv->crefs = tmp;
errout_with_sem:
nxsem_post(&priv->devsem);
errout_with_lock:
nxmutex_unlock(&priv->devlock);
return ret;
}
@@ -822,10 +813,10 @@ static int ft5x06_close(FAR struct file *filep)
/* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
ierr("ERROR: nxsem_wait failed: %d\n", ret);
ierr("ERROR: nxmutex_lock failed: %d\n", ret);
return ret;
}
@@ -847,7 +838,7 @@ static int ft5x06_close(FAR struct file *filep)
ft5x06_shutdown(priv);
}
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return OK;
}
@@ -883,10 +874,10 @@ static ssize_t ft5x06_read(FAR struct file *filep, FAR char *buffer,
/* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
ierr("ERROR: nxsem_wait failed: %d\n", ret);
ierr("ERROR: nxmutex_lock failed: %d\n", ret);
return ret;
}
@@ -920,7 +911,7 @@ static ssize_t ft5x06_read(FAR struct file *filep, FAR char *buffer,
ret = SIZEOF_TOUCH_SAMPLE_S(1);
errout:
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return ret;
}
@@ -943,10 +934,10 @@ static int ft5x06_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
/* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
ierr("ERROR: nxsem_wait failed: %d\n", ret);
ierr("ERROR: nxmutex_lock failed: %d\n", ret);
return ret;
}
@@ -975,7 +966,7 @@ static int ft5x06_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
break;
}
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return ret;
}
@@ -1000,10 +991,10 @@ static int ft5x06_poll(FAR struct file *filep, FAR struct pollfd *fds,
/* Are we setting up the poll? Or tearing it down? */
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
ierr("ERROR: nxsem_wait failed: %d\n", ret);
ierr("ERROR: nxmutex_lock failed: %d\n", ret);
return ret;
}
@@ -1066,7 +1057,7 @@ static int ft5x06_poll(FAR struct file *filep, FAR struct pollfd *fds,
}
errout:
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return ret;
}
@@ -1132,7 +1123,7 @@ int ft5x06_register(FAR struct i2c_master_s *i2c,
priv->config = config; /* Save the board configuration */
priv->frequency = config->frequency; /* Set the current I2C frequency */
nxsem_init(&priv->devsem, 0, 1); /* Initialize device structure semaphore */
nxmutex_init(&priv->devlock); /* Initialize device structure mutex */
nxsem_init(&priv->waitsem, 0, 0); /* Initialize pen event wait semaphore */
/* The event wait semaphore is used for signaling and, hence, should not
@@ -1190,7 +1181,7 @@ int ft5x06_register(FAR struct i2c_master_s *i2c,
return OK;
errout_with_priv:
nxsem_destroy(&priv->devsem);
nxmutex_destroy(&priv->devlock);
kmm_free(priv);
return ret;
}
+28 -28
View File
@@ -33,7 +33,7 @@
#include <nuttx/kmalloc.h>
#include <nuttx/list.h>
#include <nuttx/mm/circbuf.h>
#include <nuttx/semaphore.h>
#include <nuttx/mutex.h>
/****************************************************************************
* Pre-processor Definitions
@@ -46,7 +46,7 @@
struct keyboard_opriv_s
{
sem_t waitsem;
sem_t locksem;
mutex_t lock;
struct circbuf_s circ;
struct list_node node;
FAR struct pollfd *fds;
@@ -56,11 +56,11 @@ struct keyboard_opriv_s
struct keyboard_upperhalf_s
{
sem_t exclsem; /* Manages exclusive access to this structure */
struct list_node head; /* Head of list */
mutex_t lock; /* Manages exclusive access to this structure */
struct list_node head; /* Head of list */
FAR struct keyboard_lowerhalf_s
*lower; /* A pointer of lower half instance */
uint8_t nums; /* Number of buffer */
*lower; /* A pointer of lower half instance */
uint8_t nums; /* Number of buffer */
};
/****************************************************************************
@@ -109,7 +109,7 @@ static int keyboard_open(FAR struct file *filep)
FAR struct keyboard_upperhalf_s *upper = inode->i_private;
int ret;
ret = nxsem_wait(&upper->exclsem);
ret = nxmutex_lock(&upper->lock);
if (ret < 0)
{
return ret;
@@ -118,7 +118,7 @@ static int keyboard_open(FAR struct file *filep)
opriv = kmm_zalloc(sizeof(FAR struct keyboard_opriv_s));
if (opriv == NULL)
{
nxsem_post(&upper->exclsem);
nxmutex_unlock(&upper->lock);
return -ENOMEM;
}
@@ -128,7 +128,7 @@ static int keyboard_open(FAR struct file *filep)
if (ret < 0)
{
kmm_free(opriv);
nxsem_post(&upper->exclsem);
nxmutex_unlock(&upper->lock);
return ret;
}
@@ -140,18 +140,18 @@ static int keyboard_open(FAR struct file *filep)
if (ret < 0)
{
kmm_free(opriv);
nxsem_post(&upper->exclsem);
nxmutex_unlock(&upper->lock);
return ret;
}
}
nxsem_init(&opriv->waitsem, 0, 0);
nxsem_init(&opriv->locksem, 0, 1);
nxmutex_init(&opriv->lock);
nxsem_set_protocol(&opriv->waitsem, SEM_PRIO_NONE);
list_add_tail(&upper->head, &opriv->node);
filep->f_priv = opriv;
nxsem_post(&upper->exclsem);
nxmutex_unlock(&upper->lock);
return ret;
}
@@ -166,7 +166,7 @@ static int keyboard_close(FAR struct file *filep)
FAR struct keyboard_upperhalf_s *upper = inode->i_private;
int ret;
ret = nxsem_wait(&upper->exclsem);
ret = nxmutex_lock(&upper->lock);
if (ret < 0)
{
return ret;
@@ -186,11 +186,11 @@ static int keyboard_close(FAR struct file *filep)
list_delete(&opriv->node);
circbuf_uninit(&opriv->circ);
nxsem_destroy(&opriv->waitsem);
nxsem_destroy(&opriv->locksem);
nxmutex_destroy(&opriv->lock);
kmm_free(opriv);
out:
nxsem_post(&upper->exclsem);
nxmutex_unlock(&upper->lock);
return ret;
}
@@ -206,7 +206,7 @@ static ssize_t keyboard_read(FAR struct file *filep,
/* Make sure that we have exclusive access to the private data structure */
ret = nxsem_wait(&opriv->locksem);
ret = nxmutex_lock(&opriv->lock);
if (ret < 0)
{
return ret;
@@ -223,14 +223,14 @@ static ssize_t keyboard_read(FAR struct file *filep,
}
else
{
nxsem_post(&opriv->locksem);
nxmutex_unlock(&opriv->lock);
ret = nxsem_wait_uninterruptible(&opriv->waitsem);
if (ret < 0)
{
return ret;
}
ret = nxsem_wait(&opriv->locksem);
ret = nxmutex_lock(&opriv->lock);
if (ret < 0)
{
return ret;
@@ -241,7 +241,7 @@ static ssize_t keyboard_read(FAR struct file *filep,
ret = circbuf_read(&opriv->circ, buff, len);
out:
nxsem_post(&opriv->locksem);
nxmutex_unlock(&opriv->lock);
return ret;
}
@@ -255,7 +255,7 @@ static int keyboard_poll(FAR struct file *filep,
FAR struct keyboard_opriv_s *opriv = filep->f_priv;
int ret;
ret = nxsem_wait(&opriv->locksem);
ret = nxmutex_lock(&opriv->lock);
if (ret < 0)
{
return ret;
@@ -286,7 +286,7 @@ static int keyboard_poll(FAR struct file *filep,
}
errout:
nxsem_post(&opriv->locksem);
nxmutex_unlock(&opriv->lock);
return ret;
}
@@ -341,12 +341,12 @@ int keyboard_register(FAR struct keyboard_lowerhalf_s *lower,
upper->nums = nums;
lower->priv = upper;
list_initialize(&upper->head);
nxsem_init(&upper->exclsem, 0, 1);
nxmutex_init(&upper->lock);
ret = register_driver(path, &g_keyboard_fops, 0666, upper);
if (ret < 0)
{
nxsem_destroy(&upper->exclsem);
nxmutex_destroy(&upper->lock);
kmm_free(upper);
return ret;
}
@@ -376,7 +376,7 @@ int keyboard_unregister(FAR struct keyboard_lowerhalf_s *lower,
return ret;
}
nxsem_destroy(&upper->exclsem);
nxmutex_destroy(&upper->lock);
kmm_free(upper);
return 0;
}
@@ -393,7 +393,7 @@ void keyboard_event(FAR struct keyboard_lowerhalf_s *lower, uint32_t keycode,
struct keyboard_event_s key;
int semcount;
if (nxsem_wait(&upper->exclsem) < 0)
if (nxmutex_lock(&upper->lock) < 0)
{
return;
}
@@ -402,7 +402,7 @@ void keyboard_event(FAR struct keyboard_lowerhalf_s *lower, uint32_t keycode,
key.type = type;
list_for_every_entry(&upper->head, opriv, struct keyboard_opriv_s, node)
{
if (nxsem_wait(&opriv->locksem) == 0)
if (nxmutex_lock(&opriv->lock) == 0)
{
circbuf_overwrite(&opriv->circ, &key,
sizeof(struct keyboard_event_s));
@@ -413,9 +413,9 @@ void keyboard_event(FAR struct keyboard_lowerhalf_s *lower, uint32_t keycode,
}
poll_notify(&opriv->fds, 1, POLLIN);
nxsem_post(&opriv->locksem);
nxmutex_unlock(&opriv->lock);
}
}
nxsem_post(&upper->exclsem);
nxmutex_unlock(&upper->lock);
}
+20 -30
View File
@@ -338,7 +338,7 @@ static int max11802_waitsample(FAR struct max11802_dev_s *priv,
* run, but they cannot run yet because pre-emption is disabled.
*/
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
/* Try to get the a sample... if we cannot, then wait on the semaphore
* that is posted when new sample data is available.
@@ -367,7 +367,7 @@ static int max11802_waitsample(FAR struct max11802_dev_s *priv,
* sample. Interrupts and pre-emption will be re-enabled while we wait.
*/
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
errout:
/* Then re-enable interrupts. We might get interrupt here and there
@@ -483,17 +483,7 @@ static void max11802_worker(FAR void *arg)
/* Get exclusive access to the driver data structure */
do
{
ret = nxsem_wait_uninterruptible(&priv->devsem);
/* This would only fail if something canceled the worker thread?
* That is not expected.
*/
DEBUGASSERT(ret == OK || ret == -ECANCELED);
}
while (ret < 0);
nxmutex_lock(&priv->devlock);
/* Check for pen up or down by reading the PENIRQ GPIO. */
@@ -669,7 +659,7 @@ ignored:
/* Release our lock on the state structure and unlock the SPI bus */
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
max11802_unlock(priv->spi);
}
@@ -734,7 +724,7 @@ static int max11802_open(FAR struct file *filep)
/* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -748,7 +738,7 @@ static int max11802_open(FAR struct file *filep)
/* More than 255 opens; uint8_t overflows to zero */
ret = -EMFILE;
goto errout_with_sem;
goto errout_with_lock;
}
/* When the reference increments to 1, this is the first open event
@@ -759,8 +749,8 @@ static int max11802_open(FAR struct file *filep)
priv->crefs = tmp;
errout_with_sem:
nxsem_post(&priv->devsem);
errout_with_lock:
nxmutex_unlock(&priv->devlock);
return ret;
#else
iinfo("Opening\n");
@@ -788,7 +778,7 @@ static int max11802_close(FAR struct file *filep)
/* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -804,7 +794,7 @@ static int max11802_close(FAR struct file *filep)
priv->crefs--;
}
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
#endif
iinfo("Closing\n");
return OK;
@@ -846,7 +836,7 @@ static ssize_t max11802_read(FAR struct file *filep, FAR char *buffer,
/* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
ierr("ERROR: nxsem_wait: %d\n", ret);
@@ -935,7 +925,7 @@ static ssize_t max11802_read(FAR struct file *filep, FAR char *buffer,
ret = SIZEOF_TOUCH_SAMPLE_S(1);
errout:
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
iinfo("Returning: %d\n", ret);
return ret;
}
@@ -959,7 +949,7 @@ static int max11802_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
/* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -990,7 +980,7 @@ static int max11802_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
break;
}
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return ret;
}
@@ -1015,7 +1005,7 @@ static int max11802_poll(FAR struct file *filep, FAR struct pollfd *fds,
/* Are we setting up the poll? Or tearing it down? */
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -1077,7 +1067,7 @@ static int max11802_poll(FAR struct file *filep, FAR struct pollfd *fds,
}
errout:
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return ret;
}
@@ -1142,10 +1132,10 @@ int max11802_register(FAR struct spi_dev_s *spi,
priv->threshx = INVALID_THRESHOLD; /* Initialize thresholding logic */
priv->threshy = INVALID_THRESHOLD; /* Initialize thresholding logic */
/* Initialize semaphores */
/* Initialize mutex & semaphores */
nxsem_init(&priv->devsem, 0, 1); /* Initialize device structure semaphore */
nxsem_init(&priv->waitsem, 0, 0); /* Initialize pen event wait semaphore */
nxmutex_init(&priv->devlock); /* Initialize device structure mutex */
nxsem_init(&priv->waitsem, 0, 0); /* Initialize pen event wait semaphore */
/* The pen event semaphore is used for signaling and, hence, should not
* have priority inheritance enabled.
@@ -1263,7 +1253,7 @@ int max11802_register(FAR struct spi_dev_s *spi,
return OK;
errout_with_priv:
nxsem_destroy(&priv->devsem);
nxmutex_destroy(&priv->devlock);
#ifdef CONFIG_MAX11802_MULTIPLE
kmm_free(priv);
#endif
+2 -1
View File
@@ -38,6 +38,7 @@
#include <nuttx/wdog.h>
#include <nuttx/clock.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <nuttx/spi/spi.h>
#include <nuttx/input/max11802.h>
@@ -120,7 +121,7 @@ struct max11802_dev_s
volatile bool penchange; /* An unreported event is buffered */
uint16_t threshx; /* Thresholding X value */
uint16_t threshy; /* Thresholding Y value */
sem_t devsem; /* Manages exclusive access to this structure */
mutex_t devlock; /* Manages exclusive access to this structure */
sem_t waitsem; /* Used to wait for the availability of data */
FAR struct max11802_config_s *config; /* Board configuration data */
+25 -34
View File
@@ -44,6 +44,7 @@
#include <nuttx/irq.h>
#include <nuttx/kmalloc.h>
#include <nuttx/mutex.h>
#include <nuttx/arch.h>
#include <nuttx/fs/fs.h>
#include <nuttx/i2c/i2c_master.h>
@@ -188,7 +189,7 @@ struct mxt_dev_s
#endif
volatile bool event; /* True: An unreported event is buffered */
sem_t devsem; /* Manages exclusive access to this structure */
mutex_t devlock; /* Manages exclusive access to this structure */
sem_t waitsem; /* Used to wait for the availability of data */
uint32_t frequency; /* Current I2C frequency */
@@ -669,7 +670,7 @@ static inline int mxt_waitsample(FAR struct mxt_dev_s *priv)
* run, but they cannot run yet because pre-emption is disabled.
*/
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
/* Try to get the a sample... if we cannot, then wait on the semaphore
* that is posted when new sample data is available.
@@ -694,7 +695,7 @@ static inline int mxt_waitsample(FAR struct mxt_dev_s *priv)
* sample. Interrupts and pre-emption will be re-enabled while we wait.
*/
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
errout:
/* Then re-enable interrupts. We might get interrupt here and there
@@ -969,17 +970,7 @@ static void mxt_worker(FAR void *arg)
/* Get exclusive access to the MXT driver data structure */
do
{
ret = nxsem_wait_uninterruptible(&priv->devsem);
/* This would only fail if something canceled the worker thread?
* That is not expected.
*/
DEBUGASSERT(ret == OK || ret == -ECANCELED);
}
while (ret < 0);
nxmutex_lock(&priv->devlock);
/* Loop, processing each message from the maXTouch */
@@ -992,7 +983,7 @@ static void mxt_worker(FAR void *arg)
if (ret < 0)
{
ierr("ERROR: mxt_getmessage failed: %d\n", ret);
goto errout_with_semaphore;
goto errout_with_lock;
}
id = msg.id;
@@ -1054,11 +1045,11 @@ static void mxt_worker(FAR void *arg)
}
while (id != 0xff && retries < 16);
errout_with_semaphore:
errout_with_lock:
/* Release our lock on the MXT device */
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
/* Acknowledge and re-enable maXTouch interrupts */
@@ -1122,7 +1113,7 @@ static int mxt_open(FAR struct file *filep)
/* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -1137,7 +1128,7 @@ static int mxt_open(FAR struct file *filep)
ierr("ERROR: Too many opens: %d\n", priv->crefs);
ret = -EMFILE;
goto errout_with_sem;
goto errout_with_lock;
}
/* When the reference increments to 1, this is the first open event
@@ -1152,7 +1143,7 @@ static int mxt_open(FAR struct file *filep)
if (ret < 0)
{
ierr("ERROR: Failed to enable touch: %d\n", ret);
goto errout_with_sem;
goto errout_with_lock;
}
/* Clear any pending messages by reading all messages. This will
@@ -1165,7 +1156,7 @@ static int mxt_open(FAR struct file *filep)
{
ierr("ERROR: mxt_flushmsgs failed: %d\n", ret);
mxt_putobject(priv, MXT_TOUCH_MULTI_T9, MXT_TOUCH_CTRL, 0);
goto errout_with_sem;
goto errout_with_lock;
}
/* Enable touch interrupts */
@@ -1177,8 +1168,8 @@ static int mxt_open(FAR struct file *filep)
priv->crefs = tmp;
errout_with_sem:
nxsem_post(&priv->devsem);
errout_with_lock:
nxmutex_unlock(&priv->devlock);
return ret;
}
@@ -1200,7 +1191,7 @@ static int mxt_close(FAR struct file *filep)
/* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -1229,7 +1220,7 @@ static int mxt_close(FAR struct file *filep)
}
}
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return OK;
}
@@ -1268,7 +1259,7 @@ static ssize_t mxt_read(FAR struct file *filep, FAR char *buffer, size_t len)
/* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -1466,7 +1457,7 @@ static ssize_t mxt_read(FAR struct file *filep, FAR char *buffer, size_t len)
errout:
sched_unlock();
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return ret;
}
@@ -1489,7 +1480,7 @@ static int mxt_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
/* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -1521,7 +1512,7 @@ static int mxt_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
break;
}
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return ret;
}
@@ -1546,7 +1537,7 @@ static int mxt_poll(FAR struct file *filep, FAR struct pollfd *fds,
/* Are we setting up the poll? Or tearing it down? */
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -1611,7 +1602,7 @@ static int mxt_poll(FAR struct file *filep, FAR struct pollfd *fds,
}
errout:
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return ret;
}
@@ -1868,9 +1859,9 @@ int mxt_register(FAR struct i2c_master_s *i2c,
priv->i2c = i2c; /* Save the SPI device handle */
priv->lower = lower; /* Save the board configuration */
/* Initialize semaphores */
/* Initialize mutex & semaphores */
nxsem_init(&priv->devsem, 0, 1); /* Initialize device semaphore */
nxmutex_init(&priv->devlock); /* Initialize device mutex */
nxsem_init(&priv->waitsem, 0, 0); /* Initialize event wait semaphore */
/* The event wait semaphore is used for signaling and, hence, should not
@@ -1928,7 +1919,7 @@ errout_with_hwinit:
errout_with_irq:
MXT_DETACH(lower);
errout_with_priv:
nxsem_destroy(&priv->devsem);
nxmutex_destroy(&priv->devlock);
nxsem_destroy(&priv->waitsem);
kmm_free(priv);
return ret;
+20 -33
View File
@@ -43,6 +43,7 @@
#include <debug.h>
#include <nuttx/kmalloc.h>
#include <nuttx/mutex.h>
#include <nuttx/signal.h>
#include <nuttx/random.h>
#include <nuttx/fs/fs.h>
@@ -61,7 +62,7 @@ struct nunchuck_dev_s
{
FAR struct i2c_master_s *i2c_dev; /* I2C interface connected to Nunchuck */
nunchuck_buttonset_t nck_sample; /* Last sampled button states */
sem_t nck_exclsem; /* Supports exclusive access to the device */
mutex_t nck_lock; /* Supports exclusive access to the device */
/* The following is a singly linked list of open references to the
* joystick device.
@@ -87,11 +88,6 @@ struct nunchuck_open_s
* Private Function Prototypes
****************************************************************************/
/* Semaphore helpers */
static inline int nunchuck_takesem(sem_t *sem);
#define nunchuck_givesem(s) nxsem_post(s);
/* Character driver methods */
static int nunchuck_open(FAR struct file *filep);
@@ -272,15 +268,6 @@ static int nunchuck_sample(FAR struct nunchuck_dev_s *priv,
return OK;
}
/****************************************************************************
* Name: nunchuck_takesem
****************************************************************************/
static inline int nunchuck_takesem(sem_t *sem)
{
return nxsem_wait(sem);
}
/****************************************************************************
* Name: nunchuck_open
****************************************************************************/
@@ -299,10 +286,10 @@ static int nunchuck_open(FAR struct file *filep)
/* Get exclusive access to the driver structure */
ret = nunchuck_takesem(&priv->nck_exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
ierr("ERROR: nunchuck_takesem failed: %d\n", ret);
ierr("ERROR: nxmutex_lock failed: %d\n", ret);
return ret;
}
@@ -314,7 +301,7 @@ static int nunchuck_open(FAR struct file *filep)
{
ierr("ERROR: Failed to allocate open structure\n");
ret = -ENOMEM;
goto errout_with_sem;
goto errout_with_excllock;
}
/* Attach the open structure to the device */
@@ -327,8 +314,8 @@ static int nunchuck_open(FAR struct file *filep)
filep->f_priv = (FAR void *)opriv;
ret = OK;
errout_with_sem:
nunchuck_givesem(&priv->nck_exclsem);
errout_with_excllock:
nxmutex_unlock(&priv->lock);
return ret;
}
@@ -377,10 +364,10 @@ static int nunchuck_close(FAR struct file *filep)
/* Get exclusive access to the driver structure */
ret = nunchuck_takesem(&priv->nck_exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
ierr("ERROR: nunchuck_takesem failed: %d\n", ret);
ierr("ERROR: nxmutex_lock failed: %d\n", ret);
return ret;
}
@@ -395,7 +382,7 @@ static int nunchuck_close(FAR struct file *filep)
{
ierr("ERROR: Failed to find open entry\n");
ret = -ENOENT;
goto errout_with_exclsem;
goto errout_with_excllock;
}
/* Remove the structure from the device */
@@ -415,8 +402,8 @@ static int nunchuck_close(FAR struct file *filep)
ret = OK;
errout_with_exclsem:
nunchuck_givesem(&priv->nck_exclsem);
errout_with_excllock:
nxmutex_unlock(&priv->lock);
return ret;
}
@@ -450,10 +437,10 @@ static ssize_t nunchuck_read(FAR struct file *filep, FAR char *buffer,
/* Get exclusive access to the driver structure */
ret = nunchuck_takesem(&priv->nck_exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
ierr("ERROR: nunchuck_takesem failed: %d\n", ret);
ierr("ERROR: nxmutex_lock failed: %d\n", ret);
return ret;
}
@@ -465,7 +452,7 @@ static ssize_t nunchuck_read(FAR struct file *filep, FAR char *buffer,
ret = sizeof(struct nunchuck_sample_s);
}
nunchuck_givesem(&priv->nck_exclsem);
nxmutex_unlock(&priv->lock);
return (ssize_t)ret;
}
@@ -486,10 +473,10 @@ static int nunchuck_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
/* Get exclusive access to the driver structure */
ret = nunchuck_takesem(&priv->nck_exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
ierr("ERROR: nunchuck_takesem failed: %d\n", ret);
ierr("ERROR: nxmutex_lock failed: %d\n", ret);
return ret;
}
@@ -525,7 +512,7 @@ static int nunchuck_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
break;
}
nunchuck_givesem(&priv->nck_exclsem);
nxmutex_unlock(&priv->lock);
return ret;
}
@@ -577,7 +564,7 @@ int nunchuck_register(FAR const char *devname, FAR struct i2c_master_s *i2c)
/* Initialize the new nunchuck driver instance */
nxsem_init(&priv->nck_exclsem, 0, 1);
nxmutex_init(&priv->nck_lock);
/* And register the nunchuck driver */
@@ -591,7 +578,7 @@ int nunchuck_register(FAR const char *devname, FAR struct i2c_master_s *i2c)
return OK;
errout_with_priv:
nxsem_destroy(&priv->nck_exclsem);
nxmutex_destroy(&priv->nck_lock);
kmm_free(priv);
return ret;
}
+15 -14
View File
@@ -37,6 +37,7 @@
#include <nuttx/i2c/i2c_master.h>
#include <nuttx/fs/fs.h>
#include <nuttx/kmalloc.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
/****************************************************************************
@@ -181,10 +182,10 @@ struct spq10kbd_dev_s
djoy_buttonset_t djoystate; /* Joystick button state */
#endif /* CONFIG_SPQ10KBD_DJOY */
sem_t exclsem; /* Exclusive access to dev */
sem_t waitsem; /* Signal waiting thread */
bool waiting; /* Waiting for keyboard data */
struct work_s work; /* Supports the interrupt handling "bottom half" */
mutex_t lock; /* Exclusive access to dev */
sem_t waitsem; /* Signal waiting thread */
bool waiting; /* Waiting for keyboard data */
struct work_s work; /* Supports the interrupt handling "bottom half" */
/* The following is a list if poll structures of threads waiting for
* driver events. The 'struct pollfd' reference for each open is also
@@ -331,7 +332,7 @@ static void spq10kbd_worker(FAR void *arg)
uint8_t state;
int ret;
ret = nxsem_wait_uninterruptible(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return;
@@ -410,7 +411,7 @@ static void spq10kbd_worker(FAR void *arg)
/* Clear interrupt status register */
spq10kbd_putreg8(priv, SPQ10KBD_INT, 0);
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
}
/****************************************************************************
@@ -513,7 +514,7 @@ static ssize_t spq10kbd_read(FAR struct file *filep, FAR char *buffer,
/* Read data from our internal buffer of received characters */
ret = nxsem_wait_uninterruptible(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
@@ -533,14 +534,14 @@ static ssize_t spq10kbd_read(FAR struct file *filep, FAR char *buffer,
else
{
priv->waiting = true;
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
ret = nxsem_wait_uninterruptible(&priv->waitsem);
if (ret < 0)
{
return ret;
}
ret = nxsem_wait_uninterruptible(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
@@ -571,7 +572,7 @@ static ssize_t spq10kbd_read(FAR struct file *filep, FAR char *buffer,
priv->tailndx = tail;
errout:
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return ret;
}
@@ -614,7 +615,7 @@ static int spq10kbd_poll(FAR struct file *filep, FAR struct pollfd *fds,
/* Make sure that we have exclusive access to the private data structure */
DEBUGASSERT(priv);
ret = nxsem_wait_uninterruptible(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
@@ -670,7 +671,7 @@ static int spq10kbd_poll(FAR struct file *filep, FAR struct pollfd *fds,
}
errout:
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return ret;
}
@@ -1001,7 +1002,7 @@ int spq10kbd_register(FAR struct i2c_master_s *i2c,
priv->djoystate = 0;
#endif /* CONFIG_SPQ10KBD_DJOY */
nxsem_init(&priv->exclsem, 0, 1); /* Initialize device semaphore */
nxmutex_init(&priv->lock); /* Initialize device mutex */
nxsem_init(&priv->waitsem, 0, 0);
/* The waitsem semaphore is used for signaling and, hence, should
@@ -1049,7 +1050,7 @@ int spq10kbd_register(FAR struct i2c_master_s *i2c,
return OK;
errout_with_priv:
nxsem_destroy(&priv->exclsem);
nxmutex_destroy(&priv->lock);
kmm_free(priv);
return ret;
}
+2 -1
View File
@@ -32,6 +32,7 @@
#include <nuttx/config.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <nuttx/wdog.h>
#include <nuttx/clock.h>
@@ -119,7 +120,7 @@ struct stmpe811_dev_s
/* Common fields */
FAR struct stmpe811_config_s *config; /* Board configuration data */
sem_t exclsem; /* Manages exclusive access to this structure */
mutex_t lock; /* Manages exclusive access to this structure */
#ifdef CONFIG_STMPE811_SPI
FAR struct spi_dev_s *spi; /* Saved SPI driver instance */
#else
+9 -9
View File
@@ -85,10 +85,10 @@ int stmpe811_adcinitialize(STMPE811_HANDLE handle)
/* Get exclusive access to the device structure */
ret = nxsem_wait(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
ierr("ERROR: nxsem_wait failed: %d\n", ret);
ierr("ERROR: nxmutex_lock failed: %d\n", ret);
return ret;
}
@@ -113,7 +113,7 @@ int stmpe811_adcinitialize(STMPE811_HANDLE handle)
/* Mark ADC initialized */
priv->flags |= STMPE811_FLAGS_ADC_INITIALIZED;
nxsem_post(&priv->exclsem);
nxmutex_unock(&priv->lock);
return OK;
}
@@ -144,10 +144,10 @@ int stmpe811_adcconfig(STMPE811_HANDLE handle, int pin)
/* Get exclusive access to the device structure */
ret = nxsem_wait(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
ierr("ERROR: nxsem_wait failed: %d\n", ret);
ierr("ERROR: nxmutex_lock failed: %d\n", ret);
return ret;
}
@@ -156,7 +156,7 @@ int stmpe811_adcconfig(STMPE811_HANDLE handle, int pin)
if ((priv->inuse & pinmask) != 0)
{
ierr("ERROR: PIN%d is already in-use\n", pin);
nxsem_post(&priv->exclsem);
nxmutex_unock(&priv->lock);
return -EBUSY;
}
@@ -172,7 +172,7 @@ int stmpe811_adcconfig(STMPE811_HANDLE handle, int pin)
/* Mark the pin as 'in use' */
priv->inuse |= pinmask;
nxsem_post(&priv->exclsem);
nxmutex_unock(&priv->lock);
return OK;
}
@@ -203,10 +203,10 @@ uint16_t stmpe811_adcread(STMPE811_HANDLE handle, int pin)
/* Get exclusive access to the device structure */
ret = nxsem_wait(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
ierr("ERROR: nxsem_wait failed: %d\n", ret);
ierr("ERROR: nxmutex_lock failed: %d\n", ret);
return ret;
}
+1 -1
View File
@@ -288,7 +288,7 @@ STMPE811_HANDLE stmpe811_instantiate(FAR struct i2c_master_s *dev,
/* Initialize the device state structure */
nxsem_init(&priv->exclsem, 0, 1);
nxmutex_init(&priv->lock);
priv->config = config;
#ifdef CONFIG_STMPE811_SPI
+13 -13
View File
@@ -126,10 +126,10 @@ int stmpe811_gpioconfig(STMPE811_HANDLE handle, uint8_t pinconfig)
/* Get exclusive access to the device structure */
ret = nxsem_wait(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
ierr("ERROR: nxsem_wait failed: %d\n", ret);
ierr("ERROR: nxmutex_lock failed: %d\n", ret);
return ret;
}
@@ -138,7 +138,7 @@ int stmpe811_gpioconfig(STMPE811_HANDLE handle, uint8_t pinconfig)
if ((priv->inuse & pinmask) != 0)
{
ierr("ERROR: PIN%d is already in-use\n", pin);
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return -EBUSY;
}
@@ -223,7 +223,7 @@ int stmpe811_gpioconfig(STMPE811_HANDLE handle, uint8_t pinconfig)
/* Mark the pin as 'in use' */
priv->inuse |= pinmask;
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return OK;
}
@@ -254,10 +254,10 @@ void stmpe811_gpiowrite(STMPE811_HANDLE handle, uint8_t pinconfig,
/* Get exclusive access to the device structure */
ret = nxsem_wait(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
ierr("ERROR: nxsem_wait failed: %d\n", ret);
ierr("ERROR: nxmutex_lock failed: %d\n", ret);
return;
}
@@ -276,7 +276,7 @@ void stmpe811_gpiowrite(STMPE811_HANDLE handle, uint8_t pinconfig,
stmpe811_putreg8(priv, STMPE811_GPIO_CLRPIN, (1 << pin));
}
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
}
/****************************************************************************
@@ -307,16 +307,16 @@ int stmpe811_gpioread(STMPE811_HANDLE handle, uint8_t pinconfig, bool *value)
/* Get exclusive access to the device structure */
ret = nxsem_wait(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
ierr("ERROR: nxsem_wait failed: %d\n", ret);
ierr("ERROR: nxmutex_lock failed: %d\n", ret);
return ret;
}
regval = stmpe811_getreg8(priv, STMPE811_GPIO_MPSTA);
*value = ((regval & STMPE811_GPIO_PIN(pin)) != 0);
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return OK;
}
@@ -355,10 +355,10 @@ int stmpe811_gpioattach(STMPE811_HANDLE handle, uint8_t pinconfig,
/* Get exclusive access to the device structure */
ret = nxsem_wait(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
ierr("ERROR: nxsem_wait failed: %d\n", ret);
ierr("ERROR: nxmutex_lock failed: %d\n", ret);
return ret;
}
@@ -388,7 +388,7 @@ int stmpe811_gpioattach(STMPE811_HANDLE handle, uint8_t pinconfig,
stmpe811_putreg8(priv, STMPE811_GPIO_EN, regval);
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return OK;
}
#endif
+18 -18
View File
@@ -252,7 +252,7 @@ static inline int stmpe811_waitsample(FAR struct stmpe811_dev_s *priv,
* run, but they cannot run yet because pre-emption is disabled.
*/
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
/* Try to get the a sample... if we cannot, then wait on the semaphore
* that is posted when new sample data is available.
@@ -280,7 +280,7 @@ static inline int stmpe811_waitsample(FAR struct stmpe811_dev_s *priv,
* Interrupts and pre-emption will be re-enabled while we wait.
*/
ret = nxsem_wait(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
errout:
/* Restore pre-emption. We might get suspended here but that is okay
@@ -317,7 +317,7 @@ static int stmpe811_open(FAR struct file *filep)
/* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
ierr("ERROR: nxsem_wait failed: %d\n", ret);
@@ -332,7 +332,7 @@ static int stmpe811_open(FAR struct file *filep)
/* More than 255 opens; uint8_t overflows to zero */
ret = -EMFILE;
goto errout_with_sem;
goto errout_with_lock;
}
/* When the reference increments to 1, this is the first open event
@@ -343,8 +343,8 @@ static int stmpe811_open(FAR struct file *filep)
priv->crefs = tmp;
errout_with_sem:
nxsem_post(&priv->exclsem);
errout_with_lock:
nxmutex_unlock(&priv->lock);
return ret;
#else
return OK;
@@ -374,7 +374,7 @@ static int stmpe811_close(FAR struct file *filep)
/* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
ierr("ERROR: nxsem_wait failed: %d\n", ret);
@@ -391,7 +391,7 @@ static int stmpe811_close(FAR struct file *filep)
priv->crefs--;
}
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
#endif
return OK;
}
@@ -435,7 +435,7 @@ static ssize_t stmpe811_read(FAR struct file *filep,
/* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
ierr("ERROR: nxsem_wait failed: %d\n", ret);
@@ -520,7 +520,7 @@ static ssize_t stmpe811_read(FAR struct file *filep,
ret = SIZEOF_TOUCH_SAMPLE_S(1);
errout:
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return ret;
}
@@ -547,7 +547,7 @@ static int stmpe811_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
/* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
ierr("ERROR: nxsem_wait failed: %d\n", ret);
@@ -579,7 +579,7 @@ static int stmpe811_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
break;
}
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return ret;
}
@@ -608,7 +608,7 @@ static int stmpe811_poll(FAR struct file *filep, FAR struct pollfd *fds,
/* Are we setting up the poll? Or tearing it down? */
ret = nxsem_wait(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
/* This should only happen if the wait was canceled by an signal */
@@ -676,7 +676,7 @@ static int stmpe811_poll(FAR struct file *filep, FAR struct pollfd *fds,
}
errout:
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return ret;
}
@@ -850,7 +850,7 @@ int stmpe811_register(STMPE811_HANDLE handle, int minor)
/* Get exclusive access to the device structure */
ret = nxsem_wait(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
ierr("ERROR: nxsem_wait failed: %d\n", ret);
@@ -862,7 +862,7 @@ int stmpe811_register(STMPE811_HANDLE handle, int minor)
if ((priv->inuse & TSC_PIN_SET) != 0)
{
ierr("ERROR: TSC pins is already in-use: %02x\n", priv->inuse);
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return -EBUSY;
}
@@ -880,7 +880,7 @@ int stmpe811_register(STMPE811_HANDLE handle, int minor)
if (ret < 0)
{
ierr("ERROR: Failed to register driver %s: %d\n", devname, ret);
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return ret;
}
@@ -892,7 +892,7 @@ int stmpe811_register(STMPE811_HANDLE handle, int minor)
priv->inuse |= TSC_PIN_SET; /* Pins 4-7 are now in-use */
priv->flags |= STMPE811_FLAGS_TSC_INITIALIZED; /* TSC function is initialized */
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return ret;
}
+22 -21
View File
@@ -36,6 +36,7 @@
#include <nuttx/input/touchscreen.h>
#include <nuttx/kmalloc.h>
#include <nuttx/mutex.h>
#include <nuttx/list.h>
#include <nuttx/mm/circbuf.h>
@@ -49,7 +50,7 @@ struct touch_openpriv_s
struct list_node node; /* Opened file buffer linked list node */
FAR struct pollfd *fds; /* Polling structure of waiting thread */
sem_t waitsem; /* Used to wait for the availability of data */
sem_t locksem; /* Manages exclusive access to this structure */
mutex_t lock; /* Manages exclusive access to this structure */
};
/* This structure is for touchscreen upper half driver */
@@ -57,7 +58,7 @@ struct touch_openpriv_s
struct touch_upperhalf_s
{
uint8_t nums; /* Number of touch point structure */
sem_t exclsem; /* Manages exclusive access to this structure */
mutex_t lock; /* Manages exclusive access to this structure */
struct list_node head; /* Opened file buffer chain header node */
FAR struct touch_lowerhalf_s *lower; /* A pointer of lower half instance */
};
@@ -125,7 +126,7 @@ static int touch_open(FAR struct file *filep)
return ret;
}
ret = nxsem_wait(&upper->exclsem);
ret = nxmutex_lock(&upper->lock);
if (ret < 0)
{
circbuf_uninit(&openpriv->circbuf);
@@ -134,7 +135,7 @@ static int touch_open(FAR struct file *filep)
}
nxsem_init(&openpriv->waitsem, 0, 0);
nxsem_init(&openpriv->locksem, 0, 1);
nxmutex_init(&openpriv->lock);
nxsem_set_protocol(&openpriv->waitsem, SEM_PRIO_NONE);
list_add_tail(&upper->head, &openpriv->node);
@@ -143,7 +144,7 @@ static int touch_open(FAR struct file *filep)
*/
filep->f_priv = openpriv;
nxsem_post(&upper->exclsem);
nxmutex_unlock(&upper->lock);
return ret;
}
@@ -158,7 +159,7 @@ static int touch_close(FAR struct file *filep)
FAR struct touch_upperhalf_s *upper = inode->i_private;
int ret;
ret = nxsem_wait(&upper->exclsem);
ret = nxmutex_lock(&upper->lock);
if (ret < 0)
{
return ret;
@@ -167,10 +168,10 @@ static int touch_close(FAR struct file *filep)
list_delete(&openpriv->node);
circbuf_uninit(&openpriv->circbuf);
nxsem_destroy(&openpriv->waitsem);
nxsem_destroy(&openpriv->locksem);
nxmutex_destroy(&openpriv->lock);
kmm_free(openpriv);
nxsem_post(&upper->exclsem);
nxmutex_unlock(&upper->lock);
return ret;
}
@@ -208,7 +209,7 @@ static ssize_t touch_read(FAR struct file *filep, FAR char *buffer,
return -EINVAL;
}
ret = nxsem_wait(&openpriv->locksem);
ret = nxmutex_lock(&openpriv->lock);
if (ret < 0)
{
return ret;
@@ -223,14 +224,14 @@ static ssize_t touch_read(FAR struct file *filep, FAR char *buffer,
}
else
{
nxsem_post(&openpriv->locksem);
nxmutex_unlock(&openpriv->lock);
ret = nxsem_wait_uninterruptible(&openpriv->waitsem);
if (ret < 0)
{
return ret;
}
ret = nxsem_wait(&openpriv->locksem);
ret = nxmutex_lock(&openpriv->lock);
if (ret < 0)
{
return ret;
@@ -241,7 +242,7 @@ static ssize_t touch_read(FAR struct file *filep, FAR char *buffer,
ret = circbuf_read(&openpriv->circbuf, buffer, len);
out:
nxsem_post(&openpriv->locksem);
nxmutex_unlock(&openpriv->lock);
return ret;
}
@@ -252,7 +253,7 @@ static int touch_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
FAR struct touch_lowerhalf_s *lower = upper->lower;
int ret;
ret = nxsem_wait(&upper->exclsem);
ret = nxmutex_lock(&upper->lock);
if (ret < 0)
{
return ret;
@@ -267,7 +268,7 @@ static int touch_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
ret = -ENOTTY;
}
nxsem_post(&upper->exclsem);
nxmutex_unlock(&upper->lock);
return ret;
}
@@ -277,7 +278,7 @@ static int touch_poll(FAR struct file *filep, struct pollfd *fds, bool setup)
pollevent_t eventset = 0;
int ret;
ret = nxsem_wait(&openpriv->locksem);
ret = nxmutex_lock(&openpriv->lock);
if (ret < 0)
{
return ret;
@@ -310,7 +311,7 @@ static int touch_poll(FAR struct file *filep, struct pollfd *fds, bool setup)
}
errout:
nxsem_post(&openpriv->locksem);
nxmutex_unlock(&openpriv->lock);
return ret;
}
@@ -324,7 +325,7 @@ void touch_event(FAR void *priv, FAR const struct touch_sample_s *sample)
FAR struct touch_openpriv_s *openpriv;
int semcount;
if (nxsem_wait(&upper->exclsem) < 0)
if (nxmutex_lock(&upper->lock) < 0)
{
return;
}
@@ -343,7 +344,7 @@ void touch_event(FAR void *priv, FAR const struct touch_sample_s *sample)
poll_notify(&openpriv->fds, 1, POLLIN);
}
nxsem_post(&upper->exclsem);
nxmutex_unlock(&upper->lock);
}
int touch_register(FAR struct touch_lowerhalf_s *lower,
@@ -371,12 +372,12 @@ int touch_register(FAR struct touch_lowerhalf_s *lower,
upper->lower = lower;
upper->nums = nums;
list_initialize(&upper->head);
nxsem_init(&upper->exclsem, 0, 1);
nxmutex_init(&upper->lock);
ret = register_driver(path, &g_touch_fops, 0666, upper);
if (ret < 0)
{
nxsem_destroy(&upper->exclsem);
nxmutex_destroy(&upper->lock);
kmm_free(upper);
return ret;
}
@@ -396,6 +397,6 @@ void touch_unregister(FAR struct touch_lowerhalf_s *lower,
iinfo("UnRegistering %s\n", path);
unregister_driver(path);
nxsem_destroy(&upper->exclsem);
nxmutex_destroy(&upper->lock);
kmm_free(upper);
}
+18 -17
View File
@@ -51,6 +51,7 @@
#include <nuttx/arch.h>
#include <nuttx/fs/fs.h>
#include <nuttx/i2c/i2c_master.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <nuttx/wqueue.h>
#include <nuttx/random.h>
@@ -152,7 +153,7 @@ struct tsc2007_dev_s
uint8_t nwaiters; /* Number of threads waiting for TSC2007 data */
uint8_t id; /* Current touch point ID */
volatile bool penchange; /* An unreported event is buffered */
sem_t devsem; /* Manages exclusive access to this structure */
mutex_t devlock; /* Manages exclusive access to this structure */
sem_t waitsem; /* Used to wait for the availability of data */
FAR struct tsc2007_config_s *config; /* Board configuration data */
@@ -339,7 +340,7 @@ static int tsc2007_waitsample(FAR struct tsc2007_dev_s *priv,
* run, but they cannot run yet because pre-emption is disabled.
*/
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
/* Try to get the a sample... if we cannot, then wait on the semaphore
* that is posted when new sample data is available.
@@ -365,7 +366,7 @@ static int tsc2007_waitsample(FAR struct tsc2007_dev_s *priv,
* sample. Interrupts and pre-emption will be re-enabled while we wait.
*/
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
errout:
/* Then re-enable interrupts. We might get interrupt here and there
@@ -788,7 +789,7 @@ static int tsc2007_open(FAR struct file *filep)
/* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
ierr("ERROR: nxsem_wait failed: %d\n", ret);
@@ -803,7 +804,7 @@ static int tsc2007_open(FAR struct file *filep)
/* More than 255 opens; uint8_t overflows to zero */
ret = -EMFILE;
goto errout_with_sem;
goto errout_with_lock;
}
/* When the reference increments to 1, this is the first open event
@@ -814,8 +815,8 @@ static int tsc2007_open(FAR struct file *filep)
priv->crefs = tmp;
errout_with_sem:
nxsem_post(&priv->devsem);
errout_with_lock:
nxmutex_unlock(&priv->devlock);
return ret;
#else
return OK;
@@ -841,7 +842,7 @@ static int tsc2007_close(FAR struct file *filep)
/* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
ierr("ERROR: nxsem_wait failed: %d\n", ret);
@@ -858,7 +859,7 @@ static int tsc2007_close(FAR struct file *filep)
priv->crefs--;
}
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
#endif
return OK;
}
@@ -897,7 +898,7 @@ static ssize_t tsc2007_read(FAR struct file *filep, FAR char *buffer,
/* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
ierr("ERROR: nxsem_wait failed: %d\n", ret);
@@ -992,7 +993,7 @@ static ssize_t tsc2007_read(FAR struct file *filep, FAR char *buffer,
ret = SIZEOF_TOUCH_SAMPLE_S(1);
errout:
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return ret;
}
@@ -1015,7 +1016,7 @@ static int tsc2007_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
/* Get exclusive access to the driver data structure */
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
ierr("ERROR: nxsem_wait failed: %d\n", ret);
@@ -1063,7 +1064,7 @@ static int tsc2007_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
break;
}
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return ret;
}
@@ -1088,7 +1089,7 @@ static int tsc2007_poll(FAR struct file *filep, FAR struct pollfd *fds,
/* Are we setting up the poll? Or tearing it down? */
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
ierr("ERROR: nxsem_wait failed: %d\n", ret);
@@ -1154,7 +1155,7 @@ static int tsc2007_poll(FAR struct file *filep, FAR struct pollfd *fds,
}
errout:
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return ret;
}
@@ -1220,7 +1221,7 @@ int tsc2007_register(FAR struct i2c_master_s *dev,
priv->i2c = dev; /* Save the I2C device handle */
priv->config = config; /* Save the board configuration */
nxsem_init(&priv->devsem, 0, 1); /* Initialize device structure semaphore */
nxmutex_init(&priv->devlock); /* Initialize device structure mutex */
nxsem_init(&priv->waitsem, 0, 0); /* Initialize pen event wait semaphore */
/* The event wait semaphore is used for signaling and, hence, should not
@@ -1294,7 +1295,7 @@ int tsc2007_register(FAR struct i2c_master_s *dev,
return OK;
errout_with_priv:
nxsem_destroy(&priv->devsem);
nxmutex_destroy(&priv->devlock);
#ifdef CONFIG_TSC2007_MULTIPLE
kmm_free(priv);
#endif