forked from xuos/xiuos
Fit w5500 to lwip, fix some unintialized params and printf warning.
This commit is contained in:
parent
8b32c2f4ed
commit
31b939fbb8
|
@ -324,7 +324,7 @@ void TestSocket(int argc, char* argv[])
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
memset(iperf_param.host, 0, sizeof(iperf_param.host));
|
memset(iperf_param.host, 0, sizeof(iperf_param.host));
|
||||||
strncpy(iperf_param.host, ip_ptr, strlen(ip_ptr));
|
strncpy(iperf_param.host, ip_ptr, sizeof(iperf_param.host));
|
||||||
}
|
}
|
||||||
iperf_mode->mode = IPERF_MODE_CLIENT;
|
iperf_mode->mode = IPERF_MODE_CLIENT;
|
||||||
}
|
}
|
||||||
|
|
|
@ -206,7 +206,7 @@ static int PrivLcdIoctl(int fd, int cmd, void *args)
|
||||||
|
|
||||||
int PrivIoctl(int fd, int cmd, void *args)
|
int PrivIoctl(int fd, int cmd, void *args)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret = -ERROR;
|
||||||
struct PrivIoctlCfg *ioctl_cfg = (struct PrivIoctlCfg *)args;
|
struct PrivIoctlCfg *ioctl_cfg = (struct PrivIoctlCfg *)args;
|
||||||
switch (ioctl_cfg->ioctl_driver_type)
|
switch (ioctl_cfg->ioctl_driver_type)
|
||||||
{
|
{
|
||||||
|
|
|
@ -66,7 +66,7 @@ int timer_create(clockid_t clockid, struct sigevent * evp, timer_t * timerid)
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(timer_name, 0, sizeof(timer_name));
|
memset(timer_name, 0, sizeof(timer_name));
|
||||||
snprintf(timer_name, sizeof(timer_name), "timer_%d", clockid);
|
snprintf(timer_name, sizeof(timer_name), "timer_%ld", clockid);
|
||||||
|
|
||||||
sem_init(&timer_sem, 0, 0);
|
sem_init(&timer_sem, 0, 0);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
export CFLAGS := -mcmodel=medany -march=rv64imafdc -mabi=lp64d -fno-common -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -O0 -ggdb -fgnu89-inline -Werror
|
export CFLAGS := -mcmodel=medany -march=rv64imafdc -mabi=lp64d -fno-common -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -O1 -fgnu89-inline -Wformat -Wuninitialized
|
||||||
|
# export CFLAGS := -mcmodel=medany -march=rv64imafdc -mabi=lp64d -fno-common -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -O0 -ggdb -fgnu89-inline -Werror -Wformat -Wuninitialized
|
||||||
export AFLAGS := -c -mcmodel=medany -march=rv64imafdc -mabi=lp64d -x assembler-with-cpp -ggdb
|
export AFLAGS := -c -mcmodel=medany -march=rv64imafdc -mabi=lp64d -x assembler-with-cpp -ggdb
|
||||||
export LFLAGS := -mcmodel=medany -march=rv64imafdc -mabi=lp64d -nostartfiles -Wl,--gc-sections,-Map=XiZi-edu-riscv64.map,-cref,-u,_start -T $(BSP_ROOT)/link.lds
|
export LFLAGS := -mcmodel=medany -march=rv64imafdc -mabi=lp64d -nostartfiles -Wl,--gc-sections,-Map=XiZi-edu-riscv64.map,-cref,-u,_start -T $(BSP_ROOT)/link.lds
|
||||||
|
|
||||||
|
|
|
@ -25,11 +25,12 @@
|
||||||
#ifndef _BSP_ATOMIC_H
|
#ifndef _BSP_ATOMIC_H
|
||||||
#define _BSP_ATOMIC_H
|
#define _BSP_ATOMIC_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define SPINLOCK_INIT \
|
#define SPINLOCK_INIT \
|
||||||
{ \
|
{ \
|
||||||
0 \
|
0 \
|
||||||
|
@ -63,7 +64,7 @@ extern "C" {
|
||||||
|
|
||||||
typedef struct _spinlock
|
typedef struct _spinlock
|
||||||
{
|
{
|
||||||
int lock;
|
int32_t lock;
|
||||||
} spinlock_t;
|
} spinlock_t;
|
||||||
|
|
||||||
typedef struct _semaphore
|
typedef struct _semaphore
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# SRC_FILES := socket.c connect_w5500.c w5500.c wizchip_conf.c spi_interface.c wiz_ping.c connect_w5500_test.c wiz_iperf.c
|
# SRC_FILES := socket.c connect_w5500.c w5500.c wizchip_conf.c spi_interface.c wiz_ping.c connect_w5500_test.c wiz_iperf.c
|
||||||
SRC_FILES := socket.c connect_w5500.c w5500.c wizchip_conf.c spi_interface.c connect_w5500_test.c w5x00_lwip.c
|
SRC_FILES := socket.c connect_w5500.c w5500.c wizchip_conf.c spi_interface.c wiz_ping.c connect_w5500_test.c w5x00_lwip.c wiz_iperf.c
|
||||||
|
|
||||||
include $(KERNEL_ROOT)/compiler.mk
|
include $(KERNEL_ROOT)/compiler.mk
|
|
@ -5,8 +5,8 @@
|
||||||
#include <dev_pin.h>
|
#include <dev_pin.h>
|
||||||
#include <drv_io_config.h>
|
#include <drv_io_config.h>
|
||||||
#include <fpioa.h>
|
#include <fpioa.h>
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <xs_base.h>
|
#include <xs_base.h>
|
||||||
|
|
||||||
#include "gpio_common.h"
|
#include "gpio_common.h"
|
||||||
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
#include "connect_ethernet.h"
|
#include "connect_ethernet.h"
|
||||||
|
|
||||||
|
#include <sys.h>
|
||||||
|
|
||||||
#define SPI_LORA_FREQUENCY 10000000
|
#define SPI_LORA_FREQUENCY 10000000
|
||||||
|
|
||||||
// spi operations
|
// spi operations
|
||||||
|
@ -25,26 +27,29 @@ extern void spi_select_cs(void);
|
||||||
extern void spi_deselete_cs(void);
|
extern void spi_deselete_cs(void);
|
||||||
|
|
||||||
// global configurations for w5500 tcp connection
|
// global configurations for w5500 tcp connection
|
||||||
uint32_t get_gbuf_size() {
|
uint32_t get_gbuf_size()
|
||||||
|
{
|
||||||
static const uint32_t g_wiznet_buf_size = 2048;
|
static const uint32_t g_wiznet_buf_size = 2048;
|
||||||
return g_wiznet_buf_size;
|
return g_wiznet_buf_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
wiz_NetInfo *get_gnetinfo() {
|
wiz_NetInfo* get_gnetinfo()
|
||||||
static wiz_NetInfo g_wiz_netinfo = {.mac = {0x00, 0x08, 0xdc, 0x11, 0x11, 0x11},
|
{
|
||||||
.ip = {192, 168, 130, 77},
|
static wiz_NetInfo g_wiz_netinfo = { .mac = { 0x00, 0x08, 0xdc, 0x11, 0x11, 0x11 },
|
||||||
.sn = {255, 255, 254, 0},
|
.ip = { 192, 168, 130, 77 },
|
||||||
.gw = {192, 168, 130, 1},
|
.sn = { 255, 255, 254, 0 },
|
||||||
.dns = {0, 0, 0, 0},
|
.gw = { 192, 168, 130, 1 },
|
||||||
.dhcp = NETINFO_STATIC};
|
.dns = { 0, 0, 0, 0 },
|
||||||
|
.dhcp = NETINFO_STATIC };
|
||||||
return &g_wiz_netinfo;
|
return &g_wiz_netinfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
int network_init() {
|
int network_init()
|
||||||
|
{
|
||||||
wiz_NetInfo check_wiz_netinfo;
|
wiz_NetInfo check_wiz_netinfo;
|
||||||
check_wiz_netinfo.dhcp = NETINFO_STATIC;
|
check_wiz_netinfo.dhcp = NETINFO_STATIC;
|
||||||
ctlnetwork(CN_SET_NETINFO, (void *)get_gnetinfo());
|
ctlnetwork(CN_SET_NETINFO, (void*)get_gnetinfo());
|
||||||
ctlnetwork(CN_GET_NETINFO, (void *)&check_wiz_netinfo);
|
ctlnetwork(CN_GET_NETINFO, (void*)&check_wiz_netinfo);
|
||||||
|
|
||||||
if (memcmp(get_gnetinfo(), &check_wiz_netinfo, sizeof(wiz_NetInfo)) != 0) {
|
if (memcmp(get_gnetinfo(), &check_wiz_netinfo, sizeof(wiz_NetInfo)) != 0) {
|
||||||
KPrintf(
|
KPrintf(
|
||||||
|
@ -59,8 +64,8 @@ int network_init() {
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
uint8_t tmpstr[6];
|
uint8_t tmpstr[6];
|
||||||
ctlwizchip(CW_GET_ID, (void *)tmpstr);
|
ctlwizchip(CW_GET_ID, (void*)tmpstr);
|
||||||
KPrintf("=== %s NET CONF ===\r\n", (char *)tmpstr);
|
KPrintf("=== %s NET CONF ===\r\n", (char*)tmpstr);
|
||||||
KPrintf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\r\n", get_gnetinfo()->mac[0],
|
KPrintf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\r\n", get_gnetinfo()->mac[0],
|
||||||
get_gnetinfo()->mac[1], get_gnetinfo()->mac[2], get_gnetinfo()->mac[3],
|
get_gnetinfo()->mac[1], get_gnetinfo()->mac[2], get_gnetinfo()->mac[3],
|
||||||
get_gnetinfo()->mac[4], get_gnetinfo()->mac[5]);
|
get_gnetinfo()->mac[4], get_gnetinfo()->mac[5]);
|
||||||
|
@ -78,13 +83,13 @@ int network_init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************** spi init ******************/
|
/****************** spi init ******************/
|
||||||
static struct Bus *w5500_spi_bus;
|
static struct Bus* w5500_spi_bus;
|
||||||
int w5500_spi_init() {
|
int w5500_spi_init()
|
||||||
|
{
|
||||||
x_err_t ret = EOK;
|
x_err_t ret = EOK;
|
||||||
|
|
||||||
w5500_spi_bus = BusFind(SPI_BUS_NAME_1);
|
w5500_spi_bus = BusFind(SPI_BUS_NAME_1);
|
||||||
w5500_spi_bus->owner_haldev =
|
w5500_spi_bus->owner_haldev = BusFindDevice(w5500_spi_bus, SPI_1_DEVICE_NAME_0);
|
||||||
BusFindDevice(w5500_spi_bus, SPI_1_DEVICE_NAME_0);
|
|
||||||
w5500_spi_bus->owner_driver = BusFindDriver(w5500_spi_bus, SPI_1_DRV_NAME);
|
w5500_spi_bus->owner_driver = BusFindDriver(w5500_spi_bus, SPI_1_DRV_NAME);
|
||||||
|
|
||||||
w5500_spi_bus->match(w5500_spi_bus->owner_driver,
|
w5500_spi_bus->match(w5500_spi_bus->owner_driver,
|
||||||
|
@ -98,7 +103,7 @@ int w5500_spi_init() {
|
||||||
spi_master_param.spi_data_endian = 0;
|
spi_master_param.spi_data_endian = 0;
|
||||||
|
|
||||||
configure_info.configure_cmd = OPE_CFG;
|
configure_info.configure_cmd = OPE_CFG;
|
||||||
configure_info.private_data = (void *)&spi_master_param;
|
configure_info.private_data = (void*)&spi_master_param;
|
||||||
ret = BusDrvConfigure(w5500_spi_bus->owner_driver, &configure_info);
|
ret = BusDrvConfigure(w5500_spi_bus->owner_driver, &configure_info);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
KPrintf("spi drv OPE_CFG error drv %8p cfg %8p\n",
|
KPrintf("spi drv OPE_CFG error drv %8p cfg %8p\n",
|
||||||
|
@ -116,13 +121,16 @@ int w5500_spi_init() {
|
||||||
return EOK;
|
return EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi_write_byte(uint8_t tx_data) {
|
void spi_write_byte(uint8_t tx_data)
|
||||||
|
{
|
||||||
struct BusBlockWriteParam write_param;
|
struct BusBlockWriteParam write_param;
|
||||||
write_param.buffer = &tx_data;
|
uint8_t data = tx_data;
|
||||||
|
write_param.buffer = &data;
|
||||||
write_param.size = 1;
|
write_param.size = 1;
|
||||||
BusDevWriteData(w5500_spi_bus->owner_haldev, &write_param);
|
BusDevWriteData(w5500_spi_bus->owner_haldev, &write_param);
|
||||||
}
|
}
|
||||||
uint8_t spi_read_byte(void) {
|
uint8_t spi_read_byte(void)
|
||||||
|
{
|
||||||
uint8_t result = 0;
|
uint8_t result = 0;
|
||||||
struct BusBlockReadParam read_param;
|
struct BusBlockReadParam read_param;
|
||||||
read_param.buffer = &result;
|
read_param.buffer = &result;
|
||||||
|
@ -130,13 +138,15 @@ uint8_t spi_read_byte(void) {
|
||||||
BusDevReadData(w5500_spi_bus->owner_haldev, &read_param);
|
BusDevReadData(w5500_spi_bus->owner_haldev, &read_param);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
void spi_write_burst(uint8_t *tx_buf, uint16_t len) {
|
void spi_write_burst(uint8_t* tx_buf, uint16_t len)
|
||||||
|
{
|
||||||
struct BusBlockWriteParam write_param;
|
struct BusBlockWriteParam write_param;
|
||||||
write_param.buffer = tx_buf;
|
write_param.buffer = tx_buf;
|
||||||
write_param.size = len;
|
write_param.size = len;
|
||||||
BusDevWriteData(w5500_spi_bus->owner_haldev, &write_param);
|
BusDevWriteData(w5500_spi_bus->owner_haldev, &write_param);
|
||||||
}
|
}
|
||||||
void spi_read_burst(uint8_t *rx_buf, uint16_t len) {
|
void spi_read_burst(uint8_t* rx_buf, uint16_t len)
|
||||||
|
{
|
||||||
struct BusBlockReadParam read_param;
|
struct BusBlockReadParam read_param;
|
||||||
read_param.buffer = rx_buf;
|
read_param.buffer = rx_buf;
|
||||||
read_param.size = len;
|
read_param.size = len;
|
||||||
|
@ -145,7 +155,8 @@ void spi_read_burst(uint8_t *rx_buf, uint16_t len) {
|
||||||
|
|
||||||
/****************** chip init ******************/
|
/****************** chip init ******************/
|
||||||
|
|
||||||
void wiz_reset() {
|
void wiz_reset()
|
||||||
|
{
|
||||||
gpiohs_set_drive_mode(WIZ_RST_PIN, GPIO_DM_OUTPUT);
|
gpiohs_set_drive_mode(WIZ_RST_PIN, GPIO_DM_OUTPUT);
|
||||||
gpiohs_set_pin(WIZ_RST_PIN, GPIO_PV_LOW);
|
gpiohs_set_pin(WIZ_RST_PIN, GPIO_PV_LOW);
|
||||||
MdelayKTask(20);
|
MdelayKTask(20);
|
||||||
|
@ -154,10 +165,10 @@ void wiz_reset() {
|
||||||
MdelayKTask(20);
|
MdelayKTask(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wiz_spi_handler_reg() {
|
void wiz_spi_handler_reg()
|
||||||
|
{
|
||||||
// spi ops registration
|
// spi ops registration
|
||||||
#if (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_VDM_) || \
|
#if (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_VDM_) || (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_FDM_)
|
||||||
(_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_FDM_)
|
|
||||||
/* register SPI device CS select callback function */
|
/* register SPI device CS select callback function */
|
||||||
gpiohs_set_drive_mode(SPI1_CS0_PIN, GPIO_DM_OUTPUT);
|
gpiohs_set_drive_mode(SPI1_CS0_PIN, GPIO_DM_OUTPUT);
|
||||||
reg_wizchip_cs_cbfunc(spi_select_cs, spi_deselete_cs);
|
reg_wizchip_cs_cbfunc(spi_select_cs, spi_deselete_cs);
|
||||||
|
@ -174,11 +185,12 @@ void wiz_spi_handler_reg() {
|
||||||
reg_wizchip_spiburst_cbfunc(spi_read_burst, spi_write_burst);
|
reg_wizchip_spiburst_cbfunc(spi_read_burst, spi_write_burst);
|
||||||
}
|
}
|
||||||
|
|
||||||
int wiz_chip_cfg_init() {
|
int wiz_chip_cfg_init()
|
||||||
uint8_t mem_size[2][8] = {{2, 2, 2, 2, 2, 2, 2, 2}, {2, 2, 2, 2, 2, 2, 2, 2}};
|
{
|
||||||
|
uint8_t mem_size[2][8] = { { 2, 2, 2, 2, 2, 2, 2, 2 }, { 2, 2, 2, 2, 2, 2, 2, 2 } };
|
||||||
|
|
||||||
/* reset WIZnet chip internal PHY, configures PHY mode. */
|
/* reset WIZnet chip internal PHY, configures PHY mode. */
|
||||||
if (ctlwizchip(CW_INIT_WIZCHIP, (void *)mem_size) == -1) {
|
if (ctlwizchip(CW_INIT_WIZCHIP, (void*)mem_size) == -1) {
|
||||||
KPrintf("WIZCHIP initialize failed.");
|
KPrintf("WIZCHIP initialize failed.");
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
@ -186,24 +198,77 @@ int wiz_chip_cfg_init() {
|
||||||
struct wiz_NetTimeout_t net_timeout;
|
struct wiz_NetTimeout_t net_timeout;
|
||||||
net_timeout.retry_cnt = 5;
|
net_timeout.retry_cnt = 5;
|
||||||
net_timeout.time_100us = 20000;
|
net_timeout.time_100us = 20000;
|
||||||
ctlnetwork(CN_SET_TIMEOUT, (void *)&net_timeout);
|
ctlnetwork(CN_SET_TIMEOUT, (void*)&net_timeout);
|
||||||
|
|
||||||
return EOK;
|
return EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************** interrupt handle ******************/
|
/****************** interrupt handle ******************/
|
||||||
void wiz_irq_handler() {}
|
#ifdef BSP_USING_LWIP
|
||||||
|
#include <sys.h>
|
||||||
|
static inline void spi_if_clr(void)
|
||||||
|
{
|
||||||
|
setSn_IR(0, 0x1F);
|
||||||
|
setSIR(0);
|
||||||
|
}
|
||||||
|
|
||||||
int wiz_interrupt_init() {
|
void wiz_irq_handler()
|
||||||
|
{
|
||||||
|
static x_base eth_irq_lock;
|
||||||
|
eth_irq_lock = DISABLE_INTERRUPT();
|
||||||
|
|
||||||
|
if (*get_eth_recv_sem() > 0) {
|
||||||
|
sys_sem_signal(get_eth_recv_sem());
|
||||||
|
}
|
||||||
|
|
||||||
|
ENABLE_INTERRUPT(eth_irq_lock);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
void wiz_irq_handler()
|
||||||
|
{
|
||||||
|
static x_base eth_irq_lock;
|
||||||
|
eth_irq_lock = DISABLE_INTERRUPT();
|
||||||
|
|
||||||
|
printf("=");
|
||||||
|
uint8_t ir = getIR();
|
||||||
|
setSIR(0x00);
|
||||||
|
setIR(0x00);
|
||||||
|
|
||||||
|
ENABLE_INTERRUPT(eth_irq_lock);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void wizchip_interrupt_init(uint8_t socket, void (*callback)(void*))
|
||||||
|
{
|
||||||
|
int ret_val;
|
||||||
|
|
||||||
|
uint8_t reg_val1;
|
||||||
|
reg_val1 = (SIK_CONNECTED | SIK_DISCONNECTED | SIK_RECEIVED | SIK_TIMEOUT); // except SendOK
|
||||||
|
ret_val = wiz_ctlsocket(socket, CS_SET_INTMASK, (void*)®_val1);
|
||||||
|
|
||||||
|
#if (_WIZCHIP_ == W5100S)
|
||||||
|
reg_val = (1 << socket);
|
||||||
|
#elif (_WIZCHIP_ == W5500)
|
||||||
|
uint16_t reg_val2 = ((1 << socket) << 8);
|
||||||
|
#endif
|
||||||
|
ret_val = ctlwizchip(CW_SET_INTRMASK, (void*)®_val2);
|
||||||
|
|
||||||
|
(void)ret_val;
|
||||||
|
}
|
||||||
|
|
||||||
|
int wiz_interrupt_init()
|
||||||
|
{
|
||||||
int32_t ret = -ERROR;
|
int32_t ret = -ERROR;
|
||||||
|
|
||||||
struct Bus *pin_bus = PinBusInitGet();
|
wizchip_interrupt_init(0, wiz_irq_handler);
|
||||||
|
|
||||||
|
struct Bus* pin_bus = PinBusInitGet();
|
||||||
|
|
||||||
struct PinParam pin_param;
|
struct PinParam pin_param;
|
||||||
struct BusConfigureInfo pin_configure_info;
|
struct BusConfigureInfo pin_configure_info;
|
||||||
|
|
||||||
pin_configure_info.configure_cmd = OPE_CFG;
|
pin_configure_info.configure_cmd = OPE_CFG;
|
||||||
pin_configure_info.private_data = (void *)&pin_param;
|
pin_configure_info.private_data = (void*)&pin_param;
|
||||||
|
|
||||||
pin_param.cmd = GPIO_CONFIG_MODE;
|
pin_param.cmd = GPIO_CONFIG_MODE;
|
||||||
pin_param.pin = BSP_WIZ_INT_PIN;
|
pin_param.pin = BSP_WIZ_INT_PIN;
|
||||||
|
@ -243,11 +308,10 @@ int wiz_interrupt_init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
return EOK;
|
return EOK;
|
||||||
|
|
||||||
return EOK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int HwWiznetInit(void) {
|
int HwWiznetInit(void)
|
||||||
|
{
|
||||||
wiz_reset();
|
wiz_reset();
|
||||||
|
|
||||||
if (EOK != w5500_spi_init()) {
|
if (EOK != w5500_spi_init()) {
|
||||||
|
@ -264,19 +328,23 @@ int HwWiznetInit(void) {
|
||||||
setSHAR(wiz_mac);
|
setSHAR(wiz_mac);
|
||||||
ctlwizchip(CW_RESET_PHY, 0);
|
ctlwizchip(CW_RESET_PHY, 0);
|
||||||
|
|
||||||
setSn_MR(0, Sn_MR_MFEN | Sn_MR_MACRAW | Sn_MR_MIP6B | Sn_MR_MMB);
|
wiz_interrupt_init(0, wiz_irq_handler);
|
||||||
// setSn_RXBUF_SIZE(0, 16);
|
|
||||||
// setSn_TXBUF_SIZE(0, 16);
|
setSn_RXBUF_SIZE(0, 16);
|
||||||
|
setSn_TXBUF_SIZE(0, 16);
|
||||||
#define SOCK_ANY_PORT_NUM 0xC000
|
#define SOCK_ANY_PORT_NUM 0xC000
|
||||||
wiz_socket(0, Sn_MR_MACRAW, SOCK_ANY_PORT_NUM, 0x00);
|
setSn_MR(0, Sn_MR_MFEN | Sn_MR_MACRAW | Sn_MR_MIP6B | Sn_MR_MMB);
|
||||||
// setSn_CR(0, Sn_CR_OPEN);
|
wiz_socket(0, Sn_MR_MACRAW, SOCK_ANY_PORT_NUM, SOCK_IO_NONBLOCK);
|
||||||
// setSn_CR(0, Sn_CR_CONNECT);
|
|
||||||
|
uint8_t sock_iomode = SOCK_IO_NONBLOCK;
|
||||||
|
wiz_ctlsocket(0, CS_SET_IOMODE, &sock_iomode);
|
||||||
|
|
||||||
uint8_t sock_sr = 0;
|
uint8_t sock_sr = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
SYS_KDEBUG_LOG(WIZNET_DEBUG, ("[%s] sock_sr: %x, MACRAW: %x\n", __func__, sock_sr = getSn_SR(0), SOCK_MACRAW));
|
sock_sr = getSn_SR(0);
|
||||||
|
SYS_KDEBUG_LOG(WIZNET_DEBUG, ("[%s] sock_sr: %x, MACRAW: %x\n", __func__, sock_sr, SOCK_MACRAW));
|
||||||
if (sock_sr == SOCK_MACRAW) {
|
if (sock_sr == SOCK_MACRAW) {
|
||||||
SYS_KDEBUG_LOG(WIZNET_DEBUG, ("Socket 0 MACRAW mdoe established\r\n"));
|
SYS_KDEBUG_LOG(WIZNET_DEBUG, ("Socket 0 MACRAW mode established\r\n"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@
|
||||||
#include "wizchip_conf.h"
|
#include "wizchip_conf.h"
|
||||||
|
|
||||||
// M20150401 : Typing Error
|
// M20150401 : Typing Error
|
||||||
//#define SOCK_ANY_PORT_NUM 0xC000;
|
// #define SOCK_ANY_PORT_NUM 0xC000;
|
||||||
#define SOCK_ANY_PORT_NUM 0xC000
|
#define SOCK_ANY_PORT_NUM 0xC000
|
||||||
|
|
||||||
static uint16_t sock_any_port = SOCK_ANY_PORT_NUM;
|
static uint16_t sock_any_port = SOCK_ANY_PORT_NUM;
|
||||||
|
@ -96,25 +96,30 @@ uint8_t sock_remained_byte[_WIZCHIP_SOCK_NUM_] = {
|
||||||
|
|
||||||
#define CHECK_SOCKNUM() \
|
#define CHECK_SOCKNUM() \
|
||||||
do { \
|
do { \
|
||||||
if (sn > _WIZCHIP_SOCK_NUM_) return SOCKERR_SOCKNUM; \
|
if (sn > _WIZCHIP_SOCK_NUM_) \
|
||||||
|
return SOCKERR_SOCKNUM; \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
#define CHECK_SOCKMODE(mode) \
|
#define CHECK_SOCKMODE(mode) \
|
||||||
do { \
|
do { \
|
||||||
if ((getSn_MR(sn) & 0x0F) != mode) return SOCKERR_SOCKMODE; \
|
if ((getSn_MR(sn) & 0x0F) != mode) \
|
||||||
|
return SOCKERR_SOCKMODE; \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
#define CHECK_SOCKINIT() \
|
#define CHECK_SOCKINIT() \
|
||||||
do { \
|
do { \
|
||||||
if ((getSn_SR(sn) != SOCK_INIT)) return SOCKERR_SOCKINIT; \
|
if ((getSn_SR(sn) != SOCK_INIT)) \
|
||||||
|
return SOCKERR_SOCKINIT; \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
#define CHECK_SOCKDATA() \
|
#define CHECK_SOCKDATA() \
|
||||||
do { \
|
do { \
|
||||||
if (len == 0) return SOCKERR_DATALEN; \
|
if (len == 0) \
|
||||||
|
return SOCKERR_DATALEN; \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
int8_t wiz_socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag) {
|
int8_t wiz_socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag)
|
||||||
|
{
|
||||||
CHECK_SOCKNUM();
|
CHECK_SOCKNUM();
|
||||||
switch (protocol) {
|
switch (protocol) {
|
||||||
case Sn_MR_TCP: {
|
case Sn_MR_TCP: {
|
||||||
|
@ -124,8 +129,9 @@ int8_t wiz_socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag) {
|
||||||
getSIPR(taddr);
|
getSIPR(taddr);
|
||||||
*/
|
*/
|
||||||
uint32_t taddr;
|
uint32_t taddr;
|
||||||
getSIPR((uint8_t *)&taddr);
|
getSIPR((uint8_t*)&taddr);
|
||||||
if (taddr == 0) return SOCKERR_SOCKINIT;
|
if (taddr == 0)
|
||||||
|
return SOCKERR_SOCKINIT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Sn_MR_UDP:
|
case Sn_MR_UDP:
|
||||||
|
@ -141,9 +147,11 @@ int8_t wiz_socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag) {
|
||||||
}
|
}
|
||||||
// M20150601 : For SF_TCP_ALIGN & W5300
|
// M20150601 : For SF_TCP_ALIGN & W5300
|
||||||
// if((flag & 0x06) != 0) return SOCKERR_SOCKFLAG;
|
// if((flag & 0x06) != 0) return SOCKERR_SOCKFLAG;
|
||||||
if ((flag & 0x04) != 0) return SOCKERR_SOCKFLAG;
|
if ((flag & 0x04) != 0)
|
||||||
|
return SOCKERR_SOCKFLAG;
|
||||||
#if _WIZCHIP_ == 5200
|
#if _WIZCHIP_ == 5200
|
||||||
if (flag & 0x10) return SOCKERR_SOCKFLAG;
|
if (flag & 0x10)
|
||||||
|
return SOCKERR_SOCKFLAG;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (flag != 0) {
|
if (flag != 0) {
|
||||||
|
@ -161,11 +169,13 @@ int8_t wiz_socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag) {
|
||||||
break;
|
break;
|
||||||
case Sn_MR_UDP:
|
case Sn_MR_UDP:
|
||||||
if (flag & SF_IGMP_VER2) {
|
if (flag & SF_IGMP_VER2) {
|
||||||
if ((flag & SF_MULTI_ENABLE) == 0) return SOCKERR_SOCKFLAG;
|
if ((flag & SF_MULTI_ENABLE) == 0)
|
||||||
|
return SOCKERR_SOCKFLAG;
|
||||||
}
|
}
|
||||||
#if _WIZCHIP_ == 5500
|
#if _WIZCHIP_ == 5500
|
||||||
if (flag & SF_UNI_BLOCK) {
|
if (flag & SF_UNI_BLOCK) {
|
||||||
if ((flag & SF_MULTI_ENABLE) == 0) return SOCKERR_SOCKFLAG;
|
if ((flag & SF_MULTI_ENABLE) == 0)
|
||||||
|
return SOCKERR_SOCKFLAG;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
@ -176,14 +186,14 @@ int8_t wiz_socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag) {
|
||||||
wiz_sock_close(sn);
|
wiz_sock_close(sn);
|
||||||
// M20150601
|
// M20150601
|
||||||
#if _WIZCHIP_ == 5300
|
#if _WIZCHIP_ == 5300
|
||||||
setSn_MR(sn, ((uint16_t)(protocol | (flag & 0xF0))) |
|
setSn_MR(sn, ((uint16_t)(protocol | (flag & 0xF0))) | (((uint16_t)(flag & 0x02)) << 7));
|
||||||
(((uint16_t)(flag & 0x02)) << 7));
|
|
||||||
#else
|
#else
|
||||||
setSn_MR(sn, (protocol | (flag & 0xF0)));
|
setSn_MR(sn, (protocol | (flag & 0xF0)));
|
||||||
#endif
|
#endif
|
||||||
if (!port) {
|
if (!port) {
|
||||||
port = sock_any_port++;
|
port = sock_any_port++;
|
||||||
if (sock_any_port == 0xFFF0) sock_any_port = SOCK_ANY_PORT_NUM;
|
if (sock_any_port == 0xFFF0)
|
||||||
|
sock_any_port = SOCK_ANY_PORT_NUM;
|
||||||
}
|
}
|
||||||
setSn_PORT(sn, port);
|
setSn_PORT(sn, port);
|
||||||
setSn_CR(sn, Sn_CR_OPEN);
|
setSn_CR(sn, Sn_CR_OPEN);
|
||||||
|
@ -204,16 +214,16 @@ int8_t wiz_socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag) {
|
||||||
return (int8_t)sn;
|
return (int8_t)sn;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t wiz_sock_close(uint8_t sn) {
|
int8_t wiz_sock_close(uint8_t sn)
|
||||||
|
{
|
||||||
CHECK_SOCKNUM();
|
CHECK_SOCKNUM();
|
||||||
// A20160426 : Applied the erratum 1 of W5300
|
// A20160426 : Applied the erratum 1 of W5300
|
||||||
#if (_WIZCHIP_ == 5300)
|
#if (_WIZCHIP_ == 5300)
|
||||||
// M20160503 : Wrong socket parameter. s -> sn
|
// M20160503 : Wrong socket parameter. s -> sn
|
||||||
// if( ((getSn_MR(s)& 0x0F) == Sn_MR_TCP) && (getSn_TX_FSR(s) !=
|
// if( ((getSn_MR(s)& 0x0F) == Sn_MR_TCP) && (getSn_TX_FSR(s) !=
|
||||||
// getSn_TxMAX(s)) )
|
// getSn_TxMAX(s)) )
|
||||||
if (((getSn_MR(sn) & 0x0F) == Sn_MR_TCP) &&
|
if (((getSn_MR(sn) & 0x0F) == Sn_MR_TCP) && (getSn_TX_FSR(sn) != getSn_TxMAX(sn))) {
|
||||||
(getSn_TX_FSR(sn) != getSn_TxMAX(sn))) {
|
uint8_t destip[4] = { 0, 0, 0, 1 };
|
||||||
uint8_t destip[4] = {0, 0, 0, 1};
|
|
||||||
// TODO
|
// TODO
|
||||||
// You can wait for completing to sending data;
|
// You can wait for completing to sending data;
|
||||||
// wait about 1 second;
|
// wait about 1 second;
|
||||||
|
@ -255,7 +265,8 @@ int8_t wiz_sock_close(uint8_t sn) {
|
||||||
return SOCK_OK;
|
return SOCK_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t wiz_sock_listen(uint8_t sn) {
|
int8_t wiz_sock_listen(uint8_t sn)
|
||||||
|
{
|
||||||
CHECK_SOCKNUM();
|
CHECK_SOCKNUM();
|
||||||
CHECK_SOCKMODE(Sn_MR_TCP);
|
CHECK_SOCKMODE(Sn_MR_TCP);
|
||||||
CHECK_SOCKINIT();
|
CHECK_SOCKINIT();
|
||||||
|
@ -269,7 +280,8 @@ int8_t wiz_sock_listen(uint8_t sn) {
|
||||||
return SOCK_OK;
|
return SOCK_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t wiz_sock_connect(uint8_t sn, uint8_t *addr, uint16_t port) {
|
int8_t wiz_sock_connect(uint8_t sn, uint8_t* addr, uint16_t port)
|
||||||
|
{
|
||||||
CHECK_SOCKNUM();
|
CHECK_SOCKNUM();
|
||||||
CHECK_SOCKMODE(Sn_MR_TCP);
|
CHECK_SOCKMODE(Sn_MR_TCP);
|
||||||
CHECK_SOCKINIT();
|
CHECK_SOCKINIT();
|
||||||
|
@ -282,17 +294,20 @@ int8_t wiz_sock_connect(uint8_t sn, uint8_t *addr, uint16_t port) {
|
||||||
taddr = (taddr << 8) + ((uint32_t)addr[1] & 0x000000FF);
|
taddr = (taddr << 8) + ((uint32_t)addr[1] & 0x000000FF);
|
||||||
taddr = (taddr << 8) + ((uint32_t)addr[2] & 0x000000FF);
|
taddr = (taddr << 8) + ((uint32_t)addr[2] & 0x000000FF);
|
||||||
taddr = (taddr << 8) + ((uint32_t)addr[3] & 0x000000FF);
|
taddr = (taddr << 8) + ((uint32_t)addr[3] & 0x000000FF);
|
||||||
if (taddr == 0xFFFFFFFF || taddr == 0) return SOCKERR_IPINVALID;
|
if (taddr == 0xFFFFFFFF || taddr == 0)
|
||||||
|
return SOCKERR_IPINVALID;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
|
||||||
if (port == 0) return SOCKERR_PORTZERO;
|
if (port == 0)
|
||||||
|
return SOCKERR_PORTZERO;
|
||||||
setSn_DIPR(sn, addr);
|
setSn_DIPR(sn, addr);
|
||||||
setSn_DPORT(sn, port);
|
setSn_DPORT(sn, port);
|
||||||
setSn_CR(sn, Sn_CR_CONNECT);
|
setSn_CR(sn, Sn_CR_CONNECT);
|
||||||
while (getSn_CR(sn))
|
while (getSn_CR(sn))
|
||||||
;
|
;
|
||||||
if (sock_io_mode & (1 << sn)) return SOCK_BUSY;
|
if (sock_io_mode & (1 << sn))
|
||||||
|
return SOCK_BUSY;
|
||||||
while (getSn_SR(sn) != SOCK_ESTABLISHED) {
|
while (getSn_SR(sn) != SOCK_ESTABLISHED) {
|
||||||
if (getSn_IR(sn) & Sn_IR_TIMEOUT) {
|
if (getSn_IR(sn) & Sn_IR_TIMEOUT) {
|
||||||
setSn_IR(sn, Sn_IR_TIMEOUT);
|
setSn_IR(sn, Sn_IR_TIMEOUT);
|
||||||
|
@ -307,7 +322,8 @@ int8_t wiz_sock_connect(uint8_t sn, uint8_t *addr, uint16_t port) {
|
||||||
return SOCK_OK;
|
return SOCK_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t wiz_sock_disconnect(uint8_t sn) {
|
int8_t wiz_sock_disconnect(uint8_t sn)
|
||||||
|
{
|
||||||
CHECK_SOCKNUM();
|
CHECK_SOCKNUM();
|
||||||
CHECK_SOCKMODE(Sn_MR_TCP);
|
CHECK_SOCKMODE(Sn_MR_TCP);
|
||||||
setSn_CR(sn, Sn_CR_DISCON);
|
setSn_CR(sn, Sn_CR_DISCON);
|
||||||
|
@ -315,7 +331,8 @@ int8_t wiz_sock_disconnect(uint8_t sn) {
|
||||||
while (getSn_CR(sn))
|
while (getSn_CR(sn))
|
||||||
;
|
;
|
||||||
sock_is_sending &= ~(1 << sn);
|
sock_is_sending &= ~(1 << sn);
|
||||||
if (sock_io_mode & (1 << sn)) return SOCK_BUSY;
|
if (sock_io_mode & (1 << sn))
|
||||||
|
return SOCK_BUSY;
|
||||||
while (getSn_SR(sn) != SOCK_CLOSED) {
|
while (getSn_SR(sn) != SOCK_CLOSED) {
|
||||||
if (getSn_IR(sn) & Sn_IR_TIMEOUT) {
|
if (getSn_IR(sn) & Sn_IR_TIMEOUT) {
|
||||||
wiz_sock_close(sn);
|
wiz_sock_close(sn);
|
||||||
|
@ -325,7 +342,8 @@ int8_t wiz_sock_disconnect(uint8_t sn) {
|
||||||
return SOCK_OK;
|
return SOCK_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t wiz_sock_send(uint8_t sn, uint8_t *buf, uint16_t len) {
|
int32_t wiz_sock_send(uint8_t sn, uint8_t* buf, uint16_t len)
|
||||||
|
{
|
||||||
uint8_t tmp = 0;
|
uint8_t tmp = 0;
|
||||||
uint16_t freesize = 0;
|
uint16_t freesize = 0;
|
||||||
|
|
||||||
|
@ -340,7 +358,7 @@ int32_t wiz_sock_send(uint8_t sn, uint8_t *buf, uint16_t len) {
|
||||||
if (tmp & Sn_IR_SENDOK) {
|
if (tmp & Sn_IR_SENDOK) {
|
||||||
setSn_IR(sn, Sn_IR_SENDOK);
|
setSn_IR(sn, Sn_IR_SENDOK);
|
||||||
// M20150401 : Typing Error
|
// M20150401 : Typing Error
|
||||||
//#if _WZICHIP_ == 5200
|
// #if _WZICHIP_ == 5200
|
||||||
#if _WIZCHIP_ == 5200
|
#if _WIZCHIP_ == 5200
|
||||||
if (getSn_TX_RD(sn) != sock_next_rd[sn]) {
|
if (getSn_TX_RD(sn) != sock_next_rd[sn]) {
|
||||||
setSn_CR(sn, Sn_CR_SEND);
|
setSn_CR(sn, Sn_CR_SEND);
|
||||||
|
@ -357,7 +375,9 @@ int32_t wiz_sock_send(uint8_t sn, uint8_t *buf, uint16_t len) {
|
||||||
return SOCK_BUSY;
|
return SOCK_BUSY;
|
||||||
}
|
}
|
||||||
freesize = getSn_TxMAX(sn);
|
freesize = getSn_TxMAX(sn);
|
||||||
if (len > freesize) len = freesize; // check size not to exceed MAX size.
|
if (len > freesize)
|
||||||
|
len = freesize; // check size not to exceed MAX size.
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
freesize = getSn_TX_FSR(sn);
|
freesize = getSn_TX_FSR(sn);
|
||||||
tmp = getSn_SR(sn);
|
tmp = getSn_SR(sn);
|
||||||
|
@ -365,8 +385,10 @@ int32_t wiz_sock_send(uint8_t sn, uint8_t *buf, uint16_t len) {
|
||||||
wiz_sock_close(sn);
|
wiz_sock_close(sn);
|
||||||
return SOCKERR_SOCKSTATUS;
|
return SOCKERR_SOCKSTATUS;
|
||||||
}
|
}
|
||||||
if ((sock_io_mode & (1 << sn)) && (len > freesize)) return SOCK_BUSY;
|
if ((sock_io_mode & (1 << sn)) && (len > freesize))
|
||||||
if (len <= freesize) break;
|
return SOCK_BUSY;
|
||||||
|
if (len <= freesize)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
wiz_send_data(sn, buf, len);
|
wiz_send_data(sn, buf, len);
|
||||||
#if _WIZCHIP_ == 5200
|
#if _WIZCHIP_ == 5200
|
||||||
|
@ -387,7 +409,8 @@ int32_t wiz_sock_send(uint8_t sn, uint8_t *buf, uint16_t len) {
|
||||||
return (int32_t)len;
|
return (int32_t)len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t wiz_sock_recv(uint8_t sn, uint8_t *buf, uint16_t len) {
|
int32_t wiz_sock_recv(uint8_t sn, uint8_t* buf, uint16_t len)
|
||||||
|
{
|
||||||
uint8_t tmp = 0;
|
uint8_t tmp = 0;
|
||||||
uint16_t recvsize = 0;
|
uint16_t recvsize = 0;
|
||||||
// A20150601 : For integarating with W5300
|
// A20150601 : For integarating with W5300
|
||||||
|
@ -401,7 +424,8 @@ int32_t wiz_sock_recv(uint8_t sn, uint8_t *buf, uint16_t len) {
|
||||||
CHECK_SOCKDATA();
|
CHECK_SOCKDATA();
|
||||||
|
|
||||||
recvsize = getSn_RxMAX(sn);
|
recvsize = getSn_RxMAX(sn);
|
||||||
if (recvsize < len) len = recvsize;
|
if (recvsize < len)
|
||||||
|
len = recvsize;
|
||||||
|
|
||||||
// A20150601 : For Integrating with W5300
|
// A20150601 : For Integrating with W5300
|
||||||
#if _WIZCHIP_ == 5300
|
#if _WIZCHIP_ == 5300
|
||||||
|
@ -425,8 +449,10 @@ int32_t wiz_sock_recv(uint8_t sn, uint8_t *buf, uint16_t len) {
|
||||||
return SOCKERR_SOCKSTATUS;
|
return SOCKERR_SOCKSTATUS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((sock_io_mode & (1 << sn)) && (recvsize == 0)) return SOCK_BUSY;
|
if ((sock_io_mode & (1 << sn)) && (recvsize == 0))
|
||||||
if (recvsize != 0) break;
|
return SOCK_BUSY;
|
||||||
|
if (recvsize != 0)
|
||||||
|
break;
|
||||||
};
|
};
|
||||||
#if _WIZCHIP_ == 5300
|
#if _WIZCHIP_ == 5300
|
||||||
}
|
}
|
||||||
|
@ -446,7 +472,8 @@ int32_t wiz_sock_recv(uint8_t sn, uint8_t *buf, uint16_t len) {
|
||||||
}
|
}
|
||||||
sock_remained_size[sn] = recvsize;
|
sock_remained_size[sn] = recvsize;
|
||||||
}
|
}
|
||||||
if (len > sock_remained_size[sn]) len = sock_remained_size[sn];
|
if (len > sock_remained_size[sn])
|
||||||
|
len = sock_remained_size[sn];
|
||||||
recvsize = len;
|
recvsize = len;
|
||||||
if (sock_pack_info[sn] & PACK_FIFOBYTE) {
|
if (sock_pack_info[sn] & PACK_FIFOBYTE) {
|
||||||
*buf = sock_remained_byte[sn];
|
*buf = sock_remained_byte[sn];
|
||||||
|
@ -464,13 +491,16 @@ int32_t wiz_sock_recv(uint8_t sn, uint8_t *buf, uint16_t len) {
|
||||||
sock_remained_size[sn] -= recvsize;
|
sock_remained_size[sn] -= recvsize;
|
||||||
if (sock_remained_size[sn] != 0) {
|
if (sock_remained_size[sn] != 0) {
|
||||||
sock_pack_info[sn] |= PACK_REMAINED;
|
sock_pack_info[sn] |= PACK_REMAINED;
|
||||||
if (recvsize & 0x1) sock_pack_info[sn] |= PACK_FIFOBYTE;
|
if (recvsize & 0x1)
|
||||||
|
sock_pack_info[sn] |= PACK_FIFOBYTE;
|
||||||
} else
|
} else
|
||||||
sock_pack_info[sn] = PACK_COMPLETED;
|
sock_pack_info[sn] = PACK_COMPLETED;
|
||||||
if (getSn_MR(sn) & Sn_MR_ALIGN) sock_remained_size[sn] = 0;
|
if (getSn_MR(sn) & Sn_MR_ALIGN)
|
||||||
|
sock_remained_size[sn] = 0;
|
||||||
// len = recvsize;
|
// len = recvsize;
|
||||||
#else
|
#else
|
||||||
if (recvsize < len) len = recvsize;
|
if (recvsize < len)
|
||||||
|
len = recvsize;
|
||||||
wiz_recv_data(sn, buf, len);
|
wiz_recv_data(sn, buf, len);
|
||||||
setSn_CR(sn, Sn_CR_RECV);
|
setSn_CR(sn, Sn_CR_RECV);
|
||||||
while (getSn_CR(sn))
|
while (getSn_CR(sn))
|
||||||
|
@ -482,8 +512,11 @@ int32_t wiz_sock_recv(uint8_t sn, uint8_t *buf, uint16_t len) {
|
||||||
return (int32_t)len;
|
return (int32_t)len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t wiz_sock_sendto(uint8_t sn, uint8_t *buf, uint16_t len, uint8_t *addr,
|
#include <xizi.h>
|
||||||
uint16_t port) {
|
#include <xs_kdbg.h>
|
||||||
|
int32_t wiz_sock_sendto(uint8_t sn, uint8_t* buf, uint16_t len, uint8_t* addr,
|
||||||
|
uint16_t port)
|
||||||
|
{
|
||||||
uint8_t tmp = 0;
|
uint8_t tmp = 0;
|
||||||
uint16_t freesize = 0;
|
uint16_t freesize = 0;
|
||||||
uint32_t taddr;
|
uint32_t taddr;
|
||||||
|
@ -517,30 +550,34 @@ int32_t wiz_sock_sendto(uint8_t sn, uint8_t *buf, uint16_t len, uint8_t *addr,
|
||||||
if ((port == 0) && ((getSn_MR(sn) & Sn_MR_MACRAW) != Sn_MR_MACRAW))
|
if ((port == 0) && ((getSn_MR(sn) & Sn_MR_MACRAW) != Sn_MR_MACRAW))
|
||||||
return SOCKERR_PORTZERO;
|
return SOCKERR_PORTZERO;
|
||||||
tmp = getSn_SR(sn);
|
tmp = getSn_SR(sn);
|
||||||
//#if ( _WIZCHIP_ < 5200 )
|
// #if ( _WIZCHIP_ < 5200 )
|
||||||
if ((tmp != SOCK_MACRAW) && (tmp != SOCK_UDP) && (tmp != SOCK_IPRAW))
|
if ((tmp != SOCK_MACRAW) && (tmp != SOCK_UDP) && (tmp != SOCK_IPRAW))
|
||||||
return SOCKERR_SOCKSTATUS;
|
return SOCKERR_SOCKSTATUS;
|
||||||
//#else
|
// #else
|
||||||
// if(tmp != SOCK_MACRAW && tmp != SOCK_UDP) return SOCKERR_SOCKSTATUS;
|
// if(tmp != SOCK_MACRAW && tmp != SOCK_UDP) return SOCKERR_SOCKSTATUS;
|
||||||
//#endif
|
// #endif
|
||||||
|
|
||||||
setSn_DIPR(sn, addr);
|
setSn_DIPR(sn, addr);
|
||||||
setSn_DPORT(sn, port);
|
setSn_DPORT(sn, port);
|
||||||
freesize = getSn_TxMAX(sn);
|
freesize = getSn_TxMAX(sn);
|
||||||
if (len > freesize) len = freesize; // check size not to exceed MAX size.
|
if (len > freesize)
|
||||||
|
len = freesize; // check size not to exceed MAX size.
|
||||||
while (1) {
|
while (1) {
|
||||||
freesize = getSn_TX_FSR(sn);
|
freesize = getSn_TX_FSR(sn);
|
||||||
if (getSn_SR(sn) == SOCK_CLOSED) return SOCKERR_SOCKCLOSED;
|
if (getSn_SR(sn) == SOCK_CLOSED)
|
||||||
if ((sock_io_mode & (1 << sn)) && (len > freesize)) return SOCK_BUSY;
|
return SOCKERR_SOCKCLOSED;
|
||||||
if (len <= freesize) break;
|
if ((sock_io_mode & (1 << sn)) && (len > freesize))
|
||||||
|
return SOCK_BUSY;
|
||||||
|
if (len <= freesize)
|
||||||
|
break;
|
||||||
};
|
};
|
||||||
wiz_send_data(sn, buf, len);
|
wiz_send_data(sn, buf, len);
|
||||||
|
|
||||||
#if _WIZCHIP_ < 5500 // M20150401 : for WIZCHIP Errata #4, #5 (ARP errata)
|
#if _WIZCHIP_ < 5500 // M20150401 : for WIZCHIP Errata #4, #5 (ARP errata)
|
||||||
getSIPR((uint8_t *)&taddr);
|
getSIPR((uint8_t*)&taddr);
|
||||||
if (taddr == 0) {
|
if (taddr == 0) {
|
||||||
getSUBR((uint8_t *)&taddr);
|
getSUBR((uint8_t*)&taddr);
|
||||||
setSUBR((uint8_t *)"\x00\x00\x00\x00");
|
setSUBR((uint8_t*)"\x00\x00\x00\x00");
|
||||||
} else
|
} else
|
||||||
taddr = 0;
|
taddr = 0;
|
||||||
#endif
|
#endif
|
||||||
|
@ -556,6 +593,7 @@ int32_t wiz_sock_sendto(uint8_t sn, uint8_t *buf, uint16_t len, uint8_t *addr,
|
||||||
;
|
;
|
||||||
while (1) {
|
while (1) {
|
||||||
tmp = getSn_IR(sn);
|
tmp = getSn_IR(sn);
|
||||||
|
// SYS_KDEBUG_LOG(WIZNET_DEBUG, ("[%s] %d, tmp: %x\n", __func__, __LINE__, tmp));
|
||||||
if (tmp & Sn_IR_SENDOK) {
|
if (tmp & Sn_IR_SENDOK) {
|
||||||
setSn_IR(sn, Sn_IR_SENDOK);
|
setSn_IR(sn, Sn_IR_SENDOK);
|
||||||
break;
|
break;
|
||||||
|
@ -568,22 +606,25 @@ int32_t wiz_sock_sendto(uint8_t sn, uint8_t *buf, uint16_t len, uint8_t *addr,
|
||||||
// len = (uint16_t)SOCKERR_TIMEOUT;
|
// len = (uint16_t)SOCKERR_TIMEOUT;
|
||||||
// break;
|
// break;
|
||||||
#if _WIZCHIP_ < 5500 // M20150401 : for WIZCHIP Errata #4, #5 (ARP errata)
|
#if _WIZCHIP_ < 5500 // M20150401 : for WIZCHIP Errata #4, #5 (ARP errata)
|
||||||
if (taddr) setSUBR((uint8_t *)&taddr);
|
if (taddr)
|
||||||
|
setSUBR((uint8_t*)&taddr);
|
||||||
#endif
|
#endif
|
||||||
return SOCKERR_TIMEOUT;
|
return SOCKERR_TIMEOUT;
|
||||||
}
|
}
|
||||||
////////////
|
////////////
|
||||||
}
|
}
|
||||||
#if _WIZCHIP_ < 5500 // M20150401 : for WIZCHIP Errata #4, #5 (ARP errata)
|
#if _WIZCHIP_ < 5500 // M20150401 : for WIZCHIP Errata #4, #5 (ARP errata)
|
||||||
if (taddr) setSUBR((uint8_t *)&taddr);
|
if (taddr)
|
||||||
|
setSUBR((uint8_t*)&taddr);
|
||||||
#endif
|
#endif
|
||||||
// M20150409 : Explicit Type Casting
|
// M20150409 : Explicit Type Casting
|
||||||
// return len;
|
// return len;
|
||||||
return (int32_t)len;
|
return (int32_t)len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t wiz_sock_recvfrom(uint8_t sn, uint8_t *buf, uint16_t len, uint8_t *addr,
|
int32_t wiz_sock_recvfrom(uint8_t sn, uint8_t* buf, uint16_t len, uint8_t* addr,
|
||||||
uint16_t *port) {
|
uint16_t* port)
|
||||||
|
{
|
||||||
// M20150601 : For W5300
|
// M20150601 : For W5300
|
||||||
#if _WIZCHIP_ == 5300
|
#if _WIZCHIP_ == 5300
|
||||||
uint16_t mr;
|
uint16_t mr;
|
||||||
|
@ -618,9 +659,12 @@ int32_t wiz_sock_recvfrom(uint8_t sn, uint8_t *buf, uint16_t len, uint8_t *addr,
|
||||||
if (sock_remained_size[sn] == 0) {
|
if (sock_remained_size[sn] == 0) {
|
||||||
while (1) {
|
while (1) {
|
||||||
pack_len = getSn_RX_RSR(sn);
|
pack_len = getSn_RX_RSR(sn);
|
||||||
if (getSn_SR(sn) == SOCK_CLOSED) return SOCKERR_SOCKCLOSED;
|
if (getSn_SR(sn) == SOCK_CLOSED)
|
||||||
if ((sock_io_mode & (1 << sn)) && (pack_len == 0)) return SOCK_BUSY;
|
return SOCKERR_SOCKCLOSED;
|
||||||
if (pack_len != 0) break;
|
if ((sock_io_mode & (1 << sn)) && (pack_len == 0))
|
||||||
|
return SOCK_BUSY;
|
||||||
|
if (pack_len != 0)
|
||||||
|
break;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// D20150601 : Move it to bottom
|
// D20150601 : Move it to bottom
|
||||||
|
@ -705,7 +749,7 @@ int32_t wiz_sock_recvfrom(uint8_t sn, uint8_t *buf, uint16_t len, uint8_t *addr,
|
||||||
pack_len = sock_remained_size[sn];
|
pack_len = sock_remained_size[sn];
|
||||||
wiz_recv_data(sn, buf, pack_len);
|
wiz_recv_data(sn, buf, pack_len);
|
||||||
break;
|
break;
|
||||||
//#if ( _WIZCHIP_ < 5200 )
|
// #if ( _WIZCHIP_ < 5200 )
|
||||||
case Sn_MR_IPRAW:
|
case Sn_MR_IPRAW:
|
||||||
if (sock_remained_size[sn] == 0) {
|
if (sock_remained_size[sn] == 0) {
|
||||||
wiz_recv_data(sn, head, 6);
|
wiz_recv_data(sn, head, 6);
|
||||||
|
@ -731,7 +775,7 @@ int32_t wiz_sock_recvfrom(uint8_t sn, uint8_t *buf, uint16_t len, uint8_t *addr,
|
||||||
pack_len = sock_remained_size[sn];
|
pack_len = sock_remained_size[sn];
|
||||||
wiz_recv_data(sn, buf, pack_len); // data copy.
|
wiz_recv_data(sn, buf, pack_len); // data copy.
|
||||||
break;
|
break;
|
||||||
//#endif
|
// #endif
|
||||||
default:
|
default:
|
||||||
wiz_recv_ignore(sn, pack_len); // data copy.
|
wiz_recv_ignore(sn, pack_len); // data copy.
|
||||||
sock_remained_size[sn] = pack_len;
|
sock_remained_size[sn] = pack_len;
|
||||||
|
@ -747,7 +791,8 @@ int32_t wiz_sock_recvfrom(uint8_t sn, uint8_t *buf, uint16_t len, uint8_t *addr,
|
||||||
if (sock_remained_size[sn] != 0) {
|
if (sock_remained_size[sn] != 0) {
|
||||||
sock_pack_info[sn] |= PACK_REMAINED;
|
sock_pack_info[sn] |= PACK_REMAINED;
|
||||||
#if _WIZCHIP_ == 5300
|
#if _WIZCHIP_ == 5300
|
||||||
if (pack_len & 0x01) sock_pack_info[sn] |= PACK_FIFOBYTE;
|
if (pack_len & 0x01)
|
||||||
|
sock_pack_info[sn] |= PACK_FIFOBYTE;
|
||||||
#endif
|
#endif
|
||||||
} else
|
} else
|
||||||
sock_pack_info[sn] = PACK_COMPLETED;
|
sock_pack_info[sn] = PACK_COMPLETED;
|
||||||
|
@ -760,12 +805,13 @@ int32_t wiz_sock_recvfrom(uint8_t sn, uint8_t *buf, uint16_t len, uint8_t *addr,
|
||||||
return (int32_t)pack_len;
|
return (int32_t)pack_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t wiz_ctlsocket(uint8_t sn, ctlsock_type cstype, void *arg) {
|
int8_t wiz_ctlsocket(uint8_t sn, ctlsock_type cstype, void* arg)
|
||||||
|
{
|
||||||
uint8_t tmp = 0;
|
uint8_t tmp = 0;
|
||||||
CHECK_SOCKNUM();
|
CHECK_SOCKNUM();
|
||||||
switch (cstype) {
|
switch (cstype) {
|
||||||
case CS_SET_IOMODE:
|
case CS_SET_IOMODE:
|
||||||
tmp = *((uint8_t *)arg);
|
tmp = *((uint8_t*)arg);
|
||||||
if (tmp == SOCK_IO_NONBLOCK)
|
if (tmp == SOCK_IO_NONBLOCK)
|
||||||
sock_io_mode |= (1 << sn);
|
sock_io_mode |= (1 << sn);
|
||||||
else if (tmp == SOCK_IO_BLOCK)
|
else if (tmp == SOCK_IO_BLOCK)
|
||||||
|
@ -776,29 +822,31 @@ int8_t wiz_ctlsocket(uint8_t sn, ctlsock_type cstype, void *arg) {
|
||||||
case CS_GET_IOMODE:
|
case CS_GET_IOMODE:
|
||||||
// M20140501 : implict type casting -> explict type casting
|
// M20140501 : implict type casting -> explict type casting
|
||||||
//*((uint8_t*)arg) = (sock_io_mode >> sn) & 0x0001;
|
//*((uint8_t*)arg) = (sock_io_mode >> sn) & 0x0001;
|
||||||
*((uint8_t *)arg) = (uint8_t)((sock_io_mode >> sn) & 0x0001);
|
*((uint8_t*)arg) = (uint8_t)((sock_io_mode >> sn) & 0x0001);
|
||||||
//
|
//
|
||||||
break;
|
break;
|
||||||
case CS_GET_MAXTXBUF:
|
case CS_GET_MAXTXBUF:
|
||||||
*((uint16_t *)arg) = getSn_TxMAX(sn);
|
*((uint16_t*)arg) = getSn_TxMAX(sn);
|
||||||
break;
|
break;
|
||||||
case CS_GET_MAXRXBUF:
|
case CS_GET_MAXRXBUF:
|
||||||
*((uint16_t *)arg) = getSn_RxMAX(sn);
|
*((uint16_t*)arg) = getSn_RxMAX(sn);
|
||||||
break;
|
break;
|
||||||
case CS_CLR_INTERRUPT:
|
case CS_CLR_INTERRUPT:
|
||||||
if ((*(uint8_t *)arg) > SIK_ALL) return SOCKERR_ARG;
|
if ((*(uint8_t*)arg) > SIK_ALL)
|
||||||
setSn_IR(sn, *(uint8_t *)arg);
|
return SOCKERR_ARG;
|
||||||
|
setSn_IR(sn, *(uint8_t*)arg);
|
||||||
break;
|
break;
|
||||||
case CS_GET_INTERRUPT:
|
case CS_GET_INTERRUPT:
|
||||||
*((uint8_t *)arg) = getSn_IR(sn);
|
*((uint8_t*)arg) = getSn_IR(sn);
|
||||||
break;
|
break;
|
||||||
#if _WIZCHIP_ != 5100
|
#if _WIZCHIP_ != 5100
|
||||||
case CS_SET_INTMASK:
|
case CS_SET_INTMASK:
|
||||||
if ((*(uint8_t *)arg) > SIK_ALL) return SOCKERR_ARG;
|
if ((*(uint8_t*)arg) > SIK_ALL)
|
||||||
setSn_IMR(sn, *(uint8_t *)arg);
|
return SOCKERR_ARG;
|
||||||
|
setSn_IMR(sn, *(uint8_t*)arg);
|
||||||
break;
|
break;
|
||||||
case CS_GET_INTMASK:
|
case CS_GET_INTMASK:
|
||||||
*((uint8_t *)arg) = getSn_IMR(sn);
|
*((uint8_t*)arg) = getSn_IMR(sn);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
|
@ -807,31 +855,33 @@ int8_t wiz_ctlsocket(uint8_t sn, ctlsock_type cstype, void *arg) {
|
||||||
return SOCK_OK;
|
return SOCK_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t wiz_setsockopt(uint8_t sn, sockopt_type sotype, void *arg) {
|
int8_t wiz_setsockopt(uint8_t sn, sockopt_type sotype, void* arg)
|
||||||
|
{
|
||||||
// M20131220 : Remove warning
|
// M20131220 : Remove warning
|
||||||
// uint8_t tmp;
|
// uint8_t tmp;
|
||||||
CHECK_SOCKNUM();
|
CHECK_SOCKNUM();
|
||||||
switch (sotype) {
|
switch (sotype) {
|
||||||
case SO_TTL:
|
case SO_TTL:
|
||||||
setSn_TTL(sn, *(uint8_t *)arg);
|
setSn_TTL(sn, *(uint8_t*)arg);
|
||||||
break;
|
break;
|
||||||
case SO_TOS:
|
case SO_TOS:
|
||||||
setSn_TOS(sn, *(uint8_t *)arg);
|
setSn_TOS(sn, *(uint8_t*)arg);
|
||||||
break;
|
break;
|
||||||
case SO_MSS:
|
case SO_MSS:
|
||||||
setSn_MSSR(sn, *(uint16_t *)arg);
|
setSn_MSSR(sn, *(uint16_t*)arg);
|
||||||
break;
|
break;
|
||||||
case SO_DESTIP:
|
case SO_DESTIP:
|
||||||
setSn_DIPR(sn, (uint8_t *)arg);
|
setSn_DIPR(sn, (uint8_t*)arg);
|
||||||
break;
|
break;
|
||||||
case SO_DESTPORT:
|
case SO_DESTPORT:
|
||||||
setSn_DPORT(sn, *(uint16_t *)arg);
|
setSn_DPORT(sn, *(uint16_t*)arg);
|
||||||
break;
|
break;
|
||||||
#if _WIZCHIP_ != 5100
|
#if _WIZCHIP_ != 5100
|
||||||
case SO_KEEPALIVESEND:
|
case SO_KEEPALIVESEND:
|
||||||
CHECK_SOCKMODE(Sn_MR_TCP);
|
CHECK_SOCKMODE(Sn_MR_TCP);
|
||||||
#if _WIZCHIP_ > 5200
|
#if _WIZCHIP_ > 5200
|
||||||
if (getSn_KPALVTR(sn) != 0) return SOCKERR_SOCKOPT;
|
if (getSn_KPALVTR(sn) != 0)
|
||||||
|
return SOCKERR_SOCKOPT;
|
||||||
#endif
|
#endif
|
||||||
setSn_CR(sn, Sn_CR_SEND_KEEP);
|
setSn_CR(sn, Sn_CR_SEND_KEEP);
|
||||||
while (getSn_CR(sn) != 0) {
|
while (getSn_CR(sn) != 0) {
|
||||||
|
@ -846,7 +896,7 @@ int8_t wiz_setsockopt(uint8_t sn, sockopt_type sotype, void *arg) {
|
||||||
#if !((_WIZCHIP_ == 5100) || (_WIZCHIP_ == 5200))
|
#if !((_WIZCHIP_ == 5100) || (_WIZCHIP_ == 5200))
|
||||||
case SO_KEEPALIVEAUTO:
|
case SO_KEEPALIVEAUTO:
|
||||||
CHECK_SOCKMODE(Sn_MR_TCP);
|
CHECK_SOCKMODE(Sn_MR_TCP);
|
||||||
setSn_KPALVTR(sn, *(uint8_t *)arg);
|
setSn_KPALVTR(sn, *(uint8_t*)arg);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -856,54 +906,56 @@ int8_t wiz_setsockopt(uint8_t sn, sockopt_type sotype, void *arg) {
|
||||||
return SOCK_OK;
|
return SOCK_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t wiz_getsockopt(uint8_t sn, sockopt_type sotype, void *arg) {
|
int8_t wiz_getsockopt(uint8_t sn, sockopt_type sotype, void* arg)
|
||||||
|
{
|
||||||
CHECK_SOCKNUM();
|
CHECK_SOCKNUM();
|
||||||
switch (sotype) {
|
switch (sotype) {
|
||||||
case SO_FLAG:
|
case SO_FLAG:
|
||||||
*(uint8_t *)arg = getSn_MR(sn) & 0xF0;
|
*(uint8_t*)arg = getSn_MR(sn) & 0xF0;
|
||||||
break;
|
break;
|
||||||
case SO_TTL:
|
case SO_TTL:
|
||||||
*(uint8_t *)arg = getSn_TTL(sn);
|
*(uint8_t*)arg = getSn_TTL(sn);
|
||||||
break;
|
break;
|
||||||
case SO_TOS:
|
case SO_TOS:
|
||||||
*(uint8_t *)arg = getSn_TOS(sn);
|
*(uint8_t*)arg = getSn_TOS(sn);
|
||||||
break;
|
break;
|
||||||
case SO_MSS:
|
case SO_MSS:
|
||||||
*(uint16_t *)arg = getSn_MSSR(sn);
|
*(uint16_t*)arg = getSn_MSSR(sn);
|
||||||
break;
|
break;
|
||||||
case SO_DESTIP:
|
case SO_DESTIP:
|
||||||
getSn_DIPR(sn, (uint8_t *)arg);
|
getSn_DIPR(sn, (uint8_t*)arg);
|
||||||
break;
|
break;
|
||||||
case SO_DESTPORT:
|
case SO_DESTPORT:
|
||||||
*(uint16_t *)arg = getSn_DPORT(sn);
|
*(uint16_t*)arg = getSn_DPORT(sn);
|
||||||
break;
|
break;
|
||||||
#if _WIZCHIP_ > 5200
|
#if _WIZCHIP_ > 5200
|
||||||
case SO_KEEPALIVEAUTO:
|
case SO_KEEPALIVEAUTO:
|
||||||
CHECK_SOCKMODE(Sn_MR_TCP);
|
CHECK_SOCKMODE(Sn_MR_TCP);
|
||||||
*(uint16_t *)arg = getSn_KPALVTR(sn);
|
*(uint16_t*)arg = getSn_KPALVTR(sn);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case SO_SENDBUF:
|
case SO_SENDBUF:
|
||||||
*(uint16_t *)arg = getSn_TX_FSR(sn);
|
*(uint16_t*)arg = getSn_TX_FSR(sn);
|
||||||
break;
|
break;
|
||||||
case SO_RECVBUF:
|
case SO_RECVBUF:
|
||||||
*(uint16_t *)arg = getSn_RX_RSR(sn);
|
*(uint16_t*)arg = getSn_RX_RSR(sn);
|
||||||
break;
|
break;
|
||||||
case SO_STATUS:
|
case SO_STATUS:
|
||||||
*(uint8_t *)arg = getSn_SR(sn);
|
*(uint8_t*)arg = getSn_SR(sn);
|
||||||
break;
|
break;
|
||||||
case SO_REMAINSIZE:
|
case SO_REMAINSIZE:
|
||||||
if (getSn_MR(sn) & Sn_MR_TCP)
|
if (getSn_MR(sn) & Sn_MR_TCP)
|
||||||
*(uint16_t *)arg = getSn_RX_RSR(sn);
|
*(uint16_t*)arg = getSn_RX_RSR(sn);
|
||||||
else
|
else
|
||||||
*(uint16_t *)arg = sock_remained_size[sn];
|
*(uint16_t*)arg = sock_remained_size[sn];
|
||||||
break;
|
break;
|
||||||
case SO_PACKINFO:
|
case SO_PACKINFO:
|
||||||
// CHECK_SOCKMODE(Sn_MR_TCP);
|
// CHECK_SOCKMODE(Sn_MR_TCP);
|
||||||
#if _WIZCHIP_ != 5300
|
#if _WIZCHIP_ != 5300
|
||||||
if ((getSn_MR(sn) == Sn_MR_TCP)) return SOCKERR_SOCKMODE;
|
if ((getSn_MR(sn) == Sn_MR_TCP))
|
||||||
|
return SOCKERR_SOCKMODE;
|
||||||
#endif
|
#endif
|
||||||
*(uint8_t *)arg = sock_pack_info[sn];
|
*(uint8_t*)arg = sock_pack_info[sn];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return SOCKERR_SOCKOPT;
|
return SOCKERR_SOCKOPT;
|
||||||
|
|
|
@ -54,7 +54,7 @@
|
||||||
//! THE POSSIBILITY OF SUCH DAMAGE.
|
//! THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
//
|
//
|
||||||
//*****************************************************************************
|
//*****************************************************************************
|
||||||
//#include <stdio.h>
|
// #include <stdio.h>
|
||||||
#include "w5500.h"
|
#include "w5500.h"
|
||||||
|
|
||||||
#define _W5500_SPI_VDM_OP_ 0x00
|
#define _W5500_SPI_VDM_OP_ 0x00
|
||||||
|
@ -65,8 +65,9 @@
|
||||||
#if (_WIZCHIP_ == 5500)
|
#if (_WIZCHIP_ == 5500)
|
||||||
////////////////////////////////////////////////////
|
////////////////////////////////////////////////////
|
||||||
|
|
||||||
uint8_t WIZCHIP_READ(uint32_t AddrSel) {
|
uint8_t WIZCHIP_READ(uint32_t AddrSel)
|
||||||
uint8_t ret;
|
{
|
||||||
|
uint8_t ret = 0;
|
||||||
uint8_t spi_data[3];
|
uint8_t spi_data[3];
|
||||||
|
|
||||||
WIZCHIP_CRITICAL_ENTER();
|
WIZCHIP_CRITICAL_ENTER();
|
||||||
|
@ -74,8 +75,7 @@ uint8_t WIZCHIP_READ(uint32_t AddrSel) {
|
||||||
|
|
||||||
AddrSel |= (_W5500_SPI_READ_ | _W5500_SPI_VDM_OP_);
|
AddrSel |= (_W5500_SPI_READ_ | _W5500_SPI_VDM_OP_);
|
||||||
|
|
||||||
if (!WIZCHIP.IF.SPI._read_burst ||
|
if (!WIZCHIP.IF.SPI._read_burst || !WIZCHIP.IF.SPI._write_burst) // byte operation
|
||||||
!WIZCHIP.IF.SPI._write_burst) // byte operation
|
|
||||||
{
|
{
|
||||||
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16);
|
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16);
|
||||||
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8);
|
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8);
|
||||||
|
@ -94,7 +94,8 @@ uint8_t WIZCHIP_READ(uint32_t AddrSel) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb) {
|
void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb)
|
||||||
|
{
|
||||||
uint8_t spi_data[4];
|
uint8_t spi_data[4];
|
||||||
|
|
||||||
WIZCHIP_CRITICAL_ENTER();
|
WIZCHIP_CRITICAL_ENTER();
|
||||||
|
@ -123,7 +124,8 @@ void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb) {
|
||||||
WIZCHIP_CRITICAL_EXIT();
|
WIZCHIP_CRITICAL_EXIT();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WIZCHIP_READ_BUF(uint32_t AddrSel, uint8_t *pBuf, uint16_t len) {
|
void WIZCHIP_READ_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len)
|
||||||
|
{
|
||||||
uint8_t spi_data[3];
|
uint8_t spi_data[3];
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
|
|
||||||
|
@ -132,8 +134,7 @@ void WIZCHIP_READ_BUF(uint32_t AddrSel, uint8_t *pBuf, uint16_t len) {
|
||||||
|
|
||||||
AddrSel |= (_W5500_SPI_READ_ | _W5500_SPI_VDM_OP_);
|
AddrSel |= (_W5500_SPI_READ_ | _W5500_SPI_VDM_OP_);
|
||||||
|
|
||||||
if (!WIZCHIP.IF.SPI._read_burst ||
|
if (!WIZCHIP.IF.SPI._read_burst || !WIZCHIP.IF.SPI._write_burst) // byte operation
|
||||||
!WIZCHIP.IF.SPI._write_burst) // byte operation
|
|
||||||
{
|
{
|
||||||
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16);
|
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16);
|
||||||
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8);
|
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8);
|
||||||
|
@ -153,7 +154,8 @@ void WIZCHIP_READ_BUF(uint32_t AddrSel, uint8_t *pBuf, uint16_t len) {
|
||||||
WIZCHIP_CRITICAL_EXIT();
|
WIZCHIP_CRITICAL_EXIT();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t *pBuf, uint16_t len) {
|
void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len)
|
||||||
|
{
|
||||||
uint8_t spi_data[3];
|
uint8_t spi_data[3];
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
|
|
||||||
|
@ -182,7 +184,8 @@ void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t *pBuf, uint16_t len) {
|
||||||
WIZCHIP_CRITICAL_EXIT();
|
WIZCHIP_CRITICAL_EXIT();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t getSn_TX_FSR(uint8_t sn) {
|
uint16_t getSn_TX_FSR(uint8_t sn)
|
||||||
|
{
|
||||||
uint16_t val = 0, val1 = 0;
|
uint16_t val = 0, val1 = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
@ -196,7 +199,8 @@ uint16_t getSn_TX_FSR(uint8_t sn) {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t getSn_RX_RSR(uint8_t sn) {
|
uint16_t getSn_RX_RSR(uint8_t sn)
|
||||||
|
{
|
||||||
uint16_t val = 0, val1 = 0;
|
uint16_t val = 0, val1 = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
@ -210,7 +214,8 @@ uint16_t getSn_RX_RSR(uint8_t sn) {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wiz_send_data(uint8_t sn, uint8_t *wizdata, uint16_t len) {
|
void wiz_send_data(uint8_t sn, uint8_t* wizdata, uint16_t len)
|
||||||
|
{
|
||||||
uint16_t ptr = 0;
|
uint16_t ptr = 0;
|
||||||
uint32_t addrsel = 0;
|
uint32_t addrsel = 0;
|
||||||
|
|
||||||
|
@ -227,7 +232,8 @@ void wiz_send_data(uint8_t sn, uint8_t *wizdata, uint16_t len) {
|
||||||
setSn_TX_WR(sn, ptr);
|
setSn_TX_WR(sn, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wiz_recv_data(uint8_t sn, uint8_t *wizdata, uint16_t len) {
|
void wiz_recv_data(uint8_t sn, uint8_t* wizdata, uint16_t len)
|
||||||
|
{
|
||||||
uint16_t ptr = 0;
|
uint16_t ptr = 0;
|
||||||
uint32_t addrsel = 0;
|
uint32_t addrsel = 0;
|
||||||
|
|
||||||
|
@ -244,7 +250,8 @@ void wiz_recv_data(uint8_t sn, uint8_t *wizdata, uint16_t len) {
|
||||||
setSn_RX_RD(sn, ptr);
|
setSn_RX_RD(sn, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wiz_recv_ignore(uint8_t sn, uint16_t len) {
|
void wiz_recv_ignore(uint8_t sn, uint16_t len)
|
||||||
|
{
|
||||||
uint16_t ptr = 0;
|
uint16_t ptr = 0;
|
||||||
|
|
||||||
ptr = getSn_RX_RD(sn);
|
ptr = getSn_RX_RD(sn);
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
|
|
||||||
#include "netif/etharp.h"
|
#include "netif/etharp.h"
|
||||||
|
#include <sys.h>
|
||||||
|
|
||||||
#include <xs_kdbg.h>
|
#include <xs_kdbg.h>
|
||||||
|
|
||||||
|
@ -33,9 +34,10 @@
|
||||||
*/
|
*/
|
||||||
uint8_t wiz_mac[6] = { 0x00, 0x08, 0xDC, 0x12, 0x34, 0x56 };
|
uint8_t wiz_mac[6] = { 0x00, 0x08, 0xDC, 0x12, 0x34, 0x56 };
|
||||||
|
|
||||||
static uint8_t tx_frame[1542];
|
|
||||||
static const uint32_t ethernet_polynomial_le = 0xedb88320U;
|
static const uint32_t ethernet_polynomial_le = 0xedb88320U;
|
||||||
|
|
||||||
|
static sys_mutex_t wiz_trans_mtx;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ----------------------------------------------------------------------------------------------------
|
* ----------------------------------------------------------------------------------------------------
|
||||||
* Functions
|
* Functions
|
||||||
|
@ -51,165 +53,75 @@ void Time_Update_LwIP(void)
|
||||||
// no need to do
|
// no need to do
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t send_lwip(uint8_t sn, uint8_t* buf, uint16_t len)
|
static inline void spi_if_clr(void)
|
||||||
{
|
{
|
||||||
uint8_t tmp = 0;
|
setSn_IR(0, 0x1F);
|
||||||
uint16_t freesize = 0;
|
setSIR(0);
|
||||||
|
}
|
||||||
|
|
||||||
tmp = getSn_SR(sn);
|
// macraw func
|
||||||
|
uint16_t macraw_send(const uint8_t* buf, uint16_t len)
|
||||||
|
{
|
||||||
|
uint8_t sock_num = 0;
|
||||||
|
uint16_t ret = 0;
|
||||||
|
|
||||||
// freesize = getSn_TxMAX(sn);
|
if (len > getSn_TxMAX(sock_num)) {
|
||||||
// freesize = getSn_TXBUF_SIZE(sn);
|
ret = getSn_TxMAX(sock_num);
|
||||||
freesize = getSn_TX_FSR(sn);
|
} else {
|
||||||
|
ret = len;
|
||||||
|
}
|
||||||
|
|
||||||
SYS_KDEBUG_LOG(WIZNET_DEBUG, ("[%s] sending len: %d, free size: %d\n", __func__, len, freesize));
|
wiz_send_data(sock_num, (uint8_t*)buf, len);
|
||||||
if (len > freesize)
|
|
||||||
len = freesize; // check size not to exceed MAX size.
|
|
||||||
|
|
||||||
wiz_send_data(sn, buf, len);
|
WIZCHIP_WRITE(Sn_CR(sock_num), Sn_CR_SEND);
|
||||||
setSn_CR(sn, Sn_CR_SEND);
|
while (WIZCHIP_READ(Sn_CR(sock_num))) {
|
||||||
while (getSn_CR(sn))
|
}
|
||||||
|
while (WIZCHIP_READ(Sn_IR(sock_num)) & Sn_IR_SENDOK != Sn_IR_SENDOK) {
|
||||||
|
}
|
||||||
|
WIZCHIP_WRITE(Sn_IR(sock_num), Sn_IR_SENDOK);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t macraw_recv(uint8_t* buf, uint16_t len)
|
||||||
|
{
|
||||||
|
uint8_t sock_num = 0;
|
||||||
|
|
||||||
|
uint16_t lowlevel_len = getSn_RX_RSR(sock_num);
|
||||||
|
if (lowlevel_len <= 0 || len <= 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t data_len = 0;
|
||||||
|
uint8_t macraw_head[2];
|
||||||
|
|
||||||
|
uint16_t ptr = getSn_RX_RD(sock_num);
|
||||||
|
uint32_t addrsel = ((uint32_t)ptr << 8) + (WIZCHIP_RXBUF_BLOCK(sock_num) << 3);
|
||||||
|
|
||||||
|
WIZCHIP_READ_BUF(addrsel, macraw_head, 2);
|
||||||
|
ptr += 2;
|
||||||
|
|
||||||
|
data_len = (macraw_head[0] << 8) + macraw_head[1] - 2;
|
||||||
|
if (data_len > 1514) {
|
||||||
|
KPrintf("[%s:%d] Info: data recved oversize: %d\n", __func__, __LINE__, data_len);
|
||||||
|
wiz_recv_ignore(sock_num, data_len);
|
||||||
|
// wiz_sock_close(sock_num);
|
||||||
|
// wiz_socket(sock_num, Sn_MR_MACRAW, 0xC000, 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
addrsel = ((uint32_t)ptr << 8) + (WIZCHIP_RXBUF_BLOCK(sock_num) << 3);
|
||||||
|
WIZCHIP_READ_BUF(addrsel, buf, data_len);
|
||||||
|
ptr += data_len;
|
||||||
|
|
||||||
|
setSn_RX_RD(sock_num, ptr);
|
||||||
|
WIZCHIP_WRITE(Sn_CR(sock_num), Sn_CR_RECV);
|
||||||
|
while (WIZCHIP_READ(Sn_CR(sock_num)))
|
||||||
;
|
;
|
||||||
|
|
||||||
while (1) {
|
return data_len;
|
||||||
uint8_t IRtemp = getSn_IR(sn);
|
|
||||||
if (IRtemp & Sn_IR_SENDOK) {
|
|
||||||
setSn_IR(sn, Sn_IR_SENDOK);
|
|
||||||
// printf("Packet sent ok\n");
|
|
||||||
break;
|
|
||||||
} else if (IRtemp & Sn_IR_TIMEOUT) {
|
|
||||||
setSn_IR(sn, Sn_IR_TIMEOUT);
|
|
||||||
// printf("Socket is closed\n");
|
|
||||||
// There was a timeout
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (int32_t)len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t recv_lwip(uint8_t sn, uint8_t* buf, uint16_t len)
|
|
||||||
{
|
|
||||||
uint8_t head[2];
|
|
||||||
uint16_t pack_len = 0;
|
|
||||||
|
|
||||||
pack_len = getSn_RX_RSR(sn);
|
|
||||||
|
|
||||||
if (pack_len > 0) {
|
|
||||||
wiz_recv_data(sn, head, 2);
|
|
||||||
setSn_CR(sn, Sn_CR_RECV);
|
|
||||||
|
|
||||||
// byte size of data packet (2byte)
|
|
||||||
pack_len = head[0];
|
|
||||||
pack_len = (pack_len << 8) + head[1];
|
|
||||||
pack_len -= 2;
|
|
||||||
|
|
||||||
if (pack_len > len) {
|
|
||||||
// Packet is bigger than buffer - drop the packet
|
|
||||||
// wiz_recv_ignore(sn, pack_len);
|
|
||||||
// setSn_CR(sn, Sn_CR_RECV);
|
|
||||||
// return 0;
|
|
||||||
pack_len = len;
|
|
||||||
}
|
|
||||||
|
|
||||||
wiz_recv_data(sn, buf, pack_len); // data copy
|
|
||||||
setSn_CR(sn, Sn_CR_RECV);
|
|
||||||
SYS_KDEBUG_LOG(WIZNET_DEBUG, ("[%s] recved len: %d, len: %d\n", __func__, pack_len, len));
|
|
||||||
}
|
|
||||||
|
|
||||||
return (int32_t)pack_len;
|
|
||||||
}
|
|
||||||
|
|
||||||
err_t netif_output(struct netif* netif, struct pbuf* p)
|
|
||||||
{
|
|
||||||
uint32_t send_len = 0;
|
|
||||||
uint32_t tot_len = 0;
|
|
||||||
|
|
||||||
memset(tx_frame, 0x00, sizeof(tx_frame));
|
|
||||||
|
|
||||||
SYS_KDEBUG_LOG(WIZNET_DEBUG, ("[%s] pbuf len: %d, totlen: %d\n", __func__, p->len, p->tot_len));
|
|
||||||
for (struct pbuf* q = p; q != NULL; q = q->next) {
|
|
||||||
memcpy(tx_frame + tot_len, q->payload, q->len);
|
|
||||||
|
|
||||||
tot_len += q->len;
|
|
||||||
|
|
||||||
if (q->len == q->tot_len) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tot_len < 60) {
|
|
||||||
// pad
|
|
||||||
tot_len = 60;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t crc = ethernet_frame_crc(tx_frame, tot_len);
|
|
||||||
|
|
||||||
send_len = send_lwip(0, tx_frame, tot_len);
|
|
||||||
|
|
||||||
return ERR_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static uint16_t wiz_sendFrame(uint8_t* buf, uint16_t len)
|
|
||||||
{
|
|
||||||
// Wait for space in the transmit buffer
|
|
||||||
// while (1) {
|
|
||||||
// SYS_KDEBUG_LOG(WIZNET_DEBUG, ("[%s] looping for freesize, sock state: %x\n", __func__, getSn_SR(0)));
|
|
||||||
// uint16_t freesize = getSn_TX_FSR(0);
|
|
||||||
|
|
||||||
// if (len <= freesize) {
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
wiz_send_data(0, buf, len);
|
|
||||||
setSn_CR(0, Sn_CR_SEND);
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
SYS_KDEBUG_LOG(WIZNET_DEBUG, ("[%s] looping for sendok\n", __func__));
|
|
||||||
uint8_t tmp = getSn_IR(0);
|
|
||||||
if (tmp & Sn_IR_SENDOK) {
|
|
||||||
setSn_IR(0, Sn_IR_SENDOK);
|
|
||||||
// Packet sent ok
|
|
||||||
break;
|
|
||||||
} else if (tmp & Sn_IR_TIMEOUT) {
|
|
||||||
setSn_IR(0, Sn_IR_TIMEOUT);
|
|
||||||
// There was a timeout
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return len;
|
|
||||||
}
|
|
||||||
|
|
||||||
// void ethernetif_input(void* netif_arg)
|
|
||||||
// {
|
|
||||||
// struct netif* netif = (struct netif*)netif_arg;
|
|
||||||
// struct pbuf* p;
|
|
||||||
// uint16_t pack_len = 0;
|
|
||||||
// uint8_t* pack = malloc(ETHERNET_MTU);
|
|
||||||
// while (1) {
|
|
||||||
// wiz_getsockopt(SOCKET_MACRAW, SO_RECVBUF, &pack_len);
|
|
||||||
// if (pack_len > 0) {
|
|
||||||
// pack_len = recv_lwip(SOCKET_MACRAW, (uint8_t*)pack, pack_len);
|
|
||||||
// if (pack_len) {
|
|
||||||
// p = pbuf_alloc(PBUF_RAW, pack_len, PBUF_POOL);
|
|
||||||
// pbuf_take(p, pack, pack_len);
|
|
||||||
// free(pack);
|
|
||||||
// pack = malloc(ETHERNET_MTU);
|
|
||||||
// } else {
|
|
||||||
// printf(" No packet received\n");
|
|
||||||
// }
|
|
||||||
// if (pack_len && p != NULL) {
|
|
||||||
// LINK_STATS_INC(link.recv);
|
|
||||||
// if (netif->input(p, netif) != ERR_OK) {
|
|
||||||
// pbuf_free(p);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
void netif_link_callback(struct netif* netif)
|
void netif_link_callback(struct netif* netif)
|
||||||
{
|
{
|
||||||
printf("netif link status changed %s\n", netif_is_link_up(netif) ? "up" : "down");
|
printf("netif link status changed %s\n", netif_is_link_up(netif) ? "up" : "down");
|
||||||
|
@ -220,123 +132,105 @@ void netif_status_callback(struct netif* netif)
|
||||||
printf("netif status changed %s\n", ip4addr_ntoa(netif_ip4_addr(netif)));
|
printf("netif status changed %s\n", ip4addr_ntoa(netif_ip4_addr(netif)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wiz_transmit_pbuf(struct pbuf* p)
|
static int32_t wiz_transmit_pbuf(struct pbuf* p)
|
||||||
{
|
{
|
||||||
|
static uint8_t addr[4] = { 0xFF, 0xFF, 0xFF, 0xFF };
|
||||||
|
int32_t send_ret = 0;
|
||||||
|
|
||||||
SYS_KDEBUG_LOG(WIZNET_DEBUG, ("+++++++"));
|
|
||||||
uint16_t freeSize = getSn_TX_FSR(0);
|
|
||||||
SYS_KDEBUG_LOG(WIZNET_DEBUG, ("[%s] max tx len: %d, current tx len: %d\n", __func__, getSn_TxMAX(0), freeSize));
|
|
||||||
uint16_t length = p->tot_len;
|
|
||||||
|
|
||||||
if (freeSize < length) {
|
|
||||||
/* TODO: Handle insufficent space in buffer */
|
|
||||||
SYS_KDEBUG_LOG(WIZNET_DEBUG, ("[%s] max tx len: %d, current tx len: %d\n", __func__, getSn_TxMAX(0), freeSize));
|
|
||||||
setSn_CR(0, Sn_CR_SEND);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
while (1) {
|
while (1) {
|
||||||
SYS_KDEBUG_LOG(WIZNET_DEBUG, ("[%s] pbuf len: %d, totlen: %d\n", __func__, p->len, p->tot_len));
|
spi_if_clr();
|
||||||
// wiz_send_data(0, p->payload, p->len);
|
if ((send_ret = wiz_sock_sendto(0, (uint8_t*)p->payload, p->len, addr, 0)) <= 0) {
|
||||||
wiz_sendFrame((uint8_t*)p->payload, p->len);
|
SYS_KDEBUG_LOG(WIZNET_DEBUG, ("[%s] data send failed: %d, sock: %x\n", __func__, send_ret, getSn_SR(0)));
|
||||||
if (p->len == p->tot_len)
|
return -ERROR;
|
||||||
|
}
|
||||||
|
if (p->len == p->tot_len) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
p = p->next;
|
p = p->next;
|
||||||
}
|
}
|
||||||
setSn_CR(0, Sn_CR_SEND);
|
|
||||||
|
return EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int wiz_read_receive_pbuf(struct pbuf** buf)
|
static struct pbuf* wiz_read_receive_pbuf(struct pbuf* buf)
|
||||||
{
|
{
|
||||||
// uint8_t header[6];
|
#define RX_FRAME_SIZE 1542
|
||||||
uint16_t length;
|
static uint8_t rx_frame[RX_FRAME_SIZE];
|
||||||
// uint16_t readlen;
|
static uint8_t addr[4] = { 0xFF, 0xFF, 0xFF, 0xFF };
|
||||||
uint16_t framelen;
|
uint16_t port = 0;
|
||||||
// struct pbuf * p;
|
|
||||||
|
|
||||||
if (*buf != NULL)
|
uint16_t lowlevel_len = getSn_RX_RSR(0);
|
||||||
return 1;
|
if (lowlevel_len <= 0) {
|
||||||
|
return NULL;
|
||||||
// uint16_t rxRd = getSn_RX_RD(0);
|
|
||||||
|
|
||||||
length = getSn_RX_RSR(0);
|
|
||||||
if (length < 4) {
|
|
||||||
/* This could be indicative of a crashed (brown-outed?) controller */
|
|
||||||
goto end;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wiz_recv_data(0, (uint8_t*)&framelen, 2);
|
int32_t data_len = wiz_sock_recvfrom(0, rx_frame, RX_FRAME_SIZE, addr, &port);
|
||||||
setSn_CR(0, Sn_CR_RECV);
|
if (data_len > 0 && data_len <= RX_FRAME_SIZE) {
|
||||||
//__bswap16(framelen); //!< didn't work for me
|
buf = pbuf_alloc(PBUF_RAW, data_len, PBUF_POOL);
|
||||||
framelen = (framelen << 8) | (framelen >> 8);
|
memcpy(buf->payload, rx_frame, data_len);
|
||||||
|
} else {
|
||||||
/* workaround for https://savannah.nongnu.org/bugs/index.php?50040 */
|
return NULL;
|
||||||
if (framelen > 32000) {
|
|
||||||
wiz_recv_ignore(0, framelen);
|
|
||||||
setSn_CR(0, Sn_CR_RECV);
|
|
||||||
goto end;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
framelen -= 2;
|
return buf;
|
||||||
|
|
||||||
*buf = pbuf_alloc(PBUF_RAW, (framelen), PBUF_RAM);
|
|
||||||
|
|
||||||
if (*buf == NULL) {
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
wiz_recv_data(0, (*buf)->payload, framelen);
|
|
||||||
setSn_CR(0, Sn_CR_RECV);
|
|
||||||
|
|
||||||
SYS_KDEBUG_LOG(WIZNET_DEBUG, ("[%s] recved data: framelen: %d\n", __func__, framelen));
|
|
||||||
|
|
||||||
end:
|
|
||||||
return (*buf == NULL) ? 2 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void spi_if_clr(void)
|
|
||||||
{
|
|
||||||
setSn_IR(0, 0x1F);
|
|
||||||
setSIR(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ethernetif_input(void* netif_arg)
|
void ethernetif_input(void* netif_arg)
|
||||||
{
|
{
|
||||||
struct netif* netif = (struct netif*)netif_arg;
|
struct netif* netif = (struct netif*)netif_arg;
|
||||||
struct pbuf* p = NULL;
|
struct pbuf* p = NULL;
|
||||||
uint8_t res = 0;
|
|
||||||
uint16_t epktcnt;
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
sys_arch_sem_wait(get_eth_recv_sem(), WAITING_FOREVER);
|
||||||
|
while (1) {
|
||||||
|
sys_mutex_lock(&wiz_trans_mtx);
|
||||||
|
|
||||||
spi_if_clr();
|
spi_if_clr();
|
||||||
p = NULL;
|
p = NULL;
|
||||||
res = wiz_read_receive_pbuf(&p);
|
p = wiz_read_receive_pbuf(p);
|
||||||
|
|
||||||
|
sys_mutex_unlock(&wiz_trans_mtx);
|
||||||
|
|
||||||
if (p != NULL) {
|
if (p != NULL) {
|
||||||
LWIP_DEBUGF(NETIF_DEBUG, ("incoming: %d packages, first read into %x\n", epktcnt, (uintptr_t)(p)));
|
// SYS_KDEBUG_LOG(WIZNET_DEBUG, ("[%s:%d] Info Recved package with size %d\n", __func__, __LINE__, p->len));
|
||||||
if (ERR_OK != netif->input(p, netif)) {
|
if (ERR_OK != netif->input(p, netif)) {
|
||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
p = NULL;
|
|
||||||
} else {
|
|
||||||
p = NULL;
|
|
||||||
}
|
}
|
||||||
|
p = NULL;
|
||||||
} else {
|
} else {
|
||||||
// LWIP_DEBUGF(NETIF_DEBUG, ("didn't receive.\n"));
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static err_t spi_if_linkoutput(struct netif* netif, struct pbuf* p)
|
static err_t spi_if_linkoutput(struct netif* netif, struct pbuf* p)
|
||||||
{
|
{
|
||||||
while (!(getSn_SR(0) & SOCK_MACRAW))
|
sys_mutex_lock(&wiz_trans_mtx);
|
||||||
; /* TODO: Implement wait timeout */
|
|
||||||
|
if (!(getSn_SR(0) & SOCK_MACRAW)) {
|
||||||
|
SYS_KDEBUG_LOG(WIZNET_DEBUG, ("[%s:%d] err socket state %d\n", __func__, __LINE__, p->len));
|
||||||
|
wiz_sock_close(0);
|
||||||
|
setSn_MR(0, Sn_MR_MFEN | Sn_MR_MACRAW | Sn_MR_MIP6B | Sn_MR_MMB);
|
||||||
|
wiz_socket(0, Sn_MR_MACRAW, 0, SOCK_IO_NONBLOCK);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t ret = wiz_transmit_pbuf(p);
|
||||||
|
|
||||||
|
sys_mutex_unlock(&wiz_trans_mtx);
|
||||||
|
|
||||||
|
if (ret != EOK) {
|
||||||
|
return ERR_USE;
|
||||||
|
}
|
||||||
|
|
||||||
SYS_KDEBUG_LOG(WIZNET_DEBUG, ("[%s] data output, len: %d\n", __func__, p->tot_len));
|
|
||||||
wiz_transmit_pbuf(p);
|
|
||||||
LWIP_DEBUGF(NETIF_DEBUG, ("sent %d bytes.\n", p->tot_len));
|
|
||||||
/* TODO: Set up result value */
|
/* TODO: Set up result value */
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
err_t netif_initialize(struct netif* netif)
|
err_t netif_initialize(struct netif* netif)
|
||||||
{
|
{
|
||||||
|
sys_mutex_new(&wiz_trans_mtx);
|
||||||
|
|
||||||
netif->linkoutput = spi_if_linkoutput;
|
netif->linkoutput = spi_if_linkoutput;
|
||||||
// netif->linkoutput = netif_output;
|
// netif->linkoutput = netif_output;
|
||||||
netif->output = etharp_output;
|
netif->output = etharp_output;
|
||||||
|
@ -349,22 +243,3 @@ err_t netif_initialize(struct netif* netif)
|
||||||
netif->name[1] = '0';
|
netif->name[1] = '0';
|
||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t ethernet_frame_crc(const uint8_t* data, int length)
|
|
||||||
{
|
|
||||||
uint32_t crc = 0xffffffff; /* Initial value. */
|
|
||||||
|
|
||||||
while (--length >= 0) {
|
|
||||||
uint8_t current_octet = *data++;
|
|
||||||
|
|
||||||
for (int bit = 8; --bit >= 0; current_octet >>= 1) {
|
|
||||||
if ((crc ^ current_octet) & 1) {
|
|
||||||
crc >>= 1;
|
|
||||||
crc ^= ethernet_polynomial_le;
|
|
||||||
} else
|
|
||||||
crc >>= 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ~crc;
|
|
||||||
}
|
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
|
|
||||||
#define PING_BIND_PORT 3000
|
#define PING_BIND_PORT 3000
|
||||||
|
|
||||||
PINGMSGR PingRequest = {0};
|
PINGMSGR PingRequest = { 0 };
|
||||||
PINGMSGR PingReply = {0};
|
PINGMSGR PingReply = { 0 };
|
||||||
|
|
||||||
static uint16_t ping_RandomID = 0x1234;
|
static uint16_t ping_RandomID = 0x1234;
|
||||||
static uint16_t ping_RandomSeqNum = 0x4321;
|
static uint16_t ping_RandomSeqNum = 0x4321;
|
||||||
|
@ -21,7 +21,7 @@ uint8_t ping_reply_received = 0;
|
||||||
uint8_t ping_req = 0;
|
uint8_t ping_req = 0;
|
||||||
uint8_t ping_rep = 0;
|
uint8_t ping_rep = 0;
|
||||||
uint8_t ping_cnt = 0;
|
uint8_t ping_cnt = 0;
|
||||||
uint8_t ping_rep_buf[150] = {0};
|
uint8_t ping_rep_buf[150] = { 0 };
|
||||||
|
|
||||||
// ping状态机
|
// ping状态机
|
||||||
#define PING_STA_FREE 0
|
#define PING_STA_FREE 0
|
||||||
|
@ -32,20 +32,22 @@ uint8_t ping_rep_buf[150] = {0};
|
||||||
|
|
||||||
uint8_t ping_sta = PING_STA_FREE;
|
uint8_t ping_sta = PING_STA_FREE;
|
||||||
|
|
||||||
//当前ping的设备的序号
|
// 当前ping的设备的序号
|
||||||
uint8_t ping_socket = 0;
|
uint8_t ping_socket = 0;
|
||||||
|
|
||||||
#define bswap_16(A) ((((uint16)(A)&0xff00) >> 8) | (((uint16)(A)&0x00ff) << 8))
|
#define bswap_16(A) ((((uint16)(A) & 0xff00) >> 8) | (((uint16)(A) & 0x00ff) << 8))
|
||||||
|
|
||||||
uint16_t htons(uint16_t n) {
|
uint16_t htons(uint16_t n)
|
||||||
|
{
|
||||||
union {
|
union {
|
||||||
int i;
|
int i;
|
||||||
char c;
|
char c;
|
||||||
} u = {1};
|
} u = { 1 };
|
||||||
return u.c ? bswap_16(n) : n;
|
return u.c ? bswap_16(n) : n;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t checksum(uint8_t *src, uint32_t len) {
|
uint16_t checksum(uint8_t* src, uint32_t len)
|
||||||
|
{
|
||||||
uint16_t sum, tsum, i, j;
|
uint16_t sum, tsum, i, j;
|
||||||
uint32_t lsum;
|
uint32_t lsum;
|
||||||
|
|
||||||
|
@ -76,13 +78,14 @@ uint16_t checksum(uint8_t *src, uint32_t len) {
|
||||||
*@param pCount- ping的次数
|
*@param pCount- ping的次数
|
||||||
*@return ping成功次数
|
*@return ping成功次数
|
||||||
*/
|
*/
|
||||||
uint8_t ping_count(uint8_t sn, uint16_t pCount, uint8_t *addr) {
|
uint8_t ping_count(uint8_t sn, uint16_t pCount, uint8_t* addr)
|
||||||
|
{
|
||||||
uint16_t rlen, cnt, i;
|
uint16_t rlen, cnt, i;
|
||||||
|
|
||||||
ping_reply_received = 0;
|
ping_reply_received = 0;
|
||||||
ping_req = 0;
|
ping_req = 0;
|
||||||
ping_rep = 0;
|
ping_rep = 0;
|
||||||
KPrintf("Ping:%d.%d.%d.%d\r\n", (addr[0]), (addr[1]), (addr[2]), (addr[3]));
|
KPrintf("Ping:%d.%d.%d.%d, socket state: %x\r\n", (addr[0]), (addr[1]), (addr[2]), (addr[3]), getSn_SR(sn));
|
||||||
|
|
||||||
for (i = 0; i < pCount + 1; i++) /*循环ping pCount次*/
|
for (i = 0; i < pCount + 1; i++) /*循环ping pCount次*/
|
||||||
{
|
{
|
||||||
|
@ -93,8 +96,7 @@ uint8_t ping_count(uint8_t sn, uint16_t pCount, uint8_t *addr) {
|
||||||
wiz_sock_close(sn);
|
wiz_sock_close(sn);
|
||||||
/* Create Socket */
|
/* Create Socket */
|
||||||
IINCHIP_WRITE(Sn_PROTO(sn), IPPROTO_ICMP); /*设置ICMP 协议*/
|
IINCHIP_WRITE(Sn_PROTO(sn), IPPROTO_ICMP); /*设置ICMP 协议*/
|
||||||
if (wiz_socket(sn, Sn_MR_IPRAW, PING_BIND_PORT, 0) !=
|
if (wiz_socket(sn, Sn_MR_IPRAW, PING_BIND_PORT, 0) != 0) /*判断ip raw模式socket是否开启*/
|
||||||
0) /*判断ip raw模式socket是否开启*/
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
/* Check socket register */
|
/* Check socket register */
|
||||||
|
@ -142,26 +144,25 @@ uint8_t ping_count(uint8_t sn, uint16_t pCount, uint8_t *addr) {
|
||||||
*@param addr- P地址
|
*@param addr- P地址
|
||||||
*@return 无
|
*@return 无
|
||||||
*/
|
*/
|
||||||
uint8_t ping_request(uint8_t sn, uint8_t *addr) {
|
uint8_t ping_request(uint8_t sn, uint8_t* addr)
|
||||||
uint8_t *buffer;
|
{
|
||||||
|
uint8_t* buffer;
|
||||||
|
|
||||||
uint16_t i, temp_len = 0;
|
uint16_t i, temp_len = 0;
|
||||||
ping_reply_received = 0; /*ping 回复初始化标志位*/
|
ping_reply_received = 0; /*ping 回复初始化标志位*/
|
||||||
PingRequest.Type = PING_REQUEST; /*Ping-Request*/
|
PingRequest.Type = PING_REQUEST; /*Ping-Request*/
|
||||||
PingRequest.Code = CODE_ZERO; /*总是 '0'*/
|
PingRequest.Code = CODE_ZERO; /*总是 '0'*/
|
||||||
PingRequest.ID = htons(ping_RandomID++); /*设置ping响应ID为随机的整型变量*/
|
PingRequest.ID = htons(ping_RandomID++); /*设置ping响应ID为随机的整型变量*/
|
||||||
PingRequest.SeqNum =
|
PingRequest.SeqNum = htons(ping_RandomSeqNum++); /*设置ping响应的序列号为随机整形变量*/
|
||||||
htons(ping_RandomSeqNum++); /*设置ping响应的序列号为随机整形变量*/
|
|
||||||
for (i = 0; i < PING_BUF_LEN; i++) {
|
for (i = 0; i < PING_BUF_LEN; i++) {
|
||||||
PingRequest.Data[i] = (i) % 8; /*ping相应的数在'0'~'8‘*/
|
PingRequest.Data[i] = (i) % 8; /*ping相应的数在'0'~'8‘*/
|
||||||
}
|
}
|
||||||
PingRequest.CheckSum = 0;
|
PingRequest.CheckSum = 0;
|
||||||
/* 计算响应次数*/
|
/* 计算响应次数*/
|
||||||
PingRequest.CheckSum =
|
PingRequest.CheckSum = htons(checksum((uint8_t*)&PingRequest, sizeof(PingRequest)));
|
||||||
htons(checksum((uint8_t *)&PingRequest, sizeof(PingRequest)));
|
|
||||||
|
|
||||||
/*发送ping响应到目的方 */
|
/*发送ping响应到目的方 */
|
||||||
if (wiz_sock_sendto(sn, (uint8_t *)&PingRequest, sizeof(PingRequest), addr,
|
if (wiz_sock_sendto(sn, (uint8_t*)&PingRequest, sizeof(PingRequest), addr, PING_BIND_PORT) == 0) {
|
||||||
PING_BIND_PORT) == 0) {
|
|
||||||
KPrintf("Fail to send ping-reply packet\r\n");
|
KPrintf("Fail to send ping-reply packet\r\n");
|
||||||
} else {
|
} else {
|
||||||
KPrintf("ping send\n");
|
KPrintf("ping send\n");
|
||||||
|
@ -175,7 +176,8 @@ uint8_t ping_request(uint8_t sn, uint8_t *addr) {
|
||||||
*@param addr- Ping地址
|
*@param addr- Ping地址
|
||||||
*@return 无
|
*@return 无
|
||||||
*/
|
*/
|
||||||
uint8_t ping_reply(uint8_t sn, uint8_t *addr, uint16_t rlen) {
|
uint8_t ping_reply(uint8_t sn, uint8_t* addr, uint16_t rlen)
|
||||||
|
{
|
||||||
uint16_t tmp_checksum;
|
uint16_t tmp_checksum;
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
|
@ -233,10 +235,11 @@ uint8_t ping_reply(uint8_t sn, uint8_t *addr, uint16_t rlen) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wiz_ping_test(int argc, char *argv[]) {
|
void wiz_ping_test(int argc, char* argv[])
|
||||||
|
{
|
||||||
uint32_t tmp_ip[4];
|
uint32_t tmp_ip[4];
|
||||||
uint8_t target_ip[4];
|
uint8_t target_ip[4];
|
||||||
uint16_t pCount = 5; //默认ping 5次
|
uint16_t pCount = 5; // 默认ping 5次
|
||||||
|
|
||||||
if (argc >= 2) {
|
if (argc >= 2) {
|
||||||
KPrintf("This is a Ping test: %s\n", argv[1]);
|
KPrintf("This is a Ping test: %s\n", argv[1]);
|
||||||
|
@ -246,11 +249,11 @@ void wiz_ping_test(int argc, char *argv[]) {
|
||||||
target_ip[1] = (uint8_t)tmp_ip[1];
|
target_ip[1] = (uint8_t)tmp_ip[1];
|
||||||
target_ip[2] = (uint8_t)tmp_ip[2];
|
target_ip[2] = (uint8_t)tmp_ip[2];
|
||||||
target_ip[3] = (uint8_t)tmp_ip[3];
|
target_ip[3] = (uint8_t)tmp_ip[3];
|
||||||
if (argc >= 3){
|
if (argc >= 3) {
|
||||||
pCount = atoi(argv[2]); //如果ip后面跟具体的数字,代表ping的次数
|
pCount = atoi(argv[2]); // 如果ip后面跟具体的数字,代表ping的次数
|
||||||
}
|
}
|
||||||
ping_count(ping_socket, pCount, target_ip);
|
ping_count(ping_socket, pCount, target_ip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||||
ping, wiz_ping_test, ping to given addr);
|
wiz_ping, wiz_ping_test, ping to given addr);
|
|
@ -191,7 +191,7 @@ static uint32 SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDataStan
|
||||||
for (i = 0; i < spi_datacfg->length; i++) {
|
for (i = 0; i < spi_datacfg->length; i++) {
|
||||||
tx_buff[i] = ((uint8_t *)spi_datacfg->tx_buff)[i];
|
tx_buff[i] = ((uint8_t *)spi_datacfg->tx_buff)[i];
|
||||||
}
|
}
|
||||||
dmac_set_single_mode(dev_param->spi_dma_param->spi_dmac_txchannel, tx_buff, (void *)(&spi_instance[device_master_id]->dr[0]), DMAC_ADDR_INCREMENT, DMAC_ADDR_NOCHANGE,
|
dmac_set_single_mode(dev_param->spi_dma_param->spi_dmac_txchannel, tx_buff, (void*)(&spi_instance[device_master_id]->dr[0]), DMAC_ADDR_INCREMENT, DMAC_ADDR_NOCHANGE,
|
||||||
DMAC_MSIZE_4, DMAC_TRANS_WIDTH_32, spi_datacfg->length);
|
DMAC_MSIZE_4, DMAC_TRANS_WIDTH_32, spi_datacfg->length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ static uint32 SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDataStan
|
||||||
spi_instance[device_master_id]->ssienr = 0x00;
|
spi_instance[device_master_id]->ssienr = 0x00;
|
||||||
|
|
||||||
transfer_done:
|
transfer_done:
|
||||||
if (tx_buff) {
|
if (tx_buff != NULL) {
|
||||||
x_free(tx_buff);
|
x_free(tx_buff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,9 +231,9 @@ int MountFilesystem(const char *bus_name,
|
||||||
enum FilesystemType fs_type, const char *path)
|
enum FilesystemType fs_type, const char *path)
|
||||||
{
|
{
|
||||||
struct MountPoint *mp = NULL, *itr;
|
struct MountPoint *mp = NULL, *itr;
|
||||||
struct Bus *bus;
|
struct Bus* bus = NULL;
|
||||||
HardwareDevType dev;
|
HardwareDevType dev;
|
||||||
DriverType drv;
|
DriverType drv = NULL;
|
||||||
struct SysDoubleLinklistNode *node;
|
struct SysDoubleLinklistNode *node;
|
||||||
int ret = -EINVAL;
|
int ret = -EINVAL;
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ extern "C" {
|
||||||
#define FILESYS_DEBUG 0
|
#define FILESYS_DEBUG 0
|
||||||
#define NETDEV_DEBUG 0
|
#define NETDEV_DEBUG 0
|
||||||
#define WEBNET_DEBUG 0
|
#define WEBNET_DEBUG 0
|
||||||
#define WIZNET_DEBUG 1
|
#define WIZNET_DEBUG 0
|
||||||
|
|
||||||
#define SYS_KDEBUG_LOG(section, information) \
|
#define SYS_KDEBUG_LOG(section, information) \
|
||||||
do { \
|
do { \
|
||||||
|
|
|
@ -94,7 +94,7 @@ static x_err_t _MsgQueueSend(struct MsgQueue* mq,
|
||||||
NULL_PARAM_CHECK(mq);
|
NULL_PARAM_CHECK(mq);
|
||||||
NULL_PARAM_CHECK(buffer);
|
NULL_PARAM_CHECK(buffer);
|
||||||
|
|
||||||
SYS_KDEBUG_LOG(MSGQUEUE_DEBUG, ("[%s] mq_num_msgs: %d, block size: %d, needed size: %d\n", __func__, mq->num_msgs, mq->each_len, size));
|
SYS_KDEBUG_LOG(MSGQUEUE_DEBUG, ("[%s] mq_num_msgs: %d, block size: %d, needed size: %lu\n", __func__, mq->num_msgs, mq->each_len, size));
|
||||||
|
|
||||||
if (size > mq->each_len)
|
if (size > mq->each_len)
|
||||||
return -ERROR;
|
return -ERROR;
|
||||||
|
|
|
@ -175,9 +175,9 @@ SWITCH:
|
||||||
HOOK(hook.assign.hook_Assign,(runningtask, new_task));
|
HOOK(hook.assign.hook_Assign,(runningtask, new_task));
|
||||||
|
|
||||||
SYS_KDEBUG_LOG(KDBG_SCHED,
|
SYS_KDEBUG_LOG(KDBG_SCHED,
|
||||||
("[%d]switch to priority#%d "
|
("[%d]switch to priority#%ld "
|
||||||
"task:%.*s(sp:0x%08x), "
|
"task:%.*s(sp:0x%8p), "
|
||||||
"from task:%.*s(sp: 0x%08x)\n",
|
"from task:%.*s(sp: 0x%8p)\n",
|
||||||
isrManager.done->getCounter(), highest_prio,
|
isrManager.done->getCounter(), highest_prio,
|
||||||
NAME_NUM_MAX, new_task->task_base_info.name, new_task->stack_point,
|
NAME_NUM_MAX, new_task->task_base_info.name, new_task->stack_point,
|
||||||
NAME_NUM_MAX, runningtask->task_base_info.name, runningtask->stack_point));
|
NAME_NUM_MAX, runningtask->task_base_info.name, runningtask->stack_point));
|
||||||
|
@ -442,9 +442,9 @@ x_err_t YieldOsAssign(void)
|
||||||
HOOK(hook.assign.hook_Assign,(runningtask, new_task));
|
HOOK(hook.assign.hook_Assign,(runningtask, new_task));
|
||||||
|
|
||||||
SYS_KDEBUG_LOG(KDBG_SCHED,
|
SYS_KDEBUG_LOG(KDBG_SCHED,
|
||||||
("[%d]switch to priority#%d "
|
("[%d]switch to priority#%ld "
|
||||||
"task:%.*s(sp:0x%08x), "
|
"task:%.*s(sp:0x%8p), "
|
||||||
"from task:%.*s(sp: 0x%08x)\n",
|
"from task:%.*s(sp: 0x%8p)\n",
|
||||||
isrManager.done->getCounter(), highest_prio,
|
isrManager.done->getCounter(), highest_prio,
|
||||||
NAME_NUM_MAX, new_task->task_base_info.name, new_task->stack_point,
|
NAME_NUM_MAX, new_task->task_base_info.name, new_task->stack_point,
|
||||||
NAME_NUM_MAX, runningtask->task_base_info.name, runningtask->stack_point));
|
NAME_NUM_MAX, runningtask->task_base_info.name, runningtask->stack_point));
|
||||||
|
|
|
@ -37,9 +37,13 @@
|
||||||
#define LWIP_DEBUG 1
|
#define LWIP_DEBUG 1
|
||||||
// #define LWIP_SOCKET_DEBUG
|
// #define LWIP_SOCKET_DEBUG
|
||||||
// #define LWIP_TCPIP_DEBUG
|
// #define LWIP_TCPIP_DEBUG
|
||||||
|
// #define LWIP_MEMP_DEBUG
|
||||||
|
// #define LWIP_PBUF_DEBUG
|
||||||
// #define LWIP_TCP_INPUT_DEBUG
|
// #define LWIP_TCP_INPUT_DEBUG
|
||||||
// #define LWIP_TCP_OUTPUT_DEBUG
|
// #define LWIP_TCP_OUTPUT_DEBUG
|
||||||
// #define LWIP_NETIF_DEBUG
|
// #define LWIP_NETIF_DEBUG
|
||||||
|
// #define LWIP_ETHARP_DEBUG
|
||||||
|
// #define LWIP_API_MSG_DEBUG
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_DEBUG
|
#ifdef LWIP_DEBUG
|
||||||
|
@ -213,7 +217,6 @@
|
||||||
|
|
||||||
#endif /* LWIP_DEBUG */
|
#endif /* LWIP_DEBUG */
|
||||||
|
|
||||||
|
|
||||||
#define LWIP_TIMEVAL_PRIVATE 0
|
#define LWIP_TIMEVAL_PRIVATE 0
|
||||||
#define LWIP_NO_UNISTD_H 0
|
#define LWIP_NO_UNISTD_H 0
|
||||||
#define LWIP_NO_STDDEF_H 0
|
#define LWIP_NO_STDDEF_H 0
|
||||||
|
@ -256,7 +259,11 @@
|
||||||
|
|
||||||
/* MEM_SIZE: the size of the heap memory. If the application will send
|
/* MEM_SIZE: the size of the heap memory. If the application will send
|
||||||
a lot of data that needs to be copied, this should be set high. */
|
a lot of data that needs to be copied, this should be set high. */
|
||||||
#define MEM_SIZE (64*1024)
|
#ifndef RISCV_LWIP
|
||||||
|
#define MEM_SIZE (64 * 1024)
|
||||||
|
#else
|
||||||
|
#define MEM_SIZE (32 * 1024)
|
||||||
|
#endif
|
||||||
|
|
||||||
/* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application
|
/* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application
|
||||||
sends a lot of data out of ROM (or other static memory), this
|
sends a lot of data out of ROM (or other static memory), this
|
||||||
|
@ -277,14 +284,14 @@ a lot of data that needs to be copied, this should be set high. */
|
||||||
/* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active
|
/* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active
|
||||||
timeouts. */
|
timeouts. */
|
||||||
// #define MEMP_NUM_SYS_TIMEOUT 6
|
// #define MEMP_NUM_SYS_TIMEOUT 6
|
||||||
#define MEMP_NUM_SYS_TIMEOUT (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_SUPPORT + (LWIP_IPV6 ? (1 + (2*LWIP_IPV6)) : 0))
|
#define MEMP_NUM_SYS_TIMEOUT (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2 * LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_SUPPORT + (LWIP_IPV6 ? (1 + (2 * LWIP_IPV6)) : 0))
|
||||||
|
|
||||||
/* ---------- Pbuf options ---------- */
|
/* ---------- Pbuf options ---------- */
|
||||||
/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */
|
/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */
|
||||||
#define PBUF_POOL_SIZE 255
|
#define PBUF_POOL_SIZE 255
|
||||||
/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */
|
/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */
|
||||||
// #define PBUF_POOL_BUFSIZE 1024
|
// #define PBUF_POOL_BUFSIZE 1024
|
||||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS + 40 + PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN)
|
||||||
|
|
||||||
/* ---------- ARP options ---------- */
|
/* ---------- ARP options ---------- */
|
||||||
#define LWIP_ARP 1
|
#define LWIP_ARP 1
|
||||||
|
@ -303,18 +310,17 @@ a lot of data that needs to be copied, this should be set high. */
|
||||||
#define TCP_MSS (1500 - 40) /* TCP_MSS = (Ethernet MTU - IP header size - TCP header size) */
|
#define TCP_MSS (1500 - 40) /* TCP_MSS = (Ethernet MTU - IP header size - TCP header size) */
|
||||||
|
|
||||||
/* TCP sender buffer space (bytes). */
|
/* TCP sender buffer space (bytes). */
|
||||||
#define TCP_SND_BUF (11*TCP_MSS)
|
#define TCP_SND_BUF (11 * TCP_MSS)
|
||||||
|
|
||||||
/* TCP_SND_QUEUELEN: TCP sender buffer space (pbufs). This must be at least
|
/* TCP_SND_QUEUELEN: TCP sender buffer space (pbufs). This must be at least
|
||||||
as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. */
|
as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. */
|
||||||
|
|
||||||
#define TCP_SND_QUEUELEN (8* TCP_SND_BUF/TCP_MSS)
|
#define TCP_SND_QUEUELEN (8 * TCP_SND_BUF / TCP_MSS)
|
||||||
|
|
||||||
/* TCP receive window. */
|
/* TCP receive window. */
|
||||||
#define TCP_WND 8192
|
#define TCP_WND 8192
|
||||||
// #define TCP_WND (12 * TCP_MSS)
|
// #define TCP_WND (12 * TCP_MSS)
|
||||||
|
|
||||||
|
|
||||||
/* Maximum number of retransmissions of data segments. */
|
/* Maximum number of retransmissions of data segments. */
|
||||||
#define TCP_MAXRTX 12
|
#define TCP_MAXRTX 12
|
||||||
|
|
||||||
|
@ -377,19 +383,16 @@ a lot of data that needs to be copied, this should be set high. */
|
||||||
/* ---------- ICMP options ---------- */
|
/* ---------- ICMP options ---------- */
|
||||||
#define LWIP_ICMP 1
|
#define LWIP_ICMP 1
|
||||||
|
|
||||||
|
|
||||||
/* ---------- DHCP options ---------- */
|
/* ---------- DHCP options ---------- */
|
||||||
/* Define LWIP_DHCP to 1 if you want DHCP configuration of
|
/* Define LWIP_DHCP to 1 if you want DHCP configuration of
|
||||||
interfaces. DHCP is not implemented in lwIP 0.5.1, however, so
|
interfaces. DHCP is not implemented in lwIP 0.5.1, however, so
|
||||||
turning this on does currently not work. */
|
turning this on does currently not work. */
|
||||||
#define LWIP_DHCP 1
|
#define LWIP_DHCP 1
|
||||||
|
|
||||||
|
|
||||||
/* ---------- UDP options ---------- */
|
/* ---------- UDP options ---------- */
|
||||||
#define LWIP_UDP 1
|
#define LWIP_UDP 1
|
||||||
#define UDP_TTL 255
|
#define UDP_TTL 255
|
||||||
|
|
||||||
|
|
||||||
/* ---------- Statistics options ---------- */
|
/* ---------- Statistics options ---------- */
|
||||||
#define LWIP_PROVIDE_ERRNO 1
|
#define LWIP_PROVIDE_ERRNO 1
|
||||||
|
|
||||||
|
@ -409,41 +412,40 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
|
||||||
- To use this feature let the following define uncommented.
|
- To use this feature let the following define uncommented.
|
||||||
- To disable it and process by CPU comment the the checksum.
|
- To disable it and process by CPU comment the the checksum.
|
||||||
*/
|
*/
|
||||||
#define CHECKSUM_BY_HARDWARE
|
// #define CHECKSUM_BY_HARDWARE
|
||||||
|
|
||||||
#ifdef CHECKSUM_BY_HARDWARE
|
#ifdef CHECKSUM_BY_HARDWARE
|
||||||
/* CHECKSUM_GEN_IP==0: Generate checksums by hardware for outgoing IP packets.*/
|
/* CHECKSUM_GEN_IP==0: Generate checksums by hardware for outgoing IP packets.*/
|
||||||
#define CHECKSUM_GEN_IP 0
|
#define CHECKSUM_GEN_IP 0
|
||||||
/* CHECKSUM_GEN_UDP==0: Generate checksums by hardware for outgoing UDP packets.*/
|
/* CHECKSUM_GEN_UDP==0: Generate checksums by hardware for outgoing UDP packets.*/
|
||||||
#define CHECKSUM_GEN_UDP 0
|
#define CHECKSUM_GEN_UDP 0
|
||||||
/* CHECKSUM_GEN_TCP==0: Generate checksums by hardware for outgoing TCP packets.*/
|
/* CHECKSUM_GEN_TCP==0: Generate checksums by hardware for outgoing TCP packets.*/
|
||||||
#define CHECKSUM_GEN_TCP 0
|
#define CHECKSUM_GEN_TCP 0
|
||||||
/* CHECKSUM_CHECK_IP==0: Check checksums by hardware for incoming IP packets.*/
|
/* CHECKSUM_CHECK_IP==0: Check checksums by hardware for incoming IP packets.*/
|
||||||
#define CHECKSUM_CHECK_IP 0
|
#define CHECKSUM_CHECK_IP 0
|
||||||
/* CHECKSUM_CHECK_UDP==0: Check checksums by hardware for incoming UDP packets.*/
|
/* CHECKSUM_CHECK_UDP==0: Check checksums by hardware for incoming UDP packets.*/
|
||||||
#define CHECKSUM_CHECK_UDP 0
|
#define CHECKSUM_CHECK_UDP 0
|
||||||
/* CHECKSUM_CHECK_TCP==0: Check checksums by hardware for incoming TCP packets.*/
|
/* CHECKSUM_CHECK_TCP==0: Check checksums by hardware for incoming TCP packets.*/
|
||||||
#define CHECKSUM_CHECK_TCP 0
|
#define CHECKSUM_CHECK_TCP 0
|
||||||
/* CHECKSUM_CHECK_ICMP==0: Check checksums by hardware for incoming ICMP packets.*/
|
/* CHECKSUM_CHECK_ICMP==0: Check checksums by hardware for incoming ICMP packets.*/
|
||||||
#define CHECKSUM_GEN_ICMP 0
|
#define CHECKSUM_GEN_ICMP 0
|
||||||
#else
|
#else
|
||||||
/* CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP packets.*/
|
/* CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP packets.*/
|
||||||
#define CHECKSUM_GEN_IP 1
|
#define CHECKSUM_GEN_IP 1
|
||||||
/* CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets.*/
|
/* CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets.*/
|
||||||
#define CHECKSUM_GEN_UDP 1
|
#define CHECKSUM_GEN_UDP 1
|
||||||
/* CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets.*/
|
/* CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets.*/
|
||||||
#define CHECKSUM_GEN_TCP 1
|
#define CHECKSUM_GEN_TCP 1
|
||||||
/* CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets.*/
|
/* CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets.*/
|
||||||
#define CHECKSUM_CHECK_IP 1
|
#define CHECKSUM_CHECK_IP 1
|
||||||
/* CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets.*/
|
/* CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets.*/
|
||||||
#define CHECKSUM_CHECK_UDP 1
|
#define CHECKSUM_CHECK_UDP 1
|
||||||
/* CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets.*/
|
/* CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets.*/
|
||||||
#define CHECKSUM_CHECK_TCP 1
|
#define CHECKSUM_CHECK_TCP 1
|
||||||
/* CHECKSUM_CHECK_ICMP==1: Check checksums by software for incoming ICMP packets.*/
|
/* CHECKSUM_CHECK_ICMP==1: Check checksums by software for incoming ICMP packets.*/
|
||||||
#define CHECKSUM_GEN_ICMP 1
|
#define CHECKSUM_GEN_ICMP 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
----------------------------------------------
|
----------------------------------------------
|
||||||
---------- Sequential layer options ----------
|
---------- Sequential layer options ----------
|
||||||
|
@ -452,11 +454,11 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
|
||||||
/**
|
/**
|
||||||
* LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c)
|
* LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c)
|
||||||
*/
|
*/
|
||||||
#ifndef RISCV_LWIP
|
// #ifndef RISCV_LWIP
|
||||||
|
// #define LWIP_NETCONN 1
|
||||||
|
// #else
|
||||||
#define LWIP_NETCONN 1
|
#define LWIP_NETCONN 1
|
||||||
#else
|
// #endif
|
||||||
#define LWIP_NETCONN 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
------------------------------------
|
------------------------------------
|
||||||
|
@ -473,7 +475,7 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
|
||||||
*/
|
*/
|
||||||
#define LWIP_SO_RCVBUF 1
|
#define LWIP_SO_RCVBUF 1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LWIP_SO_SNDTIMEO==1: Enable send timeout for sockets/netconns and
|
* LWIP_SO_SNDTIMEO==1: Enable send timeout for sockets/netconns and
|
||||||
* SO_SNDTIMEO processing.
|
* SO_SNDTIMEO processing.
|
||||||
*/
|
*/
|
||||||
|
@ -481,7 +483,7 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
|
||||||
#define LWIP_SO_SNDTIMEO 1
|
#define LWIP_SO_SNDTIMEO 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LWIP_SO_RCVTIMEO==1: Enable receive timeout for sockets/netconns and
|
* LWIP_SO_RCVTIMEO==1: Enable receive timeout for sockets/netconns and
|
||||||
* SO_RCVTIMEO processing.
|
* SO_RCVTIMEO processing.
|
||||||
*/
|
*/
|
||||||
|
@ -489,7 +491,7 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
|
||||||
#define LWIP_SO_RCVTIMEO 1
|
#define LWIP_SO_RCVTIMEO 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LWIP_SO_LINGER==1: Enable SO_LINGER processing.
|
* LWIP_SO_LINGER==1: Enable SO_LINGER processing.
|
||||||
*/
|
*/
|
||||||
// #define LWIP_SO_LINGER 1
|
// #define LWIP_SO_LINGER 1
|
||||||
|
@ -528,11 +530,9 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
|
||||||
#define LWIP_AUTOIP 0
|
#define LWIP_AUTOIP 0
|
||||||
#define LWIP_DHCP_AUTOIP_COOP (LWIP_DHCP && LWIP_AUTOIP)
|
#define LWIP_DHCP_AUTOIP_COOP (LWIP_DHCP && LWIP_AUTOIP)
|
||||||
|
|
||||||
|
|
||||||
#define LWIP_UDPLITE 0
|
#define LWIP_UDPLITE 0
|
||||||
#define UDP_TTL 255
|
#define UDP_TTL 255
|
||||||
|
|
||||||
|
|
||||||
/* ---------- Statistics options ---------- */
|
/* ---------- Statistics options ---------- */
|
||||||
#define LWIP_STATS 1
|
#define LWIP_STATS 1
|
||||||
#define LWIP_STATS_DISPLAY 1
|
#define LWIP_STATS_DISPLAY 1
|
||||||
|
@ -546,13 +546,13 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
|
||||||
#define DEFAULT_RAW_RECVMBOX_SIZE 8
|
#define DEFAULT_RAW_RECVMBOX_SIZE 8
|
||||||
#define DEFAULT_UDP_RECVMBOX_SIZE 8
|
#define DEFAULT_UDP_RECVMBOX_SIZE 8
|
||||||
#define DEFAULT_TCP_RECVMBOX_SIZE 8
|
#define DEFAULT_TCP_RECVMBOX_SIZE 8
|
||||||
#define DEFAULT_ACCEPTMBOX_SIZE 10
|
#define DEFAULT_ACCEPTMBOX_SIZE 12
|
||||||
|
|
||||||
#define DEFAULT_THREAD_PRIO 20
|
#define DEFAULT_THREAD_PRIO 20
|
||||||
#define DEFAULT_THREAD_STACKSIZE 2048
|
#define DEFAULT_THREAD_STACKSIZE 2048
|
||||||
|
|
||||||
#define TCPIP_THREAD_NAME "tcp"
|
#define TCPIP_THREAD_NAME "tcp"
|
||||||
#define TCPIP_THREAD_STACKSIZE 2048
|
#define TCPIP_THREAD_STACKSIZE 4096
|
||||||
#define TCPIP_MBOX_SIZE 16
|
#define TCPIP_MBOX_SIZE 16
|
||||||
#define TCPIP_THREAD_PRIO 30
|
#define TCPIP_THREAD_PRIO 30
|
||||||
|
|
||||||
|
@ -573,7 +573,6 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
|
||||||
typedef unsigned int nfds_t;
|
typedef unsigned int nfds_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define MEMP_LIB_MALLOC 1
|
#define MEMP_LIB_MALLOC 1
|
||||||
#define MEMP_MEM_MALLOC 1
|
#define MEMP_MEM_MALLOC 1
|
||||||
|
|
||||||
|
@ -584,4 +583,3 @@ typedef unsigned int nfds_t;
|
||||||
#endif /* __LWIPOPTS_H__ */
|
#endif /* __LWIPOPTS_H__ */
|
||||||
|
|
||||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||||
|
|
||||||
|
|
|
@ -387,7 +387,7 @@ void lwip_config_tcp(uint8_t enet_port, char* ip, char* mask, char* gw)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
netif_set_default(&gnetif);
|
// netif_set_default(&gnetif);
|
||||||
netif_set_up(&gnetif);
|
netif_set_up(&gnetif);
|
||||||
|
|
||||||
lw_print("\r\n************************************************\r\n");
|
lw_print("\r\n************************************************\r\n");
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
SRC_FILES := ping.c lwip_ping_demo.c lwip_tcp_demo.c lwip_udp_demo.c tcpecho_raw.c lwip_config_demo.c lwip_dhcp_demo.c iperf.c http_test.c
|
# SRC_FILES := ping.c lwip_ping_demo.c lwip_config_demo.c lwip_dhcp_demo.c iperf.c http_test.c
|
||||||
# SRC_FILES := ping.c lwip_ping_demo.c lwip_tcp_demo.c lwip_udp_demo.c tcpecho_raw.c lwip_config_demo.c lwip_dhcp_demo.c iperf.c
|
SRC_FILES := ping.c lwip_ping_demo.c lwip_tcp_demo.c lwip_udp_demo.c tcpecho_raw.c lwip_config_demo.c lwip_dhcp_demo.c iperf.c
|
||||||
|
|
||||||
include $(KERNEL_ROOT)/compiler.mk
|
include $(KERNEL_ROOT)/compiler.mk
|
||||||
|
|
|
@ -9,7 +9,7 @@ void httpc_app_recv_end(void *arg, httpc_result_t httpc_result, u32_t rx_content
|
||||||
httpc_state_t **req = (httpc_state_t**)arg;
|
httpc_state_t **req = (httpc_state_t**)arg;
|
||||||
|
|
||||||
LWIP_DEBUGF(LWIP_DEBUG, ("[HTTPC] Transfer finished. rx_content_len is %lu\r\n", rx_content_len));
|
LWIP_DEBUGF(LWIP_DEBUG, ("[HTTPC] Transfer finished. rx_content_len is %lu\r\n", rx_content_len));
|
||||||
printf("[HTTPC] Transfer finished. rx_content_len is %lu\r\n", rx_content_len);
|
printf("[HTTPC] Transfer finished. rx_content_len is %u\r\n", rx_content_len);
|
||||||
*req = NULL;
|
*req = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -266,6 +266,8 @@ void iperf_server_worker(void* arg) {
|
||||||
struct sock_conn_cb *sccb = (struct sock_conn_cb *)arg;
|
struct sock_conn_cb *sccb = (struct sock_conn_cb *)arg;
|
||||||
x_ticks_t tick1, tick2;
|
x_ticks_t tick1, tick2;
|
||||||
|
|
||||||
|
int cur_tid = GetKTaskDescriptor()->id.id;
|
||||||
|
|
||||||
uint8_t *recv_data = (uint8_t *)malloc(IPERF_BUFSZ);
|
uint8_t *recv_data = (uint8_t *)malloc(IPERF_BUFSZ);
|
||||||
if(recv_data == NULL) {
|
if(recv_data == NULL) {
|
||||||
KPrintf("[%s] No Memory.\n", __func__);
|
KPrintf("[%s] No Memory.\n", __func__);
|
||||||
|
@ -282,8 +284,6 @@ void iperf_server_worker(void* arg) {
|
||||||
(void *) &flag, /* the cast is historical cruft */
|
(void *) &flag, /* the cast is historical cruft */
|
||||||
sizeof(int)); /* length of option value */
|
sizeof(int)); /* length of option value */
|
||||||
|
|
||||||
int cur_tid = GetKTaskDescriptor()->id.id;
|
|
||||||
|
|
||||||
tick1 = CurrentTicksGain();
|
tick1 = CurrentTicksGain();
|
||||||
while (param.mode != IPERF_MODE_STOP) {
|
while (param.mode != IPERF_MODE_STOP) {
|
||||||
bytes_received = recv(sccb->connected, recv_data, IPERF_BUFSZ, 0);
|
bytes_received = recv(sccb->connected, recv_data, IPERF_BUFSZ, 0);
|
||||||
|
@ -393,7 +393,7 @@ __exit:
|
||||||
|
|
||||||
void iperf_server(void *thread_param)
|
void iperf_server(void *thread_param)
|
||||||
{
|
{
|
||||||
uint8_t *recv_data;
|
uint8_t* recv_data = NULL;
|
||||||
socklen_t sin_size;
|
socklen_t sin_size;
|
||||||
x_ticks_t tick1, tick2;
|
x_ticks_t tick1, tick2;
|
||||||
int sock = -1, connected, bytes_received;
|
int sock = -1, connected, bytes_received;
|
||||||
|
|
|
@ -41,10 +41,10 @@ void LwipSetIPTest(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
if (argc >= 4) {
|
if (argc >= 4) {
|
||||||
printf("lw: [%s] ip %s mask %s gw %s netport %s\n", __func__, argv[1], argv[2], argv[3], argv[4]);
|
printf("lw: [%s] ip %s mask %s gw %s netport %s\n", __func__, argv[1], argv[2], argv[3], argv[4]);
|
||||||
sscanf(argv[1], "%d.%d.%d.%d", &lwip_ipaddr[0], &lwip_ipaddr[1], &lwip_ipaddr[2], &lwip_ipaddr[3]);
|
sscanf(argv[1], "%hhd.%hhd.%hhd.%hhd", &lwip_ipaddr[0], &lwip_ipaddr[1], &lwip_ipaddr[2], &lwip_ipaddr[3]);
|
||||||
sscanf(argv[2], "%d.%d.%d.%d", &lwip_netmask[0], &lwip_netmask[1], &lwip_netmask[2], &lwip_netmask[3]);
|
sscanf(argv[2], "%hhd.%hhd.%hhd.%hhd", &lwip_netmask[0], &lwip_netmask[1], &lwip_netmask[2], &lwip_netmask[3]);
|
||||||
sscanf(argv[3], "%d.%d.%d.%d", &lwip_gwaddr[0], &lwip_gwaddr[1], &lwip_gwaddr[2], &lwip_gwaddr[3]);
|
sscanf(argv[3], "%hhd.%hhd.%hhd.%hhd", &lwip_gwaddr[0], &lwip_gwaddr[1], &lwip_gwaddr[2], &lwip_gwaddr[3]);
|
||||||
sscanf(argv[4], "%d", &enet_id);
|
sscanf(argv[4], "%hhd", &enet_id);
|
||||||
|
|
||||||
if (0 == enet_id) {
|
if (0 == enet_id) {
|
||||||
printf("save eth0 info\n");
|
printf("save eth0 info\n");
|
||||||
|
@ -59,7 +59,7 @@ void LwipSetIPTest(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
} else if (argc == 2) {
|
} else if (argc == 2) {
|
||||||
printf("lw: [%s] set eth0 ipaddr %s \n", __func__, argv[1]);
|
printf("lw: [%s] set eth0 ipaddr %s \n", __func__, argv[1]);
|
||||||
sscanf(argv[1], "%d.%d.%d.%d", &lwip_ipaddr[0], &lwip_ipaddr[1], &lwip_ipaddr[2], &lwip_ipaddr[3]);
|
sscanf(argv[1], "%hhd.%hhd.%hhd.%hhd", &lwip_ipaddr[0], &lwip_ipaddr[1], &lwip_ipaddr[2], &lwip_ipaddr[3]);
|
||||||
memcpy(lwip_eth0_ipaddr, lwip_ipaddr, strlen(lwip_ipaddr));
|
memcpy(lwip_eth0_ipaddr, lwip_ipaddr, strlen(lwip_ipaddr));
|
||||||
}
|
}
|
||||||
// sys_thread_new("SET ip address", LwipSetIPTask, &enet_id, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
|
// sys_thread_new("SET ip address", LwipSetIPTask, &enet_id, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
|
||||||
|
|
|
@ -144,13 +144,13 @@ void LwipDHCPTest(void)
|
||||||
/* Print DHCP progress */
|
/* Print DHCP progress */
|
||||||
if(LwipPrintDHCP(&gnetif))
|
if(LwipPrintDHCP(&gnetif))
|
||||||
{
|
{
|
||||||
sscanf(ipaddr_ntoa(&gnetif.ip_addr), "%d.%d.%d.%d", &lwip_ipaddr[0], &lwip_ipaddr[1],
|
sscanf(ipaddr_ntoa(&gnetif.ip_addr), "%hhd.%hhd.%hhd.%hhd", &lwip_ipaddr[0], &lwip_ipaddr[1],
|
||||||
&lwip_ipaddr[2], &lwip_ipaddr[3]);
|
&lwip_ipaddr[2], &lwip_ipaddr[3]);
|
||||||
|
|
||||||
sscanf(ipaddr_ntoa(&gnetif.netmask), "%d.%d.%d.%d", &lwip_netmask[0], &lwip_netmask[1],
|
sscanf(ipaddr_ntoa(&gnetif.netmask), "%hhd.%hhd.%hhd.%hhd", &lwip_netmask[0], &lwip_netmask[1],
|
||||||
&lwip_netmask[2], &lwip_netmask[3]);
|
&lwip_netmask[2], &lwip_netmask[3]);
|
||||||
|
|
||||||
sscanf(ipaddr_ntoa(&gnetif.gw), "%d.%d.%d.%d", &lwip_gwaddr[0], &lwip_gwaddr[1],
|
sscanf(ipaddr_ntoa(&gnetif.gw), "%hhd.%hhd.%hhd.%hhd", &lwip_gwaddr[0], &lwip_gwaddr[1],
|
||||||
&lwip_gwaddr[2], &lwip_gwaddr[3]);
|
&lwip_gwaddr[2], &lwip_gwaddr[3]);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -47,8 +47,7 @@ void LwipPingTest(int argc, char *argv[])
|
||||||
printf("lw: [%s] ping %s\n", __func__, argv[1]);
|
printf("lw: [%s] ping %s\n", __func__, argv[1]);
|
||||||
if(isdigit(argv[1][0]))
|
if(isdigit(argv[1][0]))
|
||||||
{
|
{
|
||||||
if(sscanf(argv[1], "%d.%d.%d.%d", &arg_ip[0], &arg_ip[1], &arg_ip[2], &arg_ip[3]) == EOF)
|
if (sscanf(argv[1], "%hhd.%hhd.%hhd.%hhd", &arg_ip[0], &arg_ip[1], &arg_ip[2], &arg_ip[3]) == EOF) {
|
||||||
{
|
|
||||||
lw_notice("input wrong ip\n");
|
lw_notice("input wrong ip\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
#include "tcpecho_raw.h"
|
#include "tcpecho_raw.h"
|
||||||
char tcp_demo_msg[LWIP_TEST_MSG_SIZE] = { 0 };
|
char tcp_demo_msg[LWIP_TEST_MSG_SIZE] = { 0 };
|
||||||
char tcp_server_ip[] = {192, 168, 130, 2};
|
char tcp_server_ip[] = {192, 168, 130, 2};
|
||||||
u16_t tcp_server_port = 80;
|
u32_t tcp_server_port = 80;
|
||||||
int tcp_send_num = 0;
|
int tcp_send_num = 0;
|
||||||
int tcp_send_task_on = 0;
|
int tcp_send_task_on = 0;
|
||||||
uint32 tcp_interval = 50;
|
uint32 tcp_interval = 50;
|
||||||
|
@ -101,14 +101,13 @@ void LwipTcpSendTest(int argc, char *argv[])
|
||||||
strcat(tcp_demo_msg, "\r\n");
|
strcat(tcp_demo_msg, "\r\n");
|
||||||
|
|
||||||
if(argc >= 3) {
|
if(argc >= 3) {
|
||||||
if(sscanf(argv[2], "%d.%d.%d.%d:%d", &tcp_server_ip[0], &tcp_server_ip[1], &tcp_server_ip[2], &tcp_server_ip[3], &tcp_server_port) == EOK)
|
if (sscanf(argv[2], "%hhd.%hhd.%hhd.%hhd:%d", &tcp_server_ip[0], &tcp_server_ip[1], &tcp_server_ip[2], &tcp_server_ip[3], &tcp_server_port) == EOK) {
|
||||||
{
|
sscanf(argv[2], "%hhd.%hhd.%hhd.%hhd", &tcp_server_ip[0], &tcp_server_ip[1], &tcp_server_ip[2], &tcp_server_ip[3]);
|
||||||
sscanf(argv[2], "%d.%d.%d.%d", &tcp_server_ip[0], &tcp_server_ip[1], &tcp_server_ip[2], &tcp_server_ip[3]);
|
|
||||||
}
|
}
|
||||||
sscanf(argv[3], "%d", &tcp_send_num);
|
sscanf(argv[3], "%d", &tcp_send_num);
|
||||||
sscanf(argv[4], "%d", &tcp_interval);
|
sscanf(argv[4], "%d", &tcp_interval);
|
||||||
}
|
}
|
||||||
KPrintf("connect ipaddr %d.%d.%d.%d:%d send msg %d times\n", tcp_server_ip[0], tcp_server_ip[1], tcp_server_ip[2], tcp_server_ip[3], tcp_server_port, tcp_send_num);
|
KPrintf("connect ipaddr %hhd.%hhd.%hhd.%hhd:%hhd send msg %d times\n", tcp_server_ip[0], tcp_server_ip[1], tcp_server_ip[2], tcp_server_ip[3], tcp_server_port, tcp_send_num);
|
||||||
lwip_config_tcp(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
|
lwip_config_tcp(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
|
||||||
|
|
||||||
memcpy(param.ip, tcp_server_ip, 4);
|
memcpy(param.ip, tcp_server_ip, 4);
|
||||||
|
@ -128,7 +127,7 @@ void LwipTcpRecvTest(void)
|
||||||
|
|
||||||
lwip_config_net(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
|
lwip_config_net(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
|
||||||
|
|
||||||
uint8_t *recv_data;
|
uint8_t* recv_data = NULL;
|
||||||
socklen_t sin_size;
|
socklen_t sin_size;
|
||||||
int sock = -1, connected, bytes_received, i;
|
int sock = -1, connected, bytes_received, i;
|
||||||
struct sockaddr_in server_addr, client_addr;
|
struct sockaddr_in server_addr, client_addr;
|
||||||
|
|
|
@ -165,12 +165,12 @@ static int LwipUdpSend(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// translate string to array
|
// translate string to array
|
||||||
sscanf(ip_ptr, "%d.%d.%d.%d", &get_udp_test_info()->ip[0], &get_udp_test_info()->ip[1], &get_udp_test_info()->ip[2], &get_udp_test_info()->ip[3]);
|
sscanf(ip_ptr, "%hhd.%hhd.%hhd.%hhd", &get_udp_test_info()->ip[0], &get_udp_test_info()->ip[1], &get_udp_test_info()->ip[2], &get_udp_test_info()->ip[3]);
|
||||||
int msg_len = strlen(msg_ptr);
|
int msg_len = strlen(msg_ptr);
|
||||||
strncpy(udp_demo_buffer, msg_ptr, msg_len < UDP_BUFFER_SIZE ? msg_len : UDP_BUFFER_SIZE);
|
strncpy(udp_demo_buffer, msg_ptr, msg_len < UDP_BUFFER_SIZE ? msg_len : UDP_BUFFER_SIZE);
|
||||||
|
|
||||||
/* start task */
|
/* start task */
|
||||||
KPrintf("[%s] gw %d.%d.%d.%d:%d send time %d udp_interval %d\n", __func__,
|
KPrintf("[%s] gw %hhd.%hhd.%hhd.%hhd:%d send time %d udp_interval %d\n", __func__,
|
||||||
get_udp_test_info()->ip[0], get_udp_test_info()->ip[1], get_udp_test_info()->ip[2], get_udp_test_info()->ip[3],
|
get_udp_test_info()->ip[0], get_udp_test_info()->ip[1], get_udp_test_info()->ip[2], get_udp_test_info()->ip[3],
|
||||||
get_udp_test_info()->port,
|
get_udp_test_info()->port,
|
||||||
get_udp_test_info()->num,
|
get_udp_test_info()->num,
|
||||||
|
@ -191,7 +191,7 @@ void LwipUdpRecvTest(void)
|
||||||
//init lwip and net dirver
|
//init lwip and net dirver
|
||||||
lwip_config_net(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
|
lwip_config_net(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
|
||||||
|
|
||||||
uint8_t *recv_data;
|
uint8_t* recv_data = NULL;
|
||||||
socklen_t sin_size;
|
socklen_t sin_size;
|
||||||
int sock = -1, connected, bytes_received, i;
|
int sock = -1, connected, bytes_received, i;
|
||||||
struct sockaddr_in server_addr, client_addr;
|
struct sockaddr_in server_addr, client_addr;
|
||||||
|
|
|
@ -119,7 +119,7 @@ tcpecho_raw_ack_size(struct tcp_pcb *tpcb, int ack_len)
|
||||||
|
|
||||||
// ack message
|
// ack message
|
||||||
ack_buf = pbuf_alloc(PBUF_TRANSPORT, TCP_ACK_MSG_SIZE, PBUF_RAM);
|
ack_buf = pbuf_alloc(PBUF_TRANSPORT, TCP_ACK_MSG_SIZE, PBUF_RAM);
|
||||||
snprintf(ack_buf->payload, TCP_ACK_MSG_SIZE, "%d\n\0", ack_len);
|
snprintf(ack_buf->payload, TCP_ACK_MSG_SIZE, "%d\n", ack_len);
|
||||||
ack_buf->len = strlen(ack_buf->payload);
|
ack_buf->len = strlen(ack_buf->payload);
|
||||||
ack_buf->tot_len = strlen(ack_buf->payload);
|
ack_buf->tot_len = strlen(ack_buf->payload);
|
||||||
ack_buf->next = NULL;
|
ack_buf->next = NULL;
|
||||||
|
|
|
@ -116,7 +116,7 @@ static int CopyRecursive(const char *from, const char *to, char *buf,
|
||||||
|
|
||||||
DIR *dirp;
|
DIR *dirp;
|
||||||
struct dirent *dirent;
|
struct dirent *dirent;
|
||||||
char *sub_from, *sub_to;
|
char *sub_from = NULL, *sub_to = NULL;
|
||||||
|
|
||||||
ret = mkdir(to, 0777);
|
ret = mkdir(to, 0777);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
|
|
@ -31,7 +31,7 @@ static void PrintOctal(char *str, int len, uint64_t value)
|
||||||
char *cp;
|
char *cp;
|
||||||
int written_len;
|
int written_len;
|
||||||
|
|
||||||
written_len = sprintf(buf, "%0*llo", len, value);
|
written_len = sprintf(buf, "%0*lo", len, value);
|
||||||
cp = buf + written_len - len;
|
cp = buf + written_len - len;
|
||||||
|
|
||||||
if (*cp == '0')
|
if (*cp == '0')
|
||||||
|
|
Loading…
Reference in New Issue