1#include "libxr_system.hpp"
11#include "libxr_def.hpp"
12#include "libxr_rw.hpp"
13#include "libxr_type.hpp"
14#include "linux_timebase.hpp"
19struct timespec libxr_linux_start_time_spec;
24static constexpr size_t host_stdio_queue_bytes = 4096;
28 static uint8_t read_buff[host_stdio_queue_bytes];
30 if (!isatty(STDIN_FILENO))
32 XR_LOG_WARN(
"STDIO.read_: stdin is not a TTY, parking thread forever");
43 FD_SET(STDIN_FILENO, &rfds);
45 int ret = select(STDIN_FILENO + 1, &rfds, NULL, NULL, NULL);
47 if (ret > 0 && FD_ISSET(STDIN_FILENO, &rfds))
50 if (ioctl(STDIN_FILENO, FIONREAD, &ready) != -1 && ready > 0)
52 auto size = fread(read_buff,
sizeof(
char), ready, stdin);
67 static uint8_t write_buff[host_stdio_queue_bytes];
85 auto write_size = fwrite(write_buff,
sizeof(
char), info.
data.
size_, stdout);
86 auto fflush_ans = fflush(stdout);
101 auto write_fun = [](
WritePort& port, bool)
112 auto read_fun = [](
ReadPort& port, bool)
122 UNUSED(clock_gettime(CLOCK_MONOTONIC, &libxr_linux_start_time_spec));
125 tcgetattr(STDIN_FILENO, &tty);
126 tty.c_lflag &= ~(ICANON | ECHO);
127 tcsetattr(STDIN_FILENO, TCSANOW, &tty);
size_t size_
数据字节数 / Data size in bytes
Linux 时间基准实现 / Linux timebase implementation.
ErrorCode PushBatch(const Data *data, size_t size)
批量推入数据 / Pushes multiple elements into the queue
ErrorCode PopBatch(Data *data, size_t size)
批量弹出数据 / Pops multiple elements from the queue
ReadPort class for handling read operations.
LockFreeQueue< uint8_t > * queue_data_
RX payload queue. 接收数据字节队列。
void ProcessPendingReads(bool in_isr)
Processes pending reads.
static ReadPort * read_
Read port instance. 读取端口。
static WritePort * write_
Write port instance. 写入端口。
信号量类,实现线程同步机制 Semaphore class implementing thread synchronization
void Post()
释放(增加)信号量 Releases (increments) the semaphore
ErrorCode Wait(uint32_t timeout=UINT32_MAX)
等待(减少)信号量 Waits (decrements) the semaphore
线程管理类,封装 POSIX 线程创建和调度 Thread management class encapsulating POSIX thread creation and scheduling
Priority
线程优先级枚举 Enumeration for thread priorities
@ MEDIUM
中等优先级 Medium priority
void Create(ArgType arg, void(*function)(ArgType arg), const char *name, size_t stack_depth, Thread::Priority priority)
创建新线程 Creates a new thread
static void Sleep(uint32_t milliseconds)
让线程进入休眠状态 Puts the thread to sleep
static uint32_t stack_depth_
线程栈深度 Thread stack depth
static LibXR::Thread::Priority priority_
线程优先级 Thread priority
WritePort class for handling write operations.
void Finish(bool in_isr, ErrorCode ans, WriteInfoBlock &info)
更新写入操作的状态。 Updates the status of the write operation.
LockFreeQueue< uint8_t > * queue_data_
Payload queue for pending write bytes. 挂起写入字节的数据队列。
LockFreeQueue< WriteInfoBlock > * queue_info_
Metadata queue for pending write batches. 挂起写批次的元数据队列。
@ FAILED
操作失败 | Operation failed
@ OK
操作成功 | Operation successful
void PlatformInit(uint32_t timer_pri=2, uint32_t timer_stack_depth=65536)
平台初始化函数 Platform initialization function
ConstRawData data
Data buffer. 数据缓冲区。