adsd3500_interrupt_notifier.cpp
Go to the documentation of this file.
1 /********************************************************************************/
2 /* */
3 /* Copyright (c) 2020 Analog Devices, Inc. All Rights Reserved. */
4 /* This software is proprietary to Analog Devices, Inc. and its licensors. */
5 /* */
6 /********************************************************************************/
8 #include "adsd3500_sensor.h"
9 #ifdef USE_GLOG
10 #include <glog/logging.h>
11 #else
12 #include <aditof/log.h>
13 #include <cstring>
14 #include <unistd.h>
15 #endif
16 #include <fcntl.h>
17 #include <sys/ioctl.h>
18 
19 #define SIGETX 44
20 #define USER_TASK _IOW('A', 1, int32_t *)
21 
22 std::vector<std::weak_ptr<Adsd3500Sensor>> Adsd3500InterruptNotifier::m_sensors;
23 
25  static auto &&notifier = Adsd3500InterruptNotifier();
26  return (notifier);
27 }
28 
30  void *unused) {
31  if (n == SIGETX) {
32  int signal_value = info->si_int;
33  DLOG(INFO) << "Received signal " << info->si_int << " from kernel";
34 
35  for (auto sensor : m_sensors) {
36  if (std::shared_ptr<Adsd3500Sensor> sptr = sensor.lock()) {
37  sptr->adsd3500InterruptHandler(signal_value);
38  }
39  }
40  }
41 }
42 
44  // Subscribe to the ADSD3500 interrupt
45  struct sigaction act;
46  int32_t number;
47 
48  sigemptyset(&act.sa_mask);
49  act.sa_flags = (SA_SIGINFO | SA_RESTART);
51  sigaction(SIGETX, &act, NULL);
52 
53  m_interruptsAvailable = false;
54 
55  int debug_fd = ::open("/sys/kernel/debug/adsd3500/value", O_RDWR);
56  if (debug_fd < 0) {
57  LOG(WARNING) << "Failed to open the debug sysfs. "
58  << "Interrupts support will not be available!";
60  }
61 
62  if (ioctl(debug_fd, USER_TASK, (int32_t *)&number)) {
63  LOG(WARNING) << "Failed to register the application process with the "
64  "kernel driver. IOCTL failed.";
65  close(debug_fd);
66  }
67 
68  m_interruptsAvailable = true;
69 
70  return aditof::Status::OK;
71 }
72 
74  return aditof::Status::OK;
75 }
76 
78  return m_interruptsAvailable;
79 }
80 
82  std::weak_ptr<Adsd3500Sensor> sensor) {
83  m_sensors.emplace_back(sensor);
84 }
85 
87  std::weak_ptr<Adsd3500Sensor> sensor) {}
Adsd3500InterruptNotifier::getInstance
static Adsd3500InterruptNotifier & getInstance()
Definition: adsd3500_interrupt_notifier.cpp:24
INFO
const int INFO
Definition: log_severity.h:59
NULL
NULL
Definition: test_security_zap.cpp:405
log.h
Adsd3500InterruptNotifier::interruptsAvailable
bool interruptsAvailable()
Definition: adsd3500_interrupt_notifier.cpp:77
aditof::Status::UNAVAILABLE
@ UNAVAILABLE
The requested action or resource is unavailable.
WARNING
const int WARNING
Definition: log_severity.h:59
USER_TASK
#define USER_TASK
Definition: adsd3500_interrupt_notifier.cpp:20
DLOG
#define DLOG(x)
Definition: sdk/include/aditof/log.h:73
Adsd3500InterruptNotifier::m_sensors
static std::vector< std::weak_ptr< Adsd3500Sensor > > m_sensors
Definition: adsd3500_interrupt_notifier.h:64
Adsd3500InterruptNotifier::disableInterrupts
aditof::Status disableInterrupts()
Definition: adsd3500_interrupt_notifier.cpp:73
SIGETX
#define SIGETX
Definition: adsd3500_interrupt_notifier.cpp:19
adsd3500_sensor.h
Adsd3500InterruptNotifier::signalEventHandler
static void signalEventHandler(int n, siginfo_t *info, void *unused)
Definition: adsd3500_interrupt_notifier.cpp:29
n
GLdouble n
Definition: glcorearb.h:4153
Adsd3500InterruptNotifier::m_interruptsAvailable
bool m_interruptsAvailable
Definition: adsd3500_interrupt_notifier.h:65
aditof::Status
Status
Status of any operation that the TOF sdk performs.
Definition: status_definitions.h:48
LOG
#define LOG(x)
Definition: sdk/include/aditof/log.h:72
aditof::Status::OK
@ OK
Success.
Adsd3500InterruptNotifier
Definition: adsd3500_interrupt_notifier.h:40
Adsd3500InterruptNotifier::subscribeSensor
void subscribeSensor(std::weak_ptr< Adsd3500Sensor > sensor)
Definition: adsd3500_interrupt_notifier.cpp:81
Adsd3500InterruptNotifier::enableInterrupts
aditof::Status enableInterrupts()
Definition: adsd3500_interrupt_notifier.cpp:43
adsd3500_interrupt_notifier.h
Adsd3500InterruptNotifier::unsubscribeSensor
void unsubscribeSensor(std::weak_ptr< Adsd3500Sensor > sensor)
Definition: adsd3500_interrupt_notifier.cpp:86
number
double number
Definition: cJSON.h:326
Adsd3500InterruptNotifier::Adsd3500InterruptNotifier
Adsd3500InterruptNotifier()=default


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:47