F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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
21namespace 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
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 NATIVE_INT_TYPE portNum,
116 Fw::Logic& state);
117
120 Drv::GpioStatus gpioWrite_handler(const NATIVE_INT_TYPE portNum,
121 const Fw::Logic& state);
123 Os::Task m_poller;
124
126 Os::Mutex m_lock;
127
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
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:55
unsigned int PlatformUIntType
int PlatformIntType
DefaultTypes.hpp provides fallback defaults for the platform types.
PlatformSizeType FwSizeType
Definition FpConfig.h:35
Auto-generated base for LinuxGpioDriver component.
void stop()
stop interrupt detection thread
void join()
join interrupt detection thread
static constexpr FwSizeType GPIO_POLL_TIMEOUT
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
Drv::GpioStatus start(const FwSizeType priority=Os::Task::TASK_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
GpioConfiguration
configure the GPIO pin
@ GPIO_INPUT
Input GPIO pin for direct reading.
@ GPIO_INTERRUPT_FALLING_EDGE
Input GPIO pin triggers interrupt port on falling edge.
@ GPIO_INTERRUPT_BOTH_RISING_AND_FALLING_EDGES
Input GPIO pin triggers interrupt port on both edges.
@ GPIO_INTERRUPT_RISING_EDGE
Input GPIO pin triggers interrupt port on rising edge.
@ GPIO_OUTPUT
Output GPIO pin for direct writing.
Logic states.
@ LOW
Logic low state.
static constexpr FwSizeType TASK_DEFAULT
Definition Task.hpp:28