Commit graph

7739 commits

Author SHA1 Message Date
Xiang Xiao
4b8a738141 libc/stream: Add support for lib_scanf
This commit adds support for the `lib_scanf` function, which
is a stream-oriented version of the `scanf` function.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2025-06-20 09:48:39 +08:00
Kerogit
a3f8b55143 drivers/serial/serial: prevent race conditions on 8-bit architectures
Some code paths in drivers/serial/serial.c load head and tail values
of receive and transmit circular buffers with interrupts enabled,
making it possible that the interrupt handler changes the value.
As noted in the code, this is safe as long as the load itself is atomic.

That is not true for 8bit architectures which fetch the 16-bit values
using two load instructions. If interrupt handler runs between those
two instructions and changes the value, the read returns corrupted data.

This patch introduces CONFIG_ARCH_LDST_16BIT_NOT_ATOMIC configuration
option which is automatically selected for AVR architecture. Based
on this option, head and tail values are reduced to 8-bit length
so the read remains atomic.

Patch was tested by building on rv-virt:nsh - disassembly of functions
from serial.c showed no difference which is correct as Risc-V does
not need to protect reads of these values. There should be no impact
for architectures that do not set the new configuration option.

It was also tested by by custom echo application running on AVR128DA28.

Signed-off-by: Kerogit <kr.git@kerogit.eu>
2025-06-19 10:01:24 -03:00
yangao1
c560db04a6 stream/fileoutstream: Add open interface for coredump
Signed-off-by: yangao1 <yangao1@xiaomi.com>
2025-06-17 20:58:13 +08:00
yangao1
47dd21c3c1 stream: Add fileinstream support
This commit introduces a new fileinstream implementation
in the NuttX stream library.

Signed-off-by: yangao1 <yangao1@xiaomi.com>
2025-06-17 20:58:13 +08:00
buxiasen
379f246625 mtdstream: use mtdsostream to support seek
Decrease memory cost, flush should not be called too frequency, for not
bytewrite mtd, will cause not able to write again in same block.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2025-06-17 20:58:13 +08:00
Matteo Golin
4ccc3d4c96 drivers/syslog: Add RFC 5424 protocol support
Initial implementation of RFC 5424 support (syslog protocol). Allows
users to force-format the syslog output in a RFC 5424 compatible way,
making NuttX systems 'originators' that are able to interface with
syslog 'collectors' and 'relays' (useful for logging to syslog servers).

In addition to regular formatting options for syslog output, users can
also add structured data (currently only timeQuality is implemented,
assuming no sync and no timezone is no known). Facilities and severities
now also follow RFC 5424. Support for additional features (like
more sdata elements, msgid, etc.) will need to be built into the syslog
implementation if desired.
2025-06-13 20:26:57 +08:00
Ville Juven
b8e30b54ec fs/vfs: Separate file descriptors from file descriptions
This patch is a rework of the NuttX file descriptor implementation. The
goal is two-fold:

1. Improve POSIX compliance. The old implementation tied file description
to inode only, not the file struct. POSIX however dictates otherwise.
2. Fix a bug with descriptor duplication (dup2() and dup3()). There is
an existing race condition with this POSIX API that currently results
in a kernel side crash.

The crash occurs when a partially open / closed file descriptor is
duplicated. The reason for the crash is that even if the descriptor is
closed, the file might still be in use by the kernel (due to e.g. ongoing
write to file). The open file data is changed by file_dup3() and this
causes a crash in the device / drivers themselves as they lose access to
the inode and private data.

The fix is done by separating struct file into file and file descriptor
structs. The file struct can live on even if the descriptor is closed,
fixing the crash. This also fixes the POSIX issue, as two descriptors
can now point to the same file.

Signed-off-by: Ville Juven <ville.juven@unikie.com>
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-06-12 18:12:42 +08:00
dongjiuzhu1
a12d21e830 fs/file: unify prefix about file_xxx api, like file_open, file_ioctl
old:
fs_getfilep, fs_putfilep, fs_reffilep
new:
file_get, file_put, file_ref

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-06-12 18:12:42 +08:00
dongjiuzhu1
9ca5c1d9c6 fs/file: unify prefix f_ for member locked
update locked to f_locked

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-06-12 18:12:42 +08:00
dongjiuzhu1
3bc3092e6a fs/fs: remove unnecessary FS_REFCOUNT config
Previously, this config was added to ensure that the size of the struct
file remained unchanged, thereby preventing the Flash memory of
resource-constrained MCUs from being unnecessarily increased.

However, we have now refactored the relationship between struct fd and struct file,
reducing their memory footprint in both Flash and RAM.
Consequently, this config can be removed.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-06-12 18:12:42 +08:00
Ville Juven
1e787ea280 nuttx/fs: Reorganize the code for close, dup, et. al.
Currently the code is dumped into one massive file; fs_files. Move the
different logical parts into their own files.

Signed-off-by: Ville Juven <ville.juven@unikie.com>
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-06-12 18:12:42 +08:00
Ville Juven
840ae60b60 nuttx/spinlock: Define empty macro for spin_unlock
So that the same code can be used with and without spinlocks.

Signed-off-by: Ville Juven <ville.juven@unikie.com>
Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
2025-06-11 23:39:21 +08:00
ouyangxiangzhen
19eac98526 sched: Add comments for wd_start_next and work_queue_next.
This commit added comments for newly added APIs wd_start_next and
work_queue_next.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-06-10 11:02:45 -03:00
ouyangxiangzhen
df183b6682 sched/wqueue: Remove the work_queue_period.
For simplicity, better performance and lower memory-overhead, this commit replaced the periodical workqueue APIs with the more expressive work_queue_next. The work_queue_next restarts work based on the last expiration time.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-06-10 11:02:45 -03:00
ouyangxiangzhen
9d1b958524 sched/wdog: Remove the wd_start_period.
For better simplicity, this commit replaced the periodical wdog APIs with the more expressive wd_start_next. The wd_start_next restarts watchdog timer based on the last expiration time.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-06-10 11:02:45 -03:00
buxiasen
0b3cd35360 sched/spinlock: add recursive support(rspinlock_s) for spinlock
For drivers implement those possible recusive, native spinlock
will cause deadlock directly, critial_section is use globally,
will make lock parallel to serial, add API to keep recursive
support but isolate each other.

For race condition, we may get cpuid in stack and then thread moved
to other cpu. So we have to get cpuid with irq disabled.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2025-06-06 09:48:17 +08:00
buxiasen
225d6fb0a7 spinlock: add dummy compatible when CONFIG_SPINLOCK not enabled
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2025-06-06 09:48:17 +08:00
hujun5
907d77a056 spinlock: add spin_lock_irqsave_nopreempt/spin_unlock_irqrestore_nopreempt
reason:
By using these interfaces, the following usage can be replaced.
flags = spin_lock_irqsave(lock);
sched_lock();
.....
spin_unlock_irqrestore(lock, flags);
sched_unlock();

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-06-06 09:48:17 +08:00
George Poulios
67c7a4018a arm64/imx9: Support & configure RGMII-ID on RTL8211F
For the RTL8211F PHY, configuration of RX/TXDLY was missing.
At least on my i.MX93 EVK, this is necessary for transmission
to work (RXDLY defaults to true on the PHY).

This commit brings support for RGMII internal delay configuration
(on or off for both directions) and enables it on the i.MX93 EVK
board. The introduced Kconfig is set to default to 'n', to avoid
breaking the functionality of other, out-of-tree boards based on
i.MX93, running the RTL8211F PHY, or to avoid introducing
unnecessary code on boards running other PHYs.

Configuration of internal delay on other PHYs is not
implemented, and results in a warning (but no error).

Signed-off-by: George Poulios <gpoulios@census-labs.com>
2025-06-05 08:58:24 +02:00
raiden00pl
302ceb701b include: fix Private Types banners
unify Private Types banners according to NuttX coding standard

Signed-off-by: raiden00pl <raiden00@railab.me>
2025-05-28 10:17:15 +08:00
ouyangxiangzhen
947856efe0 sched/wdog: Add max delay tick limitation.
This commit changed the type of the delay ticks to the unsigned, which can reduce the useless branch conditions
Besides, this commit added max delay tick limitation to fix incorrect timing behavior if we delay SCLOCK_MAX in the SMP build.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-05-27 12:10:39 +02:00
ouyangxiangzhen
fce40edb6b sched/wqueue: Add max delay tick limitation.
This commit added max delay tick limitation for the workqueue.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-05-27 12:10:39 +02:00
wangzhi16
35a62b7d5e Revert "Reduce the size of tcb by four bytes."
This reverts commit 893c5e92c2.
2025-05-27 16:30:35 +08:00
dongjiuzhu1
4f57ebce66 fs/poll: remove poll_fdsetup
Allow users to operate poll in the kernel using the file_poll
approach, as file is protected with reference counting,
making it more secure.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-05-26 18:49:45 +08:00
Lars Kruse
3ce85ca54e style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
raiden00pl
3a31da9585 sensors: add support for BME688 sensor
Add support for BME688 sensor based on BME680 implementation.
The BME688 is nearly identical to the BME680, and this implementation
reuses much of the existing BME680 code. However, there are some differences
related to gas measurements that make it impractical to use the same driver
without significantly complicating it. BME688 also supports parallel mode
which isn't yet supported.

Signed-off-by: raiden00pl <raiden00@railab.me>
2025-05-17 12:16:54 +08:00
p-szafonimateusz
fab4f68b6f drivers/usbhost: add xHCI support
add xHCI PCI driver (usbhost).

Signed-off-by: p-szafonimateusz <p-szafonimateusz@xiaomi.com>
2025-05-15 21:58:57 +08:00
p-szafonimateusz
3dc1ac91d6 usbhost: add common usb host waiter and drivers initialization
add common usb host waiter and drivers initialization which is
required for xHCI support

Signed-off-by: p-szafonimateusz <p-szafonimateusz@xiaomi.com>
2025-05-15 21:58:57 +08:00
Lars Kruse
4568110d63 fix misspelled names in locally scoped code
These misspelled words are used in strictly local scopes.
Renaming these variables should not cause any problems.
2025-05-15 10:12:12 +08:00
raiden00pl
5d95d0871f drivers/can: move CAN utils to CAN common files
Move can_bytes2dlc() and can_dlc2bytes() to a common CAN file
that can be shared between socketCAN implementation and CAN
character driver.

This is the first step to simplifying the logic repeated in
many CAN drivers.

Signed-off-by: raiden00pl <raiden00@railab.me>
2025-05-14 10:30:25 -03:00
raiden00pl
486dabdd2d include/nuttx/can.h: remove dependency on CONFIG_NET_CAN
Remove dependency on CONFIG_NET_CAN for socketCAN definitions.

Definitions from this file are also used by arch/sim CAN
implementation, which is based on a host socketCAN interface.

With this change CONFIG_NET and CONFIG_NET_CAN don't need to
be enabled to support CAN character driver on sim.

Signed-off-by: raiden00pl <raiden00@railab.me>
2025-05-14 03:06:12 +08:00
George Poulios
a2a689fee0 drivers/misc/optee: Fix GP API compatibility
Previous implementation was not compatible with GlobalPlatform
API in the following ways:
 - Registered mem IDs would begin from negatives when it should
   have been greater than or equal to 0
 - Register IOCTL would return 0 on success, when it should have
   been returning a file descriptor.
 - Register IOCTL would expect the user-space client to specify
   TEE_SHM_* flags dictating its behaviour when in fact, libteec
   never specifies flags.

This commit fixes all those issues. It uses nuttx/idr.h instead
of a linked list, and it uses `file_allocate` to provide file
descriptors for registered shared memory. Upon close(fd), the
memory is de-registered and freed accordingly. It also updates
the documentation accordingly.

Signed-off-by: George Poulios <gpoulios@census-labs.com>
2025-05-13 10:14:01 +08:00
ouyangxiangzhen
64a7049dec clock: Add clock_delay2abstick.
This commit added a macro function clock_delay2abstick to calculate the
absolute tick after the delay.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-05-12 19:56:29 +08:00
ouyangxiangzhen
2e8583f759 clock: Fix timing error.
This commit resolves a timing error caused by the round-up behavior in clock_time2ticks. In rare cases, this could lead to a two-tick increment within a single tick interval. To fix this, we introduced clock_time2ticks_floor, which guarantees the correct semantics for obtaining current system ticks.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-05-12 19:56:29 +08:00
ouyangxiangzhen
5e543421ab clock: constants change to unsigned.
This commit change the type of the constants to unsigned, avoiding signed integer division.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-05-12 19:56:29 +08:00
ouyangxiangzhen
3622e4830a sched: Correct word spelling mistakes.
This commit fixed serveral word spelling mistakes.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-05-12 19:56:29 +08:00
buxiasen
1de87953e6 mm/gran: add gran_alloc_align API
for arm-v7a, possible region with 4K and need align with 16K.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2025-05-12 15:01:37 +08:00
wangjianyu3
5fc950e608 drivers/sensor: Fix spell errors of uorb.h
../nuttx/tools/checkpatch.sh -c -u -m -g d611304d61a79f581210584813a5b2894b838490..HEAD
Used config files:
    1: .codespellrc
    /home/runner/work/nuttx/nuttx/nuttx/include/nuttx/uorb.h:307: afte ==> after
    /home/runner/work/nuttx/nuttx/nuttx/include/nuttx/uorb.h:405: multipled ==> multiplied
    /home/runner/work/nuttx/nuttx/nuttx/include/nuttx/uorb.h:416: multipled ==> multiplied
    /home/runner/work/nuttx/nuttx/nuttx/include/nuttx/uorb.h:432: provies ==> provides, proves
    /home/runner/work/nuttx/nuttx/nuttx/include/nuttx/uorb.h:1173: subcribers ==> subscribers
    Error: Process completed with exit code 1.

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2025-05-11 20:28:17 +08:00
wangjianyu3
fda251aad0 drivers/sensor: Add timestamp for GNSS data
Add timestamp for GNSS measurements and clock, for matching.

When recovering the combination of `GnssMeasurement` and `GnssClock` into
[GnssData](https://android.googlesource.com/platform/hardware/libhardware/+/
           refs/heads/android14-release/include/hardware/gps.h#1748),
the reason for splitting is that the uORB buffer is not large enough to
accommodate `GnssData`, since different topics cannot guarantee the
same timing when publishing and subscribing data, we need an index to match.

WARNING: A new member "timestamp" of type uint64_t has been added at
the beginning of the struct "sensor_gnss_measurement" and "sensor_gnss_clock".

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2025-05-11 20:28:17 +08:00
Theodore Karatapanis
d278c6cb15 arch/arm64/imx9: Add ROMAPI and AHAB support for i.MX9
This adds support for the i.MX9 ROMAPI, allowing boot in a more
device agnostic and portable manner. The ROMAPI "natively" allows to:
- Query the boot device for information.
- Copy data from the boot device to RAM.

An extra functionality was added to ROMAPI to calculate
offsets of sequential AHAB containers.

The AHAB functionality is built on top of raw ELE primitives and allows to:
- Authenticate a container image.
- Release the authenticated container.

Signed-off-by: Theodore Karatapanis <tkaratapanis@census-labs.com>
2025-05-09 19:21:17 +08:00
George Poulios
a2b8c9d1d8 drivers/misc/optee.c: Add shm registration support
Adds support for SHM_REGISTER IOCTL. Registration can
be requested both against the driver (for automatic cleanup)
and against the secure OS (for sharing).

Introduces also `optee_{msg,free}_alloc()` to allocate
aligned memory for message arguments depending on the
`alignment` specified in the driver's private data. For
alignment greater than word size, memory is allocated on the
heap, otherwise it's allocated on the stack (similar to the
previous implementation but using `alloca()` instead).

Signed-off-by: George Poulios <gpoulios@census-labs.com>
2025-05-09 10:29:26 +08:00
George Poulios
da0586c7e3 drivers/misc/optee.c: Decouple transport from driver
Prepares the ground for introducing new transports to
the OP-TEE driver. "transports" as in alternatives to
RPMsg and local network.

Signed-off-by: George Poulios <gpoulios@census-labs.com>
2025-05-09 10:29:26 +08:00
Jukka Laitinen
156469f158 Clean up the nxmutex library
- Remove the redundant holder, as nxsem now manages hoder TID
- Remove DEBUGASSERTIONS which are managed in nxsem
- Remove the "reset" handling logic, as it is now managed in nxsem
- Inline the simplest functions

Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
2025-05-08 16:00:05 +08:00
Jukka Laitinen
b6f2729730 Integrate nxmutex support fully into nxsem
This puts the mutex support fully inside nxsem, allowing
locking the mutex and setting the holder with single atomic
operation.

This enables fast mutex locking from userspace, avoiding taking
critical_sections, which may be heavy in SMP and cleanup
of nxmutex library in the future.

Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
2025-05-08 16:00:05 +08:00
ouyangxiangzhen
6f72f5481d sched/wqueue: Refactor delayed and periodical workqueue.
This commit refactors the logic of workqueue processing delayed and periodic work, and changes the timer to be set in `work_thread`. The improvements of this change are as follows:
- Fixed the memory reuse problem of the original periodic workqueue implementation.
- By removing the `wdog_s` structure in the `work_s` structure, the memory overhead of each `work_s` structure is reduced by about 30 bytes.
- Set the timer for each workqueue instead of each work, which improves system performance.
- Simplified the workqueue cancel logic.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-05-07 02:02:10 +08:00
ouyangxiangzhen
9dbb9b49c6 sched/wqueue: Change dq to list.
In NuttX, the dq and the list are two different implementations of the double-linked list. Comparing to the dq, the list implementation has less branch conditions such as checking whether the head or tail is NULL. In theory and practice, the list is more friendly to the CPU pipeline. This commit changed the dq to the list in the wqueue implementation.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-05-07 02:02:10 +08:00
ouyangxiangzhen
900b1c19dd wqueue: improve the robustness of the work
struct work_s
{
  union
  {
    struct
    {
      struct dq_entry_s dq;      /* Implements a double linked list */
      clock_t qtime;             /* Time work queued */
    } s;
    struct wdog_s timer;         /* Delay expiry timer */
    struct wdog_period_s ptimer; /* Period expiry timer */
  } u;
  worker_t  worker;              /* Work callback */
  FAR void *arg;                 /* Callback argument */
  FAR struct kwork_wqueue_s *wq; /* Work queue */
};

work_cancel() should determine whether the current work is
in the timer or has already entered the queue.
This judgment is indispensable because the structure is a union.
Whether it is interpreted as a timer or as a dq needs to be determined.

But this judgment seriously depends on the order of struct wdog_s and
struct dq_entry_s, once someone change the order of any, there is a bug.
So we decide remove the union, to improve the robustness.

For the work_s structure size will grow bigger, then we will provide a
another optimization patch

Signed-off-by: ligd <liguiding1@xiaomi.com>
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2025-05-07 02:02:10 +08:00
Michal Lenc
eeb4a0de83 setlogmask: fix setlogmask behavior according to POSIX standard
POSIX states "If the maskpri argument is 0, the current log mask is
not modified." The current implementation in NuttX doesn't
respect this and thus is in a clear violation with a strict POSIX
compliance rule in The Inviolable Principles of NuttX.

This commit therefore changes the behavior to the expected one. Passing
argument 0 doesn't change the current log mask, but just returns the
old one. Completely disabling logging at runtime is thus not possible,
but you may set the highest priority LOG_EMERG only to disable most of
the messages. Default can still be set to no logging with
CONFIG_SYSLOG_DEFAULT_MASK configuration option.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
2025-05-02 16:29:08 +02:00
Tim Hardisty
ed0c18c66c drivers/video/fb.c: Add startup splashscreen option
Adds Kconfig-selected splashscreen options used when the driver is first registered

* Includes a new Python script in ./tools to create RLE bitmap files
* Includes default NS logo btimaps in 320x320, 160x160 and 80x80 resolutions along with their PNG files

Signed-off-by: Tim Hardisty  timh@jti.uk.com>
2025-04-30 06:38:05 -03:00
Lars Kruse
9b3914b740 drivers/analog/mcp47x6: Add support for MCP47X6 DAC series
The MCP47X6 series consists of the following single channel DAC chips:
- MCP4706 (8 bit)
- MCP4716 (10 bit)
- MCP4726 (12 bit)

The driver supports the following configurations:
- gain
- power down
- voltage reference

Persistent configuration storage in the internal EEPROM is not
implemented.
2025-04-29 16:17:44 -03:00