34 m_device(
"NOT_EXIST"),
37 m_quitReadThread(false) {}
47 this->m_allocationSize = allocationSize;
49 this->m_device = device;
57 fd =
::open(device, O_RDWR | O_NOCTTY);
71 stat = tcgetattr(fd, &cfg);
98 stat = tcsetattr(fd, TCSANOW, &cfg);
111 stat = tcgetattr(fd, &t);
121 t.c_cflag |= CRTSCTS;
123 stat = tcsetattr(fd, TCSANOW, &t);
153 #if defined TGT_OS_TYPE_LINUX 161 relayRate = B1000000;
164 relayRate = B1152000;
167 relayRate = B1500000;
170 relayRate = B2000000;
174 relayRate = B2500000;
179 relayRate = B3000000;
184 relayRate = B3500000;
189 relayRate = B4000000;
194 FW_ASSERT(0, static_cast<FwAssertArgType>(baud));
198 struct termios newtio;
200 stat = tcgetattr(fd, &newtio);
224 newtio.c_cflag |= CS8 | CLOCAL | CREAD;
228 newtio.c_cflag |= (PARENB | PARODD);
231 newtio.c_cflag |= PARENB;
234 newtio.c_cflag &=
static_cast<unsigned int>(~PARENB);
242 stat = cfsetispeed(&newtio, static_cast<speed_t>(relayRate));
250 stat = cfsetospeed(&newtio, static_cast<speed_t>(relayRate));
265 newtio.c_iflag = INPCK;
268 (void)tcflush(fd, TCIFLUSH);
271 stat = tcsetattr(fd, TCSANOW, &newtio);
290 if (this->m_fd != -1) {
291 (void)close(this->m_fd);
299 void LinuxUartDriver ::run_handler(
FwIndexType portNum, U32 context) {
306 if (this->m_fd == -1 || serBuffer.
getData() ==
nullptr || serBuffer.
getSize() == 0) {
309 unsigned char* data = serBuffer.
getData();
311 size_t xferSize =
static_cast<size_t>(serBuffer.
getSize());
313 ssize_t stat = ::write(this->m_fd, data, xferSize);
315 if (-1 == stat || static_cast<size_t>(stat) != xferSize) {
320 this->m_bytesSent +=
static_cast<FwSizeType>(stat);
330 void LinuxUartDriver ::serialReadTaskEntry(
void* ptr) {
334 while (!comp->m_quitReadThread) {
335 Fw::Buffer buff = comp->allocate_out(0, comp->m_allocationSize);
338 if (buff.
getData() ==
nullptr) {
340 comp->log_WARNING_HI_NoBuffers(_arg);
342 comp->recv_out(0, buff, status);
353 while ((stat == 0) && !comp->m_quitReadThread) {
354 stat =
static_cast<int>(::read(comp->m_fd, buff.
getData(),
static_cast<size_t>(buff.
getSize())));
363 comp->log_WARNING_HI_ReadError(_arg, stat);
365 }
else if (stat > 0) {
366 buff.
setSize(static_cast<U32>(stat));
368 comp->m_bytesReceived +=
static_cast<FwSizeType>(stat);
373 comp->recv_out(0, buff, status);
381 Os::Task::Arguments arguments(task, serialReadTaskEntry,
this, priority, stackSize, cpuAffinity);
387 this->m_quitReadThread =
true;
391 return m_readTask.
join();
static Status delay(Fw::TimeInterval interval)
delay the current task
PlatformSizeType FwSizeType
void setSize(FwSizeType size)
void tlmWrite_BytesRecv(FwSizeType arg, Fw::Time _tlmTime=Fw::Time()) const
Status start(const Arguments &arguments) override
start the task
Error occurred, retrying may succeed.
Auto-generated base for LinuxUartDriver component.
void log_WARNING_HI_WriteError(const Fw::StringBase &device, I32 error)
void start(FwTaskPriorityType priority=Os::Task::TASK_PRIORITY_DEFAULT, Os::Task::ParamType stackSize=Os::Task::TASK_DEFAULT, Os::Task::ParamType cpuAffinity=Os::Task::TASK_DEFAULT)
void deallocate_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port deallocate.
bool open(const char *const device, UartBaudRate baud, UartFlowControl fc, UartParity parity, FwSizeType allocationSize)
Status returned by the send call.
message sent/received okay
Status join() override
block until the task has ended
Operation worked as expected.
void quitReadThread()
Quit thread.
void log_WARNING_HI_OpenError(const Fw::StringBase &device, I32 error, const Fw::StringBase &name) const
void log_ACTIVITY_HI_PortOpened(const Fw::StringBase &device) const
PlatformTaskPriorityType FwTaskPriorityType
The type of task priorities used.
FwSizeType ParamType
backwards-compatible parameter type
LinuxUartDriver(const char *const compName)
FwSizeType getSize() const
UartBaudRate
Configure UART parameters.
PlatformIndexType FwIndexType
#define FW_ASSERT_NO_OVERFLOW(value, T)
C++ header for working with basic fprime types.
void ready_out(FwIndexType portNum)
Invoke output port ready.
bool isConnected_ready_OutputPort(FwIndexType portNum)
void tlmWrite_BytesSent(FwSizeType arg, Fw::Time _tlmTime=Fw::Time()) const
Os::Task::Status join()
Join thread.