1
0
Fork 0

formatting commit

This commit is contained in:
pca006132 2020-06-05 11:48:41 +08:00
parent 236592ae66
commit d01d0f69a4
1 changed files with 60 additions and 37 deletions

View File

@ -3,28 +3,37 @@
extern crate alloc; extern crate alloc;
use core::{mem::transmute, task::Poll};
use alloc::{borrow::ToOwned, collections::BTreeMap, format}; use alloc::{borrow::ToOwned, collections::BTreeMap, format};
use log::info; use core::{mem::transmute, task::Poll};
use libregister::RegisterR; use libasync::{
use libcortex_a9::{mutex::Mutex, sync_channel::{self, sync_channel}}; delay,
smoltcp::{Sockets, TcpStream},
task,
};
use libboard_zynq::{ use libboard_zynq::{
self as zynq,
clocks::source::{ArmPll, ClockSource, IoPll},
clocks::Clocks,
print, println, print, println,
self as zynq, clocks::Clocks, clocks::source::{ClockSource, ArmPll, IoPll}, sdio::sd_card::SdCard,
smoltcp::{ smoltcp::{
self, self,
wire::{EthernetAddress, IpAddress, IpCidr}, iface::{EthernetInterfaceBuilder, NeighborCache, Routes},
iface::{NeighborCache, EthernetInterfaceBuilder, Routes},
time::Instant, time::Instant,
wire::{EthernetAddress, IpAddress, IpCidr},
}, },
sdio::sd_card::SdCard,
time::Milliseconds, time::Milliseconds,
}; };
use libsupport_zynq::{ use libcortex_a9::{
ram, alloc::{vec, vec::Vec}, mutex::Mutex,
boot, sync_channel::{self, sync_channel},
}; };
use libasync::{delay, smoltcp::{Sockets, TcpStream}, task}; use libregister::RegisterR;
use libsupport_zynq::{
alloc::{vec, vec::Vec},
boot, ram,
};
use log::info;
mod ps7_init; mod ps7_init;
@ -38,7 +47,13 @@ pub fn main_core0() {
libboard_zynq::logger::init().unwrap(); libboard_zynq::logger::init().unwrap();
log::set_max_level(log::LevelFilter::Trace); log::set_max_level(log::LevelFilter::Trace);
info!("Boot mode: {:?}", zynq::slcr::RegisterBlock::new().boot_mode.read().boot_mode_pins()); info!(
"Boot mode: {:?}",
zynq::slcr::RegisterBlock::new()
.boot_mode
.read()
.boot_mode_pins()
);
#[cfg(feature = "target_zc706")] #[cfg(feature = "target_zc706")]
const CPU_FREQ: u32 = 800_000_000; const CPU_FREQ: u32 = 800_000_000;
@ -60,7 +75,13 @@ pub fn main_core0() {
} }
info!("PLLs set up"); info!("PLLs set up");
let clocks = zynq::clocks::Clocks::get(); let clocks = zynq::clocks::Clocks::get();
info!("CPU Clocks: {}/{}/{}/{}", clocks.cpu_6x4x(), clocks.cpu_3x2x(), clocks.cpu_2x(), clocks.cpu_1x()); info!(
"CPU Clocks: {}/{}/{}/{}",
clocks.cpu_6x4x(),
clocks.cpu_3x2x(),
clocks.cpu_2x(),
clocks.cpu_1x()
);
let mut sd = libboard_zynq::sdio::SDIO::sdio0(true); let mut sd = libboard_zynq::sdio::SDIO::sdio0(true);
// only test SD card if it is inserted // only test SD card if it is inserted
@ -202,29 +223,31 @@ pub fn main_core0() {
const TCP_PORT: u16 = 19; const TCP_PORT: u16 = 19;
async fn handle_connection(stream: TcpStream) -> smoltcp::Result<()> { async fn handle_connection(stream: TcpStream) -> smoltcp::Result<()> {
stream.send("Enter your name: ".bytes()).await?; stream.send("Enter your name: ".bytes()).await?;
let name = stream.recv(|buf| { let name = stream
for (i, b) in buf.iter().enumerate() { .recv(|buf| {
if *b == '\n' as u8 { for (i, b) in buf.iter().enumerate() {
return match core::str::from_utf8(&buf[0..i]) { if *b == '\n' as u8 {
Ok(name) => return match core::str::from_utf8(&buf[0..i]) {
Poll::Ready((i + 1, Some(name.to_owned()))), Ok(name) => Poll::Ready((i + 1, Some(name.to_owned()))),
Err(_) => Err(_) => Poll::Ready((i + 1, None)),
Poll::Ready((i + 1, None)) };
}; }
} }
} if buf.len() > 100 {
if buf.len() > 100 { // Too much input, consume all
// Too much input, consume all Poll::Ready((buf.len(), None))
Poll::Ready((buf.len(), None)) } else {
} else { Poll::Pending
Poll::Pending }
} })
}).await?; .await?;
match name { match name {
Some(name) => Some(name) => stream.send(format!("Hello {}!\n", name).bytes()).await?,
stream.send(format!("Hello {}!\n", name).bytes()).await?, None => {
None => stream
stream.send("I had trouble reading your name.\n".bytes()).await?, .send("I had trouble reading your name.\n".bytes())
.await?
}
} }
let _ = stream.flush().await; let _ = stream.flush().await;
Ok(()) Ok(())
@ -252,8 +275,8 @@ pub fn main_core0() {
delay(&mut countdown, Milliseconds(1000)).await; delay(&mut countdown, Milliseconds(1000)).await;
let timestamp = timer.get_us(); let timestamp = timer.get_us();
let seconds = timestamp / 1_000_000; let seconds = timestamp / 1_000_000;
let micros = timestamp % 1_000_000; let micros = timestamp % 1_000_000;
info!("time: {:6}.{:06}s", seconds, micros); info!("time: {:6}.{:06}s", seconds, micros);
} }
}); });