1555 Commits

Author SHA1 Message Date
Peter Bee 2a353fcc0c sim: adapt macos avfoundation backend for camera indexing and capture
Adapt the macOS AVFoundation backend for multi-device discovery,
camera index mapping and capture startup compatibility. This enables
reliable use of multiple cameras through the SIM camera framework.

Signed-off-by: Peter Bee <bijunda@bytedance.com>
2026-05-08 19:51:39 +08:00
Peter Bee ea05918799 sim: support camera framework multi-instance and dynamic mounting
Allow the SIM camera/V4L2 capture framework to manage multiple
imgdata instances with dynamic mounting. This avoids cross-talk
between camera streams when multiple devices are used.

Signed-off-by: Peter Bee <bijunda@bytedance.com>
2026-05-08 19:51:39 +08:00
Lingao Meng e7fd9b1d49 arch/sim: add host_set_timeratio stub for Windows
The simulated time ratio feature introduced a host_set_timeratio()
call in sim_head.c, but the Windows host time implementation was
missing this symbol, causing a link error. Add a no-op stub since
the time ratio feature is not implemented on Windows.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2026-04-27 15:04:33 +08:00
Lingao Meng 62629d5efe arch/sim: fix host_settimer clock mismatch on macOS
dispatch_walltime() expects a delta in nanoseconds from now, but the
previous code subtracted CLOCK_REALTIME from a CLOCK_MONOTONIC absolute
timestamp, which have different epochs and produce a meaningless result.

Fix by subtracting the current CLOCK_MONOTONIC absolute time to get the
correct remaining duration.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2026-04-25 15:53:42 +08:00
Lingao Meng dfd735045c arch/sim: add simulated time ratio support
Add CONFIG_SIM_WALLTIME_RATIO Kconfig option and --sim-rt-ratio=
command-line argument to control the ratio of simulated time to
real time in percent. 100 means real-time (default), 200 means
simulated time advances twice as fast, 50 means half speed.

The implementation applies the ratio in host_gettime(), host_sleepuntil()
and host_settimer() so both SIM_WALLTIME_SLEEP and SIM_WALLTIME_SIGNAL
modes are supported.

This is inspired by the --rt-ratio feature in Zephyr's native_sim board.

Tested on sim:nsh with the following sleep test:

  $ echo -e "sleep 2\nexit" | time ./nuttx
  real    0m2.0xxs

  $ echo -e "sleep 2\nexit" | time ./nuttx --sim-rt-ratio=200
  real    0m1.0xxs

  $ echo -e "sleep 2\nexit" | time ./nuttx --sim-rt-ratio=50
  real    0m4.0xxs

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2026-04-25 15:53:42 +08:00
bijunda e874561291 sim: replace posix timer with GCD dispatch timer on macOS
macOS does not provide full POSIX timer support for the host-side
simulator build, so references to timer_t and timer_create can fail when
building sim:fb on Apple hosts. Replace the POSIX timer path with a
Grand Central Dispatch timer on macOS while keeping the existing POSIX
implementation for other hosts.

The dispatch timer raises SIGALRM from its event handler so the host
side keeps the same timer-driven behavior expected by the simulator.
This preserves the existing timing model and fixes the macOS host build
failure for sim:fb.

Signed-off-by: Peter Bee <bijunda@bytedance.com>
2026-04-14 19:40:10 +08:00
bijunda 333815c594 build(sim): fix macOS XQuartz include and library paths for sim:fb
macOS does not ship X11 headers and libraries in the default system
search paths, so sim:fb fails to build unless the XQuartz installation
prefix is detected explicitly. Probe /opt/X11 first and fall back to
/usr/X11 so the simulator can find the required X11 headers and libs on
common macOS setups.

This fixes the sim:fb build failure on macOS hosts that rely on XQuartz
for X11 development files.

Signed-off-by: Peter Bee <bijunda@bytedance.com>
2026-04-14 19:40:10 +08:00
Piyush Patle 13d0e64ee6 style: fix checkpatch issues after debug.h move
Build Documentation / build-html (push) Has been cancelled
Fixed copespell errors, for CI sucess!

Signed-off-by: Piyush Patle <piyushpatle228@gmail.com>
2026-04-07 07:50:06 -03:00
Piyush Patle 0dccc8ba21 include/debug.h: Move to include/nuttx/debug.h
debug.h is a NuttX-specific, non-POSIX header. Placing it in the
top-level include/ directory creates naming conflicts with external
projects that define their own debug.h.
This commit moves the canonical header to include/nuttx/debug.h,
following the NuttX convention for non-POSIX/non-standard headers,
and updates all in-tree references.

A backward-compatibility shim is left at include/debug.h that
emits a deprecation #warning and re-includes <nuttx/debug.h>,
allowing out-of-tree code to continue building while migrating.

Signed-off-by: Piyush Patle <piyushpatle228@gmail.com>
2026-04-07 07:50:06 -03:00
Huang Qi e3eeaefd6d style: Fix "the the" typo across the codebase.
Fix 269 occurrences of duplicate "the" word typo found in 209 files
across source code, header files, and configuration.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2026-03-23 11:07:49 +01:00
Aditya Yadav 574fc64ab9 sim: Fix linker support and macOS host build issues
Update SIM configuration and CMake toolchain to resolve
linker errors when building on macOS. Adjust POSIX host
implementation to ensure successful compilation and
proper behavior of the sim target.

Modified:
- arch/sim/Kconfig
- arch/sim/src/cmake/Toolchain.cmake
- arch/sim/src/sim/posix/sim_hostmisc.c

Signed-off-by: Aditya Yadav <166515021+aditya0yadav@users.noreply.github.com>
2026-03-05 21:52:58 +08:00
zhenwei fang f0fc695a81 arch/sim: fix warning ‘sim_buttonmap’ defined but not used
N/A

Signed-off-by: zhenwei fang <fangzhenwei@bytedance.com>
Signed-off-by: chao an <anchao.archer@bytedance.com>
2026-02-27 19:54:46 +08:00
xingrentai.1 bf83ff3fbd arch/sim: guard X11 touchscreen events with CONFIG_SIM_TOUCHSCREEN
The X11 event loop in the POSIX simulator was processing MotionNotify
(touch/mouse movement)and ButtonPress/ButtonRelease events unconditionally,
even when the touchscreen feature(CONFIG_SIM_TOUCHSCREEN) was disabled.

This could lead to unnecessary event processing, potential compiler warnings
about unusedfunctions (e.g., sim_buttonevent), or unintended behavior in simulator
builds withouttouchscreen support. The touchscreen-related event handling should
only be active whenthe corresponding configuration is enabled.

This fix wraps the MotionNotify and ButtonPress/ButtonRelease event handling
logicwith #ifdef CONFIG_SIM_TOUCHSCREEN guards to:

1. Ensure touchscreen/mouse event processing is only compiled when CONFIG_SIM_TOUCHSCREEN is enabled.
2. Eliminate unused code warnings in non-touchscreen simulator builds.
3. Align event loop behavior with the configured feature set, reducing unnecessary runtime overhead.

The change maintains full touchscreen functionality when the config is enabled, whilecleaning up the
code path for builds that don't require touchscreen support.

Signed-off-by: chao an <anchao.archer@bytedance.com>
2026-02-27 19:54:46 +08:00
xingrentai.1 ee3e931812 arch/sim: fix X11 framebuffer window not visible in POSIX simulator
The X11 framebuffer implementation in the POSIX simulator was creating a window
and graphics context but failing to map (display) the window to thescreen with XMapWindow().

This omission meant the framebuffer window would be created in the X11server but remain hidden,
making it impossible to see any graphics outputfrom the simulator. The window existed in the X11
server's state but wasnot rendered to the screen.

This fix adds the missing XMapWindow(display, g_window) call aftercreating the graphics context, which:
1. Maps the created X11 window to the screen (makes it visible).
2. Ensures framebuffer output is rendered to the display as expected.
3. Maintains compatibility with existing X11 framebuffer logic.

The change restores basic visibility of the simulator's framebuffer window,
fixing a critical usability issue for graphics-related testing in the POSIX simulator.

Signed-off-by: chao an <anchao.archer@bytedance.com>
2026-02-27 19:54:46 +08:00
fangzhenwei e4ed6156ca arch/sim: fix incomplete HCI socket data reading in simulator interrupt handler
The sim_bthcisock_interrupt() handler for Bluetooth HCI sockets in the simulatorwas using
an if statement to check for available data on the HCI socket. Thismeant that only a single
packet would be read and processed per interrupt trigger,even if multiple packets were waiting
in the socket buffer.

This led to incomplete data processing: unread packets would remain in the bufferuntil the next
interrupt tick, causing delayed handling of Bluetooth HCI events/commands,packet backlogs,
or missed data in high-throughput scenarios.

This fix replaces the if with a while loop to:

1. Continuously check for and read available data from the HCI socket until no more
   packets are present in the buffer.
2. Ensure all pending HCI packets are processed in a single interrupt handler invocation.
3. Eliminate packet backlogs and reduce latency in Bluetooth HCI communication.

The change maintains the same core data reception logic (bthcisock_receive()) butensures it runs
for all available packets, improving the reliability and responsivenessof the simulator's Bluetooth HCI socket implementation.

Signed-off-by: chao an <anchao.archer@bytedance.com>
2026-02-26 08:15:28 -03:00
SPRESENSE 72b67832ea Makefile: Remove make depend files by make distclean
Intermediate files of make depend like .ddc and .dds may remain
when make is interrupted. Remove them using make distclean.

Signed-off-by: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com>
2026-02-16 16:27:57 +01:00
yaojingwei c5549143ad sim_camera: support enum pixel format.
Expose enum pixel format support in sim_camera.

Signed-off-by: yaojingwei <yaojingwei@xiaomi.com>
2026-02-09 20:56:46 -03:00
wangmingrong1 28026af824 arch/sim: Add sigdelset to nuttx-names.in
sigdelset is used in up_enable_irq: sigdelset(&act.sa_mask, SIGSTOP);

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2026-01-31 14:14:32 +08:00
ganjing 206aaa8612 arch/sim: improve heap management on Simulator
and proper accounting of heap metadata

Signed-off-by: ganjing <ganjing@xiaomi.com>
2026-01-27 21:27:53 +08:00
ganjing e941b18e29 mm/umm: Allow customizing the implementation of umm heap
and migrate arch/sim from the customized mm_heap to
umm_heap, so the default mm_heap implementation can
still be used(e.g. shared memory in OpenAMP).

Signed-off-by: ganjing <ganjing@xiaomi.com>
2026-01-27 21:27:53 +08:00
xuxin19 80505da579 cmake(bugfix):remove unused libmad link in SIM build
libmad has been ported into apps
and does not require linking to the host.

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2026-01-27 20:54:26 +08:00
hujun5 a3273e6a96 arch: Add stack alignment and stack size checking when CONFIG_TLS_ALIGNED=y
Build Documentation / build-html (push) Has been cancelled
Add validation to ensure allocated stack size does not exceed TLS_MAXSTACK when
CONFIG_TLS_ALIGNED is enabled, and verify proper stack alignment using STACK_ALIGN_MASK
across all architectures. This improves stack safety and prevents potential TLS overflow conditions.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2026-01-22 22:18:11 +08:00
hujun5 6f03601169 arch: rename STACK_ALIGNMENT to STACKFRAME_ALIGN across all architectures
Rename STACK_ALIGNMENT macro to STACKFRAME_ALIGN throughout the codebase
to provide clearer naming semantics. The new name better reflects the macro's
purpose of frame alignment rather than general stack alignment.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2026-01-22 15:37:24 +08:00
hujun5 e604bacd42 sim: it is not necessary to call restore_critical_section in irq
Build Documentation / build-html (push) Has been cancelled
Remove restore_critical_section() call from up_switch_context() in simulator
as it is not necessary during interrupt context switching. The critical
section state is properly managed elsewhere in the interrupt handling flow.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2026-01-20 12:22:18 -03:00
hujun5 63e59e26c0 arch: move some macros to public code.
Move stack alignment and kernel stack macros from architecture-specific internal
headers to public include/nuttx/irq.h. Consolidates duplicate definitions across
17 architecture families, reducing code duplication while enabling common code
to access these core alignment utilities without architecture dependencies.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2026-01-20 01:53:08 +08:00
zhangshuai39 1c2d1c579f simwifi: Fix compilation warning
Added the `<nuttx/kmalloc.h>` header file and fixed the implicit conversion issue.

Signed-off-by: zhangshuai39 <zhangshuai39@xiaomi.com>
2026-01-19 12:14:18 -03:00
xuxin19 a7c6f589f9 cmake(bugfix):fix sim loadable elf build support
1.add sanity check for START_OBJS
2.make laodable -e entry setting in each arch elf.cmake
3.add sim elf.cmake

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2026-01-19 14:45:37 +08:00
hujun5 8bb250a4c0 arch: move STACK_ALIGNMENT to irq.h
Move STACK_ALIGNMENT macro definitions from architecture-specific internal
headers to public irq.h headers. This enables common code to directly access
STACK_ALIGNMENT without requiring internal header inclusion, improving code
organization and reducing header dependencies. Applies to all architectures:
ARM, ARM64, AVR, HC, MIPS, or1k, Renesas, RISC-V, SIM, SPARC, TriCore, x86,
x86_64, Xtensa, Z16, and Z80.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2026-01-19 14:43:43 +08:00
Bowen Wang e686a3ac42 mm/mm_heap: use struct mm_heap_config_s to init the memory heap
To avoid add new parameters to the mm_initialize_heap() and
mm_initialize_pool()

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2026-01-19 14:18:27 +08:00
anjiahao 6ed4ea63d8 mm: support mm_initialize_heap to specify a specific heap pointer
Support user pass it own heap struct to the mm_initialize_heap() to
avoid the heap struct is reserved from the heap range

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2026-01-19 14:18:27 +08:00
Bowen Wang 0bc9f94304 sim/sim_rptun: modify sim_rptun to port new rptun framework
1. Use reserved[0] filed in struct fw_rsc_vdev and the driver
master/slave to judge the device role;
2. Use struct fw_rsc_carveout in resource table to provide the
share memory to virtio driver side;

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
2026-01-19 14:18:27 +08:00
Bowen Wang 47b6c1f2a9 sim/sim_rptun: use host_kill() to kill proxy core when stop proxy
To avoid hang in the host_waitpid() in sim_rptun_stop()

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2026-01-19 14:18:27 +08:00
Bowen Wang 906299df21 sim/posix: add host_kill API to kill other thread
sim rptun need use this api to kill the proxy core

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2026-01-19 14:18:27 +08:00
Yongrong Wang 911ab7c55b drivers/rptun and rpmsg_virtio: remove cmd initialize
don't need initialize in sim

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
2026-01-19 14:18:27 +08:00
wangchengdong 2a0990bd31 arch/sim: Add support to disable signals actions related data struct
Add support to disable signals actions related struct

Co-authored-by: guoshichao <guoshichao@xiaomi.com>
Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
2026-01-18 08:24:13 -03:00
ligd 113bb02568 checkstack: fix access overflow when checkstack
We should check length first, and then check the value

Signed-off-by: ligd <liguiding1@xiaomi.com>
2026-01-17 18:04:28 -03:00
guanyi3 f99dd20c4e sim/usrsock: move g_work_queue init before net_initialize
usrsock register work in net_initialize before g_work_queue is created, so move g_work_queue in irq_initialize.

Signed-off-by: guanyi3 <guanyi3@xiaomi.com>
2026-01-16 09:39:02 +08:00
guanyi3 7dde767155 sim: add global work queue to replace HPWORK
rpmsg work in hpwork are waiting for remote buffer, remote get buffer and callback, but callback also in hpwork, deadlock occurs here.
now we move periodic work to global work queue instead of hpwork to fix deadlock.

Signed-off-by: guanyi3 <guanyi3@xiaomi.com>
2026-01-16 09:39:02 +08:00
guanyi3 27c9d388d9 sim: replace wdog to work queue to avoid deadlock
The wdog callbacks are executed in the host's signal handler context, which has strict limitations on what operations can be safely performed. Specifically, signal handlers should not call non-async-signal-safe functions (e.g., sim_alsa use mutex_lock in wdog and cause deadlock).

This change only replaces uses of wdog for periodic tasks. Other interrupt callbacks that are still invoked from the host signal handler are not replace to work queue.

Signed-off-by: guanyi3 <guanyi3@xiaomi.com>
2026-01-16 09:39:02 +08:00
daichuan 1817484bcd arch/sim: support SOCK_RAW in host_usrsock_socket
Convert NUTTX_SOCK_RAW to native SOCK_RAW in the simulator usrsock implementation.

Signed-off-by: daichuan <daichuan@xiaomi.com>
2026-01-16 09:38:46 +08:00
liqinhui 0e4d291156 sim: Pass through unknown sockopt to system.
Remove the interception of unknown levels and option names in sim usrsock.
This allows the system socket interface to handle them and return the correct error codes or behavior, rather than returning a generic error locally.

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2026-01-15 13:29:56 -08:00
cuiziwei e9bbf2928b libcxx: porting libcxx test.
porting libcxx test case to nuttx.

Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
2026-01-15 13:40:42 -03:00
liqinhui 1d8eab937f simwifi: refactor the interfaces of simwifi and simnet
Fix CMake logic to correctly include sim_wifihost.

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2026-01-14 09:22:54 +08:00
liqinhui 3843f7b4fe wifi: Support the wifi operations based on the bss file.
Add support for BSS file-based WiFi simulation.

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2026-01-14 09:22:54 +08:00
liqinhui dce89e1820 simwifi: Refactor the interfaces of simwifi and simnet
Refactor simwifi to separate host and sim logic.

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
2026-01-14 09:22:54 +08:00
buxiasen a938926b52 arch/sim: add JB_ALIGN0 for x64 to ensure the align
Or will cause the fork break as call will auto push 1 item.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2026-01-13 10:29:24 +08:00
buxiasen 1058397807 arch/sim: save errno when do context switch
Avoid the errno changed after interrupt in sim and make return value
mistake when according to errno.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2026-01-13 10:29:24 +08:00
buxiasen 100c9dd20b arch/sim: add host_errno_get/set for sim to backup/restore in "irq"
Avoid the errno changed after interrupt in sim and make return value
mistake when according to errno.
Move host_errno_convert from macro to sim_errno.c.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2026-01-13 10:29:24 +08:00
buxiasen cd2bf49474 arch/sim/rawgadget: remove the host_uninterruptible_errno
We will remove the API in next commit, so remove the errno manual save
API and save errno more commonly.
After whole pull request, should no longer need to care about errno.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2026-01-13 10:29:24 +08:00
buxiasen 8d2ef7f43c Revert "arch/sim: avoid host-call being interrupted before getting errno"
This reverts commit ac5b38c9e5.

Keep host_errno_convert as a common interface in sim_internal.h
Keep the up_irq_save & up_irq_restore as common interface

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2026-01-13 10:29:24 +08:00