Split a code
This commit is contained in:
parent
56c68af52e
commit
3eb9321b27
45
src/main.rs
45
src/main.rs
|
@ -1,52 +1,20 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use core::cmp::Ordering;
|
||||
mod model;
|
||||
|
||||
use bxcan::Frame;
|
||||
use heapless::binary_heap::{BinaryHeap, Max};
|
||||
use panic_halt as _;
|
||||
use stm32f1xx_hal::pac::Interrupt;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PriorityFrame(Frame);
|
||||
|
||||
impl Ord for PriorityFrame {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.0.priority().cmp(&other.0.priority())
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for PriorityFrame {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for PriorityFrame {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.cmp(other) == Ordering::Equal
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for PriorityFrame {}
|
||||
|
||||
fn enqueue_frame(queue: &mut BinaryHeap<PriorityFrame, Max, 16>, frame: Frame) {
|
||||
queue.push(PriorityFrame(frame)).unwrap();
|
||||
rtic::pend(Interrupt::USB_HP_CAN_TX);
|
||||
}
|
||||
|
||||
#[rtic::app(device = stm32f1xx_hal::pac)]
|
||||
mod app {
|
||||
use heapless::binary_heap::{BinaryHeap, Max};
|
||||
|
||||
use super::{enqueue_frame, PriorityFrame};
|
||||
use crate::model::PriorityFrame;
|
||||
use bxcan::{filter::Mask32, Fifo, Frame, Interrupts, Rx0, StandardId, Tx};
|
||||
use heapless::binary_heap::{BinaryHeap, Max};
|
||||
use stm32f1xx_hal::{
|
||||
can::Can,
|
||||
device::TIM2,
|
||||
gpio::{Output, Pin},
|
||||
pac::CAN1,
|
||||
pac::{CAN1, Interrupt},
|
||||
prelude::*,
|
||||
timer::Delay,
|
||||
};
|
||||
|
@ -130,6 +98,11 @@ mod app {
|
|||
[b[0], b[1], b[0], b[1], b[0], b[1], b[0], b[1]]
|
||||
}
|
||||
|
||||
fn enqueue_frame(queue: &mut BinaryHeap<PriorityFrame, Max, 16>, frame: Frame) {
|
||||
queue.push(PriorityFrame(frame)).unwrap();
|
||||
rtic::pend(Interrupt::USB_HP_CAN_TX);
|
||||
}
|
||||
|
||||
#[idle(shared = [can_tx_queue, tx_count], local = [delay])]
|
||||
fn idle(cx: idle::Context) -> ! {
|
||||
let mut tx_queue = cx.shared.can_tx_queue;
|
||||
|
|
26
src/model.rs
Normal file
26
src/model.rs
Normal file
|
@ -0,0 +1,26 @@
|
|||
use core::cmp::Ordering;
|
||||
|
||||
use bxcan::Frame;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PriorityFrame(pub Frame);
|
||||
|
||||
impl Ord for PriorityFrame {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.0.priority().cmp(&other.0.priority())
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for PriorityFrame {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for PriorityFrame {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.cmp(other) == Ordering::Equal
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for PriorityFrame {}
|
Loading…
Reference in New Issue
Block a user