Commit Graph

7858 Commits

Author SHA1 Message Date
Huang Qi
311f42bbac libc/unistd: Replace pipe() macro with proper function implementation
Replace the pipe() macro definition with a proper function implementation
to improve POSIX compliance and debugging capabilities. The new pipe()
function serves as a wrapper around pipe2() with flags set to 0.

Changes include:
- Convert pipe() from macro to function declaration in unistd.h
- Add lib_pipe.c implementation file with proper function documentation
- Update build system files (CMakeLists.txt and Make.defs) to include
  the new source file when CONFIG_PIPES is enabled
- Add pipe() entry to libc.csv for symbol tracking

This change allows for better debugging, proper symbol resolution,
and follows NuttX coding standards for library function implementations.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2025-11-26 17:18:13 +08:00
wangchengdong
bc561c677a sched/sleep: Add nxched_nanosleep() API
Introduce the nxched_nanosleep() API to provide a lightweight
nanosecond-level sleep based on nxsched_ticksleep().
This API offers the same functionality as nxsig_nanosleep() but without
signal-related overhead, making it suitable for implementing libc
sleep() or usleep() when signals are disabled.

Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
2025-11-25 10:02:13 +08:00
Antoine Juckler
02db473e97 drivers/eeprom: Set the bus frequency
Add EEPIOC_SETSPEED ioctl acting like the MTDIOC_SETSPEED ioctl. The
default frequency is settable in the Kconfig.

Add xx25xx SPI delay control configurations.

Signed-off-by: Antoine Juckler <6445757+ajuckler@users.noreply.github.com>
2025-11-25 09:49:26 +08:00
Karel Kočí
c61d7c7e8d nuttx/can: add message alignment
This adds ability for read and write operations to work with messages
aligned to configured number of bytes. This has few different use
cases.

The alignment is specified as unsigned integer and can be changed with
ioctl command CANIOC_SET_MSGALIGN. The current value can be queried by
CANIOC_GET_MSGALIGN command.

The default value for the message alignment is 1. This will provide
behavior consistent with current one. Thus messages are placed to the
buffer right after data of the previous one. The same applies for
writes.

The special alignment value 0 disables read and write of multiple frames. Thus
read will always return at most one message and write will always write
only one message even if larger buffer size is provided.

Another use case is if message alignment is set to exactly message
representation size (`sizeof(struct can_msg_s)`). This allows writing
and reading arrays of messages.

Other values provide even more advanced and specialized use cases, such
as optimizations if architecture has to emulate some non-aligned
accesses, there alignment of for example 4 bytes could provide
performance boost.

The original motivation behind this is was compatibility with socket
CAN. It is easier to port applications to NuttX's CAN driver if only one
frame is provided at the time. This solution was suggested by Pavel Pisa
<pisa@fel.cvut.cz> as a more versatile variant of plain boolean
disabling the multiple frame retrieval.

Signed-off-by: Karel Kočí <kkoci@elektroline.cz>
2025-11-24 14:11:41 +08:00
Karel Kočí
8230c44517 nuttx/can: fix two documented CANIOC names
This is just a simple typo (missing underscore) in the definition. I am
fixing the documentation instead to make it consistent instead of
breaking an API.

Signed-off-by: Karel Kočí <kkoci@elektroline.cz>
2025-11-24 14:11:41 +08:00
Karel Kočí
b9066e42bb include: add BSD rounding macros to sys/param.h
These macros are commonly provided on BSD systems. They are not part of
C nor POSIX but these types of operations can be required in drivers
implementation as well as in user space. The operations themself are
simple but kind of cryptic when placed in the code as is. Thus having
macro with an appropriate name is beneficial.

The use of BSD naming here is only to cling to at least some other
implementation instead of creating completelly NuttX specific one.

Kudos to @hartmannathan for the source code documentation.

Signed-off-by: Karel Kočí <kkoci@elektroline.cz>
2025-11-24 14:11:41 +08:00
ouyangxiangzhen
39d9eb2343 timers: Fix typo.
This commit fixed typo in clkcnt.h and oneshot.h

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-11-19 12:24:56 +08:00
ouyangxiangzhen
a5f5ab185c driver/timers: Fix coverity uninitialzed timespec.
This commit fixed uninitialized timespec.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-11-19 12:24:56 +08:00
ouyangxiangzhen
4b31291043 timers/oneshot: Add clkdev fast-path.
This commit add fast-path for oneshot clkdev APIs.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-11-19 12:24:56 +08:00
ouyangxiangzhen
9569129862 timers/oneshot: Add new start_absolute interface.
Current timer hardware supports both absolute and relative count timers. Without an absolute count timer interface, setting an alarm timer might incur additional overhead in obtaining the current time, resulting in performance degradation and inaccurate timing.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-11-19 12:24:56 +08:00
ouyangxiangzhen
6dcb8270e3 timers/oneshot: Add new clkdev interfaces.
This commit introduce new clockdevice interfaces for oneshot.
- It can represent both `timer` and `alarm`.
- It simplifies the implementation of timer driver. Timer driver do not need considering the time conversion between clock count, tick and timespec.
- It sets timer align to the tick boundary to improve timer accuracy.
- It can avoid using 64-bit division during timer expiration interrupt, improves performance and reduces interrupt latency.
- It considers almost all multiplication overflow problems in time conversion without processing at the driver.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-11-19 12:24:56 +08:00
ouyangxiangzhen
06fe9f076e timers/oneshot: Introduce count-based interfaces.
This commit introduced count-based oneshot interfaces.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-11-19 12:24:56 +08:00
ouyangxiangzhen
c6139f89c8 timers/oneshot: Improve tick-compatiable interfaces.
This commit improved tick-compatiable interfaces.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-11-19 12:24:56 +08:00
Antoine Juckler
224afcb77b drivers/eeprom/spi_xx25xx: Multi-device SPI bus support
Adds a device ID to ee25xx_initialize, which is stored in the
ee25xx_dev_s structure. This ID is used when calling SPI_SELECT.

The implementation is based on the handling of the chip select in
mtd/ramtron.c

This change is NOT backward compatible: the function signature has changed

Signed-off-by: Antoine Juckler <6445757+ajuckler@users.noreply.github.com>
2025-11-18 09:37:07 -03:00
Antoine Juckler
81550800d4 drivers/mtd/at25ee: Multi-device SPI bus support
Adds a device ID to at25ee_initialize, which is stored in the
at25ee_dev_s structure. This ID is used when calling SPI_SELECT.

The implementation is based on the handling of the chip select in
mtd/ramtron.c

This change is NOT backward compatible: the function signature has changed

Signed-off-by: Antoine Juckler <6445757+ajuckler@users.noreply.github.com>
2025-11-18 09:37:07 -03:00
ouyangxiangzhen
7e7828b3f6 timers/oneshot: Remove oneshot tick API.
This commit removed all oneshot tick API for new clkdev API.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-11-18 13:02:29 +01:00
ouyangxiangzhen
fc28b93224 timers/oneshot: Remove all callback and args.
This commit remove all callback and args in the APIs.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-11-18 13:02:29 +01:00
ouyangxiangzhen
5c113f79b7 timers/oneshot: Remove all private callback.
This commit removed all private callback and handle it on the upperhalf
of oneshot.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-11-18 13:02:29 +01:00
ouyangxiangzhen
dd88c99863 timers/clkcnt: Fix the assertion if max_tick > CLOCK_MAX.
This commit fixed the assertion if max_tick > CLOCK_MAX when the clock_t is
32-bit.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-11-17 14:15:44 +08:00
ouyangxiangzhen
575844ad39 clkcnt: Add clockcount abstraction.
This commit added the clkcnt abstraction.
Clkcnt is used to abstract the cycle counter of hardware timer, which can represent almost all existing timers. Time conversion through API provided by clkcnt can avoid any timing conversion problem (multiplication overflow, division precision loss, etc.).

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-11-17 14:15:44 +08:00
ouyangxiangzhen
152c66de05 compiler: Support pure function attributes and compile-time constant condition.
This commit added support for pure function attributes and compile-time
constant condition.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-11-17 14:15:44 +08:00
wangchengdong
1b58a449c5 sched/clock: Make g_system_ticks a static variable
Make g_system_ticks a static variable, as it is only accessed by
    clock_get_sched_ticks().

    This change improves code modularity and enhances safety, since
    clock_get_sched_ticks() performs proper synchronization when
    reading g_system_ticks.

Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
2025-11-13 18:40:16 -03:00
Antoine Juckler
23de88e70e fs/fs.h: Add register_driver_with_size function
It acts as register_driver but also populates the inode size.
This allows to return a non-zero size when calling stat() on an eeprom
driver.

The conditions (CONFIG_PSEUDOFS_FILE or CONFIG_FS_SHMFS) for the
declaration of the inode size field have also been removed so that other
drivers can populate this field in the future.

Signed-off-by: Antoine Juckler <6445757+ajuckler@users.noreply.github.com>
2025-11-13 08:57:52 -03:00
Antoine Juckler
934dfdf645 drivers/eeprom: Retrieve the geometry
Add EEPIOC_GEOMETRY IOCTL command to retrieve the
EEPROM geometry.

Signed-off-by: Antoine Juckler <6445757+ajuckler@users.noreply.github.com>
2025-11-13 08:57:52 -03:00
Jani Paalijarvi
c793572c1c include/nuttx/mtd/mtd.h: Add MTDIOC_RESET ioctl
Define MTDIOC_RESET ioctl command for resetting flash memory.

Signed-off-by: Jani Paalijarvi <jani.paalijarvi@unikie.com>
2025-11-12 20:39:00 +08:00
wangchengdong
07e05b8591 sched/wdog: Add wd_restart_next() for precise wdog restart upon expiration
This patch introduces wd_restart_next(), which enables precise and
    convenient watchdog restarts upon expiration. It is designed to be
    invoked within the watchdog expiration callback to facilitate accurate
    periodic events.

Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
2025-11-10 23:16:57 +08:00
wangchengdong
8696632abe sched/wdog: Add wd_restart() for convenient restart of a wdog
Introduce wd_restart() to allow restarting an existing watchdog
    with its previously configured callback and argument, making it
    easier to refresh or reuse preconfigured watchdog timers.

Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
2025-11-10 23:16:57 +08:00
wangchengdong
71f53c6c74 sched/wdog: Inline wd_start() to improve performance
Move wd_start() to an inline function to reduce function call
    overhead and improve performance in time-critical watchdog operations.

Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
2025-11-10 23:16:57 +08:00
chao an
8847389886 style/FAR: remove FAR qualifier
N/A, remove FAR qualifier from non-pointer types

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-11-10 10:56:29 +01:00
nuttxs
65e318421d netdb/lib_dnsdelserver.c: support delete the DNS server address
Some checks failed
Build Documentation / build-html (push) Has been cancelled
by index or address

 - dns_del_nameserver()
 - dns_del_nameserver_by_index()

Update the "DNS function" section in 11_network.rst, and create
the netlib API documentation in netlib/index.rst

Signed-off-by: nuttxs <zhaoqing.zhang@sony.com>
2025-11-08 16:17:40 -03:00
wangchengdong
190daef2bf sched/wdog: Use list_in_list() to detect active watchdogs
Use list_in_list() to determine whether a watchdog is active,
     eliminating the need to set the watchdog function pointer to NULL
     as an indicator of inactivity.

Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
2025-11-07 10:30:53 +08:00
Jukka Laitinen
5961b8bd1a binfmt: Add a configuration flag to store the module filename
This flag can be used to store the filename of a loaded module or
executable in binfmt. The filename is useful for example in debugging.
For example, gdb or a jtag debugger can be configured to automatically
fetch the symbols for the currently executing module.

Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
2025-11-01 22:59:47 +08:00
chao an
62660a692d sched/task: move lock to mhead scope
1. rename mutex_lock to mhead_lock to declare purpose of lock
2. move lock to mhead scope

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-11-01 22:52:07 +08:00
wangchengdong
de5973268b [!] sched/event: Remove wait object dependency from event implementation
The current event implementation relies on a dedicated wait object,
    which introduces several issues:
        1. Increases memory usage
        2. Complicates the event logic
        3. Makes the API design less clean, as it requires a separate
                nxevent_tickwait_wait() function

    This patch removes the event’s dependency on the wait object
    and eliminates the nxevent_tickwait_wait() API accordingly.

    BREAKING CHANGE: this commit removed the nxevent_tickwait_wait function
    so the related docs should be updated accordingly

Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
2025-10-31 19:56:32 -03:00
wangchengdong
735e489070 [!] sched/event: Replace semaphore with direct scheduler operations in event
The current event implementation uses semaphores for wait and post
    operations. Since semaphores are relatively heavy-weight and intended
    for resource-based synchronization, this is suboptimal.

    So this patch replaced the semaphore-based mechanism with direct
    scheduler operations to improve performance and reduce memory footprint.

    This patch also introduce a new task state TSTATE_WAIT_EVENT to indicate
    the task is waiting for a event.

    BREAKING CHANGE:  This commit introduced a new task state TSTATE_WAIT_EVENT
    so apps/nshlib/, procfs/ and tools/pynuttx/nxgdb/ are needed to be updated accordingly.

Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
2025-10-31 19:56:32 -03:00
wangchengdong
5fa8634ce7 sched/event: Restore critical section protection for event wait and post
Restore the use of critical sections to provide mutual exclusion
    between event wait and post operations. This allows replacing the
    heavier semaphore-based mechanism with direct scheduler operations
    for synchronization.

Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
2025-10-31 19:56:32 -03:00
wangchengdong
378a827a7a sched/syslog: Add early_syslog() for early boot or system down debugging
Introduce early_syslog() to enable basic logging during the very early
    boot or system down stages, when the full syslog subsystem is not yet
    available.

Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
2025-10-31 08:29:17 -03:00
wangchengdong
5beb4ae6d5 sched/sched: Introduce nxsched_wakeup()
Add a new function nxsched_wakeup() to the scheduler,
    which allows waking up a sleeping task before its timeout.

Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
2025-10-28 10:43:24 +08:00
ouyangxiangzhen
be413af022 compiler: Fix inlining stack-overflow.
If the compiler optimization is disabled, the stack-usage of inlining functions will not be optimized.
In this case, force inlining can lead to stack-overflow (e.g.
qemu-armeabi-v7a-bl). This commit replaced the definition of the
always_inline_function and inline_function with the inline
keyword to avoid force-inlining.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-10-22 09:46:42 +08:00
ouyangxiangzhen
f309d65a7f lib/math32: improve the performance of invdiv_u32.
This commit provided a better invdiv_u32 implementation on 64-bit architectures. The test results showed it is 25% faster than the original implementation on x86_64.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-10-22 09:46:42 +08:00
ouyangxiangzhen
f6dfd3f6d0 lib/math32: Support optimized runtime-invariant integer division.
This commit implemented optimized runtime-invariant integer division
proposed by T. Granlund and L. Montgomery. It can be used to convert the
hardware clock cycles to seconds, where the clock frequency is runtime-invariant.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-10-22 09:46:42 +08:00
wangchengdong
519ffe66d0 sched/sched: Replace nxsched_alarm_tick_expiration()
Introduce a new function nxsched_tick_expiration() to replace
    nxsched_alarm_tick_expiration(). The new function provides a
    common implementation that can be shared by both the alarm
    and timer architectures.

    This change reduces code duplication and provides a unified
    function that can be directly reused.

Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
2025-10-18 20:07:59 +08:00
chao an
a8af5f3d0e style/spell: fix spell checker error
To make checker happy:

arch/arm/src/sama5/sam_classd.c:997: nd ==> and, 2nd
arch/arm/src/sama5/sam_classd.c:1362: levl ==> level
drivers/sensors/apds9922.c:286: persistance ==> persistence

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-10-17 14:05:02 +08:00
chao an
02bfd290ac sched/sleep: add support for scheduling sleep
Nuttx currently has 2 types of sleep interfaces:

1. Signal-scheduled sleep: nxsig_sleep() / nxsig_usleep() / nxsig_nanosleep()
Weaknesses:
  a. Signal-dependent: The signal-scheduled sleep method is bound to the signal framework, while some driver sleep operations do not depend on signals.
  b. Timespec conversion: Signal-scheduled sleep involves timespec conversion, which has a significant impact on performance.
2. Busy sleep: up_mdelay() / up_udelay()
Weaknesses:
  a. Does not actively trigger scheduling, occupy the CPU loading.

3. New interfaces: Scheduled sleep: nxsched_sleep() / nxsched_usleep() / nxsched_msleep() / nxsched_ticksleep()
Strengths:
  a. Does not depend on the signal framework.
  b. Tick-based, without additional computational overhead.

Currently, the Nuttx driver framework extensively uses nxsig_* interfaces. However, the driver does not need to rely on signals or timespec conversion.
Therefore, a new set of APIs is added to reduce dependencies on other modules.

(This PR also aims to make signals optional, further reducing the code size of Nuttx.)

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-10-16 12:46:42 +02:00
yushuailong1
097c594aba video/fb: add FBIOGET_PANINFOCNT ioctl
Add a new ioctl to get the count of paninfo

The framebuffer is usually in high-speed RAM. Getting the paninfo
count can help us get the idle state of the framebuffer so that we
can temporarily use this memory.

Signed-off-by: yushuailong1 <yushuailong1@xiaomi.com>
2025-10-14 17:50:42 +08:00
chao an
10fd309452 sched/signal: Remove shadow definitions to reduce unnecessary API
Reduce unnecessary API definitions:

nxsig_waitinfo() -> nxsig_timedwait()

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-10-14 17:40:18 +08:00
raiden00pl
9daa23d4e4 include/nuttx/sensors: fix reference to non-existent readme
fix reference to non-existent readme and point to the Documentation.

Signed-off-by: raiden00pl <raiden00@railab.me>
2025-10-11 17:07:51 -04:00
raiden00pl
13ab107d67 libc: remove reference to non-existent readme
remove reference to non-existent readme in libc.

Pointing to the documentation page doesn't make sense in this case,
because it doesn't explain the use of `#undef XXX` for this case anyway.

Signed-off-by: raiden00pl <raiden00@railab.me>
2025-10-11 17:07:51 -04:00
Stepan Pressl
4f7fc3dd04 1wire DS2XXX: add 1wire and DS2XXX documentation
Also fix some minor issues in the DS2XXX header file.

Signed-off-by: Stepan Pressl <pressl.stepan@gmail.com>
2025-10-11 07:39:01 -03:00
Jukka Laitinen
2435caa925 drivers/usbdev: Unregister CDCACM by instance number
Add a function to search the cdcacm instance by the devnode
minor number to unregister it

Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
2025-10-11 00:47:02 +08:00