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,14 +223,13 @@ 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
.recv(|buf| {
for (i, b) in buf.iter().enumerate() { for (i, b) in buf.iter().enumerate() {
if *b == '\n' as u8 { if *b == '\n' as u8 {
return match core::str::from_utf8(&buf[0..i]) { return match core::str::from_utf8(&buf[0..i]) {
Ok(name) => Ok(name) => Poll::Ready((i + 1, Some(name.to_owned()))),
Poll::Ready((i + 1, Some(name.to_owned()))), Err(_) => Poll::Ready((i + 1, None)),
Err(_) =>
Poll::Ready((i + 1, None))
}; };
} }
} }
@ -219,12 +239,15 @@ pub fn main_core0() {
} 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(())