This commit adds comprehensive signal notification support to the capture
driver, enabling applications to be asynchronously notified when capture
edge events occur on any channel, rather than having to poll for events.
Background:
The capture driver is used to measure frequency and duty cycle of external
signals by detecting edges (rising/falling). Previously, applications could
only retrieve captured values through periodic polling via CAPIOC_GETDUTY
and CAPIOC_GETFREQ ioctl commands, which is inefficient for event-driven
applications.
Problem:
Without event notification, applications must:
- Continuously poll the capture device to check for new events
- Waste CPU cycles in polling loops
- Experience higher latency in responding to capture events
- Cannot efficiently handle multiple capture channels simultaneously
Solution:
This commit adds a signal-based notification mechanism that allows
applications to register callbacks for specific capture channels and
edge types (rising, falling, or both). When the hardware detects the
configured edge, a signal is sent to the registered task.
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
reduce the execution consumption of irrelevant code
testing the TX rates of TCP and UDP based on the Infineon board can
increase them by 13%.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
when traversing g_netdevices, it is necessary to ensure that they are
not modified during the traversal.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
two rmutexes can be passed in, and later the wait scenarios that require
break the conn and netdev locks will be replaced.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
dup2 and setsockopt can use the lock in conn to protect resources,
the lock in accept is originally used to protect the connection status.
however, only the send, recv, netpoll, and connect processes will
check this flag. only when the interface returns will the corresponding
conn structure be exposed to the caller, and then the above operations
can be performed. Therefore, this net_lock is not necessary.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
The items is not used in up_flush_dcache, and we should use it in
function cache_invalidate_dcache_items.
Signed-off-by: rongyichang <rongyichang@xiaommi.com>
Since the task and group structures are no longer allocated in the same space, the memory for group is allocated in the group_allocate() function, and no further allocation is needed during the task allocation process.
Signed-off-by: wangzhi16 <wangzhi16@xiaomi.com>
This documentation helps users understand when and how to use IO expander
pins for implementing additional I2C buses in their applications.
Related commit: 06099d492e (drivers/i2c: Add IO expander-based I2C bit-bang)
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit adds a new lower-half driver implementation for I2C bit-bang
that uses IO expander pins as the GPIO backend, enabling I2C bit-bang
functionality on systems where direct GPIO access is not available or
when I2C needs to be implemented using IO expander pins.
Background:
The existing I2C bit-bang driver (i2c_bitbang.c) provides a generic
upper-half implementation that requires a platform-specific lower-half
to control the SDA and SCL GPIO lines. Previously, each platform had to
implement its own lower-half using direct GPIO access.
Usage Example:
FAR struct ioexpander_dev_s *ioe = /* get IO expander */;
FAR struct i2c_master_s *i2c;
/* Initialize I2C bit-bang using IO expander pins 10 (SCL) and 11 (SDA) */
i2c = i2c_bitbang_ioexpander_initialize(ioe, 10, 11, 0);
if (i2c)
{
/* Use i2c master device normally */
}
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
Issue:
When using a stack-allocated file structure, the sequence:
1. file_open() initializes the stack file structure
2. file_mmap() creates memory mapping and increments reference count
3. file_munmap() decrements reference count and may free the file structure
4. file_close() attempts to close already freed structure → crash
Root cause:
The memory mapping operations (fs_reffilep/fs_putfilep) manage reference counts
independently and can free the stack-allocated file structure prematurely.
Solution:
- Add reference count protection during file_open() for stack-allocated files
- Clear reference count appropriately during file_close()
- This ensures the file structure remains valid throughout its lifetime
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
for output to avoid log disorder.
If no newline character is found, and the buffer is full, forced output
is required; if the buffer is not full, output is performed according to
the newline character to prevent log disorder.
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This reverts commit 696a94c8055dc59933457e8ce5c3c91dbecab980
first, when continuous ping from tester to vela, if ignore arp expire when ping response use arp_out to build L2 layer, this cause TC13 testing arp entry expire feature failed. second, the patch of support queue iob when arp_out failed can fix this bug.
Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
arp_out will replace the dev->d_iob to arp request if the iob destination
address is not exist in arp table, this mechanism cause this iob lost
result in first received ping no response or first synack retransmit.
to fix this bug, we queue the iob if arp_out failed, allocate a new
iob to send arp request, after the arp request completed, then we retry
send the queue iob packet.
Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
Improve the behavior of the ARP table so that the manually configured
ARP table has the highest priority, can only be manually modified to
other values, otherwise will never change again, and will not time out.
The modified behavior is consistent with that of Linux.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
When a thread is terminated via pthread_exit() while blocked in epoll_wait(),
the file reference taken at the beginning of epoll_wait() is not properly
released, leading to resource leaks.
Problem scenario found during libuv test:
1. Echo server thread is blocked in epoll_wait()
2. Main task sends pthread_kill signal to the server thread
3. Signal handler calls pthread_exit() to terminate the thread
4. epoll_wait() is interrupted before reaching the file_put() call
5. The epoll fd reference count remains elevated
6. epoll_do_close() is never called, leaving fds in internal queues
7. File descriptors leak
Solution:
Register a TLS (Thread Local Storage) cleanup handler using tls_cleanup_push()
at the beginning of epoll_wait() blocking section. This ensures that if the
thread exits abnormally (via pthread_exit, pthread_cancel, etc.), the cleanup
handler (epoll_cleanup) will be called automatically to release the file
reference via file_put().
The cleanup handler is properly paired with tls_cleanup_pop() when epoll_wait()
completes normally, ensuring the handler is only invoked on abnormal exit.
This fix is applied to both epoll_wait() code paths (with and without extended
mode) to ensure consistent behavior.
Impact:
- Prevents epoll fd reference count leaks on thread cancellation
- Ensures proper cleanup even when epoll_wait() is interrupted by pthread_exit
- Critical for multi-threaded applications using signals and thread termination
- Works together with previous fix for teardown/oneshot list cleanup
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
When an epoll fd is closed, the file descriptors in the teardown and
oneshot lists were not being properly dereferenced, leading to fd leaks.
This fix ensures that all fds in the teardown and oneshot lists are
properly released via file_put() during epoll_do_close(), matching the
behavior for fds in the setup list.
Impact:
- Prevents fd leaks when epoll fd is closed
- Ensures proper cleanup of all tracked file descriptors
- Critical for applications using EPOLLONESHOT or fd removal operations
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
00086373 00000634 T __aeabi_dsub
00086373 00000634 T __subdf3
00087841 00000724 T __udivmoddi4
and other small symbol, save total flash size 3K
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This moves mtd.rst from special/ directory to its own special/mtd
subdirectory and adds pages for supported devices (NOR/NAND flashes and
EEPROMS) with some basic configuration and initialization description.
Signed-off-by: Michal Lenc <michallenc@seznam.cz>
OpenAMP already change virtqueue_get_available_buffer() to
virtqueue_get_first_avail_buffer(), so update them
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
new virtio_alloc_buf() return int type, so add virtio_malloc_buf()
for the convenience of use.
And replace all virtio_alloc_buf() to virtio_malloc_buf() in NuttX.
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
and remove somes libmetal and openamp patches that already merged
in the OpenAMP and Libmetal community.
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
1. In cfi_write_unalign(): Add additional check to ensure nbytes is
at least bankwidth size before skipping unaligned start handling.
This prevents incorrect behavior when writing small amounts of
data that are less than bankwidth.
2. In cfi_write(): Align down the write size to bankwidth boundary
when the remaining nbytes is less than the buffer write size.
This ensures the buffer write operation always works with properly
aligned data size, preventing write failures.))
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
Bug Description:
The original code always used conn->pollinfo[0] (the first element) to store
new poll setup context, regardless of whether that slot was already in use.
This caused multiple poll operations on the same CAN socket to overwrite each
other's context, leading to:
- Lost poll waiters when multiple threads poll the same socket
- Memory corruption in pollfd structures
- Undefined behavior when poll_teardown tries to clean up
Root Cause:
The code directly assigned `info = conn->pollinfo` without checking if the
slot was available, effectively always using pollinfo[0]. When a second
thread called poll() on the same socket, it would overwrite the first
thread's poll context.
Solution:
1. Initialize info to NULL instead of conn->pollinfo
2. Before setting up poll, iterate through all CONFIG_NET_CAN_NPOLLWAITERS
slots to find the first free slot (where fds == NULL)
3. Return -EBUSY if no free slots are available
4. During teardown, properly mark the slot as free by setting fds = NULL
Additional Changes:
- Added CONFIG_NET_CAN_NPOLLWAITERS Kconfig option (default 4) to make the
maximum number of concurrent poll waiters configurable
- Changed hardcoded array size from 4 to CONFIG_NET_CAN_NPOLLWAITERS
- Fixed lock ordering in teardown to ensure fds is cleared before unlock
Impact:
- Enables multiple threads to safely poll the same CAN socket concurrently
- Prevents poll context corruption in multi-threaded applications
- Provides proper resource management with -EBUSY when all slots are full
- Makes the number of supported concurrent pollers configurable per use case
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit removes unnecessary file duplication and memory allocation when
passing file descriptors through Unix domain sockets, leveraging the new
filep reference counting framework.
Background:
With the new filep framework, file structures (filep) can be safely shared
across processes using reference counting. When passing file descriptors
through SCM_RIGHTS control messages on local sockets, the previous
implementation unnecessarily duplicated the entire file structure.
Changes:
1. In local_sendctl() (sender side):
- Removed allocation of filep2 structure (kmm_zalloc)
- Removed file_dup2() call that copied the file structure
- Now directly stores the original filep with its reference count
- Eliminates memory allocation overhead and potential failure points
2. In local_recvctl() (receiver side):
- Changed from file_close() + kmm_free() to file_put()
- file_put() properly decrements reference count and handles cleanup
- Consistent with the new filep reference counting model
3. In local_freectl() (cleanup on error):
- Changed from file_close() + kmm_free() to file_put()
- Ensures proper reference count management during error paths
Technical Details:
The new filep framework ensures that:
- Multiple file descriptors across different processes can reference the
same underlying filep structure safely
- Reference counting (via file_get/file_put) manages lifetime correctly
- The underlying file object is only released when all references are gone
This change is safe because file_dup() in the receiver already calls
file_get() internally to increment the reference count for the new fd,
so the filep remains valid after the sender calls file_put().
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
The 'created' flag values were incorrectly inverted in file_mq_vopen():
1. When opening an existing message queue (inode_find succeeds):
- Before: incorrectly set *created = 1 (indicating new creation)
- After: correctly set *created = 0 (indicating existing queue)
2. When creating a new message queue (inode_find fails):
- Before: incorrectly set *created = 0 (indicating existing queue)
- After: correctly set *created = 1 (indicating new creation)
This bug could lead to incorrect resource management and cleanup behavior
in the calling function nxmq_vopen() when file_allocate() returns an error,
as it relies on the 'created' flag to determine whether the message queue
was newly created and needs to be cleaned up.
Impact:
- Resource leak when opening existing queues that should not be released
- Missing cleanup when creating new queues that should be released on error
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
Shmem region lives in RAM and should not be load in FLASH.
This fixes the issue with wrong binary size when build AMP
configurations with RPTUN enabled. Before this change shmem
region was exported by objcopy to binary file which caused
the bin size to be huge and impossible to flash.
Signed-off-by: raiden00pl <raiden00@railab.me>