F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
LinuxGpioDriverCommon.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title LinuxGpioDriverImpl.cpp
3 // \author tcanham
4 // \brief cpp 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 
14 #include <Fw/FPrimeBasicTypes.hpp>
15 
16 namespace Drv {
17 
18 // ----------------------------------------------------------------------
19 // Construction, initialization, and destruction
20 // ----------------------------------------------------------------------
21 
22 LinuxGpioDriver ::LinuxGpioDriver(const char* const compName) : LinuxGpioDriverComponentBase(compName) {}
23 
25  const FwSizeType stackSize,
26  const FwSizeType cpuAffinity,
27  const FwTaskIdType identifier) {
29  if (this->m_configuration < GpioConfiguration::MAX_GPIO_CONFIGURATION &&
30  this->m_configuration >= GpioConfiguration::GPIO_INTERRUPT_RISING_EDGE) {
31  status = Drv::GpioStatus::OP_OK;
32  {
33  Os::ScopeLock lock(m_lock);
34  this->m_running = true;
35  }
36  Fw::String name;
37  (void)name.format("%s.interrupt", FW_OPTIONAL_NAME(this->getObjName())); // task name may safely truncate
38  Os::Task::Arguments arguments(name, &this->interruptFunction, this, priority, stackSize, cpuAffinity,
39  identifier);
40  Os::Task::Status taskStatus = this->m_poller.start(arguments);
41  if (taskStatus != Os::Task::Status::OP_OK) {
43  }
44  }
45  return status;
46 }
47 
49  Os::ScopeLock lock(m_lock);
50  this->m_running = false;
51 }
52 
54  (void)this->m_poller.join(); // best-effort join on shutdown
55 }
56 
57 void LinuxGpioDriver ::interruptFunction(void* self) {
58  FW_ASSERT(self != nullptr);
59  LinuxGpioDriver* component = reinterpret_cast<LinuxGpioDriver*>(self);
60  component->pollLoop();
61 }
62 
63 bool LinuxGpioDriver ::getRunning() {
64  Os::ScopeLock lock(m_lock);
65  return this->m_running;
66 }
67 
68 } // end namespace Drv
void stop()
stop interrupt detection thread
PlatformTaskIdType FwTaskIdType
The type of task priorities used.
Operation succeeded.
Definition: Os.hpp:27
PlatformSizeType FwSizeType
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
#define FW_OPTIONAL_NAME(name)
Definition: FpConfig.h:47
Status start(const Arguments &arguments) override
start the task
Definition: Task.cpp:84
Operation succeeded.
An unknown error occurred.
Auto-generated base for LinuxGpioDriver component.
Operation not permitted with current configuration.
Status join() override
block until the task has ended
Definition: Task.cpp:141
FormatStatus format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:58
PlatformTaskPriorityType FwTaskPriorityType
The type of task priorities used.
LinuxGpioDriver(const char *const compName)
locks a mutex within the current scope
Definition: Mutex.hpp:80
#define FW_ASSERT(...)
Definition: Assert.hpp:14
void join()
join interrupt detection thread