diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/src/lib.rs b/src/lib.rs index b06eb36e6..133ce3161 100644 --- a/src/lib.rs +++ b/src/lib.rs | |||
| @@ -209,7 +209,6 @@ enum IoctlState { | |||
| 209 | } | 209 | } |
| 210 | 210 | ||
| 211 | pub struct State { | 211 | pub struct State { |
| 212 | ioctl_id: Cell<u16>, | ||
| 213 | ioctl_state: Cell<IoctlState>, | 212 | ioctl_state: Cell<IoctlState>, |
| 214 | 213 | ||
| 215 | tx_channel: Channel<NoopRawMutex, PacketBuf, 8>, | 214 | tx_channel: Channel<NoopRawMutex, PacketBuf, 8>, |
| @@ -220,7 +219,6 @@ pub struct State { | |||
| 220 | impl State { | 219 | impl State { |
| 221 | pub fn new() -> Self { | 220 | pub fn new() -> Self { |
| 222 | Self { | 221 | Self { |
| 223 | ioctl_id: Cell::new(0), | ||
| 224 | ioctl_state: Cell::new(IoctlState::Idle), | 222 | ioctl_state: Cell::new(IoctlState::Idle), |
| 225 | 223 | ||
| 226 | tx_channel: Channel::new(), | 224 | tx_channel: Channel::new(), |
| @@ -453,8 +451,6 @@ impl<'a> Control<'a> { | |||
| 453 | yield_now().await; | 451 | yield_now().await; |
| 454 | } | 452 | } |
| 455 | 453 | ||
| 456 | self.state.ioctl_id.set(self.state.ioctl_id.get().wrapping_add(1)); | ||
| 457 | |||
| 458 | self.state | 454 | self.state |
| 459 | .ioctl_state | 455 | .ioctl_state |
| 460 | .set(IoctlState::Pending { kind, cmd, iface, buf }); | 456 | .set(IoctlState::Pending { kind, cmd, iface, buf }); |
| @@ -522,7 +518,8 @@ pub struct Runner<'a, PWR, SPI> { | |||
| 522 | pwr: PWR, | 518 | pwr: PWR, |
| 523 | spi: SPI, | 519 | spi: SPI, |
| 524 | 520 | ||
| 525 | ioctl_seq: u8, | 521 | ioctl_id: u16, |
| 522 | sdpcm_seq: u8, | ||
| 526 | backplane_window: u32, | 523 | backplane_window: u32, |
| 527 | } | 524 | } |
| 528 | 525 | ||
| @@ -542,7 +539,8 @@ where | |||
| 542 | pwr, | 539 | pwr, |
| 543 | spi, | 540 | spi, |
| 544 | 541 | ||
| 545 | ioctl_seq: 0, | 542 | ioctl_id: 0, |
| 543 | sdpcm_seq: 0, | ||
| 546 | backplane_window: 0xAAAA_AAAA, | 544 | backplane_window: 0xAAAA_AAAA, |
| 547 | }; | 545 | }; |
| 548 | 546 | ||
| @@ -669,8 +667,7 @@ where | |||
| 669 | // Send stuff | 667 | // Send stuff |
| 670 | // TODO flow control | 668 | // TODO flow control |
| 671 | if let IoctlState::Pending { kind, cmd, iface, buf } = self.state.ioctl_state.get() { | 669 | if let IoctlState::Pending { kind, cmd, iface, buf } = self.state.ioctl_state.get() { |
| 672 | self.send_ioctl(kind, cmd, iface, unsafe { &*buf }, self.state.ioctl_id.get()) | 670 | self.send_ioctl(kind, cmd, iface, unsafe { &*buf }).await; |
| 673 | .await; | ||
| 674 | self.state.ioctl_state.set(IoctlState::Sent { buf }); | 671 | self.state.ioctl_state.set(IoctlState::Sent { buf }); |
| 675 | } | 672 | } |
| 676 | 673 | ||
| @@ -723,8 +720,8 @@ where | |||
| 723 | 720 | ||
| 724 | let total_len = SdpcmHeader::SIZE + BcdHeader::SIZE + packet.len(); | 721 | let total_len = SdpcmHeader::SIZE + BcdHeader::SIZE + packet.len(); |
| 725 | 722 | ||
| 726 | let seq = self.ioctl_seq; | 723 | let seq = self.sdpcm_seq; |
| 727 | self.ioctl_seq = self.ioctl_seq.wrapping_add(1); | 724 | self.sdpcm_seq = self.sdpcm_seq.wrapping_add(1); |
| 728 | 725 | ||
| 729 | let sdpcm_header = SdpcmHeader { | 726 | let sdpcm_header = SdpcmHeader { |
| 730 | len: total_len as u16, // TODO does this len need to be rounded up to u32? | 727 | len: total_len as u16, // TODO does this len need to be rounded up to u32? |
| @@ -802,7 +799,7 @@ where | |||
| 802 | trace!(" {:?}", cdc_header); | 799 | trace!(" {:?}", cdc_header); |
| 803 | 800 | ||
| 804 | if let IoctlState::Sent { buf } = self.state.ioctl_state.get() { | 801 | if let IoctlState::Sent { buf } = self.state.ioctl_state.get() { |
| 805 | if cdc_header.id == self.state.ioctl_id.get() { | 802 | if cdc_header.id == self.ioctl_id { |
| 806 | assert_eq!(cdc_header.status, 0); // todo propagate error instead | 803 | assert_eq!(cdc_header.status, 0); // todo propagate error instead |
| 807 | 804 | ||
| 808 | let resp_len = cdc_header.len as usize; | 805 | let resp_len = cdc_header.len as usize; |
| @@ -858,19 +855,20 @@ where | |||
| 858 | } | 855 | } |
| 859 | } | 856 | } |
| 860 | 857 | ||
| 861 | async fn send_ioctl(&mut self, kind: u32, cmd: u32, iface: u32, data: &[u8], id: u16) { | 858 | async fn send_ioctl(&mut self, kind: u32, cmd: u32, iface: u32, data: &[u8]) { |
| 862 | let mut buf = [0; 512]; | 859 | let mut buf = [0; 512]; |
| 863 | let buf8 = slice8_mut(&mut buf); | 860 | let buf8 = slice8_mut(&mut buf); |
| 864 | 861 | ||
| 865 | let total_len = SdpcmHeader::SIZE + CdcHeader::SIZE + data.len(); | 862 | let total_len = SdpcmHeader::SIZE + CdcHeader::SIZE + data.len(); |
| 866 | 863 | ||
| 867 | let seq = self.ioctl_seq; | 864 | let sdpcm_seq = self.sdpcm_seq; |
| 868 | self.ioctl_seq = self.ioctl_seq.wrapping_add(1); | 865 | self.sdpcm_seq = self.sdpcm_seq.wrapping_add(1); |
| 866 | self.ioctl_id = self.ioctl_id.wrapping_add(1); | ||
| 869 | 867 | ||
| 870 | let sdpcm_header = SdpcmHeader { | 868 | let sdpcm_header = SdpcmHeader { |
| 871 | len: total_len as u16, // TODO does this len need to be rounded up to u32? | 869 | len: total_len as u16, // TODO does this len need to be rounded up to u32? |
| 872 | len_inv: !total_len as u16, | 870 | len_inv: !total_len as u16, |
| 873 | sequence: seq, | 871 | sequence: sdpcm_seq, |
| 874 | channel_and_flags: 0, // control channel | 872 | channel_and_flags: 0, // control channel |
| 875 | next_length: 0, | 873 | next_length: 0, |
| 876 | header_length: SdpcmHeader::SIZE as _, | 874 | header_length: SdpcmHeader::SIZE as _, |
| @@ -883,7 +881,7 @@ where | |||
| 883 | cmd: cmd, | 881 | cmd: cmd, |
| 884 | len: data.len() as _, | 882 | len: data.len() as _, |
| 885 | flags: kind as u16 | (iface as u16) << 12, | 883 | flags: kind as u16 | (iface as u16) << 12, |
| 886 | id, | 884 | id: self.ioctl_id, |
| 887 | status: 0, | 885 | status: 0, |
| 888 | }; | 886 | }; |
| 889 | trace!("tx {:?}", sdpcm_header); | 887 | trace!("tx {:?}", sdpcm_header); |
