F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
LinuxGpioDriver.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title LinuxGpioDriver.hpp
3 // \author lestarch
4 // \brief hpp file for LinuxGpioDriver 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 DRV_LINUX_GPIO_DRIVER_HPP
14 #define DRV_LINUX_GPIO_DRIVER_HPP
15 
16 #include <Os/File.hpp>
17 #include <Os/Mutex.hpp>
18 #include <Os/Task.hpp>
20 
21 namespace Drv {
22 
24  public:
25  static constexpr FwSizeType GPIO_POLL_TIMEOUT = 500; // Timeout looking for interrupts to check for shutdown
26  // ----------------------------------------------------------------------
27  // Construction, initialization, and destruction
28  // ----------------------------------------------------------------------
29 
32  LinuxGpioDriver(const char* const compName
33  );
34 
38 
49  };
50 
52  enum ApiVersion {
56  };
57 
72  Os::File::Status open(const char* device,
73  const U32 gpio,
74  const GpioConfiguration& configuration,
75  const Fw::Logic& default_state = Fw::Logic::LOW);
76 
80  const FwSizeType stackSize = Os::Task::TASK_DEFAULT,
81  const FwSizeType cpuAffinity = Os::Task::TASK_DEFAULT,
82  const FwTaskIdType identifier = static_cast<FwTaskIdType>(Os::Task::TASK_DEFAULT));
83 
86  void stop();
87 
90  void join();
91 
92  private:
94  Os::File::Status setupLineRequestV2(const int chip_descriptor,
95  const U32 gpio,
96  const GpioConfiguration& configuration,
97  const Fw::Logic& default_state,
98  int& fd);
99 
101  Os::File::Status setupLineHandle(const int chip_descriptor,
102  const U32 gpio,
103  const GpioConfiguration& configuration,
104  const Fw::Logic& default_state,
105  int& fd);
106 
108  Os::File::Status setupLineEvent(const int chip_descriptor,
109  const U32 gpio,
110  const GpioConfiguration& configuration,
111  int& fd);
112 
115  void pollLoop();
116 
119  bool getRunning();
120 
123  static void interruptFunction(void* self);
124 
125  // ----------------------------------------------------------------------
126  // Handler implementations for user-defined typed input ports
127  // ----------------------------------------------------------------------
128 
131  Drv::GpioStatus gpioRead_handler(const FwIndexType portNum,
132  Fw::Logic& state);
133 
136  Drv::GpioStatus gpioWrite_handler(const FwIndexType portNum,
137  const Fw::Logic& state);
139  Os::Task m_poller;
140 
142  Os::Mutex m_lock;
143 
145  GpioConfiguration m_configuration = GpioConfiguration::MAX_GPIO_CONFIGURATION;
146 
148  ApiVersion m_apiVersion = ApiVersion::API_VERSION_UNSET;
149 
151  int m_fd = -1;
152 
154  bool m_running = false;
155 };
156 
157 } // end namespace Drv
158 
159 #endif // DRV_LINUX_GPIO_DRIVER_HPP
void stop()
stop interrupt detection thread
static constexpr FwSizeType TASK_DEFAULT
Definition: Task.hpp:41
PlatformTaskIdType FwTaskIdType
The type of task priorities used.
PlatformSizeType FwSizeType
Input GPIO pin triggers interrupt port on falling edge.
Drv::GpioStatus start(const FwTaskPriorityType priority=Os::Task::TASK_PRIORITY_DEFAULT, const FwSizeType stackSize=Os::Task::TASK_DEFAULT, const FwSizeType cpuAffinity=Os::Task::TASK_DEFAULT, const FwTaskIdType identifier=static_cast< FwTaskIdType >(Os::Task::TASK_DEFAULT))
start interrupt detection thread
Deprecated version 1 (gpiohandle_*/gpioevent_*) uAPI.
static constexpr FwTaskPriorityType TASK_PRIORITY_DEFAULT
Definition: Task.hpp:47
Auto-generated base for LinuxGpioDriver component.
GpioConfiguration
configure the GPIO pin
Input GPIO pin triggers interrupt port on both edges.
PlatformTaskPriorityType FwTaskPriorityType
The type of task priorities used.
Logic low state.
Definition: LogicEnumAc.hpp:34
Os::File::Status open(const char *device, const U32 gpio, const GpioConfiguration &configuration, const Fw::Logic &default_state=Fw::Logic::LOW)
open a GPIO pin for use in the system
LinuxGpioDriver(const char *const compName)
PlatformIndexType FwIndexType
Output GPIO pin for direct writing.
Logic states.
Definition: LogicEnumAc.hpp:18
Version 2 (gpio_v2_*) uAPI.
Input GPIO pin for direct reading.
Input GPIO pin triggers interrupt port on rising edge.
ApiVersion
Linux GPIO character device uAPI version used for the opened pin.
static constexpr FwSizeType GPIO_POLL_TIMEOUT
void join()
join interrupt detection thread