APM:Libraries
CAN.cpp
Go to the documentation of this file.
1 /*
2  * This file is free software: you can redistribute it and/or modify it
3  * under the terms of the GNU General Public License as published by the
4  * Free Software Foundation, either version 3 of the License, or
5  * (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.
10  * See the GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License along
13  * with this program. If not, see <http://www.gnu.org/licenses/>.
14  *
15  * Code by Andrew Tridgell and Siddharth Bharat Purohit
16  * Based on stm32 can driver by Pavel Kirienko
17  */
18 
19 #include "CAN.h"
20 
21 #if HAL_WITH_UAVCAN
22 
23 #include <uavcan_stm32/../../src/internal.hpp>
24 
25 using namespace ChibiOS;
26 using namespace uavcan_stm32;
27 
28 extern const AP_HAL::HAL& hal;
29 
30 namespace uavcan_stm32 {
31 
33 {
34  return AP_HAL::micros64();
35 }
36 
37 uavcan::MonotonicTime clock::getMonotonic()
38 {
39  return uavcan::MonotonicTime::fromUSec(AP_HAL::micros64());
40 }
41 
42 }
43 
44 bool CANManager::begin(uint32_t bitrate, uint8_t can_number)
45 {
46  if (can_helper.init(bitrate, CanIface::OperatingMode::NormalMode, can_number) == 0) {
47  bitrate_ = bitrate;
48  initialized_ = true;
49  }
50  return initialized_;
51 }
52 
53 bool CANManager::is_initialized()
54 {
55  return initialized_;
56 }
57 
58 void CANManager::initialized(bool val)
59 {
60  initialized_ = val;
61 }
62 
63 AP_UAVCAN *CANManager::get_UAVCAN(void)
64 {
65  return p_uavcan;
66 }
67 
68 void CANManager::set_UAVCAN(AP_UAVCAN *uavcan)
69 {
70  p_uavcan = uavcan;
71 }
72 
73 void CANManager::_timer_tick()
74 {
75  if (!initialized_) return;
76 
77  if (p_uavcan != nullptr) {
78  p_uavcan->do_cyclic();
79  }
80 }
81 
82 #endif //HAL_WITH_UAVCAN
const AP_HAL::HAL & hal
Definition: UARTDriver.cpp:37
uavcan::MonotonicTime getMonotonic()
uint64_t micros64()
Definition: system.cpp:162
uint64_t getUtcUSecFromCanInterrupt()
void do_cyclic(void)