1#include "libxr_system.hpp"
3#include <bits/types/FILE.h>
13#include "libxr_def.hpp"
14#include "libxr_rw.hpp"
15#include "libxr_type.hpp"
16#include "linux_timebase.hpp"
20struct timeval libxr_linux_start_time;
22struct timespec libxr_linux_start_time_spec;
30 static uint8_t read_buff[
static_cast<size_t>(4 * LIBXR_PRINTF_BUFFER_SIZE)];
36 FD_SET(STDIN_FILENO, &rfds);
38 int ret = select(STDIN_FILENO + 1, &rfds, NULL, NULL, NULL);
40 if (ret > 0 && FD_ISSET(STDIN_FILENO, &rfds))
43 if (ioctl(STDIN_FILENO, FIONREAD, &ready) != -1 && ready > 0)
45 auto size = fread(read_buff,
sizeof(
char), ready, stdin);
50 read_port->queue_data_->
PushBatch(read_buff, size);
60 static uint8_t write_buff[
static_cast<size_t>(4 * LIBXR_PRINTF_BUFFER_SIZE)];
64 if (stdo_sem.
Wait() == ErrorCode::OK)
66 auto ans = write_port->queue_info_->Pop(info);
67 if (ans != ErrorCode::OK)
72 ans = write_port->queue_data_->
PopBatch(write_buff, info.data.
size_);
73 if (ans != ErrorCode::OK)
78 auto write_size = fwrite(write_buff,
sizeof(
char), info.data.
size_, stdout);
81 false, write_size == info.data.
size_ ? ErrorCode::OK : ErrorCode::FAILED, info,
93 return ErrorCode::FAILED;
104 return ErrorCode::FAILED;
108 new LibXR::ReadPort(
static_cast<size_t>(4 * LIBXR_PRINTF_BUFFER_SIZE));
112 gettimeofday(&libxr_linux_start_time,
nullptr);
113 UNUSED(clock_gettime(CLOCK_REALTIME, &libxr_linux_start_time_spec));
116 tcgetattr(STDIN_FILENO, &tty);
117 tty.c_lflag &= ~(ICANON | ECHO);
118 tcsetattr(STDIN_FILENO, TCSANOW, &tty);
size_t size_
数据大小(字节)。 The size of the data (in bytes).
LinuxTimebase 类,用于获取 Linux 系统的时间基准。Provides a timebase for Linux systems.
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.
virtual 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
@ 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
WritePort class for handling write operations.
void Finish(bool in_isr, ErrorCode ans, WriteInfoBlock &info, uint32_t size)
更新写入操作的状态。 Updates the status of the write operation.
void PlatformInit()
平台初始化函数 Platform initialization function