Hello, i managed to create a TCP Server and to make it listen, the thing is that the socket is stuck in listen state and i can’t managed to make any client to connect to it, am i missing something here ?
I’m using a EVB Pico W5500 Board :
IP and Gateway are correctly wrote in my code.
/**
-
- Includes
-
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include “port_common.h”
#include “wizchip_conf.h”
#include “socket.h”
#include “w5x00_spi.h”
#include “timer.h”
/**
-
- Macros
-
/
/ Clock */
#define PLL_SYS_KHZ (133 * 1000)
/* Buffer */
#define ETHERNET_BUF_MAX_SIZE (1024 * 2)
/**
-
- Variables
-
/
/ Network */
static wiz_NetInfo g_net_info =
{
.mac = {0x00, 0x08, 0xDC, 0x12, 0x34, 0x56}, // MAC address
.ip = {192, 168, XX, XX}, // IP address
.sn = {255, 255, 255, 0}, // Subnet Mask
.gw = {192, 168, XX, X}, // Gateway
.dhcp = NETINFO_DHCP // DHCP enable/disable
};
/**
-
- Functions
-
/
/ Clock */
static void set_clock_khz(void)
{
// set a system clock frequency in khz
set_sys_clock_khz(PLL_SYS_KHZ, true);
// configure the specified clock
clock_configure(
clk_peri,
0, // No glitchless mux
CLOCKS_CLK_PERI_CTRL_AUXSRC_VALUE_CLKSRC_PLL_SYS, // System PLL on AUX mux
PLL_SYS_KHZ * 1000, // Input frequency
PLL_SYS_KHZ * 1000 // Output (must be same as no divider)
);
}
/**
-
- Functions
-
/
/ Clock */
static void set_clock_khz(void);
void handleEstablishedStage(uint8_t sn) {
// Your code to handle the ESTABLISHED stage goes here
printf(“Socket %d is in ESTABLISHED stage\n”, sn);
}
/**
-
- Main
-
/
int main()
{
/ Initialize */
const int *list = NULL;
uint16_t len = 0;
uint32_t retval = 0;
uint32_t start_ms = 0;
set_clock_khz();
stdio_init_all();
wizchip_spi_initialize();
wizchip_cris_initialize();
wizchip_reset();
wizchip_initialize();
wizchip_check();
/* SPI read */
/* Get network information */
network_initialize(g_net_info);
print_network_information(g_net_info);
uint8_t tcp_data_buf[1024];
uint16_t sn = 0; // using only the socket 0
int32_t ret;
// init socket
uint8_t tcp_socket = socket(sn, Sn_MR_TCP, 50000, 0x00);
while (getSn_SR(sn) != SOCK_INIT);
uint8_t listen_status = listen(sn);
while (getSn_SR(sn) != SOCK_LISTEN);
uint8_t socket_status = getSn_SR(sn);
uint8_t socket_interrupt = getSn_IR(sn);
uint32_t tcp_data = recv(sn,tcp_data_buf,1024);
while(socket_interrupt == 0){
listen(sn);
recv(sn,tcp_data_buf,1024);
print_network_information(g_net_info);
printf("%d\n", tcp_socket);
printf("%d\n", listen_status);
printf("%x\n", socket_status);
printf("%x\n", socket_interrupt);
// Check if the interrupt flag is set for the specified socket
if (getSn_IR(sn) & Sn_IR_CON) {
// Clear the interrupt flag by writing '1' to the corresponding bit
setSn_IR(sn, Sn_IR_CON);
// Execute the code for ESTABLISHED stage
handleEstablishedStage(sn);
}
sleep_ms(1000);
}
while(socket_interrupt == 1){
printf(“Established\n” );
printf(“%x\n”, socket_status);
sleep_ms(1000);
}
}