diff options
Diffstat (limited to 'firmware/microblaze/lib')
-rw-r--r-- | firmware/microblaze/lib/net_common.c | 15 | ||||
-rw-r--r-- | firmware/microblaze/lib/net_common.h | 4 | ||||
-rw-r--r-- | firmware/microblaze/lib/pkt_ctrl.c | 24 | ||||
-rw-r--r-- | firmware/microblaze/lib/pkt_ctrl.h | 7 |
4 files changed, 35 insertions, 15 deletions
diff --git a/firmware/microblaze/lib/net_common.c b/firmware/microblaze/lib/net_common.c index 48aa460f9..e9b633b13 100644 --- a/firmware/microblaze/lib/net_common.c +++ b/firmware/microblaze/lib/net_common.c @@ -39,21 +39,12 @@ static const eth_mac_addr_t BCAST_MAC_ADDR = {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}; -static inline bool -ip_addr_eq(const struct ip_addr a, const struct ip_addr b) -{ - return a.addr == b.addr; -} - // ------------------------------------------------------------------------ static eth_mac_addr_t _local_mac_addr; -void register_mac_addr(const eth_mac_addr_t *mac_addr){ - _local_mac_addr = *mac_addr; -} - static struct ip_addr _local_ip_addr; -void register_ip_addr(const struct ip_addr *ip_addr){ +void register_addrs(const eth_mac_addr_t *mac_addr, const struct ip_addr *ip_addr){ + _local_mac_addr = *mac_addr; _local_ip_addr = *ip_addr; } @@ -382,7 +373,7 @@ handle_arp_packet(struct arp_eth_ipv4 *p, size_t size) sip.addr = get_int32(p->ar_sip); tip.addr = get_int32(p->ar_tip); - if (ip_addr_eq(tip, _local_ip_addr)){ // They're looking for us... + if (memcmp(&tip, &_local_ip_addr, sizeof(_local_ip_addr)) == 0){ // They're looking for us... send_arp_reply(p, _local_mac_addr); } } diff --git a/firmware/microblaze/lib/net_common.h b/firmware/microblaze/lib/net_common.h index 9d6a3e345..5e364adeb 100644 --- a/firmware/microblaze/lib/net_common.h +++ b/firmware/microblaze/lib/net_common.h @@ -26,9 +26,7 @@ typedef void (*udp_receiver_t)(struct socket_address src, struct socket_address dst, unsigned char *payload, int payload_len); -void register_mac_addr(const eth_mac_addr_t *mac_addr); - -void register_ip_addr(const struct ip_addr *ip_addr); +void register_addrs(const eth_mac_addr_t *mac_addr, const struct ip_addr *ip_addr); void register_udp_listener(int port, udp_receiver_t rcvr); diff --git a/firmware/microblaze/lib/pkt_ctrl.c b/firmware/microblaze/lib/pkt_ctrl.c index 9f662122d..52ba80e3a 100644 --- a/firmware/microblaze/lib/pkt_ctrl.c +++ b/firmware/microblaze/lib/pkt_ctrl.c @@ -47,6 +47,30 @@ static bool is_status_bit_set(int bit){ #define MODE_BIT 2 #define CLR_BIT 8 +void pkt_ctrl_register_addrs( + const eth_mac_addr_t *mac_addr, const struct ip_addr *ip_addr +){ + //program in the ip addr + set_control(0x1 << 4, 0x7 << 4); + set_control((ip_addr->addr & 0x0000ffff) << 16, 0xffff << 16); + set_control(0x2 << 4, 0x7 << 4); + set_control((ip_addr->addr & 0xffff0000) << 0, 0xffff << 16); + + //program in the mac addr + set_control(0x3 << 4, 0x7 << 4); + set_control((uint32_t)mac_addr->addr[0] << 16, 0x00ff << 16); + set_control((uint32_t)mac_addr->addr[1] << 24, 0xff00 << 16); + set_control(0x4 << 4, 0x7 << 4); + set_control((uint32_t)mac_addr->addr[2] << 16, 0x00ff << 16); + set_control((uint32_t)mac_addr->addr[3] << 24, 0xff00 << 16); + set_control(0x5 << 4, 0x7 << 4); + set_control((uint32_t)mac_addr->addr[4] << 16, 0x00ff << 16); + set_control((uint32_t)mac_addr->addr[5] << 24, 0xff00 << 16); + + //clear cmd + set_control(0x0, 0x7 << 4); +} + void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode){ switch(mode){ case PKT_CTRL_ROUTING_MODE_SLAVE: diff --git a/firmware/microblaze/lib/pkt_ctrl.h b/firmware/microblaze/lib/pkt_ctrl.h index 86fb46d32..761209530 100644 --- a/firmware/microblaze/lib/pkt_ctrl.h +++ b/firmware/microblaze/lib/pkt_ctrl.h @@ -19,12 +19,19 @@ #define INCLUDED_PKT_CTRL_H #include <stddef.h> +#include <lwip/ip_addr.h> +#include <net/eth_mac_addr.h> typedef enum { PKT_CTRL_ROUTING_MODE_SLAVE, PKT_CTRL_ROUTING_MODE_MASTER, } pkt_ctrl_routing_mode_t; +//! Register this devices addresses into the router +void pkt_ctrl_register_addrs( + const eth_mac_addr_t *mac_addr, const struct ip_addr *ip_addr +); + //! Set the routing mode for this device void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode); |