Skip to content

Commit 57217a7

Browse files
Donny9acassis
authored andcommitted
drivers/capture: add fake capture driver for testing and development
This commit introduces a software-based fake capture driver that simulates a 10Hz square wave with 50% duty cycle, enabling development and testing of capture-related applications without requiring real hardware. Background: The capture driver subsystem requires hardware support (timers with input capture functionality) to measure external signal frequency and duty cycle. During development, testing, or on platforms without capture hardware, it's difficult to develop and test applications that use the capture API. Problem: Without a fake/simulator driver: - Developers cannot test capture applications without specific hardware - Continuous Integration (CI) systems cannot run capture-related tests - Applications cannot be developed on platforms lacking capture hardware - Testing edge notification features requires complex hardware setup - Difficult to reproduce specific timing scenarios for debugging Solution: This commit provides a software-simulated capture driver that generates predictable capture events using a watchdog timer. The fake driver produces a square wave signal at 10Hz frequency with 50% duty cycle, allowing applications to test the full capture API without hardware. Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
1 parent f6a9f82 commit 57217a7

File tree

6 files changed

+396
-0
lines changed

6 files changed

+396
-0
lines changed

drivers/drivers_initialize.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include <nuttx/syslog/syslog_console.h>
5252
#include <nuttx/thermal.h>
5353
#include <nuttx/timers/ptp_clock_dummy.h>
54+
#include <nuttx/timers/capture.h>
5455
#include <nuttx/trace.h>
5556
#include <nuttx/usrsock/usrsock_rpmsg.h>
5657
#include <nuttx/vhost/vhost.h>
@@ -298,5 +299,9 @@ void drivers_initialize(void)
298299
ptp_clock_dummy_initialize(0);
299300
#endif
300301

302+
#ifdef CONFIG_FAKE_CAPTURE
303+
fake_capture_initialize(2);
304+
#endif
305+
301306
drivers_trace_end();
302307
}

drivers/timers/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ endif()
8484

8585
if(CONFIG_CAPTURE)
8686
list(APPEND SRCS capture.c)
87+
88+
if(CONFIG_FAKE_CAPTURE)
89+
list(APPEND SRCS fake_capture.c)
90+
endif()
8791
endif()
8892

8993
if(CONFIG_GOLDFISH_TIMER)

drivers/timers/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ config CAPTURE_NOTIFY
102102
occurs. If the hardware will support notification, then this
103103
configuration should be set to enable the capability.
104104

105+
config FAKE_CAPTURE
106+
bool "Fake Capture Driver"
107+
default n
108+
depends on CAPTURE_NSIGNALS > 0
109+
---help---
110+
Enables a fake capture driver for testing purposes.
111+
105112
endif # CAPTURE
106113

107114
config TIMER

drivers/timers/Make.defs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ endif
114114

115115
ifeq ($(CONFIG_CAPTURE),y)
116116
CSRCS += capture.c
117+
118+
ifeq ($(CONFIG_FAKE_CAPTURE),y)
119+
CSRCS += fake_capture.c
120+
endif
121+
117122
TMRDEPPATH = --dep-path timers
118123
TMRVPATH = :timers
119124
endif

0 commit comments

Comments
 (0)