libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
ch32_usbcan_shared.cpp
1#include "ch32_usbcan_shared.hpp"
2
3namespace LibXR::CH32UsbCanShared
4{
5void register_usb_irq(IrqFn fn) { usb_irq_cb.store(fn, std::memory_order_release); }
6
7void register_can1_rx0(IrqFn fn)
8{
9 if constexpr (K_USB_CAN_IRQ_SHARE)
10 {
11 can1_rx0_cb.store(fn, std::memory_order_release);
12 }
13 else
14 {
15 (void)fn;
16 }
17}
18
19void register_can1_tx(IrqFn fn)
20{
21 if constexpr (K_USB_CAN_IRQ_SHARE)
22 {
23 can1_tx_cb.store(fn, std::memory_order_release);
24 }
25 else
26 {
27 (void)fn;
28 }
29}
30} // namespace LibXR::CH32UsbCanShared
31
32#if defined(RCC_APB1Periph_USB) && defined(CAN1)
33
34// NOLINTNEXTLINE(readability-identifier-naming)
35extern "C" __attribute__((interrupt("WCH-Interrupt-fast"))) void
36USB_LP_CAN1_RX0_IRQHandler(void)
37{
38 using namespace LibXR::CH32UsbCanShared;
39
40 if (auto fn = usb_irq_cb.load(std::memory_order_acquire))
41 {
42 fn();
43 }
44 if (auto fn = can1_rx0_cb.load(std::memory_order_acquire))
45 {
46 fn();
47 }
48}
49
50// NOLINTNEXTLINE(readability-identifier-naming)
51extern "C" __attribute__((interrupt("WCH-Interrupt-fast"))) void
52USB_HP_CAN1_TX_IRQHandler(void)
53{
54 using namespace LibXR::CH32UsbCanShared;
55
56 if (auto fn = usb_irq_cb.load(std::memory_order_acquire))
57 {
58 fn();
59 }
60 if (auto fn = can1_tx_cb.load(std::memory_order_acquire))
61 {
62 fn();
63 }
64}
65
66#endif