From fd47add2a3fd8480e21b0f1144d4ee3b9ab283d3 Mon Sep 17 00:00:00 2001 From: yangguangcai Date: Tue, 18 Jun 2024 21:42:18 +0800 Subject: [PATCH] capture:add CAPIOC_ALL for ioctl. When monitoring multiple capture channels, the `ioctl` function is called three times, leading to significant overhead mainly due to VFS and `nxmutex_lock/unlock`. Adding a new interface can save the overhead of two `ioctl` calls. Signed-off-by: yangguangcai --- drivers/timers/capture.c | 33 +++++++++++++++++++++++++++++++++ include/nuttx/timers/capture.h | 8 ++++++++ 2 files changed, 41 insertions(+) diff --git a/drivers/timers/capture.c b/drivers/timers/capture.c index 556f646797c..a67614d150f 100644 --- a/drivers/timers/capture.c +++ b/drivers/timers/capture.c @@ -316,6 +316,39 @@ static int cap_ioctl(FAR struct file *filep, int cmd, unsigned long arg) } break; + /* CAPIOC_ALL - Get the pwm duty, pulse frequence, pwm edges, from + * the capture. + * Argument: A reference to struct cap_all_s. + */ + + case CAPIOC_ALL: + { + FAR struct cap_all_s *ptr = + (FAR struct cap_all_s *)((uintptr_t)arg); + DEBUGASSERT(lower->ops->getduty != NULL && ptr); + DEBUGASSERT(lower->ops->getedges != NULL && ptr); + DEBUGASSERT(lower->ops->getfreq != NULL && ptr); + + ret = lower->ops->getduty(lower, &ptr->duty); + if (ret < 0) + { + break; + } + + ret = lower->ops->getfreq(lower, &ptr->freq); + if (ret < 0) + { + break; + } + + ret = lower->ops->getedges(lower, &ptr->edges); + if (ret < 0) + { + break; + } + } + break; + /* Any unrecognized IOCTL commands might be platform-specific ioctl * commands */ diff --git a/include/nuttx/timers/capture.h b/include/nuttx/timers/capture.h index ea620701f2f..1f6ec190514 100644 --- a/include/nuttx/timers/capture.h +++ b/include/nuttx/timers/capture.h @@ -37,11 +37,19 @@ #define CAPIOC_DUTYCYCLE _CAPIOC(1) #define CAPIOC_FREQUENCE _CAPIOC(2) #define CAPIOC_EDGES _CAPIOC(3) +#define CAPIOC_ALL _CAPIOC(4) /**************************************************************************** * Public Types ****************************************************************************/ +struct cap_all_s +{ + uint32_t freq; + uint32_t edges; + uint8_t duty; +}; + /* This structure provides the "lower-half" driver operations available to * the "upper-half" driver. */