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>
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>
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>
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>
using Desired frequency offset from nominal frequency in
parts per billion(ppb) to adjust frequency
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This patch implements clock_adjtime() with CLOCKFD support, enabling
precise time and frequency adjustments for PTP clocks through the
standard POSIX clock API.
Key changes include:
1. New clock_adjtime() system call:
- Added sched/clock/clock_adjtime.c implementation
- Provides POSIX-compliant time adjustment interface
- Supports both standard clocks and CLOCKFD-based dynamic clocks
- Added CONFIG_CLOCK_ADJTIME Kconfig option
2. CLOCKFD support in clock_adjtime():
- Detects CLOCKFD-encoded clockids via CLOCKFD_TO_FD() check
- Extracts file descriptor and validates through fs_getfilep()
- Issues PTP_CLOCK_ADJTIME ioctl to underlying PTP clock device
- Returns clock status and adjustment results via struct timex
3. Enhanced struct timex support:
- Extended include/sys/timex.h with additional ADJ_* flags
- Added ADJ_OFFSET, ADJ_FREQUENCY, ADJ_MAXERROR, ADJ_ESTERROR
- Added ADJ_STATUS, ADJ_TIMECONST, ADJ_TAI, ADJ_SETOFFSET
- Added ADJ_MICRO, ADJ_NANO for time unit selection
- Added STA_* status flags for clock state reporting
4. Clock operations supported:
- ADJ_SETOFFSET: Apply time offset adjustment
- ADJ_FREQUENCY: Adjust clock frequency (PPM)
- ADJ_MAXERROR: Set maximum error estimate
- ADJ_ESTERROR: Set estimated error
- ADJ_STATUS: Modify clock status bits
- ADJ_NANO: Use nanosecond resolution
- ADJ_SETOFFSET: Set absolute time offset
5. API declarations:
- Added clock_adjtime() prototype in include/nuttx/clock.h
- Enabled by CONFIG_CLOCK_ADJTIME configuration
- Compatible with Linux clock_adjtime() interface
Usage example:
int fd = open("/dev/ptp0", O_RDWR);
struct timex tx = {0};
tx.modes = ADJ_FREQUENCY;
tx.freq = 10000000; /* Adjust frequency by 10 PPM */
clock_adjtime(CLOCKFD(fd), &tx);
close(fd);
This completes the PTP clock framework's POSIX clock API integration,
providing comprehensive time control capabilities for precision timing
applications including PTP synchronization daemons (ptp4l, timemaster).
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This patch implements POSIX-compliant CLOCKFD support, enabling user
applications to access dynamic PTP clocks through file descriptors
combined with clock_gettime() and clock_settime() system calls.
Key changes include:
1. CLOCKFD macro support:
- Added CLOCKFD() macro in include/nuttx/clock.h
- Allows encoding file descriptor into clockid_t: CLOCKFD(fd)
- Enables accessing PTP clocks via: clock_gettime(CLOCKFD(fd), &ts)
2. clock_gettime() enhancements:
- Modified sched/clock/clock_gettime.c to detect CLOCKFD clockids
- Extracts file descriptor from clockid using CLOCKFD_TO_FD()
- Validates file descriptor and calls file_ioctl() with PTP_CLOCK_GETTIME
- Falls back to standard clock handling for non-CLOCKFD clockids
3. clock_settime() enhancements:
- Modified sched/clock/clock_settime.c to support CLOCKFD clockids
- Extracts file descriptor and validates accessibility
- Issues PTP_CLOCK_SETTIME ioctl to underlying PTP clock device
- Maintains backward compatibility with standard POSIX clocks
4. File descriptor validation:
- Checks file descriptor validity using fs_getfilep()
- Ensures proper reference counting with fs_putfilep()
- Returns appropriate error codes (EINVAL, EBADF) on failures
5. Integration with PTP clock framework:
- Seamlessly integrates with PTP clock driver's ioctl interface
- Enables standard POSIX clock API usage for dynamic PTP clocks
- No changes required to existing applications using standard clocks
Usage example:
int fd = open("/dev/ptp0", O_RDONLY);
struct timespec ts;
clock_gettime(CLOCKFD(fd), &ts); /* Get PTP clock time */
clock_settime(CLOCKFD(fd), &ts); /* Set PTP clock time */
close(fd);
This implementation follows the Linux kernel's PTP clock model, providing
a familiar interface for developers working with PTP hardware.
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This patch adds a dummy PTP clock driver implementation that provides
a software-based PTP clock for testing and development purposes.
Key changes include:
1. Dummy PTP clock driver implementation:
- Added drivers/timers/ptp_clock_dummy.c
- Provides software-based PTP clock using system monotonic clock
- Implements all required lower-half driver operations
2. Lower-half driver operations:
- adjfine: Frequency adjustment (stores adjustment value)
- adjtime: Time offset adjustment (applies delta to base time)
- gettime: Returns current PTP clock time
- settime: Sets PTP clock time
- getcaps: Reports clock capabilities (1 billion PPB max adjustment)
- getcrosststamp: Provides system/device cross-timestamp
3. Driver initialization:
- Added ptp_clock_dummy_init() in drivers/drivers_initialize.c
- Auto-registration under CONFIG_PTP_CLOCK_DUMMY configuration
- Creates /dev/ptp0 character device node
4. Build system integration:
- Added CONFIG_PTP_CLOCK_DUMMY Kconfig option (depends on PTP_CLOCK)
- Updated CMakeLists.txt and Make.defs
- Added include/nuttx/timers/ptp_clock_dummy.h header
5. Implementation details:
- Uses clock_gettime(CLOCK_MONOTONIC) as time base
- Tracks time offset and frequency adjustment internally
- Suitable for testing PTP clock applications without hardware
This dummy driver enables development and testing of PTP clock applications
on platforms without dedicated PTP hardware support.
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This patch introduces the foundational PTP (Precision Time Protocol) clock
driver framework for NuttX, enabling precise time synchronization support
based on IEEE 1588 standard.
Key changes include:
1. New PTP clock driver infrastructure:
- Added drivers/timers/ptp_clock.c implementing upper-half driver
- Created include/nuttx/timers/ptp_clock.h with PTP clock interfaces
- Implemented upper/lower half driver architecture for hardware abstraction
2. Core functionality:
- Clock time get/set operations (gettime, settime)
- Frequency adjustment support (adjtime, adjfine)
- Phase adjustment capabilities
- System-device cross-timestamping for precise synchronization
3. IOCTL commands:
- PTP_CLOCK_SETTIME/GETTIME for time manipulation
- PTP_CLOCK_GETRES for resolution queries
- PTP_CLOCK_ADJTIME for time adjustment
- PTP_CLOCK_GETCAPS for capability queries
- PTP_SYS_OFFSET* for system offset measurements
4. Supporting structures:
- struct ptp_lowerhalf_s: lower-half driver interface
- struct ptp_clock_caps: clock capabilities descriptor
- struct ptp_sys_offset: system time offset measurement
- Added timex structures in include/sys/timex.h for ADJ_* operations
5. Build system integration:
- Added CONFIG_PTP_CLOCK Kconfig option
- Updated CMakeLists.txt and Make.defs
- Added PTPCLK debug macros in include/debug.h
This framework provides the base for PTP clock implementations, allowing
hardware-specific drivers to register and provide precise time services
through a standardized interface.
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
avoid packet processing delays caused by task switching,
to support those applications that are extremely time-sensitive.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
UDP and PKT will hold the dev lock and conn lock when calling back the
protocol stack from the network dirver. At this time, if the poll_notify
notifies usrsock_server and executes poll_teardown, a conn double lock
will appear. so we changed the lock to a recursive lock
sched_dumpstack
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/Libs/libc/sched/sched_dumpstack.c:71
__assert
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/libs/libc/assert/lib_assert.c:49
nxsem_wait_slow
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/sched/semaphore/sem_wait.c:102 (discriminator 1)
nxmutex_lock
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/include/nuttx/mutex.h:514
udp_pollteardown
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/net/udp/udp_netpoll.c:278
usrsock_rpmsg_poll_setup
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/drivers/usrsock/usrsock_rpmsg_server.c:1232
usrsock_rpmsg_poll_cb
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/drivers/usrsock/usrsock_rpmsg_server.c:1299
poll_notify
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/fs/vfs/fs_poll.c:296
udp_poll_eventhandler
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/net/udp/udp_netpoll.c:105
devif_conn_event
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/net/devif/devif_callback.c:481
udp_callback
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/net/udp/udp_callback.c:324
udp_input_conn
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/net/udp/udp_input.c:150
ipv4_in
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/net/devif/ipv4_input.c:425
ipv4_input
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/net/devif/ipv4_input.c:533
tun_net_receive_tun
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/drivers/net/tun.c:574
tun_net_receive_tun
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/drivers/net/tun.c:574
file_writev_compat
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/fs/vfs/fs_write.c:89
rpmsgdev_write_handler
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/drivers/misc/rpmsgdev_server.c:354
rpmsg_virtio_process_rx_buffer
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/drivers/rpmsg/rpmsg_virtio.c:256
rpmsg_virtio_rx_worker
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/drivers/rpmsg/rpmsg_virtio.c:291
work_dispatch
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/sched/wqueue/kwork_thread.c:233
work_thread
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/sched/wqueue/kwork_thread.c:293
nxtask_start
/home/work/ssd1/workspace/MiRTOS-062-dev-system-CI/nuttx/sched/task/task_start.c:99
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
CLOSE-WAIT - represents waiting for a connection termination request
from the local user.
TCP A TCP B
1. ESTABLISHED ESTABLISHED
2. (Close)
FIN-WAIT-1 --> <SEQ=100><ACK=300><CTL=FIN,ACK> --> CLOSE-WAIT
3. FIN-WAIT-2 <-- <SEQ=300><ACK=101><CTL=ACK> <-- CLOSE-WAIT
4. (Close)
TIME-WAIT <-- <SEQ=300><ACK=101><CTL=FIN,ACK> <-- LAST-ACK
5. TIME-WAIT --> <SEQ=101><ACK=301><CTL=ACK> --> CLOSED
6. (2 MSL)
CLOSED
in the current state, we can continue to send data until the user
calls shutdown or close, then directly enter the TCP_LAST_ACK state
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
According to the feedback from SPDX community we should use
LicenseRef-NuttX-PublicDomain because NuttX-PublicDomain
is not a valid SPDX id, so it will fail tests for SPDX spec compliance.
Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
This interface needs to be called in the libc library, but the interface is implemented in the kernel, so this interface needs to be exposed
Signed-off-by: zhangshuai39 <zhangshuai39@xiaomi.com>
To avoid memory waste, can add support for using an independent iob buffer
The IP protocol often configures CONFIG_IOB_BUFSIZE to be relatively large,
such as 512, for higher throughput. However, the buffer required by CAN is
fixed at a length of 16 or 64. If the system's IOB is directly used,
a lot of memory will be wasted.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This interface allows different protocol modules to use their own unique IOB
buffer sources and allocation strategies without interfering with each other.
Representative examples are the IP protocol and the CAN protocol. The IP
protocol generally transmits packets of varying lengths and requires
relatively high peak throughput. In this case, to ensure higher performance,
IOB_BUFSIZE is often configured to be relatively large, such as greater than
500. The CAN protocol generally transmits short packets of fixed length.
In this case, to improve memory utilization, IOB_BUFSIZE is often configured
to be relatively small, such as 16 or 64. To optimize the memory utilization
when the IP protocol and the CAN protocol share the same core,
this interface was added.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
Some third-party network libraries use PACKET_ADD_MEMBERSHIP to add MAC
addresses to devices, and this patch can add support for this.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This commit reduced 1 write operation for wdog deleting and decoupled
the WDOG_ISACTIVE with the list implementation.
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
The value returned by sizeof(struct note_start_s) is larger
than the actual memory footprint of struct note_start_s.
This causes the length calculated in sched_note_start to be larger
than the actual memory size,which further leads to out-of-bounds reads in note_common.
Signed-off-by: guohao15 <guohao15@xiaomi.com>
Since the adafruit-kb2040:smp do not support the `atomic_init`, we have
to remove the function.
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
The optimization reduces one judgment in read operations, improving write performance by 3% and read performance by 10%.
Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit implemented seqlock for non-SMP platforms, which achieves
1.62x performance improvement.
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit improved the seqlock performance on non-SMP and SMP
platforms by 31.7% on average (83Mops -> 106Mops, tested on qemu-intel64/KVM).
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit provided a better implementation of the seqlock, which
ensure the functional correctness and provide better performance.
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit removed unnecessary memory barriers of the seqlock
implementation, since they may block the CPU pipeline and lead to
performance degradation.
Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>