26 #define DEBUG_PRINT(...)
46 this->m_allocationSize = allocationSize;
48 this->m_device = device;
58 fd =
::open(device, O_RDWR | O_NOCTTY);
61 DEBUG_PRINT(
"open UART device %s failed.\n", device);
67 DEBUG_PRINT(
"Successfully opened UART device %s fd %d\n", device, fd);
75 stat = tcgetattr(fd, &cfg);
77 DEBUG_PRINT(
"tcgetattr failed: (%d): %s\n", stat, strerror(errno));
103 cfg.c_cc[VTIME] = 10;
105 stat = tcsetattr(fd, TCSANOW, &cfg);
107 DEBUG_PRINT(
"tcsetattr failed: (%d): %s\n", stat, strerror(errno));
121 stat = tcgetattr(fd, &t);
132 t.c_cflag |= CRTSCTS;
134 stat = tcsetattr(fd, TCSANOW, &t);
165 #if defined TGT_OS_TYPE_LINUX
173 relayRate = B1000000;
176 relayRate = B1152000;
179 relayRate = B1500000;
182 relayRate = B2000000;
186 relayRate = B2500000;
191 relayRate = B3000000;
196 relayRate = B3500000;
201 relayRate = B4000000;
210 struct termios newtio;
212 stat = tcgetattr(fd, &newtio);
237 newtio.c_cflag |= CS8 | CLOCAL | CREAD;
241 newtio.c_cflag |= (PARENB | PARODD);
244 newtio.c_cflag |= PARENB;
247 newtio.c_cflag &=
static_cast<unsigned int>(~PARENB);
255 stat = cfsetispeed(&newtio,
static_cast<speed_t
>(relayRate));
264 stat = cfsetospeed(&newtio,
static_cast<speed_t
>(relayRate));
280 newtio.c_iflag = INPCK;
283 (void)tcflush(fd, TCIFLUSH);
286 stat = tcsetattr(fd, TCSANOW, &newtio);
306 if (this->m_fd != -1) {
307 DEBUG_PRINT(
"Closing UART device %d\n", this->m_fd);
309 (void)close(this->m_fd);
319 if (this->m_fd == -1 || serBuffer.
getData() ==
nullptr || serBuffer.
getSize() == 0) {
322 unsigned char *data = serBuffer.
getData();
327 if (-1 == stat || stat != xferSize) {
340 void LinuxUartDriver ::serialReadTaskEntry(
void* ptr) {
344 while (!comp->m_quitReadThread) {
345 Fw::Buffer buff = comp->allocate_out(0,comp->m_allocationSize);
348 if (buff.
getData() ==
nullptr) {
350 comp->log_WARNING_HI_NoBuffers(_arg);
352 comp->recv_out(0, buff, status);
366 while ((stat == 0) && !comp->m_quitReadThread) {
367 stat =
static_cast<int>(::read(comp->m_fd, buff.
getData(), buff.
getSize()));
376 comp->log_WARNING_HI_ReadError(_arg, stat);
378 }
else if (stat > 0) {
379 buff.
setSize(
static_cast<U32
>(stat));
384 comp->recv_out(0, buff, status);
390 Os::Task::Arguments arguments(task, serialReadTaskEntry,
this, priority, stackSize, cpuAffinity);
396 this->m_quitReadThread =
true;
400 return m_readTask.
join();
PlatformIntType NATIVE_INT_TYPE
C++ header for working with basic fprime types.
PlatformAssertArgType FwAssertArgType
Auto-generated base for LinuxUartDriver component.
void deallocate_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port deallocate.
void log_WARNING_HI_OpenError(const Fw::StringBase &device, I32 error, const Fw::StringBase &name)
bool isConnected_deallocate_OutputPort(FwIndexType portNum)
void ready_out(FwIndexType portNum)
Invoke output port ready.
void log_WARNING_HI_WriteError(const Fw::StringBase &device, I32 error)
void log_ACTIVITY_HI_PortOpened(const Fw::StringBase &device)
bool isConnected_ready_OutputPort(FwIndexType portNum)
void quitReadThread()
Quit thread.
Os::Task::Status join()
Join thread.
LinuxUartDriver(const char *const compName)
UartBaudRate
Configure UART parameters.
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)
bool open(const char *const device, UartBaudRate baud, UartFlowControl fc, UartParity parity, U32 allocationSize)
Status associated with the received data.
@ RECV_OK
Receive worked as expected.
@ RECV_ERROR
Receive error occurred retrying may succeed.
Status returned by the send call.
@ SEND_ERROR
Send error occurred retrying may succeed.
@ SEND_OK
Send worked as expected.
static Status delay(Fw::TimeInterval interval)
delay the current task
FwSizeType ParamType
backwards-compatible parameter type
Status start(const Arguments &arguments) override
start the task
Status join() override
block until the task has ended
@ OP_OK
message sent/received okay