ether2ser 0.1.0
Ethernet <-> synchronous V.24 bridge firmware for RP2040 + W5500
Loading...
Searching...
No Matches
w5500_driver.c File Reference
#include "w5500_driver.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "socket.h"
#include "w5500.h"
#include "wizchip_conf.h"
#include "wizchip_qspi_pio.h"
#include "wizchip_spi.h"
#include "system/common.h"
#include "system/error.h"
Include dependency graph for w5500_driver.c:

Go to the source code of this file.

Macros

#define IP_SOCKET   0
 
#define UDP_SOCKET   1
 
#define UDP_MAX_PAYLOAD_BYTES   1472U
 
#define UDP_W5500_OVERHEAD_BYTES   8U
 
#define UDP_RX_REQUIRED_BYTES   (UDP_MAX_PAYLOAD_BYTES + UDP_W5500_OVERHEAD_BYTES)
 

Functions

void w5500_poll_udp_buffer_full_events (uint64_t *rx_full_enter_events, uint64_t *tx_full_enter_events)
 
static void ipv4_calc_broadcast_u8 (const uint8_t ip_addr[4], const uint8_t mask[4], uint8_t bcast[4])
 
void w5500_debug_status (void)
 Print W5500 socket/PHY debug status.
 
void w5500_udp_tx (UDP_CONFIG_T *send_config, const UDP_FRAME_T *frame)
 Send one UDP frame through W5500.
 
bool w5500_poll_rx (UDP_CONFIG_T *send_config, UDP_FRAME_T *frame)
 Poll W5500 for received UDP data.
 
e2s_error_t w5500_open_ipraw_socket (void)
 Open IPRAW socket mode.
 
e2s_error_t w5500_open_udp_socket (UDP_CONFIG_T *config)
 Open configured UDP socket.
 
e2s_error_t w5500_reconfigure_udp_socket (UDP_CONFIG_T *config)
 Reconfigure UDP socket with new endpoint settings.
 
void w5500_set_network (NETWORK_CONFIG_T *config)
 Apply network configuration to W5500 hardware.
 
static e2s_error_t w5500_apply_socket_mem_map (void)
 
void w5500_set_network_defaults (NETWORK_CONFIG_T *config)
 Fill network config with compile-time defaults.
 
void w5500_driver_init (void)
 Initialize W5500 driver and low-level interface.
 

Macro Definition Documentation

◆ IP_SOCKET

#define IP_SOCKET   0

Definition at line 37 of file w5500_driver.c.

◆ UDP_MAX_PAYLOAD_BYTES

#define UDP_MAX_PAYLOAD_BYTES   1472U

Definition at line 39 of file w5500_driver.c.

◆ UDP_RX_REQUIRED_BYTES

#define UDP_RX_REQUIRED_BYTES   (UDP_MAX_PAYLOAD_BYTES + UDP_W5500_OVERHEAD_BYTES)

Definition at line 41 of file w5500_driver.c.

◆ UDP_SOCKET

#define UDP_SOCKET   1

Definition at line 38 of file w5500_driver.c.

◆ UDP_W5500_OVERHEAD_BYTES

#define UDP_W5500_OVERHEAD_BYTES   8U

Definition at line 40 of file w5500_driver.c.

Function Documentation

◆ ipv4_calc_broadcast_u8()

static void ipv4_calc_broadcast_u8 ( const uint8_t  ip_addr[4],
const uint8_t  mask[4],
uint8_t  bcast[4] 
)
static

Definition at line 87 of file w5500_driver.c.

Referenced by w5500_set_network().

Here is the caller graph for this function:

◆ w5500_apply_socket_mem_map()

static e2s_error_t w5500_apply_socket_mem_map ( void  )
static

Definition at line 194 of file w5500_driver.c.

References E2S_ERR_W5500_INIT_FAILED, E2S_OK, LOG_ERROR, LOG_INFO, and UDP_SOCKET.

Referenced by w5500_driver_init().

Here is the caller graph for this function:

◆ w5500_debug_status()

void w5500_debug_status ( void  )

Print W5500 socket/PHY debug status.

Definition at line 96 of file w5500_driver.c.

References IP_SOCKET, and LOG_DEBUG.

Referenced by main().

Here is the caller graph for this function:

◆ w5500_driver_init()

void w5500_driver_init ( void  )

Initialize W5500 driver and low-level interface.

Definition at line 226 of file w5500_driver.c.

References E2S_ERR_W5500_INIT_FAILED, E2S_OK, fatal_panic(), LOG_DEBUG, and w5500_apply_socket_mem_map().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ w5500_open_ipraw_socket()

e2s_error_t w5500_open_ipraw_socket ( void  )

Open IPRAW socket mode.

Returns
E2S_OK on success, error code otherwise.

Definition at line 149 of file w5500_driver.c.

References E2S_ERR_W5500_SOCKET_OPEN_FAILED, E2S_OK, IP_SOCKET, LOG_DEBUG, and LOG_ERROR.

◆ w5500_open_udp_socket()

e2s_error_t w5500_open_udp_socket ( UDP_CONFIG_T config)

Open configured UDP socket.

Parameters
send_configLocal endpoint settings.
Returns
E2S_OK on success, error code otherwise.

Definition at line 161 of file w5500_driver.c.

References E2S_ERR_W5500_SOCKET_OPEN_FAILED, E2S_OK, LOG_DEBUG, LOG_ERROR, UDP_CONFIG_T::port, and UDP_SOCKET.

Referenced by main(), and w5500_reconfigure_udp_socket().

Here is the caller graph for this function:

◆ w5500_poll_rx()

bool w5500_poll_rx ( UDP_CONFIG_T send_config,
UDP_FRAME_T frame 
)

Poll W5500 for received UDP data.

Parameters
send_configSource endpoint output (updated with sender info).
frameDestination frame buffer for received payload.
Returns
true if a frame was received, false otherwise.

Definition at line 119 of file w5500_driver.c.

References UDP_CONFIG_T::ip_address, UDP_FRAME_T::length, LOG_DEBUG, UDP_FRAME_T::payload, UDP_CONFIG_T::port, RX_BUF_SIZE, and UDP_SOCKET.

Referenced by poll_and_enqueue_udp_rx().

Here is the caller graph for this function:

◆ w5500_poll_udp_buffer_full_events()

void w5500_poll_udp_buffer_full_events ( uint64_t *  rx_full_enter_events,
uint64_t *  tx_full_enter_events 
)

Definition at line 43 of file w5500_driver.c.

References UDP_RX_REQUIRED_BYTES, and UDP_SOCKET.

Referenced by event_loop().

Here is the caller graph for this function:

◆ w5500_reconfigure_udp_socket()

e2s_error_t w5500_reconfigure_udp_socket ( UDP_CONFIG_T config)

Reconfigure UDP socket with new endpoint settings.

Parameters
configLocal endpoint settings.
Returns
E2S_OK on success, error code otherwise.

Definition at line 177 of file w5500_driver.c.

References LOG_DEBUG, UDP_SOCKET, and w5500_open_udp_socket().

Referenced by ev_set_net_settings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ w5500_set_network()

void w5500_set_network ( NETWORK_CONFIG_T config)

Apply network configuration to W5500 hardware.

Parameters
configSource config object.

Definition at line 184 of file w5500_driver.c.

References NETWORK_CONFIG_T::broadcast_address, ipv4_calc_broadcast_u8(), LOG_DEBUG, and NETWORK_CONFIG_T::net_info.

Referenced by init_app(), and w5500_set_network_defaults().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ w5500_set_network_defaults()

void w5500_set_network_defaults ( NETWORK_CONFIG_T config)

Fill network config with compile-time defaults.

Parameters
configDestination config object.

Definition at line 213 of file w5500_driver.c.

References DEFAULT_DNS_ADDR, DEFAULT_GATEWAY_ADDR, DEFAULT_IP_ADDR, DEFAULT_MAC_ADDR, DEFAULT_SUBNET_MASK, NETWORK_CONFIG_T::net_info, and w5500_set_network().

Referenced by init_app().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ w5500_udp_tx()

void w5500_udp_tx ( UDP_CONFIG_T send_config,
const UDP_FRAME_T frame 
)

Send one UDP frame through W5500.

Parameters
send_configDestination endpoint.
frameFrame payload to send.

Definition at line 106 of file w5500_driver.c.

References UDP_CONFIG_T::ip_address, UDP_FRAME_T::length, LOG_DEBUG, UDP_FRAME_T::payload, UDP_CONFIG_T::port, and UDP_SOCKET.

Referenced by decode_hdlc_to_udp_tx(), and event_dispatch().

Here is the caller graph for this function: