CANFDIface.cpp 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  1. /*
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2014 Pavel Kirienko
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  7. * this software and associated documentation files (the "Software"), to deal in
  8. * the Software without restriction, including without limitation the rights to
  9. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10. * the Software, and to permit persons to whom the Software is furnished to do so,
  11. * subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all
  14. * copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. /*
  24. * This file is free software: you can redistribute it and/or modify it
  25. * under the terms of the GNU General Public License as published by the
  26. * Free Software Foundation, either version 3 of the License, or
  27. * (at your option) any later version.
  28. *
  29. * This file is distributed in the hope that it will be useful, but
  30. * WITHOUT ANY WARRANTY; without even the implied warranty of
  31. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  32. * See the GNU General Public License for more details.
  33. *
  34. * You should have received a copy of the GNU General Public License along
  35. * with this program. If not, see <http://www.gnu.org/licenses/>.
  36. *
  37. * Code by Siddharth Bharat Purohit
  38. */
  39. #include "AP_HAL_ChibiOS.h"
  40. #if HAL_WITH_UAVCAN
  41. #include <cassert>
  42. #include <cstring>
  43. #include "CANClock.h"
  44. #include "CANInternal.h"
  45. #include "CANSerialRouter.h"
  46. #include <AP_UAVCAN/AP_UAVCAN_SLCAN.h>
  47. #include <AP_Math/AP_Math.h>
  48. # include <hal.h>
  49. # if defined(STM32H7XX)
  50. #include "CANFDIface.h"
  51. #define FDCAN1_IT0_IRQHandler STM32_FDCAN1_IT0_HANDLER
  52. #define FDCAN1_IT1_IRQHandler STM32_FDCAN1_IT1_HANDLER
  53. #define FDCAN2_IT0_IRQHandler STM32_FDCAN2_IT0_HANDLER
  54. #define FDCAN2_IT1_IRQHandler STM32_FDCAN2_IT1_HANDLER
  55. #define FDCAN_FRAME_BUFFER_SIZE 4 // Buffer size for 8 bytes data field
  56. //Message RAM Allocations in Word lengths
  57. #define MAX_FILTER_LIST_SIZE 80U //80 element Standard Filter List elements or 40 element Extended Filter List
  58. #define FDCAN_NUM_RXFIFO0_SIZE 104U //26 Frames
  59. #define FDCAN_TX_FIFO_BUFFER_SIZE 128U //32 Frames
  60. #define MESSAGE_RAM_END_ADDR 0x4000B5FC
  61. extern const AP_HAL::HAL& hal;
  62. namespace ChibiOS_CAN
  63. {
  64. namespace
  65. {
  66. CanIface* ifaces[UAVCAN_STM32_NUM_IFACES] = {
  67. UAVCAN_NULLPTR
  68. #if UAVCAN_STM32_NUM_IFACES > 1
  69. , UAVCAN_NULLPTR
  70. #endif
  71. };
  72. inline void handleInterrupt(uavcan::uint8_t iface_index, uavcan::uint8_t line_index)
  73. {
  74. UAVCAN_ASSERT(iface_index < UAVCAN_STM32_NUM_IFACES);
  75. if (ifaces[iface_index] == UAVCAN_NULLPTR) {
  76. //Just reset all the interrupts and return
  77. ifaces[iface_index]->can_reg()->IR = FDCAN_IR_RF0N;
  78. ifaces[iface_index]->can_reg()->IR = FDCAN_IR_RF1N;
  79. ifaces[iface_index]->can_reg()->IR = FDCAN_IR_TEFN;
  80. UAVCAN_ASSERT(0);
  81. return;
  82. }
  83. if (line_index == 0) {
  84. if ((ifaces[iface_index]->can_reg()->IR & FDCAN_IR_RF0N) ||
  85. (ifaces[iface_index]->can_reg()->IR & FDCAN_IR_RF0F)) {
  86. ifaces[iface_index]->can_reg()->IR = FDCAN_IR_RF0N | FDCAN_IR_RF0F;
  87. ifaces[iface_index]->handleRxInterrupt(0);
  88. }
  89. if ((ifaces[iface_index]->can_reg()->IR & FDCAN_IR_RF1N) ||
  90. (ifaces[iface_index]->can_reg()->IR & FDCAN_IR_RF1F)) {
  91. ifaces[iface_index]->can_reg()->IR = FDCAN_IR_RF1N | FDCAN_IR_RF1F;
  92. ifaces[iface_index]->handleRxInterrupt(1);
  93. }
  94. } else {
  95. if (ifaces[iface_index]->can_reg()->IR & FDCAN_IR_TC) {
  96. ifaces[iface_index]->can_reg()->IR = FDCAN_IR_TC;
  97. uavcan::uint64_t utc_usec = clock::getUtcUSecFromCanInterrupt();
  98. if (utc_usec > 0) {
  99. utc_usec--;
  100. }
  101. ifaces[iface_index]->handleTxCompleteInterrupt(utc_usec);
  102. }
  103. }
  104. ifaces[iface_index]->pollErrorFlagsFromISR();
  105. }
  106. } // namespace
  107. uint32_t CanIface::FDCANMessageRAMOffset_ = 0;
  108. #if AP_UAVCAN_SLCAN_ENABLED
  109. SLCANRouter CanIface::_slcan_router;
  110. #endif
  111. CanIface::CanIface(fdcan::CanType* can, BusEvent& update_event, uavcan::uint8_t self_index,
  112. CanRxItem* rx_queue_buffer, uavcan::uint8_t rx_queue_capacity)
  113. : rx_queue_(rx_queue_buffer, rx_queue_capacity)
  114. , can_(can)
  115. , error_cnt_(0)
  116. , served_aborts_cnt_(0)
  117. , update_event_(update_event)
  118. , peak_tx_mailbox_index_(0)
  119. , self_index_(self_index)
  120. , had_activity_(false)
  121. {
  122. UAVCAN_ASSERT(self_index_ < UAVCAN_STM32_NUM_IFACES);
  123. }
  124. /*
  125. * CanIface::RxQueue
  126. */
  127. void CanIface::RxQueue::registerOverflow()
  128. {
  129. if (overflow_cnt_ < 0xFFFFFFFF) {
  130. overflow_cnt_++;
  131. }
  132. }
  133. void CanIface::RxQueue::push(const uavcan::CanFrame& frame, const uint64_t& utc_usec, uavcan::CanIOFlags flags)
  134. {
  135. buf_[in_].frame = frame;
  136. buf_[in_].utc_usec = utc_usec;
  137. buf_[in_].flags = flags;
  138. in_++;
  139. if (in_ >= capacity_) {
  140. in_ = 0;
  141. }
  142. len_++;
  143. if (len_ > capacity_) {
  144. len_ = capacity_;
  145. registerOverflow();
  146. out_++;
  147. if (out_ >= capacity_) {
  148. out_ = 0;
  149. }
  150. }
  151. }
  152. void CanIface::RxQueue::pop(uavcan::CanFrame& out_frame, uavcan::uint64_t& out_utc_usec, uavcan::CanIOFlags& out_flags)
  153. {
  154. if (len_ > 0) {
  155. out_frame = buf_[out_].frame;
  156. out_utc_usec = buf_[out_].utc_usec;
  157. out_flags = buf_[out_].flags;
  158. out_++;
  159. if (out_ >= capacity_) {
  160. out_ = 0;
  161. }
  162. len_--;
  163. } else {
  164. UAVCAN_ASSERT(0);
  165. }
  166. }
  167. void CanIface::RxQueue::reset()
  168. {
  169. in_ = 0;
  170. out_ = 0;
  171. len_ = 0;
  172. overflow_cnt_ = 0;
  173. }
  174. int CanIface::computeTimings(const uavcan::uint32_t target_bitrate, Timings& out_timings)
  175. {
  176. if (target_bitrate < 1) {
  177. return -ErrInvalidBitRate;
  178. }
  179. /*
  180. * Hardware configuration
  181. */
  182. const uavcan::uint32_t pclk = STM32_PLL1_Q_CK;
  183. static const int MaxBS1 = 16;
  184. static const int MaxBS2 = 8;
  185. /*
  186. * Ref. "Automatic Baudrate Detection in CANopen Networks", U. Koppe, MicroControl GmbH & Co. KG
  187. * CAN in Automation, 2003
  188. *
  189. * According to the source, optimal quanta per bit are:
  190. * Bitrate Optimal Maximum
  191. * 1000 kbps 8 10
  192. * 500 kbps 16 17
  193. * 250 kbps 16 17
  194. * 125 kbps 16 17
  195. */
  196. const int max_quanta_per_bit = (target_bitrate >= 1000000) ? 10 : 17;
  197. UAVCAN_ASSERT(max_quanta_per_bit <= (MaxBS1 + MaxBS2));
  198. static const int MaxSamplePointLocation = 900;
  199. /*
  200. * Computing (prescaler * BS):
  201. * BITRATE = 1 / (PRESCALER * (1 / PCLK) * (1 + BS1 + BS2)) -- See the Reference Manual
  202. * BITRATE = PCLK / (PRESCALER * (1 + BS1 + BS2)) -- Simplified
  203. * let:
  204. * BS = 1 + BS1 + BS2 -- Number of time quanta per bit
  205. * PRESCALER_BS = PRESCALER * BS
  206. * ==>
  207. * PRESCALER_BS = PCLK / BITRATE
  208. */
  209. const uavcan::uint32_t prescaler_bs = pclk / target_bitrate;
  210. /*
  211. * Searching for such prescaler value so that the number of quanta per bit is highest.
  212. */
  213. uavcan::uint8_t bs1_bs2_sum = uavcan::uint8_t(max_quanta_per_bit - 1);
  214. while ((prescaler_bs % (1 + bs1_bs2_sum)) != 0) {
  215. if (bs1_bs2_sum <= 2) {
  216. return -ErrInvalidBitRate; // No solution
  217. }
  218. bs1_bs2_sum--;
  219. }
  220. const uavcan::uint32_t prescaler = prescaler_bs / (1 + bs1_bs2_sum);
  221. if ((prescaler < 1U) || (prescaler > 1024U)) {
  222. return -ErrInvalidBitRate; // No solution
  223. }
  224. /*
  225. * Now we have a constraint: (BS1 + BS2) == bs1_bs2_sum.
  226. * We need to find the values so that the sample point is as close as possible to the optimal value.
  227. *
  228. * Solve[(1 + bs1)/(1 + bs1 + bs2) == 7/8, bs2] (* Where 7/8 is 0.875, the recommended sample point location *)
  229. * {{bs2 -> (1 + bs1)/7}}
  230. *
  231. * Hence:
  232. * bs2 = (1 + bs1) / 7
  233. * bs1 = (7 * bs1_bs2_sum - 1) / 8
  234. *
  235. * Sample point location can be computed as follows:
  236. * Sample point location = (1 + bs1) / (1 + bs1 + bs2)
  237. *
  238. * Since the optimal solution is so close to the maximum, we prepare two solutions, and then pick the best one:
  239. * - With rounding to nearest
  240. * - With rounding to zero
  241. */
  242. struct BsPair {
  243. uavcan::uint8_t bs1;
  244. uavcan::uint8_t bs2;
  245. uavcan::uint16_t sample_point_permill;
  246. BsPair() :
  247. bs1(0),
  248. bs2(0),
  249. sample_point_permill(0)
  250. { }
  251. BsPair(uavcan::uint8_t bs1_bs2_sum, uavcan::uint8_t arg_bs1) :
  252. bs1(arg_bs1),
  253. bs2(uavcan::uint8_t(bs1_bs2_sum - bs1)),
  254. sample_point_permill(uavcan::uint16_t(1000 * (1 + bs1) / (1 + bs1 + bs2)))
  255. {
  256. UAVCAN_ASSERT(bs1_bs2_sum > arg_bs1);
  257. }
  258. bool isValid() const
  259. {
  260. return (bs1 >= 1) && (bs1 <= MaxBS1) && (bs2 >= 1) && (bs2 <= MaxBS2);
  261. }
  262. };
  263. // First attempt with rounding to nearest
  264. BsPair solution(bs1_bs2_sum, uavcan::uint8_t(((7 * bs1_bs2_sum - 1) + 4) / 8));
  265. if (solution.sample_point_permill > MaxSamplePointLocation) {
  266. // Second attempt with rounding to zero
  267. solution = BsPair(bs1_bs2_sum, uavcan::uint8_t((7 * bs1_bs2_sum - 1) / 8));
  268. }
  269. /*
  270. * Final validation
  271. * Helpful Python:
  272. * def sample_point_from_btr(x):
  273. * assert 0b0011110010000000111111000000000 & x == 0
  274. * ts2,ts1,brp = (x>>20)&7, (x>>16)&15, x&511
  275. * return (1+ts1+1)/(1+ts1+1+ts2+1)
  276. *
  277. */
  278. if ((target_bitrate != (pclk / (prescaler * (1 + solution.bs1 + solution.bs2)))) || !solution.isValid()) {
  279. UAVCAN_ASSERT(0);
  280. return -ErrLogic;
  281. }
  282. UAVCAN_STM32_LOG("Timings: quanta/bit: %d, sample point location: %.1f%%",
  283. int(1 + solution.bs1 + solution.bs2), float(solution.sample_point_permill) / 10.F);
  284. out_timings.prescaler = uavcan::uint16_t(prescaler - 1U);
  285. out_timings.sjw = 0; // Which means one
  286. out_timings.bs1 = uavcan::uint8_t(solution.bs1 - 1);
  287. out_timings.bs2 = uavcan::uint8_t(solution.bs2 - 1);
  288. return 0;
  289. }
  290. uavcan::int16_t CanIface::send(const uavcan::CanFrame& frame, uavcan::MonotonicTime tx_deadline,
  291. uavcan::CanIOFlags flags)
  292. {
  293. if (frame.isErrorFrame() || frame.dlc > 8) {
  294. return -ErrUnsupportedFrame;
  295. }
  296. /*
  297. * Normally we should perform the same check as in @ref canAcceptNewTxFrame(), because
  298. * it is possible that the highest-priority frame between select() and send() could have been
  299. * replaced with a lower priority one due to TX timeout. But we don't do this check because:
  300. *
  301. * - It is a highly unlikely scenario.
  302. *
  303. * - Frames do not timeout on a properly functioning bus. Since frames do not timeout, the new
  304. * frame can only have higher priority, which doesn't break the logic.
  305. *
  306. * - If high-priority frames are timing out in the TX queue, there's probably a lot of other
  307. * issues to take care of before this one becomes relevant.
  308. *
  309. * - It takes CPU time. Not just CPU time, but critical section time, which is expensive.
  310. */
  311. CriticalSectionLocker lock;
  312. /*
  313. * Seeking for an empty slot
  314. */
  315. uavcan::uint8_t index;
  316. if ((can_->TXFQS & FDCAN_TXFQS_TFQF) != 0) {
  317. return false; //we don't have free space
  318. }
  319. index = ((can_->TXFQS & FDCAN_TXFQS_TFQPI) >> FDCAN_TXFQS_TFQPI_Pos);
  320. // Copy Frame to RAM
  321. // Calculate Tx element address
  322. uint32_t* buffer = (uint32_t *)(MessageRam_.TxFIFOQSA + (index * FDCAN_FRAME_BUFFER_SIZE * 4));
  323. //Setup Frame ID
  324. if (frame.isExtended()) {
  325. buffer[0] = (fdcan::IDE | frame.id);
  326. } else {
  327. buffer[0] = (frame.id << 18);
  328. }
  329. if (frame.isRemoteTransmissionRequest()) {
  330. buffer[0] |= fdcan::RTR;
  331. }
  332. //Write Data Length Code, and Message Marker
  333. buffer[1] = frame.dlc << 16 | index << 24;
  334. // Write Frame to the message RAM
  335. buffer[2] = (uavcan::uint32_t(frame.data[3]) << 24) |
  336. (uavcan::uint32_t(frame.data[2]) << 16) |
  337. (uavcan::uint32_t(frame.data[1]) << 8) |
  338. (uavcan::uint32_t(frame.data[0]) << 0);
  339. buffer[3] = (uavcan::uint32_t(frame.data[7]) << 24) |
  340. (uavcan::uint32_t(frame.data[6]) << 16) |
  341. (uavcan::uint32_t(frame.data[5]) << 8) |
  342. (uavcan::uint32_t(frame.data[4]) << 0);
  343. //Set Add Request
  344. can_->TXBAR = (1 << index);
  345. //Registering the pending transmission so we can track its deadline and loopback it as needed
  346. pending_tx_[index].deadline = tx_deadline;
  347. pending_tx_[index].frame = frame;
  348. pending_tx_[index].loopback = (flags & uavcan::CanIOFlagLoopback) != 0;
  349. pending_tx_[index].abort_on_error = (flags & uavcan::CanIOFlagAbortOnError) != 0;
  350. pending_tx_[index].index = index;
  351. return 1;
  352. }
  353. uavcan::int16_t CanIface::receive(uavcan::CanFrame& out_frame, uavcan::MonotonicTime& out_ts_monotonic,
  354. uavcan::UtcTime& out_ts_utc, uavcan::CanIOFlags& out_flags)
  355. {
  356. out_ts_monotonic = clock::getMonotonic(); // High precision is not required for monotonic timestamps
  357. uavcan::uint64_t utc_usec = 0;
  358. {
  359. CriticalSectionLocker lock;
  360. if (rx_queue_.getLength() == 0) {
  361. return 0;
  362. }
  363. rx_queue_.pop(out_frame, utc_usec, out_flags);
  364. }
  365. out_ts_utc = uavcan::UtcTime::fromUSec(utc_usec);
  366. return 1;
  367. }
  368. uavcan::int16_t CanIface::configureFilters(const uavcan::CanFilterConfig* filter_configs,
  369. uavcan::uint16_t num_configs)
  370. {
  371. uint32_t num_extid = 0, num_stdid = 0;
  372. uint32_t total_available_list_size = MAX_FILTER_LIST_SIZE;
  373. uint32_t* filter_ptr;
  374. //count number of frames of each type
  375. for (uint8_t i = 0; i < num_configs; i++) {
  376. const uavcan::CanFilterConfig* const cfg = filter_configs + i;
  377. if ((cfg->id & uavcan::CanFrame::FlagEFF) || !(cfg->mask & uavcan::CanFrame::FlagEFF)) {
  378. num_extid++;
  379. } else {
  380. num_stdid++;
  381. }
  382. }
  383. CriticalSectionLocker lock;
  384. can_->CCCR |= FDCAN_CCCR_INIT; // Request init
  385. while ((can_->CCCR & FDCAN_CCCR_INIT) == 0) {}
  386. can_->CCCR |= FDCAN_CCCR_CCE; //Enable Config change
  387. //Allocate Message RAM for Standard ID Filter List
  388. if (num_stdid == 0) { //No Frame with Standard ID is to be accepted
  389. can_->GFC |= 0x2; //Reject All Standard ID Frames
  390. } else if ((num_stdid < total_available_list_size) && (num_stdid <= 128)) {
  391. can_->SIDFC = (FDCANMessageRAMOffset_ << 2) | (num_stdid << 16);
  392. MessageRam_.StandardFilterSA = SRAMCAN_BASE + (FDCANMessageRAMOffset_ * 4U);
  393. FDCANMessageRAMOffset_ += num_stdid;
  394. total_available_list_size -= num_stdid;
  395. can_->GFC |= (0x3U << 4); //Reject non matching Standard frames
  396. } else { //The List is too big, return fail
  397. can_->CCCR &= ~FDCAN_CCCR_INIT; // Leave init mode
  398. return -ErrFilterNumConfigs;
  399. }
  400. if (num_stdid) {
  401. num_stdid = 0; //reset list count
  402. filter_ptr = (uint32_t*)MessageRam_.StandardFilterSA;
  403. //Run through the filter list and setup standard id filter list
  404. for (uint8_t i = 0; i < num_configs; i++) {
  405. uint32_t id = 0;
  406. uint32_t mask = 0;
  407. const uavcan::CanFilterConfig* const cfg = filter_configs + i;
  408. if (!((cfg->id & uavcan::CanFrame::FlagEFF) || !(cfg->mask & uavcan::CanFrame::FlagEFF))) {
  409. id = (cfg->id & uavcan::CanFrame::MaskStdID); // Regular std frames, nothing fancy.
  410. mask = (cfg->mask & 0x7F);
  411. filter_ptr[num_stdid] = 0x2U << 30 | //Classic CAN Filter
  412. 0x1U << 27 | //Store in Rx FIFO0 if filter matches
  413. id << 16 |
  414. mask;
  415. num_stdid++;
  416. }
  417. }
  418. }
  419. //Allocate Message RAM for Extended ID Filter List
  420. if (num_extid == 0) { //No Frame with Extended ID is to be accepted
  421. can_->GFC |= 0x1; //Reject All Extended ID Frames
  422. } else if ((num_extid < (total_available_list_size/2)) && (num_extid <= 64)) {
  423. can_->XIDFC = (FDCANMessageRAMOffset_ << 2) | (num_extid << 16);
  424. MessageRam_.ExtendedFilterSA = SRAMCAN_BASE + (FDCANMessageRAMOffset_ * 4U);
  425. FDCANMessageRAMOffset_ += num_extid*2;
  426. can_->GFC = (0x3U << 2); // Reject non matching Extended frames
  427. } else { //The List is too big, return fail
  428. can_->CCCR &= ~FDCAN_CCCR_INIT; // Leave init mode
  429. return -ErrFilterNumConfigs;
  430. }
  431. if (num_extid) {
  432. num_extid = 0;
  433. filter_ptr = (uint32_t*)MessageRam_.ExtendedFilterSA;
  434. //Run through the filter list and setup extended id filter list
  435. for (uint8_t i = 0; i < num_configs; i++) {
  436. uint32_t id = 0;
  437. uint32_t mask = 0;
  438. const uavcan::CanFilterConfig* const cfg = filter_configs + i;
  439. if ((cfg->id & uavcan::CanFrame::FlagEFF) || !(cfg->mask & uavcan::CanFrame::FlagEFF)) {
  440. id = (cfg->id & uavcan::CanFrame::MaskExtID);
  441. mask = (cfg->mask & uavcan::CanFrame::MaskExtID);
  442. filter_ptr[num_extid*2] = 0x1U << 29 | id; // Classic CAN Filter
  443. filter_ptr[num_extid*2 + 1] = 0x2U << 30 | mask; //Store in Rx FIFO0 if filter matches
  444. num_extid++;
  445. }
  446. }
  447. }
  448. MessageRam_.EndAddress = SRAMCAN_BASE + (FDCANMessageRAMOffset_ * 4U);
  449. if (MessageRam_.EndAddress > MESSAGE_RAM_END_ADDR) {
  450. //We are overflowing the limit of Allocated Message RAM
  451. AP_HAL::panic("CANFDIface: Message RAM Overflow!");
  452. }
  453. can_->CCCR &= ~FDCAN_CCCR_INIT; // Leave init mode
  454. return 0;
  455. }
  456. uavcan::uint16_t CanIface::getNumFilters() const
  457. {
  458. return MAX_FILTER_LIST_SIZE;
  459. }
  460. int CanIface::init(const uavcan::uint32_t bitrate, const OperatingMode mode)
  461. {
  462. // Setup FDCAN for configuration mode and disable all interrupts
  463. {
  464. CriticalSectionLocker lock;
  465. can_->CCCR &= ~FDCAN_CCCR_CSR; // Exit sleep mode
  466. while ((can_->CCCR & FDCAN_CCCR_CSA) == FDCAN_CCCR_CSA) {} //Wait for wake up ack
  467. can_->CCCR |= FDCAN_CCCR_INIT; // Request init
  468. while ((can_->CCCR & FDCAN_CCCR_INIT) == 0) {}
  469. can_->CCCR |= FDCAN_CCCR_CCE; //Enable Config change
  470. can_->IE = 0; // Disable interrupts while initialization is in progress
  471. }
  472. /*
  473. * Object state - interrupts are disabled, so it's safe to modify it now
  474. */
  475. rx_queue_.reset();
  476. error_cnt_ = 0;
  477. served_aborts_cnt_ = 0;
  478. uavcan::fill_n(pending_tx_, NumTxMailboxes, TxItem());
  479. peak_tx_mailbox_index_ = 0;
  480. had_activity_ = false;
  481. /*
  482. * CAN timings for this bitrate
  483. */
  484. Timings timings;
  485. const int timings_res = computeTimings(bitrate, timings);
  486. if (timings_res < 0) {
  487. can_->CCCR &= ~FDCAN_CCCR_INIT;
  488. return timings_res;
  489. }
  490. UAVCAN_STM32_LOG("Timings: presc=%u sjw=%u bs1=%u bs2=%u",
  491. unsigned(timings.prescaler), unsigned(timings.sjw), unsigned(timings.bs1), unsigned(timings.bs2));
  492. //setup timing register
  493. //TODO: Do timing calculations for FDCAN
  494. can_->NBTP = ((timings.sjw << FDCAN_NBTP_NSJW_Pos) |
  495. (timings.bs1 << FDCAN_NBTP_NTSEG1_Pos) |
  496. (timings.bs2 << FDCAN_NBTP_TSEG2_Pos) |
  497. (timings.prescaler << FDCAN_NBTP_NBRP_Pos));
  498. //RX Config
  499. can_->RXESC = 0; //Set for 8Byte Frames
  500. //Setup Message RAM
  501. setupMessageRam();
  502. //Clear all Interrupts
  503. can_->IR = 0x3FFFFFFF;
  504. //Enable Interrupts
  505. can_->IE = FDCAN_IE_TCE | // Transmit Complete interrupt enable
  506. FDCAN_IE_RF0NE | // RX FIFO 0 new message
  507. FDCAN_IE_RF0FE | // Rx FIFO 1 FIFO Full
  508. FDCAN_IE_RF1NE | // RX FIFO 1 new message
  509. FDCAN_IE_RF1FE; // Rx FIFO 1 FIFO Full
  510. can_->ILS = FDCAN_ILS_TCL; //Set Line 1 for Transmit Complete Event Interrupt
  511. can_->TXBTIE = 0xFFFFFFFF;
  512. can_->ILE = 0x3;
  513. //Leave Init
  514. can_->CCCR &= ~FDCAN_CCCR_INIT; // Leave init mode
  515. return 0;
  516. }
  517. void CanIface::setupMessageRam()
  518. {
  519. uint32_t num_elements = 0;
  520. // Rx FIFO 0 start address and element count
  521. num_elements = MIN((FDCAN_NUM_RXFIFO0_SIZE/FDCAN_FRAME_BUFFER_SIZE), 64U);
  522. if (num_elements) {
  523. can_->RXF0C = (FDCANMessageRAMOffset_ << 2) | (num_elements << 16);
  524. MessageRam_.RxFIFO0SA = SRAMCAN_BASE + (FDCANMessageRAMOffset_ * 4U);
  525. FDCANMessageRAMOffset_ += num_elements*FDCAN_FRAME_BUFFER_SIZE;
  526. }
  527. // Tx FIFO/queue start address and element count
  528. num_elements = MIN((FDCAN_TX_FIFO_BUFFER_SIZE/FDCAN_FRAME_BUFFER_SIZE), 32U);
  529. if (num_elements) {
  530. can_->TXBC = (FDCANMessageRAMOffset_ << 2) | (num_elements << 24);
  531. can_->TXBC |= 1U << 30; //Set Queue mode
  532. MessageRam_.TxFIFOQSA = SRAMCAN_BASE + (FDCANMessageRAMOffset_ * 4U);
  533. FDCANMessageRAMOffset_ += num_elements*FDCAN_FRAME_BUFFER_SIZE;
  534. }
  535. MessageRam_.EndAddress = SRAMCAN_BASE + (FDCANMessageRAMOffset_ * 4U);
  536. if (MessageRam_.EndAddress > MESSAGE_RAM_END_ADDR) {
  537. //We are overflowing the limit of Allocated Message RAM
  538. AP_HAL::panic("CANFDIface: Message RAM Overflow!");
  539. return;
  540. }
  541. }
  542. void CanIface::handleTxCompleteInterrupt(const uavcan::uint64_t utc_usec)
  543. {
  544. for (uint8_t i = 0; i < NumTxMailboxes; i++) {
  545. if ((can_->TXBTO & (1UL << i))) {
  546. if (pending_tx_[i].loopback && had_activity_) {
  547. rx_queue_.push(pending_tx_[i].frame, utc_usec, uavcan::CanIOFlagLoopback);
  548. }
  549. }
  550. }
  551. }
  552. bool CanIface::readRxFIFO(uavcan::uint8_t fifo_index)
  553. {
  554. UAVCAN_ASSERT(fifo_index < 2);
  555. uint32_t *frame_ptr;
  556. uint32_t index;
  557. uavcan::uint64_t utc_usec = clock::getUtcUSecFromCanInterrupt();
  558. if (fifo_index == 0) {
  559. //Check if RAM allocated to RX FIFO
  560. if ((can_->RXF0C & FDCAN_RXF0C_F0S) == 0) {
  561. UAVCAN_ASSERT(0);
  562. return false;
  563. }
  564. //Register Message Lost as a hardware error
  565. if ((can_->RXF0S & FDCAN_RXF0S_RF0L) != 0) {
  566. error_cnt_++;
  567. }
  568. if ((can_->RXF0S & FDCAN_RXF0S_F0FL) == 0) {
  569. return false; //No More messages in FIFO
  570. } else {
  571. index = ((can_->RXF0S & FDCAN_RXF0S_F0GI) >> 8);
  572. frame_ptr = (uint32_t *)(MessageRam_.RxFIFO0SA + (index * FDCAN_FRAME_BUFFER_SIZE * 4));
  573. }
  574. } else if (fifo_index == 1) {
  575. //Check if RAM allocated to RX FIFO
  576. if ((can_->RXF1C & FDCAN_RXF1C_F1S) == 0) {
  577. UAVCAN_ASSERT(0);
  578. return false;
  579. }
  580. //Register Message Lost as a hardware error
  581. if ((can_->RXF1S & FDCAN_RXF1S_RF1L) != 0) {
  582. error_cnt_++;
  583. }
  584. if ((can_->RXF1S & FDCAN_RXF1S_F1FL) == 0) {
  585. return false;
  586. } else {
  587. index = ((can_->RXF1S & FDCAN_RXF1S_F1GI) >> 8);
  588. frame_ptr = (uint32_t *)(MessageRam_.RxFIFO1SA + (index * FDCAN_FRAME_BUFFER_SIZE * 4));
  589. }
  590. } else {
  591. return false;
  592. }
  593. // Read the frame contents
  594. uavcan::CanFrame frame;
  595. uint32_t id = frame_ptr[0];
  596. if ((id & fdcan::IDE) == 0) {
  597. //Standard ID
  598. frame.id = ((id & fdcan::STID_MASK) >> 18) & uavcan::CanFrame::MaskStdID;
  599. } else {
  600. //Extended ID
  601. frame.id = (id & fdcan::EXID_MASK) & uavcan::CanFrame::MaskExtID;
  602. frame.id |= uavcan::CanFrame::FlagEFF;
  603. }
  604. if ((id & fdcan::RTR) != 0) {
  605. frame.id |= uavcan::CanFrame::FlagRTR;
  606. }
  607. frame.dlc = (frame_ptr[1] & fdcan::DLC_MASK) >> 16;
  608. uint8_t *data = (uint8_t*)&frame_ptr[2];
  609. //We only handle Data Length of 8 Bytes for now
  610. for (uint8_t i = 0; i < 8; i++) {
  611. frame.data[i] = data[i];
  612. }
  613. //Acknowledge the FIFO entry we just read
  614. if (fifo_index == 0) {
  615. can_->RXF0A = index;
  616. } else if (fifo_index == 1) {
  617. can_->RXF1A = index;
  618. }
  619. /*
  620. * Store with timeout into the FIFO buffer and signal update event
  621. */
  622. rx_queue_.push(frame, utc_usec, 0);
  623. #if AP_UAVCAN_SLCAN_ENABLED
  624. _slcan_router.route_frame_to_slcan(this, frame, utc_usec);
  625. #endif
  626. return true;
  627. }
  628. void CanIface::handleRxInterrupt(uavcan::uint8_t fifo_index)
  629. {
  630. while (readRxFIFO(fifo_index)) {
  631. had_activity_ = true;
  632. }
  633. update_event_.signalFromInterrupt();
  634. }
  635. void CanIface::pollErrorFlagsFromISR()
  636. {
  637. const uavcan::uint8_t cel = can_->ECR >> 16;
  638. if (cel != 0) {
  639. for (int i = 0; i < NumTxMailboxes; i++) {
  640. if (!pending_tx_[i].abort_on_error) {
  641. continue;
  642. }
  643. if (((1 << pending_tx_[i].index) & can_->TXBRP)) {
  644. can_->TXBCR = 1 << pending_tx_[i].index; // Goodnight sweet transmission
  645. error_cnt_++;
  646. served_aborts_cnt_++;
  647. }
  648. }
  649. }
  650. }
  651. void CanIface::discardTimedOutTxMailboxes(uavcan::MonotonicTime current_time)
  652. {
  653. CriticalSectionLocker lock;
  654. for (int i = 0; i < NumTxMailboxes; i++) {
  655. if (((1 << pending_tx_[i].index) & can_->TXBRP) && pending_tx_[i].deadline < current_time) {
  656. can_->TXBCR = 1 << pending_tx_[i].index; // Goodnight sweet transmission
  657. error_cnt_++;
  658. }
  659. }
  660. }
  661. bool CanIface::canAcceptNewTxFrame(const uavcan::CanFrame& frame) const
  662. {
  663. //Check if Tx FIFO is allocated
  664. if ((can_->TXBC & FDCAN_TXBC_TFQS) == 0) {
  665. return false;
  666. }
  667. if ((can_->TXFQS & FDCAN_TXFQS_TFQF) != 0) {
  668. return false; //we don't have free space
  669. }
  670. return true;
  671. }
  672. bool CanIface::isRxBufferEmpty() const
  673. {
  674. CriticalSectionLocker lock;
  675. return rx_queue_.getLength() == 0;
  676. }
  677. uavcan::uint64_t CanIface::getErrorCount() const
  678. {
  679. CriticalSectionLocker lock;
  680. return error_cnt_ + rx_queue_.getOverflowCount();
  681. }
  682. unsigned CanIface::getRxQueueLength() const
  683. {
  684. CriticalSectionLocker lock;
  685. return rx_queue_.getLength();
  686. }
  687. bool CanIface::hadActivity()
  688. {
  689. CriticalSectionLocker lock;
  690. const bool ret = had_activity_;
  691. had_activity_ = false;
  692. return ret;
  693. }
  694. /*
  695. * CanDriver
  696. */
  697. uavcan::CanSelectMasks CanDriver::makeSelectMasks(const uavcan::CanFrame* (& pending_tx)[uavcan::MaxCanIfaces]) const
  698. {
  699. uavcan::CanSelectMasks msk;
  700. for (uavcan::uint8_t i = 0; i < num_ifaces_; i++) {
  701. CanIface* iface = ifaces[if_int_to_gl_index_[i]];
  702. msk.read |= (iface->isRxBufferEmpty() ? 0 : 1) << i;
  703. if (pending_tx[i] != UAVCAN_NULLPTR) {
  704. msk.write |= (iface->canAcceptNewTxFrame(*pending_tx[i]) ? 1 : 0) << i;
  705. }
  706. }
  707. return msk;
  708. }
  709. bool CanDriver::hasReadableInterfaces() const
  710. {
  711. for (uavcan::uint8_t i = 0; i < num_ifaces_; i++) {
  712. if (!ifaces[if_int_to_gl_index_[i]]->isRxBufferEmpty()) {
  713. return true;
  714. }
  715. }
  716. return false;
  717. }
  718. uavcan::int16_t CanDriver::select(uavcan::CanSelectMasks& inout_masks,
  719. const uavcan::CanFrame* (& pending_tx)[uavcan::MaxCanIfaces],
  720. const uavcan::MonotonicTime blocking_deadline)
  721. {
  722. const uavcan::CanSelectMasks in_masks = inout_masks;
  723. const uavcan::MonotonicTime time = clock::getMonotonic();
  724. for (uavcan::uint8_t i = 0; i < num_ifaces_; i++) {
  725. CanIface* iface = ifaces[if_int_to_gl_index_[i]];
  726. iface->discardTimedOutTxMailboxes(time); // Check TX timeouts - this may release some TX slots
  727. {
  728. CriticalSectionLocker cs_locker;
  729. iface->pollErrorFlagsFromISR();
  730. }
  731. }
  732. inout_masks = makeSelectMasks(pending_tx); // Check if we already have some of the requested events
  733. if ((inout_masks.read & in_masks.read) != 0 ||
  734. (inout_masks.write & in_masks.write) != 0) {
  735. return 1;
  736. }
  737. (void)update_event_.wait(blocking_deadline - time); // Block until timeout expires or any iface updates
  738. inout_masks = makeSelectMasks(pending_tx); // Return what we got even if none of the requested events are set
  739. return 1; // Return value doesn't matter as long as it is non-negative
  740. }
  741. void CanDriver::initOnce()
  742. {
  743. {
  744. CriticalSectionLocker lock;
  745. RCC->APB1HRSTR |= RCC_APB1HRSTR_FDCANRST;
  746. RCC->APB1HRSTR &= ~RCC_APB1HRSTR_FDCANRST;
  747. RCC->APB1HENR |= RCC_APB1HENR_FDCANEN;
  748. }
  749. /*
  750. * IRQ
  751. */
  752. {
  753. CriticalSectionLocker lock;
  754. nvicEnableVector(FDCAN1_IT0_IRQn, UAVCAN_STM32_IRQ_PRIORITY_MASK);
  755. nvicEnableVector(FDCAN1_IT1_IRQn, UAVCAN_STM32_IRQ_PRIORITY_MASK);
  756. # if UAVCAN_STM32_NUM_IFACES > 1
  757. nvicEnableVector(FDCAN2_IT0_IRQn, UAVCAN_STM32_IRQ_PRIORITY_MASK);
  758. nvicEnableVector(FDCAN2_IT1_IRQn, UAVCAN_STM32_IRQ_PRIORITY_MASK);
  759. # endif
  760. }
  761. }
  762. int CanDriver::init(const uavcan::uint32_t bitrate, const CanIface::OperatingMode mode)
  763. {
  764. int res = 0;
  765. UAVCAN_STM32_LOG("Bitrate %lu mode %d", static_cast<unsigned long>(bitrate), static_cast<int>(mode));
  766. static bool initialized_once = false;
  767. if (!initialized_once) {
  768. initialized_once = true;
  769. UAVCAN_STM32_LOG("First initialization");
  770. initOnce();
  771. }
  772. /*
  773. * CAN1
  774. */
  775. UAVCAN_STM32_LOG("Initing iface 0...");
  776. ifaces[0] = &if0_; // This link must be initialized first,
  777. res = if0_.init(bitrate, mode); // otherwise an IRQ may fire while the interface is not linked yet;
  778. if (res < 0) { // a typical race condition.
  779. UAVCAN_STM32_LOG("Iface 0 init failed %i", res);
  780. ifaces[0] = UAVCAN_NULLPTR;
  781. goto fail;
  782. }
  783. /*
  784. * CAN2
  785. */
  786. #if UAVCAN_STM32_NUM_IFACES > 1
  787. UAVCAN_STM32_LOG("Initing iface 1...");
  788. ifaces[1] = &if1_; // Same thing here.
  789. res = if1_.init(bitrate, mode);
  790. if (res < 0) {
  791. UAVCAN_STM32_LOG("Iface 1 init failed %i", res);
  792. ifaces[1] = UAVCAN_NULLPTR;
  793. goto fail;
  794. }
  795. #endif
  796. UAVCAN_STM32_LOG("CAN drv init OK");
  797. UAVCAN_ASSERT(res >= 0);
  798. return res;
  799. fail:
  800. UAVCAN_STM32_LOG("CAN drv init failed %i", res);
  801. UAVCAN_ASSERT(res < 0);
  802. return res;
  803. }
  804. bool CanDriver::clock_init_ = false;
  805. void CanDriver::initOnce(uavcan::uint8_t can_number, bool enable_irqs)
  806. {
  807. //Only do it once
  808. //Doing it second time will reset the previously initialised bus
  809. if (!clock_init_) {
  810. CriticalSectionLocker lock;
  811. RCC->APB1HENR |= RCC_APB1HENR_FDCANEN;
  812. RCC->APB1HRSTR |= RCC_APB1HRSTR_FDCANRST;
  813. RCC->APB1HRSTR &= ~RCC_APB1HRSTR_FDCANRST;
  814. clock_init_ = true;
  815. }
  816. if (!enable_irqs) {
  817. return;
  818. }
  819. /*
  820. * IRQ
  821. */
  822. {
  823. CriticalSectionLocker lock;
  824. if (can_number == 0) {
  825. nvicEnableVector(FDCAN1_IT0_IRQn, UAVCAN_STM32_IRQ_PRIORITY_MASK);
  826. nvicEnableVector(FDCAN1_IT1_IRQn, UAVCAN_STM32_IRQ_PRIORITY_MASK);
  827. }
  828. # if UAVCAN_STM32_NUM_IFACES > 1
  829. else if (can_number == 1) {
  830. nvicEnableVector(FDCAN2_IT0_IRQn, UAVCAN_STM32_IRQ_PRIORITY_MASK);
  831. nvicEnableVector(FDCAN2_IT1_IRQn, UAVCAN_STM32_IRQ_PRIORITY_MASK);
  832. }
  833. # endif
  834. }
  835. }
  836. int CanDriver::init(const uavcan::uint32_t bitrate, const CanIface::OperatingMode mode, uavcan::uint8_t can_number)
  837. {
  838. int res = 0;
  839. UAVCAN_STM32_LOG("Bitrate %lu mode %d", static_cast<unsigned long>(bitrate), static_cast<int>(mode));
  840. if (can_number > UAVCAN_STM32_NUM_IFACES) {
  841. res = -1;
  842. goto fail;
  843. }
  844. static bool initialized_once[UAVCAN_STM32_NUM_IFACES] = {false};
  845. if (!initialized_once[can_number]) {
  846. initialized_once[can_number] = true;
  847. initialized_by_me_[can_number] = true;
  848. if (can_number == 1 && !initialized_once[0]) {
  849. UAVCAN_STM32_LOG("Iface 0 is not initialized yet but we need it for Iface 1, trying to init it");
  850. UAVCAN_STM32_LOG("Enabling CAN iface 0");
  851. initOnce(0, false);
  852. UAVCAN_STM32_LOG("Initing iface 0...");
  853. res = if0_.init(bitrate, mode);
  854. if (res < 0) {
  855. UAVCAN_STM32_LOG("Iface 0 init failed %i", res);
  856. goto fail;
  857. }
  858. }
  859. UAVCAN_STM32_LOG("Enabling CAN iface %d", can_number);
  860. initOnce(can_number, true);
  861. } else if (!initialized_by_me_[can_number]) {
  862. UAVCAN_STM32_LOG("CAN iface %d initialized in another CANDriver!", can_number);
  863. res = -2;
  864. goto fail;
  865. }
  866. if (can_number == 0) {
  867. /*
  868. * CAN1
  869. */
  870. UAVCAN_STM32_LOG("Initing iface 0...");
  871. ifaces[0] = &if0_; // This link must be initialized first,
  872. res = if0_.init(bitrate, mode); // otherwise an IRQ may fire while the interface is not linked yet;
  873. if (res < 0) { // a typical race condition.
  874. UAVCAN_STM32_LOG("Iface 0 init failed %i", res);
  875. ifaces[0] = UAVCAN_NULLPTR;
  876. goto fail;
  877. }
  878. } else if (can_number == 1) {
  879. /*
  880. * CAN2
  881. */
  882. #if UAVCAN_STM32_NUM_IFACES > 1
  883. UAVCAN_STM32_LOG("Initing iface 1...");
  884. ifaces[1] = &if1_; // Same thing here.
  885. res = if1_.init(bitrate, mode);
  886. if (res < 0) {
  887. UAVCAN_STM32_LOG("Iface 1 init failed %i", res);
  888. ifaces[1] = UAVCAN_NULLPTR;
  889. goto fail;
  890. }
  891. #endif
  892. }
  893. if_int_to_gl_index_[num_ifaces_++] = can_number;
  894. UAVCAN_STM32_LOG("CAN drv init OK");
  895. UAVCAN_ASSERT(res >= 0);
  896. return res;
  897. fail:
  898. UAVCAN_STM32_LOG("CAN drv init failed %i", res);
  899. UAVCAN_ASSERT(res < 0);
  900. return res;
  901. }
  902. CanIface* CanDriver::getIface(uavcan::uint8_t iface_index)
  903. {
  904. if (iface_index < num_ifaces_) {
  905. return ifaces[if_int_to_gl_index_[iface_index]];
  906. }
  907. return UAVCAN_NULLPTR;
  908. }
  909. bool CanDriver::hadActivity()
  910. {
  911. for (uavcan::uint8_t i = 0; i < num_ifaces_; i++) {
  912. if (ifaces[if_int_to_gl_index_[i]]->hadActivity()) {
  913. return true;
  914. }
  915. }
  916. return false;
  917. }
  918. } // namespace uavcan_stm32
  919. /*
  920. * Interrupt handlers
  921. */
  922. extern "C"
  923. {
  924. UAVCAN_STM32_IRQ_HANDLER(FDCAN1_IT0_IRQHandler);
  925. UAVCAN_STM32_IRQ_HANDLER(FDCAN1_IT0_IRQHandler)
  926. {
  927. UAVCAN_STM32_IRQ_PROLOGUE();
  928. ChibiOS_CAN::handleInterrupt(0, 0);
  929. UAVCAN_STM32_IRQ_EPILOGUE();
  930. }
  931. UAVCAN_STM32_IRQ_HANDLER(FDCAN1_IT1_IRQHandler);
  932. UAVCAN_STM32_IRQ_HANDLER(FDCAN1_IT1_IRQHandler)
  933. {
  934. UAVCAN_STM32_IRQ_PROLOGUE();
  935. ChibiOS_CAN::handleInterrupt(0, 1);
  936. UAVCAN_STM32_IRQ_EPILOGUE();
  937. }
  938. # if UAVCAN_STM32_NUM_IFACES > 1
  939. UAVCAN_STM32_IRQ_HANDLER(FDCAN2_IT0_IRQHandler);
  940. UAVCAN_STM32_IRQ_HANDLER(FDCAN2_IT0_IRQHandler)
  941. {
  942. UAVCAN_STM32_IRQ_PROLOGUE();
  943. ChibiOS_CAN::handleInterrupt(1, 0);
  944. UAVCAN_STM32_IRQ_EPILOGUE();
  945. }
  946. UAVCAN_STM32_IRQ_HANDLER(FDCAN2_IT1_IRQHandler);
  947. UAVCAN_STM32_IRQ_HANDLER(FDCAN2_IT1_IRQHandler)
  948. {
  949. UAVCAN_STM32_IRQ_PROLOGUE();
  950. ChibiOS_CAN::handleInterrupt(1, 1);
  951. UAVCAN_STM32_IRQ_EPILOGUE();
  952. }
  953. # endif
  954. } // extern "C"
  955. #endif //defined(STM32H7XX)
  956. #endif //HAL_WITH_UAVCAN