40 PlatformIntType fd = -1;
41 PlatformIntType stat = -1;
42 this->m_allocationSize = allocationSize;
44 this->m_device = device;
53 fd =
::open(device, O_RDWR | O_NOCTTY);
67 stat = tcgetattr(fd, &cfg);
94 stat = tcsetattr(fd, TCSANOW, &cfg);
107 stat = tcgetattr(fd, &t);
117 t.c_cflag |= CRTSCTS;
119 stat = tcsetattr(fd, TCSANOW, &t);
129 PlatformIntType relayRate = B0;
149 #if defined TGT_OS_TYPE_LINUX 157 relayRate = B1000000;
160 relayRate = B1152000;
163 relayRate = B1500000;
166 relayRate = B2000000;
170 relayRate = B2500000;
175 relayRate = B3000000;
180 relayRate = B3500000;
185 relayRate = B4000000;
190 FW_ASSERT(0, static_cast<FwAssertArgType>(baud));
194 struct termios newtio;
196 stat = tcgetattr(fd, &newtio);
220 newtio.c_cflag |= CS8 | CLOCAL | CREAD;
224 newtio.c_cflag |= (PARENB | PARODD);
227 newtio.c_cflag |= PARENB;
230 newtio.c_cflag &=
static_cast<unsigned int>(~PARENB);
238 stat = cfsetispeed(&newtio, static_cast<speed_t>(relayRate));
246 stat = cfsetospeed(&newtio, static_cast<speed_t>(relayRate));
261 newtio.c_iflag = INPCK;
264 (void)tcflush(fd, TCIFLUSH);
267 stat = tcsetattr(fd, TCSANOW, &newtio);
286 if (this->m_fd != -1) {
287 (void)close(this->m_fd);
297 if (this->m_fd == -1 || serBuffer.
getData() ==
nullptr || serBuffer.
getSize() == 0) {
300 unsigned char *data = serBuffer.
getData();
301 FW_ASSERT(static_cast<size_t>(serBuffer.
getSize()) <= std::numeric_limits<size_t>::max(),
303 size_t xferSize =
static_cast<size_t>(serBuffer.
getSize());
305 ssize_t stat = ::write(this->m_fd, data, xferSize);
307 if (-1 == stat || static_cast<size_t>(stat) != xferSize) {
317 void LinuxUartDriver ::serialReadTaskEntry(
void* ptr) {
321 while (!comp->m_quitReadThread) {
322 Fw::Buffer buff = comp->allocate_out(0,comp->m_allocationSize);
325 if (buff.
getData() ==
nullptr) {
327 comp->log_WARNING_HI_NoBuffers(_arg);
329 comp->recv_out(0, buff, status);
339 while ((stat == 0) && !comp->m_quitReadThread) {
340 stat =
static_cast<int>(::read(comp->m_fd, buff.
getData(), buff.
getSize()));
349 comp->log_WARNING_HI_ReadError(_arg, stat);
351 }
else if (stat > 0) {
352 buff.
setSize(static_cast<U32>(stat));
357 comp->recv_out(0, buff, status);
363 Os::Task::Arguments arguments(task, serialReadTaskEntry,
this, priority, stackSize, cpuAffinity);
369 this->m_quitReadThread =
true;
373 return m_readTask.
join();
static Status delay(Fw::TimeInterval interval)
delay the current task
void setSize(SizeType size)
Status start(const Arguments &arguments) override
start the task
Error occurred, retrying may succeed.
Auto-generated base for LinuxUartDriver component.
void dataReturnOut_out(FwIndexType portNum, Fw::Buffer &buffer, const Drv::ByteStreamStatus &status)
Invoke output port dataReturnOut.
void log_WARNING_HI_WriteError(const Fw::StringBase &device, I32 error)
void start(Os::Task::ParamType priority=Os::Task::TASK_DEFAULT, Os::Task::ParamType stackSize=Os::Task::TASK_DEFAULT, Os::Task::ParamType cpuAffinity=Os::Task::TASK_DEFAULT)
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
FwSizeType ParamType
backwards-compatible parameter type
LinuxUartDriver(const char *const compName)
UartBaudRate
Configure UART parameters.
PlatformIndexType FwIndexType
C++ header for working with basic fprime types.
bool open(const char *const device, UartBaudRate baud, UartFlowControl fc, UartParity parity, U32 allocationSize)
void ready_out(FwIndexType portNum)
Invoke output port ready.
bool isConnected_ready_OutputPort(FwIndexType portNum)
Os::Task::Status join()
Join thread.
PlatformAssertArgType FwAssertArgType
The type of arguments to assert functions.