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 TGT_OS_TYPE_LINUX
45  BAUD_460K = 460800,
46  BAUD_921K = 921600,
47  BAUD_1000K = 1000000,
48  BAUD_1152K = 1152000,
49  BAUD_1500K = 1500000,
50  BAUD_2000K = 2000000,
51 #ifdef B2500000
52  BAUD_2500K = 2500000,
53 #endif
54 #ifdef B3000000
55  BAUD_3000K = 3000000,
56 #endif
57 #ifdef B3500000
58  BAUD_3500K = 3500000,
59 #endif
60 #ifdef B4000000
61  BAUD_4000K = 4000000
62 #endif
63 #endif
64  };
65 
67 
69 
70  // Open device with specified baud and flow control.
71  bool open(const char* const device,
72  UartBaudRate baud,
73  UartFlowControl fc,
74  UartParity parity,
75  FwSizeType allocationSize);
76 
83 
85  void quitReadThread();
86 
89 
93 
94  private:
95  // ----------------------------------------------------------------------
96  // Handler implementations for user-defined typed input ports
97  // ----------------------------------------------------------------------
98 
102  void run_handler(FwIndexType portNum,
103  U32 context
104  ) override;
105 
108  Drv::ByteStreamStatus send_handler(FwIndexType portNum,
109  Fw::Buffer& serBuffer) override;
110 
114  void recvReturnIn_handler(FwIndexType portNum,
115  Fw::Buffer& fwBuffer
116  ) override;
117 
118  int m_fd;
119  FwSizeType m_allocationSize;
120  const char* m_device;
121 
123  static void serialReadTaskEntry(void* ptr);
124 
125  Os::Task m_readTask;
126 
127  std::atomic<FwSizeType> m_bytesSent;
128  std::atomic<FwSizeType> m_bytesReceived;
129  bool m_quitReadThread;
130 };
131 
132 } // end namespace Drv
133 
134 #endif
static constexpr FwSizeType TASK_DEFAULT
Definition: Task.hpp:37
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:38
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:222
LinuxUartDriver(const char *const compName)
UartBaudRate
Configure UART parameters.
PlatformIndexType FwIndexType
Os::Task::Status join()
Join thread.