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 
63  Os::File::Status open(const char* device,
64  const U32 gpio,
65  const GpioConfiguration& configuration,
66  const Fw::Logic& default_state = Fw::Logic::LOW);
67 
71  const FwSizeType stackSize = Os::Task::TASK_DEFAULT,
72  const FwSizeType cpuAffinity = Os::Task::TASK_DEFAULT,
73  const PlatformUIntType identifier = static_cast<PlatformUIntType>(Os::Task::TASK_DEFAULT));
74 
77  void stop();
78 
81  void join();
82 
83  private:
85  Os::File::Status setupLineHandle(const PlatformIntType chip_descriptor,
86  const U32 gpio,
87  const GpioConfiguration& configuration,
88  const Fw::Logic& default_state,
89  PlatformIntType& fd);
90 
92  Os::File::Status setupLineEvent(const PlatformIntType chip_descriptor,
93  const U32 gpio,
94  const GpioConfiguration& configuration,
95  PlatformIntType& fd);
96 
99  void pollLoop();
100 
103  bool getRunning();
104 
107  static void interruptFunction(void* self);
108 
109  // ----------------------------------------------------------------------
110  // Handler implementations for user-defined typed input ports
111  // ----------------------------------------------------------------------
112 
115  Drv::GpioStatus gpioRead_handler(const FwIndexType portNum,
116  Fw::Logic& state);
117 
120  Drv::GpioStatus gpioWrite_handler(const FwIndexType portNum,
121  const Fw::Logic& state);
123  Os::Task m_poller;
124 
126  Os::Mutex m_lock;
127 
129  GpioConfiguration m_configuration = GpioConfiguration::MAX_GPIO_CONFIGURATION;
130 
132  PlatformIntType m_fd = -1;
133 
135  bool m_running = false;
136 };
137 
138 } // end namespace Drv
139 
140 #endif // DRV_LINUX_GPIO_DRIVER_HPP
void stop()
stop interrupt detection thread
static constexpr FwSizeType TASK_DEFAULT
Definition: Task.hpp:28
PlatformSizeType FwSizeType
Input GPIO pin triggers interrupt port on falling edge.
static constexpr FwTaskPriorityType TASK_PRIORITY_DEFAULT
Definition: Task.hpp:29
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:33
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:17
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 PlatformUIntType identifier=static_cast< PlatformUIntType >(Os::Task::TASK_DEFAULT))
start interrupt detection thread
Input GPIO pin for direct reading.
Input GPIO pin triggers interrupt port on rising edge.
static constexpr FwSizeType GPIO_POLL_TIMEOUT
void join()
join interrupt detection thread