added gateway

This commit is contained in:
Niklas Kuhrmeyer 2020-10-30 12:16:28 +01:00
parent 66c917b576
commit dfe3ac877a
1 changed files with 10 additions and 0 deletions

View File

@ -36,6 +36,8 @@ use stm32h7xx_hal::prelude::*;
use embedded_hal::digital::v2::{InputPin, OutputPin};
use smoltcp as net;
use smoltcp::wire::Ipv4Address;
use smoltcp::iface::Routes;
use stm32h7_ethernet as ethernet;
use heapless::{consts::*, String};
@ -76,6 +78,7 @@ mod build_info {
pub struct NetStorage {
ip_addrs: [net::wire::IpCidr; 1],
neighbor_cache: [Option<(net::wire::IpAddress, net::iface::Neighbor)>; 8],
routes_storage: [Option<(smoltcp::wire::IpCidr, smoltcp::iface::Route)>; 2],
}
static mut NET_STORE: NetStorage = NetStorage {
@ -85,6 +88,8 @@ static mut NET_STORE: NetStorage = NetStorage {
)],
neighbor_cache: [None; 8],
routes_storage: [None; 2],
};
const SCALE: f32 = ((1 << 15) - 1) as f32;
@ -617,6 +622,10 @@ const APP: () = {
24,
);
let default_v4_gw = Ipv4Address::new(10,0,16,1);
let mut routes = Routes::new(&mut store.routes_storage[..]);
routes.add_default_ipv4_route(default_v4_gw).unwrap();
let neighbor_cache =
net::iface::NeighborCache::new(&mut store.neighbor_cache[..]);
@ -624,6 +633,7 @@ const APP: () = {
.ethernet_addr(mac_addr)
.neighbor_cache(neighbor_cache)
.ip_addrs(&mut store.ip_addrs[..])
.routes(routes)
.finalize();
(interface, eth_mac)