Microchip® Advanced Software Framework

emac_example.c File Reference

EMAC example for SAM.

Copyright (c) 2011-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 configure_console (void)
 Configure UART console. More...
 
static void emac_display_ip_packet (p_ip_header_t p_ip_header, uint32_t ul_size)
 Display the IP packet. More...
 
void EMAC_Handler (void)
 EMAC interrupt handler. More...
 
static uint16_t emac_icmp_checksum (uint16_t *p_buff, uint32_t ul_len)
 Process & return the ICMP checksum. More...
 
static void emac_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 emac_process_eth_packet (uint8_t *p_uc_data, uint32_t ul_size)
 Process the received EMAC packet. More...
 
static void emac_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)
 EMAC example entry point. More...
 

Variables

static emac_device_t gs_emac_dev
 The EMAC driver instance. More...
 
static volatile uint8_t gs_uc_eth_buffer [EMAC_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:
"-- EMAC Example --\r" \
"-- "BOARD_NAME" --\r" \
"-- Compiled: "__DATE__" "__TIME__" --"STRING_EOL
#define BOARD_NAME
Definition: fatfs_access_example.c:112
#define STRING_EOL
Definition: emac_example.c:115

Referenced by main().

static void configure_console ( void  )
static

Configure UART console.

References uart_rs232_options::baudrate, stdio_serial_init(), and sysclk_enable_peripheral_clock().

Referenced by main().

static void emac_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 emac_process_eth_packet().

void EMAC_Handler ( void  )

EMAC interrupt handler.

References emac_handler().

static uint16_t emac_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 emac_process_ip_packet().

static void emac_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, emac_dev_write(), EMAC_OK, ethernet_header::et_dest, ethernet_header::et_src, ETH_HEADER_SIZE, NULL, and SWAP16.

Referenced by emac_process_eth_packet().

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

Process the received EMAC packet.

Parameters
p_uc_dataThe data to process.
ul_sizeThe data size.

References emac_display_ip_packet(), emac_process_arp_packet(), emac_process_ip_packet(), ethernet_header::et_protlen, ETH_HEADER_SIZE, ETH_PROT_ARP, ETH_PROT_IP, and SWAP16.

Referenced by main().

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

emac_device_t gs_emac_dev
static

The EMAC driver instance.

volatile uint8_t gs_uc_eth_buffer[EMAC_FRAME_LENTGH_MAX]
static

Buffer for ethernet packets.

uint8_t gs_uc_ip_address[]
static
Initial value:
=
{ ETHERNET_CONF_IPADDR0, ETHERNET_CONF_IPADDR1,
ETHERNET_CONF_IPADDR2, ETHERNET_CONF_IPADDR3 }

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

uint8_t gs_uc_mac_address[]
static
Initial value:
=
{ ETHERNET_CONF_ETHADDR0, ETHERNET_CONF_ETHADDR1, ETHERNET_CONF_ETHADDR2,
ETHERNET_CONF_ETHADDR3, ETHERNET_CONF_ETHADDR4, ETHERNET_CONF_ETHADDR5
}

The MAC address used for the test.