2019-05-05 20:56:23 +08:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(asm)]
|
2019-05-31 02:30:19 +08:00
|
|
|
#![feature(global_asm)]
|
2019-05-05 20:56:23 +08:00
|
|
|
#![feature(naked_functions)]
|
2019-06-09 07:00:58 +08:00
|
|
|
#![feature(compiler_builtins_lib)]
|
2019-06-17 09:32:10 +08:00
|
|
|
#![feature(never_type)]
|
2019-10-31 08:41:10 +08:00
|
|
|
#![feature(alloc_error_handler)]
|
2019-08-11 06:55:27 +08:00
|
|
|
// TODO: disallow unused/dead_code when code moves into a lib crate
|
|
|
|
#![allow(dead_code)]
|
2019-05-05 20:56:23 +08:00
|
|
|
|
2019-11-01 02:20:49 +08:00
|
|
|
extern crate alloc;
|
2019-11-11 09:37:06 +08:00
|
|
|
use alloc::{vec, vec::Vec};
|
2019-11-11 08:21:30 +08:00
|
|
|
use core::mem::transmute;
|
2019-06-09 07:00:58 +08:00
|
|
|
use compiler_builtins as _;
|
2019-07-05 06:44:53 +08:00
|
|
|
use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr};
|
2019-11-11 08:21:30 +08:00
|
|
|
use smoltcp::iface::{NeighborCache, EthernetInterfaceBuilder};
|
2019-07-05 06:44:53 +08:00
|
|
|
use smoltcp::time::Instant;
|
|
|
|
use smoltcp::socket::SocketSet;
|
2019-05-05 20:56:23 +08:00
|
|
|
|
2019-11-11 09:43:05 +08:00
|
|
|
mod boot;
|
2019-05-07 05:56:53 +08:00
|
|
|
mod regs;
|
2019-05-05 20:56:23 +08:00
|
|
|
mod cortex_a9;
|
2019-11-11 09:37:06 +08:00
|
|
|
mod abort;
|
|
|
|
mod panic;
|
2019-10-19 05:46:00 +08:00
|
|
|
mod zynq;
|
2019-11-11 09:37:06 +08:00
|
|
|
mod stdio;
|
|
|
|
mod ram;
|
2019-05-05 20:56:23 +08:00
|
|
|
|
2019-07-05 06:44:53 +08:00
|
|
|
const HWADDR: [u8; 6] = [0, 0x23, 0xde, 0xea, 0xbe, 0xef];
|
|
|
|
|
2019-11-11 09:43:05 +08:00
|
|
|
pub fn main() {
|
2019-06-20 06:30:18 +08:00
|
|
|
println!("Main.");
|
2019-10-22 04:19:03 +08:00
|
|
|
|
2019-10-26 05:19:34 +08:00
|
|
|
let mut ddr = zynq::ddr::DdrRam::new();
|
|
|
|
println!("DDR: {:?}", ddr.status());
|
|
|
|
ddr.memtest();
|
2019-11-11 09:37:06 +08:00
|
|
|
ram::init_alloc(&mut ddr);
|
2019-10-31 08:41:10 +08:00
|
|
|
|
2019-10-22 04:19:03 +08:00
|
|
|
let eth = zynq::eth::Eth::default(HWADDR.clone());
|
2019-06-20 06:30:18 +08:00
|
|
|
println!("Eth on");
|
2019-05-08 01:28:33 +08:00
|
|
|
|
2019-11-01 02:20:49 +08:00
|
|
|
const RX_LEN: usize = 8;
|
|
|
|
let mut rx_descs = (0..RX_LEN)
|
|
|
|
.map(|_| zynq::eth::rx::DescEntry::zeroed())
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
let mut rx_buffers = vec![[0u8; zynq::eth::MTU]; RX_LEN];
|
2019-09-29 07:39:57 +08:00
|
|
|
// Number of transmission buffers (minimum is two because with
|
|
|
|
// one, duplicate packet transmission occurs)
|
2019-11-01 02:20:49 +08:00
|
|
|
const TX_LEN: usize = 8;
|
|
|
|
let mut tx_descs = (0..TX_LEN)
|
|
|
|
.map(|_| zynq::eth::tx::DescEntry::zeroed())
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
let mut tx_buffers = vec![[0u8; zynq::eth::MTU]; TX_LEN];
|
2019-08-11 06:55:27 +08:00
|
|
|
let eth = eth.start_rx(&mut rx_descs, &mut rx_buffers);
|
2019-07-05 06:44:53 +08:00
|
|
|
//let mut eth = eth.start_tx(&mut tx_descs, &mut tx_buffers);
|
|
|
|
let mut eth = eth.start_tx(
|
|
|
|
// HACK
|
2019-11-01 02:20:49 +08:00
|
|
|
unsafe { transmute(tx_descs.as_mut_slice()) },
|
|
|
|
unsafe { transmute(tx_buffers.as_mut_slice()) },
|
2019-07-05 06:44:53 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
let ethernet_addr = EthernetAddress(HWADDR);
|
|
|
|
// IP stack
|
2019-11-11 08:04:55 +08:00
|
|
|
let local_addr = IpAddress::v4(192, 168, 1, 28);
|
2019-07-05 06:44:53 +08:00
|
|
|
let mut ip_addrs = [IpCidr::new(local_addr, 24)];
|
2019-11-01 02:20:49 +08:00
|
|
|
let mut neighbor_storage = vec![None; 256];
|
2019-07-05 06:44:53 +08:00
|
|
|
let neighbor_cache = NeighborCache::new(&mut neighbor_storage[..]);
|
|
|
|
let mut iface = EthernetInterfaceBuilder::new(&mut eth)
|
|
|
|
.ethernet_addr(ethernet_addr)
|
|
|
|
.ip_addrs(&mut ip_addrs[..])
|
|
|
|
.neighbor_cache(neighbor_cache)
|
|
|
|
.finalize();
|
|
|
|
let mut sockets_storage = [
|
|
|
|
None, None, None, None,
|
|
|
|
None, None, None, None
|
|
|
|
];
|
|
|
|
let mut sockets = SocketSet::new(&mut sockets_storage[..]);
|
|
|
|
|
|
|
|
let mut time = 0u32;
|
2019-06-10 08:44:29 +08:00
|
|
|
loop {
|
2019-07-05 06:44:53 +08:00
|
|
|
time += 1;
|
2019-11-11 08:21:30 +08:00
|
|
|
let timestamp = Instant::from_millis(time);
|
2019-07-05 06:44:53 +08:00
|
|
|
|
|
|
|
match iface.poll(&mut sockets, timestamp) {
|
|
|
|
Ok(_) => {},
|
2019-06-22 07:20:18 +08:00
|
|
|
Err(e) => {
|
2019-07-05 06:44:53 +08:00
|
|
|
println!("poll error: {}", e);
|
2019-06-10 08:44:29 +08:00
|
|
|
}
|
|
|
|
}
|
2019-06-22 07:34:47 +08:00
|
|
|
|
2019-07-05 06:44:53 +08:00
|
|
|
// match eth.recv_next() {
|
|
|
|
// Ok(Some(pkt)) => {
|
|
|
|
// print!("eth: rx {} bytes", pkt.len());
|
|
|
|
// for b in pkt.iter() {
|
|
|
|
// print!(" {:02X}", b);
|
|
|
|
// }
|
|
|
|
// println!("");
|
|
|
|
// }
|
|
|
|
// Ok(None) => {}
|
|
|
|
// Err(e) => {
|
|
|
|
// println!("eth rx error: {:?}", e);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// match eth.send(512) {
|
|
|
|
// Some(mut pkt) => {
|
|
|
|
// let mut x = 0;
|
|
|
|
// for b in pkt.iter_mut() {
|
|
|
|
// *b = x;
|
|
|
|
// x += 1;
|
|
|
|
// }
|
|
|
|
// println!("eth tx {} bytes", pkt.len());
|
|
|
|
// }
|
|
|
|
// None => println!("eth tx shortage"),
|
|
|
|
// }
|
2019-06-10 08:44:29 +08:00
|
|
|
}
|
2019-05-28 06:28:35 +08:00
|
|
|
|
|
|
|
}
|
2019-05-31 02:30:19 +08:00
|
|
|
|