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
+18 -95
View File
@@ -36,6 +36,7 @@
#include <nuttx/arch.h>
#include <nuttx/irq.h>
#include <nuttx/clock.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <nuttx/i2c/i2c_master.h>
@@ -181,7 +182,7 @@ struct am335x_i2c_priv_s
const struct am335x_i2c_config_s *config;
int refs; /* Reference count */
sem_t sem_excl; /* Mutual exclusion semaphore */
mutex_t lock; /* Mutual exclusion mutex */
#ifndef CONFIG_I2C_POLLED
sem_t sem_isr; /* Interrupt wait semaphore */
#endif
@@ -219,9 +220,6 @@ static inline void am335x_i2c_putreg(struct am335x_i2c_priv_s *priv,
static inline void am335x_i2c_modifyreg(struct am335x_i2c_priv_s *priv,
uint16_t offset, uint32_t clearbits,
uint32_t setbits);
static inline int am335x_i2c_sem_wait(struct am335x_i2c_priv_s *priv);
static int
am335x_i2c_sem_wait_noncancelable(struct am335x_i2c_priv_s *priv);
#ifdef CONFIG_AM335X_I2C_DYNTIMEO
static uint32_t am335x_i2c_toticks(int msgc, struct i2c_msg_s *msgs);
@@ -231,10 +229,6 @@ static inline int
am335x_i2c_sem_waitdone(struct am335x_i2c_priv_s *priv);
static inline bool
am335x_i2c_sem_waitstop(struct am335x_i2c_priv_s *priv);
static inline void am335x_i2c_sem_post(struct am335x_i2c_priv_s *priv);
static inline void am335x_i2c_sem_init(struct am335x_i2c_priv_s *priv);
static inline void
am335x_i2c_sem_destroy(struct am335x_i2c_priv_s *priv);
#ifdef CONFIG_I2C_TRACE
static void am335x_i2c_tracereset(struct am335x_i2c_priv_s *priv);
@@ -320,6 +314,10 @@ static struct am335x_i2c_priv_s am335x_i2c0_priv =
.ops = &am335x_i2c_ops,
.config = &am335x_i2c0_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
#ifndef CONFIG_I2C_POLLED
.sem_isr = NXSEM_INITIALIZER(0, PRIOINHERIT_FLAGS_DISABLE),
#endif
.intstate = INTSTATE_IDLE,
.msgc = 0,
.msgv = NULL,
@@ -351,6 +349,10 @@ static struct am335x_i2c_priv_s am335x_i2c1_priv =
.ops = &am335x_i2c_ops,
.config = &am335x_i2c1_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
#ifndef CONFIG_I2C_POLLED
.sem_isr = NXSEM_INITIALIZER(0, PRIOINHERIT_FLAGS_DISABLE),
#endif
.intstate = INTSTATE_IDLE,
.msgc = 0,
.msgv = NULL,
@@ -382,6 +384,10 @@ static struct am335x_i2c_priv_s am335x_i2c2_priv =
.ops = &am335x_i2c_ops,
.config = &am335x_i2c2_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
#ifndef CONFIG_I2C_POLLED
.sem_isr = NXSEM_INITIALIZER(0, PRIOINHERIT_FLAGS_DISABLE),
#endif
.intstate = INTSTATE_IDLE,
.msgc = 0,
.msgv = NULL,
@@ -439,34 +445,6 @@ static inline void am335x_i2c_modifyreg(struct am335x_i2c_priv_s *priv,
modifyreg32(priv->config->base + offset, clearbits, setbits);
}
/****************************************************************************
* Name: am335x_i2c_sem_wait
*
* Description:
* Take the exclusive access, waiting as necessary. May be interrupted by
* a signal.
*
****************************************************************************/
static inline int am335x_i2c_sem_wait(struct am335x_i2c_priv_s *priv)
{
return nxsem_wait(&priv->sem_excl);
}
/****************************************************************************
* Name: am335x_i2c_sem_wait_noncancelable
*
* Description:
* Take the exclusive access, waiting as necessary.
*
****************************************************************************/
static int
am335x_i2c_sem_wait_noncancelable(struct am335x_i2c_priv_s *priv)
{
return nxsem_wait_uninterruptible(&priv->sem_excl);
}
/****************************************************************************
* Name: am335x_i2c_toticks
*
@@ -691,57 +669,6 @@ am335x_i2c_sem_waitstop(struct am335x_i2c_priv_s *priv)
return false;
}
/****************************************************************************
* Name: am335x_i2c_sem_post
*
* Description:
* Release the mutual exclusion semaphore
*
****************************************************************************/
static inline void am335x_i2c_sem_post(struct am335x_i2c_priv_s *priv)
{
nxsem_post(&priv->sem_excl);
}
/****************************************************************************
* Name: am335x_i2c_sem_init
*
* Description:
* Initialize semaphores
*
****************************************************************************/
static inline void am335x_i2c_sem_init(struct am335x_i2c_priv_s *priv)
{
nxsem_init(&priv->sem_excl, 0, 1);
#ifndef CONFIG_I2C_POLLED
/* This semaphore is used for signaling and, hence, should not have
* priority inheritance enabled.
*/
nxsem_init(&priv->sem_isr, 0, 0);
nxsem_set_protocol(&priv->sem_isr, SEM_PRIO_NONE);
#endif
}
/****************************************************************************
* Name: am335x_i2c_sem_destroy
*
* Description:
* Destroy semaphores.
*
****************************************************************************/
static inline void am335x_i2c_sem_destroy(struct am335x_i2c_priv_s *priv)
{
nxsem_destroy(&priv->sem_excl);
#ifndef CONFIG_I2C_POLLED
nxsem_destroy(&priv->sem_isr);
#endif
}
/****************************************************************************
* Name: am335x_i2c_trace*
*
@@ -1382,7 +1309,7 @@ static int am335x_i2c_transfer(struct i2c_master_s *dev,
/* Ensure that address or flags don't change meanwhile */
ret = am335x_i2c_sem_wait(priv);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
@@ -1498,7 +1425,7 @@ static int am335x_i2c_transfer(struct i2c_master_s *dev,
priv->ptr = NULL;
}
am335x_i2c_sem_post(priv);
nxmutex_unlock(&priv->lock);
return ret;
}
@@ -1535,7 +1462,7 @@ static int am335x_i2c_reset(struct i2c_master_s *dev)
/* Lock out other clients */
ret = am335x_i2c_sem_wait_noncancelable(priv);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
@@ -1630,7 +1557,7 @@ out:
/* Release the port for re-use by other clients */
am335x_i2c_sem_post(priv);
nxmutex_unlock(&priv->lock);
return ret;
}
#endif /* CONFIG_I2C_RESET */
@@ -1683,7 +1610,6 @@ struct i2c_master_s *am335x_i2cbus_initialize(int port)
if ((volatile int)priv->refs++ == 0)
{
am335x_i2c_sem_init(priv);
am335x_i2c_init(priv);
}
@@ -1728,9 +1654,6 @@ int am335x_i2cbus_uninitialize(struct i2c_master_s *dev)
am335x_i2c_deinit(priv);
/* Release unused resources */
am335x_i2c_sem_destroy(priv);
return OK;
}
-3
View File
@@ -53,7 +53,6 @@
#include <debug.h>
#include <nuttx/arch.h>
#include <nuttx/semaphore.h>
#include <nuttx/video/fb.h>
#include "arm_internal.h"
@@ -143,7 +142,6 @@ struct am335x_lcd_dev_s
struct am335x_panel_info_s panel;
sem_t exclsem; /* Assure mutually exclusive access */
nxgl_coord_t stride; /* Width of framebuffer in bytes */
size_t fbsize; /* Size of the framebuffer allocation */
};
@@ -586,7 +584,6 @@ int am335x_lcd_initialize(const struct am335x_panel_info_s *panel)
/* Initialize the device state singleton */
nxsem_init(&priv->exclsem, 0, 1);
memcpy(&priv->panel, panel, sizeof(struct am335x_panel_info_s));
/* Save framebuffer information */
+16 -18
View File
@@ -36,7 +36,7 @@
#include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h>
#include <nuttx/irq.h>
#include <nuttx/semaphore.h>
#include <nuttx/mutex.h>
#include <arch/chip/scu.h>
#include <arch/chip/adc.h>
@@ -174,7 +174,7 @@ struct cxd56adc_dev_s
struct scufifo_wm_s *wm; /* water mark */
struct math_filter_s *filter; /* math filter */
struct scuev_notify_s * notify; /* notify */
sem_t exclsem; /* exclusive semaphore */
mutex_t lock; /* exclusive mutex */
int crefs; /* reference count */
};
@@ -718,14 +718,14 @@ static int cxd56_adc_open(struct file *filep)
/* Increment reference counter */
nxsem_wait_uninterruptible(&priv->exclsem);
nxmutex_lock(&priv->lock);
priv->crefs++;
DEBUGASSERT(priv->crefs > 0);
if (priv->crefs > 1)
{
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return OK;
}
@@ -738,7 +738,7 @@ static int cxd56_adc_open(struct file *filep)
priv->seq = seq_open(SEQ_TYPE_NORMAL, type);
if (!priv->seq)
{
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return -ENOENT;
}
@@ -751,14 +751,13 @@ static int cxd56_adc_open(struct file *filep)
ret = set_ofstgain(priv);
if (ret < 0)
{
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return ret;
}
ainfo("open ch%d freq%d scufifo%d\n", priv->ch, priv->freq, priv->fsize);
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return OK;
}
@@ -781,14 +780,14 @@ static int cxd56_adc_close(struct file *filep)
/* Decrement reference counter */
nxsem_wait_uninterruptible(&priv->exclsem);
nxmutex_lock(&priv->lock);
DEBUGASSERT(priv->crefs > 0);
priv->crefs--;
if (priv->crefs > 0)
{
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return OK;
}
@@ -815,8 +814,7 @@ static int cxd56_adc_close(struct file *filep)
priv->notify = NULL;
}
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return OK;
}
@@ -1110,7 +1108,7 @@ int cxd56_adcinitialize(void)
return ret;
}
nxsem_init(&g_lpadc0priv.exclsem, 0, 1);
nxmutex_init(&g_lpadc0priv.lock);
#endif
#if defined (CONFIG_CXD56_LPADC1) || defined (CONFIG_CXD56_LPADC0_1) || defined (CONFIG_CXD56_LPADC_ALL)
ret = register_driver("/dev/lpadc1", &g_adcops, 0666, &g_lpadc1priv);
@@ -1120,7 +1118,7 @@ int cxd56_adcinitialize(void)
return ret;
}
nxsem_init(&g_lpadc1priv.exclsem, 0, 1);
nxmutex_init(&g_lpadc1priv.lock);
#endif
#if defined (CONFIG_CXD56_LPADC2) || defined (CONFIG_CXD56_LPADC_ALL)
ret = register_driver("/dev/lpadc2", &g_adcops, 0666, &g_lpadc2priv);
@@ -1130,7 +1128,7 @@ int cxd56_adcinitialize(void)
return ret;
}
nxsem_init(&g_lpadc2priv.exclsem, 0, 1);
nxmutex_init(&g_lpadc2priv.lock);
#endif
#if defined (CONFIG_CXD56_LPADC3) || defined (CONFIG_CXD56_LPADC_ALL)
ret = register_driver("/dev/lpadc3", &g_adcops, 0666, &g_lpadc3priv);
@@ -1140,7 +1138,7 @@ int cxd56_adcinitialize(void)
return ret;
}
nxsem_init(&g_lpadc3priv.exclsem, 0, 1);
nxmutex_init(&g_lpadc3priv.lock);
#endif
#ifdef CONFIG_CXD56_HPADC0
ret = register_driver("/dev/hpadc0", &g_adcops, 0666, &g_hpadc0priv);
@@ -1150,7 +1148,7 @@ int cxd56_adcinitialize(void)
return ret;
}
nxsem_init(&g_hpadc0priv.exclsem, 0, 1);
nxmutex_init(&g_hpadc0priv.lock);
#endif
#ifdef CONFIG_CXD56_HPADC1
ret = register_driver("/dev/hpadc1", &g_adcops, 0666, &g_hpadc1priv);
@@ -1160,7 +1158,7 @@ int cxd56_adcinitialize(void)
return ret;
}
nxsem_init(&g_hpadc1priv.exclsem, 0, 1);
nxmutex_init(&g_hpadc1priv.lock);
#endif
return ret;
+5 -5
View File
@@ -39,6 +39,7 @@
#include <math.h>
#include <nuttx/kmalloc.h>
#include <nuttx/mutex.h>
#include <nuttx/power/battery_charger.h>
#include <nuttx/power/battery_ioctl.h>
@@ -64,7 +65,7 @@
struct charger_dev_s
{
sem_t batsem;
mutex_t batlock;
};
/****************************************************************************
@@ -451,7 +452,7 @@ static int charger_ioctl(struct file *filep, int cmd, unsigned long arg)
struct charger_dev_s *priv = inode->i_private;
int ret = -ENOTTY;
nxsem_wait_uninterruptible(&priv->batsem);
nxmutex_lock(&priv->batlock);
switch (cmd)
{
@@ -593,8 +594,7 @@ static int charger_ioctl(struct file *filep, int cmd, unsigned long arg)
break;
}
nxsem_post(&priv->batsem);
nxmutex_unlock(&priv->batlock);
return ret;
}
@@ -623,7 +623,7 @@ int cxd56_charger_initialize(const char *devpath)
/* Initialize the CXD5247 device structure */
nxsem_init(&priv->batsem, 0, 1);
nxmutex_init(&priv->batlock);
/* Register battery driver */
+28 -27
View File
@@ -31,6 +31,7 @@
#include <stdint.h>
#include <arch/chip/pm.h>
#include <nuttx/mutex.h>
#include "arm_internal.h"
#include "chip.h"
@@ -155,7 +156,7 @@ static uint32_t g_active_imgdevs = 0;
/* Exclusive control */
static sem_t g_clockexc = SEM_INITIALIZER(1);
static mutex_t g_clocklock = NXMUTEX_INITIALIZER;
/* For peripherals inside SCU block
*
@@ -219,19 +220,19 @@ const struct scu_peripheral g_scuhpadc =
* Private Functions
****************************************************************************/
static void clock_semtake(sem_t *id)
static void clock_lock(mutex_t *lock)
{
if (!up_interrupt_context())
{
nxsem_wait_uninterruptible(id);
nxmutex_lock(lock);
}
}
static void clock_semgive(sem_t *id)
static void clock_unlock(mutex_t *lock)
{
if (!up_interrupt_context())
{
nxsem_post(id);
nxmutex_unlock(lock);
}
}
@@ -889,11 +890,11 @@ static void cxd56_spim_clock_disable(void)
static void cxd56_img_spi_clock_enable(void)
{
clock_semtake(&g_clockexc);
clock_lock(&g_clocklock);
enable_pwd(PDID_APP_SUB);
cxd56_img_clock_enable();
putreg32(0x00010002, CXD56_CRG_GEAR_IMG_SPI);
clock_semgive(&g_clockexc);
clock_unlock(&g_clocklock);
}
/****************************************************************************
@@ -906,11 +907,11 @@ static void cxd56_img_spi_clock_enable(void)
static void cxd56_img_spi_clock_disable(void)
{
clock_semtake(&g_clockexc);
clock_lock(&g_clocklock);
putreg32(0, CXD56_CRG_GEAR_IMG_SPI);
cxd56_img_clock_disable();
disable_pwd(PDID_APP_SUB);
clock_semgive(&g_clockexc);
clock_unlock(&g_clocklock);
}
#endif
@@ -926,11 +927,11 @@ static void cxd56_img_spi_clock_disable(void)
static void cxd56_img_wspi_clock_enable(void)
{
clock_semtake(&g_clockexc);
clock_lock(&g_clocklock);
enable_pwd(PDID_APP_SUB);
cxd56_img_clock_enable();
putreg32(0x00010004, CXD56_CRG_GEAR_IMG_WSPI);
clock_semgive(&g_clockexc);
clock_unlock(&g_clocklock);
}
/****************************************************************************
@@ -943,11 +944,11 @@ static void cxd56_img_wspi_clock_enable(void)
static void cxd56_img_wspi_clock_disable(void)
{
clock_semtake(&g_clockexc);
clock_lock(&g_clocklock);
putreg32(0, CXD56_CRG_GEAR_IMG_WSPI);
cxd56_img_clock_disable();
disable_pwd(PDID_APP_SUB);
clock_semgive(&g_clockexc);
clock_unlock(&g_clocklock);
}
#endif
@@ -1089,7 +1090,7 @@ void cxd56_spi_clock_gear_adjust(int port, uint32_t maxfreq)
return;
}
clock_semtake(&g_clockexc);
clock_lock(&g_clocklock);
baseclock = cxd56_get_appsmp_baseclock();
if (baseclock != 0)
{
@@ -1108,7 +1109,7 @@ void cxd56_spi_clock_gear_adjust(int port, uint32_t maxfreq)
putreg32(gear, addr);
}
clock_semgive(&g_clockexc);
clock_unlock(&g_clocklock);
}
#if defined(CONFIG_CXD56_I2C2)
@@ -1320,7 +1321,7 @@ void cxd56_img_uart_clock_enable()
{
uint32_t val = 0;
clock_semtake(&g_clockexc);
clock_lock(&g_clocklock);
enable_pwd(PDID_APP_SUB);
cxd56_img_clock_enable();
@@ -1333,7 +1334,7 @@ void cxd56_img_uart_clock_enable()
#endif /* CONFIG_CXD56_UART2 */
putreg32(val, CXD56_CRG_GEAR_IMG_UART);
clock_semgive(&g_clockexc);
clock_unlock(&g_clocklock);
}
/****************************************************************************
@@ -1348,7 +1349,7 @@ void cxd56_img_uart_clock_disable()
{
uint32_t val = 0;
clock_semtake(&g_clockexc);
clock_lock(&g_clocklock);
val = getreg32(CXD56_CRG_GEAR_IMG_UART);
val &= ~(1UL << 16);
@@ -1357,7 +1358,7 @@ void cxd56_img_uart_clock_disable()
cxd56_img_clock_disable();
disable_pwd(PDID_APP_SUB);
clock_semgive(&g_clockexc);
clock_unlock(&g_clocklock);
}
/****************************************************************************
@@ -1370,13 +1371,13 @@ void cxd56_img_uart_clock_disable()
void cxd56_img_cisif_clock_enable(void)
{
clock_semtake(&g_clockexc);
clock_lock(&g_clocklock);
enable_pwd(PDID_APP_SUB);
cxd56_img_clock_enable();
g_active_imgdevs |= FLAG_IMG_CISIF;
clock_semgive(&g_clockexc);
clock_unlock(&g_clocklock);
}
/****************************************************************************
@@ -1389,13 +1390,13 @@ void cxd56_img_cisif_clock_enable(void)
void cxd56_img_cisif_clock_disable(void)
{
clock_semtake(&g_clockexc);
clock_lock(&g_clocklock);
g_active_imgdevs &= ~FLAG_IMG_CISIF;
cxd56_img_clock_disable();
disable_pwd(PDID_APP_SUB);
clock_semgive(&g_clockexc);
clock_unlock(&g_clocklock);
}
/****************************************************************************
@@ -1408,13 +1409,13 @@ void cxd56_img_cisif_clock_disable(void)
void cxd56_img_ge2d_clock_enable(void)
{
clock_semtake(&g_clockexc);
clock_lock(&g_clocklock);
enable_pwd(PDID_APP_SUB);
cxd56_img_clock_enable();
g_active_imgdevs |= FLAG_IMG_GE2D;
clock_semgive(&g_clockexc);
clock_unlock(&g_clocklock);
}
/****************************************************************************
@@ -1427,13 +1428,13 @@ void cxd56_img_ge2d_clock_enable(void)
void cxd56_img_ge2d_clock_disable(void)
{
clock_semtake(&g_clockexc);
clock_lock(&g_clocklock);
g_active_imgdevs &= ~FLAG_IMG_GE2D;
cxd56_img_clock_disable();
disable_pwd(PDID_APP_SUB);
clock_semgive(&g_clockexc);
clock_unlock(&g_clocklock);
}
static uint32_t cxd56_get_clock(enum clock_source cs)
+8 -9
View File
@@ -34,7 +34,7 @@
#include <nuttx/arch.h>
#include <nuttx/irq.h>
#include <nuttx/semaphore.h>
#include <nuttx/mutex.h>
#include "cxd56_dmac.h"
@@ -290,7 +290,7 @@ struct dma_channel_s
/* This is the array of all DMA channels */
static struct dma_channel_s g_dmach[NCHANNELS];
static sem_t g_dmaexc;
static mutex_t g_dmalock;
static int dma_init(int ch);
static int dma_uninit(int ch);
@@ -727,7 +727,7 @@ void weak_function arm_dma_initialize(void)
up_enable_irq(irq_map[i]);
}
nxsem_init(&g_dmaexc, 0, 1);
nxmutex_init(&g_dmalock);
}
/****************************************************************************
@@ -762,7 +762,7 @@ DMA_HANDLE cxd56_dmachannel(int ch, ssize_t maxsize)
/* Get exclusive access to allocate channel */
nxsem_wait_uninterruptible(&g_dmaexc);
nxmutex_lock(&g_dmalock);
if (ch < 0 || ch >= NCHANNELS)
{
@@ -806,12 +806,11 @@ DMA_HANDLE cxd56_dmachannel(int ch, ssize_t maxsize)
dmach->inuse = true;
nxsem_post(&g_dmaexc);
nxmutex_unlock(&g_dmalock);
return (DMA_HANDLE)dmach;
err:
nxsem_post(&g_dmaexc);
nxmutex_unlock(&g_dmalock);
return NULL;
}
@@ -845,7 +844,7 @@ void cxd56_dmafree(DMA_HANDLE handle)
return;
}
nxsem_wait_uninterruptible(&g_dmaexc);
nxmutex_lock(&g_dmalock);
if (!dmach->inuse)
{
@@ -863,7 +862,7 @@ void cxd56_dmafree(DMA_HANDLE handle)
dmach->inuse = false;
err:
nxsem_post(&g_dmaexc);
nxmutex_unlock(&g_dmalock);
}
/****************************************************************************
+13 -25
View File
@@ -35,6 +35,7 @@
#include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h>
#include <nuttx/irq.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <arch/board/board.h>
@@ -91,7 +92,7 @@ struct emmc_dma_desc_s
struct cxd56_emmc_state_s
{
sem_t excsem;
mutex_t lock;
int crefs;
uint32_t total_sectors;
};
@@ -143,16 +144,6 @@ struct cxd56_emmc_state_s g_emmcdev;
* Private Functions
****************************************************************************/
static int emmc_takesem(sem_t *sem)
{
return nxsem_wait_uninterruptible(sem);
}
static void emmc_givesem(sem_t *sem)
{
nxsem_post(sem);
}
static void emmc_cmdstarted(void)
{
uint32_t val;
@@ -429,7 +420,7 @@ static void emmc_send(int datatype, uint32_t opcode, uint32_t arg,
/* Wait for command or data transfer done */
ret = emmc_takesem(&g_waitsem);
ret = nxsem_wait_uninterruptible(&g_waitsem);
if (ret < 0)
{
return;
@@ -592,8 +583,7 @@ static int emmc_interrupt(int irq, void *context, void *arg)
ferr("End-bit error/write no CRC.\n");
}
emmc_givesem(&g_waitsem);
nxsem_post(&g_waitsem);
return OK;
}
@@ -705,7 +695,7 @@ static int cxd56_emmc_readsectors(struct cxd56_emmc_state_s *priv,
return -ENOMEM;
}
ret = emmc_takesem(&priv->excsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
kmm_free(descs);
@@ -746,9 +736,8 @@ static int cxd56_emmc_readsectors(struct cxd56_emmc_state_s *priv,
}
finish:
emmc_givesem(&priv->excsem);
nxmutex_unlock(&priv->lock);
kmm_free(descs);
return ret;
}
@@ -767,7 +756,7 @@ static int cxd56_emmc_writesectors(struct cxd56_emmc_state_s *priv,
return -ENOMEM;
}
ret = emmc_takesem(&priv->excsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
kmm_free(descs);
@@ -822,9 +811,8 @@ static int cxd56_emmc_writesectors(struct cxd56_emmc_state_s *priv,
emmc_flushwritefifo();
finish:
emmc_givesem(&priv->excsem);
nxmutex_unlock(&priv->lock);
kmm_free(descs);
return ret;
}
#endif
@@ -839,14 +827,14 @@ static int cxd56_emmc_open(struct inode *inode)
/* Just increment the reference count on the driver */
ret = emmc_takesem(&priv->excsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
}
priv->crefs++;
emmc_givesem(&priv->excsem);
nxmutex_unlock(&priv->lock);
return OK;
}
@@ -861,14 +849,14 @@ static int cxd56_emmc_close(struct inode *inode)
/* Decrement the reference count on the block driver */
DEBUGASSERT(priv->crefs > 0);
ret = emmc_takesem(&priv->excsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
}
priv->crefs--;
emmc_givesem(&priv->excsem);
nxmutex_unlock(&priv->lock);
return OK;
}
@@ -952,7 +940,7 @@ int cxd56_emmcinitialize(void)
priv = &g_emmcdev;
memset(priv, 0, sizeof(struct cxd56_emmc_state_s));
nxsem_init(&priv->excsem, 0, 1);
nxmutex_init(&priv->lock);
nxsem_init(&g_waitsem, 0, 0);
nxsem_set_protocol(&g_waitsem, SEM_PRIO_NONE);
+6 -11
View File
@@ -28,6 +28,7 @@
#include <nuttx/sched.h>
#include <nuttx/irq.h>
#include <nuttx/signal.h>
#include <nuttx/mutex.h>
#include <assert.h>
#include <debug.h>
#include <errno.h>
@@ -113,7 +114,7 @@ extern struct modulelist_s _image_modlist_base[];
****************************************************************************/
static sem_t g_farwait;
static sem_t g_farlock;
static mutex_t g_farlock;
static struct pm_cpu_wakelock_s g_wlock =
{
.count = 0,
@@ -124,11 +125,6 @@ static struct pm_cpu_wakelock_s g_wlock =
* Private Functions
****************************************************************************/
static int farapi_semtake(sem_t *id)
{
return nxsem_wait_uninterruptible(id);
}
#ifdef CONFIG_CXD56_FARAPI_DEBUG
static void dump_farapi_message(struct farmsg_s *msg)
{
@@ -225,7 +221,7 @@ void farapi_main(int id, void *arg, struct modulelist_s *mlist)
}
#endif
farapi_semtake(&g_farlock);
nxmutex_lock(&g_farlock);
api = &msg.u.api;
@@ -256,7 +252,7 @@ void farapi_main(int id, void *arg, struct modulelist_s *mlist)
/* Wait event flag message as Far API done */
farapi_semtake(&g_farwait);
nxsem_wait_uninterruptible(&g_farwait);
/* Permit hot sleep with Far API done */
@@ -265,8 +261,7 @@ void farapi_main(int id, void *arg, struct modulelist_s *mlist)
dump_farapi_message(&msg);
err:
nxsem_post(&g_farlock);
nxmutex_unlock(&g_farlock);
#ifdef CONFIG_SMP
if (0 != cpu)
{
@@ -295,7 +290,7 @@ void cxd56_farapiinitialize(void)
}
#endif
nxsem_init(&g_farlock, 0, 1);
nxmutex_init(&g_farlock);
nxsem_init(&g_farwait, 0, 0);
nxsem_set_protocol(&g_farwait, SEM_PRIO_NONE);
+5 -5
View File
@@ -36,6 +36,7 @@
#include <debug.h>
#include <nuttx/kmalloc.h>
#include <nuttx/mutex.h>
#include <nuttx/power/battery_gauge.h>
#include <nuttx/power/battery_ioctl.h>
@@ -55,7 +56,7 @@
struct bat_gauge_dev_s
{
sem_t batsem;
mutex_t batlock;
};
/****************************************************************************
@@ -279,7 +280,7 @@ static int gauge_ioctl(struct file *filep, int cmd, unsigned long arg)
struct bat_gauge_dev_s *priv = inode->i_private;
int ret = -ENOTTY;
nxsem_wait_uninterruptible(&priv->batsem);
nxmutex_lock(&priv->batlock);
switch (cmd)
{
@@ -317,8 +318,7 @@ static int gauge_ioctl(struct file *filep, int cmd, unsigned long arg)
break;
}
nxsem_post(&priv->batsem);
nxmutex_unlock(&priv->batlock);
return ret;
}
@@ -347,7 +347,7 @@ int cxd56_gauge_initialize(const char *devpath)
/* Initialize the CXD5247 device structure */
nxsem_init(&priv->batsem, 0, 1);
nxmutex_init(&priv->batlock);
/* Register battery driver */
+8 -29
View File
@@ -27,6 +27,7 @@
#include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h>
#include <nuttx/irq.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <stdio.h>
@@ -50,8 +51,6 @@ static ssize_t ge2d_read(struct file *filep, char *buffer,
static ssize_t ge2d_write(struct file *filep, const char *buffer,
size_t len);
static int ge2d_ioctl(struct file *filep, int cmd, unsigned long arg);
static int ge2d_semtake(sem_t *id);
static void ge2d_semgive(sem_t *id);
static int ge2d_irqhandler(int irq, void *context, void *arg);
/****************************************************************************
@@ -66,30 +65,12 @@ static const struct file_operations g_ge2dfops =
};
static sem_t g_wait;
static sem_t g_lock;
static mutex_t g_lock;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: ge2d_semtake
****************************************************************************/
static int ge2d_semtake(sem_t *id)
{
return nxsem_wait_uninterruptible(id);
}
/****************************************************************************
* Name: ge2d_semgive
****************************************************************************/
static void ge2d_semgive(sem_t *id)
{
nxsem_post(id);
}
/****************************************************************************
* Name: ge2d_read
****************************************************************************/
@@ -119,7 +100,7 @@ static ssize_t ge2d_write(struct file *filep, const char *buffer,
/* Get exclusive access */
ge2d_semtake(&g_lock);
nxmutex_lock(&g_lock);
/* Set operation buffer and start processing.
* Descriptor start address bit 0 is select to bus, always 1 (memory),
@@ -141,14 +122,13 @@ static ssize_t ge2d_write(struct file *filep, const char *buffer,
/* Wait for interrupts for processing done. */
ge2d_semtake(&g_wait);
nxsem_wait_uninterruptible(&g_wait);
/* Disable interrupts */
putreg32(0, GE2D_INTR_ENABLE);
ge2d_semgive(&g_lock);
nxmutex_unlock(&g_lock);
return len;
}
@@ -192,8 +172,7 @@ static int ge2d_irqhandler(int irq, void *context, void *arg)
/* Release semaphore anyway */
ge2d_semgive(&g_wait);
nxsem_post(&g_wait);
return OK;
}
@@ -205,7 +184,7 @@ int cxd56_ge2dinitialize(const char *devname)
{
int ret;
nxsem_init(&g_lock, 0, 1);
nxmutex_init(&g_lock);
nxsem_init(&g_wait, 0, 0);
nxsem_set_protocol(&g_wait, SEM_PRIO_NONE);
@@ -238,7 +217,7 @@ void cxd56_ge2duninitialize(const char *devname)
cxd56_img_ge2d_clock_disable();
nxsem_destroy(&g_lock);
nxmutex_destroy(&g_lock);
nxsem_destroy(&g_wait);
unregister_driver(devname);
+7 -6
View File
@@ -33,6 +33,7 @@
#include <debug.h>
#include <nuttx/kmalloc.h>
#include <nuttx/mutex.h>
#include <nuttx/fs/fs.h>
#include <nuttx/board.h>
#include <nuttx/spi/spi.h>
@@ -58,7 +59,7 @@
struct cxd56_geofence_dev_s
{
sem_t devsem;
mutex_t devlock;
struct pollfd *fds[CONFIG_GEOFENCE_NPOLLWAITERS];
};
@@ -435,7 +436,7 @@ static void cxd56_geofence_sighandler(uint32_t data, void *userdata)
(struct cxd56_geofence_dev_s *)userdata;
int ret;
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return;
@@ -443,7 +444,7 @@ static void cxd56_geofence_sighandler(uint32_t data, void *userdata)
poll_notify(priv->fds, CONFIG_GEOFENCE_NPOLLWAITERS, POLLIN);
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
}
/****************************************************************************
@@ -557,7 +558,7 @@ static int cxd56_geofence_poll(struct file *filep,
inode = filep->f_inode;
priv = (struct cxd56_geofence_dev_s *)inode->i_private;
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -608,7 +609,7 @@ static int cxd56_geofence_poll(struct file *filep,
}
errout:
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return ret;
}
@@ -640,7 +641,7 @@ static int cxd56_geofence_register(const char *devpath)
}
memset(priv, 0, sizeof(struct cxd56_geofence_dev_s));
nxsem_init(&priv->devsem, 0, 1);
nxmutex_init(&priv->devlock);
ret = cxd56_geofence_initialize(priv);
if (ret < 0)
+16 -16
View File
@@ -34,6 +34,7 @@
#include <debug.h>
#include <nuttx/kmalloc.h>
#include <nuttx/mutex.h>
#include <nuttx/board.h>
#include <nuttx/signal.h>
#include <nuttx/fs/fs.h>
@@ -154,7 +155,7 @@ struct cxd56_devsig_table_s
struct cxd56_gnss_dev_s
{
sem_t devsem;
mutex_t devlock;
sem_t syncsem;
uint8_t num_open;
uint8_t notify_data;
@@ -165,7 +166,7 @@ struct cxd56_gnss_dev_s
struct cxd56_gnss_sig_s sigs[CONFIG_CXD56_GNSS_NSIGNALRECEIVERS];
#endif
struct cxd56_gnss_shared_info_s shared_info;
sem_t ioctllock;
mutex_t ioctllock;
sem_t apiwait;
int apiret;
};
@@ -1483,7 +1484,7 @@ static int cxd56_gnss_set_signal(struct file *filep, unsigned long arg)
inode = filep->f_inode;
priv = (struct cxd56_gnss_dev_s *)inode->i_private;
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -2270,7 +2271,7 @@ static void cxd56_gnss_common_signalhandler(uint32_t data,
int i;
int ret;
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return;
@@ -2294,7 +2295,7 @@ static void cxd56_gnss_common_signalhandler(uint32_t data,
fw_gd_setnotifymask(sigtype, FALSE);
}
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
}
#endif /* CONFIG_CXD56_GNSS_NSIGNALRECEIVERS != 0 */
@@ -2378,7 +2379,7 @@ static void cxd56_gnss_default_sighandler(uint32_t data, void *userdata)
break;
}
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return;
@@ -2386,7 +2387,7 @@ static void cxd56_gnss_default_sighandler(uint32_t data, void *userdata)
poll_notify(priv->fds, CONFIG_CXD56_GNSS_NPOLLWAITERS, POLLIN);
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
#if CONFIG_CXD56_GNSS_NSIGNALRECEIVERS != 0
cxd56_gnss_common_signalhandler(data, userdata);
@@ -2594,7 +2595,7 @@ static int cxd56_gnss_open(struct file *filep)
usleep(100 * 1000);
}
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -2695,7 +2696,7 @@ static int cxd56_gnss_close(struct file *filep)
inode = filep->f_inode;
priv = (struct cxd56_gnss_dev_s *)inode->i_private;
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -2842,7 +2843,7 @@ static int cxd56_gnss_ioctl(struct file *filep, int cmd,
return -EINVAL;
}
ret = nxsem_wait(&priv->ioctllock);
ret = nxmutex_lock(&priv->ioctllock);
if (ret < 0)
{
return ret;
@@ -2850,8 +2851,7 @@ static int cxd56_gnss_ioctl(struct file *filep, int cmd,
ret = g_cmdlist[cmd](filep, arg);
nxsem_post(&priv->ioctllock);
nxmutex_unlock(&priv->ioctllock);
return ret;
}
@@ -2882,7 +2882,7 @@ static int cxd56_gnss_poll(struct file *filep, struct pollfd *fds,
inode = filep->f_inode;
priv = (struct cxd56_gnss_dev_s *)inode->i_private;
ret = nxsem_wait(&priv->devsem);
ret = nxmutex_lock(&priv->devlock);
if (ret < 0)
{
return ret;
@@ -2933,7 +2933,7 @@ static int cxd56_gnss_poll(struct file *filep, struct pollfd *fds,
}
errout:
nxsem_post(&priv->devsem);
nxmutex_unlock(&priv->devlock);
return ret;
}
@@ -3015,7 +3015,7 @@ static int cxd56_gnss_register(const char *devpath)
memset(priv, 0, sizeof(struct cxd56_gnss_dev_s));
ret = nxsem_init(&priv->devsem, 0, 1);
ret = nxmutex_init(&priv->devlock);
if (ret < 0)
{
gnsserr("Failed to initialize gnss devsem!\n");
@@ -3031,7 +3031,7 @@ static int cxd56_gnss_register(const char *devpath)
nxsem_set_protocol(&priv->apiwait, SEM_PRIO_NONE);
ret = nxsem_init(&priv->ioctllock, 0, 1);
ret = nxmutex_init(&priv->ioctllock);
if (ret < 0)
{
gnsserr("Failed to initialize gnss ioctllock!\n");
+8 -9
View File
@@ -24,6 +24,7 @@
#include <nuttx/config.h>
#include <nuttx/kmalloc.h>
#include <nuttx/mutex.h>
#include <nuttx/irq.h>
#include <stdio.h>
@@ -89,7 +90,7 @@ struct cxd56_hifdev_s
uint32_t flags;
const void *buffer;
size_t len;
sem_t exclsem;
mutex_t lock;
int crefs;
};
@@ -220,14 +221,14 @@ static int hif_open(struct file *filep)
/* Increment reference counter */
nxsem_wait_uninterruptible(&priv->exclsem);
nxmutex_lock(&priv->lock);
priv->crefs++;
DEBUGASSERT(priv->crefs > 0);
if (priv->crefs > 1)
{
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return OK;
}
@@ -238,8 +239,7 @@ static int hif_open(struct file *filep)
priv->flags |= O_NONBLOCK;
}
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return OK;
}
@@ -256,13 +256,12 @@ static int hif_close(struct file *filep)
/* Decrement reference counter */
nxsem_wait_uninterruptible(&priv->exclsem);
nxmutex_lock(&priv->lock);
DEBUGASSERT(priv->crefs > 0);
priv->crefs--;
nxsem_post(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return OK;
}
@@ -424,7 +423,7 @@ static int hif_initialize(struct hostif_buff_s *buffer)
return ret;
}
nxsem_init(&priv->exclsem, 0, 1);
nxmutex_init(&priv->lock);
priv->crefs = 0;
}
+18 -41
View File
@@ -34,6 +34,7 @@
#include <assert.h>
#include <nuttx/arch.h>
#include <nuttx/mutex.h>
#include <nuttx/i2c/i2c_master.h>
#include <nuttx/irq.h>
@@ -79,7 +80,7 @@ struct cxd56_i2cdev_s
int8_t port; /* Port number */
uint32_t base_freq; /* branch frequency */
sem_t mutex; /* Only one thread can access at a time */
mutex_t lock; /* Only one thread can access at a time */
sem_t wait; /* Place to wait for transfer completion */
struct wdog_s timeout; /* watchdog to timeout when bus hung */
uint32_t frequency; /* Current I2C frequency */
@@ -103,6 +104,8 @@ static struct cxd56_i2cdev_s g_i2c0dev =
.port = 0,
.base = CXD56_SCU_I2C0_BASE,
.irqid = CXD56_IRQ_SCU_I2C0,
.lock = NXMUTEX_INITIALIZER,
.wait = NXSEM_INITIALIZER(0, PRIOINHERIT_FLAGS_DISABLE),
.refs = 0,
};
#endif
@@ -112,6 +115,8 @@ static struct cxd56_i2cdev_s g_i2c1dev =
.port = 1,
.base = CXD56_SCU_I2C1_BASE,
.irqid = CXD56_IRQ_SCU_I2C1,
.lock = NXMUTEX_INITIALIZER,
.wait = NXSEM_INITIALIZER(0, PRIOINHERIT_FLAGS_DISABLE),
.refs = 0,
};
#endif
@@ -121,6 +126,8 @@ static struct cxd56_i2cdev_s g_i2c2dev =
.port = 2,
.base = CXD56_I2CM_BASE,
.irqid = CXD56_IRQ_I2CM,
.lock = NXMUTEX_INITIALIZER,
.wait = NXSEM_INITIALIZER(0, PRIOINHERIT_FLAGS_DISABLE),
.refs = 0,
};
#endif
@@ -129,9 +136,6 @@ static struct cxd56_i2cdev_s g_i2c2dev =
* Private Functions
****************************************************************************/
static inline int i2c_takesem(sem_t *sem);
static inline int i2c_givesem(sem_t *sem);
static inline uint32_t i2c_reg_read(struct cxd56_i2cdev_s *priv,
uint32_t offset);
static inline void i2c_reg_write(struct cxd56_i2cdev_s *priv,
@@ -158,24 +162,6 @@ static int cxd56_i2c_transfer_scu(struct i2c_master_s *dev,
struct i2c_msg_s *msgs, int count);
#endif
/****************************************************************************
* Name: i2c_takesem
****************************************************************************/
static inline int i2c_takesem(sem_t *sem)
{
return nxsem_wait_uninterruptible(sem);
}
/****************************************************************************
* Name: i2c_givesem
****************************************************************************/
static inline int i2c_givesem(sem_t *sem)
{
return nxsem_post(sem);
}
/****************************************************************************
* Name: cxd56_i2c_pincontrol
*
@@ -372,7 +358,7 @@ static void cxd56_i2c_timeout(wdparm_t arg)
irqstate_t flags = enter_critical_section();
priv->error = -ENODEV;
i2c_givesem(&priv->wait);
nxsem_post(&priv->wait);
leave_critical_section(flags);
}
@@ -479,7 +465,7 @@ static int cxd56_i2c_interrupt(int irq, void *context, void *arg)
ret = wd_cancel(&priv->timeout);
if (ret == OK)
{
i2c_givesem(&priv->wait);
nxsem_post(&priv->wait);
}
}
@@ -542,7 +528,7 @@ static int cxd56_i2c_receive(struct cxd56_i2cdev_s *priv, int last)
i2c_reg_rmw(priv, CXD56_IC_INTR_MASK, INTR_RX_FULL, INTR_RX_FULL);
leave_critical_section(flags);
i2c_takesem(&priv->wait);
nxsem_wait_uninterruptible(&priv->wait);
if (priv->error != OK)
{
@@ -589,8 +575,7 @@ static int cxd56_i2c_send(struct cxd56_i2cdev_s *priv, int last)
i2c_reg_rmw(priv, CXD56_IC_INTR_MASK, INTR_TX_EMPTY, INTR_TX_EMPTY);
leave_critical_section(flags);
i2c_takesem(&priv->wait);
nxsem_wait_uninterruptible(&priv->wait);
return 0;
}
@@ -618,7 +603,7 @@ static int cxd56_i2c_transfer(struct i2c_master_s *dev,
/* Get exclusive access to the I2C bus */
i2c_takesem(&priv->mutex);
nxmutex_lock(&priv->lock);
/* Check wait semaphore value. If the value is not 0, the transfer can not
* be performed normally.
@@ -696,8 +681,7 @@ static int cxd56_i2c_transfer(struct i2c_master_s *dev,
cxd56_i2c_clock_gate_enable(priv->port);
i2c_givesem(&priv->mutex);
nxmutex_unlock(&priv->lock);
return ret;
}
@@ -835,7 +819,7 @@ static int cxd56_i2c_transfer_scu(struct i2c_master_s *dev,
/* Get exclusive access to the I2C bus */
i2c_takesem(&priv->mutex);
nxmutex_lock(&priv->lock);
/* Apply frequency for request msgs */
@@ -869,8 +853,7 @@ static int cxd56_i2c_transfer_scu(struct i2c_master_s *dev,
}
}
i2c_givesem(&priv->mutex);
nxmutex_unlock(&priv->lock);
return ret;
}
#endif
@@ -957,7 +940,7 @@ struct i2c_master_s *cxd56_i2cbus_initialize(int port)
#ifdef CONFIG_CXD56_I2C0
if (port == 0)
{
priv = &g_i2c0dev;
priv = &g_i2c0dev;
# ifndef CONFIG_CXD56_I2C0_SCUSEQ
priv->dev.ops = &cxd56_i2c_ops;
# else
@@ -969,7 +952,7 @@ struct i2c_master_s *cxd56_i2cbus_initialize(int port)
#ifdef CONFIG_CXD56_I2C1
if (port == 1)
{
priv = &g_i2c1dev;
priv = &g_i2c1dev;
# ifndef CONFIG_CXD56_I2C1_SCUSEQ
priv->dev.ops = &cxd56_i2c_ops;
# else
@@ -1034,10 +1017,6 @@ struct i2c_master_s *cxd56_i2cbus_initialize(int port)
cxd56_i2c_pincontrol(port, true);
nxsem_init(&priv->mutex, 0, 1);
nxsem_init(&priv->wait, 0, 0);
nxsem_set_protocol(&priv->wait, SEM_PRIO_NONE);
/* Attach Interrupt Handler */
irq_attach(priv->irqid, cxd56_i2c_interrupt, priv);
@@ -1100,8 +1079,6 @@ int cxd56_i2cbus_uninitialize(struct i2c_master_s *dev)
irq_detach(priv->irqid);
wd_cancel(&priv->timeout);
nxsem_destroy(&priv->mutex);
nxsem_destroy(&priv->wait);
return OK;
}
+5 -21
View File
@@ -145,21 +145,6 @@ static struct iccdev_s *g_cpumsg[NCPUS];
* Private Functions
****************************************************************************/
static int icc_semtake(sem_t *semid)
{
return nxsem_wait_uninterruptible(semid);
}
static int icc_semtrytake(sem_t *semid)
{
return nxsem_trywait(semid);
}
static void icc_semgive(sem_t *semid)
{
nxsem_post(semid);
}
static struct iccdev_s *icc_getprotocol(int protoid)
{
if (protoid < 0 || protoid >= NPROTOCOLS)
@@ -234,7 +219,7 @@ static int icc_irqhandler(int cpuid, uint32_t word[2])
sq_addlast((sq_entry_t *)req, &priv->recvq);
icc_semgive(&priv->rxwait);
nxsem_post(&priv->rxwait);
/* If signal registered by cxd56_iccnotify(), then send POSIX signal to
* process.
@@ -295,7 +280,7 @@ static int icc_msghandler(int cpuid, int protoid, uint32_t pdata,
static void icc_rxtimeout(wdparm_t arg)
{
struct iccdev_s *priv = (struct iccdev_s *)arg;
icc_semgive(&priv->rxwait);
nxsem_post(&priv->rxwait);
}
static int icc_recv(struct iccdev_s *priv, iccmsg_t *msg, int32_t ms)
@@ -308,7 +293,7 @@ static int icc_recv(struct iccdev_s *priv, iccmsg_t *msg, int32_t ms)
{
/* Try to take the semaphore without waiging. */
ret = icc_semtrytake(&priv->rxwait);
ret = nxsem_trywait(&priv->rxwait);
if (ret < 0)
{
return ret;
@@ -316,7 +301,7 @@ static int icc_recv(struct iccdev_s *priv, iccmsg_t *msg, int32_t ms)
}
else if (ms == 0)
{
icc_semtake(&priv->rxwait);
nxsem_wait_uninterruptible(&priv->rxwait);
}
else
{
@@ -324,8 +309,7 @@ static int icc_recv(struct iccdev_s *priv, iccmsg_t *msg, int32_t ms)
timo = ms * 1000 / CONFIG_USEC_PER_TICK;
wd_start(&priv->rxtimeout, timo, icc_rxtimeout, (wdparm_t)priv);
icc_semtake(&priv->rxwait);
nxsem_wait_uninterruptible(&priv->rxwait);
wd_cancel(&priv->rxtimeout);
}
+20 -28
View File
@@ -27,6 +27,7 @@
#include <nuttx/config.h>
#include <nuttx/kmalloc.h>
#include <nuttx/mutex.h>
#include <nuttx/mqueue.h>
#include <nuttx/queue.h>
@@ -149,7 +150,6 @@ static int cxd56_pm_do_callback(uint8_t id,
static int cxd56_pm_needcallback(uint32_t target,
struct cxd56_pm_target_id_s *table);
static void cxd56_pm_clkchange(struct cxd56_pm_message_s *message);
static int cxd56_pm_semtake(sem_t *id);
static void cxd56_pm_checkfreqlock(void);
static int cxd56_pm_maintask(int argc, char *argv[]);
#if defined(CONFIG_CXD56_HOT_SLEEP)
@@ -167,8 +167,8 @@ static int cxd56_pmmsghandler(int cpuid, int protoid, uint32_t pdata,
static struct cxd56_pm_target_id_s g_target_id_table;
static struct file g_queuedesc;
static sem_t g_bootsync;
static sem_t g_regcblock;
static sem_t g_freqlock;
static mutex_t g_regcblock;
static mutex_t g_freqlock;
static sem_t g_freqlockwait;
static dq_queue_t g_cbqueue;
static sq_queue_t g_freqlockqueue;
@@ -179,11 +179,6 @@ static int g_freqlock_flag;
static struct pm_cpu_wakelock_s g_wlock =
PM_CPUWAKELOCK_INIT(PM_CPUWAKELOCK_TAG('P', 'M', 0));
static int cxd56_pm_semtake(sem_t *id)
{
return nxsem_wait_uninterruptible(id);
}
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -311,13 +306,13 @@ static void cxd56_pm_clkchange(struct cxd56_pm_message_s *message)
return;
}
cxd56_pm_semtake(&g_regcblock);
nxmutex_lock(&g_regcblock);
ret = cxd56_pm_do_callback(id, &g_target_id_table);
cxd56_pmsendmsg(mid, ret);
nxsem_post(&g_regcblock);
nxmutex_unlock(&g_regcblock);
}
static void cxd56_pm_checkfreqlock(void)
@@ -337,7 +332,7 @@ static void cxd56_pm_checkfreqlock(void)
{
g_freqlock_flag = flag;
cxd56_pmsendmsg(MSGID_FREQLOCK, flag);
cxd56_pm_semtake(&g_freqlockwait);
nxsem_wait_uninterruptible(&g_freqlockwait);
}
}
@@ -486,12 +481,12 @@ void *cxd56_pm_register_callback(uint32_t target,
{
struct pm_cbentry_s *entry = NULL;
cxd56_pm_semtake(&g_regcblock);
nxmutex_lock(&g_regcblock);
entry = (struct pm_cbentry_s *)kmm_malloc(sizeof(struct pm_cbentry_s));
if (entry == NULL)
{
nxsem_post(&g_regcblock);
nxmutex_unlock(&g_regcblock);
return NULL;
}
@@ -499,19 +494,19 @@ void *cxd56_pm_register_callback(uint32_t target,
entry->callback = callback;
dq_addlast((dq_entry_t *)entry, &g_cbqueue);
nxsem_post(&g_regcblock);
nxmutex_unlock(&g_regcblock);
return (void *)entry;
}
void cxd56_pm_unregister_callback(void *handle)
{
cxd56_pm_semtake(&g_regcblock);
nxmutex_lock(&g_regcblock);
dq_rem((dq_entry_t *)handle, &g_cbqueue);
kmm_free(handle);
nxsem_post(&g_regcblock);
nxmutex_unlock(&g_regcblock);
}
static int cxd56_pmmsghandler(int cpuid, int protoid, uint32_t pdata,
@@ -583,7 +578,7 @@ void up_pm_acquire_freqlock(struct pm_cpu_freqlock_s *lock)
up_pm_acquire_wakelock(&g_wlock);
cxd56_pm_semtake(&g_freqlock);
nxmutex_lock(&g_freqlock);
if (lock->flag == PM_CPUFREQLOCK_FLAG_HOLD)
{
@@ -608,8 +603,7 @@ void up_pm_acquire_freqlock(struct pm_cpu_freqlock_s *lock)
lock->count++;
nxsem_post(&g_freqlock);
nxmutex_unlock(&g_freqlock);
up_pm_release_wakelock(&g_wlock);
}
@@ -640,7 +634,7 @@ void up_pm_release_freqlock(struct pm_cpu_freqlock_s *lock)
up_pm_acquire_wakelock(&g_wlock);
cxd56_pm_semtake(&g_freqlock);
nxmutex_lock(&g_freqlock);
for (entry = sq_peek(&g_freqlockqueue); entry; entry = sq_next(entry))
{
@@ -657,8 +651,7 @@ void up_pm_release_freqlock(struct pm_cpu_freqlock_s *lock)
}
exit:
nxsem_post(&g_freqlock);
nxmutex_unlock(&g_freqlock);
up_pm_release_wakelock(&g_wlock);
}
@@ -683,7 +676,7 @@ int up_pm_get_freqlock_count(struct pm_cpu_freqlock_s *lock)
DEBUGASSERT(lock);
cxd56_pm_semtake(&g_freqlock);
nxmutex_lock(&g_freqlock);
for (entry = sq_peek(&g_freqlockqueue); entry; entry = sq_next(entry))
{
@@ -694,7 +687,7 @@ int up_pm_get_freqlock_count(struct pm_cpu_freqlock_s *lock)
}
}
nxsem_post(&g_freqlock);
nxmutex_unlock(&g_freqlock);
return count;
}
@@ -831,13 +824,13 @@ int cxd56_pm_initialize(void)
sq_init(&g_freqlockqueue);
sq_init(&g_wakelockqueue);
ret = nxsem_init(&g_regcblock, 0, 1);
ret = nxmutex_init(&g_regcblock);
if (ret < 0)
{
return ret;
}
ret = nxsem_init(&g_freqlock, 0, 1);
ret = nxmutex_init(&g_freqlock);
if (ret < 0)
{
return ret;
@@ -867,8 +860,7 @@ int cxd56_pm_initialize(void)
/* wait until cxd56_pm_maintask thread is ready */
cxd56_pm_semtake(&g_bootsync);
nxsem_wait_uninterruptible(&g_bootsync);
return OK;
}
+14 -33
View File
@@ -26,6 +26,7 @@
#include <nuttx/kmalloc.h>
#include <nuttx/irq.h>
#include <nuttx/signal.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <inttypes.h>
@@ -186,8 +187,8 @@ struct decimator_s
struct cxd56_scudev_s
{
sem_t syncwait; /* Semaphore for synchronize with SCU firmware */
sem_t syncexc; /* Semaphore for exclusive access to sync */
sem_t syncwait; /* Semaphore for synchronize with SCU firmware */
mutex_t synclock; /* Mutex for exclusive access to sync */
/* SCU hardware resource management bitmaps (1 = allocated) */
@@ -230,8 +231,6 @@ static int8_t seq_alloc(void);
static inline void seq_free(int8_t sid);
static inline int8_t oneshot_alloc(void);
static inline void oneshot_free(int8_t tid);
static int seq_semtake(sem_t *id);
static void seq_semgive(sem_t *id);
static void seq_fifosetactive(struct seq_s *seq, int fifoid);
static void seq_fifosetinactive(struct seq_s *seq, int fifoid);
static int seq_fifoisactive(struct seq_s *seq, int fifoid);
@@ -359,24 +358,6 @@ static const struct coeff_addr_s g_caddrs[3][2] =
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: seq_semtake
****************************************************************************/
static int seq_semtake(sem_t *id)
{
return nxsem_wait_uninterruptible(id);
}
/****************************************************************************
* Name: seq_semgive
****************************************************************************/
static void seq_semgive(sem_t *id)
{
nxsem_post(id);
}
/****************************************************************************
* Name: seq_fifosetactive
****************************************************************************/
@@ -1083,7 +1064,7 @@ static int seq_oneshot(int bustype, int slave, uint16_t *inst,
/* Wait for one shot is done */
seq_semtake(&priv->oneshotwait[tid]);
nxsem_wait_uninterruptible(&priv->oneshotwait[tid]);
/* Disable interrupt for one shot sequencer */
@@ -1451,7 +1432,7 @@ static void seq_sync(struct seq_s *seq, int req)
{
struct cxd56_scudev_s *priv = &g_scudev;
seq_semtake(&priv->syncexc);
nxmutex_lock(&priv->synclock);
/* Save current request */
@@ -1468,11 +1449,11 @@ static void seq_sync(struct seq_s *seq, int req)
/* Wait for interrupt from SCU firmware */
seq_semtake(&priv->syncwait);
nxsem_wait_uninterruptible(&priv->syncwait);
priv->currentreq = 0;
seq_semgive(&priv->syncexc);
nxmutex_unlock(&priv->synclock);
}
/****************************************************************************
@@ -1628,7 +1609,7 @@ static void seq_handleoneshot(struct cxd56_scudev_s *priv, uint32_t intr)
{
putreg32(bit, SCU_INT_CLEAR_MAIN);
seq_semgive(&priv->oneshotwait[i]);
nxsem_post(&priv->oneshotwait[i]);
}
}
}
@@ -1655,7 +1636,7 @@ static void seq_handleisopdoneintr(struct cxd56_scudev_s *priv,
putreg32(1 << 27, SCU_INT_DISABLE_MAIN);
putreg32(1 << 27, SCU_INT_CLEAR_MAIN);
seq_semgive(&priv->syncwait);
nxsem_post(&priv->syncwait);
}
}
@@ -1754,7 +1735,7 @@ static int seq_scuirqhandler(int irq, void *context, void *arg)
tid = out - 1;
priv->oneshoterr[tid] = -EIO;
seq_semgive(&priv->oneshotwait[tid]);
nxsem_post(&priv->oneshotwait[tid]);
}
}
}
@@ -2886,7 +2867,7 @@ static void seq_fifodmadone(DMA_HANDLE handle, uint8_t status, void *arg)
{
struct scufifo_s *fifo = (struct scufifo_s *)arg;
fifo->dmaresult = status;
seq_semgive(&fifo->dmawait);
nxsem_post(&fifo->dmawait);
}
#else
/****************************************************************************
@@ -3045,7 +3026,7 @@ int seq_read(struct seq_s *seq, int fifoid, char *buffer, int length)
/* Wait for DMA is done */
seq_semtake(&fifo->dmawait);
nxsem_wait_uninterruptible(&fifo->dmawait);
if (fifo->dmaresult)
{
/* ERROR */
@@ -3446,7 +3427,7 @@ void scu_initialize(void)
memset(priv, 0, sizeof(struct cxd56_scudev_s));
nxsem_init(&priv->syncexc, 0, 1);
nxmutex_init(&priv->synclock);
nxsem_init(&priv->syncwait, 0, 0);
nxsem_set_protocol(&priv->syncwait, SEM_PRIO_NONE);
@@ -3520,7 +3501,7 @@ void scu_uninitialize(void)
cxd56_scuseq_clock_disable();
nxsem_destroy(&priv->syncwait);
nxsem_destroy(&priv->syncexc);
nxmutex_destroy(&priv->synclock);
for (i = 0; i < 3; i++)
{
+3 -27
View File
@@ -308,8 +308,6 @@ struct cxd56_sdhcregs_s
/* Low-level helpers ********************************************************/
static int cxd56_takesem(struct cxd56_sdiodev_s *priv);
#define cxd56_givesem(priv) (nxsem_post(&(priv)->waitsem))
static void cxd56_configwaitints(struct cxd56_sdiodev_s *priv,
uint32_t waitints, sdio_eventset_t waitevents,
sdio_eventset_t wkupevents);
@@ -484,27 +482,6 @@ static uint32_t cxd56_sdhci_adma_dscr[CXD56_SDIO_MAX_LEN_ADMA_DSCR * 2];
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: cxd56_takesem
*
* Description:
* Take the wait semaphore (handling false alarm wakeups due to the receipt
* of signals).
*
* Input Parameters:
* dev - Instance of the SDIO device driver state structure.
*
* Returned Value:
* Normally OK, but may return -ECANCELED in the rare event that the task
* has been canceled.
*
****************************************************************************/
static int cxd56_takesem(struct cxd56_sdiodev_s *priv)
{
return nxsem_wait_uninterruptible(&priv->waitsem);
}
/****************************************************************************
* Name: cxd56_configwaitints
*
@@ -1006,7 +983,7 @@ static void cxd56_endwait(struct cxd56_sdiodev_s *priv,
/* Wake up the waiting thread */
cxd56_givesem(priv);
nxsem_post(&priv->waitsem);
}
/****************************************************************************
@@ -2599,7 +2576,7 @@ static sdio_eventset_t cxd56_sdio_eventwait(struct sdio_dev_s *dev)
* there will be no wait.
*/
ret = cxd56_takesem(priv);
ret = nxsem_wait_uninterruptible(&priv->waitsem);
if (ret < 0)
{
/* Task canceled. Cancel the wdog (assuming it was started) and
@@ -2641,7 +2618,7 @@ static sdio_eventset_t cxd56_sdio_eventwait(struct sdio_dev_s *dev)
cxd56_configwaitints(priv, 0, 0, 0);
#ifdef CONFIG_SDIO_DMA
priv->xfrflags = 0;
priv->xfrflags = 0;
if (priv->aligned_buffer)
{
if (priv->dma_cmd == MMCSD_CMD17 || priv->dma_cmd == MMCSD_CMD18)
@@ -2655,7 +2632,6 @@ static sdio_eventset_t cxd56_sdio_eventwait(struct sdio_dev_s *dev)
/* Free aligned buffer */
kmm_free(priv->aligned_buffer);
priv->aligned_buffer = NULL;
}
#endif
+2 -15
View File
@@ -78,8 +78,6 @@ struct sph_dev_s
static int sph_open(struct file *filep);
static int sph_ioctl(struct file *filep, int cmd, unsigned long arg);
static int sph_semtake(sem_t *id);
static void sph_semgive(sem_t *id);
static int sph_lock(struct sph_dev_s *priv);
static int sph_trylock(struct sph_dev_s *priv);
static inline int sph_unlock(struct sph_dev_s *priv);
@@ -148,16 +146,6 @@ static int sph_ioctl(struct file *filep, int cmd, unsigned long arg)
return ret;
}
static int sph_semtake(sem_t *id)
{
return nxsem_wait_uninterruptible(id);
}
static void sph_semgive(sem_t *id)
{
nxsem_post(id);
}
static int sph_lock(struct sph_dev_s *priv)
{
uint32_t sts;
@@ -182,7 +170,7 @@ static int sph_lock(struct sph_dev_s *priv)
sts = getreg32(CXD56_SPH_STS(priv->id));
if (sph_state_busy(sts))
{
sph_semtake(&priv->wait);
nxsem_wait_uninterruptible(&priv->wait);
}
/* Get latest status for determining locked owner. */
@@ -268,8 +256,7 @@ static int cxd56_sphirqhandler(int irq, void *context, void *arg)
/* Give semaphore for hardware semaphore is locked */
sph_semgive(&g_sphdev[id].wait);
nxsem_post(&g_sphdev[id].wait);
return OK;
}
+7 -7
View File
@@ -37,7 +37,7 @@
#include <arch/chip/pm.h>
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <nuttx/semaphore.h>
#include <nuttx/mutex.h>
#include <nuttx/spi/spi.h>
#include "arm_internal.h"
@@ -69,7 +69,7 @@ struct cxd56_spidev_s
#ifdef CONFIG_CXD56_SPI_INTERRUPTS
uint8_t spiirq; /* SPI IRQ number */
#endif
sem_t exclsem; /* Held while chip is selected for mutual exclusion */
mutex_t lock; /* Held while chip is selected for mutual exclusion */
uint32_t frequency; /* Requested clock frequency */
uint32_t actual; /* Actual clock frequency */
uint8_t nbits; /* Width of word in bits (4 to 16) */
@@ -402,13 +402,13 @@ static int spi_lock(struct spi_dev_s *dev, bool lock)
if (lock)
{
/* Take the semaphore (perhaps waiting) */
/* Take the mutex (perhaps waiting) */
return nxsem_wait_uninterruptible(&priv->exclsem);
return nxmutex_lock(&priv->lock);
}
else
{
return nxsem_post(&priv->exclsem);
return nxmutex_unlock(&priv->lock);
}
}
@@ -1244,9 +1244,9 @@ struct spi_dev_s *cxd56_spibus_initialize(int port)
spi_setfrequency((struct spi_dev_s *)priv, 400000);
/* Initialize the SPI semaphore that enforces mutually exclusive access */
/* Initialize the SPI mutex that enforces mutually exclusive access */
nxsem_init(&priv->exclsem, 0, 1);
nxmutex_init(&priv->lock);
#ifdef CONFIG_CXD56_SPI3_SCUSEQ
/* Enable the SPI, but not enable port 3 when SCU support enabled.
+9 -22
View File
@@ -27,6 +27,7 @@
#include <nuttx/arch.h>
#include <nuttx/fs/fs.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <stdio.h>
@@ -57,8 +58,6 @@
****************************************************************************/
static int sysctl_ioctl(struct file *filep, int cmd, unsigned long arg);
static int sysctl_semtake(sem_t *semid);
static void sysctl_semgive(sem_t *semid);
static int sysctl_rxhandler(int cpuid, int protoid,
uint32_t pdata, uint32_t data,
void *userdata);
@@ -67,7 +66,7 @@ static int sysctl_rxhandler(int cpuid, int protoid,
* Private Data
****************************************************************************/
static sem_t g_exc;
static mutex_t g_lock;
static sem_t g_sync;
static int g_errcode = 0;
@@ -96,16 +95,6 @@ static int sysctl_ioctl(struct file *filep, int cmd, unsigned long arg)
return ret;
}
static int sysctl_semtake(sem_t *semid)
{
return nxsem_wait_uninterruptible(semid);
}
static void sysctl_semgive(sem_t *semid)
{
nxsem_post(semid);
}
static int sysctl_rxhandler(int cpuid, int protoid,
uint32_t pdata, uint32_t data,
void *userdata)
@@ -115,8 +104,7 @@ static int sysctl_rxhandler(int cpuid, int protoid,
g_errcode = (int)data;
sysctl_semgive(&g_sync);
nxsem_post(&g_sync);
return OK;
}
@@ -131,7 +119,7 @@ int cxd56_sysctlcmd(uint8_t id, uint32_t data)
/* Get exclusive access */
ret = sysctl_semtake(&g_exc);
ret = nxmutex_lock(&g_lock);
if (ret < 0)
{
return ret;
@@ -146,17 +134,17 @@ int cxd56_sysctlcmd(uint8_t id, uint32_t data)
ret = cxd56_iccsend(CXD56_PROTO_SYSCTL, &msg, SYSCTL_TIMEOUT);
if (ret < 0)
{
sysctl_semgive(&g_exc);
nxmutex_unlock(&g_lock);
_err("Timeout.\n");
return ret;
}
/* Wait for reply message from system CPU */
ret = sysctl_semtake(&g_sync);
ret = nxsem_wait_uninterruptible(&g_sync);
if (ret < 0)
{
sysctl_semgive(&g_exc);
nxmutex_unlock(&g_lock);
return ret;
}
@@ -164,8 +152,7 @@ int cxd56_sysctlcmd(uint8_t id, uint32_t data)
ret = g_errcode;
sysctl_semgive(&g_exc);
nxmutex_unlock(&g_lock);
return ret;
}
@@ -173,7 +160,7 @@ void cxd56_sysctlinitialize(void)
{
cxd56_iccinit(CXD56_PROTO_SYSCTL);
nxsem_init(&g_exc, 0, 1);
nxmutex_init(&g_lock);
nxsem_init(&g_sync, 0, 0);
nxsem_set_protocol(&g_sync, SEM_PRIO_NONE);
+8 -30
View File
@@ -27,7 +27,7 @@
#include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h>
#include <nuttx/irq.h>
#include <nuttx/semaphore.h>
#include <nuttx/mutex.h>
#include <stdio.h>
#include <stdint.h>
@@ -71,8 +71,6 @@ static ssize_t uart0_read(struct file *filep,
char *buffer, size_t len);
static ssize_t uart0_write(struct file *filep,
const char *buffer, size_t len);
static int uart0_semtake(sem_t *id);
static void uart0_semgive(sem_t *id);
/****************************************************************************
* FarAPI prototypes
@@ -99,30 +97,12 @@ static const struct file_operations g_uart0fops =
.write = uart0_write
};
static sem_t g_lock;
static mutex_t g_lock;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: uart0_semtake
****************************************************************************/
static int uart0_semtake(sem_t *id)
{
return nxsem_wait_uninterruptible(id);
}
/****************************************************************************
* Name: uart0_semgive
****************************************************************************/
static void uart0_semgive(sem_t *id)
{
nxsem_post(id);
}
/****************************************************************************
* Name: uart0_open
****************************************************************************/
@@ -218,13 +198,12 @@ static ssize_t uart0_read(struct file *filep,
{
int ret;
uart0_semtake(&g_lock);
nxmutex_lock(&g_lock);
ret = fw_pd_uartreceive(0, buffer, len,
((filep->f_oflags & O_NONBLOCK) != 0));
uart0_semgive(&g_lock);
nxmutex_unlock(&g_lock);
return (ssize_t)ret;
}
@@ -237,13 +216,12 @@ static ssize_t uart0_write(struct file *filep,
{
int ret;
uart0_semtake(&g_lock);
nxmutex_lock(&g_lock);
ret = fw_pd_uartsend(0, (void *)buffer, len,
((filep->f_oflags & O_NONBLOCK) != 0));
uart0_semgive(&g_lock);
nxmutex_unlock(&g_lock);
return (ssize_t)ret;
}
@@ -255,7 +233,7 @@ int cxd56_uart0initialize(const char *devname)
{
int ret;
nxsem_init(&g_lock, 0, 1);
nxmutex_init(&g_lock);
ret = register_driver(devname, &g_uart0fops, 0666, NULL);
if (ret != 0)
@@ -273,7 +251,7 @@ int cxd56_uart0initialize(const char *devname)
void cxd56_uart0uninitialize(const char *devname)
{
unregister_driver(devname);
nxsem_destroy(&g_lock);
nxmutex_destroy(&g_lock);
}
#endif /* CONFIG_CXD56_UART0 */
+6 -5
View File
@@ -33,6 +33,7 @@
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include "arm_internal.h"
@@ -67,8 +68,8 @@ struct dma_channel_s
struct dma_controller_s
{
sem_t exclsem; /* Protects channel table */
sem_t chansem; /* Count of free channels */
mutex_t lock; /* Protects channel table */
sem_t chansem; /* Count of free channels */
};
/****************************************************************************
@@ -238,7 +239,7 @@ void cxd56_udmainitialize(void)
/* Initialize the channel list */
nxsem_init(&g_dmac.exclsem, 0, 1);
nxmutex_init(&g_dmac.lock);
nxsem_init(&g_dmac.chansem, 0, CXD56_DMA_NCHANNELS);
for (i = 0; i < CXD56_DMA_NCHANNELS; i++)
@@ -306,7 +307,7 @@ DMA_HANDLE cxd56_udmachannel(void)
/* Get exclusive access to the DMA channel list */
ret = nxsem_wait_uninterruptible(&g_dmac.exclsem);
ret = nxmutex_lock(&g_dmac.lock);
if (ret < 0)
{
nxsem_post(&g_dmac.chansem);
@@ -332,7 +333,7 @@ DMA_HANDLE cxd56_udmachannel(void)
}
}
nxsem_post(&g_dmac.exclsem);
nxmutex_unlock(&g_dmac.lock);
/* Attach DMA interrupt vector */
+5 -4
View File
@@ -33,6 +33,7 @@
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include "arm_internal.h"
@@ -67,7 +68,7 @@ struct dma_channel_s
struct dma_controller_s
{
sem_t exclsem; /* Protects channel table */
mutex_t lock; /* Protects channel table */
sem_t chansem; /* Count of free channels */
};
@@ -265,7 +266,7 @@ void weak_function arm_dma_initialize(void)
/* Initialize the channel list */
nxsem_init(&g_dmac.exclsem, 0, 1);
nxmutex_init(&g_dmac.lock);
nxsem_init(&g_dmac.chansem, 0, EFM32_DMA_NCHANNELS);
for (i = 0; i < EFM32_DMA_NCHANNELS; i++)
@@ -343,7 +344,7 @@ DMA_HANDLE efm32_dmachannel(void)
/* Get exclusive access to the DMA channel list */
ret = nxsem_wait_uninterruptible(&g_dmac.exclsem);
ret = nxmutex_lock(&g_dmac.lock);
if (ret < 0)
{
nxsem_post(&g_dmac.chansem);
@@ -372,7 +373,7 @@ DMA_HANDLE efm32_dmachannel(void)
}
}
nxsem_post(&g_dmac.exclsem);
nxmutex_unlock(&g_dmac.lock);
/* Since we have reserved a DMA descriptor by taking a count from chansem,
* it would be a serious logic failure if we could not find a free channel
+14 -94
View File
@@ -53,6 +53,7 @@
#include <nuttx/arch.h>
#include <nuttx/irq.h>
#include <nuttx/clock.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <nuttx/i2c/i2c_master.h>
@@ -218,7 +219,7 @@ struct efm32_i2c_priv_s
const struct efm32_i2c_config_s *config;
int refs; /* Reference count */
sem_t sem_excl; /* Mutual exclusion semaphore */
mutex_t lock; /* Mutual exclusion mutex */
#ifndef CONFIG_I2C_POLLED
sem_t sem_isr; /* Interrupt wait semaphore */
#endif
@@ -260,18 +261,12 @@ static inline void efm32_i2c_putreg(struct efm32_i2c_priv_s *priv,
static inline void efm32_i2c_modifyreg(struct efm32_i2c_priv_s *priv,
uint8_t offset, uint32_t clearbits,
uint32_t setbits);
static inline int efm32_i2c_sem_wait(struct efm32_i2c_priv_s *priv);
static int
efm32_i2c_sem_wait_noncancelable(struct efm32_i2c_priv_s *priv);
#ifdef CONFIG_EFM32_I2C_DYNTIMEO
static uint32_t efm32_i2c_toticks(int msgc, struct i2c_msg_s *msgs);
#endif /* CONFIG_EFM32_I2C_DYNTIMEO */
static inline int efm32_i2c_sem_waitdone(struct efm32_i2c_priv_s *priv);
static inline void efm32_i2c_sem_post(struct efm32_i2c_priv_s *priv);
static inline void efm32_i2c_sem_init(struct efm32_i2c_priv_s *priv);
static inline void efm32_i2c_sem_destroy(struct efm32_i2c_priv_s *priv);
#ifdef CONFIG_I2C_TRACE
static void efm32_i2c_tracereset(struct efm32_i2c_priv_s *priv);
@@ -335,6 +330,10 @@ static struct efm32_i2c_priv_s efm32_i2c0_priv =
.ops = &efm32_i2c_ops,
.config = &efm32_i2c0_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
#ifndef CONFIG_I2C_POLLED
.sem_isr = NXSEM_INITIALIZER(0, PRIOINHERIT_FLAGS_DISABLE),
#endif
.result = I2CRESULT_NONE,
.msgc = 0,
.msgv = NULL,
@@ -362,6 +361,10 @@ static struct efm32_i2c_priv_s efm32_i2c1_priv =
.ops = &efm32_i2c_ops,
.config = &efm32_i2c1_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
#ifndef CONFIG_I2C_POLLED
.sem_isr = NXSEM_INITIALIZER(0, PRIOINHERIT_FLAGS_DISABLE),
#endif
.result = I2CRESULT_NONE,
.msgc = 0,
.msgv = NULL,
@@ -459,34 +462,6 @@ static const char *efm32_i2c_state_str(int i2c_state)
}
#endif
/****************************************************************************
* Name: efm32_i2c_sem_wait
*
* Description:
* Take the exclusive access, waiting as necessary. May be interrupted by
* a signal.
*
****************************************************************************/
static inline int efm32_i2c_sem_wait(struct efm32_i2c_priv_s *priv)
{
return nxsem_wait(&priv->sem_excl);
}
/****************************************************************************
* Name: efm32_i2c_sem_wait_noncancelable
*
* Description:
* Take the exclusive access, waiting as necessary
*
****************************************************************************/
static int
efm32_i2c_sem_wait_noncancelable(struct efm32_i2c_priv_s *priv)
{
return nxsem_wait_uninterruptible(&priv->sem_excl);
}
/****************************************************************************
* Name: efm32_i2c_toticks
*
@@ -628,57 +603,6 @@ static inline int efm32_i2c_sem_waitdone(struct efm32_i2c_priv_s *priv)
}
#endif
/****************************************************************************
* Name: efm32_i2c_sem_post
*
* Description:
* Release the mutual exclusion semaphore
*
****************************************************************************/
static inline void efm32_i2c_sem_post(struct efm32_i2c_priv_s *priv)
{
nxsem_post(&priv->sem_excl);
}
/****************************************************************************
* Name: efm32_i2c_sem_init
*
* Description:
* Initialize semaphores
*
****************************************************************************/
static inline void efm32_i2c_sem_init(struct efm32_i2c_priv_s *priv)
{
nxsem_init(&priv->sem_excl, 0, 1);
#ifndef CONFIG_I2C_POLLED
/* This semaphore is used for signaling and, hence, should not have
* priority inheritance enabled.
*/
nxsem_init(&priv->sem_isr, 0, 0);
nxsem_set_protocol(&priv->sem_isr, SEM_PRIO_NONE);
#endif
}
/****************************************************************************
* Name: efm32_i2c_sem_destroy
*
* Description:
* Destroy semaphores.
*
****************************************************************************/
static inline void efm32_i2c_sem_destroy(struct efm32_i2c_priv_s *priv)
{
nxsem_destroy(&priv->sem_excl);
#ifndef CONFIG_I2C_POLLED
nxsem_destroy(&priv->sem_isr);
#endif
}
/****************************************************************************
* Name: efm32_i2c_trace*
*
@@ -1415,7 +1339,7 @@ static int efm32_i2c_transfer(struct i2c_master_s *dev,
/* Ensure that address or flags don't change meanwhile */
ret = efm32_i2c_sem_wait(priv);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
@@ -1546,7 +1470,7 @@ static int efm32_i2c_transfer(struct i2c_master_s *dev,
priv->dcnt = 0;
priv->ptr = NULL;
efm32_i2c_sem_post(priv);
nxmutex_unlock(&priv->lock);
return ret;
}
@@ -1582,7 +1506,7 @@ int efm32_i2c_reset(struct i2c_master_s *dev)
/* Lock out other clients */
ret = efm32_i2c_sem_wait_noncancelable(priv);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
@@ -1671,7 +1595,7 @@ out:
/* Release the port for re-use by other clients */
efm32_i2c_sem_post(priv);
nxmutex_unlock(&priv->lock);
return ret;
}
#endif /* CONFIG_I2C_RESET */
@@ -1721,7 +1645,6 @@ struct i2c_master_s *efm32_i2cbus_initialize(int port)
if ((volatile int)priv->refs++ == 0)
{
efm32_i2c_sem_init(priv);
efm32_i2c_init(priv);
}
@@ -1765,9 +1688,6 @@ int efm32_i2cbus_uninitialize(struct i2c_master_s *dev)
efm32_i2c_deinit(priv);
/* Release unused resources */
efm32_i2c_sem_destroy(priv);
return OK;
}
+6 -5
View File
@@ -35,6 +35,7 @@
#include <nuttx/arch.h>
#include <nuttx/wdog.h>
#include <nuttx/clock.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <nuttx/spi/spi.h>
@@ -116,7 +117,7 @@ struct efm32_spidev_s
sem_t txdmasem; /* Wait for TX DMA to complete */
#endif
sem_t exclsem; /* Supports mutually exclusive access */
mutex_t lock; /* Supports mutually exclusive access */
uint32_t frequency; /* Requested clock frequency */
uint32_t actual; /* Actual clock frequency */
uint8_t mode; /* Mode 0,1,2,3 */
@@ -718,11 +719,11 @@ static int spi_lock(struct spi_dev_s *dev, bool lock)
if (lock)
{
ret = nxsem_wait_uninterruptible(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
}
else
{
ret = nxsem_post(&priv->exclsem);
ret = nxmutex_unlock(&priv->lock);
}
return ret;
@@ -1576,9 +1577,9 @@ static int spi_portinitialize(struct efm32_spidev_s *priv)
spi_putreg(config, EFM32_USART_CMD_OFFSET, USART_CMD_MASTEREN);
/* Initialize the SPI semaphore that enforces mutually exclusive access */
/* Initialize the SPI mutex that enforces mutually exclusive access */
nxsem_init(&priv->exclsem, 0, 1);
nxmutex_init(&priv->lock);
#ifdef CONFIG_EFM32_SPI_DMA
/* Allocate two DMA channels... one for the RX and one for the TX side of
+26 -44
View File
@@ -38,6 +38,7 @@
#include <nuttx/kmalloc.h>
#include <nuttx/clock.h>
#include <nuttx/signal.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <nuttx/usb/usb.h>
#include <nuttx/usb/usbhost.h>
@@ -250,7 +251,7 @@ struct efm32_usbhost_s
volatile bool connected; /* Connected to device */
volatile bool change; /* Connection change */
volatile bool pscwait; /* True: Thread is waiting for a port event */
sem_t exclsem; /* Support mutually exclusive access */
mutex_t lock; /* Support mutually exclusive access */
sem_t pscsem; /* Semaphore to wait for a port event */
struct efm32_ctrlinfo_s ep0; /* Root hub port EP0 description */
@@ -303,11 +304,6 @@ static inline void efm32_modifyreg(uint32_t addr, uint32_t clrbits,
# define efm32_pktdump(m,b,n)
#endif
/* Semaphores ***************************************************************/
static int efm32_takesem(sem_t *sem);
#define efm32_givesem(s) nxsem_post(s);
/* Byte stream access helper functions **************************************/
static inline uint16_t efm32_getle16(const uint8_t *val);
@@ -746,20 +742,6 @@ static inline void efm32_modifyreg(uint32_t addr, uint32_t clrbits,
efm32_putreg(addr, (((efm32_getreg(addr)) & ~clrbits) | setbits));
}
/****************************************************************************
* Name: efm32_takesem
*
* Description:
* This is just a wrapper to handle the annoying behavior of semaphore
* waits that return due to the receipt of a signal.
*
****************************************************************************/
static int efm32_takesem(sem_t *sem)
{
return nxsem_wait_uninterruptible(sem);
}
/****************************************************************************
* Name: efm32_getle16
*
@@ -1269,7 +1251,7 @@ static void efm32_chan_wakeup(struct efm32_usbhost_s *priv,
USBHOST_VTRACE2_CHANWAKEUP_OUT,
chan->epno, chan->result);
efm32_givesem(&chan->waitsem);
nxsem_post(chan->waitsem);
chan->waiter = false;
}
@@ -2965,7 +2947,7 @@ static void efm32_gint_connected(struct efm32_usbhost_s *priv)
priv->smstate = SMSTATE_ATTACHED;
if (priv->pscwait)
{
efm32_givesem(&priv->pscsem);
nxsem_post(&priv->pscsem);
priv->pscwait = false;
}
}
@@ -3012,7 +2994,7 @@ static void efm32_gint_disconnected(struct efm32_usbhost_s *priv)
if (priv->pscwait)
{
efm32_givesem(&priv->pscsem);
nxsem_post(&priv->pscsem);
priv->pscwait = false;
}
}
@@ -3918,7 +3900,7 @@ static int efm32_wait(struct usbhost_connection_s *conn,
/* Wait for the next connection event */
priv->pscwait = true;
ret = efm32_takesem(&priv->pscsem);
ret = nxsem_wait_uninterruptible(&priv->pscsem);
if (ret < 0)
{
return ret;
@@ -4099,7 +4081,7 @@ static int efm32_ep0configure(struct usbhost_driver_s *drvr,
* structures.
*/
ret = efm32_takesem(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
@@ -4123,7 +4105,7 @@ static int efm32_ep0configure(struct usbhost_driver_s *drvr,
efm32_chan_configure(priv, ep0info->inndx);
efm32_givesem(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return OK;
}
@@ -4166,7 +4148,7 @@ static int efm32_epalloc(struct usbhost_driver_s *drvr,
* structures.
*/
ret = efm32_takesem(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
@@ -4187,7 +4169,7 @@ static int efm32_epalloc(struct usbhost_driver_s *drvr,
ret = efm32_xfrep_alloc(priv, epdesc, ep);
}
efm32_givesem(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return ret;
}
@@ -4220,7 +4202,7 @@ static int efm32_epfree(struct usbhost_driver_s *drvr, usbhost_ep_t ep)
/* We must have exclusive access to the USB host hardware and structures */
ret = efm32_takesem(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
@@ -4252,7 +4234,7 @@ static int efm32_epfree(struct usbhost_driver_s *drvr, usbhost_ep_t ep)
kmm_free(ctrlep);
}
efm32_givesem(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return OK;
}
@@ -4490,7 +4472,7 @@ static int efm32_ctrlin(struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
* structures.
*/
ret = efm32_takesem(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
@@ -4534,7 +4516,7 @@ static int efm32_ctrlin(struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
{
/* All success transactions exit here */
efm32_givesem(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return OK;
}
@@ -4549,7 +4531,7 @@ static int efm32_ctrlin(struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
/* All failures exit here after all retries and timeouts are exhausted */
efm32_givesem(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return -ETIMEDOUT;
}
@@ -4577,7 +4559,7 @@ static int efm32_ctrlout(struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
/* We must have exclusive access to the USB host hardware and structures */
ret = efm32_takesem(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
@@ -4625,7 +4607,7 @@ static int efm32_ctrlout(struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
{
/* All success transactins exit here */
efm32_givesem(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return OK;
}
@@ -4641,7 +4623,7 @@ static int efm32_ctrlout(struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
/* All failures exit here after all retries and timeouts are exhausted */
efm32_givesem(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return -ETIMEDOUT;
}
@@ -4698,7 +4680,7 @@ static ssize_t efm32_transfer(struct usbhost_driver_s *drvr,
/* We must have exclusive access to the USB host hardware and structures */
ret = efm32_takesem(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return (ssize_t)ret;
@@ -4715,7 +4697,7 @@ static ssize_t efm32_transfer(struct usbhost_driver_s *drvr,
nbytes = efm32_out_transfer(priv, chidx, buffer, buflen);
}
efm32_givesem(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return nbytes;
}
@@ -4770,7 +4752,7 @@ static int efm32_asynch(struct usbhost_driver_s *drvr, usbhost_ep_t ep,
/* We must have exclusive access to the USB host hardware and structures */
ret = efm32_takesem(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
@@ -4787,7 +4769,7 @@ static int efm32_asynch(struct usbhost_driver_s *drvr, usbhost_ep_t ep,
ret = efm32_out_asynch(priv, chidx, buffer, buflen, callback, arg);
}
efm32_givesem(&priv->exclsem);
nxmutex_unlock(&priv->lock);
return ret;
}
#endif /* CONFIG_USBHOST_ASYNCH */
@@ -4846,7 +4828,7 @@ static int efm32_cancel(struct usbhost_driver_s *drvr, usbhost_ep_t ep)
/* Wake'em up! */
efm32_givesem(&chan->waitsem);
nxsem_post(&chan->waitsem);
chan->waiter = false;
}
@@ -4923,7 +4905,7 @@ static int efm32_connect(struct usbhost_driver_s *drvr,
if (priv->pscwait)
{
priv->pscwait = false;
efm32_givesem(&priv->pscsem);
nxsem_post(&priv->pscsem);
}
leave_critical_section(flags);
@@ -5277,10 +5259,10 @@ static inline void efm32_sw_initialize(struct efm32_usbhost_s *priv)
usbhost_devaddr_initialize(&priv->rhport);
/* Initialize semaphores */
/* Initialize semaphores & mutex */
nxsem_init(&priv->pscsem, 0, 0);
nxsem_init(&priv->exclsem, 0, 1);
nxmutex_init(&priv->lock);
/* The pscsem semaphore is used for signaling and, hence, should not have
* priority inheritance enabled.
+2 -29
View File
@@ -211,32 +211,6 @@ static void gd32_dma_clock_enable(uint32_t dmabase)
modifyreg32(regaddr, 0, rcu_en);
}
/****************************************************************************
* Name: gd32_dmasem_take
*
* Description:
* Used to request exclusive access to a DMA channel.
*
****************************************************************************/
static int gd32_dmasem_take(struct gd32_dma_channel_s *dmachan)
{
return nxsem_wait_uninterruptible(&dmachan->chsem);
}
/****************************************************************************
* Name: gd32_dmasem_give
*
* Description:
* Used to free exclusive access to a DMA channel.
*
****************************************************************************/
static inline void gd32_dmasem_give(struct gd32_dma_channel_s *dmachan)
{
nxsem_post(&dmachan->chsem);
}
/****************************************************************************
* Name: gd32_dma_channel_get
*
@@ -647,10 +621,9 @@ DMA_HANDLE gd32_dma_channel_alloc(uint8_t periph_req)
/* Get exclusive access to the DMA channel */
ret = gd32_dmasem_take(dmachan);
ret = nxsem_wait_uninterruptible(&dmachan->chsem);
if (ret < 0)
{
gd32_dmasem_give(dmachan);
return NULL;
}
@@ -692,7 +665,7 @@ void gd32_dma_channel_free(DMA_HANDLE handle)
/* Release the channel */
gd32_dmasem_give(dmachan);
nxsem_post(&dmachan->chsem);
}
/****************************************************************************
+6 -39
View File
@@ -24,7 +24,7 @@
#include <nuttx/config.h>
#include <nuttx/arch.h>
#include <nuttx/semaphore.h>
#include <nuttx/mutex.h>
#include <stdbool.h>
#include <assert.h>
@@ -41,43 +41,12 @@
* Private Data
****************************************************************************/
static sem_t g_gd32_fmc_sem = SEM_INITIALIZER(1);
static mutex_t g_gd32_fmc_lock = NXMUTEX_INITIALIZER;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: gd32_fmc_sem_lock
*
* Description:
* Lock semaphore
*
* Return Value:
* Zero(OK) - On success
* EINVAL - Invalid attempt to get the semaphore
* ECANCELED - May be returned if the thread is canceled while waiting
*
****************************************************************************/
static int gd32_fmc_sem_lock(void)
{
return nxsem_wait_uninterruptible(&g_gd32_fmc_sem);
}
/****************************************************************************
* Name: gd32_fmc_sem_unlock
*
* Description:
* Lock semaphore
*
****************************************************************************/
static void gd32_fmc_sem_unlock(void)
{
nxsem_post(&g_gd32_fmc_sem);
}
/****************************************************************************
* Name: gd32_fmc_state_get
*
@@ -203,7 +172,7 @@ int gd32_fmc_unlock(void)
{
int ret;
ret = gd32_fmc_sem_lock();
ret = nxmutex_lock(&g_gd32_fmc_lock);
if (ret < 0)
{
return ret;
@@ -217,8 +186,7 @@ int gd32_fmc_unlock(void)
putreg32(FMC_UNLOCK_KEY1, GD32_FMC_KEY);
}
gd32_fmc_sem_unlock();
nxmutex_unlock(&g_gd32_fmc_lock);
return ret;
}
@@ -234,7 +202,7 @@ int gd32_fmc_lock(void)
{
int ret;
ret = gd32_fmc_sem_lock();
ret = nxmutex_lock(&g_gd32_fmc_lock);
if (ret < 0)
{
return ret;
@@ -244,8 +212,7 @@ int gd32_fmc_lock(void)
modifyreg32(GD32_FMC_CTL, 0, FMC_CTL_LK);
gd32_fmc_sem_unlock();
nxmutex_unlock(&g_gd32_fmc_lock);
return ret;
}
+7 -41
View File
@@ -31,7 +31,7 @@
#include <arch/board/board.h>
#include <nuttx/progmem.h>
#include <nuttx/irq.h>
#include <nuttx/semaphore.h>
#include <nuttx/mutex.h>
#include "gd32f4xx_progmem.h"
#include "gd32f4xx_fmc.h"
@@ -126,7 +126,7 @@ typedef struct
static const size_t sector_sizes[FMC_PROGMEM_SECTOR_NUM] =
FMC_PROGMEM_SECTOR_SIZES;
static sem_t g_gd32_progmem_sem = SEM_INITIALIZER(1);
static mutex_t g_gd32_progmem_lock = NXMUTEX_INITIALIZER;
/****************************************************************************
* Private Function Prototypes
@@ -248,37 +248,6 @@ static fmc_sector_info_struct gd32_fmc_sector_info_get(uint32_t addr)
return sector_info;
}
/****************************************************************************
* Name: gd32_progmem_sem_lock
*
* Description:
* Lock semaphore
*
* Return Value:
* Zero(OK) - On success
* EINVAL - Invalid attempt to get the semaphore
* ECANCELED - May be returned if the thread is canceled while waiting
*
****************************************************************************/
static int gd32_progmem_sem_lock(void)
{
return nxsem_wait_uninterruptible(&g_gd32_progmem_sem);
}
/****************************************************************************
* Name: gd32_progmem_sem_unlock
*
* Description:
* Lock semaphore
*
****************************************************************************/
static void gd32_progmem_sem_unlock(void)
{
nxsem_post(&g_gd32_progmem_sem);
}
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -572,8 +541,7 @@ ssize_t up_progmem_write(size_t addr, const void *buf, size_t count)
return -EFAULT;
}
ret = gd32_progmem_sem_lock();
ret = nxmutex_lock(&g_gd32_progmem_lock);
if (ret < 0)
{
return -EFAULT;
@@ -590,7 +558,7 @@ ssize_t up_progmem_write(size_t addr, const void *buf, size_t count)
if (getreg8(addr) != *byte)
{
gd32_fmc_lock();
gd32_progmem_sem_unlock();
nxmutex_unlock(&g_gd32_progmem_lock);
return -EIO;
}
@@ -599,8 +567,7 @@ ssize_t up_progmem_write(size_t addr, const void *buf, size_t count)
}
gd32_fmc_lock();
gd32_progmem_sem_unlock();
nxmutex_unlock(&g_gd32_progmem_lock);
return count;
}
@@ -653,8 +620,7 @@ ssize_t up_progmem_read(size_t addr, void *buf, size_t count)
return -EFAULT;
}
ret = gd32_progmem_sem_lock();
ret = nxmutex_lock(&g_gd32_progmem_lock);
if (ret < 0)
{
return -EFAULT;
@@ -668,7 +634,7 @@ ssize_t up_progmem_read(size_t addr, void *buf, size_t count)
addr++;
}
gd32_progmem_sem_unlock();
nxmutex_unlock(&g_gd32_progmem_lock);
}
#endif
+6 -5
View File
@@ -57,6 +57,7 @@
#include <debug.h>
#include <nuttx/arch.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <nuttx/spi/spi.h>
@@ -148,7 +149,7 @@ struct gd32_spidev_s
uint32_t spiclock; /* Clocking for the SPI module */
uint32_t frequency; /* Requested clock frequency */
uint32_t actual; /* Actual clock frequency */
sem_t exclsem; /* Held while chip is selected for mutual exclusion */
mutex_t lock; /* Held while chip is selected for mutual exclusion */
uint8_t nbits; /* Width of word in bits (8 to 16) */
uint8_t mode; /* Mode 0,1,2,3 */
#ifdef CONFIG_GD32F4_SPI_INTERRUPT
@@ -1096,11 +1097,11 @@ static int spi_lock(struct spi_dev_s *dev, bool lock)
if (lock)
{
ret = nxsem_wait_uninterruptible(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
}
else
{
ret = nxsem_post(&priv->exclsem);
ret = nxmutex_unlock(&priv->lock);
}
return ret;
@@ -2111,9 +2112,9 @@ static void spi_bus_initialize(struct gd32_spidev_s *priv)
spi_setfrequency((struct spi_dev_s *)priv, 400000);
/* Initialize the SPI semaphore that enforces mutually exclusive access */
/* Initialize the SPI lock that enforces mutually exclusive access */
nxsem_init(&priv->exclsem, 0, 1);
nxmutex_init(&priv->lock);
#ifdef CONFIG_GD32F4_SPI_DMA
/* Initialize the SPI semaphores that is used to wait for DMA completion.
+5 -4
View File
@@ -34,6 +34,7 @@
#include <nuttx/spi/spi.h>
#include <nuttx/irq.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <arch/board/board.h>
@@ -85,7 +86,7 @@ struct imx_spidev_s
#ifndef CONFIG_SPI_POLLWAIT
sem_t waitsem; /* Wait for transfer to complete */
#endif
sem_t exclsem; /* Supports mutually exclusive access */
mutex_t lock; /* Supports mutually exclusive access */
/* These following are the source and destination buffers of the transfer.
* they are retained in this structure so that they will be accessible
@@ -703,11 +704,11 @@ static int spi_lock(struct spi_dev_s *dev, bool lock)
if (lock)
{
ret = nxsem_wait_uninterruptible(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
}
else
{
ret = nxsem_post(&priv->exclsem);
ret = nxmutex_unlock(&priv->lock);
}
return ret;
@@ -1116,7 +1117,7 @@ struct spi_dev_s *imx_spibus_initialize(int port)
nxsem_init(&priv->waitsem, 0, 0);
nxsem_set_protocol(&priv->waitsem, SEM_PRIO_NONE);
#endif
nxsem_init(&priv->exclsem, 0, 1);
nxmutex_init(&priv->lock);
/* Initialize control register:
* min frequency, ignore ready, master mode, mode=0, 8-bit
+5 -4
View File
@@ -31,6 +31,7 @@
#include <debug.h>
#include <nuttx/arch.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <nuttx/spi/spi.h>
@@ -128,7 +129,7 @@ struct imx_spidev_s
#ifndef CONFIG_SPI_POLLWAIT
sem_t waitsem; /* Wait for transfer to complete */
#endif
sem_t exclsem; /* Supports mutually exclusive access */
mutex_t lock; /* Supports mutually exclusive access */
/* These following are the source and destination buffers of the transfer.
* they are retained in this structure so that they will be accessible
@@ -777,11 +778,11 @@ static int spi_lock(struct spi_dev_s *dev, bool lock)
if (lock)
{
ret = nxsem_wait_uninterruptible(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
}
else
{
ret = nxsem_post(&priv->exclsem);
ret = nxmutex_unlock(&priv->lock);
}
return ret;
@@ -1292,7 +1293,7 @@ struct spi_dev_s *imx_spibus_initialize(int port)
nxsem_init(&priv->waitsem, 0, 0);
nxsem_set_protocol(&priv->waitsem, SEM_PRIO_NONE);
#endif
nxsem_init(&priv->exclsem, 0, 1);
nxmutex_init(&priv->lock);
/* Initialize control register:
* min frequency, ignore ready, master mode, mode=0, 8-bit
+7 -25
View File
@@ -57,6 +57,7 @@
#include <nuttx/arch.h>
#include <nuttx/queue.h>
#include <nuttx/spinlock.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include "arm_internal.h"
@@ -136,9 +137,9 @@ struct imxrt_dmach_s
struct imxrt_edma_s
{
/* These semaphores protect the DMA channel and descriptor tables */
/* These mutex protect the DMA channel and descriptor tables */
sem_t chsem; /* Protects channel table */
mutex_t chlock; /* Protects channel table */
#if CONFIG_IMXRT_EDMA_NTCD > 0
sem_t dsem; /* Supports wait for free descriptors */
#endif
@@ -171,25 +172,6 @@ static struct imxrt_edmatcd_s g_tcd_pool[CONFIG_IMXRT_EDMA_NTCD]
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: imxrt_takechsem() and imxrt_givechsem()
*
* Description:
* Used to get exclusive access to the DMA channel table for channel
* allocation.
*
****************************************************************************/
static int imxrt_takechsem(void)
{
return nxsem_wait_uninterruptible(&g_edma.chsem);
}
static inline void imxrt_givechsem(void)
{
nxsem_post(&g_edma.chsem);
}
/****************************************************************************
* Name: imxrt_takedsem() and imxrt_givedsem()
*
@@ -764,9 +746,9 @@ void weak_function arm_dma_initialize(void)
g_edma.dmach[i].chan = i;
}
/* Initialize semaphores */
/* Initialize mutex & semaphores */
nxsem_init(&g_edma.chsem, 0, 1);
nxmutex_init(&g_edma.chlock);
#if CONFIG_IMXRT_EDMA_NTCD > 0
nxsem_init(&g_edma.dsem, 0, CONFIG_IMXRT_EDMA_NTCD);
@@ -880,7 +862,7 @@ DMACH_HANDLE imxrt_dmach_alloc(uint32_t dmamux, uint8_t dchpri)
/* Search for an available DMA channel */
dmach = NULL;
ret = imxrt_takechsem();
ret = nxmutex_lock(&g_edma.chlock);
if (ret < 0)
{
return NULL;
@@ -917,7 +899,7 @@ DMACH_HANDLE imxrt_dmach_alloc(uint32_t dmamux, uint8_t dchpri)
}
}
imxrt_givechsem();
nxmutex_unlock(&g_edma.chlock);
/* Show the result of the allocation */
+54 -109
View File
@@ -36,6 +36,7 @@
#include <nuttx/kmalloc.h>
#include <nuttx/wqueue.h>
#include <nuttx/signal.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <nuttx/usb/usb.h>
#include <nuttx/usb/usbhost.h>
@@ -275,7 +276,7 @@ struct imxrt_ehci_s
{
volatile bool pscwait; /* TRUE: Thread is waiting for port status change event */
sem_t exclsem; /* Support mutually exclusive access */
mutex_t lock; /* Support mutually exclusive access */
sem_t pscsem; /* Semaphore to wait for port status change events */
struct imxrt_epinfo_s ep0; /* Endpoint 0 */
@@ -416,12 +417,6 @@ static inline void imxrt_putreg(uint32_t regval, volatile uint32_t *regaddr);
static int ehci_wait_usbsts(uint32_t maskbits, uint32_t donebits,
unsigned int delay);
/* Semaphores ***************************************************************/
static int imxrt_takesem(sem_t *sem);
static int imxrt_takesem_noncancelable(sem_t *sem);
#define imxrt_givesem(s) nxsem_post(s);
/* Allocators ***************************************************************/
static struct imxrt_qh_s *imxrt_qh_alloc(void);
@@ -1053,61 +1048,13 @@ static int ehci_wait_usbsts(uint32_t maskbits, uint32_t donebits,
return (regval == donebits) ? OK : -ETIMEDOUT;
}
/****************************************************************************
* Name: imxrt_takesem
*
* Description:
* This is just a wrapper to handle the annoying behavior of semaphore
* waits that return due to the receipt of a signal.
*
****************************************************************************/
static int imxrt_takesem(sem_t *sem)
{
return nxsem_wait_uninterruptible(sem);
}
/****************************************************************************
* Name: imxrt_takesem_noncancelable
*
* Description:
* This is just a wrapper to handle the annoying behavior of semaphore
* waits that return due to the receipt of a signal. This version also
* ignores attempts to cancel the thread.
*
****************************************************************************/
static int imxrt_takesem_noncancelable(sem_t *sem)
{
int result;
int ret = OK;
do
{
result = nxsem_wait_uninterruptible(sem);
/* The only expected error is ECANCELED which would occur if the
* calling thread were canceled.
*/
DEBUGASSERT(result == OK || result == -ECANCELED);
if (ret == OK && result < 0)
{
ret = result;
}
}
while (result < 0);
return ret;
}
/****************************************************************************
* Name: imxrt_qh_alloc
*
* Description:
* Allocate a Queue Head (QH) structure by removing it from the free list
*
* Assumption: Caller holds the exclsem
* Assumption: Caller holds the lock
*
****************************************************************************/
@@ -1133,7 +1080,7 @@ static struct imxrt_qh_s *imxrt_qh_alloc(void)
* Description:
* Free a Queue Head (QH) structure by returning it to the free list
*
* Assumption: Caller holds the exclsem
* Assumption: Caller holds the lock
*
****************************************************************************/
@@ -1154,7 +1101,7 @@ static void imxrt_qh_free(struct imxrt_qh_s *qh)
* Allocate a Queue Element Transfer Descriptor (qTD) by removing it from
* the free list
*
* Assumption: Caller holds the exclsem
* Assumption: Caller holds the lock
*
****************************************************************************/
@@ -1182,7 +1129,7 @@ static struct imxrt_qtd_s *imxrt_qtd_alloc(void)
* free list
*
* Assumption:
* Caller holds the exclsem
* Caller holds the lock
*
****************************************************************************/
@@ -1630,7 +1577,7 @@ static inline uint8_t imxrt_ehci_speed(uint8_t usbspeed)
* this to minimize race conditions. This logic would have to be expanded
* if we want to have more than one packet in flight at a time!
*
* Assumption: The caller holds the EHCI exclsem
* Assumption: The caller holds the EHCI lock
*
****************************************************************************/
@@ -1676,7 +1623,7 @@ static int imxrt_ioc_setup(struct imxrt_rhport_s *rhport,
* Description:
* Wait for the IOC event.
*
* Assumption: The caller does *NOT* hold the EHCI exclsem. That would
* Assumption: The caller does *NOT* hold the EHCI lock. That would
* cause a deadlock when the bottom-half, worker thread needs to take the
* semaphore.
*
@@ -1692,7 +1639,7 @@ static int imxrt_ioc_wait(struct imxrt_epinfo_s *epinfo)
while (epinfo->iocwait)
{
ret = imxrt_takesem(&epinfo->iocsem);
ret = nxsem_wait_uninterruptible(&epinfo->iocsem);
if (ret < 0)
{
break;
@@ -1708,7 +1655,7 @@ static int imxrt_ioc_wait(struct imxrt_epinfo_s *epinfo)
* Description:
* Add a new, ready-to-go QH w/attached qTDs to the asynchronous queue.
*
* Assumptions: The caller holds the EHCI exclsem
* Assumptions: The caller holds the EHCI lock
*
****************************************************************************/
@@ -2155,7 +2102,7 @@ static struct imxrt_qtd_s *imxrt_qtd_statusphase(uint32_t tokenbits)
* This is a blocking function; it will not return until the control
* transfer has completed.
*
* Assumption: The caller holds the EHCI exclsem.
* Assumption: The caller holds the EHCI lock.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is return on
@@ -2438,7 +2385,7 @@ errout_with_qh:
* frame list), followed by shorter poll rates, with queue heads with a
* poll rate of one, on the very end."
*
* Assumption: The caller holds the EHCI exclsem.
* Assumption: The caller holds the EHCI lock.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is return on
@@ -2542,8 +2489,8 @@ errout_with_qh:
* Description:
* Wait for an IN or OUT transfer to complete.
*
* Assumption: The caller holds the EHCI exclsem. The caller must be aware
* that the EHCI exclsem will released while waiting for the transfer to
* Assumption: The caller holds the EHCI lock. The caller must be aware
* that the EHCI lock will released while waiting for the transfer to
* complete, but will be re-acquired when before returning. The state of
* EHCI resources could be very different upon return.
*
@@ -2561,29 +2508,29 @@ static ssize_t imxrt_transfer_wait(struct imxrt_epinfo_s *epinfo)
int ret;
int ret2;
/* Release the EHCI semaphore while we wait. Other threads need the
/* Release the EHCI lock while we wait. Other threads need the
* opportunity to access the EHCI resources while we wait.
*
* REVISIT: Is this safe? NO. This is a bug and needs rethinking.
* We need to lock all of the port-resources (not EHCI common) until
* the transfer is complete. But we can't use the common EHCI exclsem
* the transfer is complete. But we can't use the common EHCI lock
* or we will deadlock while waiting (because the working thread that
* wakes this thread up needs the exclsem).
* wakes this thread up needs the lock).
*/
/* REVISIT */
imxrt_givesem(&g_ehci.exclsem);
nxmutex_unlock(&g_ehci.lock);
/* Wait for the IOC completion event */
ret = imxrt_ioc_wait(epinfo);
/* Re-acquire the EHCI semaphore. The caller expects to be holding
/* Re-acquire the EHCI lock. The caller expects to be holding
* this upon return.
*/
ret2 = imxrt_takesem_noncancelable(&g_ehci.exclsem);
ret2 = nxmutex_lock(&g_ehci.lock);
if (ret >= 0 && ret2 < 0)
{
ret = ret2;
@@ -2607,9 +2554,7 @@ static ssize_t imxrt_transfer_wait(struct imxrt_epinfo_s *epinfo)
}
#endif
/* Did imxrt_ioc_wait() or imxrt_takesem_noncancelable() report an
* error?
*/
/* Did imxrt_ioc_wait() or nxmutex_lock() report an error? */
if (ret < 0)
{
@@ -2917,7 +2862,7 @@ static int imxrt_qh_ioccheck(struct imxrt_qh_s *qh, uint32_t **bp, void *arg)
/* Yes... wake it up */
epinfo->iocwait = false;
imxrt_givesem(&epinfo->iocsem);
nxsem_post(&epinfo->iocsem);
}
#ifdef CONFIG_USBHOST_ASYNCH
@@ -3076,7 +3021,7 @@ static int imxrt_qh_cancel(struct imxrt_qh_s *qh, uint32_t **bp, void *arg)
* detected (actual number of bytes received was less than the expected
* number of bytes)."
*
* Assumptions: The caller holds the EHCI exclsem
* Assumptions: The caller holds the EHCI lock
*
****************************************************************************/
@@ -3213,7 +3158,7 @@ static inline void imxrt_portsc_bottomhalf(void)
if (g_ehci.pscwait)
{
imxrt_givesem(&g_ehci.pscsem);
nxsem_post(&g_ehci.pscsem);
g_ehci.pscwait = false;
}
}
@@ -3253,7 +3198,7 @@ static inline void imxrt_portsc_bottomhalf(void)
if (g_ehci.pscwait)
{
imxrt_givesem(&g_ehci.pscsem);
nxsem_post(&g_ehci.pscsem);
g_ehci.pscwait = false;
}
}
@@ -3330,7 +3275,7 @@ static void imxrt_ehci_bottomhalf(void *arg)
* real option (other than to reschedule and delay).
*/
imxrt_takesem_noncancelable(&g_ehci.exclsem);
nxmutex_lock(&g_ehci.lock);
/* Handle all unmasked interrupt sources
* USB Interrupt (USBINT)
@@ -3441,7 +3386,7 @@ static void imxrt_ehci_bottomhalf(void *arg)
/* We are done with the EHCI structures */
imxrt_givesem(&g_ehci.exclsem);
nxmutex_unlock(&g_ehci.lock);
/* Re-enable relevant EHCI interrupts. Interrupts should still be enabled
* at the level of the interrupt controller.
@@ -3600,7 +3545,7 @@ static int imxrt_wait(struct usbhost_connection_s *conn,
*/
g_ehci.pscwait = true;
ret = imxrt_takesem(&g_ehci.pscsem);
ret = nxsem_wait_uninterruptible(&g_ehci.pscsem);
if (ret < 0)
{
return ret;
@@ -3935,7 +3880,7 @@ static int imxrt_ep0configure(struct usbhost_driver_s *drvr,
/* We must have exclusive access to the EHCI data structures. */
ret = imxrt_takesem(&g_ehci.exclsem);
ret = nxmutex_lock(&g_ehci.lock);
if (ret >= 0)
{
/* Remember the new device address and max packet size */
@@ -3944,7 +3889,7 @@ static int imxrt_ep0configure(struct usbhost_driver_s *drvr,
epinfo->speed = speed;
epinfo->maxpacket = maxpacketsize;
imxrt_givesem(&g_ehci.exclsem);
nxmutex_unlock(&g_ehci.lock);
}
return ret;
@@ -4307,7 +4252,7 @@ static int imxrt_ctrlin(struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
* structures.
*/
ret = imxrt_takesem(&g_ehci.exclsem);
ret = nxmutex_lock(&g_ehci.lock);
if (ret < 0)
{
return ret;
@@ -4319,7 +4264,7 @@ static int imxrt_ctrlin(struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
if (ret != OK)
{
usbhost_trace1(EHCI_TRACE1_DEVDISCONNECTED, -ret);
goto errout_with_sem;
goto errout_with_lock;
}
/* Now initiate the transfer */
@@ -4334,13 +4279,13 @@ static int imxrt_ctrlin(struct usbhost_driver_s *drvr, usbhost_ep_t ep0,
/* And wait for the transfer to complete */
nbytes = imxrt_transfer_wait(ep0info);
imxrt_givesem(&g_ehci.exclsem);
nxmutex_unlock(&g_ehci.lock);
return nbytes >= 0 ? OK : (int)nbytes;
errout_with_iocwait:
ep0info->iocwait = false;
errout_with_sem:
imxrt_givesem(&g_ehci.exclsem);
errout_with_lock:
nxmutex_unlock(&g_ehci.lock);
return ret;
}
@@ -4409,7 +4354,7 @@ static ssize_t imxrt_transfer(struct usbhost_driver_s *drvr,
* structures.
*/
ret = imxrt_takesem(&g_ehci.exclsem);
ret = nxmutex_lock(&g_ehci.lock);
if (ret < 0)
{
return (ssize_t)ret;
@@ -4423,7 +4368,7 @@ static ssize_t imxrt_transfer(struct usbhost_driver_s *drvr,
if (ret != OK)
{
usbhost_trace1(EHCI_TRACE1_DEVDISCONNECTED, -ret);
goto errout_with_sem;
goto errout_with_lock;
}
/* Initiate the transfer */
@@ -4461,14 +4406,14 @@ static ssize_t imxrt_transfer(struct usbhost_driver_s *drvr,
/* Then wait for the transfer to complete */
nbytes = imxrt_transfer_wait(epinfo);
imxrt_givesem(&g_ehci.exclsem);
nxmutex_unlock(&g_ehci.lock);
return nbytes;
errout_with_iocwait:
epinfo->iocwait = false;
errout_with_sem:
errout_with_lock:
uerr("!!!\n");
imxrt_givesem(&g_ehci.exclsem);
nxmutex_unlock(&g_ehci.lock);
return (ssize_t)ret;
}
@@ -4523,7 +4468,7 @@ static int imxrt_asynch(struct usbhost_driver_s *drvr, usbhost_ep_t ep,
* structures.
*/
ret = imxrt_takesem(&g_ehci.exclsem);
ret = nxmutex_lock(&g_ehci.lock);
if (ret < 0)
{
return ret;
@@ -4535,7 +4480,7 @@ static int imxrt_asynch(struct usbhost_driver_s *drvr, usbhost_ep_t ep,
if (ret != OK)
{
usbhost_trace1(EHCI_TRACE1_DEVDISCONNECTED, -ret);
goto errout_with_sem;
goto errout_with_lock;
}
/* Initiate the transfer */
@@ -4572,14 +4517,14 @@ static int imxrt_asynch(struct usbhost_driver_s *drvr, usbhost_ep_t ep,
/* The transfer is in progress */
imxrt_givesem(&g_ehci.exclsem);
nxmutex_unlock(&g_ehci.lock);
return OK;
errout_with_callback:
epinfo->callback = NULL;
epinfo->arg = NULL;
errout_with_sem:
imxrt_givesem(&g_ehci.exclsem);
errout_with_lock:
nxmutex_unlock(&g_ehci.lock);
return ret;
}
#endif /* CONFIG_USBHOST_ASYNCH */
@@ -4627,7 +4572,7 @@ static int imxrt_cancel(struct usbhost_driver_s *drvr, usbhost_ep_t ep)
* interrupt level.
*/
ret = imxrt_takesem(&g_ehci.exclsem);
ret = nxmutex_lock(&g_ehci.lock);
if (ret < 0)
{
return ret;
@@ -4670,7 +4615,7 @@ static int imxrt_cancel(struct usbhost_driver_s *drvr, usbhost_ep_t ep)
#endif
{
ret = OK;
goto errout_with_sem;
goto errout_with_lock;
}
/* Handle the cancellation according to the type of the transfer */
@@ -4733,7 +4678,7 @@ static int imxrt_cancel(struct usbhost_driver_s *drvr, usbhost_ep_t ep)
default:
usbhost_trace1(EHCI_TRACE1_BADXFRTYPE, epinfo->xfrtype);
ret = -ENOSYS;
goto errout_with_sem;
goto errout_with_lock;
}
/* Find and remove the QH. There are four possibilities:
@@ -4763,7 +4708,7 @@ exit_terminate:
/* Yes... wake it up */
DEBUGASSERT(callback == NULL);
imxrt_givesem(&epinfo->iocsem);
nxsem_post(&epinfo->iocsem);
}
/* No.. Is there a pending asynchronous transfer? */
@@ -4778,11 +4723,11 @@ exit_terminate:
#else
/* Wake up the waiting thread */
imxrt_givesem(&epinfo->iocsem);
nxsem_post(&epinfo->iocsem);
#endif
errout_with_sem:
imxrt_givesem(&g_ehci.exclsem);
errout_with_lock:
nxmutex_unlock(&g_ehci.lock);
return ret;
}
@@ -4829,7 +4774,7 @@ static int imxrt_connect(struct usbhost_driver_s *drvr,
if (g_ehci.pscwait)
{
g_ehci.pscwait = false;
imxrt_givesem(&g_ehci.pscsem);
nxsem_post(&g_ehci.pscsem);
}
leave_critical_section(flags);
@@ -5055,7 +5000,7 @@ struct usbhost_connection_s *imxrt_ehci_initialize(int controller)
/* Initialize the EHCI state data structure */
nxsem_init(&g_ehci.exclsem, 0, 1);
nxmutex_init(&g_ehci.lock);
nxsem_init(&g_ehci.pscsem, 0, 0);
/* The pscsem semaphore is used for signaling and, hence, should not have
+12 -43
View File
@@ -32,7 +32,7 @@
#include <nuttx/arch.h>
#include <nuttx/irq.h>
#include <nuttx/sensors/qencoder.h>
#include <nuttx/semaphore.h>
#include <nuttx/mutex.h>
#include "chip.h"
#include "arm_internal.h"
@@ -302,7 +302,7 @@ struct imxrt_enc_lowerhalf_s
const struct imxrt_qeconfig_s *config; /* static configuration */
struct qe_index_s *data;
sem_t sem_excl; /* Mutual exclusion semaphore to
mutex_t lock; /* Mutual exclusion mutex to
* ensure atomic 32-bit reads.
*/
};
@@ -324,10 +324,6 @@ static inline void imxrt_enc_modifyreg16
static void imxrt_enc_clock_enable (uint32_t base);
static void imxrt_enc_clock_disable (uint32_t base);
static inline int imxrt_enc_sem_wait(struct imxrt_enc_lowerhalf_s *priv);
static inline void imxrt_enc_sem_post
(struct imxrt_enc_lowerhalf_s *priv);
static int imxrt_enc_reconfig(struct imxrt_enc_lowerhalf_s *priv,
uint16_t args);
static void imxrt_enc_set_initial_val(struct imxrt_enc_lowerhalf_s *priv,
@@ -635,32 +631,6 @@ void imxrt_enc_clock_disable(uint32_t base)
#endif /* CONFIG_ARCH_FAMILY_IMXRT105x || CONFIG_ARCH_FAMILY_IMXRT106x */
}
/****************************************************************************
* Name: imxrt_enc_sem_wait
*
* Description:
* Take exclusive access to the position register, waiting as necessary
*
****************************************************************************/
static inline int imxrt_enc_sem_wait(struct imxrt_enc_lowerhalf_s *priv)
{
return nxsem_wait_uninterruptible(&priv->sem_excl);
}
/****************************************************************************
* Name: imxrt_enc_sem_post
*
* Description:
* Release the mutual exclusion semaphore
*
****************************************************************************/
static inline void imxrt_enc_sem_post(struct imxrt_enc_lowerhalf_s *priv)
{
nxsem_post(&priv->sem_excl);
}
/****************************************************************************
* Name: imxrt_enc_reconfig
*
@@ -939,7 +909,7 @@ static int imxrt_setup(struct qe_lowerhalf_s *lower)
uint32_t regval;
int ret;
ret = imxrt_enc_sem_wait(priv);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
@@ -1003,8 +973,7 @@ static int imxrt_setup(struct qe_lowerhalf_s *lower)
regval = ((config->init_flags >> MOD_SHIFT) & 1) ? ENC_CTRL2_MOD : 0;
imxrt_enc_putreg16(priv, IMXRT_ENC_CTRL2_OFFSET, regval);
imxrt_enc_sem_post(priv);
nxmutex_unlock(&priv->lock);
return OK;
}
@@ -1026,7 +995,7 @@ static int imxrt_shutdown(struct qe_lowerhalf_s *lower)
/* Ensure any in-progress operations are done. */
ret = imxrt_enc_sem_wait(priv);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
@@ -1059,7 +1028,7 @@ static int imxrt_shutdown(struct qe_lowerhalf_s *lower)
imxrt_enc_clock_disable(priv->config->base);
imxrt_enc_sem_post(priv);
nxmutex_unlock(&priv->lock);
return OK;
}
@@ -1080,7 +1049,7 @@ static int imxrt_position(struct qe_lowerhalf_s *lower, int32_t *pos)
int i;
int ret;
ret = imxrt_enc_sem_wait(priv);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
@@ -1107,13 +1076,13 @@ static int imxrt_position(struct qe_lowerhalf_s *lower, int32_t *pos)
if (lpos != imxrt_enc_getreg16(priv, IMXRT_ENC_LPOSH_OFFSET))
{
imxrt_enc_sem_post(priv);
nxmutex_unlock(&priv->lock);
return -EAGAIN;
}
upos = imxrt_enc_getreg16(priv, IMXRT_ENC_UPOSH_OFFSET);
imxrt_enc_sem_post(priv);
nxmutex_unlock(&priv->lock);
*pos = (int32_t)((upos << 16) | lpos);
return OK;
@@ -1135,14 +1104,14 @@ static int imxrt_reset(struct qe_lowerhalf_s *lower)
/* Write a 1 to the SWIP bit to load UINIT and LINIT into UPOS and LPOS */
ret = imxrt_enc_sem_wait(priv);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
}
imxrt_enc_modifyreg16(priv, IMXRT_ENC_CTRL_OFFSET, 0, ENC_CTRL_SWIP);
imxrt_enc_sem_post(priv);
nxmutex_unlock(&priv->lock);
return OK;
}
@@ -1258,7 +1227,7 @@ int imxrt_qeinitialize(const char *devpath, int enc)
/* Initialize private data */
nxsem_init(&priv->sem_excl, 0, 1);
nxmutex_init(&priv->lock);
/* Register the upper-half driver */
+6 -6
View File
@@ -39,7 +39,7 @@
#include <nuttx/wdog.h>
#include <nuttx/clock.h>
#include <nuttx/kmalloc.h>
#include <nuttx/semaphore.h>
#include <nuttx/mutex.h>
#include "arm_internal.h"
#include "barriers.h"
@@ -71,7 +71,7 @@ struct imxrt_flexspidev_s
bool initialized; /* TRUE: Controller has been initialized */
sem_t exclsem; /* Assures mutually exclusive access to
mutex_t lock; /* Assures mutually exclusive access to
* FlexSPI */
};
@@ -1104,11 +1104,11 @@ static int imxrt_flexspi_lock(struct flexspi_dev_s *dev, bool lock)
spiinfo("lock=%d\n", lock);
if (lock)
{
ret = nxsem_wait_uninterruptible(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
}
else
{
ret = nxsem_post(&priv->exclsem);
ret = nxmutex_unlock(&priv->lock);
}
return ret;
@@ -1268,11 +1268,11 @@ struct flexspi_dev_s *imxrt_flexspi_initialize(int intf)
{
/* No perform one time initialization */
/* Initialize the FlexSPI semaphore that enforces mutually exclusive
/* Initialize the FlexSPI mutex that enforces mutually exclusive
* access to the FlexSPI registers.
*/
nxsem_init(&priv->exclsem, 0, 1);
nxmutex_init(&priv->lock);
/* Perform hardware initialization. Puts the FlexSPI into an active
* state.
+23 -102
View File
@@ -37,6 +37,7 @@
#include <nuttx/arch.h>
#include <nuttx/irq.h>
#include <nuttx/clock.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <nuttx/i2c/i2c_master.h>
@@ -192,7 +193,7 @@ struct imxrt_lpi2c_priv_s
const struct imxrt_lpi2c_config_s *config;
int refs; /* Reference count */
sem_t sem_excl; /* Mutual exclusion semaphore */
mutex_t lock; /* Mutual exclusion mutex */
#ifndef CONFIG_I2C_POLLED
sem_t sem_isr; /* Interrupt wait semaphore */
#endif
@@ -235,11 +236,6 @@ static inline void imxrt_lpi2c_putreg(struct imxrt_lpi2c_priv_s *priv,
static inline void imxrt_lpi2c_modifyreg(struct imxrt_lpi2c_priv_s *priv,
uint16_t offset, uint32_t clearbits,
uint32_t setbits);
static inline int imxrt_lpi2c_sem_wait(struct imxrt_lpi2c_priv_s *priv);
#ifdef CONFIG_I2C_RESET
static int
imxrt_lpi2c_sem_wait_noncancelable(struct imxrt_lpi2c_priv_s *priv);
#endif
#ifdef CONFIG_IMXRT_LPI2C_DYNTIMEO
static uint32_t imxrt_lpi2c_toticks(int msgc, struct i2c_msg_s *msgs);
@@ -249,12 +245,6 @@ static inline int
imxrt_lpi2c_sem_waitdone(struct imxrt_lpi2c_priv_s *priv);
static inline void
imxrt_lpi2c_sem_waitstop(struct imxrt_lpi2c_priv_s *priv);
static inline void
imxrt_lpi2c_sem_post(struct imxrt_lpi2c_priv_s *priv);
static inline void
imxrt_lpi2c_sem_init(struct imxrt_lpi2c_priv_s *priv);
static inline void
imxrt_lpi2c_sem_destroy(struct imxrt_lpi2c_priv_s *priv);
#ifdef CONFIG_I2C_TRACE
static void imxrt_lpi2c_tracereset(struct imxrt_lpi2c_priv_s *priv);
@@ -363,6 +353,10 @@ static struct imxrt_lpi2c_priv_s imxrt_lpi2c1_priv =
.ops = &imxrt_lpi2c_ops,
.config = &imxrt_lpi2c1_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
#ifndef CONFIG_I2C_POLLED
.sem_isr = NXSEM_INITIALIZER(0, PRIOINHERIT_FLAGS_DISABLE),
#endif
.intstate = INTSTATE_IDLE,
.msgc = 0,
.msgv = NULL,
@@ -404,6 +398,10 @@ static struct imxrt_lpi2c_priv_s imxrt_lpi2c2_priv =
.ops = &imxrt_lpi2c_ops,
.config = &imxrt_lpi2c2_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
#ifndef CONFIG_I2C_POLLED
.sem_isr = NXSEM_INITIALIZER(0, PRIOINHERIT_FLAGS_DISABLE),
#endif
.intstate = INTSTATE_IDLE,
.msgc = 0,
.msgv = NULL,
@@ -445,6 +443,10 @@ static struct imxrt_lpi2c_priv_s imxrt_lpi2c3_priv =
.ops = &imxrt_lpi2c_ops,
.config = &imxrt_lpi2c3_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
#ifndef CONFIG_I2C_POLLED
.sem_isr = NXSEM_INITIALIZER(0, PRIOINHERIT_FLAGS_DISABLE),
#endif
.intstate = INTSTATE_IDLE,
.msgc = 0,
.msgv = NULL,
@@ -486,6 +488,10 @@ static struct imxrt_lpi2c_priv_s imxrt_lpi2c4_priv =
.ops = &imxrt_lpi2c_ops,
.config = &imxrt_lpi2c4_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
#ifndef CONFIG_I2C_POLLED
.sem_isr = NXSEM_INITIALIZER(0, PRIOINHERIT_FLAGS_DISABLE),
#endif
.intstate = INTSTATE_IDLE,
.msgc = 0,
.msgv = NULL,
@@ -543,36 +549,6 @@ static inline void imxrt_lpi2c_modifyreg(struct imxrt_lpi2c_priv_s *priv,
modifyreg32(priv->config->base + offset, clearbits, setbits);
}
/****************************************************************************
* Name: imxrt_lpi2c_sem_wait
*
* Description:
* Take the exclusive access, waiting as necessary. May be interrupted by
* a signal.
*
****************************************************************************/
static inline int imxrt_lpi2c_sem_wait(struct imxrt_lpi2c_priv_s *priv)
{
return nxsem_wait(&priv->sem_excl);
}
/****************************************************************************
* Name: imxrt_lpi2c_sem_wait_noncancelable
*
* Description:
* Take the exclusive access, waiting as necessary.
*
****************************************************************************/
#ifdef CONFIG_I2C_RESET
static int
imxrt_lpi2c_sem_wait_noncancelable(struct imxrt_lpi2c_priv_s *priv)
{
return nxsem_wait_uninterruptible(&priv->sem_excl);
}
#endif
/****************************************************************************
* Name: imxrt_lpi2c_toticks
*
@@ -856,58 +832,6 @@ imxrt_lpi2c_sem_waitstop(struct imxrt_lpi2c_priv_s *priv)
i2cinfo("Timeout with Status Register: %" PRIx32 "\n", regval);
}
/****************************************************************************
* Name: imxrt_lpi2c_sem_post
*
* Description:
* Release the mutual exclusion semaphore
*
****************************************************************************/
static inline void imxrt_lpi2c_sem_post(struct imxrt_lpi2c_priv_s *priv)
{
nxsem_post(&priv->sem_excl);
}
/****************************************************************************
* Name: imxrt_lpi2c_sem_init
*
* Description:
* Initialize semaphores
*
****************************************************************************/
static inline void imxrt_lpi2c_sem_init(struct imxrt_lpi2c_priv_s *priv)
{
nxsem_init(&priv->sem_excl, 0, 1);
#ifndef CONFIG_I2C_POLLED
/* This semaphore is used for signaling and, hence, should not have
* priority inheritance enabled.
*/
nxsem_init(&priv->sem_isr, 0, 0);
nxsem_set_protocol(&priv->sem_isr, SEM_PRIO_NONE);
#endif
}
/****************************************************************************
* Name: imxrt_lpi2c_sem_destroy
*
* Description:
* Destroy semaphores.
*
****************************************************************************/
static inline void
imxrt_lpi2c_sem_destroy(struct imxrt_lpi2c_priv_s *priv)
{
nxsem_destroy(&priv->sem_excl);
#ifndef CONFIG_I2C_POLLED
nxsem_destroy(&priv->sem_isr);
#endif
}
/****************************************************************************
* Name: imxrt_dma_callback
*
@@ -915,6 +839,7 @@ imxrt_lpi2c_sem_destroy(struct imxrt_lpi2c_priv_s *priv)
* This function performs the next I2C operation
*
****************************************************************************/
#ifdef CONFIG_IMXRT_LPI2C_DMA
static void imxrt_dma_callback(DMACH_HANDLE handle, void *arg, bool done,
int result)
@@ -2077,7 +2002,7 @@ static int imxrt_lpi2c_transfer(struct i2c_master_s *dev,
/* Ensure that address or flags don't change meanwhile */
ret = imxrt_lpi2c_sem_wait(priv);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
@@ -2178,7 +2103,7 @@ static int imxrt_lpi2c_transfer(struct i2c_master_s *dev,
priv->dcnt = 0;
priv->ptr = NULL;
imxrt_lpi2c_sem_post(priv);
nxmutex_unlock(&priv->lock);
return ret;
}
@@ -2215,7 +2140,7 @@ static int imxrt_lpi2c_reset(struct i2c_master_s *dev)
/* Lock out other clients */
ret = imxrt_lpi2c_sem_wait_noncancelable(priv);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
@@ -2313,7 +2238,7 @@ out:
/* Release the port for re-use by other clients */
imxrt_lpi2c_sem_post(priv);
nxmutex_unlock(&priv->lock);
return ret;
}
#endif /* CONFIG_I2C_RESET */
@@ -2371,7 +2296,6 @@ struct i2c_master_s *imxrt_i2cbus_initialize(int port)
if ((volatile int)priv->refs++ == 0)
{
imxrt_lpi2c_sem_init(priv);
imxrt_lpi2c_init(priv);
#ifdef CONFIG_IMXRT_LPI2C_DMA
@@ -2434,9 +2358,6 @@ int imxrt_i2cbus_uninitialize(struct i2c_master_s *dev)
imxrt_lpi2c_deinit(priv);
/* Release unused resources */
imxrt_lpi2c_sem_destroy(priv);
return OK;
}
+6 -6
View File
@@ -59,7 +59,7 @@
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <nuttx/semaphore.h>
#include <nuttx/mutex.h>
#include <nuttx/spi/spi.h>
#include <arch/board/board.h>
@@ -112,7 +112,7 @@ struct imxrt_lpspidev_s
#ifdef CONFIG_IMXRT_LPSPI_INTERRUPTS
uint8_t spiirq; /* SPI IRQ number */
#endif
sem_t exclsem; /* Held while chip is selected for mutual exclusion */
mutex_t lock; /* Held while chip is selected for mutual exclusion */
uint32_t frequency; /* Requested clock frequency */
uint32_t actual; /* Actual clock frequency */
int8_t nbits; /* Width of word in bits */
@@ -883,11 +883,11 @@ static int imxrt_lpspi_lock(struct spi_dev_s *dev, bool lock)
if (lock)
{
ret = nxsem_wait_uninterruptible(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
}
else
{
ret = nxsem_post(&priv->exclsem);
ret = nxmutex_unlock(&priv->lock);
}
return ret;
@@ -1711,9 +1711,9 @@ static void imxrt_lpspi_bus_initialize(struct imxrt_lpspidev_s *priv)
imxrt_lpspi_setmode((struct spi_dev_s *)priv, SPIDEV_MODE0);
/* Initialize the SPI semaphore that enforces mutually exclusive access */
/* Initialize the SPI mutex that enforces mutually exclusive access */
nxsem_init(&priv->exclsem, 0, 1);
nxmutex_init(&priv->lock);
/* Enable LPSPI */
+9 -9
View File
@@ -32,6 +32,7 @@
#include <debug.h>
#include <nuttx/arch.h>
#include <nuttx/mutex.h>
#include <nuttx/timers/rtc.h>
#include "arm_internal.h"
@@ -61,7 +62,7 @@ struct imxrt_lowerhalf_s
* this file.
*/
sem_t devsem; /* Threads can only exclusively access the RTC */
mutex_t devlock; /* Threads can only exclusively access the RTC */
#ifdef CONFIG_RTC_ALARM
/* Alarm callback information */
@@ -297,10 +298,10 @@ static int imxrt_setalarm(struct rtc_lowerhalf_s *lower,
/* Get exclusive access to the alarm */
ret = nxsem_wait(&rtc->devsem);
ret = nxmutex_lock(&rtc->devlock);
if (ret < 0)
{
rtcerr("ERROR: nxsem_wait failed: %d\n", ret);
rtcerr("ERROR: nxmutex_lock failed: %d\n", ret);
return ret;
}
@@ -329,7 +330,7 @@ static int imxrt_setalarm(struct rtc_lowerhalf_s *lower,
}
}
nxsem_post(&rtc->devsem);
nxmutex_unlock(&rtc->devlock);
return ret;
}
#endif
@@ -364,10 +365,10 @@ static int imxrt_setrelative(struct rtc_lowerhalf_s *lower,
/* Get exclusive access to the alarm */
ret = nxsem_wait(&rtc->devsem);
ret = nxmutex_lock(&rtc->devlock);
if (ret < 0)
{
rtcerr("ERROR: nxsem_wait failed: %d\n", ret);
rtcerr("ERROR: nxmutex_lock failed: %d\n", ret);
return ret;
}
@@ -402,7 +403,7 @@ static int imxrt_setrelative(struct rtc_lowerhalf_s *lower,
}
}
nxsem_post(&rtc->devsem);
nxmutex_unlock(&rtc->devlock);
return ret;
}
#endif
@@ -513,8 +514,7 @@ static int imxrt_rdalarm(struct rtc_lowerhalf_s *lower,
struct rtc_lowerhalf_s *imxrt_rtc_lowerhalf(void)
{
nxsem_init(&g_rtc_lowerhalf.devsem, 0, 1);
nxmutex_init(&g_rtc_lowerhalf.devlock);
return (struct rtc_lowerhalf_s *)&g_rtc_lowerhalf;
}
+2 -25
View File
@@ -246,8 +246,6 @@ struct imxrt_sdhcregs_s
/* Low-level helpers ********************************************************/
static int imxrt_takesem(struct imxrt_dev_s *priv);
#define imxrt_givesem(priv) (nxsem_post(&priv->waitsem))
static void imxrt_configwaitints(struct imxrt_dev_s *priv, uint32_t waitints,
sdio_eventset_t waitevents, sdio_eventset_t wkupevents);
static void imxrt_configxfrints(struct imxrt_dev_s *priv, uint32_t xfrints);
@@ -497,27 +495,6 @@ static struct imxrt_sdhcregs_s g_sampleregs[DEBUG_NSAMPLES];
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: imxrt_takesem
*
* Description:
* Take the wait semaphore (handling false alarm wakeups due to the receipt
* of signals).
*
* Input Parameters:
* dev - Instance of the SDIO device driver state structure.
*
* Returned Value:
* Normally OK, but may return -ECANCELED in the rare event that the task
* has been canceled.
*
****************************************************************************/
static int imxrt_takesem(struct imxrt_dev_s *priv)
{
return nxsem_wait_uninterruptible(&priv->waitsem);
}
/****************************************************************************
* Name: imxrt_configwaitints
*
@@ -1150,7 +1127,7 @@ static void imxrt_endwait(struct imxrt_dev_s *priv,
/* Wake up the waiting thread */
imxrt_givesem(priv);
nxsem_post(&priv->waitsem);
}
/****************************************************************************
@@ -2818,7 +2795,7 @@ static sdio_eventset_t imxrt_eventwait(struct sdio_dev_s *dev)
* incremented and there will be no wait.
*/
ret = imxrt_takesem(priv);
ret = nxsem_wait_uninterruptible(&priv->waitsem);
if (ret < 0)
{
/* Task canceled. Cancel the wdog (assuming it was started) and
+7 -25
View File
@@ -59,6 +59,7 @@
#include <nuttx/arch.h>
#include <nuttx/queue.h>
#include <nuttx/spinlock.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include "arm_internal.h"
@@ -138,9 +139,9 @@ struct kinetis_dmach_s
struct kinetis_edma_s
{
/* These semaphores protect the DMA channel and descriptor tables */
/* These mutex protect the DMA channel and descriptor tables */
sem_t chsem; /* Protects channel table */
mutex_t chlock; /* Protects channel table */
#if CONFIG_KINETIS_EDMA_NTCD > 0
sem_t dsem; /* Supports wait for free descriptors */
#endif
@@ -173,25 +174,6 @@ static struct kinetis_edmatcd_s g_tcd_pool[CONFIG_KINETIS_EDMA_NTCD]
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: kinetis_takechsem() and kinetis_givechsem()
*
* Description:
* Used to get exclusive access to the DMA channel table for channel
* allocation.
*
****************************************************************************/
static int kinetis_takechsem(void)
{
return nxsem_wait_uninterruptible(&g_edma.chsem);
}
static inline void kinetis_givechsem(void)
{
nxsem_post(&g_edma.chsem);
}
/****************************************************************************
* Name: kinetis_takedsem() and kinetis_givedsem()
*
@@ -745,9 +727,9 @@ void weak_function arm_dma_initialize(void)
g_edma.dmach[i].chan = i;
}
/* Initialize semaphores */
/* Initialize mutex & semaphore */
nxsem_init(&g_edma.chsem, 0, 1);
nxmutex_init(&g_edma.chlock);
#if CONFIG_KINETIS_EDMA_NTCD > 0
nxsem_init(&g_edma.dsem, 0, CONFIG_KINETIS_EDMA_NTCD);
@@ -857,7 +839,7 @@ DMACH_HANDLE kinetis_dmach_alloc(uint8_t dmamux, uint8_t dchpri)
/* Search for an available DMA channel */
dmach = NULL;
ret = kinetis_takechsem();
ret = nxmutex_lock(&g_edma.chlock);
if (ret < 0)
{
return NULL;
@@ -894,7 +876,7 @@ DMACH_HANDLE kinetis_dmach_alloc(uint8_t dmamux, uint8_t dchpri)
}
}
kinetis_givechsem();
nxmutex_unlock(&g_edma.chlock);
/* Show the result of the allocation */
+18 -103
View File
@@ -35,6 +35,7 @@
#include <nuttx/arch.h>
#include <nuttx/wdog.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <nuttx/i2c/i2c_master.h>
@@ -112,7 +113,7 @@ struct kinetis_i2cdev_s
int refs; /* Reference count */
volatile uint8_t state; /* State of state machine */
bool restart; /* Should next transfer restart or not */
sem_t mutex; /* Only one thread can access at a time */
mutex_t lock; /* Only one thread can access at a time */
sem_t wait; /* Place to wait for state machine completion */
struct wdog_s timeout; /* watchdog to timeout when bus hung */
struct i2c_msg_s *msgs; /* Remaining transfers - first one is in
@@ -130,20 +131,6 @@ static uint8_t kinetis_i2c_getreg(struct kinetis_i2cdev_s *priv,
static void kinetis_i2c_putreg(struct kinetis_i2cdev_s *priv,
uint8_t value, uint8_t offset);
/* Exclusion Helpers */
static inline void kinetis_i2c_sem_init(struct kinetis_i2cdev_s *priv);
static inline void
kinetis_i2c_sem_destroy(struct kinetis_i2cdev_s *priv);
static inline int kinetis_i2c_sem_wait(struct kinetis_i2cdev_s *priv);
#ifdef CONFIG_I2C_RESET
static int
kinetis_i2c_sem_wait_noncancelable(struct kinetis_i2cdev_s *priv);
#endif
static inline void kinetis_i2c_sem_post(struct kinetis_i2cdev_s *priv);
/* Signal Helper */
static inline void kinetis_i2c_endwait(struct kinetis_i2cdev_s *priv);
@@ -203,6 +190,8 @@ static struct kinetis_i2cdev_s g_i2c0_dev =
.dev.ops = &kinetis_i2c_ops,
.config = &kinetis_i2c0_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.wait = NXSEM_INITIALIZER(0, PRIOINHERIT_FLAGS_DISABLE),
.state = STATE_OK,
.msgs = NULL,
};
@@ -224,6 +213,8 @@ static struct kinetis_i2cdev_s g_i2c1_dev =
.dev.ops = &kinetis_i2c_ops,
.config = &kinetis_i2c1_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.wait = NXSEM_INITIALIZER(0, PRIOINHERIT_FLAGS_DISABLE),
.state = STATE_OK,
.msgs = NULL,
};
@@ -245,6 +236,8 @@ static struct kinetis_i2cdev_s g_i2c2_dev =
.dev.ops = &kinetis_i2c_ops,
.config = &kinetis_i2c2_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.wait = NXSEM_INITIALIZER(0, PRIOINHERIT_FLAGS_DISABLE),
.state = STATE_OK,
.msgs = NULL,
};
@@ -266,6 +259,8 @@ static struct kinetis_i2cdev_s g_i2c3_dev =
.dev.ops = &kinetis_i2c_ops,
.config = &kinetis_i2c3_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
.wait = NXSEM_INITIALIZER(0, PRIOINHERIT_FLAGS_DISABLE),
.state = STATE_OK,
.msgs = NULL,
};
@@ -303,83 +298,6 @@ static void kinetis_i2c_putreg(struct kinetis_i2cdev_s *priv, uint8_t value,
putreg8(value, priv->config->base + offset);
}
/****************************************************************************
* Name: kinetis_i2c_sem_init
*
* Description:
* Initialize semaphores
*
****************************************************************************/
static inline void kinetis_i2c_sem_init(struct kinetis_i2cdev_s *priv)
{
nxsem_init(&priv->mutex, 0, 1);
/* This semaphore is used for signaling and, hence, should not have
* priority inheritance enabled.
*/
nxsem_init(&priv->wait, 0, 0);
nxsem_set_protocol(&priv->wait, SEM_PRIO_NONE);
}
/****************************************************************************
* Name: kinetis_i2c_sem_destroy
*
* Description:
* Destroy semaphores.
*
****************************************************************************/
static inline void kinetis_i2c_sem_destroy(struct kinetis_i2cdev_s *priv)
{
nxsem_destroy(&priv->mutex);
nxsem_destroy(&priv->wait);
}
/****************************************************************************
* Name: kinetis_i2c_sem_wait
*
* Description:
* Take the exclusive access, waiting as necessary. May be interrupted by
* a signal.
*
****************************************************************************/
static inline int kinetis_i2c_sem_wait(struct kinetis_i2cdev_s *priv)
{
return nxsem_wait(&priv->mutex);
}
#ifdef CONFIG_I2C_RESET
/****************************************************************************
* Name: kinetis_i2c_sem_wait_noncancelable
*
* Description:
* Take the exclusive access, waiting as necessary
*
****************************************************************************/
static int
kinetis_i2c_sem_wait_noncancelable(struct kinetis_i2cdev_s *priv)
{
return nxsem_wait_uninterruptible(&priv->mutex);
}
#endif
/****************************************************************************
* Name: kinetis_i2c_sem_post
*
* Description:
* Release the mutual exclusion semaphore
*
****************************************************************************/
static inline void kinetis_i2c_sem_post(struct kinetis_i2cdev_s *priv)
{
nxsem_post(&priv->mutex);
}
/****************************************************************************
* Name: kinetis_i2c_wait
*
@@ -1142,7 +1060,7 @@ static int kinetis_i2c_transfer(struct i2c_master_s *dev,
/* Get exclusive access to the I2C bus */
ret = kinetis_i2c_sem_wait(priv);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
@@ -1232,8 +1150,7 @@ timeout:
/* Release access to I2C bus */
kinetis_i2c_sem_post(priv);
nxmutex_unlock(&priv->lock);
return ret;
}
@@ -1270,7 +1187,7 @@ static int kinetis_i2c_reset(struct i2c_master_s *dev)
/* Lock out other clients */
ret = kinetis_i2c_sem_wait_noncancelable(priv);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
@@ -1369,7 +1286,7 @@ out:
/* Release the port for re-use by other clients */
kinetis_i2c_sem_post(priv);
nxmutex_unlock(&priv->lock);
return ret;
}
#endif /* CONFIG_I2C_RESET */
@@ -1397,25 +1314,25 @@ struct i2c_master_s *kinetis_i2cbus_initialize(int port)
{
#ifdef CONFIG_KINETIS_I2C0
case 0:
priv = &g_i2c0_dev;
priv = &g_i2c0_dev;
break;
#endif
#ifdef CONFIG_KINETIS_I2C1
case 1:
priv = &g_i2c1_dev;
priv = &g_i2c1_dev;
break;
#endif
#ifdef CONFIG_KINETIS_I2C2
case 2:
priv = &g_i2c2_dev;
priv = &g_i2c2_dev;
break;
#endif
#ifdef CONFIG_KINETIS_I2C3
case 3:
priv = &g_i2c3_dev;
priv = &g_i2c3_dev;
break;
#endif
@@ -1427,7 +1344,6 @@ struct i2c_master_s *kinetis_i2cbus_initialize(int port)
flags = enter_critical_section();
if ((volatile int)priv->refs++ == 0)
{
kinetis_i2c_sem_init(priv);
kinetis_i2c_init(priv);
}
@@ -1471,7 +1387,6 @@ int kinetis_i2cbus_uninitialize(struct i2c_master_s *dev)
/* Disable power and other HW resource (GPIO's) */
kinetis_i2c_deinit(priv);
kinetis_i2c_sem_destroy(priv);
wd_cancel(&priv->timeout);
return OK;
}
+2 -25
View File
@@ -229,8 +229,6 @@ struct kinetis_sdhcregs_s
/* Low-level helpers ********************************************************/
static int kinetis_takesem(struct kinetis_dev_s *priv);
#define kinetis_givesem(priv) (nxsem_post(&priv->waitsem))
static void kinetis_configwaitints(struct kinetis_dev_s *priv,
uint32_t waitints, sdio_eventset_t waitevents,
sdio_eventset_t wkupevents);
@@ -411,27 +409,6 @@ static struct kinetis_sdhcregs_s g_sampleregs[DEBUG_NSAMPLES];
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: kinetis_takesem
*
* Description:
* Take the wait semaphore (handling false alarm wakeups due to the receipt
* of signals).
*
* Input Parameters:
* dev - Instance of the SDIO device driver state structure.
*
* Returned Value:
* Normally OK, but may return -ECANCELED in the rare event that the task
* has been canceled.
*
****************************************************************************/
static int kinetis_takesem(struct kinetis_dev_s *priv)
{
return nxsem_wait_uninterruptible(&priv->waitsem);
}
/****************************************************************************
* Name: kinetis_configwaitints
*
@@ -985,7 +962,7 @@ static void kinetis_endwait(struct kinetis_dev_s *priv,
/* Wake up the waiting thread */
kinetis_givesem(priv);
nxsem_post(&priv->waitsem);
}
/****************************************************************************
@@ -2534,7 +2511,7 @@ static sdio_eventset_t kinetis_eventwait(struct sdio_dev_s *dev)
* incremented and there will be no wait.
*/
ret = kinetis_takesem(priv);
ret = nxsem_wait_uninterruptible(&priv->waitsem);
if (ret < 0)
{
/* Task canceled. Cancel the wdog (assuming it was started) and
+6 -6
View File
@@ -58,7 +58,7 @@
#include <debug.h>
#include <nuttx/arch.h>
#include <nuttx/semaphore.h>
#include <nuttx/mutex.h>
#include <nuttx/spi/spi.h>
#include <arch/irq.h>
@@ -96,7 +96,7 @@ struct kinetis_spidev_s
{
struct spi_dev_s spidev; /* Externally visible part of the SPI interface */
uint32_t spibase; /* Base address of SPI registers */
sem_t exclsem; /* Held while chip is selected for mutual exclusion */
mutex_t lock; /* Held while chip is selected for mutual exclusion */
uint32_t frequency; /* Requested clock frequency */
uint32_t actual; /* Actual clock frequency */
uint8_t nbits; /* Width of word in bits (8 to 16) */
@@ -672,11 +672,11 @@ static int spi_lock(struct spi_dev_s *dev, bool lock)
if (lock)
{
ret = nxsem_wait_uninterruptible(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
}
else
{
ret = nxsem_post(&priv->exclsem);
ret = nxmutex_unlock(&priv->lock);
}
return ret;
@@ -1666,9 +1666,9 @@ struct spi_dev_s *kinetis_spibus_initialize(int port)
priv->frequency = 0;
spi_setfrequency(&priv->spidev, KINETIS_SPI_CLK_INIT);
/* Initialize the SPI semaphore that enforces mutually exclusive access */
/* Initialize the SPI mutex that enforces mutually exclusive access */
nxsem_init(&priv->exclsem, 0, 1);
nxmutex_init(&priv->lock);
#ifdef CONFIG_KINETIS_SPI_DMA
/* Initialize the SPI semaphores that is used to wait for DMA completion.
* This semaphore is used for signaling and, hence, should not have
+55 -110
View File
@@ -36,6 +36,7 @@
#include <nuttx/kmalloc.h>
#include <nuttx/wqueue.h>
#include <nuttx/signal.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <nuttx/usb/usb.h>
#include <nuttx/usb/usbhost.h>
@@ -284,7 +285,7 @@ struct kinetis_ehci_s
{
volatile bool pscwait; /* TRUE: Thread is waiting for port status change event */
sem_t exclsem; /* Support mutually exclusive access */
mutex_t lock; /* Support mutually exclusive access */
sem_t pscsem; /* Semaphore to wait for port status change events */
struct kinetis_epinfo_s ep0; /* Endpoint 0 */
@@ -427,12 +428,6 @@ static inline void kinetis_putreg(uint32_t regval,
static int ehci_wait_usbsts(uint32_t maskbits, uint32_t donebits,
unsigned int delay);
/* Semaphores ***************************************************************/
static int kinetis_takesem(sem_t *sem);
static int kinetis_takesem_noncancelable(sem_t *sem);
#define kinetis_givesem(s) nxsem_post(s);
/* Allocators ***************************************************************/
static struct kinetis_qh_s *kinetis_qh_alloc(void);
@@ -1075,61 +1070,13 @@ static int ehci_wait_usbsts(uint32_t maskbits, uint32_t donebits,
return (regval == donebits) ? OK : -ETIMEDOUT;
}
/****************************************************************************
* Name: kinetis_takesem
*
* Description:
* This is just a wrapper to handle the annoying behavior of semaphore
* waits that return due to the receipt of a signal.
*
****************************************************************************/
static int kinetis_takesem(sem_t *sem)
{
return nxsem_wait_uninterruptible(sem);
}
/****************************************************************************
* Name: kinetis_takesem_noncancelable
*
* Description:
* This is just a wrapper to handle the annoying behavior of semaphore
* waits that return due to the receipt of a signal. This version also
* ignores attempts to cancel the thread.
*
****************************************************************************/
static int kinetis_takesem_noncancelable(sem_t *sem)
{
int result;
int ret = OK;
do
{
result = nxsem_wait_uninterruptible(sem);
/* The only expected error is ECANCELED which would occur if the
* calling thread were canceled.
*/
DEBUGASSERT(result == OK || result == -ECANCELED);
if (ret == OK && result < 0)
{
ret = result;
}
}
while (result < 0);
return ret;
}
/****************************************************************************
* Name: kinetis_qh_alloc
*
* Description:
* Allocate a Queue Head (QH) structure by removing it from the free list
*
* Assumption: Caller holds the exclsem
* Assumption: Caller holds the lock
*
****************************************************************************/
@@ -1156,7 +1103,7 @@ static struct kinetis_qh_s *kinetis_qh_alloc(void)
* Let a Queue Head (QH) structure wait for free by adding it to the
* aawait list
*
* Assumption: Caller holds the exclsem
* Assumption: Caller holds the lock
*
****************************************************************************/
@@ -1179,7 +1126,7 @@ static void kinetis_qh_aawait(struct kinetis_qh_s *qh)
* Description:
* Free a Queue Head (QH) structure by returning it to the free list
*
* Assumption: Caller holds the exclsem
* Assumption: Caller holds the lock
*
****************************************************************************/
@@ -1198,7 +1145,7 @@ static void kinetis_qh_free(struct kinetis_qh_s *qh)
* Allocate a Queue Element Transfer Descriptor (qTD) by removing it from
* the free list
*
* Assumption: Caller holds the exclsem
* Assumption: Caller holds the lock
*
****************************************************************************/
@@ -1226,7 +1173,7 @@ static struct kinetis_qtd_s *kinetis_qtd_alloc(void)
* free list
*
* Assumption:
* Caller holds the exclsem
* Caller holds the lock
*
****************************************************************************/
@@ -1677,7 +1624,7 @@ static inline uint8_t kinetis_ehci_speed(uint8_t usbspeed)
* this to minimize race conditions. This logic would have to be expanded
* if we want to have more than one packet in flight at a time!
*
* Assumption: The caller holds the EHCI exclsem
* Assumption: The caller holds the EHCI lock
*
****************************************************************************/
@@ -1723,7 +1670,7 @@ static int kinetis_ioc_setup(struct kinetis_rhport_s *rhport,
* Description:
* Wait for the IOC event.
*
* Assumption: The caller does *NOT* hold the EHCI exclsem. That would
* Assumption: The caller does *NOT* hold the EHCI lock. That would
* cause a deadlock when the bottom-half, worker thread needs to take the
* semaphore.
*
@@ -1739,7 +1686,7 @@ static int kinetis_ioc_wait(struct kinetis_epinfo_s *epinfo)
while (epinfo->iocwait)
{
ret = kinetis_takesem(&epinfo->iocsem);
ret = nxsem_wait_uninterruptible(&epinfo->iocsem);
if (ret < 0)
{
break;
@@ -1755,7 +1702,7 @@ static int kinetis_ioc_wait(struct kinetis_epinfo_s *epinfo)
* Description:
* Add a new, ready-to-go QH w/attached qTDs to the asynchronous queue.
*
* Assumptions: The caller holds the EHCI exclsem
* Assumptions: The caller holds the EHCI lock
*
****************************************************************************/
@@ -2205,7 +2152,7 @@ static struct kinetis_qtd_s *kinetis_qtd_statusphase(uint32_t tokenbits)
* This is a blocking function; it will not return until the control
* transfer has completed.
*
* Assumption: The caller holds the EHCI exclsem.
* Assumption: The caller holds the EHCI lock.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is return on
@@ -2488,7 +2435,7 @@ errout_with_qh:
* frame list), followed by shorter poll rates, with queue heads with a
* poll rate of one, on the very end."
*
* Assumption: The caller holds the EHCI exclsem.
* Assumption: The caller holds the EHCI lock.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is return on
@@ -2592,8 +2539,8 @@ errout_with_qh:
* Description:
* Wait for an IN or OUT transfer to complete.
*
* Assumption: The caller holds the EHCI exclsem. The caller must be aware
* that the EHCI exclsem will released while waiting for the transfer to
* Assumption: The caller holds the EHCI lock. The caller must be aware
* that the EHCI lock will released while waiting for the transfer to
* complete, but will be re-acquired when before returning. The state of
* EHCI resources could be very different upon return.
*
@@ -2611,29 +2558,29 @@ static ssize_t kinetis_transfer_wait(struct kinetis_epinfo_s *epinfo)
int ret;
int ret2;
/* Release the EHCI semaphore while we wait. Other threads need the
/* Release the EHCI mutex while we wait. Other threads need the
* opportunity to access the EHCI resources while we wait.
*
* REVISIT: Is this safe? NO. This is a bug and needs rethinking.
* We need to lock all of the port-resources (not EHCI common) until
* the transfer is complete. But we can't use the common EHCI exclsem
* the transfer is complete. But we can't use the common EHCI lock
* or we will deadlock while waiting (because the working thread that
* wakes this thread up needs the exclsem).
* wakes this thread up needs the lock).
*/
/* REVISIT */
kinetis_givesem(&g_ehci.exclsem);
nxmutex_unlock(&g_ehci.lock);
/* Wait for the IOC completion event */
ret = kinetis_ioc_wait(epinfo);
/* Re-acquire the EHCI semaphore. The caller expects to be holding
/* Re-acquire the EHCI mutex. The caller expects to be holding
* this upon return.
*/
ret2 = kinetis_takesem_noncancelable(&g_ehci.exclsem);
ret2 = nxmutex_lock(&g_ehci.lock);
if (ret >= 0 && ret2 < 0)
{
ret = ret2;
@@ -2657,9 +2604,7 @@ static ssize_t kinetis_transfer_wait(struct kinetis_epinfo_s *epinfo)
}
#endif
/* Did kinetis_ioc_wait() or kinetis_takesem_noncancelable() report an
* error?
*/
/* Did kinetis_ioc_wait() or nxmutex_lock() report an error? */
if (ret < 0)
{
@@ -2968,7 +2913,7 @@ static int kinetis_qh_ioccheck(struct kinetis_qh_s *qh,
/* Yes... wake it up */
epinfo->iocwait = false;
kinetis_givesem(&epinfo->iocsem);
nxsem_post(&epinfo->iocsem);
}
#ifdef CONFIG_USBHOST_ASYNCH
@@ -3129,7 +3074,7 @@ static int kinetis_qh_cancel(struct kinetis_qh_s *qh,
* detected (actual number of bytes received was less than the expected
* number of bytes)."
*
* Assumptions: The caller holds the EHCI exclsem
* Assumptions: The caller holds the EHCI lock
*
****************************************************************************/
@@ -3266,7 +3211,7 @@ static inline void kinetis_portsc_bottomhalf(void)
if (g_ehci.pscwait)
{
kinetis_givesem(&g_ehci.pscsem);
nxsem_post(&g_ehci.pscsem);
g_ehci.pscwait = false;
}
}
@@ -3318,7 +3263,7 @@ static inline void kinetis_portsc_bottomhalf(void)
if (g_ehci.pscwait)
{
kinetis_givesem(&g_ehci.pscsem);
nxsem_post(&g_ehci.pscsem);
g_ehci.pscwait = false;
}
}
@@ -3401,7 +3346,7 @@ static void kinetis_ehci_bottomhalf(void *arg)
* real option (other than to reschedule and delay).
*/
kinetis_takesem_noncancelable(&g_ehci.exclsem);
nxmutex_lock(&g_ehci.lock);
/* Handle all unmasked interrupt sources
* Interrupt on Async Advance
@@ -3518,7 +3463,7 @@ static void kinetis_ehci_bottomhalf(void *arg)
/* We are done with the EHCI structures */
kinetis_givesem(&g_ehci.exclsem);
nxmutex_unlock(&g_ehci.lock);
/* Re-enable relevant EHCI interrupts. Interrupts should still be enabled
* at the level of the interrupt controller.
@@ -3671,7 +3616,7 @@ static int kinetis_wait(struct usbhost_connection_s *conn,
*/
g_ehci.pscwait = true;
ret = kinetis_takesem(&g_ehci.pscsem);
ret = nxsem_wait_uninterruptible(&g_ehci.pscsem);
if (ret < 0)
{
return ret;
@@ -4004,7 +3949,7 @@ static int kinetis_ep0configure(struct usbhost_driver_s *drvr,
/* We must have exclusive access to the EHCI data structures. */
ret = kinetis_takesem(&g_ehci.exclsem);
ret = nxmutex_lock(&g_ehci.lock);
if (ret >= 0)
{
/* Remember the new device address and max packet size */
@@ -4013,7 +3958,7 @@ static int kinetis_ep0configure(struct usbhost_driver_s *drvr,
epinfo->speed = speed;
epinfo->maxpacket = maxpacketsize;
kinetis_givesem(&g_ehci.exclsem);
nxmutex_unlock(&g_ehci.lock);
}
return ret;
@@ -4378,7 +4323,7 @@ static int kinetis_ctrlin(struct usbhost_driver_s *drvr,
* structures.
*/
ret = kinetis_takesem(&g_ehci.exclsem);
ret = nxmutex_lock(&g_ehci.lock);
if (ret < 0)
{
return ret;
@@ -4390,7 +4335,7 @@ static int kinetis_ctrlin(struct usbhost_driver_s *drvr,
if (ret != OK)
{
usbhost_trace1(EHCI_TRACE1_DEVDISCONNECTED, -ret);
goto errout_with_sem;
goto errout_with_lock;
}
/* Now initiate the transfer */
@@ -4405,13 +4350,13 @@ static int kinetis_ctrlin(struct usbhost_driver_s *drvr,
/* And wait for the transfer to complete */
nbytes = kinetis_transfer_wait(ep0info);
kinetis_givesem(&g_ehci.exclsem);
nxmutex_unlock(&g_ehci.lock);
return nbytes >= 0 ? OK : (int)nbytes;
errout_with_iocwait:
ep0info->iocwait = false;
errout_with_sem:
kinetis_givesem(&g_ehci.exclsem);
errout_with_lock:
nxmutex_unlock(&g_ehci.lock);
return ret;
}
@@ -4481,7 +4426,7 @@ static ssize_t kinetis_transfer(struct usbhost_driver_s *drvr,
* structures.
*/
ret = kinetis_takesem(&g_ehci.exclsem);
ret = nxmutex_lock(&g_ehci.lock);
if (ret < 0)
{
return (ssize_t)ret;
@@ -4493,7 +4438,7 @@ static ssize_t kinetis_transfer(struct usbhost_driver_s *drvr,
if (ret != OK)
{
usbhost_trace1(EHCI_TRACE1_DEVDISCONNECTED, -ret);
goto errout_with_sem;
goto errout_with_lock;
}
/* Initiate the transfer */
@@ -4531,14 +4476,14 @@ static ssize_t kinetis_transfer(struct usbhost_driver_s *drvr,
/* Then wait for the transfer to complete */
nbytes = kinetis_transfer_wait(epinfo);
kinetis_givesem(&g_ehci.exclsem);
nxmutex_unlock(&g_ehci.lock);
return nbytes;
errout_with_iocwait:
epinfo->iocwait = false;
errout_with_sem:
errout_with_lock:
uerr("!!!\n");
kinetis_givesem(&g_ehci.exclsem);
nxmutex_unlock(&g_ehci.lock);
return (ssize_t)ret;
}
@@ -4593,7 +4538,7 @@ static int kinetis_asynch(struct usbhost_driver_s *drvr, usbhost_ep_t ep,
* structures.
*/
ret = kinetis_takesem(&g_ehci.exclsem);
ret = nxmutex_lock(&g_ehci.lock);
if (ret < 0)
{
return ret;
@@ -4605,7 +4550,7 @@ static int kinetis_asynch(struct usbhost_driver_s *drvr, usbhost_ep_t ep,
if (ret != OK)
{
usbhost_trace1(EHCI_TRACE1_DEVDISCONNECTED, -ret);
goto errout_with_sem;
goto errout_with_lock;
}
/* Initiate the transfer */
@@ -4642,14 +4587,14 @@ static int kinetis_asynch(struct usbhost_driver_s *drvr, usbhost_ep_t ep,
/* The transfer is in progress */
kinetis_givesem(&g_ehci.exclsem);
nxmutex_unlock(&g_ehci.lock);
return OK;
errout_with_callback:
epinfo->callback = NULL;
epinfo->arg = NULL;
errout_with_sem:
kinetis_givesem(&g_ehci.exclsem);
errout_with_lock:
nxmutex_unlock(&g_ehci.lock);
return ret;
}
#endif /* CONFIG_USBHOST_ASYNCH */
@@ -4697,7 +4642,7 @@ static int kinetis_cancel(struct usbhost_driver_s *drvr, usbhost_ep_t ep)
* interrupt level.
*/
ret = kinetis_takesem(&g_ehci.exclsem);
ret = nxmutex_lock(&g_ehci.lock);
if (ret < 0)
{
return ret;
@@ -4740,7 +4685,7 @@ static int kinetis_cancel(struct usbhost_driver_s *drvr, usbhost_ep_t ep)
#endif
{
ret = OK;
goto errout_with_sem;
goto errout_with_lock;
}
/* Handle the cancellation according to the type of the transfer */
@@ -4803,7 +4748,7 @@ static int kinetis_cancel(struct usbhost_driver_s *drvr, usbhost_ep_t ep)
default:
usbhost_trace1(EHCI_TRACE1_BADXFRTYPE, epinfo->xfrtype);
ret = -ENOSYS;
goto errout_with_sem;
goto errout_with_lock;
}
/* Find and remove the QH. There are four possibilities:
@@ -4833,7 +4778,7 @@ exit_terminate:
/* Yes... wake it up */
DEBUGASSERT(callback == NULL);
kinetis_givesem(&epinfo->iocsem);
nxsem_post(&epinfo->iocsem);
}
/* No.. Is there a pending asynchronous transfer? */
@@ -4848,11 +4793,11 @@ exit_terminate:
#else
/* Wake up the waiting thread */
kinetis_givesem(&epinfo->iocsem);
nxsem_post(&epinfo->iocsem);
#endif
errout_with_sem:
kinetis_givesem(&g_ehci.exclsem);
errout_with_lock:
nxmutex_unlock(&g_ehci.lock);
return ret;
}
@@ -4899,7 +4844,7 @@ static int kinetis_connect(struct usbhost_driver_s *drvr,
if (g_ehci.pscwait)
{
g_ehci.pscwait = false;
kinetis_givesem(&g_ehci.pscsem);
nxsem_post(&g_ehci.pscsem);
}
leave_critical_section(flags);
@@ -5125,7 +5070,7 @@ struct usbhost_connection_s *kinetis_ehci_initialize(int controller)
/* Initialize the EHCI state data structure */
nxsem_init(&g_ehci.exclsem, 0, 1);
nxmutex_init(&g_ehci.lock);
nxsem_init(&g_ehci.pscsem, 0, 0);
/* The pscsem semaphore is used for signaling and, hence, should not have
+6 -6
View File
@@ -30,7 +30,7 @@
#include <assert.h>
#include <debug.h>
#include <nuttx/semaphore.h>
#include <nuttx/mutex.h>
#include <nuttx/spi/spi.h>
#include <arch/irq.h>
@@ -54,7 +54,7 @@ struct kl_spidev_s
{
struct spi_dev_s spidev; /* Externally visible part of the SPI interface */
uint32_t spibase; /* Base address of SPI registers */
sem_t exclsem; /* Held while chip is selected for mutual exclusion */
mutex_t lock; /* Held while chip is selected for mutual exclusion */
uint32_t frequency; /* Requested clock frequency */
uint32_t actual; /* Actual clock frequency */
uint8_t nbits; /* Width of word in bits (8 to 16) */
@@ -236,11 +236,11 @@ static int spi_lock(struct spi_dev_s *dev, bool lock)
if (lock)
{
ret = nxsem_wait_uninterruptible(&priv->exclsem);
ret = nxmutex_lock(&priv->lock);
}
else
{
ret = nxsem_post(&priv->exclsem);
ret = nxmutex_unlock(&priv->lock);
}
return ret;
@@ -689,9 +689,9 @@ struct spi_dev_s *kl_spibus_initialize(int port)
spi_setfrequency((struct spi_dev_s *)priv, 400000);
/* Initialize the SPI semaphore that enforces mutually exclusive access */
/* Initialize the SPI mutex that enforces mutually exclusive access */
nxsem_init(&priv->exclsem, 0, 1);
nxmutex_init(&priv->lock);
return &priv->spidev;
}
+12 -44
View File
@@ -44,6 +44,7 @@
#include <nuttx/fs/ioctl.h>
#include <nuttx/analog/adc.h>
#include <nuttx/analog/ioctl.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include "arm_internal.h"
@@ -80,7 +81,7 @@ struct lc823450_adc_inst_s
const struct adc_callback_s *cb;
struct adc_dev_s dev;
sem_t sem_excl; /* Mutual exclusion semaphore */
mutex_t lock; /* Mutual exclusion mutex */
#ifndef CONFIG_ADC_POLLED
sem_t sem_isr; /* Interrupt wait semaphore */
#endif
@@ -93,10 +94,6 @@ struct lc823450_adc_inst_s
****************************************************************************/
static inline void lc823450_adc_clearirq(void);
static inline int lc823450_adc_sem_wait(
struct lc823450_adc_inst_s *inst);
static inline void lc823450_adc_sem_post(
struct lc823450_adc_inst_s *inst);
static int lc823450_adc_bind(struct adc_dev_s *dev,
const struct adc_callback_s *callback);
@@ -256,33 +253,6 @@ static void lc823450_adc_start(struct lc823450_adc_inst_s *inst)
#endif
}
/****************************************************************************
* Name: lc823450_adc_sem_wait
*
* Description:
* Take the exclusive access, waiting as necessary
*
****************************************************************************/
static inline int lc823450_adc_sem_wait(struct lc823450_adc_inst_s *inst)
{
return nxsem_wait_uninterruptible(&inst->sem_excl);
}
/****************************************************************************
* Name: lc823450_adc_sem_post
*
* Description:
* Release the mutual exclusion semaphore
*
****************************************************************************/
static inline void lc823450_adc_sem_post(
struct lc823450_adc_inst_s *inst)
{
nxsem_post(&inst->sem_excl);
}
/****************************************************************************
* Name: lc823450_adc_isr
*
@@ -399,7 +369,7 @@ static void lc823450_adc_rxint(struct adc_dev_s *dev, bool enable)
ainfo("enable: %d\n", enable);
ret = lc823450_adc_sem_wait(inst);
ret = nxmutex_lock(&inst->lock);
if (ret < 0)
{
return;
@@ -416,7 +386,7 @@ static void lc823450_adc_rxint(struct adc_dev_s *dev, bool enable)
}
#endif
lc823450_adc_sem_post(inst);
nxmutex_unlock(&inst->lock);
}
/****************************************************************************
@@ -442,7 +412,7 @@ static int lc823450_adc_ioctl(struct adc_dev_s *dev, int cmd,
ainfo("cmd=%xh\n", cmd);
ret = lc823450_adc_sem_wait(priv);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
@@ -493,8 +463,7 @@ static int lc823450_adc_ioctl(struct adc_dev_s *dev, int cmd,
break;
}
lc823450_adc_sem_post(priv);
nxmutex_unlock(&priv->lock);
return ret;
}
@@ -538,12 +507,12 @@ struct adc_dev_s *lc823450_adcinitialize(void)
inst->nchannels = CONFIG_LC823450_ADC_NCHANNELS;
inst->chanlist = lc823450_chanlist;
nxsem_init(&inst->sem_excl, 0, 1);
nxmutex_init(&inst->lock);
#ifndef CONFIG_ADC_POLLED
nxsem_init(&inst->sem_isr, 0, 0);
#endif
ret = lc823450_adc_sem_wait(inst);
ret = nxmutex_lock(&inst->lock);
if (ret < 0)
{
aerr("adc_register failed: %d\n", ret);
@@ -578,7 +547,7 @@ struct adc_dev_s *lc823450_adcinitialize(void)
if (ret < 0)
{
aerr("adc_register failed: %d\n", ret);
lc823450_adc_sem_post(inst);
nxmutex_unlock(&inst->lock);
kmm_free(g_inst);
return NULL;
}
@@ -590,8 +559,7 @@ struct adc_dev_s *lc823450_adcinitialize(void)
/* Now we are initialized */
g_inst = inst;
lc823450_adc_sem_post(inst);
nxmutex_unlock(&inst->lock);
}
return &g_inst->dev;
@@ -619,7 +587,7 @@ int lc823450_adc_receive(struct adc_dev_s *dev,
return -EINVAL;
}
ret = lc823450_adc_sem_wait(inst);
ret = nxmutex_lock(&inst->lock);
if (ret < 0)
{
return ret;
@@ -635,7 +603,7 @@ int lc823450_adc_receive(struct adc_dev_s *dev,
}
lc823450_adc_standby(1);
lc823450_adc_sem_post(inst);
nxmutex_unlock(&inst->lock);
return OK;
}
+3 -2
View File
@@ -36,6 +36,7 @@
#include <nuttx/arch.h>
#include <nuttx/spinlock.h>
#include <nuttx/mutex.h>
#include "arm_internal.h"
#include "lc823450_dma.h"
@@ -106,7 +107,7 @@ struct lc823450_dmach_s
struct lc823450_dma_s
{
sem_t exclsem; /* For exclusive access to the DMA channel list */
mutex_t lock; /* For exclusive access to the DMA channel list */
/* This is the state of each DMA channel */
@@ -341,7 +342,7 @@ void arm_dma_initialize(void)
sq_init(&g_dma.phydmach[i].req_q);
}
nxsem_init(&g_dma.exclsem, 0, 1);
nxmutex_init(&g_dma.lock);
if (irq_attach(LC823450_IRQ_DMAC, dma_interrupt, NULL) != 0)
{
+12 -47
View File
@@ -39,6 +39,7 @@
#include <nuttx/kmalloc.h>
#include <nuttx/clock.h>
#include <nuttx/signal.h>
#include <nuttx/mutex.h>
#include <nuttx/semaphore.h>
#include <nuttx/i2c/i2c_master.h>
@@ -117,7 +118,7 @@ struct lc823450_i2c_priv_s
const struct lc823450_i2c_config_s *config;
int refs; /* Reference count */
sem_t sem_excl; /* Mutual exclusion semaphore */
mutex_t lock; /* Mutual exclusion mutex */
#ifndef CONFIG_I2C_POLLED
sem_t sem_isr; /* Interrupt wait semaphore */
#endif
@@ -137,10 +138,6 @@ struct lc823450_i2c_priv_s
* Private Function Prototypes
****************************************************************************/
static inline int
lc823450_i2c_sem_wait(struct lc823450_i2c_priv_s *priv);
static inline void
lc823450_i2c_sem_post(struct lc823450_i2c_priv_s *priv);
static inline int
lc823450_i2c_sem_waitdone(struct lc823450_i2c_priv_s *priv);
@@ -209,6 +206,10 @@ static struct lc823450_i2c_priv_s lc823450_i2c0_priv =
.ops = &lc823450_i2c_ops,
.config = &lc823450_i2c0_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
#ifndef CONFIG_I2C_POLLED
.sem_isr = NXSEM_INITIALIZER(0, PRIOINHERIT_FLAGS_DISABLE),
#endif
.irqstate = IRQSTATE_IDLE,
.msgc = 0,
.msgv = NULL,
@@ -235,6 +236,10 @@ static struct lc823450_i2c_priv_s lc823450_i2c1_priv =
.ops = &lc823450_i2c_ops,
.config = &lc823450_i2c1_config,
.refs = 0,
.lock = NXMUTEX_INITIALIZER,
#ifndef CONFIG_I2C_POLLED
.sem_isr = NXSEM_INITIALIZER(0, PRIOINHERIT_FLAGS_DISABLE),
#endif
.irqstate = IRQSTATE_IDLE,
.msgc = 0,
.msgv = NULL,
@@ -250,34 +255,6 @@ static struct lc823450_i2c_priv_s lc823450_i2c1_priv =
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: lc823450_i2c_sem_wait
*
* Description:
* Take the exclusive access, waiting as necessary. May be interrupted by
* a signal.
*
****************************************************************************/
static inline int lc823450_i2c_sem_wait(struct lc823450_i2c_priv_s *priv)
{
return nxsem_wait(&priv->sem_excl);
}
/****************************************************************************
* Name: lc823450_i2c_sem_post
*
* Description:
* Release the mutual exclusion semaphore
*
****************************************************************************/
static inline void
lc823450_i2c_sem_post(struct lc823450_i2c_priv_s *priv)
{
nxsem_post(&priv->sem_excl);
}
/****************************************************************************
* Name: lc823450_i2c_sem_waitdone
*
@@ -978,7 +955,7 @@ static int lc823450_i2c_transfer(struct i2c_master_s *dev,
/* Ensure that address or flags don't change meanwhile */
ret = lc823450_i2c_sem_wait(priv);
ret = nxmutex_lock(&priv->lock);
if (ret < 0)
{
return ret;
@@ -1073,8 +1050,7 @@ static int lc823450_i2c_transfer(struct i2c_master_s *dev,
#endif
exit:
lc823450_i2c_sem_post(priv);
nxmutex_unlock(&priv->lock);
return ret;
}
@@ -1120,10 +1096,6 @@ struct i2c_master_s *lc823450_i2cbus_initialize(int port)
if ((volatile int)priv->refs++ == 0)
{
nxsem_init(&priv->sem_excl, 0, 1);
#ifndef CONFIG_I2C_POLLED
nxsem_init(&priv->sem_isr, 0, 0);
#endif
lc823450_i2c_init(priv, port);
}
@@ -1188,13 +1160,6 @@ int lc823450_i2cbus_uninitialize(struct i2c_master_s *dev)
lc823450_i2c_deinit(priv, port);
/* Release unused resources */
nxsem_destroy(&priv->sem_excl);
#ifndef CONFIG_I2C_POLLED
nxsem_destroy(&priv->sem_isr);
#endif
return OK;
}

Some files were not shown because too many files have changed in this diff Show More