26 #define DEBUG_PRINT(...)
50 this->m_allocationSize = allocationSize;
52 this->m_device = device;
62 fd =
::open(device, O_RDWR | O_NOCTTY);
65 DEBUG_PRINT(
"open UART device %s failed.\n", device);
71 DEBUG_PRINT(
"Successfully opened UART device %s fd %d\n", device, fd);
79 stat = tcgetattr(fd, &cfg);
81 DEBUG_PRINT(
"tcgetattr failed: (%d): %s\n", stat, strerror(errno));
107 cfg.c_cc[VTIME] = 10;
109 stat = tcsetattr(fd, TCSANOW, &cfg);
111 DEBUG_PRINT(
"tcsetattr failed: (%d): %s\n", stat, strerror(errno));
125 stat = tcgetattr(fd, &t);
136 t.c_cflag |= CRTSCTS;
138 stat = tcsetattr(fd, TCSANOW, &t);
169 #if defined TGT_OS_TYPE_LINUX
177 relayRate = B1000000;
180 relayRate = B1152000;
183 relayRate = B1500000;
186 relayRate = B2000000;
190 relayRate = B2500000;
195 relayRate = B3000000;
200 relayRate = B3500000;
205 relayRate = B4000000;
214 struct termios newtio;
216 stat = tcgetattr(fd, &newtio);
241 newtio.c_cflag |= CS8 | CLOCAL | CREAD;
245 newtio.c_cflag |= (PARENB | PARODD);
248 newtio.c_cflag |= PARENB;
251 newtio.c_cflag &=
static_cast<unsigned int>(~PARENB);
259 stat = cfsetispeed(&newtio,
static_cast<speed_t
>(relayRate));
268 stat = cfsetospeed(&newtio,
static_cast<speed_t
>(relayRate));
284 newtio.c_iflag = INPCK;
287 (void)tcflush(fd, TCIFLUSH);
290 stat = tcsetattr(fd, TCSANOW, &newtio);
310 if (this->m_fd != -1) {
311 DEBUG_PRINT(
"Closing UART device %d\n", this->m_fd);
313 (void)close(this->m_fd);
323 if (this->m_fd == -1 || serBuffer.
getData() ==
nullptr || serBuffer.
getSize() == 0) {
326 unsigned char *data = serBuffer.
getData();
331 if (-1 == stat || stat != xferSize) {
344 void LinuxUartDriver ::serialReadTaskEntry(
void* ptr) {
348 while (!comp->m_quitReadThread) {
349 Fw::Buffer buff = comp->allocate_out(0,comp->m_allocationSize);
352 if (buff.
getData() ==
nullptr) {
354 comp->log_WARNING_HI_NoBuffers(_arg);
356 comp->recv_out(0, buff, status);
370 while ((stat == 0) && !comp->m_quitReadThread) {
371 stat =
static_cast<int>(::read(comp->m_fd, buff.
getData(), buff.
getSize()));
380 comp->log_WARNING_HI_ReadError(_arg, stat);
382 }
else if (stat > 0) {
383 buff.
setSize(
static_cast<U32
>(stat));
388 comp->recv_out(0, buff, status);
394 Os::Task::Arguments arguments(task, serialReadTaskEntry,
this, priority, stackSize, cpuAffinity);
400 this->m_quitReadThread =
true;
404 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.
void init()
Object initializer.
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
static Status delay(Fw::Time interval)
delay the current task