Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Commit

Permalink
W55RP20 iperf test
Browse files Browse the repository at this point in the history
  • Loading branch information
wizhannah committed Jun 10, 2024
1 parent a239507 commit 948105a
Show file tree
Hide file tree
Showing 11 changed files with 778 additions and 29 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ set(CMAKE_CXX_STANDARD 17)
pico_sdk_init()

# Set ethernet chip
set(WIZNET_CHIP W5100S)
set(WIZNET_CHIP W5500)#W5100S)

if(${WIZNET_CHIP} STREQUAL W5100S)
add_definitions(-D_WIZCHIP_=W5100S)
Expand All @@ -36,6 +36,9 @@ endif()

message(STATUS "WIZNET_CHIP = ${WIZNET_CHIP}")


set(PICO_EXTRAS_LWIP_SRC_DIR "${CMAKE_SOURCE_DIR}/libraries/pico-extras/lib/lwip")

# Set the project root directory if it's not already defined, as may happen if
# the tests folder is included directly by a parent project, without including
# the top level CMakeLists.txt.
Expand Down
14 changes: 8 additions & 6 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
add_subdirectory(dhcp_dns)
add_subdirectory(ftp)
add_subdirectory(http)
#add_subdirectory(dhcp_dns)
#add_subdirectory(ftp)
#add_subdirectory(http)
add_subdirectory(loopback)
add_subdirectory(mqtt)
add_subdirectory(sntp)
add_subdirectory(tcp_client_over_ssl)
# add_subdirectory(lwip)
#add_subdirectory(mqtt)
#add_subdirectory(sntp)
#add_subdirectory(tcp_client_over_ssl)
#add_subdirectory(spi)
70 changes: 67 additions & 3 deletions examples/loopback/w5x00_loopback.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,43 @@

#include "loopback.h"

#include "socket.h"

/**
* ----------------------------------------------------------------------------------------------------
* Macros
* ----------------------------------------------------------------------------------------------------
*/
/* Clock */
#define PLL_SYS_KHZ (133 * 1000)
// #define PLL_SYS_KHZ (133 * 1000)
#define PLL_SYS_KHZ (90 * 1000)
//#define PLL_SYS_KHZ (125 * 1000) 62.5 XXX
//#define PLL_SYS_KHZ (100 * 1000) 50 xxx

/* Buffer */
#define ETHERNET_BUF_MAX_SIZE (1024 * 2)

#define ETHERNET_BUF_MAX_SIZE (1024 * 16)

/* Socket */
#define SOCKET_LOOPBACK 0
#define SOCKET_TOE_IPERF 0

/* Port */
#define PORT_LOOPBACK 5000
#define PORT_TOE_IPERF 5001

/**
* ----------------------------------------------------------------------------------------------------
* Variables
* ----------------------------------------------------------------------------------------------------
*
*
*/
/* Network */
static wiz_NetInfo g_net_info =
{
.mac = {0x00, 0x08, 0xDC, 0x12, 0x34, 0x56}, // MAC address
.ip = {192, 168, 11, 2}, // IP address
.ip = {192, 168, 11, 3}, // IP address
.sn = {255, 255, 255, 0}, // Subnet Mask
.gw = {192, 168, 11, 1}, // Gateway
.dns = {8, 8, 8, 8}, // DNS server
Expand All @@ -56,6 +66,11 @@ static uint8_t g_loopback_buf[ETHERNET_BUF_MAX_SIZE] = {
0,
};

/* iperf */
static uint8_t g_iperf_buf[ETHERNET_BUF_MAX_SIZE] = {
0,
};

/**
* ----------------------------------------------------------------------------------------------------
* Functions
Expand All @@ -74,15 +89,29 @@ int main()
/* Initialize */
int retval = 0;

//iperf
uint32_t pack_len = 0, recv_len = 0;
uint8_t destip[4];
uint16_t destport;

set_clock_khz();

stdio_init_all();

sleep_ms(3000);

wizchip_spi_initialize();
printf("Start1\n");

wizchip_cris_initialize();
printf("Start2\n");

wizchip_reset();
printf("Start3\n");

wizchip_initialize();

printf("Start\n");
wizchip_check();

network_initialize(g_net_info);
Expand All @@ -93,6 +122,40 @@ int main()
/* Infinite loop */
while (1)
{
#if 1
switch(getSn_SR(SOCKET_TOE_IPERF))
{
case SOCK_ESTABLISHED :
while(1)
{
getsockopt(SOCKET_TOE_IPERF, SO_RECVBUF, &pack_len);
if (pack_len > 0)
{
recv_iperf(SOCKET_TOE_IPERF, (uint8_t *)g_iperf_buf, ETHERNET_BUF_MAX_SIZE / 2);
#if 0
while(1)
{
recv_len = recv(SOCKET_TOE_IPERF, (uint8_t *)g_iperf_buf, (pack_len > ETHERNET_BUF_MAX_SIZE) ? ETHERNET_BUF_MAX_SIZE : pack_len);
pack_len -= recv_len;
if (pack_len == 0)
break;
}
#endif
}
}
case SOCK_CLOSE_WAIT :
disconnect(SOCKET_TOE_IPERF);
break;
case SOCK_INIT :
listen(SOCKET_TOE_IPERF);
break;
case SOCK_CLOSED:
socket(SOCKET_TOE_IPERF, Sn_MR_TCP, PORT_TOE_IPERF, 0x00);
break;
default:
break;
}
#else
/* TCP server loopback test */
if ((retval = loopback_tcps(SOCKET_LOOPBACK, g_loopback_buf, PORT_LOOPBACK)) < 0)
{
Expand All @@ -101,6 +164,7 @@ int main()
while (1)
;
}
#endif
}
}

Expand Down
2 changes: 2 additions & 0 deletions examples/mqtt/publish/w5x00_mqtt_publish.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ int main()

stdio_init_all();

sleep_ms(3000);

wizchip_spi_initialize();
wizchip_cris_initialize();

Expand Down
34 changes: 30 additions & 4 deletions port/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
# ioLibrary_Driver
add_library(IOLIBRARY_FILES STATIC)
add_library(IOLIBRARY_FILES INTERFACE) #STATIC)

target_sources(IOLIBRARY_FILES PUBLIC
#pico_generate_pio_header(IOLIBRARY_FILES ${PORT_DIR}/ioLibrary_Driver/src/spi.pio)
pico_generate_pio_header(IOLIBRARY_FILES ${PORT_DIR}/ioLibrary_Driver/src/wiznet_spi_pio.pio)

target_sources(IOLIBRARY_FILES INTERFACE #PUBLIC
${PORT_DIR}/ioLibrary_Driver/src/w5x00_spi.c
${PORT_DIR}/ioLibrary_Driver/src/w5x00_gpio_irq.c
${PORT_DIR}/ioLibrary_Driver/src/wiznet_spi_pio.c
# ${PORT_DIR}/ioLibrary_Driver/src/pio_spi.c
)

target_include_directories(IOLIBRARY_FILES PUBLIC
target_include_directories(IOLIBRARY_FILES INTERFACE #PUBLIC
${WIZNET_DIR}/Ethernet
${PORT_DIR}/ioLibrary_Driver/inc
${PORT_DIR}
)

target_link_libraries(IOLIBRARY_FILES PRIVATE
target_link_libraries(IOLIBRARY_FILES INTERFACE #PRIVATE
pico_stdlib
hardware_pio
hardware_spi
hardware_dma
hardware_clocks
# WIZ_LWIP_FILES
)

# timer
Expand All @@ -33,3 +40,22 @@ target_include_directories(TIMER_FILES PUBLIC
target_link_libraries(TIMER_FILES PRIVATE
pico_stdlib
)

# # wiznet lwip
# add_library(WIZ_LWIP_FILES STATIC)

# target_sources(WIZ_LWIP_FILES PUBLIC
# ${PORT_DIR}/lwip/src/w5x00_lwip.c
# )

# target_include_directories(WIZ_LWIP_FILES PUBLIC
# ${PICO_EXTRAS_LWIP_SRC_DIR}
# ${WIZNET_DIR}/Ethernet
# ${PORT_DIR}
# ${PORT_DIR}/lwip/inc
# )

# target_link_libraries(WIZ_LWIP_FILES PRIVATE
# ETHERNET_FILES
# lwip
# )
21 changes: 13 additions & 8 deletions port/ioLibrary_Driver/inc/w5x00_spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
* Macros
* ----------------------------------------------------------------------------------------------------
*/

#define USE_SPI_PIO

/* SPI */
#define SPI_PORT spi0
//#define SPI_PORT spi0

#define PIN_SCK 18
#define PIN_MOSI 19
#define PIN_MISO 16
#define PIN_CS 17
#define PIN_RST 20
#define PIN_SCK 21
#define PIN_MOSI 23
#define PIN_MISO 22
#define PIN_CS 20
#define PIN_RST 25

/* Use SPI DMA */
//#define USE_SPI_DMA // if you want to use SPI DMA, uncomment.
Expand Down Expand Up @@ -57,7 +60,7 @@ static inline void wizchip_deselect(void);
*
* \param none
*/
static uint8_t wizchip_read(void);
uint8_t wizchip_read(void);

/*! \brief Write to an SPI device, blocking
* \ingroup w5x00_spi
Expand All @@ -68,7 +71,7 @@ static uint8_t wizchip_read(void);
*
* \param tx_data Buffer of data to write
*/
static void wizchip_write(uint8_t tx_data);
void wizchip_write(uint8_t tx_data);

#ifdef USE_SPI_DMA
/*! \brief Configure all DMA parameters and optionally start transfer
Expand Down Expand Up @@ -182,4 +185,6 @@ void network_initialize(wiz_NetInfo net_info);
*/
void print_network_information(wiz_NetInfo net_info);

int32_t recv_iperf(uint8_t sn, uint8_t * buf, uint16_t len);

#endif /* _W5X00_SPI_H_ */
39 changes: 39 additions & 0 deletions port/ioLibrary_Driver/inc/wiznet_spi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2023 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#ifndef _WIZNET_SPI_FUNCS_H_
#define _WIZNET_SPI_FUNCS_H_

#include <stdint.h>

typedef struct wiznet_spi_config {
uint8_t data_in_pin;
uint8_t data_out_pin;
uint8_t cs_pin;
uint8_t clock_pin;
uint8_t irq_pin;
uint8_t reset_pin;
uint16_t clock_div_major;
uint8_t clock_div_minor;
uint8_t spi_hw_instance;
} wiznet_spi_config_t;

typedef struct wiznet_spi_funcs** wiznet_spi_handle_t;

typedef struct wiznet_spi_funcs {
void (*close)(wiznet_spi_handle_t funcs);
void (*set_active)(wiznet_spi_handle_t funcs);
void (*set_inactive)(void);
void (*frame_start)(void);
void (*frame_end)(void);
uint8_t (*read_byte)(void);
void (*write_byte)(uint8_t tx_data);
void (*read_buffer)(uint8_t *pBuf, uint16_t len);
void (*write_buffer)(uint8_t *pBuf, uint16_t len);
void (*reset)(wiznet_spi_handle_t funcs);
} wiznet_spi_funcs_t;

#endif
15 changes: 15 additions & 0 deletions port/ioLibrary_Driver/inc/wiznet_spi_pio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2023 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#ifndef _WIZNET_SPI_PIO_H_
#define _WIZNET_SPI_PIO_H_

#include "wiznet_spi.h"


wiznet_spi_handle_t wiznet_spi_pio_open(const wiznet_spi_config_t *spi_config);

#endif
Loading

0 comments on commit 948105a

Please sign in to comment.