APM:Libraries
Device.h
Go to the documentation of this file.
1 /*
2  * This file is free software: you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published
4  * by the Free Software Foundation, either version 3 of the License,
5  * or (at your option) any later version.
6  *
7  * This file is distributed in the hope that it will be useful, but
8  * WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10  * General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program. If not, see <http://www.gnu.org/licenses/>.
14  */
15 #pragma once
16 
17 #include <inttypes.h>
18 #include <AP_HAL/HAL.h>
19 #include "Semaphores.h"
20 #include "Scheduler.h"
21 
22 namespace VRBRAIN {
23 
24 class DeviceBus {
25 public:
26  DeviceBus(uint8_t _thread_priority = APM_I2C_PRIORITY) :
27  thread_priority(_thread_priority) {}
28 
29  struct DeviceBus *next;
31 
32  AP_HAL::Device::PeriodicHandle register_periodic_callback(uint32_t period_usec, AP_HAL::Device::PeriodicCb, AP_HAL::Device *hal_device);
33  bool adjust_timer(AP_HAL::Device::PeriodicHandle h, uint32_t period_usec);
34  static void *bus_thread(void *arg);
35 
36 private:
37  struct callback_info {
39  AP_HAL::Device::PeriodicCb cb;
40  uint32_t period_usec;
41  uint64_t next_usec;
42  } *callbacks;
43  uint8_t thread_priority;
44  pthread_t thread_ctx;
47 };
48 
49 }
AP_HAL::Device * hal_device
Definition: Device.h:46
struct VRBRAIN::DeviceBus::callback_info * callbacks
bool thread_started
Definition: Device.h:45
uint8_t thread_priority
Definition: Device.h:43
struct DeviceBus * next
Definition: Device.h:29
#define APM_I2C_PRIORITY
Definition: Scheduler.h:56
void * PeriodicHandle
Definition: Device.h:42
DeviceBus(uint8_t _thread_priority=APM_I2C_PRIORITY)
Definition: Device.h:26
AP_HAL::Device::PeriodicHandle register_periodic_callback(uint32_t period_usec, AP_HAL::Device::PeriodicCb, AP_HAL::Device *hal_device)
Definition: Device.cpp:102
Semaphore semaphore
Definition: Device.h:30
struct callback_info * next
Definition: Device.h:38
static void * bus_thread(void *arg)
Definition: Device.cpp:34
bool adjust_timer(AP_HAL::Device::PeriodicHandle h, uint32_t period_usec)
Definition: Device.cpp:140
AP_HAL::Device::PeriodicCb cb
Definition: Device.h:39
pthread_t thread_ctx
Definition: Device.h:44