33 m_device(
"NOT_EXIST"),
36 m_quitReadThread(false) {}
46 this->m_allocationSize = allocationSize;
48 this->m_device = device;
56 fd =
::open(device, O_RDWR | O_NOCTTY);
70 stat = tcgetattr(fd, &cfg);
97 stat = tcsetattr(fd, TCSANOW, &cfg);
110 stat = tcgetattr(fd, &t);
120 t.c_cflag |= CRTSCTS;
122 stat = tcsetattr(fd, TCSANOW, &t);
152 #if defined TGT_OS_TYPE_LINUX 160 relayRate = B1000000;
163 relayRate = B1152000;
166 relayRate = B1500000;
169 relayRate = B2000000;
173 relayRate = B2500000;
178 relayRate = B3000000;
183 relayRate = B3500000;
188 relayRate = B4000000;
193 FW_ASSERT(0, static_cast<FwAssertArgType>(baud));
197 struct termios newtio;
199 stat = tcgetattr(fd, &newtio);
223 newtio.c_cflag |= CS8 | CLOCAL | CREAD;
227 newtio.c_cflag |= (PARENB | PARODD);
230 newtio.c_cflag |= PARENB;
233 newtio.c_cflag &=
static_cast<unsigned int>(~PARENB);
241 stat = cfsetispeed(&newtio, static_cast<speed_t>(relayRate));
249 stat = cfsetospeed(&newtio, static_cast<speed_t>(relayRate));
264 newtio.c_iflag = INPCK;
267 (void)tcflush(fd, TCIFLUSH);
270 stat = tcsetattr(fd, TCSANOW, &newtio);
289 if (this->m_fd != -1) {
290 (void)close(this->m_fd);
298 void LinuxUartDriver ::run_handler(
FwIndexType portNum, U32 context) {
305 if (this->m_fd == -1 || serBuffer.
getData() ==
nullptr || serBuffer.
getSize() == 0) {
308 unsigned char* data = serBuffer.
getData();
310 size_t xferSize =
static_cast<size_t>(serBuffer.
getSize());
312 ssize_t stat = ::write(this->m_fd, data, xferSize);
314 if (-1 == stat || static_cast<size_t>(stat) != xferSize) {
319 this->m_bytesSent +=
static_cast<FwSizeType>(stat);
329 void LinuxUartDriver ::serialReadTaskEntry(
void* ptr) {
333 while (!comp->m_quitReadThread) {
334 Fw::Buffer buff = comp->allocate_out(0, comp->m_allocationSize);
337 if (buff.
getData() ==
nullptr) {
339 comp->log_WARNING_HI_NoBuffers(_arg);
341 comp->recv_out(0, buff, status);
352 while ((stat == 0) && !comp->m_quitReadThread) {
353 stat =
static_cast<int>(::read(comp->m_fd, buff.
getData(),
static_cast<size_t>(buff.
getSize())));
362 comp->log_WARNING_HI_ReadError(_arg, stat);
364 }
else if (stat > 0) {
365 buff.
setSize(static_cast<U32>(stat));
367 comp->m_bytesReceived +=
static_cast<FwSizeType>(stat);
372 comp->recv_out(0, buff, status);
380 Os::Task::Arguments arguments(task, serialReadTaskEntry,
this, priority, stackSize, cpuAffinity);
386 this->m_quitReadThread =
true;
390 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.