Add USEC2MSEC macro to provide a convenient and consistent interface for
converting microseconds to milliseconds, complementing the existing SEC, USEC,
and NSEC conversion macros and improving code readability.
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
Follow the virtio spec:
For the device-specific configuration space, the driver MUST use 8
bit wide accesses for 8 bit wide fields, 16 bit wide and aligned
accesses for 16 bit wide fields and 32 bit wide and aligned accesses
for 32 and 64 bit wide fields.
For a string in the virtio config space, we should should byte to
byte read operations to read this string, so add a api
virtio_read_config_bytes() for this.
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
This patch adds an AUTOSAR-style CRC library used by E2E functionality.
It introduces multiple CRC variants (CRC8, CRC16, CRC32, CRC64) and the
corresponding public headers and implementation files.
Key changes:
- Public headers: `include/nuttx/crc8.h`, `include/nuttx/crc16.h`,
`include/nuttx/crc32.h`, `include/nuttx/crc64.h` with new APIs for
specific polynomial variants and incremental (part) helpers.
- Implementations added under `libs/libc/misc/` for several polynomials:
- `lib_crc16h1021.c` (CRC-16 CCITT-FALSE)
- `lib_crc16h8005.c`
- `lib_crc32h04c11db7.c`
- `lib_crc32hf4acfb13.c`
- `lib_crc64emac.c`
- `lib_crc8h1d.c`
- `lib_crc8h2f.c`
- Build files updated to include the new sources.
This addition provides low-level CRC primitives required by higher-level
protocols and test suites.
Signed-off-by: yukangzhi <yukangzhi@xiaomi.com>
Implement Linux-compatible TFD_TIMER_CANCEL_ON_SET flag for timerfd to
allow applications to detect discontinuous changes to CLOCK_REALTIME.
Background:
According to Linux timerfd_create(2) man page, when a timerfd is created
with CLOCK_REALTIME and TFD_TIMER_CANCEL_ON_SET flag is specified, the
read() operation should fail with ECANCELED if the real-time clock
undergoes a discontinuous change. This allows applications to detect
and respond to system time changes.
Implementation:
1. Add clock notifier infrastructure (clock_notifier.h/c) to notify
interested parties when system time changes
2. Implement TFD_TIMER_CANCEL_ON_SET flag support in timerfd
3. Register timerfd with clock notifier when flag is set
4. Cancel timer and return ECANCELED when clock change is detected
5. Notify clock changes in:
- clock_settime()
- clock_initialize()
- clock_timekeeping_set_wall_time()
- rpmsg_rtc time synchronization
Changes include:
- New files: include/nuttx/clock_notifier.h, sched/clock/clock_notifier.c
- Modified: fs/vfs/fs_timerfd.c to handle TFD_TIMER_CANCEL_ON_SET
- Modified: clock subsystem to call notifier chain on time changes
- Modified: rpmsg_rtc to notify time changes during sync
Use case example:
Applications using timerfd with absolute time can now detect when
system time is adjusted (e.g., NTP sync, manual time change) and
take appropriate action such as recalculating timeouts or updating
scheduled events.
Reference: https://man7.org/linux/man-pages/man2/timerfd_create.2.html
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
Replace left-shift of 1 by 31 bits with direct hexadecimal constant
to eliminate undefined behavior warning when left-shifting signed values
beyond their bit width on platforms with strict sanitizer checking.
Signed-off-by: hujun5 <hujun5@xiaomi.com>
Fix linker error caused by including spinlock_type.h instead of
spinlock.h in notifier.h header file.
Error message:
undefined reference to 'spin_lock_irqsave_nopreempt'
in .text.clock_changed_notifier_call_chain
Root cause:
The notifier.h header was including <nuttx/spinlock_type.h> which only
provides type definitions, but the inline functions in notifier.h use
spinlock functions like spin_lock_irqsave_nopreempt(). These functions
are defined in <nuttx/spinlock.h>, not in spinlock_type.h.
Solution:
Change the include from <nuttx/spinlock_type.h> to <nuttx/spinlock.h>
to get both the type definitions and the function implementations.
This fixes the undefined reference error when using notifier chains
with spinlock protection.
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
Previously, IRQ bounds checking (irq >= 0 && irq < NR_IRQS) was duplicated
across multiple IRQ subsystem functions before calling IRQ_TO_NDX(). This
led to code duplication and inconsistency.
This patch consolidates all IRQ bounds checking into the IRQ_TO_NDX() macro
itself, which now returns -EINVAL for out-of-bounds IRQ numbers. This approach:
1. Eliminates duplicated bounds checking code
2. Ensures consistent error handling across all IRQ functions
3. Simplifies caller code - just check if IRQ_TO_NDX() returns negative
4. Makes the macro behavior more predictable and self-contained
Changes:
- Modified IRQ_TO_NDX() to check (irq < 0 || irq >= NR_IRQS) and return -EINVAL
- Removed redundant IRQ range checks in irq_attach(), irq_attach_thread(),
irq_attach_wqueue(), and irqchain_detach()
- Simplified error handling to check ndx < 0 after IRQ_TO_NDX() call
This consolidation reduces code size and improves maintainability while
preserving all existing error checking functionality.
Signed-off-by: pangzhen1 <pangzhen1@xiaomi.com>
This patch adds support for managing cryptographic keys using MTD storage.
It enables the persistence of keys across reboots using a software-based key management system.
Includes fixes for compilation warnings and validation logic.
Signed-off-by: makejian <makejian@xiaomi.com>
Export the sched_note_event_ip function as a syscall under
CONFIG_SCHED_INSTRUMENTATION_DUMP. This allows user-space or
other kernel components to trigger event-type logs via the
instrumentation dump mechanism.
Signed-off-by: yukangzhi <yukangzhi@xiaomi.com>
Because enter_critical_section() changes from calling spin_lock() to calling spin_lock_wo_note(), it is necessary to count the busywait time in enter_critical_section() additionally.
Signed-off-by: wangzhi16 <wangzhi16@xiaomi.com>
Add configuration "CONFIG_SCHED_CRITMONITOR_MAXTIME_BUSYWAIT", which can record the busy waiting time to get spinlock or enter critical section.
Signed-off-by: wangzhi16 <wangzhi16@xiaomi.com>
Add NOTE_DUMP_BINARY to the note_type_e enum and implement its handling
in noteram_dump_one. This enables the recording and dumping of binary
logs in hexadecimal format, improving traceability for binary event data.
Signed-off-by: yukangzhi <yukangzhi@xiaomi.com>
Add defensive bounds validation before memory access operations to
prevent out-of-bounds access. This addresses Coverity OVERRUN defect
by ensuring array indices and buffer sizes stay within valid range.
Signed-off-by: hujun5 <hujun5@xiaomi.com>
The hrtimer subsystem is independent of the OS tick mechanism and tickless
mode. It must always be able to reprogram the hardware timer to achieve
nanosecond-level resolution.
A recent update restricted hardware timer reprogramming to tickless mode
only. As a result, hrtimer no longer functions correctly when the scheduler
is running in tick-based mode.
This change removes the incorrect dependency on tickless mode and restores
proper hrtimer operation.
Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
Fix incorrect memory management for asynchronous process callbacks.
Ensure callback memory is self-managed to prevent leaks or use-after-free issues.
Signed-off-by: makejian <makejian@xiaomi.com>
Add support for exporting RSA operations with PKCS#1 v1.5 and PSS padding schemes through the cryptodev interface.
This enables both traditional and modern RSA signature schemes:
- CRK_RSA_PKCS15_SIGN/VERIFY for PKCS#1 v1.5 padding
- CRK_RSA_PSS_SIGN/VERIFY for PSS padding
Signed-off-by: makejian <makejian@xiaomi.com>
Add try-lock variants for rspinlock_t to support non-blocking spinlock
acquisition with optional IRQ save/restore and preemption control.
These variants enable fine-grained synchronization patterns in nested
contexts with maximum nesting depth support (UINT16_MAX).
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
Move rpmsg internal APIs from public header include/nuttx/rpmsg/rpmsg.h
to private header drivers/rpmsg/rpmsg.h. These APIs are only used within
the rpmsg driver implementation and should not be exposed to external
modules.
Moved APIs:
- rpmsg_modify_signals()
- rpmsg_ns_bind() / rpmsg_ns_unbind()
- rpmsg_device_created() / rpmsg_device_destory()
- rpmsg_register() / rpmsg_unregister()
Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
Add trace points to record transitions of g_nx_initstate and to mark
board early/late initialization boundaries. Also add trace marks for
RESET and PANIC to improve boot-time diagnostics and failure analysis.
Add OSINIT_RESET to indicate system is in reset process.
Signed-off-by: yukangzhi <yukangzhi@xiaomi.com>
Add a new getrecvbuf callback to the SPI slave device operations
that allows the slave device to provide a pre-allocated receive
buffer directly to the controller. This enables zero-copy data
transfer by allowing the controller to receive data directly into
the device's buffer instead of copying.
Changes:
- Add SPIS_DEV_GETRECVBUF macro and getrecvbuf callback to
spi_slave_devops_s structure in include/nuttx/spi/slave.h
- Implement getrecvbuf in rpmsg_port_spi_slave driver
- Update getdata to return 0 as it's no longer used for this path
Signed-off-by: liaoao <liaoao@xiaomi.com>
This commit fixes a memory alignment issue in the rpmsg subsystem.
The previous implementation used a flexible array member (rdev[0])
in struct rpmsg_s, but due to automatic 8-byte padding, rpmsg->rdev
could differ from the transport layer's rdev address (e.g.,
rpmsg_virtio->rvdev.rdev), causing potential memory corruption.
Changes:
- Remove rdev[0] flexible array member from struct rpmsg_s
- Add rpmsg_get_rdev_by_rpmsg() inline helper to calculate rdev
address as (rpmsg + 1), ensuring correct pointer arithmetic
- Update all rpmsg->rdev references to use the new helper function
- Fix rpmsg_virtio_notify_wait() to use correct container_of macro
Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
This lock is currently used in three places,
mainly to protect tls->tl_mhead. Among them,
pthread_mutex_add and pthread_mutex_remove involve
writing to tls->tl_mhead, and there is
certainly no conflict within the same thread.
As for pthread_mutex_inconsistent, it involves reading. Currently,
it can only be called when the TCB task corresponding to
this tls exits, and the TCB corresponding to the
tls can no longer continue to run.
It seems that adding the lock serves no real purpose.
Signed-off-by: hujun5 <hujun5@xiaomi.com>
ARM specifies that SysTick RELOAD must be programmed with N-1 to get a period of N CPU cycles.
Adjust the timeout/reload conversions accordingly: subtract 1 when writing RELOAD and add 1 back when converting RELOAD to a timeout/interval.
Also clamp RELOAD to the valid 24-bit range (1..0x00ffffff) for Armv7-M/Armv8-M to avoid invalid values.
Reference: https://developer.arm.com/documentation/dui0646/c/Cortex-M7-Peripherals/System-timer--SysTick/SysTick-Reload-Value-Register
Signed-off-by: Gao Jiawei <gaojiawei@xiaomi.com>
This commit fixed the functional correctness issue in hrtimer_start by
adding HRTIMER_MAX_DELAY fr the HRTIMER_MODE_REL.
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit added hrtimer_gettime API to support the query of the
rest of the delay time of the hrtimer in nanoseconds.
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit move the hrtimer_gettime to clock_systime_nsec to improve
the code reusability.
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
Since the hrtimer->expired is not monotonic, it can not be used as the
version. This commit added the ownership encoding to ensure the
invariant that the cancelled the timer can not modify the hrtimer again.
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
Conditionally enable MMU-specific configuration
checks (CONFIG_MM_PGALLOC, CONFIG_MM_PGSIZE,
address base/size definitions) only when
CONFIG_ARCH_USE_MMU is defined. This allows
addrenv support in MPU-based systems that
don't use MMU paging.
Signed-off-by: zhangyuan29 <zhangyuan29@xiaomi.com>
support set_nonwakeup ops for sensor driver to save power
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
Signed-off-by: likun17 <likun17@xiaomi.com>
Several code comments in the hrtimer subsystem have become outdated
following recent implementation changes. This patch updates them to
accurately describe the current code behavior and algorithms.
Signed-off-by: Chengdong Wang <wangcd91@gmail.com>
Fix macro line continuation formatting in trace.h by consolidating
multi-line macro definitions onto single lines. This eliminates unnecessary
line continuations and improves code readability while maintaining functionality.
Signed-off-by: hujun5 <hujun5@xiaomi.com>