1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
use returncode::ReturnCode;
pub trait TxClient {
fn send_done(&self, buf: &'static mut [u8], acked: bool, result: ReturnCode);
}
pub trait RxClient {
fn receive(
&self,
buf: &'static mut [u8],
frame_len: usize,
crc_valid: bool,
result: ReturnCode,
);
}
pub trait ConfigClient {
fn config_done(&self, result: ReturnCode);
}
pub trait PowerClient {
fn changed(&self, on: bool);
}
pub const MIN_MHR_SIZE: usize = 9;
pub const MFR_SIZE: usize = 2;
pub const MAX_MTU: usize = 127;
pub const MIN_FRAME_SIZE: usize = MIN_MHR_SIZE + MFR_SIZE;
pub const MAX_FRAME_SIZE: usize = MAX_MTU;
pub const PSDU_OFFSET: usize = 2;
pub const MAX_BUF_SIZE: usize = PSDU_OFFSET + MAX_MTU;
pub const MIN_PAYLOAD_OFFSET: usize = PSDU_OFFSET + MIN_MHR_SIZE;
pub trait Radio: RadioConfig + RadioData {}
pub trait RadioConfig {
fn initialize(
&self,
spi_buf: &'static mut [u8],
reg_write: &'static mut [u8],
reg_read: &'static mut [u8],
) -> ReturnCode;
fn reset(&self) -> ReturnCode;
fn start(&self) -> ReturnCode;
fn stop(&self) -> ReturnCode;
fn is_on(&self) -> bool;
fn busy(&self) -> bool;
fn set_power_client(&self, client: &'static PowerClient);
fn config_commit(&self);
fn set_config_client(&self, client: &'static ConfigClient);
fn get_address(&self) -> u16;
fn get_address_long(&self) -> [u8; 8];
fn get_pan(&self) -> u16;
fn get_tx_power(&self) -> i8;
fn get_channel(&self) -> u8;
fn set_address(&self, addr: u16);
fn set_address_long(&self, addr: [u8; 8]);
fn set_pan(&self, id: u16);
fn set_tx_power(&self, power: i8) -> ReturnCode;
fn set_channel(&self, chan: u8) -> ReturnCode;
}
pub trait RadioData {
fn set_transmit_client(&self, client: &'static TxClient);
fn set_receive_client(&self, client: &'static RxClient, receive_buffer: &'static mut [u8]);
fn set_receive_buffer(&self, receive_buffer: &'static mut [u8]);
fn transmit(
&self,
spi_buf: &'static mut [u8],
frame_len: usize,
) -> (ReturnCode, Option<&'static mut [u8]>);
}