19 #ifndef __RFLPC_ETHERNET_H__
20 #define __RFLPC_ETHERNET_H__
24 #ifdef RFLPC_CONFIG_ENABLE_ETHERNET
36 #include "../nxp/LPC17xx.h"
37 #include "../interrupt.h"
55 #define RFLPC_ETH_LINK_MODE_SPEED_BIT (1 << 0)
57 #define RFLPC_ETH_LINK_MODE_DUPLEX_BIT (1 << 1)
59 #define RFLPC_ETH_LINK_MODE_100HD (RFLPC_ETH_LINK_MODE_SPEED_BIT)
61 #define RFLPC_ETH_LINK_MODE_10HD (0)
63 #define RFLPC_ETH_LINK_MODE_100FD (RFLPC_ETH_LINK_MODE_SPEED_BIT | RFLPC_ETH_LINK_MODE_DUPLEX_BIT)
65 #define RFLPC_ETH_LINK_MODE_10FD (RFLPC_ETH_LINK_MODE_DUPLEX_BIT)
185 return (status_info & 0x7FF) + 1;
198 *control = ((size_to_send-1) & 0x7FF) | ((last_fragment & 1) << 30) | ((trigger_it & 1) << 31) |
219 if (LPC_EMAC->RxConsumeIndex == LPC_EMAC->RxProduceIndex)
234 if (LPC_EMAC->RxConsumeIndex == LPC_EMAC->RxProduceIndex)
247 if (LPC_EMAC->RxConsumeIndex == LPC_EMAC->RxProduceIndex)
249 if (LPC_EMAC->RxConsumeIndex == LPC_EMAC->RxDescriptorNumber)
250 LPC_EMAC->RxConsumeIndex = 0;
252 LPC_EMAC->RxConsumeIndex++;
263 #define TX_PRODUCE_INDEX_INC(inc) ((LPC_EMAC->TxProduceIndex + (inc))% (LPC_EMAC->TxDescriptorNumber+1))
299 int idx = LPC_EMAC->TxConsumeIndex - 1;
301 return LPC_EMAC->TxDescriptorNumber;
313 ((
TX_PRODUCE_INDEX_INC(count-1) == LPC_EMAC->TxDescriptorNumber) && LPC_EMAC->TxConsumeIndex == 0))
344 LPC_EMAC->IntEnable |= irqs;
354 LPC_EMAC->IntEnable &= ~irqs;
364 LPC_EMAC->IntEnable = irqs;
370 LPC_EMAC->IntClear = irqs;
378 return LPC_EMAC->IntStatus;
390 LPC_EMAC->IntSet = irqs;
405 LPC_EMAC->RxFilterCtrl = 0;
407 LPC_EMAC->RxFilterCtrl |= RFLPC_ETH_RXFILTER_UNICAST_EN;
408 if (accept_multicast)
409 LPC_EMAC->RxFilterCtrl |= RFLPC_ETH_RXFILTER_MULTICAST_EN;
410 if (accept_broadcast)
411 LPC_EMAC->RxFilterCtrl |= RFLPC_ETH_RXFILTER_BROADCAST_EN;
412 LPC_EMAC->RxFilterCtrl |= RFLPC_ETH_RXFILTER_PERFECT_EN;
414 LPC_EMAC->Command &= ~RFLPC_ETH_CMD_PASS_RX_FILTER;
422 LPC_EMAC->Command |= RFLPC_ETH_CMD_PASS_RX_FILTER;
static void rflpc_eth_irq_enable_set(uint32_t irqs)
sets the irq enable register This function will disable all irqs and then only enable those given...
static uint32_t rflpc_eth_get_packet_size(uint32_t status_info)
Returns the size of a packet from the status_info field of a rflpc_eth_tx_status_t or rflpc_eth_rx_st...
static void rflpc_eth_activate_rx_filter(int accept_unicast, int accept_multicast, int accept_broadcast)
Activate the hardware receive filter.
This structure holds a descriptor which describes the fragment received or sent by the ethernet DMA...
static uint32_t rflpc_eth_irq_get_status()
gets the interrupt status.
This structure holds the transmit status associated to a descriptor.
Ethernet driver constants.
int rflpc_eth_init()
Inits the ethernet device.
static void rflpc_eth_irq_disable(uint32_t irqs)
disable eth interrupts This function will remove irq enable bits.
static void rflpc_eth_irq_trigger(uint32_t irqs)
Force the generation of the given interrupt.
static void rflpc_eth_irq_clear(uint32_t irqs)
clear given pending interrupts
void rflpc_eth_get_mac_address(uint8_t *addr)
returns the device MAC address
static int rflpc_eth_get_current_tx_packet_descriptor(rflpc_eth_descriptor_t **descriptor, rflpc_eth_tx_status_t **status, int idx)
returns the index of the current tx packet descriptor.
static void rflpc_eth_done_process_tx_packet(int count)
When the packet has been generated, calling this function will make it owned by the hardware and queu...
static int rflpc_eth_get_last_sent_packet_idx()
Returns the index of the last send buffer.
void rflpc_irq_set_handler(IRQn_Type irq, rflpc_irq_handler_t handler)
Sets an handler for the given IRQ.
static void rflpc_eth_irq_enable(uint32_t irqs)
enable eth interrupts
int rflpc_eth_link_auto_negociate(int max_desired_mode)
Force the physical link to perform auto negociation of mode.
void rflpc_eth_set_rx_base_addresses(rflpc_eth_descriptor_t *descriptors, rflpc_eth_rx_status_t *status, int count)
Sets rx descriptors and status base address.
uint8_t * packet
pointer to buffer where the ethernet frame (or frame fragment) is stored
static void rflpc_irq_enable(IRQn_Type irq)
Enables a specific interrupt.
volatile uint32_t status_info
Transmission status info.
static void rflpc_eth_set_tx_control_word(uint32_t size_to_send, volatile uint32_t *control, int trigger_it, int last_fragment)
Sets the transmission control word of a rflpc_eth_descriptor_t struct.
void rflpc_eth_dump_internals()
Use the printf function to dump the values of the MAC registers.
static void rflpc_irq_disable(IRQn_Type irq)
Disables a specific interrupt.
int rflpc_eth_link_state()
Returns the link state.
volatile uint32_t status_info
Receive status return flags.
static int rflpc_eth_get_current_rx_packet_descriptor(rflpc_eth_descriptor_t **descriptor, rflpc_eth_rx_status_t **status)
Returns the pointers on the current rx packet descriptor.
static void rflpc_eth_set_irq_handler(rflpc_irq_handler_t c)
sets the interrupt handler of the ethernet peripheral
static void rflpc_eth_deactivate_rx_filter()
Deactivates the hardware receive filter.
This structure holds the reception status associated to a descriptor.
volatile uint32_t status_hash_crc
hash CRC calculated from source and destination address.
static void rflpc_eth_done_process_rx_packet()
This function has to be called when a packet (which descriptor is returned by rflpc_eth_get_current_r...
volatile uint32_t control
Control word where we find data buffer size and other information relative to reception/emission of t...
#define TX_PRODUCE_INDEX_INC(inc)
Helper macro for rflpc_eth_get_current_tx_packet_descriptor.
void rflpc_eth_set_tx_base_addresses(rflpc_eth_descriptor_t *descriptos, rflpc_eth_tx_status_t *status, int count)
Sets tx descriptors and status base address.
static int rflpc_eth_rx_available()
Returns true if a packet has been received and not yet processed available.
void rflpc_eth_set_mac_address(const uint8_t *addr)
sets the device MAC address
int rflpc_eth_get_link_mode()
returns the current link mode.
void(* rflpc_irq_handler_t)(void)
Interrupt handler type.
void rflpc_eth_set_link_mode(int mode)
Forces the MAC and PHY devices to operate on the given mode no matter the capability of the linked pa...