F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
LinuxUartDriver.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title LinuxUartDriverImpl.hpp
3 // \author tcanham
4 // \brief hpp file for LinuxUartDriver component implementation class
5 //
6 // \copyright
7 // Copyright 2009-2015, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12 
13 #ifndef LinuxUartDriver_HPP
14 #define LinuxUartDriver_HPP
15 
17 #include <Os/Mutex.hpp>
18 #include <Os/Task.hpp>
19 
20 #include <termios.h>
21 #include <atomic>
22 
23 namespace Drv {
24 
26  public:
27  // ----------------------------------------------------------------------
28  // Construction, initialization, and destruction
29  // ----------------------------------------------------------------------
30 
33  LinuxUartDriver(const char* const compName
34  );
35 
37  enum UartBaudRate {
38  BAUD_9600 = 9600,
39  BAUD_19200 = 19200,
40  BAUD_38400 = 38400,
41  BAUD_57600 = 57600,
42  BAUD_115K = 115200,
43  BAUD_230K = 230400,
44 #ifdef B460800
45  BAUD_460K = 460800,
46 #endif
47 #ifdef B921600
48  BAUD_921K = 921600,
49 #endif
50 #ifdef B1000000
51  BAUD_1000K = 1000000,
52 #endif
53 #ifdef B1152000
54  BAUD_1152K = 1152000,
55 #endif
56 #ifdef B1500000
57  BAUD_1500K = 1500000,
58 #endif
59 #ifdef B2000000
60  BAUD_2000K = 2000000,
61 #endif
62 #ifdef B2500000
63  BAUD_2500K = 2500000,
64 #endif
65 #ifdef B3000000
66  BAUD_3000K = 3000000,
67 #endif
68 #ifdef B3500000
69  BAUD_3500K = 3500000,
70 #endif
71 #ifdef B4000000
72  BAUD_4000K = 4000000
73 #endif
74  };
75 
77 
79 
80  // Open device with specified baud and flow control.
81  bool open(const char* const device,
82  UartBaudRate baud,
83  UartFlowControl fc,
84  UartParity parity,
85  FwSizeType allocationSize);
86 
93 
95  void quitReadThread();
96 
99 
103 
104  private:
105  // ----------------------------------------------------------------------
106  // Handler implementations for user-defined typed input ports
107  // ----------------------------------------------------------------------
108 
112  void run_handler(FwIndexType portNum,
113  U32 context
114  ) override;
115 
118  Drv::ByteStreamStatus send_handler(FwIndexType portNum,
119  Fw::Buffer& serBuffer) override;
120 
124  void recvReturnIn_handler(FwIndexType portNum,
125  Fw::Buffer& fwBuffer
126  ) override;
127 
128  int m_fd;
129  FwSizeType m_allocationSize;
130  const char* m_device;
131 
133  static void serialReadTaskEntry(void* ptr);
134 
135  Os::Task m_readTask;
136 
137  std::atomic<FwSizeType> m_bytesSent;
138  std::atomic<FwSizeType> m_bytesReceived;
139  bool m_quitReadThread;
140 };
141 
142 } // end namespace Drv
143 
144 #endif
static constexpr FwSizeType TASK_DEFAULT
Definition: Task.hpp:41
PlatformSizeType FwSizeType
Auto-generated base for LinuxUartDriver component.
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)
static constexpr FwTaskPriorityType TASK_PRIORITY_DEFAULT
Definition: Task.hpp:47
bool open(const char *const device, UartBaudRate baud, UartFlowControl fc, UartParity parity, FwSizeType allocationSize)
Status returned by the send call.
void quitReadThread()
Quit thread.
PlatformTaskPriorityType FwTaskPriorityType
The type of task priorities used.
FwSizeType ParamType
backwards-compatible parameter type
Definition: Task.hpp:233
LinuxUartDriver(const char *const compName)
UartBaudRate
Configure UART parameters.
PlatformIndexType FwIndexType
Os::Task::Status join()
Join thread.