aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs220
1 files changed, 115 insertions, 105 deletions
diff --git a/src/lib.rs b/src/lib.rs
index c7e0285f9..b8ce2e2a2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -32,13 +32,6 @@ fn swap16(x: u32) -> u32 {
32 x.rotate_left(16) 32 x.rotate_left(16)
33} 33}
34 34
35// CYW_SPID command structure constants.
36const WRITE: bool = true;
37const READ: bool = false;
38const INC_ADDR: bool = true;
39#[allow(unused)]
40const FIXED_ADDR: bool = false;
41
42fn cmd_word(write: bool, incr: bool, func: u32, addr: u32, len: u32) -> u32 { 35fn cmd_word(write: bool, incr: bool, func: u32, addr: u32, len: u32) -> u32 {
43 (write as u32) << 31 | (incr as u32) << 30 | (func & 0b11) << 28 | (addr & 0x1FFFF) << 11 | (len & 0x7FF) 36 (write as u32) << 31 | (incr as u32) << 30 | (func & 0b11) << 28 | (addr & 0x1FFFF) << 11 | (len & 0x7FF)
44} 37}
@@ -48,104 +41,114 @@ fn slice8_mut(x: &mut [u32]) -> &mut [u8] {
48 unsafe { slice::from_raw_parts_mut(x.as_mut_ptr() as _, len) } 41 unsafe { slice::from_raw_parts_mut(x.as_mut_ptr() as _, len) }
49} 42}
50 43
51const FUNC_BUS: u32 = 0; 44mod constants {
52const FUNC_BACKPLANE: u32 = 1; 45 #![allow(unused)]
53const FUNC_WLAN: u32 = 2; 46 pub(crate) const FUNC_BUS: u32 = 0;
54const FUNC_BT: u32 = 3; 47 pub(crate) const FUNC_BACKPLANE: u32 = 1;
55 48 pub(crate) const FUNC_WLAN: u32 = 2;
56const REG_BUS_CTRL: u32 = 0x0; 49 pub(crate) const FUNC_BT: u32 = 3;
57const REG_BUS_INTERRUPT: u32 = 0x04; // 16 bits - Interrupt status 50
58const REG_BUS_INTERRUPT_ENABLE: u32 = 0x06; // 16 bits - Interrupt mask 51 pub(crate) const REG_BUS_CTRL: u32 = 0x0;
59const REG_BUS_STATUS: u32 = 0x8; 52 pub(crate) const REG_BUS_INTERRUPT: u32 = 0x04; // 16 bits - Interrupt status
60const REG_BUS_TEST_RO: u32 = 0x14; 53 pub(crate) const REG_BUS_INTERRUPT_ENABLE: u32 = 0x06; // 16 bits - Interrupt mask
61const REG_BUS_TEST_RW: u32 = 0x18; 54 pub(crate) const REG_BUS_STATUS: u32 = 0x8;
62const REG_BUS_RESP_DELAY: u32 = 0x1c; 55 pub(crate) const REG_BUS_TEST_RO: u32 = 0x14;
63const WORD_LENGTH_32: u32 = 0x1; 56 pub(crate) const REG_BUS_TEST_RW: u32 = 0x18;
64const HIGH_SPEED: u32 = 0x10; 57 pub(crate) const REG_BUS_RESP_DELAY: u32 = 0x1c;
65 58 pub(crate) const WORD_LENGTH_32: u32 = 0x1;
66// SPI_STATUS_REGISTER bits 59 pub(crate) const HIGH_SPEED: u32 = 0x10;
67const STATUS_DATA_NOT_AVAILABLE: u32 = 0x00000001; 60
68const STATUS_UNDERFLOW: u32 = 0x00000002; 61 // SPI_STATUS_REGISTER bits
69const STATUS_OVERFLOW: u32 = 0x00000004; 62 pub(crate) const STATUS_DATA_NOT_AVAILABLE: u32 = 0x00000001;
70const STATUS_F2_INTR: u32 = 0x00000008; 63 pub(crate) const STATUS_UNDERFLOW: u32 = 0x00000002;
71const STATUS_F3_INTR: u32 = 0x00000010; 64 pub(crate) const STATUS_OVERFLOW: u32 = 0x00000004;
72const STATUS_F2_RX_READY: u32 = 0x00000020; 65 pub(crate) const STATUS_F2_INTR: u32 = 0x00000008;
73const STATUS_F3_RX_READY: u32 = 0x00000040; 66 pub(crate) const STATUS_F3_INTR: u32 = 0x00000010;
74const STATUS_HOST_CMD_DATA_ERR: u32 = 0x00000080; 67 pub(crate) const STATUS_F2_RX_READY: u32 = 0x00000020;
75const STATUS_F2_PKT_AVAILABLE: u32 = 0x00000100; 68 pub(crate) const STATUS_F3_RX_READY: u32 = 0x00000040;
76const STATUS_F2_PKT_LEN_MASK: u32 = 0x000FFE00; 69 pub(crate) const STATUS_HOST_CMD_DATA_ERR: u32 = 0x00000080;
77const STATUS_F2_PKT_LEN_SHIFT: u32 = 9; 70 pub(crate) const STATUS_F2_PKT_AVAILABLE: u32 = 0x00000100;
78const STATUS_F3_PKT_AVAILABLE: u32 = 0x00100000; 71 pub(crate) const STATUS_F2_PKT_LEN_MASK: u32 = 0x000FFE00;
79const STATUS_F3_PKT_LEN_MASK: u32 = 0xFFE00000; 72 pub(crate) const STATUS_F2_PKT_LEN_SHIFT: u32 = 9;
80const STATUS_F3_PKT_LEN_SHIFT: u32 = 21; 73 pub(crate) const STATUS_F3_PKT_AVAILABLE: u32 = 0x00100000;
81 74 pub(crate) const STATUS_F3_PKT_LEN_MASK: u32 = 0xFFE00000;
82const REG_BACKPLANE_GPIO_SELECT: u32 = 0x10005; 75 pub(crate) const STATUS_F3_PKT_LEN_SHIFT: u32 = 21;
83const REG_BACKPLANE_GPIO_OUTPUT: u32 = 0x10006; 76
84const REG_BACKPLANE_GPIO_ENABLE: u32 = 0x10007; 77 pub(crate) const REG_BACKPLANE_GPIO_SELECT: u32 = 0x10005;
85const REG_BACKPLANE_FUNCTION2_WATERMARK: u32 = 0x10008; 78 pub(crate) const REG_BACKPLANE_GPIO_OUTPUT: u32 = 0x10006;
86const REG_BACKPLANE_DEVICE_CONTROL: u32 = 0x10009; 79 pub(crate) const REG_BACKPLANE_GPIO_ENABLE: u32 = 0x10007;
87const REG_BACKPLANE_BACKPLANE_ADDRESS_LOW: u32 = 0x1000A; 80 pub(crate) const REG_BACKPLANE_FUNCTION2_WATERMARK: u32 = 0x10008;
88const REG_BACKPLANE_BACKPLANE_ADDRESS_MID: u32 = 0x1000B; 81 pub(crate) const REG_BACKPLANE_DEVICE_CONTROL: u32 = 0x10009;
89const REG_BACKPLANE_BACKPLANE_ADDRESS_HIGH: u32 = 0x1000C; 82 pub(crate) const REG_BACKPLANE_BACKPLANE_ADDRESS_LOW: u32 = 0x1000A;
90const REG_BACKPLANE_FRAME_CONTROL: u32 = 0x1000D; 83 pub(crate) const REG_BACKPLANE_BACKPLANE_ADDRESS_MID: u32 = 0x1000B;
91const REG_BACKPLANE_CHIP_CLOCK_CSR: u32 = 0x1000E; 84 pub(crate) const REG_BACKPLANE_BACKPLANE_ADDRESS_HIGH: u32 = 0x1000C;
92const REG_BACKPLANE_PULL_UP: u32 = 0x1000F; 85 pub(crate) const REG_BACKPLANE_FRAME_CONTROL: u32 = 0x1000D;
93const REG_BACKPLANE_READ_FRAME_BC_LOW: u32 = 0x1001B; 86 pub(crate) const REG_BACKPLANE_CHIP_CLOCK_CSR: u32 = 0x1000E;
94const REG_BACKPLANE_READ_FRAME_BC_HIGH: u32 = 0x1001C; 87 pub(crate) const REG_BACKPLANE_PULL_UP: u32 = 0x1000F;
95const REG_BACKPLANE_WAKEUP_CTRL: u32 = 0x1001E; 88 pub(crate) const REG_BACKPLANE_READ_FRAME_BC_LOW: u32 = 0x1001B;
96const REG_BACKPLANE_SLEEP_CSR: u32 = 0x1001F; 89 pub(crate) const REG_BACKPLANE_READ_FRAME_BC_HIGH: u32 = 0x1001C;
97 90 pub(crate) const REG_BACKPLANE_WAKEUP_CTRL: u32 = 0x1001E;
98const BACKPLANE_WINDOW_SIZE: usize = 0x8000; 91 pub(crate) const REG_BACKPLANE_SLEEP_CSR: u32 = 0x1001F;
99const BACKPLANE_ADDRESS_MASK: u32 = 0x7FFF; 92
100const BACKPLANE_ADDRESS_32BIT_FLAG: u32 = 0x08000; 93 pub(crate) const BACKPLANE_WINDOW_SIZE: usize = 0x8000;
101const BACKPLANE_MAX_TRANSFER_SIZE: usize = 64; 94 pub(crate) const BACKPLANE_ADDRESS_MASK: u32 = 0x7FFF;
102// Active Low Power (ALP) clock constants 95 pub(crate) const BACKPLANE_ADDRESS_32BIT_FLAG: u32 = 0x08000;
103const BACKPLANE_ALP_AVAIL_REQ: u8 = 0x08; 96 pub(crate) const BACKPLANE_MAX_TRANSFER_SIZE: usize = 64;
104const BACKPLANE_ALP_AVAIL: u8 = 0x40; 97 // Active Low Power (ALP) clock constants
105 98 pub(crate) const BACKPLANE_ALP_AVAIL_REQ: u8 = 0x08;
106// Broadcom AMBA (Advanced Microcontroller Bus Architecture) Interconnect (AI) 99 pub(crate) const BACKPLANE_ALP_AVAIL: u8 = 0x40;
107// constants 100
108const AI_IOCTRL_OFFSET: u32 = 0x408; 101 // Broadcom AMBA (Advanced Microcontroller Bus Architecture) Interconnect
109const AI_IOCTRL_BIT_FGC: u8 = 0x0002; 102 // (AI) pub (crate) constants
110const AI_IOCTRL_BIT_CLOCK_EN: u8 = 0x0001; 103 pub(crate) const AI_IOCTRL_OFFSET: u32 = 0x408;
111const AI_IOCTRL_BIT_CPUHALT: u8 = 0x0020; 104 pub(crate) const AI_IOCTRL_BIT_FGC: u8 = 0x0002;
112 105 pub(crate) const AI_IOCTRL_BIT_CLOCK_EN: u8 = 0x0001;
113const AI_RESETCTRL_OFFSET: u32 = 0x800; 106 pub(crate) const AI_IOCTRL_BIT_CPUHALT: u8 = 0x0020;
114const AI_RESETCTRL_BIT_RESET: u8 = 1; 107
115 108 pub(crate) const AI_RESETCTRL_OFFSET: u32 = 0x800;
116const AI_RESETSTATUS_OFFSET: u32 = 0x804; 109 pub(crate) const AI_RESETCTRL_BIT_RESET: u8 = 1;
117 110
118const TEST_PATTERN: u32 = 0x12345678; 111 pub(crate) const AI_RESETSTATUS_OFFSET: u32 = 0x804;
119const FEEDBEAD: u32 = 0xFEEDBEAD; 112
120 113 pub(crate) const TEST_PATTERN: u32 = 0x12345678;
121// SPI_INTERRUPT_REGISTER and SPI_INTERRUPT_ENABLE_REGISTER Bits 114 pub(crate) const FEEDBEAD: u32 = 0xFEEDBEAD;
122const IRQ_DATA_UNAVAILABLE: u16 = 0x0001; // Requested data not available; Clear by writing a "1" 115
123const IRQ_F2_F3_FIFO_RD_UNDERFLOW: u16 = 0x0002; 116 // SPI_INTERRUPT_REGISTER and SPI_INTERRUPT_ENABLE_REGISTER Bits
124const IRQ_F2_F3_FIFO_WR_OVERFLOW: u16 = 0x0004; 117 pub(crate) const IRQ_DATA_UNAVAILABLE: u16 = 0x0001; // Requested data not available; Clear by writing a "1"
125const IRQ_COMMAND_ERROR: u16 = 0x0008; // Cleared by writing 1 118 pub(crate) const IRQ_F2_F3_FIFO_RD_UNDERFLOW: u16 = 0x0002;
126const IRQ_DATA_ERROR: u16 = 0x0010; // Cleared by writing 1 119 pub(crate) const IRQ_F2_F3_FIFO_WR_OVERFLOW: u16 = 0x0004;
127const IRQ_F2_PACKET_AVAILABLE: u16 = 0x0020; 120 pub(crate) const IRQ_COMMAND_ERROR: u16 = 0x0008; // Cleared by writing 1
128const IRQ_F3_PACKET_AVAILABLE: u16 = 0x0040; 121 pub(crate) const IRQ_DATA_ERROR: u16 = 0x0010; // Cleared by writing 1
129const IRQ_F1_OVERFLOW: u16 = 0x0080; // Due to last write. Bkplane has pending write requests 122 pub(crate) const IRQ_F2_PACKET_AVAILABLE: u16 = 0x0020;
130const IRQ_MISC_INTR0: u16 = 0x0100; 123 pub(crate) const IRQ_F3_PACKET_AVAILABLE: u16 = 0x0040;
131const IRQ_MISC_INTR1: u16 = 0x0200; 124 pub(crate) const IRQ_F1_OVERFLOW: u16 = 0x0080; // Due to last write. Bkplane has pending write requests
132const IRQ_MISC_INTR2: u16 = 0x0400; 125 pub(crate) const IRQ_MISC_INTR0: u16 = 0x0100;
133const IRQ_MISC_INTR3: u16 = 0x0800; 126 pub(crate) const IRQ_MISC_INTR1: u16 = 0x0200;
134const IRQ_MISC_INTR4: u16 = 0x1000; 127 pub(crate) const IRQ_MISC_INTR2: u16 = 0x0400;
135const IRQ_F1_INTR: u16 = 0x2000; 128 pub(crate) const IRQ_MISC_INTR3: u16 = 0x0800;
136const IRQ_F2_INTR: u16 = 0x4000; 129 pub(crate) const IRQ_MISC_INTR4: u16 = 0x1000;
137const IRQ_F3_INTR: u16 = 0x8000; 130 pub(crate) const IRQ_F1_INTR: u16 = 0x2000;
138 131 pub(crate) const IRQ_F2_INTR: u16 = 0x4000;
139const IOCTL_CMD_UP: u32 = 2; 132 pub(crate) const IRQ_F3_INTR: u16 = 0x8000;
140const IOCTL_CMD_SET_SSID: u32 = 26; 133
141const IOCTL_CMD_ANTDIV: u32 = 64; 134 pub(crate) const IOCTL_CMD_UP: u32 = 2;
142const IOCTL_CMD_SET_VAR: u32 = 263; 135 pub(crate) const IOCTL_CMD_SET_SSID: u32 = 26;
143const IOCTL_CMD_GET_VAR: u32 = 262; 136 pub(crate) const IOCTL_CMD_ANTDIV: u32 = 64;
144const IOCTL_CMD_SET_PASSPHRASE: u32 = 268; 137 pub(crate) const IOCTL_CMD_SET_VAR: u32 = 263;
145 138 pub(crate) const IOCTL_CMD_GET_VAR: u32 = 262;
146const CHANNEL_TYPE_CONTROL: u8 = 0; 139 pub(crate) const IOCTL_CMD_SET_PASSPHRASE: u32 = 268;
147const CHANNEL_TYPE_EVENT: u8 = 1; 140
148const CHANNEL_TYPE_DATA: u8 = 2; 141 pub(crate) const CHANNEL_TYPE_CONTROL: u8 = 0;
142 pub(crate) const CHANNEL_TYPE_EVENT: u8 = 1;
143 pub(crate) const CHANNEL_TYPE_DATA: u8 = 2;
144
145 // CYW_SPID command structure constants.
146 pub(crate) const WRITE: bool = true;
147 pub(crate) const READ: bool = false;
148 pub(crate) const INC_ADDR: bool = true;
149 pub(crate) const FIXED_ADDR: bool = false;
150}
151use crate::constants::*;
149 152
150#[derive(Clone, Copy)] 153#[derive(Clone, Copy)]
151pub enum IoctlType { 154pub enum IoctlType {
@@ -153,6 +156,7 @@ pub enum IoctlType {
153 Set = 2, 156 Set = 2,
154} 157}
155 158
159#[allow(unused)]
156#[derive(Clone, Copy, PartialEq, Eq)] 160#[derive(Clone, Copy, PartialEq, Eq)]
157enum Core { 161enum Core {
158 WLAN = 0, 162 WLAN = 0,
@@ -170,6 +174,7 @@ impl Core {
170 } 174 }
171} 175}
172 176
177#[allow(unused)]
173struct Chip { 178struct Chip {
174 arm_core_base_address: u32, 179 arm_core_base_address: u32,
175 socsram_base_address: u32, 180 socsram_base_address: u32,
@@ -1077,6 +1082,7 @@ where
1077 true 1082 true
1078 } 1083 }
1079 1084
1085 #[allow(unused)]
1080 async fn bp_read(&mut self, mut addr: u32, mut data: &mut [u32]) { 1086 async fn bp_read(&mut self, mut addr: u32, mut data: &mut [u32]) {
1081 // It seems the HW force-aligns the addr 1087 // It seems the HW force-aligns the addr
1082 // to 2 if data.len() >= 2 1088 // to 2 if data.len() >= 2
@@ -1170,10 +1176,12 @@ where
1170 self.backplane_readn(addr, 2).await as u16 1176 self.backplane_readn(addr, 2).await as u16
1171 } 1177 }
1172 1178
1179 #[allow(unused)]
1173 async fn bp_write16(&mut self, addr: u32, val: u16) { 1180 async fn bp_write16(&mut self, addr: u32, val: u16) {
1174 self.backplane_writen(addr, val as u32, 2).await 1181 self.backplane_writen(addr, val as u32, 2).await
1175 } 1182 }
1176 1183
1184 #[allow(unused)]
1177 async fn bp_read32(&mut self, addr: u32) -> u32 { 1185 async fn bp_read32(&mut self, addr: u32) -> u32 {
1178 self.backplane_readn(addr, 4).await 1186 self.backplane_readn(addr, 4).await
1179 } 1187 }
@@ -1244,6 +1252,7 @@ where
1244 self.readn(func, addr, 2).await as u16 1252 self.readn(func, addr, 2).await as u16
1245 } 1253 }
1246 1254
1255 #[allow(unused)]
1247 async fn write16(&mut self, func: u32, addr: u32, val: u16) { 1256 async fn write16(&mut self, func: u32, addr: u32, val: u16) {
1248 self.writen(func, addr, val as u32, 2).await 1257 self.writen(func, addr, val as u32, 2).await
1249 } 1258 }
@@ -1252,6 +1261,7 @@ where
1252 self.readn(func, addr, 4).await 1261 self.readn(func, addr, 4).await
1253 } 1262 }
1254 1263
1264 #[allow(unused)]
1255 async fn write32(&mut self, func: u32, addr: u32, val: u32) { 1265 async fn write32(&mut self, func: u32, addr: u32, val: u32) {
1256 self.writen(func, addr, val, 4).await 1266 self.writen(func, addr, val, 4).await
1257 } 1267 }