PX4 Firmware
PX4 Autopilot Software http://px4.io
thread.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014, 2018 Pavel Kirienko <pavel.kirienko@gmail.com>
3  * Kinetis Port Author David Sidrane <david_s5@nscdg.com>
4  */
5 
6 #pragma once
7 
9 
10 #include <nuttx/config.h>
11 #include <nuttx/fs/fs.h>
12 #include <poll.h>
13 #include <errno.h>
14 #include <cstdio>
15 #include <ctime>
16 #include <cstring>
17 
18 #include <uavcan/uavcan.hpp>
19 
20 namespace uavcan_kinetis
21 {
22 
23 class CanDriver;
24 
25 
26 /**
27  * All bus events are reported as POLLIN.
28  */
29 class BusEvent : uavcan::Noncopyable
30 {
31  using SignalCallbackHandler = void(*)();
32 
34  sem_t sem_;
35 public:
36 
37  BusEvent(CanDriver &can_driver);
38  ~BusEvent();
39 
41 
42  bool wait(uavcan::MonotonicDuration duration);
43 
44  void signalFromInterrupt();
45 };
46 
47 class Mutex
48 {
49  pthread_mutex_t mutex_;
50 
51 public:
53  {
54  init();
55  }
56 
57  int init()
58  {
59  return pthread_mutex_init(&mutex_, UAVCAN_NULLPTR);
60  }
61 
62  int deinit()
63  {
64  return pthread_mutex_destroy(&mutex_);
65  }
66 
67  void lock()
68  {
69  (void)pthread_mutex_lock(&mutex_);
70  }
71 
72  void unlock()
73  {
74  (void)pthread_mutex_unlock(&mutex_);
75  }
76 };
77 
78 
80 {
82 
83 public:
85  : mutex_(mutex)
86  {
87  mutex_.lock();
88  }
90  {
91  mutex_.unlock();
92  }
93 };
94 
95 }
void(*)() SignalCallbackHandler
Definition: thread.hpp:31
BusEvent(CanDriver &can_driver)
MutexLocker(Mutex &mutex)
Definition: thread.hpp:84
CAN driver, incorporates all available CAN ifaces.
Definition: can.hpp:269
void init()
Activates/configures the hardware registers.
All bus events are reported as POLLIN.
Definition: thread.hpp:29
pthread_mutex_t mutex_
Definition: thread.hpp:49
void registerSignalCallback(SignalCallbackHandler handler)
Definition: thread.hpp:40
SignalCallbackHandler signal_cb_
Definition: thread.hpp:33
bool wait(uavcan::MonotonicDuration duration)