mirror of
https://github.com/apache/nuttx.git
synced 2026-06-01 16:59:28 +08:00
driver/motor: Remove the unnecessary critical section operation
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
@@ -68,10 +68,6 @@ static int foc_notifier(FAR struct foc_dev_s *dev,
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/* Device counter */
|
||||
|
||||
static uint8_t g_devno_cntr = 0;
|
||||
|
||||
/* File operations */
|
||||
|
||||
static const struct file_operations g_foc_fops =
|
||||
@@ -113,7 +109,6 @@ static int foc_open(FAR struct file *filep)
|
||||
FAR struct foc_dev_s *dev = inode->i_private;
|
||||
uint8_t tmp = 0;
|
||||
int ret = OK;
|
||||
irqstate_t flags;
|
||||
|
||||
/* Non-blocking operations not supported */
|
||||
|
||||
@@ -147,10 +142,6 @@ static int foc_open(FAR struct file *filep)
|
||||
|
||||
if (tmp == 1)
|
||||
{
|
||||
/* Yes.. perform one time driver setup */
|
||||
|
||||
flags = enter_critical_section();
|
||||
|
||||
ret = foc_setup(dev);
|
||||
if (ret == OK)
|
||||
{
|
||||
@@ -158,8 +149,6 @@ static int foc_open(FAR struct file *filep)
|
||||
|
||||
dev->ocount = tmp;
|
||||
}
|
||||
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -189,7 +178,6 @@ static int foc_close(FAR struct file *filep)
|
||||
FAR struct inode *inode = filep->f_inode;
|
||||
FAR struct foc_dev_s *dev = inode->i_private;
|
||||
int ret = 0;
|
||||
irqstate_t flags;
|
||||
|
||||
ret = nxsem_wait(&dev->closesem);
|
||||
if (ret >= 0)
|
||||
@@ -211,10 +199,7 @@ static int foc_close(FAR struct file *filep)
|
||||
|
||||
/* Shutdown the device */
|
||||
|
||||
flags = enter_critical_section();
|
||||
ret = foc_shutdown(dev);
|
||||
leave_critical_section(flags);
|
||||
|
||||
nxsem_post(&dev->closesem);
|
||||
}
|
||||
}
|
||||
@@ -259,9 +244,6 @@ static int foc_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
FAR struct inode *inode = filep->f_inode;
|
||||
FAR struct foc_dev_s *dev = inode->i_private;
|
||||
int ret = 0;
|
||||
irqstate_t flags;
|
||||
|
||||
flags = enter_critical_section();
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
@@ -388,8 +370,6 @@ static int foc_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
}
|
||||
}
|
||||
|
||||
leave_critical_section(flags);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -462,7 +442,6 @@ static int foc_setup(FAR struct foc_dev_s *dev)
|
||||
if (ret < 0)
|
||||
{
|
||||
mtrerr("foc_lower_bind failed %d\n", ret);
|
||||
set_errno(EINVAL);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
@@ -606,8 +585,8 @@ static int foc_cfg_set(FAR struct foc_dev_s *dev, FAR struct foc_cfg_s *cfg)
|
||||
|
||||
memcpy(&dev->cfg, cfg, sizeof(struct foc_cfg_s));
|
||||
|
||||
mtrinfo("FOC %" PRIu8 " PWM=%" PRIu32 " notifier=%" PRIu32 "\n",
|
||||
dev->devno, dev->cfg.pwm_freq, dev->cfg.notifier_freq);
|
||||
mtrinfo("FOC PWM=%" PRIu32 " notifier=%" PRIu32 "\n",
|
||||
dev->cfg.pwm_freq, dev->cfg.notifier_freq);
|
||||
|
||||
/* Call arch configuration */
|
||||
|
||||
@@ -762,13 +741,6 @@ static int foc_notifier(FAR struct foc_dev_s *dev,
|
||||
FOC_OPS_TRACE(dev, FOC_TRACE_NOTIFIER, true);
|
||||
#endif
|
||||
|
||||
/* Disable pre-emption until all of the waiting threads have been
|
||||
* restarted. This is necessary to assure that the sval behaves as
|
||||
* expected in the following while loop
|
||||
*/
|
||||
|
||||
sched_lock();
|
||||
|
||||
/* Copy currents */
|
||||
|
||||
memcpy(&dev->state.curr,
|
||||
@@ -817,10 +789,6 @@ static int foc_notifier(FAR struct foc_dev_s *dev,
|
||||
}
|
||||
}
|
||||
|
||||
/* Now we can let the restarted threads run */
|
||||
|
||||
sched_unlock();
|
||||
|
||||
#ifdef CONFIG_MOTOR_FOC_TRACE
|
||||
FOC_OPS_TRACE(dev, FOC_TRACE_NOTIFIER, false);
|
||||
#endif
|
||||
@@ -857,24 +825,10 @@ int foc_register(FAR const char *path, FAR struct foc_dev_s *dev)
|
||||
DEBUGASSERT(dev->lower->ops);
|
||||
DEBUGASSERT(dev->lower->data);
|
||||
|
||||
/* Check if the device instance is supported by the driver */
|
||||
|
||||
if (dev->devno > CONFIG_MOTOR_FOC_INST)
|
||||
{
|
||||
mtrerr("Unsupported foc devno %d\n\n", dev->devno);
|
||||
set_errno(EINVAL);
|
||||
ret = ERROR;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Reset counter */
|
||||
|
||||
dev->ocount = 0;
|
||||
|
||||
/* Store device number */
|
||||
|
||||
dev->devno = g_devno_cntr;
|
||||
|
||||
/* Assert the lower-half interface */
|
||||
|
||||
ret = foc_lower_ops_assert(dev->lower->ops);
|
||||
@@ -895,15 +849,10 @@ int foc_register(FAR const char *path, FAR struct foc_dev_s *dev)
|
||||
if (ret < 0)
|
||||
{
|
||||
nxsem_destroy(&dev->closesem);
|
||||
set_errno(ret);
|
||||
ret = ERROR;
|
||||
nxsem_destroy(&dev->statesem);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Increase device counter */
|
||||
|
||||
g_devno_cntr += 1;
|
||||
|
||||
errout:
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user