Microchip® Advanced Software Framework

gmac_example.c File Reference

GMAC example for SAM.

Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.

#include <asf.h>
#include <string.h>
#include "mini_ip.h"
#include "conf_eth.h"

Macros

#define STRING_EOL   "\r"
 
#define STRING_HEADER
 

Functions

static void at24mac_get_mac_address (void)
 
static void configure_console (void)
 Configure UART console. More...
 
static void gmac_display_ip_packet (p_ip_header_t p_ip_header, uint32_t ul_size)
 Display the IP packet. More...
 
void GMAC_Handler (void)
 GMAC interrupt handler. More...
 
static uint16_t gmac_icmp_checksum (uint16_t *p_buff, uint32_t ul_len)
 Process & return the ICMP checksum. More...
 
static void gmac_process_arp_packet (uint8_t *p_uc_data, uint32_t ul_size)
 Process the received ARP packet; change address and send it back. More...
 
static void gmac_process_eth_packet (uint8_t *p_uc_data, uint32_t ul_size)
 Process the received GMAC packet. More...
 
static void gmac_process_ip_packet (uint8_t *p_uc_data, uint32_t ul_size)
 Process the received IP packet; change address and send it back. More...
 
int main (void)
 GMAC example entry point. More...
 

Variables

static gmac_device_t gs_gmac_dev
 The GMAC driver instance. More...
 
static volatile uint8_t gs_uc_eth_buffer [GMAC_FRAME_LENTGH_MAX]
 Buffer for ethernet packets. More...
 
static uint8_t gs_uc_ip_address []
 The IP address used for test (ping ...) More...
 
static uint8_t gs_uc_mac_address []
 The MAC address used for the test. More...
 

#define STRING_EOL   "\r"
#define STRING_HEADER
Value:
"-- GMAC Example --\r\n" \
"-- "BOARD_NAME" --\r\n" \
"-- Compiled: "__DATE__" "__TIME__" --"STRING_EOL
#define BOARD_NAME
Name of the board.
Definition: same70_xplained.h:75
#define STRING_EOL
Definition: gmac_example.c:116

Referenced by main().

static void configure_console ( void  )
static
static void gmac_display_ip_packet ( p_ip_header_t  p_ip_header,
uint32_t  ul_size 
)
static

Display the IP packet.

Parameters
p_ip_headerPointer to the IP header.
ul_sizeThe data size.

References _IPheader::ip_dst, _IPheader::ip_hl_v, _IPheader::ip_id, _IPheader::ip_len, _IPheader::ip_p, IP_PROT_ICMP, IP_PROT_IP, IP_PROT_TCP, IP_PROT_UDP, _IPheader::ip_src, _IPheader::ip_sum, and _IPheader::ip_tos.

Referenced by gmac_process_eth_packet().

void GMAC_Handler ( void  )

GMAC interrupt handler.

References gmac_handler(), and GMAC_QUE_0.

static uint16_t gmac_icmp_checksum ( uint16_t *  p_buff,
uint32_t  ul_len 
)
static

Process & return the ICMP checksum.

Parameters
p_buffPointer to the buffer.
ul_lenThe length of the buffered data.
Returns
Checksum of the ICMP.

References SWAP16.

Referenced by gmac_process_ip_packet().

static void gmac_process_arp_packet ( uint8_t *  p_uc_data,
uint32_t  ul_size 
)
static

Process the received ARP packet; change address and send it back.

Parameters
p_uc_dataThe data to process.
ul_sizeThe data size.

References arp_header::ar_op, arp_header::ar_sha, arp_header::ar_spa, arp_header::ar_tha, arp_header::ar_tpa, ARP_REPLY, ARP_REQUEST, ethernet_header::et_dest, ethernet_header::et_src, ETH_HEADER_SIZE, gmac_dev_write(), GMAC_OK, GMAC_QUE_0, and SWAP16.

Referenced by gmac_process_eth_packet().

static void gmac_process_eth_packet ( uint8_t *  p_uc_data,
uint32_t  ul_size 
)
static

Process the received GMAC packet.

Parameters
p_uc_dataThe data to process.
ul_sizeThe data size.

References ethernet_header::et_protlen, ETH_HEADER_SIZE, ETH_PROT_ARP, ETH_PROT_IP, gmac_display_ip_packet(), gmac_process_arp_packet(), gmac_process_ip_packet(), and SWAP16.

Referenced by main().

static void gmac_process_ip_packet ( uint8_t *  p_uc_data,
uint32_t  ul_size 
)
static

gmac_device_t gs_gmac_dev
static

The GMAC driver instance.

volatile uint8_t gs_uc_eth_buffer[GMAC_FRAME_LENTGH_MAX]
static

Buffer for ethernet packets.

uint8_t gs_uc_ip_address[]
static
Initial value:
=
#define ETHERNET_CONF_IPADDR0
WAN Address: 192.168.0.2.
Definition: conf_eth.h:61
#define ETHERNET_CONF_IPADDR2
Definition: conf_eth.h:63
#define ETHERNET_CONF_IPADDR3
Definition: conf_eth.h:64
#define ETHERNET_CONF_IPADDR1
Definition: conf_eth.h:62

The IP address used for test (ping ...)

uint8_t gs_uc_mac_address[]
static
Initial value:
=
}
#define ETHERNET_CONF_ETHADDR2
Definition: conf_eth.h:54
#define ETHERNET_CONF_ETHADDR0
MAC address definition.
Definition: conf_eth.h:52
#define ETHERNET_CONF_ETHADDR4
Definition: conf_eth.h:56
#define ETHERNET_CONF_ETHADDR5
Definition: conf_eth.h:57
#define ETHERNET_CONF_ETHADDR1
Definition: conf_eth.h:53
#define ETHERNET_CONF_ETHADDR3
Definition: conf_eth.h:55

The MAC address used for the test.