Skip to content

Commit 54dd611

Browse files
authored
Merge pull request #11 from torkeldanielsson/rustfmt
rustfmt
2 parents 2c5dce3 + 6d521c8 commit 54dd611

File tree

12 files changed

+265
-257
lines changed

12 files changed

+265
-257
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target/
2+
Cargo.lock

examples/ip.rs

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use cortex_m::asm;
77
use cortex_m_rt::{entry, exception};
88
use stm32f4xx_hal::{
99
gpio::GpioExt,
10-
stm32::{Peripherals, CorePeripherals, SYST, interrupt},
10+
stm32::{interrupt, CorePeripherals, Peripherals, SYST},
1111
};
1212

1313
use core::cell::RefCell;
@@ -16,12 +16,11 @@ use cortex_m::interrupt::Mutex;
1616
use core::fmt::Write;
1717
use cortex_m_semihosting::hio;
1818

19-
use smoltcp::time::Instant;
20-
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr,
21-
Ipv4Address};
22-
use smoltcp::iface::{NeighborCache, EthernetInterfaceBuilder};
19+
use log::{Level, LevelFilter, Metadata, Record};
20+
use smoltcp::iface::{EthernetInterfaceBuilder, NeighborCache};
2321
use smoltcp::socket::{SocketSet, TcpSocket, TcpSocketBuffer};
24-
use log::{Record, Level, Metadata, LevelFilter};
22+
use smoltcp::time::Instant;
23+
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address};
2524

2625
use stm32_eth::{Eth, RingEntry};
2726

@@ -37,8 +36,7 @@ impl log::Log for HioLogger {
3736
fn log(&self, record: &Record) {
3837
if self.enabled(record.metadata()) {
3938
let mut stdout = hio::hstdout().unwrap();
40-
writeln!(stdout, "{} - {}", record.level(), record.args())
41-
.unwrap();
39+
writeln!(stdout, "{} - {}", record.level(), record.args()).unwrap();
4240
}
4341
}
4442
fn flush(&self) {}
@@ -51,9 +49,11 @@ static ETH_PENDING: Mutex<RefCell<bool>> = Mutex::new(RefCell::new(false));
5149

5250
#[entry]
5351
fn main() -> ! {
54-
unsafe { log::set_logger(&LOGGER).unwrap(); }
52+
unsafe {
53+
log::set_logger(&LOGGER).unwrap();
54+
}
5555
log::set_max_level(LevelFilter::Info);
56-
56+
5757
let mut stdout = hio::hstdout().unwrap();
5858

5959
let p = Peripherals::take().unwrap();
@@ -68,15 +68,17 @@ fn main() -> ! {
6868
let gpioc = p.GPIOC.split();
6969
let gpiog = p.GPIOG.split();
7070
stm32_eth::setup_pins(
71-
gpioa.pa1, gpioa.pa2, gpioa.pa7, gpiob.pb13, gpioc.pc1,
72-
gpioc.pc4, gpioc.pc5, gpiog.pg11, gpiog.pg13
71+
gpioa.pa1, gpioa.pa2, gpioa.pa7, gpiob.pb13, gpioc.pc1, gpioc.pc4, gpioc.pc5, gpiog.pg11,
72+
gpiog.pg13,
7373
);
7474

7575
let mut rx_ring: [RingEntry<_>; 8] = Default::default();
7676
let mut tx_ring: [RingEntry<_>; 2] = Default::default();
7777
let mut eth = Eth::new(
78-
p.ETHERNET_MAC, p.ETHERNET_DMA,
79-
&mut rx_ring[..], &mut tx_ring[..]
78+
p.ETHERNET_MAC,
79+
p.ETHERNET_DMA,
80+
&mut rx_ring[..],
81+
&mut tx_ring[..],
8082
);
8183
eth.enable_interrupt(&mut cp.NVIC);
8284

@@ -96,32 +98,26 @@ fn main() -> ! {
9698
let mut server_tx_buffer = [0; 2048];
9799
let server_socket = TcpSocket::new(
98100
TcpSocketBuffer::new(&mut server_rx_buffer[..]),
99-
TcpSocketBuffer::new(&mut server_tx_buffer[..])
101+
TcpSocketBuffer::new(&mut server_tx_buffer[..]),
100102
);
101103
let mut sockets_storage = [None, None];
102104
let mut sockets = SocketSet::new(&mut sockets_storage[..]);
103105
let server_handle = sockets.add(server_socket);
104106

105107
writeln!(stdout, "Ready, listening at {}", ip_addr).unwrap();
106108
loop {
107-
let time: u64 = cortex_m::interrupt::free(|cs| {
108-
*TIME.borrow(cs)
109-
.borrow()
110-
});
109+
let time: u64 = cortex_m::interrupt::free(|cs| *TIME.borrow(cs).borrow());
111110
cortex_m::interrupt::free(|cs| {
112-
let mut eth_pending =
113-
ETH_PENDING.borrow(cs)
114-
.borrow_mut();
111+
let mut eth_pending = ETH_PENDING.borrow(cs).borrow_mut();
115112
*eth_pending = false;
116113
});
117114
match iface.poll(&mut sockets, Instant::from_millis(time as i64)) {
118115
Ok(true) => {
119116
let mut socket = sockets.get::<TcpSocket>(server_handle);
120117
if !socket.is_open() {
121-
socket.listen(80)
122-
.or_else(|e| {
123-
writeln!(stdout, "TCP listen error: {:?}", e)
124-
})
118+
socket
119+
.listen(80)
120+
.or_else(|e| writeln!(stdout, "TCP listen error: {:?}", e))
125121
.unwrap();
126122
}
127123

@@ -130,27 +126,25 @@ fn main() -> ! {
130126
.map(|_| {
131127
socket.close();
132128
})
133-
.or_else(|e| {
134-
writeln!(stdout, "TCP send error: {:?}", e)
135-
})
129+
.or_else(|e| writeln!(stdout, "TCP send error: {:?}", e))
136130
.unwrap();
137131
}
138-
},
132+
}
139133
Ok(false) => {
140134
// Sleep if no ethernet work is pending
141135
cortex_m::interrupt::free(|cs| {
142-
let eth_pending =
143-
ETH_PENDING.borrow(cs)
144-
.borrow_mut();
145-
if ! *eth_pending {
136+
let eth_pending = ETH_PENDING.borrow(cs).borrow_mut();
137+
if !*eth_pending {
146138
asm::wfi();
147139
// Awaken by interrupt
148140
}
149141
});
150-
},
142+
}
151143
Err(e) =>
152-
// Ignore malformed packets
153-
writeln!(stdout, "Error: {:?}", e).unwrap(),
144+
// Ignore malformed packets
145+
{
146+
writeln!(stdout, "Error: {:?}", e).unwrap()
147+
}
154148
}
155149
}
156150
}
@@ -164,19 +158,15 @@ fn setup_systick(syst: &mut SYST) {
164158
#[exception]
165159
fn SysTick() {
166160
cortex_m::interrupt::free(|cs| {
167-
let mut time =
168-
TIME.borrow(cs)
169-
.borrow_mut();
161+
let mut time = TIME.borrow(cs).borrow_mut();
170162
*time += 1;
171163
})
172164
}
173165

174166
#[interrupt]
175167
fn ETH() {
176168
cortex_m::interrupt::free(|cs| {
177-
let mut eth_pending =
178-
ETH_PENDING.borrow(cs)
179-
.borrow_mut();
169+
let mut eth_pending = ETH_PENDING.borrow(cs).borrow_mut();
180170
*eth_pending = true;
181171
});
182172

examples/pktgen.rs

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,29 @@
33

44
extern crate panic_itm;
55

6-
use cortex_m_rt::{entry, exception};
76
use core::cell::RefCell;
87
use core::default::Default;
8+
use cortex_m_rt::{entry, exception};
99

1010
use cortex_m::asm;
1111
use cortex_m::interrupt::Mutex;
1212
use stm32f4xx_hal::{
1313
gpio::GpioExt,
14-
stm32::{Peripherals, CorePeripherals, SYST, interrupt},
14+
stm32::{interrupt, CorePeripherals, Peripherals, SYST},
1515
};
1616

1717
use core::fmt::Write;
1818
use cortex_m_semihosting::hio;
1919

2020
use stm32_eth::{Eth, RingEntry, TxError};
2121

22-
2322
const SRC_MAC: [u8; 6] = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF];
2423
const DST_MAC: [u8; 6] = [0x00, 0x00, 0xBE, 0xEF, 0xDE, 0xAD];
2524
const ETH_TYPE: [u8; 2] = [0x80, 0x00];
2625

2726
static TIME: Mutex<RefCell<usize>> = Mutex::new(RefCell::new(0));
2827
static ETH_PENDING: Mutex<RefCell<bool>> = Mutex::new(RefCell::new(false));
2928

30-
3129
#[entry]
3230
fn main() -> ! {
3331
let mut stdout = hio::hstdout().unwrap();
@@ -44,15 +42,17 @@ fn main() -> ! {
4442
let gpioc = p.GPIOC.split();
4543
let gpiog = p.GPIOG.split();
4644
stm32_eth::setup_pins(
47-
gpioa.pa1, gpioa.pa2, gpioa.pa7, gpiob.pb13, gpioc.pc1,
48-
gpioc.pc4, gpioc.pc5, gpiog.pg11, gpiog.pg13
45+
gpioa.pa1, gpioa.pa2, gpioa.pa7, gpiob.pb13, gpioc.pc1, gpioc.pc4, gpioc.pc5, gpiog.pg11,
46+
gpiog.pg13,
4947
);
5048

5149
let mut rx_ring: [RingEntry<_>; 16] = Default::default();
5250
let mut tx_ring: [RingEntry<_>; 8] = Default::default();
5351
let mut eth = Eth::new(
54-
p.ETHERNET_MAC, p.ETHERNET_DMA,
55-
&mut rx_ring[..], &mut tx_ring[..]
52+
p.ETHERNET_MAC,
53+
p.ETHERNET_DMA,
54+
&mut rx_ring[..],
55+
&mut tx_ring[..],
5656
);
5757
eth.enable_interrupt(&mut cp.NVIC);
5858

@@ -65,20 +65,21 @@ fn main() -> ! {
6565
let mut last_status = None;
6666

6767
loop {
68-
let time: usize = cortex_m::interrupt::free(|cs| {
69-
*TIME.borrow(cs)
70-
.borrow()
71-
});
68+
let time: usize = cortex_m::interrupt::free(|cs| *TIME.borrow(cs).borrow());
7269

7370
// print stats every 30 seconds
7471
if time >= last_stats_time + 30 {
7572
let t = time - last_stats_time;
7673
writeln!(
77-
stdout, "T={}\tRx:\t{} KB/s\t{} pps\tTx:\t{} KB/s\t{} pps",
74+
stdout,
75+
"T={}\tRx:\t{} KB/s\t{} pps\tTx:\t{} KB/s\t{} pps",
7876
time,
79-
rx_bytes / 1024 / t, rx_pkts / t,
80-
tx_bytes / 1024 / t, tx_pkts / t
81-
).unwrap();
77+
rx_bytes / 1024 / t,
78+
rx_pkts / t,
79+
tx_bytes / 1024 / t,
80+
tx_pkts / t
81+
)
82+
.unwrap();
8283
// Reset
8384
rx_bytes = 0;
8485
rx_pkts = 0;
@@ -89,14 +90,12 @@ fn main() -> ! {
8990

9091
// Link change detection
9192
let status = eth.status();
92-
if last_status.map(|last_status| last_status != status)
93+
if last_status
94+
.map(|last_status| last_status != status)
9395
.unwrap_or(true)
9496
{
95-
if ! status.link_detected() {
96-
writeln!(
97-
stdout,
98-
"Ethernet: no link detected"
99-
).unwrap();
97+
if !status.link_detected() {
98+
writeln!(stdout, "Ethernet: no link detected").unwrap();
10099
} else {
101100
writeln!(
102101
stdout,
@@ -107,16 +106,15 @@ fn main() -> ! {
107106
Some(false) => "HD",
108107
None => "?",
109108
}
110-
).unwrap();
109+
)
110+
.unwrap();
111111
}
112112

113113
last_status = Some(status);
114114
}
115115

116116
cortex_m::interrupt::free(|cs| {
117-
let mut eth_pending =
118-
ETH_PENDING.borrow(cs)
119-
.borrow_mut();
117+
let mut eth_pending = ETH_PENDING.borrow(cs).borrow_mut();
120118
*eth_pending = false;
121119
});
122120

@@ -135,7 +133,7 @@ fn main() -> ! {
135133
}
136134
}
137135
}
138-
if ! eth.rx_is_running() {
136+
if !eth.rx_is_running() {
139137
writeln!(stdout, "RX stopped").unwrap();
140138
}
141139

@@ -160,10 +158,8 @@ fn main() -> ! {
160158
}
161159

162160
cortex_m::interrupt::free(|cs| {
163-
let eth_pending =
164-
ETH_PENDING.borrow(cs)
165-
.borrow_mut();
166-
if ! *eth_pending {
161+
let eth_pending = ETH_PENDING.borrow(cs).borrow_mut();
162+
if !*eth_pending {
167163
asm::wfi();
168164
}
169165
});
@@ -175,32 +171,29 @@ fn setup_systick(syst: &mut SYST) {
175171
syst.enable_counter();
176172
syst.enable_interrupt();
177173

178-
if ! SYST::is_precise() {
174+
if !SYST::is_precise() {
179175
let mut stderr = hio::hstderr().unwrap();
180176
writeln!(
181177
stderr,
182178
"Warning: SYSTICK with source {:?} is not precise",
183179
syst.get_clock_source()
184-
).unwrap();
180+
)
181+
.unwrap();
185182
}
186183
}
187184

188185
#[exception]
189186
fn SysTick() {
190187
cortex_m::interrupt::free(|cs| {
191-
let mut time =
192-
TIME.borrow(cs)
193-
.borrow_mut();
188+
let mut time = TIME.borrow(cs).borrow_mut();
194189
*time += 1;
195190
})
196191
}
197192

198193
#[interrupt]
199194
fn ETH() {
200195
cortex_m::interrupt::free(|cs| {
201-
let mut eth_pending =
202-
ETH_PENDING.borrow(cs)
203-
.borrow_mut();
196+
let mut eth_pending = ETH_PENDING.borrow(cs).borrow_mut();
204197
*eth_pending = true;
205198
});
206199

src/desc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use core::ops::{Deref, DerefMut};
33
use aligned::{Aligned, A8};
44
use volatile_register::{RO, RW};
55

6-
76
#[repr(C)]
87
pub struct Descriptor {
98
desc: Aligned<A8, [u32; 4]>,
@@ -12,7 +11,7 @@ pub struct Descriptor {
1211
impl Clone for Descriptor {
1312
fn clone(&self) -> Self {
1413
Descriptor {
15-
desc: Aligned((*self.desc).clone())
14+
desc: Aligned((*self.desc).clone()),
1615
}
1716
}
1817
}
@@ -45,7 +44,8 @@ impl Descriptor {
4544
}
4645

4746
pub unsafe fn modify<F>(&mut self, n: usize, f: F)
48-
where F: FnOnce(u32) -> u32
47+
where
48+
F: FnOnce(u32) -> u32,
4949
{
5050
self.rw(n).modify(f)
5151
}

0 commit comments

Comments
 (0)