Removed socket ownership checking, giving up on that effort for now

This commit is contained in:
Jonah Dahlquist 2019-09-19 10:00:36 -05:00 committed by Jonah Dahlquist
commit b6a52cbf8e
10 changed files with 81 additions and 171 deletions

View file

@ -5,35 +5,17 @@ use embedded_hal::digital::v2::OutputPin;
use embedded_hal::spi::FullDuplex;
use network::Network;
use register;
use socket::{OwnedSockets, Socket, Sockets};
use socket::Socket;
use udp::UdpSocket;
pub struct W5500<SpiBus: ActiveBus, NetworkImpl: Network> {
bus: SpiBus,
pub bus: SpiBus,
network: NetworkImpl,
sockets: OwnedSockets,
}
impl<SpiBus: ActiveBus, NetworkImpl: Network> W5500<SpiBus, NetworkImpl> {
pub fn new(bus: SpiBus, network: NetworkImpl, sockets: OwnedSockets) -> Self {
W5500 {
bus,
network,
sockets,
}
}
pub fn sockets(&mut self) -> Sockets {
(
&mut self.sockets.0,
&mut self.sockets.1,
&mut self.sockets.2,
&mut self.sockets.3,
&mut self.sockets.4,
&mut self.sockets.5,
&mut self.sockets.6,
&mut self.sockets.7,
)
pub fn new(bus: SpiBus, network: NetworkImpl) -> Self {
W5500 { bus, network }
}
pub fn reset(mut self) -> Result<UninitializedW5500<SpiBus>, SpiBus::Error> {
@ -50,22 +32,16 @@ impl<SpiBus: ActiveBus, NetworkImpl: Network> W5500<SpiBus, NetworkImpl> {
Ok(())
}
pub fn open_udp_socket<'a, SocketImpl: Socket>(
pub fn open_udp_socket<SocketImpl: Socket>(
self,
port: u16,
socket: &'a mut SocketImpl,
) -> Result<UdpSocket<'a, SpiBus, NetworkImpl, SocketImpl>, OpenSocketError<SpiBus::Error>>
{
if socket.is_owned_by(&self.sockets) {
UdpSocket::new(port, self.bus, self.network, self.sockets, socket)
.map_err(|e| OpenSocketError::BusError(e))
} else {
Err(OpenSocketError::ForeignSocketError)
}
socket: SocketImpl,
) -> Result<UdpSocket<SpiBus, NetworkImpl, SocketImpl>, SpiBus::Error> {
UdpSocket::new(port, self, socket)
}
pub fn release(self) -> (SpiBus, NetworkImpl, OwnedSockets) {
(self.bus, self.network, self.sockets)
pub fn release(self) -> (SpiBus, NetworkImpl) {
(self.bus, self.network)
}
}
@ -74,20 +50,13 @@ impl<Spi: FullDuplex<u8>, ChipSelect: OutputPin, NetworkImpl: Network>
{
pub fn deactivate(self) -> (InactiveW5500<FourWire<ChipSelect>, NetworkImpl>, Spi) {
let (bus, spi) = self.bus.deactivate();
(InactiveW5500::new(bus, self.network, self.sockets), spi)
(InactiveW5500::new(bus, self.network), spi)
}
}
impl<Spi: FullDuplex<u8>, NetworkImpl: Network> W5500<ActiveThreeWire<Spi>, NetworkImpl> {
pub fn deactivate(self) -> (InactiveW5500<ThreeWire, NetworkImpl>, Spi) {
let (bus, spi) = self.bus.deactivate();
(InactiveW5500::new(bus, self.network, self.sockets), spi)
(InactiveW5500::new(bus, self.network), spi)
}
}
pub enum OpenSocketError<BusError> {
ForeignSocketError,
BusError(BusError),
}
pub struct ForeignSocketError {}