forked from xuos/xiuos
Merge branch 'prepare_for_master' of https://git.trustie.net/xuos/xiuos into jerryscript
This commit is contained in:
commit
e8061577da
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ menu "lib using MQTT"
|
||||||
menu "MQTT connection parameter configuration."
|
menu "MQTT connection parameter configuration."
|
||||||
config PLATFORM_PRODUCTKEY
|
config PLATFORM_PRODUCTKEY
|
||||||
string "Product Key, used to identify a product."
|
string "Product Key, used to identify a product."
|
||||||
default "iywhcgnuezz"
|
default "iv74vebCdJC"
|
||||||
|
|
||||||
config CLIENT_DEVICENAME
|
config CLIENT_DEVICENAME
|
||||||
string "Device name, used to identify a client device."
|
string "Device name, used to identify a client device."
|
||||||
|
@ -18,7 +18,7 @@ menu "lib using MQTT"
|
||||||
|
|
||||||
config CLIENT_DEVICESECRET
|
config CLIENT_DEVICESECRET
|
||||||
string "Device secret, used for device authentication and data encryption."
|
string "Device secret, used for device authentication and data encryption."
|
||||||
default "c9a4ce03e9382065fc089e9ff54b771d"
|
default "d2e613c4f714b6b0774bd7b68eeceae3"
|
||||||
|
|
||||||
config PLATFORM_SERVERIP
|
config PLATFORM_SERVERIP
|
||||||
string "mqtt platform server ip."
|
string "mqtt platform server ip."
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
@ -19,7 +20,7 @@ export CXXFLAGS := -mcmodel=medany -march=rv64imafdc -mabi=lp64d -fno-common -ff
|
||||||
export CROSS_COMPILE ?=/opt/gnu-mcu-eclipse/riscv-none-gcc/8.2.0-2.1-20190425-1021/bin/riscv-none-embed-
|
export CROSS_COMPILE ?=/opt/gnu-mcu-eclipse/riscv-none-gcc/8.2.0-2.1-20190425-1021/bin/riscv-none-embed-
|
||||||
|
|
||||||
|
|
||||||
export DEFINES := -DHAVE_CCONFIG_H -DHAVE_SIGINFO
|
export DEFINES := -DHAVE_CCONFIG_H -DHAVE_SIGINFO -DRISCV_LWIP
|
||||||
|
|
||||||
export ARCH = risc-v
|
export ARCH = risc-v
|
||||||
export MCU = k210
|
export MCU = k210
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
config BSP_USING_W5500
|
config BSP_USING_W5500
|
||||||
bool "Using w5500"
|
bool "Using w5500"
|
||||||
|
select BSP_USING_LWIP
|
||||||
default y
|
default y
|
||||||
|
|
||||||
config BSP_WIZ_RST_PIN
|
config BSP_WIZ_RST_PIN
|
||||||
|
@ -15,3 +16,8 @@ config BSP_WIZ_INT_PIN
|
||||||
config BSP_WIZ_USE_IPERF
|
config BSP_WIZ_USE_IPERF
|
||||||
bool "Using iperf"
|
bool "Using iperf"
|
||||||
default y
|
default y
|
||||||
|
|
||||||
|
menuconfig BSP_USING_LWIP
|
||||||
|
bool "Using LwIP device"
|
||||||
|
default n
|
||||||
|
select RESOURCES_LWIP
|
|
@ -1,3 +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 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"
|
||||||
|
@ -14,6 +14,10 @@
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
#include "w5500.h"
|
#include "w5500.h"
|
||||||
|
|
||||||
|
#include "connect_ethernet.h"
|
||||||
|
|
||||||
|
#include <sys.h>
|
||||||
|
|
||||||
#define SPI_LORA_FREQUENCY 10000000
|
#define SPI_LORA_FREQUENCY 10000000
|
||||||
|
|
||||||
// spi operations
|
// spi operations
|
||||||
|
@ -23,242 +27,329 @@ 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;
|
{
|
||||||
return g_wiznet_buf_size;
|
static const uint32_t g_wiznet_buf_size = 2048;
|
||||||
|
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 },
|
||||||
return &g_wiz_netinfo;
|
.dhcp = NETINFO_STATIC };
|
||||||
|
return &g_wiz_netinfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
int network_init() {
|
int network_init()
|
||||||
wiz_NetInfo check_wiz_netinfo;
|
{
|
||||||
check_wiz_netinfo.dhcp = NETINFO_STATIC;
|
wiz_NetInfo check_wiz_netinfo;
|
||||||
ctlnetwork(CN_SET_NETINFO, (void *)get_gnetinfo());
|
check_wiz_netinfo.dhcp = NETINFO_STATIC;
|
||||||
ctlnetwork(CN_GET_NETINFO, (void *)&check_wiz_netinfo);
|
ctlnetwork(CN_SET_NETINFO, (void*)get_gnetinfo());
|
||||||
|
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(
|
||||||
"mac: %d; ip: %d; gw: %d; sn: %d; dns: %d; dhcp: %d;\n",
|
"mac: %d; ip: %d; gw: %d; sn: %d; dns: %d; dhcp: %d;\n",
|
||||||
memcmp(&get_gnetinfo()->mac, &check_wiz_netinfo.mac, sizeof(uint8_t) * 6),
|
memcmp(&get_gnetinfo()->mac, &check_wiz_netinfo.mac, sizeof(uint8_t) * 6),
|
||||||
memcmp(&get_gnetinfo()->ip, &check_wiz_netinfo.ip, sizeof(uint8_t) * 4),
|
memcmp(&get_gnetinfo()->ip, &check_wiz_netinfo.ip, sizeof(uint8_t) * 4),
|
||||||
memcmp(&get_gnetinfo()->sn, &check_wiz_netinfo.sn, sizeof(uint8_t) * 4),
|
memcmp(&get_gnetinfo()->sn, &check_wiz_netinfo.sn, sizeof(uint8_t) * 4),
|
||||||
memcmp(&get_gnetinfo()->gw, &check_wiz_netinfo.gw, sizeof(uint8_t) * 4),
|
memcmp(&get_gnetinfo()->gw, &check_wiz_netinfo.gw, sizeof(uint8_t) * 4),
|
||||||
memcmp(&get_gnetinfo()->dns, &check_wiz_netinfo.dns, sizeof(uint8_t) * 4),
|
memcmp(&get_gnetinfo()->dns, &check_wiz_netinfo.dns, sizeof(uint8_t) * 4),
|
||||||
memcmp(&get_gnetinfo()->dhcp, &check_wiz_netinfo.dhcp, sizeof(uint8_t)));
|
memcmp(&get_gnetinfo()->dhcp, &check_wiz_netinfo.dhcp, sizeof(uint8_t)));
|
||||||
KPrintf("WIZCHIP set network information fail.\n");
|
KPrintf("WIZCHIP set network information fail.\n");
|
||||||
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]);
|
||||||
KPrintf("SIP: %d.%d.%d.%d\r\n", get_gnetinfo()->ip[0], get_gnetinfo()->ip[1],
|
KPrintf("SIP: %d.%d.%d.%d\r\n", get_gnetinfo()->ip[0], get_gnetinfo()->ip[1],
|
||||||
get_gnetinfo()->ip[2], get_gnetinfo()->ip[3]);
|
get_gnetinfo()->ip[2], get_gnetinfo()->ip[3]);
|
||||||
KPrintf("GAR: %d.%d.%d.%d\r\n", get_gnetinfo()->gw[0], get_gnetinfo()->gw[1],
|
KPrintf("GAR: %d.%d.%d.%d\r\n", get_gnetinfo()->gw[0], get_gnetinfo()->gw[1],
|
||||||
get_gnetinfo()->gw[2], get_gnetinfo()->gw[3]);
|
get_gnetinfo()->gw[2], get_gnetinfo()->gw[3]);
|
||||||
KPrintf("SUB: %d.%d.%d.%d\r\n", get_gnetinfo()->sn[0], get_gnetinfo()->sn[1],
|
KPrintf("SUB: %d.%d.%d.%d\r\n", get_gnetinfo()->sn[0], get_gnetinfo()->sn[1],
|
||||||
get_gnetinfo()->sn[2], get_gnetinfo()->sn[3]);
|
get_gnetinfo()->sn[2], get_gnetinfo()->sn[3]);
|
||||||
KPrintf("DNS: %d.%d.%d.%d\r\n", get_gnetinfo()->dns[0], get_gnetinfo()->dns[1],
|
KPrintf("DNS: %d.%d.%d.%d\r\n", get_gnetinfo()->dns[0], get_gnetinfo()->dns[1],
|
||||||
get_gnetinfo()->dns[2], get_gnetinfo()->dns[3]);
|
get_gnetinfo()->dns[2], get_gnetinfo()->dns[3]);
|
||||||
KPrintf("======================\r\n");
|
KPrintf("======================\r\n");
|
||||||
|
|
||||||
return EOK;
|
return EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************** 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,
|
||||||
w5500_spi_bus->owner_haldev);
|
w5500_spi_bus->owner_haldev);
|
||||||
|
|
||||||
struct BusConfigureInfo configure_info;
|
struct BusConfigureInfo configure_info;
|
||||||
struct SpiMasterParam spi_master_param;
|
struct SpiMasterParam spi_master_param;
|
||||||
spi_master_param.spi_data_bit_width = 8;
|
spi_master_param.spi_data_bit_width = 8;
|
||||||
spi_master_param.spi_work_mode = SPI_MODE_0 | SPI_MSB;
|
spi_master_param.spi_work_mode = SPI_MODE_0 | SPI_MSB;
|
||||||
spi_master_param.spi_maxfrequency = SPI_LORA_FREQUENCY;
|
spi_master_param.spi_maxfrequency = SPI_LORA_FREQUENCY;
|
||||||
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",
|
||||||
w5500_spi_bus->owner_driver, &spi_master_param);
|
w5500_spi_bus->owner_driver, &spi_master_param);
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
configure_info.configure_cmd = OPE_INT;
|
configure_info.configure_cmd = OPE_INT;
|
||||||
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_INT error drv %8p\n", w5500_spi_bus->owner_driver);
|
KPrintf("spi drv OPE_INT error drv %8p\n", w5500_spi_bus->owner_driver);
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EOK;
|
return EOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spi_write_byte(uint8_t tx_data) {
|
void spi_write_byte(uint8_t tx_data)
|
||||||
struct BusBlockWriteParam write_param;
|
{
|
||||||
write_param.buffer = &tx_data;
|
struct BusBlockWriteParam write_param;
|
||||||
write_param.size = 1;
|
uint8_t data = tx_data;
|
||||||
BusDevWriteData(w5500_spi_bus->owner_haldev, &write_param);
|
write_param.buffer = &data;
|
||||||
|
write_param.size = 1;
|
||||||
|
BusDevWriteData(w5500_spi_bus->owner_haldev, &write_param);
|
||||||
}
|
}
|
||||||
uint8_t spi_read_byte(void) {
|
uint8_t spi_read_byte(void)
|
||||||
uint8_t result = 0;
|
{
|
||||||
struct BusBlockReadParam read_param;
|
uint8_t result = 0;
|
||||||
read_param.buffer = &result;
|
struct BusBlockReadParam read_param;
|
||||||
read_param.size = 1;
|
read_param.buffer = &result;
|
||||||
BusDevReadData(w5500_spi_bus->owner_haldev, &read_param);
|
read_param.size = 1;
|
||||||
return result;
|
BusDevReadData(w5500_spi_bus->owner_haldev, &read_param);
|
||||||
|
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;
|
{
|
||||||
write_param.buffer = tx_buf;
|
struct BusBlockWriteParam write_param;
|
||||||
write_param.size = len;
|
write_param.buffer = tx_buf;
|
||||||
BusDevWriteData(w5500_spi_bus->owner_haldev, &write_param);
|
write_param.size = len;
|
||||||
|
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;
|
{
|
||||||
read_param.buffer = rx_buf;
|
struct BusBlockReadParam read_param;
|
||||||
read_param.size = len;
|
read_param.buffer = rx_buf;
|
||||||
BusDevReadData(w5500_spi_bus->owner_haldev, &read_param);
|
read_param.size = len;
|
||||||
|
BusDevReadData(w5500_spi_bus->owner_haldev, &read_param);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************** chip init ******************/
|
/****************** chip init ******************/
|
||||||
|
|
||||||
void wiz_reset() {
|
void wiz_reset()
|
||||||
gpiohs_set_drive_mode(WIZ_RST_PIN, GPIO_DM_OUTPUT);
|
{
|
||||||
gpiohs_set_pin(WIZ_RST_PIN, GPIO_PV_LOW);
|
gpiohs_set_drive_mode(WIZ_RST_PIN, GPIO_DM_OUTPUT);
|
||||||
MdelayKTask(20);
|
gpiohs_set_pin(WIZ_RST_PIN, GPIO_PV_LOW);
|
||||||
|
MdelayKTask(20);
|
||||||
|
|
||||||
gpiohs_set_pin(WIZ_RST_PIN, GPIO_PV_HIGH);
|
gpiohs_set_pin(WIZ_RST_PIN, GPIO_PV_HIGH);
|
||||||
MdelayKTask(20);
|
MdelayKTask(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wiz_spi_handler_reg() {
|
void wiz_spi_handler_reg()
|
||||||
// spi ops registration
|
{
|
||||||
#if (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_VDM_) || \
|
// spi ops registration
|
||||||
(_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_FDM_)
|
#if (_WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_VDM_) || (_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);
|
||||||
#else
|
#else
|
||||||
#if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SIP_) != _WIZCHIP_IO_MODE_SIP_
|
#if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SIP_) != _WIZCHIP_IO_MODE_SIP_
|
||||||
#error "Unknown _WIZCHIP_IO_MODE_"
|
#error "Unknown _WIZCHIP_IO_MODE_"
|
||||||
#else
|
#else
|
||||||
reg_wizchip_cs_cbfunc(wizchip_select, wizchip_deselect);
|
reg_wizchip_cs_cbfunc(wizchip_select, wizchip_deselect);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
reg_wizchip_spi_cbfunc(spi_read_byte, spi_write_byte);
|
reg_wizchip_spi_cbfunc(spi_read_byte, spi_write_byte);
|
||||||
reg_wizchip_cris_cbfunc(spi_enter_cris, spi_exit_cris);
|
reg_wizchip_cris_cbfunc(spi_enter_cris, spi_exit_cris);
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
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>
|
||||||
int wiz_interrupt_init() {
|
static inline void spi_if_clr(void)
|
||||||
int32_t ret = -ERROR;
|
{
|
||||||
|
setSn_IR(0, 0x1F);
|
||||||
struct Bus *pin_bus = PinBusInitGet();
|
setSIR(0);
|
||||||
|
|
||||||
struct PinParam pin_param;
|
|
||||||
struct BusConfigureInfo pin_configure_info;
|
|
||||||
|
|
||||||
pin_configure_info.configure_cmd = OPE_CFG;
|
|
||||||
pin_configure_info.private_data = (void *)&pin_param;
|
|
||||||
|
|
||||||
pin_param.cmd = GPIO_CONFIG_MODE;
|
|
||||||
pin_param.pin = BSP_WIZ_INT_PIN;
|
|
||||||
pin_param.mode = GPIO_CFG_INPUT_PULLUP;
|
|
||||||
ret = BusDrvConfigure(pin_bus->owner_driver, &pin_configure_info);
|
|
||||||
if (ret != EOK) {
|
|
||||||
KPrintf("config pin_param %d input failed!\n", pin_param.pin);
|
|
||||||
return -ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
pin_param.cmd = GPIO_IRQ_REGISTER;
|
|
||||||
pin_param.pin = BSP_WIZ_INT_PIN;
|
|
||||||
pin_param.irq_set.irq_mode = GPIO_IRQ_EDGE_FALLING;
|
|
||||||
pin_param.irq_set.hdr = wiz_irq_handler;
|
|
||||||
pin_param.irq_set.args = NONE;
|
|
||||||
ret = BusDrvConfigure(pin_bus->owner_driver, &pin_configure_info);
|
|
||||||
if (ret != EOK) {
|
|
||||||
KPrintf("register pin_param %d irq failed!\n", pin_param.pin);
|
|
||||||
return -ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
pin_param.cmd = GPIO_IRQ_DISABLE;
|
|
||||||
pin_param.pin = BSP_WIZ_INT_PIN;
|
|
||||||
ret = BusDrvConfigure(pin_bus->owner_driver, &pin_configure_info);
|
|
||||||
if (ret != EOK) {
|
|
||||||
KPrintf("disable pin_param %d irq failed!\n", pin_param.pin);
|
|
||||||
return -ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. enable interuption
|
|
||||||
pin_param.cmd = GPIO_IRQ_ENABLE;
|
|
||||||
pin_param.pin = BSP_WIZ_INT_PIN;
|
|
||||||
ret = BusDrvConfigure(pin_bus->owner_driver, &pin_configure_info);
|
|
||||||
if (ret != EOK) {
|
|
||||||
KPrintf("enable pin_param %d irq failed!\n", pin_param.pin);
|
|
||||||
return -ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
return EOK;
|
|
||||||
|
|
||||||
return EOK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int HwWiznetInit(void) {
|
void wiz_irq_handler()
|
||||||
wiz_reset();
|
{
|
||||||
|
static x_base eth_irq_lock;
|
||||||
|
eth_irq_lock = DISABLE_INTERRUPT();
|
||||||
|
|
||||||
if (EOK != w5500_spi_init()) {
|
if (*get_eth_recv_sem() > 0) {
|
||||||
return ERROR;
|
sys_sem_signal(get_eth_recv_sem());
|
||||||
}
|
}
|
||||||
|
|
||||||
wiz_spi_handler_reg();
|
ENABLE_INTERRUPT(eth_irq_lock);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
void wiz_irq_handler()
|
||||||
|
{
|
||||||
|
static x_base eth_irq_lock;
|
||||||
|
eth_irq_lock = DISABLE_INTERRUPT();
|
||||||
|
|
||||||
if (EOK != wiz_chip_cfg_init()) {
|
printf("=");
|
||||||
return ERROR;
|
uint8_t ir = getIR();
|
||||||
}
|
setSIR(0x00);
|
||||||
|
setIR(0x00);
|
||||||
|
|
||||||
network_init();
|
ENABLE_INTERRUPT(eth_irq_lock);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return EOK;
|
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;
|
||||||
|
|
||||||
|
wizchip_interrupt_init(0, wiz_irq_handler);
|
||||||
|
|
||||||
|
struct Bus* pin_bus = PinBusInitGet();
|
||||||
|
|
||||||
|
struct PinParam pin_param;
|
||||||
|
struct BusConfigureInfo pin_configure_info;
|
||||||
|
|
||||||
|
pin_configure_info.configure_cmd = OPE_CFG;
|
||||||
|
pin_configure_info.private_data = (void*)&pin_param;
|
||||||
|
|
||||||
|
pin_param.cmd = GPIO_CONFIG_MODE;
|
||||||
|
pin_param.pin = BSP_WIZ_INT_PIN;
|
||||||
|
pin_param.mode = GPIO_CFG_INPUT_PULLUP;
|
||||||
|
ret = BusDrvConfigure(pin_bus->owner_driver, &pin_configure_info);
|
||||||
|
if (ret != EOK) {
|
||||||
|
KPrintf("config pin_param %d input failed!\n", pin_param.pin);
|
||||||
|
return -ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
pin_param.cmd = GPIO_IRQ_REGISTER;
|
||||||
|
pin_param.pin = BSP_WIZ_INT_PIN;
|
||||||
|
pin_param.irq_set.irq_mode = GPIO_IRQ_EDGE_FALLING;
|
||||||
|
pin_param.irq_set.hdr = wiz_irq_handler;
|
||||||
|
pin_param.irq_set.args = NONE;
|
||||||
|
ret = BusDrvConfigure(pin_bus->owner_driver, &pin_configure_info);
|
||||||
|
if (ret != EOK) {
|
||||||
|
KPrintf("register pin_param %d irq failed!\n", pin_param.pin);
|
||||||
|
return -ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
pin_param.cmd = GPIO_IRQ_DISABLE;
|
||||||
|
pin_param.pin = BSP_WIZ_INT_PIN;
|
||||||
|
ret = BusDrvConfigure(pin_bus->owner_driver, &pin_configure_info);
|
||||||
|
if (ret != EOK) {
|
||||||
|
KPrintf("disable pin_param %d irq failed!\n", pin_param.pin);
|
||||||
|
return -ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. enable interuption
|
||||||
|
pin_param.cmd = GPIO_IRQ_ENABLE;
|
||||||
|
pin_param.pin = BSP_WIZ_INT_PIN;
|
||||||
|
ret = BusDrvConfigure(pin_bus->owner_driver, &pin_configure_info);
|
||||||
|
if (ret != EOK) {
|
||||||
|
KPrintf("enable pin_param %d irq failed!\n", pin_param.pin);
|
||||||
|
return -ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int HwWiznetInit(void)
|
||||||
|
{
|
||||||
|
wiz_reset();
|
||||||
|
|
||||||
|
if (EOK != w5500_spi_init()) {
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
wiz_spi_handler_reg();
|
||||||
|
|
||||||
|
if (EOK != wiz_chip_cfg_init()) {
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern uint8_t wiz_mac[6];
|
||||||
|
setSHAR(wiz_mac);
|
||||||
|
ctlwizchip(CW_RESET_PHY, 0);
|
||||||
|
|
||||||
|
wiz_interrupt_init(0, wiz_irq_handler);
|
||||||
|
|
||||||
|
setSn_RXBUF_SIZE(0, 16);
|
||||||
|
setSn_TXBUF_SIZE(0, 16);
|
||||||
|
#define SOCK_ANY_PORT_NUM 0xC000
|
||||||
|
setSn_MR(0, Sn_MR_MFEN | Sn_MR_MACRAW | Sn_MR_MIP6B | Sn_MR_MMB);
|
||||||
|
wiz_socket(0, Sn_MR_MACRAW, SOCK_ANY_PORT_NUM, SOCK_IO_NONBLOCK);
|
||||||
|
|
||||||
|
uint8_t sock_iomode = SOCK_IO_NONBLOCK;
|
||||||
|
wiz_ctlsocket(0, CS_SET_IOMODE, &sock_iomode);
|
||||||
|
|
||||||
|
uint8_t sock_sr = 0;
|
||||||
|
while (1) {
|
||||||
|
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) {
|
||||||
|
SYS_KDEBUG_LOG(WIZNET_DEBUG, ("Socket 0 MACRAW mode established\r\n"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
network_init();
|
||||||
|
|
||||||
|
return EOK;
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -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,191 +65,198 @@
|
||||||
#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 spi_data[3];
|
uint8_t ret = 0;
|
||||||
|
uint8_t spi_data[3];
|
||||||
|
|
||||||
WIZCHIP_CRITICAL_ENTER();
|
WIZCHIP_CRITICAL_ENTER();
|
||||||
WIZCHIP.CS._select();
|
WIZCHIP.CS._select();
|
||||||
|
|
||||||
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);
|
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0);
|
||||||
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0);
|
} else // burst operation
|
||||||
} else // burst operation
|
{
|
||||||
{
|
spi_data[0] = (AddrSel & 0x00FF0000) >> 16;
|
||||||
spi_data[0] = (AddrSel & 0x00FF0000) >> 16;
|
spi_data[1] = (AddrSel & 0x0000FF00) >> 8;
|
||||||
spi_data[1] = (AddrSel & 0x0000FF00) >> 8;
|
spi_data[2] = (AddrSel & 0x000000FF) >> 0;
|
||||||
spi_data[2] = (AddrSel & 0x000000FF) >> 0;
|
WIZCHIP.IF.SPI._write_burst(spi_data, 3);
|
||||||
WIZCHIP.IF.SPI._write_burst(spi_data, 3);
|
|
||||||
}
|
|
||||||
ret = WIZCHIP.IF.SPI._read_byte();
|
|
||||||
|
|
||||||
WIZCHIP.CS._deselect();
|
|
||||||
WIZCHIP_CRITICAL_EXIT();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb) {
|
|
||||||
uint8_t spi_data[4];
|
|
||||||
|
|
||||||
WIZCHIP_CRITICAL_ENTER();
|
|
||||||
WIZCHIP.CS._select();
|
|
||||||
|
|
||||||
AddrSel |= (_W5500_SPI_WRITE_ | _W5500_SPI_VDM_OP_);
|
|
||||||
|
|
||||||
// if(!WIZCHIP.IF.SPI._read_burst || !WIZCHIP.IF.SPI._write_burst) // byte
|
|
||||||
// operation
|
|
||||||
if (!WIZCHIP.IF.SPI._write_burst) // byte operation
|
|
||||||
{
|
|
||||||
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16);
|
|
||||||
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8);
|
|
||||||
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0);
|
|
||||||
WIZCHIP.IF.SPI._write_byte(wb);
|
|
||||||
} else // burst operation
|
|
||||||
{
|
|
||||||
spi_data[0] = (AddrSel & 0x00FF0000) >> 16;
|
|
||||||
spi_data[1] = (AddrSel & 0x0000FF00) >> 8;
|
|
||||||
spi_data[2] = (AddrSel & 0x000000FF) >> 0;
|
|
||||||
spi_data[3] = wb;
|
|
||||||
WIZCHIP.IF.SPI._write_burst(spi_data, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
WIZCHIP.CS._deselect();
|
|
||||||
WIZCHIP_CRITICAL_EXIT();
|
|
||||||
}
|
|
||||||
|
|
||||||
void WIZCHIP_READ_BUF(uint32_t AddrSel, uint8_t *pBuf, uint16_t len) {
|
|
||||||
uint8_t spi_data[3];
|
|
||||||
uint16_t i;
|
|
||||||
|
|
||||||
WIZCHIP_CRITICAL_ENTER();
|
|
||||||
WIZCHIP.CS._select();
|
|
||||||
|
|
||||||
AddrSel |= (_W5500_SPI_READ_ | _W5500_SPI_VDM_OP_);
|
|
||||||
|
|
||||||
if (!WIZCHIP.IF.SPI._read_burst ||
|
|
||||||
!WIZCHIP.IF.SPI._write_burst) // byte operation
|
|
||||||
{
|
|
||||||
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16);
|
|
||||||
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8);
|
|
||||||
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0);
|
|
||||||
for (i = 0; i < len; i++)
|
|
||||||
pBuf[i] = WIZCHIP.IF.SPI._read_byte();
|
|
||||||
} else // burst operation
|
|
||||||
{
|
|
||||||
spi_data[0] = (AddrSel & 0x00FF0000) >> 16;
|
|
||||||
spi_data[1] = (AddrSel & 0x0000FF00) >> 8;
|
|
||||||
spi_data[2] = (AddrSel & 0x000000FF) >> 0;
|
|
||||||
WIZCHIP.IF.SPI._write_burst(spi_data, 3);
|
|
||||||
WIZCHIP.IF.SPI._read_burst(pBuf, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
WIZCHIP.CS._deselect();
|
|
||||||
WIZCHIP_CRITICAL_EXIT();
|
|
||||||
}
|
|
||||||
|
|
||||||
void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t *pBuf, uint16_t len) {
|
|
||||||
uint8_t spi_data[3];
|
|
||||||
uint16_t i;
|
|
||||||
|
|
||||||
WIZCHIP_CRITICAL_ENTER();
|
|
||||||
WIZCHIP.CS._select();
|
|
||||||
|
|
||||||
AddrSel |= (_W5500_SPI_WRITE_ | _W5500_SPI_VDM_OP_);
|
|
||||||
|
|
||||||
if (!WIZCHIP.IF.SPI._write_burst) // byte operation
|
|
||||||
{
|
|
||||||
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16);
|
|
||||||
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8);
|
|
||||||
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0);
|
|
||||||
for (i = 0; i < len; i++)
|
|
||||||
WIZCHIP.IF.SPI._write_byte(pBuf[i]);
|
|
||||||
} else // burst operation
|
|
||||||
{
|
|
||||||
spi_data[0] = (AddrSel & 0x00FF0000) >> 16;
|
|
||||||
spi_data[1] = (AddrSel & 0x0000FF00) >> 8;
|
|
||||||
spi_data[2] = (AddrSel & 0x000000FF) >> 0;
|
|
||||||
WIZCHIP.IF.SPI._write_burst(spi_data, 3);
|
|
||||||
WIZCHIP.IF.SPI._write_burst(pBuf, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
WIZCHIP.CS._deselect();
|
|
||||||
WIZCHIP_CRITICAL_EXIT();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t getSn_TX_FSR(uint8_t sn) {
|
|
||||||
uint16_t val = 0, val1 = 0;
|
|
||||||
|
|
||||||
do {
|
|
||||||
val1 = WIZCHIP_READ(Sn_TX_FSR(sn));
|
|
||||||
val1 = (val1 << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_FSR(sn), 1));
|
|
||||||
if (val1 != 0) {
|
|
||||||
val = WIZCHIP_READ(Sn_TX_FSR(sn));
|
|
||||||
val = (val << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_FSR(sn), 1));
|
|
||||||
}
|
}
|
||||||
} while (val != val1);
|
ret = WIZCHIP.IF.SPI._read_byte();
|
||||||
return val;
|
|
||||||
|
WIZCHIP.CS._deselect();
|
||||||
|
WIZCHIP_CRITICAL_EXIT();
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t getSn_RX_RSR(uint8_t sn) {
|
void WIZCHIP_WRITE(uint32_t AddrSel, uint8_t wb)
|
||||||
uint16_t val = 0, val1 = 0;
|
{
|
||||||
|
uint8_t spi_data[4];
|
||||||
|
|
||||||
do {
|
WIZCHIP_CRITICAL_ENTER();
|
||||||
val1 = WIZCHIP_READ(Sn_RX_RSR(sn));
|
WIZCHIP.CS._select();
|
||||||
val1 = (val1 << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RSR(sn), 1));
|
|
||||||
if (val1 != 0) {
|
AddrSel |= (_W5500_SPI_WRITE_ | _W5500_SPI_VDM_OP_);
|
||||||
val = WIZCHIP_READ(Sn_RX_RSR(sn));
|
|
||||||
val = (val << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RSR(sn), 1));
|
// if(!WIZCHIP.IF.SPI._read_burst || !WIZCHIP.IF.SPI._write_burst) // byte
|
||||||
|
// operation
|
||||||
|
if (!WIZCHIP.IF.SPI._write_burst) // byte operation
|
||||||
|
{
|
||||||
|
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16);
|
||||||
|
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8);
|
||||||
|
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0);
|
||||||
|
WIZCHIP.IF.SPI._write_byte(wb);
|
||||||
|
} else // burst operation
|
||||||
|
{
|
||||||
|
spi_data[0] = (AddrSel & 0x00FF0000) >> 16;
|
||||||
|
spi_data[1] = (AddrSel & 0x0000FF00) >> 8;
|
||||||
|
spi_data[2] = (AddrSel & 0x000000FF) >> 0;
|
||||||
|
spi_data[3] = wb;
|
||||||
|
WIZCHIP.IF.SPI._write_burst(spi_data, 4);
|
||||||
}
|
}
|
||||||
} while (val != val1);
|
|
||||||
return val;
|
WIZCHIP.CS._deselect();
|
||||||
|
WIZCHIP_CRITICAL_EXIT();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wiz_send_data(uint8_t sn, uint8_t *wizdata, uint16_t len) {
|
void WIZCHIP_READ_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len)
|
||||||
uint16_t ptr = 0;
|
{
|
||||||
uint32_t addrsel = 0;
|
uint8_t spi_data[3];
|
||||||
|
uint16_t i;
|
||||||
|
|
||||||
if (len == 0)
|
WIZCHIP_CRITICAL_ENTER();
|
||||||
return;
|
WIZCHIP.CS._select();
|
||||||
ptr = getSn_TX_WR(sn);
|
|
||||||
// M20140501 : implict type casting -> explict type casting
|
|
||||||
// addrsel = (ptr << 8) + (WIZCHIP_TXBUF_BLOCK(sn) << 3);
|
|
||||||
addrsel = ((uint32_t)ptr << 8) + (WIZCHIP_TXBUF_BLOCK(sn) << 3);
|
|
||||||
//
|
|
||||||
WIZCHIP_WRITE_BUF(addrsel, wizdata, len);
|
|
||||||
|
|
||||||
ptr += len;
|
AddrSel |= (_W5500_SPI_READ_ | _W5500_SPI_VDM_OP_);
|
||||||
setSn_TX_WR(sn, ptr);
|
|
||||||
|
if (!WIZCHIP.IF.SPI._read_burst || !WIZCHIP.IF.SPI._write_burst) // byte operation
|
||||||
|
{
|
||||||
|
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16);
|
||||||
|
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8);
|
||||||
|
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0);
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
pBuf[i] = WIZCHIP.IF.SPI._read_byte();
|
||||||
|
} else // burst operation
|
||||||
|
{
|
||||||
|
spi_data[0] = (AddrSel & 0x00FF0000) >> 16;
|
||||||
|
spi_data[1] = (AddrSel & 0x0000FF00) >> 8;
|
||||||
|
spi_data[2] = (AddrSel & 0x000000FF) >> 0;
|
||||||
|
WIZCHIP.IF.SPI._write_burst(spi_data, 3);
|
||||||
|
WIZCHIP.IF.SPI._read_burst(pBuf, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
WIZCHIP.CS._deselect();
|
||||||
|
WIZCHIP_CRITICAL_EXIT();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wiz_recv_data(uint8_t sn, uint8_t *wizdata, uint16_t len) {
|
void WIZCHIP_WRITE_BUF(uint32_t AddrSel, uint8_t* pBuf, uint16_t len)
|
||||||
uint16_t ptr = 0;
|
{
|
||||||
uint32_t addrsel = 0;
|
uint8_t spi_data[3];
|
||||||
|
uint16_t i;
|
||||||
|
|
||||||
if (len == 0)
|
WIZCHIP_CRITICAL_ENTER();
|
||||||
return;
|
WIZCHIP.CS._select();
|
||||||
ptr = getSn_RX_RD(sn);
|
|
||||||
// M20140501 : implict type casting -> explict type casting
|
|
||||||
// addrsel = ((ptr << 8) + (WIZCHIP_RXBUF_BLOCK(sn) << 3);
|
|
||||||
addrsel = ((uint32_t)ptr << 8) + (WIZCHIP_RXBUF_BLOCK(sn) << 3);
|
|
||||||
//
|
|
||||||
WIZCHIP_READ_BUF(addrsel, wizdata, len);
|
|
||||||
ptr += len;
|
|
||||||
|
|
||||||
setSn_RX_RD(sn, ptr);
|
AddrSel |= (_W5500_SPI_WRITE_ | _W5500_SPI_VDM_OP_);
|
||||||
|
|
||||||
|
if (!WIZCHIP.IF.SPI._write_burst) // byte operation
|
||||||
|
{
|
||||||
|
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x00FF0000) >> 16);
|
||||||
|
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x0000FF00) >> 8);
|
||||||
|
WIZCHIP.IF.SPI._write_byte((AddrSel & 0x000000FF) >> 0);
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
WIZCHIP.IF.SPI._write_byte(pBuf[i]);
|
||||||
|
} else // burst operation
|
||||||
|
{
|
||||||
|
spi_data[0] = (AddrSel & 0x00FF0000) >> 16;
|
||||||
|
spi_data[1] = (AddrSel & 0x0000FF00) >> 8;
|
||||||
|
spi_data[2] = (AddrSel & 0x000000FF) >> 0;
|
||||||
|
WIZCHIP.IF.SPI._write_burst(spi_data, 3);
|
||||||
|
WIZCHIP.IF.SPI._write_burst(pBuf, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
WIZCHIP.CS._deselect();
|
||||||
|
WIZCHIP_CRITICAL_EXIT();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wiz_recv_ignore(uint8_t sn, uint16_t len) {
|
uint16_t getSn_TX_FSR(uint8_t sn)
|
||||||
uint16_t ptr = 0;
|
{
|
||||||
|
uint16_t val = 0, val1 = 0;
|
||||||
|
|
||||||
ptr = getSn_RX_RD(sn);
|
do {
|
||||||
ptr += len;
|
val1 = WIZCHIP_READ(Sn_TX_FSR(sn));
|
||||||
setSn_RX_RD(sn, ptr);
|
val1 = (val1 << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_FSR(sn), 1));
|
||||||
|
if (val1 != 0) {
|
||||||
|
val = WIZCHIP_READ(Sn_TX_FSR(sn));
|
||||||
|
val = (val << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_TX_FSR(sn), 1));
|
||||||
|
}
|
||||||
|
} while (val != val1);
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t getSn_RX_RSR(uint8_t sn)
|
||||||
|
{
|
||||||
|
uint16_t val = 0, val1 = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
val1 = WIZCHIP_READ(Sn_RX_RSR(sn));
|
||||||
|
val1 = (val1 << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RSR(sn), 1));
|
||||||
|
if (val1 != 0) {
|
||||||
|
val = WIZCHIP_READ(Sn_RX_RSR(sn));
|
||||||
|
val = (val << 8) + WIZCHIP_READ(WIZCHIP_OFFSET_INC(Sn_RX_RSR(sn), 1));
|
||||||
|
}
|
||||||
|
} while (val != val1);
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wiz_send_data(uint8_t sn, uint8_t* wizdata, uint16_t len)
|
||||||
|
{
|
||||||
|
uint16_t ptr = 0;
|
||||||
|
uint32_t addrsel = 0;
|
||||||
|
|
||||||
|
if (len == 0)
|
||||||
|
return;
|
||||||
|
ptr = getSn_TX_WR(sn);
|
||||||
|
// M20140501 : implict type casting -> explict type casting
|
||||||
|
// addrsel = (ptr << 8) + (WIZCHIP_TXBUF_BLOCK(sn) << 3);
|
||||||
|
addrsel = ((uint32_t)ptr << 8) + (WIZCHIP_TXBUF_BLOCK(sn) << 3);
|
||||||
|
//
|
||||||
|
WIZCHIP_WRITE_BUF(addrsel, wizdata, len);
|
||||||
|
|
||||||
|
ptr += len;
|
||||||
|
setSn_TX_WR(sn, ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wiz_recv_data(uint8_t sn, uint8_t* wizdata, uint16_t len)
|
||||||
|
{
|
||||||
|
uint16_t ptr = 0;
|
||||||
|
uint32_t addrsel = 0;
|
||||||
|
|
||||||
|
if (len == 0)
|
||||||
|
return;
|
||||||
|
ptr = getSn_RX_RD(sn);
|
||||||
|
// M20140501 : implict type casting -> explict type casting
|
||||||
|
// addrsel = ((ptr << 8) + (WIZCHIP_RXBUF_BLOCK(sn) << 3);
|
||||||
|
addrsel = ((uint32_t)ptr << 8) + (WIZCHIP_RXBUF_BLOCK(sn) << 3);
|
||||||
|
//
|
||||||
|
WIZCHIP_READ_BUF(addrsel, wizdata, len);
|
||||||
|
ptr += len;
|
||||||
|
|
||||||
|
setSn_RX_RD(sn, ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wiz_recv_ignore(uint8_t sn, uint16_t len)
|
||||||
|
{
|
||||||
|
uint16_t ptr = 0;
|
||||||
|
|
||||||
|
ptr = getSn_RX_RD(sn);
|
||||||
|
ptr += len;
|
||||||
|
setSn_RX_RD(sn, ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -0,0 +1,248 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2022 WIZnet Co.,Ltd
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ----------------------------------------------------------------------------------------------------
|
||||||
|
* Includes
|
||||||
|
* ----------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "connect_ethernet.h"
|
||||||
|
|
||||||
|
#include "socket.h"
|
||||||
|
|
||||||
|
#include "netif/etharp.h"
|
||||||
|
#include <sys.h>
|
||||||
|
|
||||||
|
#include <xs_kdbg.h>
|
||||||
|
|
||||||
|
#include <xizi.h>
|
||||||
|
/**
|
||||||
|
* ----------------------------------------------------------------------------------------------------
|
||||||
|
* Macros
|
||||||
|
* ----------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ----------------------------------------------------------------------------------------------------
|
||||||
|
* Variables
|
||||||
|
* ----------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
uint8_t wiz_mac[6] = { 0x00, 0x08, 0xDC, 0x12, 0x34, 0x56 };
|
||||||
|
|
||||||
|
static const uint32_t ethernet_polynomial_le = 0xedb88320U;
|
||||||
|
|
||||||
|
static sys_mutex_t wiz_trans_mtx;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ----------------------------------------------------------------------------------------------------
|
||||||
|
* Functions
|
||||||
|
* ----------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
void* ethernetif_config_enet_set(uint8_t enet_port)
|
||||||
|
{
|
||||||
|
return NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Time_Update_LwIP(void)
|
||||||
|
{
|
||||||
|
// no need to do
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void spi_if_clr(void)
|
||||||
|
{
|
||||||
|
setSn_IR(0, 0x1F);
|
||||||
|
setSIR(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// macraw func
|
||||||
|
uint16_t macraw_send(const uint8_t* buf, uint16_t len)
|
||||||
|
{
|
||||||
|
uint8_t sock_num = 0;
|
||||||
|
uint16_t ret = 0;
|
||||||
|
|
||||||
|
if (len > getSn_TxMAX(sock_num)) {
|
||||||
|
ret = getSn_TxMAX(sock_num);
|
||||||
|
} else {
|
||||||
|
ret = len;
|
||||||
|
}
|
||||||
|
|
||||||
|
wiz_send_data(sock_num, (uint8_t*)buf, len);
|
||||||
|
|
||||||
|
WIZCHIP_WRITE(Sn_CR(sock_num), Sn_CR_SEND);
|
||||||
|
while (WIZCHIP_READ(Sn_CR(sock_num))) {
|
||||||
|
}
|
||||||
|
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)))
|
||||||
|
;
|
||||||
|
|
||||||
|
return data_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
void netif_link_callback(struct netif* netif)
|
||||||
|
{
|
||||||
|
printf("netif link status changed %s\n", netif_is_link_up(netif) ? "up" : "down");
|
||||||
|
}
|
||||||
|
|
||||||
|
void netif_status_callback(struct netif* netif)
|
||||||
|
{
|
||||||
|
printf("netif status changed %s\n", ip4addr_ntoa(netif_ip4_addr(netif)));
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t wiz_transmit_pbuf(struct pbuf* p)
|
||||||
|
{
|
||||||
|
static uint8_t addr[4] = { 0xFF, 0xFF, 0xFF, 0xFF };
|
||||||
|
int32_t send_ret = 0;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
spi_if_clr();
|
||||||
|
if ((send_ret = wiz_sock_sendto(0, (uint8_t*)p->payload, p->len, addr, 0)) <= 0) {
|
||||||
|
SYS_KDEBUG_LOG(WIZNET_DEBUG, ("[%s] data send failed: %d, sock: %x\n", __func__, send_ret, getSn_SR(0)));
|
||||||
|
return -ERROR;
|
||||||
|
}
|
||||||
|
if (p->len == p->tot_len) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
p = p->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct pbuf* wiz_read_receive_pbuf(struct pbuf* buf)
|
||||||
|
{
|
||||||
|
#define RX_FRAME_SIZE 1542
|
||||||
|
static uint8_t rx_frame[RX_FRAME_SIZE];
|
||||||
|
static uint8_t addr[4] = { 0xFF, 0xFF, 0xFF, 0xFF };
|
||||||
|
uint16_t port = 0;
|
||||||
|
|
||||||
|
uint16_t lowlevel_len = getSn_RX_RSR(0);
|
||||||
|
if (lowlevel_len <= 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t data_len = wiz_sock_recvfrom(0, rx_frame, RX_FRAME_SIZE, addr, &port);
|
||||||
|
if (data_len > 0 && data_len <= RX_FRAME_SIZE) {
|
||||||
|
buf = pbuf_alloc(PBUF_RAW, data_len, PBUF_POOL);
|
||||||
|
if (buf == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
memcpy(buf->payload, rx_frame, data_len);
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ethernetif_input(void* netif_arg)
|
||||||
|
{
|
||||||
|
struct netif* netif = (struct netif*)netif_arg;
|
||||||
|
struct pbuf* p = NULL;
|
||||||
|
for (;;) {
|
||||||
|
sys_arch_sem_wait(get_eth_recv_sem(), WAITING_FOREVER);
|
||||||
|
while (1) {
|
||||||
|
sys_mutex_lock(&wiz_trans_mtx);
|
||||||
|
|
||||||
|
spi_if_clr();
|
||||||
|
p = NULL;
|
||||||
|
p = wiz_read_receive_pbuf(p);
|
||||||
|
|
||||||
|
sys_mutex_unlock(&wiz_trans_mtx);
|
||||||
|
|
||||||
|
if (p != NULL) {
|
||||||
|
// 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)) {
|
||||||
|
pbuf_free(p);
|
||||||
|
}
|
||||||
|
p = NULL;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static err_t spi_if_linkoutput(struct netif* netif, struct pbuf* p)
|
||||||
|
{
|
||||||
|
sys_mutex_lock(&wiz_trans_mtx);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO: Set up result value */
|
||||||
|
return ERR_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
err_t netif_initialize(struct netif* netif)
|
||||||
|
{
|
||||||
|
sys_mutex_new(&wiz_trans_mtx);
|
||||||
|
|
||||||
|
netif->linkoutput = spi_if_linkoutput;
|
||||||
|
// netif->linkoutput = netif_output;
|
||||||
|
netif->output = etharp_output;
|
||||||
|
netif->mtu = ETHERNET_MTU;
|
||||||
|
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET | NETIF_FLAG_IGMP | NETIF_FLAG_MLD6;
|
||||||
|
netif->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;
|
||||||
|
SMEMCPY(netif->hwaddr, wiz_mac, sizeof(netif->hwaddr));
|
||||||
|
netif->hwaddr_len = sizeof(netif->hwaddr);
|
||||||
|
netif->name[0] = 'e';
|
||||||
|
netif->name[1] = '0';
|
||||||
|
return ERR_OK;
|
||||||
|
}
|
|
@ -304,7 +304,7 @@ __exit:
|
||||||
if (recv_data) free(recv_data);
|
if (recv_data) free(recv_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void iperf_usage(void)
|
static void iperf_usage(void)
|
||||||
{
|
{
|
||||||
KPrintf("Usage: iperf [-s|-c host] [options] [multi-threaded]\n");
|
KPrintf("Usage: iperf [-s|-c host] [options] [multi-threaded]\n");
|
||||||
KPrintf(" iperf [-h|--stop]\n");
|
KPrintf(" iperf [-h|--stop]\n");
|
||||||
|
@ -326,7 +326,7 @@ void iperf_usage(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int iperf(int argc, char **argv)
|
int wiz_iperf(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int mode = 0; /* server mode */
|
int mode = 0; /* server mode */
|
||||||
char *host = NULL;
|
char *host = NULL;
|
||||||
|
@ -460,6 +460,6 @@ __usage:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
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),
|
||||||
iperf, iperf,
|
wiz_iperf, wiz_iperf,
|
||||||
iperf throughput test);
|
iperf throughput test);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -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,41 +32,43 @@ 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 {
|
{
|
||||||
int i;
|
union {
|
||||||
char c;
|
int i;
|
||||||
} u = {1};
|
char c;
|
||||||
return u.c ? bswap_16(n) : n;
|
} u = { 1 };
|
||||||
|
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;
|
{
|
||||||
uint32_t lsum;
|
uint16_t sum, tsum, i, j;
|
||||||
|
uint32_t lsum;
|
||||||
|
|
||||||
j = len >> 1;
|
j = len >> 1;
|
||||||
lsum = 0;
|
lsum = 0;
|
||||||
|
|
||||||
for (i = 0; i < j; i++) {
|
for (i = 0; i < j; i++) {
|
||||||
tsum = src[i * 2];
|
tsum = src[i * 2];
|
||||||
tsum = tsum << 8;
|
tsum = tsum << 8;
|
||||||
tsum += src[i * 2 + 1];
|
tsum += src[i * 2 + 1];
|
||||||
lsum += tsum;
|
lsum += tsum;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len % 2) {
|
if (len % 2) {
|
||||||
tsum = src[i * 2];
|
tsum = src[i * 2];
|
||||||
lsum += (tsum << 8);
|
lsum += (tsum << 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
sum = lsum;
|
sum = lsum;
|
||||||
sum = ~(sum + (lsum >> 16));
|
sum = ~(sum + (lsum >> 16));
|
||||||
return (uint16_t)sum;
|
return (uint16_t)sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,64 +78,64 @@ 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次*/
|
||||||
{
|
|
||||||
switch (getSn_SR(sn)) /*获取socket状态*/
|
|
||||||
{
|
{
|
||||||
case SOCK_CLOSED: /*socket关闭状态*/
|
switch (getSn_SR(sn)) /*获取socket状态*/
|
||||||
{
|
|
||||||
wiz_sock_close(sn);
|
|
||||||
/* Create Socket */
|
|
||||||
IINCHIP_WRITE(Sn_PROTO(sn), IPPROTO_ICMP); /*设置ICMP 协议*/
|
|
||||||
if (wiz_socket(sn, Sn_MR_IPRAW, PING_BIND_PORT, 0) !=
|
|
||||||
0) /*判断ip raw模式socket是否开启*/
|
|
||||||
{
|
{
|
||||||
}
|
case SOCK_CLOSED: /*socket关闭状态*/
|
||||||
/* Check socket register */
|
{
|
||||||
while (getSn_SR(sn) != SOCK_IPRAW) {
|
wiz_sock_close(sn);
|
||||||
MdelayKTask(50);
|
/* Create Socket */
|
||||||
};
|
IINCHIP_WRITE(Sn_PROTO(sn), IPPROTO_ICMP); /*设置ICMP 协议*/
|
||||||
break;
|
if (wiz_socket(sn, Sn_MR_IPRAW, PING_BIND_PORT, 0) != 0) /*判断ip raw模式socket是否开启*/
|
||||||
}
|
{
|
||||||
case SOCK_IPRAW: /*ip raw模式*/
|
|
||||||
{
|
|
||||||
cnt = 0;
|
|
||||||
ping_request(sn, addr); /*发送Ping请求*/
|
|
||||||
ping_req++;
|
|
||||||
while (1) {
|
|
||||||
if ((rlen = getSn_RX_RSR(sn)) > 0) {
|
|
||||||
rlen = ping_reply(sn, addr, rlen); /*获取回复信息*/
|
|
||||||
ping_rep++;
|
|
||||||
if (ping_reply_received) {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
/* Check socket register */
|
||||||
if ((cnt > 300)) {
|
while (getSn_SR(sn) != SOCK_IPRAW) {
|
||||||
cnt = 0;
|
MdelayKTask(50);
|
||||||
|
};
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
cnt++;
|
|
||||||
MdelayKTask(10);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
case SOCK_IPRAW: /*ip raw模式*/
|
||||||
}
|
{
|
||||||
default:
|
cnt = 0;
|
||||||
break;
|
ping_request(sn, addr); /*发送Ping请求*/
|
||||||
|
ping_req++;
|
||||||
|
while (1) {
|
||||||
|
if ((rlen = getSn_RX_RSR(sn)) > 0) {
|
||||||
|
rlen = ping_reply(sn, addr, rlen); /*获取回复信息*/
|
||||||
|
ping_rep++;
|
||||||
|
if (ping_reply_received) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((cnt > 300)) {
|
||||||
|
cnt = 0;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
cnt++;
|
||||||
|
MdelayKTask(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (ping_req >= pCount) {
|
||||||
|
wiz_sock_close(sn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (ping_req >= pCount) {
|
return ping_rep;
|
||||||
wiz_sock_close(sn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ping_rep;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -142,31 +144,30 @@ 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;
|
{
|
||||||
uint16_t i, temp_len = 0;
|
uint8_t* buffer;
|
||||||
ping_reply_received = 0; /*ping 回复初始化标志位*/
|
|
||||||
PingRequest.Type = PING_REQUEST; /*Ping-Request*/
|
|
||||||
PingRequest.Code = CODE_ZERO; /*总是 '0'*/
|
|
||||||
PingRequest.ID = htons(ping_RandomID++); /*设置ping响应ID为随机的整型变量*/
|
|
||||||
PingRequest.SeqNum =
|
|
||||||
htons(ping_RandomSeqNum++); /*设置ping响应的序列号为随机整形变量*/
|
|
||||||
for (i = 0; i < PING_BUF_LEN; i++) {
|
|
||||||
PingRequest.Data[i] = (i) % 8; /*ping相应的数在'0'~'8‘*/
|
|
||||||
}
|
|
||||||
PingRequest.CheckSum = 0;
|
|
||||||
/* 计算响应次数*/
|
|
||||||
PingRequest.CheckSum =
|
|
||||||
htons(checksum((uint8_t *)&PingRequest, sizeof(PingRequest)));
|
|
||||||
|
|
||||||
/*发送ping响应到目的方 */
|
uint16_t i, temp_len = 0;
|
||||||
if (wiz_sock_sendto(sn, (uint8_t *)&PingRequest, sizeof(PingRequest), addr,
|
ping_reply_received = 0; /*ping 回复初始化标志位*/
|
||||||
PING_BIND_PORT) == 0) {
|
PingRequest.Type = PING_REQUEST; /*Ping-Request*/
|
||||||
KPrintf("Fail to send ping-reply packet\r\n");
|
PingRequest.Code = CODE_ZERO; /*总是 '0'*/
|
||||||
} else {
|
PingRequest.ID = htons(ping_RandomID++); /*设置ping响应ID为随机的整型变量*/
|
||||||
KPrintf("ping send\n");
|
PingRequest.SeqNum = htons(ping_RandomSeqNum++); /*设置ping响应的序列号为随机整形变量*/
|
||||||
}
|
for (i = 0; i < PING_BUF_LEN; i++) {
|
||||||
return 0;
|
PingRequest.Data[i] = (i) % 8; /*ping相应的数在'0'~'8‘*/
|
||||||
|
}
|
||||||
|
PingRequest.CheckSum = 0;
|
||||||
|
/* 计算响应次数*/
|
||||||
|
PingRequest.CheckSum = htons(checksum((uint8_t*)&PingRequest, sizeof(PingRequest)));
|
||||||
|
|
||||||
|
/*发送ping响应到目的方 */
|
||||||
|
if (wiz_sock_sendto(sn, (uint8_t*)&PingRequest, sizeof(PingRequest), addr, PING_BIND_PORT) == 0) {
|
||||||
|
KPrintf("Fail to send ping-reply packet\r\n");
|
||||||
|
} else {
|
||||||
|
KPrintf("ping send\n");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -175,82 +176,84 @@ 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 len;
|
uint16_t tmp_checksum;
|
||||||
uint16_t i;
|
uint16_t len;
|
||||||
|
uint16_t i;
|
||||||
|
|
||||||
uint16_t port = PING_BIND_PORT;
|
uint16_t port = PING_BIND_PORT;
|
||||||
PINGMSGR PingReply;
|
PINGMSGR PingReply;
|
||||||
|
|
||||||
memset(ping_rep_buf, 0, sizeof(ping_rep_buf));
|
memset(ping_rep_buf, 0, sizeof(ping_rep_buf));
|
||||||
len = wiz_sock_recvfrom(sn, ping_rep_buf, rlen, addr,
|
len = wiz_sock_recvfrom(sn, ping_rep_buf, rlen, addr,
|
||||||
&port); /*从目的端接收数据*/
|
&port); /*从目的端接收数据*/
|
||||||
|
|
||||||
if (ping_rep_buf[0] == PING_REPLY) {
|
if (ping_rep_buf[0] == PING_REPLY) {
|
||||||
PingReply.Type = ping_rep_buf[0];
|
PingReply.Type = ping_rep_buf[0];
|
||||||
PingReply.Code = ping_rep_buf[1];
|
PingReply.Code = ping_rep_buf[1];
|
||||||
PingReply.CheckSum = (ping_rep_buf[3] << 8) + ping_rep_buf[2];
|
PingReply.CheckSum = (ping_rep_buf[3] << 8) + ping_rep_buf[2];
|
||||||
PingReply.ID = (ping_rep_buf[5] << 8) + ping_rep_buf[4];
|
PingReply.ID = (ping_rep_buf[5] << 8) + ping_rep_buf[4];
|
||||||
PingReply.SeqNum = (ping_rep_buf[7] << 8) + ping_rep_buf[6];
|
PingReply.SeqNum = (ping_rep_buf[7] << 8) + ping_rep_buf[6];
|
||||||
|
|
||||||
for (i = 0; i < len - 8; i++) {
|
for (i = 0; i < len - 8; i++) {
|
||||||
PingReply.Data[i] = ping_rep_buf[8 + i];
|
PingReply.Data[i] = ping_rep_buf[8 + i];
|
||||||
}
|
}
|
||||||
tmp_checksum = ~checksum(ping_rep_buf, len); /*检查ping回复的次数*/
|
tmp_checksum = ~checksum(ping_rep_buf, len); /*检查ping回复的次数*/
|
||||||
if (tmp_checksum != 0xffff) {
|
if (tmp_checksum != 0xffff) {
|
||||||
KPrintf("tmp_checksum = %x\r\n", tmp_checksum);
|
KPrintf("tmp_checksum = %x\r\n", tmp_checksum);
|
||||||
|
} else {
|
||||||
|
KPrintf("Reply from %3d.%3d.%3d.%3d ID=%x Byte=%d\r\n\r\n", (addr[0]),
|
||||||
|
(addr[1]), (addr[2]), (addr[3]), htons(PingReply.ID), (rlen + 6));
|
||||||
|
ping_reply_received = 1; /*当退出ping回复循环时,设置ping回复标志为1*/
|
||||||
|
}
|
||||||
|
} else if (ping_rep_buf[0] == PING_REQUEST) {
|
||||||
|
PingReply.Code = ping_rep_buf[1];
|
||||||
|
PingReply.Type = ping_rep_buf[2];
|
||||||
|
PingReply.CheckSum = (ping_rep_buf[3] << 8) + ping_rep_buf[2];
|
||||||
|
PingReply.ID = (ping_rep_buf[5] << 8) + ping_rep_buf[4];
|
||||||
|
PingReply.SeqNum = (ping_rep_buf[7] << 8) + ping_rep_buf[6];
|
||||||
|
for (i = 0; i < len - 8; i++) {
|
||||||
|
PingReply.Data[i] = ping_rep_buf[8 + i];
|
||||||
|
}
|
||||||
|
tmp_checksum = PingReply.CheckSum; /*检查ping回复次数*/
|
||||||
|
PingReply.CheckSum = 0;
|
||||||
|
if (tmp_checksum != PingReply.CheckSum) {
|
||||||
|
KPrintf(" \n CheckSum is in correct %x shold be %x \n", (tmp_checksum),
|
||||||
|
htons(PingReply.CheckSum));
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
KPrintf(
|
||||||
|
" Request from %d.%d.%d.%d ID:%x SeqNum:%x :data size %d bytes\r\n",
|
||||||
|
(addr[0]), (addr[1]), (addr[2]), (addr[3]), (PingReply.ID),
|
||||||
|
(PingReply.SeqNum), (rlen + 6));
|
||||||
|
ping_reply_received = 1; /* 当退出ping回复循环时,设置ping回复标志为1
|
||||||
|
*/
|
||||||
} else {
|
} else {
|
||||||
KPrintf("Reply from %3d.%3d.%3d.%3d ID=%x Byte=%d\r\n\r\n", (addr[0]),
|
KPrintf(" Unkonwn msg. \n");
|
||||||
(addr[1]), (addr[2]), (addr[3]), htons(PingReply.ID), (rlen + 6));
|
|
||||||
ping_reply_received = 1; /*当退出ping回复循环时,设置ping回复标志为1*/
|
|
||||||
}
|
}
|
||||||
} else if (ping_rep_buf[0] == PING_REQUEST) {
|
return 0;
|
||||||
PingReply.Code = ping_rep_buf[1];
|
|
||||||
PingReply.Type = ping_rep_buf[2];
|
|
||||||
PingReply.CheckSum = (ping_rep_buf[3] << 8) + ping_rep_buf[2];
|
|
||||||
PingReply.ID = (ping_rep_buf[5] << 8) + ping_rep_buf[4];
|
|
||||||
PingReply.SeqNum = (ping_rep_buf[7] << 8) + ping_rep_buf[6];
|
|
||||||
for (i = 0; i < len - 8; i++) {
|
|
||||||
PingReply.Data[i] = ping_rep_buf[8 + i];
|
|
||||||
}
|
|
||||||
tmp_checksum = PingReply.CheckSum; /*检查ping回复次数*/
|
|
||||||
PingReply.CheckSum = 0;
|
|
||||||
if (tmp_checksum != PingReply.CheckSum) {
|
|
||||||
KPrintf(" \n CheckSum is in correct %x shold be %x \n", (tmp_checksum),
|
|
||||||
htons(PingReply.CheckSum));
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
KPrintf(
|
|
||||||
" Request from %d.%d.%d.%d ID:%x SeqNum:%x :data size %d bytes\r\n",
|
|
||||||
(addr[0]), (addr[1]), (addr[2]), (addr[3]), (PingReply.ID),
|
|
||||||
(PingReply.SeqNum), (rlen + 6));
|
|
||||||
ping_reply_received = 1; /* 当退出ping回复循环时,设置ping回复标志为1
|
|
||||||
*/
|
|
||||||
} else {
|
|
||||||
KPrintf(" Unkonwn msg. \n");
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wiz_ping_test(int argc, char *argv[]) {
|
void wiz_ping_test(int argc, char* argv[])
|
||||||
uint32_t tmp_ip[4];
|
{
|
||||||
uint8_t target_ip[4];
|
uint32_t tmp_ip[4];
|
||||||
uint16_t pCount = 5; //默认ping 5次
|
uint8_t target_ip[4];
|
||||||
|
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]);
|
||||||
sscanf(argv[1], "%d.%d.%d.%d", &tmp_ip[0], &tmp_ip[1], &tmp_ip[2],
|
sscanf(argv[1], "%d.%d.%d.%d", &tmp_ip[0], &tmp_ip[1], &tmp_ip[2],
|
||||||
&tmp_ip[3]);
|
&tmp_ip[3]);
|
||||||
target_ip[0] = (uint8_t)tmp_ip[0];
|
target_ip[0] = (uint8_t)tmp_ip[0];
|
||||||
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);
|
|
@ -0,0 +1,118 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2022 WIZnet Co.,Ltd
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _W5x00_LWIP_H_
|
||||||
|
#define _W5x00_LWIP_H_
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ----------------------------------------------------------------------------------------------------
|
||||||
|
* Includes
|
||||||
|
* ----------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
#include "lwip/netif.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ----------------------------------------------------------------------------------------------------
|
||||||
|
* Macros
|
||||||
|
* ----------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
/* LWIP */
|
||||||
|
#define ETHERNET_MTU 1500
|
||||||
|
#define SOCKET_MACRAW 0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ----------------------------------------------------------------------------------------------------
|
||||||
|
* Variables
|
||||||
|
* ----------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ----------------------------------------------------------------------------------------------------
|
||||||
|
* Functions
|
||||||
|
* ----------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
/*! \brief send an ethernet packet
|
||||||
|
* \ingroup w5x00_lwip
|
||||||
|
*
|
||||||
|
* It is used to send outgoing data to the socket.
|
||||||
|
*
|
||||||
|
* \param sn socket number
|
||||||
|
* \param buf a pointer to the data to send
|
||||||
|
* \param len the length of data in packet
|
||||||
|
* \return he sent data size
|
||||||
|
*/
|
||||||
|
int32_t send_lwip(uint8_t sn, uint8_t* buf, uint16_t len);
|
||||||
|
|
||||||
|
/*! \brief read an ethernet packet
|
||||||
|
* \ingroup w5x00_lwip
|
||||||
|
*
|
||||||
|
* It is used to read incoming data from the socket.
|
||||||
|
*
|
||||||
|
* \param sn socket number
|
||||||
|
* \param buf a pointer buffer to read incoming data
|
||||||
|
* \param len the length of the data in the packet
|
||||||
|
* \return the real received data size
|
||||||
|
*/
|
||||||
|
int32_t recv_lwip(uint8_t sn, uint8_t* buf, uint16_t len);
|
||||||
|
|
||||||
|
/*! \brief callback function
|
||||||
|
* \ingroup w5x00_lwip
|
||||||
|
*
|
||||||
|
* This function is called by ethernet_output() when it wants
|
||||||
|
* to send a packet on the interface. This function outputs
|
||||||
|
* the pbuf as-is on the link medium.
|
||||||
|
*
|
||||||
|
* \param netif a pre-allocated netif structure
|
||||||
|
* \param p main packet buffer struct
|
||||||
|
* \return ERR_OK if data was sent.
|
||||||
|
*/
|
||||||
|
err_t netif_output(struct netif* netif, struct pbuf* p);
|
||||||
|
|
||||||
|
/*! \brief callback function
|
||||||
|
* \ingroup w5x00_lwip
|
||||||
|
*
|
||||||
|
* Callback function for link.
|
||||||
|
*
|
||||||
|
* \param netif a pre-allocated netif structure
|
||||||
|
*/
|
||||||
|
void netif_link_callback(struct netif* netif);
|
||||||
|
|
||||||
|
/*! \brief callback function
|
||||||
|
* \ingroup w5x00_lwip
|
||||||
|
*
|
||||||
|
* Callback function for status.
|
||||||
|
*
|
||||||
|
* \param netif a pre-allocated netif structure
|
||||||
|
*/
|
||||||
|
void netif_status_callback(struct netif* netif);
|
||||||
|
|
||||||
|
/*! \brief callback function
|
||||||
|
* \ingroup w5x00_lwip
|
||||||
|
*
|
||||||
|
* Callback function that initializes the interface.
|
||||||
|
*
|
||||||
|
* \param netif a pre-allocated netif structure
|
||||||
|
* \return ERR_OK if Network interface initialized
|
||||||
|
*/
|
||||||
|
err_t netif_initialize(struct netif* netif);
|
||||||
|
|
||||||
|
/*! \brief ethernet frame cyclic redundancy check
|
||||||
|
* \ingroup w5x00_lwip
|
||||||
|
*
|
||||||
|
* Perform cyclic redundancy check on ethernet frame
|
||||||
|
*
|
||||||
|
* \param data a pointer to the ethernet frame
|
||||||
|
* \param length the total length of ethernet frame
|
||||||
|
* \return an ethernet frame cyclic redundancy check result value
|
||||||
|
*/
|
||||||
|
static uint32_t ethernet_frame_crc(const uint8_t* data, int length);
|
||||||
|
|
||||||
|
void ethernetif_input(void* netif_arg);
|
||||||
|
void* ethernetif_config_enet_set(uint8_t enet_port);
|
||||||
|
void Time_Update_LwIP(void);
|
||||||
|
#define NETIF_ENET0_INIT_FUNC netif_initialize
|
||||||
|
|
||||||
|
#endif /* _W5x00_LWIP_H_ */
|
|
@ -191,8 +191,8 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
spi_instance[device_master_id]->ser = 1U << dev_param->spi_slave_param->spi_cs_select_id;
|
spi_instance[device_master_id]->ser = 1U << dev_param->spi_slave_param->spi_cs_select_id;
|
||||||
|
@ -202,9 +202,9 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spi_datacfg->spi_cs_release) {
|
if (spi_datacfg->spi_cs_release) {
|
||||||
|
|
|
@ -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,6 +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 0
|
||||||
|
|
||||||
#define SYS_KDEBUG_LOG(section, information) \
|
#define SYS_KDEBUG_LOG(section, information) \
|
||||||
do { \
|
do { \
|
||||||
|
|
|
@ -61,6 +61,9 @@ enum SmallSizeAllocSize {
|
||||||
#define SMALL_SIZE_32B(ITEMSIZE) ((ITEMSIZE + SIZEOF_DYNAMICALLOCNODE_MEM) * SMALL_NUMBER_32B) /* Calculate the total size for SIZEOF_32B blocks*/
|
#define SMALL_SIZE_32B(ITEMSIZE) ((ITEMSIZE + SIZEOF_DYNAMICALLOCNODE_MEM) * SMALL_NUMBER_32B) /* Calculate the total size for SIZEOF_32B blocks*/
|
||||||
#define SMALL_SIZE_64B(ITEMSIZE) ((ITEMSIZE + SIZEOF_DYNAMICALLOCNODE_MEM) * SMALL_NUMBER_64B) /* Calculate the total size for SIZEOF_64B blocks*/
|
#define SMALL_SIZE_64B(ITEMSIZE) ((ITEMSIZE + SIZEOF_DYNAMICALLOCNODE_MEM) * SMALL_NUMBER_64B) /* Calculate the total size for SIZEOF_64B blocks*/
|
||||||
|
|
||||||
|
#define FREE_LIST_LOCK() DISABLE_INTERRUPT()
|
||||||
|
#define FREE_LIST_UNLOCK(lock) ENABLE_INTERRUPT(lock)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The structure describes an allocated memory block from dynamic buddy memory.
|
* The structure describes an allocated memory block from dynamic buddy memory.
|
||||||
*/
|
*/
|
||||||
|
@ -632,66 +635,65 @@ void *x_malloc(x_size_t size)
|
||||||
register x_base lock = 0;
|
register x_base lock = 0;
|
||||||
|
|
||||||
/* hold lock before allocation */
|
/* hold lock before allocation */
|
||||||
lock = CriticalAreaLock();
|
lock = FREE_LIST_LOCK();
|
||||||
|
|
||||||
/* alignment */
|
/* alignment */
|
||||||
size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
|
size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
|
||||||
|
|
||||||
/* parameter detection */
|
/* parameter detection */
|
||||||
#ifdef MEM_EXTERN_SRAM
|
#ifdef MEM_EXTERN_SRAM
|
||||||
/* parameter detection */
|
/* parameter detection */
|
||||||
if(size == 0 ){
|
if (size == 0) {
|
||||||
CriticalAreaUnLock(lock);
|
FREE_LIST_UNLOCK(lock);
|
||||||
return NONE;
|
return NONE;
|
||||||
}
|
}
|
||||||
if((size > ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start - ByteManager.dynamic_buddy_manager.active_memory)){
|
if ((size > ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start - ByteManager.dynamic_buddy_manager.active_memory)) {
|
||||||
/* alignment */
|
/* alignment */
|
||||||
size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
|
size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
|
||||||
goto try_extmem;
|
goto try_extmem;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
/* parameter detection */
|
/* parameter detection */
|
||||||
if((size == 0) || (size > ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start - ByteManager.dynamic_buddy_manager.active_memory)) {
|
if ((size == 0) || (size > ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start - ByteManager.dynamic_buddy_manager.active_memory)) {
|
||||||
CriticalAreaUnLock(lock);
|
FREE_LIST_UNLOCK(lock);
|
||||||
return NONE;
|
return NONE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* determine allocation operation from static segments or dynamic buddy memory */
|
/* determine allocation operation from static segments or dynamic buddy memory */
|
||||||
#ifdef KERNEL_SMALL_MEM_ALLOC
|
#ifdef KERNEL_SMALL_MEM_ALLOC
|
||||||
if(size <= SIZEOF_32B) {
|
if (size <= SIZEOF_32B) {
|
||||||
ret = ByteManager.static_manager[0].done->malloc(&ByteManager, SIZEOF_32B);
|
ret = ByteManager.static_manager[0].done->malloc(&ByteManager, SIZEOF_32B);
|
||||||
} else if (size <= SIZEOF_64B) {
|
} else if (size <= SIZEOF_64B) {
|
||||||
ret = ByteManager.static_manager[1].done->malloc(&ByteManager, SIZEOF_64B);
|
ret = ByteManager.static_manager[1].done->malloc(&ByteManager, SIZEOF_64B);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (ret == NONE) {
|
if (ret == NONE) {
|
||||||
ret = ByteManager.dynamic_buddy_manager.done->malloc(&ByteManager.dynamic_buddy_manager, size, DYNAMIC_BLOCK_NO_EXTMEM_MASK);
|
ret = ByteManager.dynamic_buddy_manager.done->malloc(&ByteManager.dynamic_buddy_manager, size, DYNAMIC_BLOCK_NO_EXTMEM_MASK);
|
||||||
if (ret != NONE) {
|
if (ret != NONE) {
|
||||||
CHECK(ByteManager.dynamic_buddy_manager.done->JudgeLegal(&ByteManager.dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
|
CHECK(ByteManager.dynamic_buddy_manager.done->JudgeLegal(&ByteManager.dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MEM_EXTERN_SRAM
|
#ifdef MEM_EXTERN_SRAM
|
||||||
try_extmem:
|
try_extmem:
|
||||||
if(NONE == ret) {
|
if (NONE == ret) {
|
||||||
for(i = 0; i < EXTSRAM_MAX_NUM; i++) {
|
for (i = 0; i < EXTSRAM_MAX_NUM; i++) {
|
||||||
if(NONE != ExtByteManager[i].done) {
|
if (NONE != ExtByteManager[i].done) {
|
||||||
ret = ExtByteManager[i].dynamic_buddy_manager.done->malloc(&ExtByteManager[i].dynamic_buddy_manager, size, DYNAMIC_BLOCK_EXTMEMn_MASK(i + 1));
|
ret = ExtByteManager[i].dynamic_buddy_manager.done->malloc(&ExtByteManager[i].dynamic_buddy_manager, size, DYNAMIC_BLOCK_EXTMEMn_MASK(i + 1));
|
||||||
if (ret){
|
if (ret) {
|
||||||
CHECK(ExtByteManager[i].dynamic_buddy_manager.done->JudgeLegal(&ExtByteManager[i].dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
|
CHECK(ExtByteManager[i].dynamic_buddy_manager.done->JudgeLegal(&ExtByteManager[i].dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* release lock */
|
/* release lock */
|
||||||
CriticalAreaUnLock(lock);
|
FREE_LIST_UNLOCK(lock);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -702,49 +704,49 @@ try_extmem:
|
||||||
*
|
*
|
||||||
* @return pointer on success; NULL on failure
|
* @return pointer on success; NULL on failure
|
||||||
*/
|
*/
|
||||||
void *x_realloc(void *pointer, x_size_t size)
|
void* x_realloc(void* pointer, x_size_t size)
|
||||||
{
|
{
|
||||||
x_size_t newsize = 0;
|
x_size_t newsize = 0;
|
||||||
x_size_t oldsize = 0;
|
x_size_t oldsize = 0;
|
||||||
void *newmem = NONE;
|
void* newmem = NONE;
|
||||||
struct DynamicAllocNode *oldnode = NONE;
|
struct DynamicAllocNode* oldnode = NONE;
|
||||||
|
|
||||||
/* the given pointer is NULL */
|
/* the given pointer is NULL */
|
||||||
if (pointer == NONE)
|
if (pointer == NONE)
|
||||||
return x_malloc(size);
|
return x_malloc(size);
|
||||||
|
|
||||||
/* parameter detection */
|
/* parameter detection */
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
x_free(pointer);
|
x_free(pointer);
|
||||||
return NONE;
|
return NONE;
|
||||||
}
|
}
|
||||||
CHECK(ByteManager.dynamic_buddy_manager.done->JudgeLegal(&ByteManager.dynamic_buddy_manager,pointer));
|
CHECK(ByteManager.dynamic_buddy_manager.done->JudgeLegal(&ByteManager.dynamic_buddy_manager, pointer));
|
||||||
|
|
||||||
/* alignment and calculate the real size */
|
/* alignment and calculate the real size */
|
||||||
newsize = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
|
newsize = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
|
||||||
newsize += SIZEOF_DYNAMICALLOCNODE_MEM;
|
newsize += SIZEOF_DYNAMICALLOCNODE_MEM;
|
||||||
|
|
||||||
oldnode= PTR2ALLOCNODE((char*)pointer - SIZEOF_DYNAMICALLOCNODE_MEM);
|
oldnode = PTR2ALLOCNODE((char*)pointer - SIZEOF_DYNAMICALLOCNODE_MEM);
|
||||||
CHECK(ByteManager.done->JudgeAllocated(oldnode));
|
CHECK(ByteManager.done->JudgeAllocated(oldnode));
|
||||||
|
|
||||||
/* achieve the old memory size */
|
/* achieve the old memory size */
|
||||||
if(ByteManager.done->JudgeStaticOrDynamic(oldnode)) {
|
if (ByteManager.done->JudgeStaticOrDynamic(oldnode)) {
|
||||||
oldsize = ((struct segment*)(long)(oldnode->size))->block_size;
|
oldsize = ((struct segment*)(long)(oldnode->size))->block_size;
|
||||||
} else {
|
} else {
|
||||||
oldsize = oldnode->size - SIZEOF_DYNAMICALLOCNODE_MEM;
|
oldsize = oldnode->size - SIZEOF_DYNAMICALLOCNODE_MEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allocate new memory */
|
/* allocate new memory */
|
||||||
newmem = x_malloc(size);
|
newmem = x_malloc(size);
|
||||||
if(newmem == NONE) {
|
if (newmem == NONE) {
|
||||||
return NONE;
|
return NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* copy the old memory and then release old memory pointer */
|
/* copy the old memory and then release old memory pointer */
|
||||||
memcpy((char*)newmem, (char*) pointer,size > oldsize ? oldsize : size);
|
memcpy((char*)newmem, (char*)pointer, size > oldsize ? oldsize : size);
|
||||||
x_free(pointer);
|
x_free(pointer);
|
||||||
|
|
||||||
return newmem;
|
return newmem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -755,22 +757,22 @@ void *x_realloc(void *pointer, x_size_t size)
|
||||||
*
|
*
|
||||||
* @return pointer on success; NULL on failure
|
* @return pointer on success; NULL on failure
|
||||||
*/
|
*/
|
||||||
void *x_calloc(x_size_t count, x_size_t size)
|
void* x_calloc(x_size_t count, x_size_t size)
|
||||||
{
|
{
|
||||||
void *p = NONE;
|
void* p = NONE;
|
||||||
|
|
||||||
/* parameter detection */
|
/* parameter detection */
|
||||||
if(count * size > ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start - ByteManager.dynamic_buddy_manager.active_memory)
|
if (count * size > ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start - ByteManager.dynamic_buddy_manager.active_memory)
|
||||||
return NONE;
|
return NONE;
|
||||||
|
|
||||||
/* calls x_malloc to allocate count * size memory */
|
/* calls x_malloc to allocate count * size memory */
|
||||||
p = x_malloc(count * size);
|
p = x_malloc(count * size);
|
||||||
|
|
||||||
/* zero the memory */
|
/* zero the memory */
|
||||||
if (p)
|
if (p)
|
||||||
memset((char*)p, 0, count * size);
|
memset((char*)p, 0, count * size);
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -778,52 +780,52 @@ void *x_calloc(x_size_t count, x_size_t size)
|
||||||
*
|
*
|
||||||
* @param pointer the memory to be released
|
* @param pointer the memory to be released
|
||||||
*/
|
*/
|
||||||
void x_free(void *pointer)
|
void x_free(void* pointer)
|
||||||
{
|
{
|
||||||
x_base lock = 0;
|
x_base lock = 0;
|
||||||
struct DynamicAllocNode *node = NONE;
|
struct DynamicAllocNode* node = NONE;
|
||||||
|
|
||||||
/* parameter detection */
|
/* parameter detection */
|
||||||
if (pointer == NONE) {
|
if (pointer == NONE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* hold lock before release */
|
/* hold lock before release */
|
||||||
lock = CriticalAreaLock();
|
lock = FREE_LIST_LOCK();
|
||||||
|
|
||||||
if (!ByteManager.dynamic_buddy_manager.done->JudgeLegal(&ByteManager.dynamic_buddy_manager, pointer)) {
|
if (!ByteManager.dynamic_buddy_manager.done->JudgeLegal(&ByteManager.dynamic_buddy_manager, pointer)) {
|
||||||
CriticalAreaUnLock(lock);
|
FREE_LIST_UNLOCK(lock);
|
||||||
SYS_ERR("[%s] Freeing a unallocated address.\n", __func__);
|
SYS_ERR("[%s] Freeing a unallocated address.\n", __func__);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
node = PTR2ALLOCNODE((char*)pointer - SIZEOF_DYNAMICALLOCNODE_MEM);
|
node = PTR2ALLOCNODE((char*)pointer - SIZEOF_DYNAMICALLOCNODE_MEM);
|
||||||
CHECK(ByteManager.done->JudgeAllocated(node));
|
CHECK(ByteManager.done->JudgeAllocated(node));
|
||||||
|
|
||||||
/* judge release the memory block ro static_segment or dynamic buddy memory */
|
/* judge release the memory block ro static_segment or dynamic buddy memory */
|
||||||
#ifdef KERNEL_SMALL_MEM_ALLOC
|
#ifdef KERNEL_SMALL_MEM_ALLOC
|
||||||
if(node->flag & STATIC_BLOCK_MASK) {
|
if (node->flag & STATIC_BLOCK_MASK) {
|
||||||
ByteManager.static_manager->done->release(pointer);
|
ByteManager.static_manager->done->release(pointer);
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#ifdef MEM_EXTERN_SRAM
|
#ifdef MEM_EXTERN_SRAM
|
||||||
/* judge the pointer is not malloced from extern memory*/
|
/* judge the pointer is not malloced from extern memory*/
|
||||||
if(0 == (node->flag & 0xFF0000)) {
|
if (0 == (node->flag & 0xFF0000)) {
|
||||||
ByteManager.dynamic_buddy_manager.done->release(&ByteManager,pointer);
|
ByteManager.dynamic_buddy_manager.done->release(&ByteManager, pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* judge the pointer is malloced from extern memory*/
|
/* judge the pointer is malloced from extern memory*/
|
||||||
if(0 != (node->flag & 0xFF0000)) {
|
if (0 != (node->flag & 0xFF0000)) {
|
||||||
ExtByteManager[((node->flag & 0xFF0000) >> 16) - 1].dynamic_buddy_manager.done->release(&ExtByteManager[((node->flag & 0xFF0000) >> 16) - 1],pointer);
|
ExtByteManager[((node->flag & 0xFF0000) >> 16) - 1].dynamic_buddy_manager.done->release(&ExtByteManager[((node->flag & 0xFF0000) >> 16) - 1], pointer);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
ByteManager.dynamic_buddy_manager.done->release(&ByteManager, pointer);
|
ByteManager.dynamic_buddy_manager.done->release(&ByteManager, pointer);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* release the lock */
|
/* release the lock */
|
||||||
CriticalAreaUnLock(lock);
|
FREE_LIST_UNLOCK(lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MEM_EXTERN_SRAM
|
#ifdef MEM_EXTERN_SRAM
|
||||||
|
@ -834,43 +836,42 @@ void x_free(void *pointer)
|
||||||
* @param end_phy_address the end physical address for static and dynamic memory
|
* @param end_phy_address the end physical address for static and dynamic memory
|
||||||
* @param extsram_idx the idx of extsram chip
|
* @param extsram_idx the idx of extsram chip
|
||||||
*/
|
*/
|
||||||
void ExtSramInitBoardMemory(void *start_phy_address, void *end_phy_address, uint8 extsram_idx)
|
void ExtSramInitBoardMemory(void* start_phy_address, void* end_phy_address, uint8 extsram_idx)
|
||||||
{
|
{
|
||||||
register x_size_t offset = 0;
|
register x_size_t offset = 0;
|
||||||
|
|
||||||
NULL_PARAM_CHECK(start_phy_address);
|
NULL_PARAM_CHECK(start_phy_address);
|
||||||
NULL_PARAM_CHECK(end_phy_address);
|
NULL_PARAM_CHECK(end_phy_address);
|
||||||
|
|
||||||
KDEBUG_NOT_IN_INTERRUPT;
|
KDEBUG_NOT_IN_INTERRUPT;
|
||||||
struct DynamicBuddyMemory *uheap = &ExtByteManager[extsram_idx].dynamic_buddy_manager;
|
struct DynamicBuddyMemory* uheap = &ExtByteManager[extsram_idx].dynamic_buddy_manager;
|
||||||
|
|
||||||
/* align begin and end addr to page */
|
/* align begin and end addr to page */
|
||||||
ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_start = ALIGN_MEN_UP((x_ubase)start_phy_address, MM_PAGE_SIZE);
|
ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_start = ALIGN_MEN_UP((x_ubase)start_phy_address, MM_PAGE_SIZE);
|
||||||
ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_end = ALIGN_MEN_DOWN((x_ubase)end_phy_address, MM_PAGE_SIZE);
|
ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_end = ALIGN_MEN_DOWN((x_ubase)end_phy_address, MM_PAGE_SIZE);
|
||||||
KPrintf("%s: 0x%x-0x%x extsram_idx = %d\n",__func__,ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_start,ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_end, extsram_idx);
|
KPrintf("%s: 0x%x-0x%x extsram_idx = %d\n", __func__, ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_start, ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_end, extsram_idx);
|
||||||
|
|
||||||
/* parameter detection */
|
/* parameter detection */
|
||||||
if (ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_start >= ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_end) {
|
if (ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_start >= ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_end) {
|
||||||
KPrintf("ExtSramInitBoardMemory, wrong address[0x%x - 0x%x]\n",
|
KPrintf("ExtSramInitBoardMemory, wrong address[0x%x - 0x%x]\n",
|
||||||
(x_ubase)start_phy_address, (x_ubase)end_phy_address);
|
(x_ubase)start_phy_address, (x_ubase)end_phy_address);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uheap->mm_total_size = 0;
|
uheap->mm_total_size = 0;
|
||||||
memset(uheap->mm_freenode_list, 0, SIZEOF_XSFREENODE_MEM * MEM_LINKNRS);
|
memset(uheap->mm_freenode_list, 0, SIZEOF_XSFREENODE_MEM * MEM_LINKNRS);
|
||||||
|
|
||||||
/* initialize the freeNodeList */
|
/* initialize the freeNodeList */
|
||||||
for (offset = 1; offset < MEM_LINKNRS; offset++) {
|
for (offset = 1; offset < MEM_LINKNRS; offset++) {
|
||||||
uheap->mm_freenode_list[offset - 1].next = &uheap->mm_freenode_list[offset];
|
uheap->mm_freenode_list[offset - 1].next = &uheap->mm_freenode_list[offset];
|
||||||
uheap->mm_freenode_list[offset].prev = &uheap->mm_freenode_list[offset - 1];
|
uheap->mm_freenode_list[offset].prev = &uheap->mm_freenode_list[offset - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
ExtByteManager[extsram_idx].dynamic_buddy_manager.done = &DynamicDone;
|
|
||||||
ExtByteManager[extsram_idx].done = &NodeDone;
|
|
||||||
|
|
||||||
|
ExtByteManager[extsram_idx].dynamic_buddy_manager.done = &DynamicDone;
|
||||||
|
ExtByteManager[extsram_idx].done = &NodeDone;
|
||||||
|
|
||||||
/* dynamic buddy memory initialization */
|
/* dynamic buddy memory initialization */
|
||||||
ExtByteManager[extsram_idx].dynamic_buddy_manager.done->init(&ExtByteManager[extsram_idx].dynamic_buddy_manager, ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_start, ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_end - ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_start);
|
ExtByteManager[extsram_idx].dynamic_buddy_manager.done->init(&ExtByteManager[extsram_idx].dynamic_buddy_manager, ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_start, ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_end - ExtByteManager[extsram_idx].dynamic_buddy_manager.dynamic_buddy_start);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -880,49 +881,48 @@ void ExtSramInitBoardMemory(void *start_phy_address, void *end_phy_address, uint
|
||||||
* @param start_phy_address the start physical address for static and dynamic memory
|
* @param start_phy_address the start physical address for static and dynamic memory
|
||||||
* @param end_phy_address the end physical address for static and dynamic memory
|
* @param end_phy_address the end physical address for static and dynamic memory
|
||||||
*/
|
*/
|
||||||
void InitBoardMemory(void *start_phy_address, void *end_phy_address)
|
void InitBoardMemory(void* start_phy_address, void* end_phy_address)
|
||||||
{
|
{
|
||||||
register x_size_t offset = 0;
|
register x_size_t offset = 0;
|
||||||
|
|
||||||
NULL_PARAM_CHECK(start_phy_address);
|
NULL_PARAM_CHECK(start_phy_address);
|
||||||
NULL_PARAM_CHECK(end_phy_address);
|
NULL_PARAM_CHECK(end_phy_address);
|
||||||
|
|
||||||
KDEBUG_NOT_IN_INTERRUPT;
|
KDEBUG_NOT_IN_INTERRUPT;
|
||||||
struct DynamicBuddyMemory *mheap = &ByteManager.dynamic_buddy_manager;
|
struct DynamicBuddyMemory* mheap = &ByteManager.dynamic_buddy_manager;
|
||||||
|
|
||||||
/* align begin and end addr to page */
|
/* align begin and end addr to page */
|
||||||
ByteManager.dynamic_buddy_manager.dynamic_buddy_start = ALIGN_MEN_UP((x_ubase)start_phy_address, MM_PAGE_SIZE);
|
ByteManager.dynamic_buddy_manager.dynamic_buddy_start = ALIGN_MEN_UP((x_ubase)start_phy_address, MM_PAGE_SIZE);
|
||||||
ByteManager.dynamic_buddy_manager.dynamic_buddy_end = ALIGN_MEN_DOWN((x_ubase)end_phy_address, MM_PAGE_SIZE);
|
ByteManager.dynamic_buddy_manager.dynamic_buddy_end = ALIGN_MEN_DOWN((x_ubase)end_phy_address, MM_PAGE_SIZE);
|
||||||
//KPrintf("%s: 0x%x-0x%x \n",__func__,ByteManager.dynamic_buddy_manager.dynamic_buddy_start,ByteManager.dynamic_buddy_manager.dynamic_buddy_end);
|
// KPrintf("%s: 0x%x-0x%x \n",__func__,ByteManager.dynamic_buddy_manager.dynamic_buddy_start,ByteManager.dynamic_buddy_manager.dynamic_buddy_end);
|
||||||
|
|
||||||
/* parameter detection */
|
/* parameter detection */
|
||||||
if (ByteManager.dynamic_buddy_manager.dynamic_buddy_start >= ByteManager.dynamic_buddy_manager.dynamic_buddy_end) {
|
if (ByteManager.dynamic_buddy_manager.dynamic_buddy_start >= ByteManager.dynamic_buddy_manager.dynamic_buddy_end) {
|
||||||
//KPrintf("InitBoardMemory, wrong address[0x%x - 0x%x]\n", (x_ubase)start_phy_address, (x_ubase)end_phy_address);
|
// KPrintf("InitBoardMemory, wrong address[0x%x - 0x%x]\n", (x_ubase)start_phy_address, (x_ubase)end_phy_address);
|
||||||
SYS_KDEBUG_LOG(KDBG_MEM, ("InitBoardMemory, wrong address[0x%x - 0x%x]\n", (x_ubase)start_phy_address, (x_ubase)end_phy_address));
|
SYS_KDEBUG_LOG(KDBG_MEM, ("InitBoardMemory, wrong address[0x%x - 0x%x]\n", (x_ubase)start_phy_address, (x_ubase)end_phy_address));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mheap->mm_total_size = 0;
|
mheap->mm_total_size = 0;
|
||||||
memset(mheap->mm_freenode_list, 0, SIZEOF_XSFREENODE_MEM * MEM_LINKNRS);
|
memset(mheap->mm_freenode_list, 0, SIZEOF_XSFREENODE_MEM * MEM_LINKNRS);
|
||||||
|
|
||||||
/* initialize the freeNodeList */
|
/* initialize the freeNodeList */
|
||||||
for (offset = 1; offset < MEM_LINKNRS; offset++) {
|
for (offset = 1; offset < MEM_LINKNRS; offset++) {
|
||||||
mheap->mm_freenode_list[offset - 1].next = &mheap->mm_freenode_list[offset];
|
mheap->mm_freenode_list[offset - 1].next = &mheap->mm_freenode_list[offset];
|
||||||
mheap->mm_freenode_list[offset].prev = &mheap->mm_freenode_list[offset - 1];
|
mheap->mm_freenode_list[offset].prev = &mheap->mm_freenode_list[offset - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteManager.dynamic_buddy_manager.done = &DynamicDone;
|
|
||||||
ByteManager.static_manager[MM_SEGMENT_32B].done = &StaticDone;
|
|
||||||
ByteManager.static_manager[MM_SEGMENT_64B].done = &StaticDone;
|
|
||||||
ByteManager.done = &NodeDone;
|
|
||||||
|
|
||||||
|
ByteManager.dynamic_buddy_manager.done = &DynamicDone;
|
||||||
|
ByteManager.static_manager[MM_SEGMENT_32B].done = &StaticDone;
|
||||||
|
ByteManager.static_manager[MM_SEGMENT_64B].done = &StaticDone;
|
||||||
|
ByteManager.done = &NodeDone;
|
||||||
|
|
||||||
/* dynamic buddy memory initialization */
|
/* dynamic buddy memory initialization */
|
||||||
ByteManager.dynamic_buddy_manager.done->init(&ByteManager.dynamic_buddy_manager, ByteManager.dynamic_buddy_manager.dynamic_buddy_start, ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start);
|
ByteManager.dynamic_buddy_manager.done->init(&ByteManager.dynamic_buddy_manager, ByteManager.dynamic_buddy_manager.dynamic_buddy_start, ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start);
|
||||||
|
|
||||||
/* dynamic static segments initialization */
|
/* dynamic static segments initialization */
|
||||||
#ifdef KERNEL_SMALL_MEM_ALLOC
|
#ifdef KERNEL_SMALL_MEM_ALLOC
|
||||||
ByteManager.static_manager->done->init(&ByteManager);
|
ByteManager.static_manager->done->init(&ByteManager);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -935,57 +935,55 @@ void InitBoardMemory(void *start_phy_address, void *end_phy_address)
|
||||||
*
|
*
|
||||||
* @return pointer on success; NULL on failure
|
* @return pointer on success; NULL on failure
|
||||||
*/
|
*/
|
||||||
void *x_umalloc(x_size_t size)
|
void* x_umalloc(x_size_t size)
|
||||||
{
|
{
|
||||||
uint8 i = 0;
|
uint8 i = 0;
|
||||||
void *ret = NONE;
|
void* ret = NONE;
|
||||||
register x_base lock = 0;
|
register x_base lock = 0;
|
||||||
|
|
||||||
|
|
||||||
#ifdef MEM_EXTERN_SRAM
|
#ifdef MEM_EXTERN_SRAM
|
||||||
/* parameter detection */
|
/* parameter detection */
|
||||||
if(size == 0 ){
|
if (size == 0) {
|
||||||
return NONE;
|
return NONE;
|
||||||
}
|
}
|
||||||
if((size > ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start - ByteManager.dynamic_buddy_manager.active_memory)){
|
if ((size > ByteManager.dynamic_buddy_manager.dynamic_buddy_end - ByteManager.dynamic_buddy_manager.dynamic_buddy_start - ByteManager.dynamic_buddy_manager.active_memory)) {
|
||||||
lock = CriticalAreaLock();
|
lock = FREE_LIST_LOCK();
|
||||||
/* alignment */
|
/* alignment */
|
||||||
size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
|
size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
|
||||||
goto try_extmem;
|
goto try_extmem;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
/* parameter detection */
|
/* parameter detection */
|
||||||
if((size == 0) || (size > UserByteManager.dynamic_buddy_manager.dynamic_buddy_end - UserByteManager.dynamic_buddy_manager.dynamic_buddy_start - UserByteManager.dynamic_buddy_manager.active_memory))
|
if ((size == 0) || (size > UserByteManager.dynamic_buddy_manager.dynamic_buddy_end - UserByteManager.dynamic_buddy_manager.dynamic_buddy_start - UserByteManager.dynamic_buddy_manager.active_memory))
|
||||||
return NONE;
|
return NONE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* hold lock before allocation */
|
/* hold lock before allocation */
|
||||||
lock = CriticalAreaLock();
|
lock = FREE_LIST_LOCK();
|
||||||
/* alignment */
|
/* alignment */
|
||||||
size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
|
size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
|
||||||
ret = UserByteManager.dynamic_buddy_manager.done->malloc(&UserByteManager.dynamic_buddy_manager,size,DYNAMIC_BLOCK_NO_EXTMEM_MASK);
|
ret = UserByteManager.dynamic_buddy_manager.done->malloc(&UserByteManager.dynamic_buddy_manager, size, DYNAMIC_BLOCK_NO_EXTMEM_MASK);
|
||||||
if(ret != NONE)
|
if (ret != NONE)
|
||||||
CHECK(UserByteManager.dynamic_buddy_manager.done->JudgeLegal(&UserByteManager.dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
|
CHECK(UserByteManager.dynamic_buddy_manager.done->JudgeLegal(&UserByteManager.dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
|
||||||
|
|
||||||
|
|
||||||
#ifdef MEM_EXTERN_SRAM
|
#ifdef MEM_EXTERN_SRAM
|
||||||
try_extmem:
|
try_extmem:
|
||||||
if(NONE == ret) {
|
if (NONE == ret) {
|
||||||
for(i = 0; i < EXTSRAM_MAX_NUM; i++) {
|
for (i = 0; i < EXTSRAM_MAX_NUM; i++) {
|
||||||
if(NONE != ExtByteManager[i].done) {
|
if (NONE != ExtByteManager[i].done) {
|
||||||
ret = ExtByteManager[i].dynamic_buddy_manager.done->malloc(&ExtByteManager[i].dynamic_buddy_manager, size, DYNAMIC_BLOCK_EXTMEMn_MASK(i + 1));
|
ret = ExtByteManager[i].dynamic_buddy_manager.done->malloc(&ExtByteManager[i].dynamic_buddy_manager, size, DYNAMIC_BLOCK_EXTMEMn_MASK(i + 1));
|
||||||
if (ret) {
|
if (ret) {
|
||||||
CHECK(ExtByteManager[i].dynamic_buddy_manager.done->JudgeLegal(&ExtByteManager[i].dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
|
CHECK(ExtByteManager[i].dynamic_buddy_manager.done->JudgeLegal(&ExtByteManager[i].dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* release lock */
|
/* release lock */
|
||||||
CriticalAreaUnLock(lock);
|
FREE_LIST_UNLOCK(lock);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -996,49 +994,49 @@ try_extmem:
|
||||||
*
|
*
|
||||||
* @return pointer on success; NULL on failure
|
* @return pointer on success; NULL on failure
|
||||||
*/
|
*/
|
||||||
void *x_urealloc(void *pointer, x_size_t size)
|
void* x_urealloc(void* pointer, x_size_t size)
|
||||||
{
|
{
|
||||||
x_size_t newsize = 0;
|
x_size_t newsize = 0;
|
||||||
x_size_t oldsize = 0;
|
x_size_t oldsize = 0;
|
||||||
void *newmem = NONE;
|
void* newmem = NONE;
|
||||||
struct DynamicAllocNode *oldnode = NONE;
|
struct DynamicAllocNode* oldnode = NONE;
|
||||||
|
|
||||||
/* the given pointer is NULL */
|
/* the given pointer is NULL */
|
||||||
if (pointer == NONE)
|
if (pointer == NONE)
|
||||||
return x_umalloc(size);
|
return x_umalloc(size);
|
||||||
|
|
||||||
/* parameter detection */
|
/* parameter detection */
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
x_ufree(pointer);
|
x_ufree(pointer);
|
||||||
return NONE;
|
return NONE;
|
||||||
}
|
}
|
||||||
CHECK(UserByteManager.dynamic_buddy_manager.done->JudgeLegal(&UserByteManager.dynamic_buddy_manager,pointer));
|
CHECK(UserByteManager.dynamic_buddy_manager.done->JudgeLegal(&UserByteManager.dynamic_buddy_manager, pointer));
|
||||||
|
|
||||||
/* alignment and calculate the real size */
|
/* alignment and calculate the real size */
|
||||||
newsize = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
|
newsize = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
|
||||||
newsize += SIZEOF_DYNAMICALLOCNODE_MEM;
|
newsize += SIZEOF_DYNAMICALLOCNODE_MEM;
|
||||||
|
|
||||||
oldnode= PTR2ALLOCNODE((char*)pointer - SIZEOF_DYNAMICALLOCNODE_MEM);
|
oldnode = PTR2ALLOCNODE((char*)pointer - SIZEOF_DYNAMICALLOCNODE_MEM);
|
||||||
CHECK(UserByteManager.done->JudgeAllocated(oldnode));
|
CHECK(UserByteManager.done->JudgeAllocated(oldnode));
|
||||||
|
|
||||||
/* achieve the old memory size */
|
/* achieve the old memory size */
|
||||||
if(UserByteManager.done->JudgeStaticOrDynamic(oldnode)) {
|
if (UserByteManager.done->JudgeStaticOrDynamic(oldnode)) {
|
||||||
oldsize = ((struct segment*)(oldnode->size))->block_size;
|
oldsize = ((struct segment*)(oldnode->size))->block_size;
|
||||||
} else {
|
} else {
|
||||||
oldsize = oldnode->size - SIZEOF_DYNAMICALLOCNODE_MEM;
|
oldsize = oldnode->size - SIZEOF_DYNAMICALLOCNODE_MEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allocate new memory */
|
/* allocate new memory */
|
||||||
newmem = x_umalloc(size);
|
newmem = x_umalloc(size);
|
||||||
if(newmem == NONE) {
|
if (newmem == NONE) {
|
||||||
return NONE;
|
return NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* copy the old memory and then release old memory pointer */
|
/* copy the old memory and then release old memory pointer */
|
||||||
memcpy((char*)newmem, (char*) pointer,size > oldsize ? oldsize : size);
|
memcpy((char*)newmem, (char*)pointer, size > oldsize ? oldsize : size);
|
||||||
x_ufree(pointer);
|
x_ufree(pointer);
|
||||||
|
|
||||||
return newmem;
|
return newmem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1049,22 +1047,22 @@ void *x_urealloc(void *pointer, x_size_t size)
|
||||||
*
|
*
|
||||||
* @return pointer on success; NULL on failure
|
* @return pointer on success; NULL on failure
|
||||||
*/
|
*/
|
||||||
void *x_ucalloc(x_size_t count, x_size_t size)
|
void* x_ucalloc(x_size_t count, x_size_t size)
|
||||||
{
|
{
|
||||||
void *p = NONE;
|
void* p = NONE;
|
||||||
|
|
||||||
/* parameter detection */
|
/* parameter detection */
|
||||||
if(count * size > UserByteManager.dynamic_buddy_manager.dynamic_buddy_end - UserByteManager.dynamic_buddy_manager.dynamic_buddy_start - UserByteManager.dynamic_buddy_manager.active_memory)
|
if (count * size > UserByteManager.dynamic_buddy_manager.dynamic_buddy_end - UserByteManager.dynamic_buddy_manager.dynamic_buddy_start - UserByteManager.dynamic_buddy_manager.active_memory)
|
||||||
return NONE;
|
return NONE;
|
||||||
|
|
||||||
/* calls x_malloc to allocate count * size memory */
|
/* calls x_malloc to allocate count * size memory */
|
||||||
p = x_umalloc(count * size);
|
p = x_umalloc(count * size);
|
||||||
|
|
||||||
/* zero the memory */
|
/* zero the memory */
|
||||||
if (p)
|
if (p)
|
||||||
memset((char*)p, 0, count * size);
|
memset((char*)p, 0, count * size);
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1072,37 +1070,37 @@ void *x_ucalloc(x_size_t count, x_size_t size)
|
||||||
*
|
*
|
||||||
* @param pointer the memory to be released
|
* @param pointer the memory to be released
|
||||||
*/
|
*/
|
||||||
void x_ufree(void *pointer)
|
void x_ufree(void* pointer)
|
||||||
{
|
{
|
||||||
x_base lock = 0;
|
x_base lock = 0;
|
||||||
struct DynamicAllocNode *node = NONE;
|
struct DynamicAllocNode* node = NONE;
|
||||||
|
|
||||||
/* parameter detection */
|
/* parameter detection */
|
||||||
if (pointer == NONE)
|
if (pointer == NONE)
|
||||||
return ;
|
return;
|
||||||
CHECK(UserByteManager.dynamic_buddy_manager.done->JudgeLegal(&UserByteManager.dynamic_buddy_manager,pointer));
|
CHECK(UserByteManager.dynamic_buddy_manager.done->JudgeLegal(&UserByteManager.dynamic_buddy_manager, pointer));
|
||||||
|
|
||||||
/* hold lock before release */
|
/* hold lock before release */
|
||||||
lock = CriticalAreaLock();
|
lock = FREE_LIST_LOCK();
|
||||||
node = PTR2ALLOCNODE((char*)pointer-SIZEOF_DYNAMICALLOCNODE_MEM);
|
node = PTR2ALLOCNODE((char*)pointer - SIZEOF_DYNAMICALLOCNODE_MEM);
|
||||||
CHECK(UserByteManager.done->JudgeAllocated(node));
|
CHECK(UserByteManager.done->JudgeAllocated(node));
|
||||||
|
|
||||||
#ifdef MEM_EXTERN_SRAM
|
#ifdef MEM_EXTERN_SRAM
|
||||||
/* judge the pointer is not malloced from extern memory*/
|
/* judge the pointer is not malloced from extern memory*/
|
||||||
if(0 == (node->flag & 0xFF0000)) {
|
if (0 == (node->flag & 0xFF0000)) {
|
||||||
UserByteManager.dynamic_buddy_manager.done->release(&ByteManager,pointer);
|
UserByteManager.dynamic_buddy_manager.done->release(&ByteManager, pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* judge the pointer is malloced from extern memory*/
|
/* judge the pointer is malloced from extern memory*/
|
||||||
if(0 != (node->flag & 0xFF0000)) {
|
if (0 != (node->flag & 0xFF0000)) {
|
||||||
ExtByteManager[((node->flag & 0xFF0000) >> 16) - 1].dynamic_buddy_manager.done->release(&ExtByteManager[((node->flag & 0xFF0000) >> 16) - 1],pointer);
|
ExtByteManager[((node->flag & 0xFF0000) >> 16) - 1].dynamic_buddy_manager.done->release(&ExtByteManager[((node->flag & 0xFF0000) >> 16) - 1], pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
UserByteManager.dynamic_buddy_manager.done->release(&UserByteManager,pointer);
|
UserByteManager.dynamic_buddy_manager.done->release(&UserByteManager, pointer);
|
||||||
#endif
|
#endif
|
||||||
/* release the lock */
|
/* release the lock */
|
||||||
CriticalAreaUnLock(lock);
|
FREE_LIST_UNLOCK(lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1213,8 +1211,8 @@ void ShowBuddy(void)
|
||||||
int lock = 0;
|
int lock = 0;
|
||||||
struct DynamicFreeNode *debug = NONE;
|
struct DynamicFreeNode *debug = NONE;
|
||||||
|
|
||||||
lock = CriticalAreaLock();
|
lock = FREE_LIST_LOCK();
|
||||||
KPrintf("\n\033[41;1mlist memory information\033[0m\n", __func__);
|
KPrintf("\n\033[41;1mlist memory information\033[0m\n", __func__);
|
||||||
for(int level = 0; level < MEM_LINKNRS; level++) {
|
for(int level = 0; level < MEM_LINKNRS; level++) {
|
||||||
KPrintf("%s level [%d],memory size[2^%d] \n",__func__, level,level +6);
|
KPrintf("%s level [%d],memory size[2^%d] \n",__func__, level,level +6);
|
||||||
for (debug = &ByteManager.dynamic_buddy_manager.mm_freenode_list[level]; ; ) {
|
for (debug = &ByteManager.dynamic_buddy_manager.mm_freenode_list[level]; ; ) {
|
||||||
|
@ -1258,7 +1256,7 @@ void ShowBuddy(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
CriticalAreaUnLock(lock);
|
FREE_LIST_UNLOCK(lock);
|
||||||
}
|
}
|
||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),
|
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0),
|
||||||
ShowBuddy,ShowBuddy,list memory usage information);
|
ShowBuddy,ShowBuddy,list memory usage information);
|
||||||
|
|
|
@ -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,12 +175,12 @@ 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));
|
||||||
|
|
||||||
Assign.smp_assign_done->SwitchToNew(runningtask,new_task);
|
Assign.smp_assign_done->SwitchToNew(runningtask,new_task);
|
||||||
}
|
}
|
||||||
|
@ -442,12 +442,12 @@ 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));
|
||||||
|
|
||||||
Assign.smp_assign_done->SwitchToNew(runningtask,new_task);
|
Assign.smp_assign_done->SwitchToNew(runningtask,new_task);
|
||||||
|
|
||||||
|
|
|
@ -112,6 +112,21 @@ KERNELPATHS += \
|
||||||
-I$(BSP_ROOT)/third_party_driver/drivers \
|
-I$(BSP_ROOT)/third_party_driver/drivers \
|
||||||
-I$(BSP_ROOT)/third_party_driver/lcd \
|
-I$(BSP_ROOT)/third_party_driver/lcd \
|
||||||
-I$(KERNEL_ROOT)/include #
|
-I$(KERNEL_ROOT)/include #
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_RESOURCES_LWIP),y)
|
||||||
|
KERNELPATHS += \
|
||||||
|
-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include \
|
||||||
|
-I$(KERNEL_ROOT)/resources/ethernet/LwIP \
|
||||||
|
-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/compat \
|
||||||
|
-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip \
|
||||||
|
-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/netif \
|
||||||
|
-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/apps \
|
||||||
|
-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/priv \
|
||||||
|
-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/prot \
|
||||||
|
-I$(KERNEL_ROOT)/resources/ethernet/LwIP/arch
|
||||||
|
|
||||||
|
KERNELPATHS += -I$(KERNEL_ROOT)/resources/include/netdev
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(BSP_ROOT),$(KERNEL_ROOT)/board/kd233)
|
ifeq ($(BSP_ROOT),$(KERNEL_ROOT)/board/kd233)
|
||||||
|
|
|
@ -1,31 +1,31 @@
|
||||||
/**
|
/**
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @file lwipopts.h
|
* @file lwipopts.h
|
||||||
* @author MCD Application Team
|
* @author MCD Application Team
|
||||||
* @version V1.1.0
|
* @version V1.1.0
|
||||||
* @date 31-July-2013
|
* @date 31-July-2013
|
||||||
* @brief lwIP Options Configuration.
|
* @brief lwIP Options Configuration.
|
||||||
* This file is based on Utilities\lwip_v1.4.1\src\include\lwip\opt.h
|
* This file is based on Utilities\lwip_v1.4.1\src\include\lwip\opt.h
|
||||||
* and contains the lwIP configuration for the STM32F4x7 demonstration.
|
* and contains the lwIP configuration for the STM32F4x7 demonstration.
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @attention
|
* @attention
|
||||||
*
|
*
|
||||||
* <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
|
* <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2>
|
||||||
*
|
*
|
||||||
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
|
||||||
* You may not use this file except in compliance with the License.
|
* You may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at:
|
* You may obtain a copy of the License at:
|
||||||
*
|
*
|
||||||
* http://www.st.com/software_license_agreement_liberty_v2
|
* http://www.st.com/software_license_agreement_liberty_v2
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __LWIPOPTS_H__
|
#ifndef __LWIPOPTS_H__
|
||||||
#define __LWIPOPTS_H__
|
#define __LWIPOPTS_H__
|
||||||
|
@ -34,282 +34,298 @@
|
||||||
|
|
||||||
/* ---------- Debug options ---------- */
|
/* ---------- Debug options ---------- */
|
||||||
#ifndef LWIP_DEBUG
|
#ifndef LWIP_DEBUG
|
||||||
#define LWIP_DEBUG 1
|
#define LWIP_DEBUG 1
|
||||||
|
// #define LWIP_SOCKET_DEBUG
|
||||||
|
// #define LWIP_TCPIP_DEBUG
|
||||||
|
// #define LWIP_MEMP_DEBUG
|
||||||
|
// #define LWIP_PBUF_DEBUG
|
||||||
|
// #define LWIP_TCP_INPUT_DEBUG
|
||||||
|
// #define LWIP_TCP_OUTPUT_DEBUG
|
||||||
|
// #define LWIP_NETIF_DEBUG
|
||||||
|
// #define LWIP_ETHARP_DEBUG
|
||||||
|
// #define LWIP_API_MSG_DEBUG
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_DEBUG
|
#ifdef LWIP_DEBUG
|
||||||
#ifdef LWIP_SYS_DEBUG
|
#ifdef LWIP_SYS_DEBUG
|
||||||
#define SYS_DEBUG LWIP_DBG_ON
|
#define SYS_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define SYS_DEBUG LWIP_DBG_OFF
|
#define SYS_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_ETHARP_DEBUG
|
#ifdef LWIP_ETHARP_DEBUG
|
||||||
#define ETHARP_DEBUG LWIP_DBG_ON
|
#define ETHARP_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define ETHARP_DEBUG LWIP_DBG_OFF
|
#define ETHARP_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_PPP_DEBUG
|
#ifdef LWIP_PPP_DEBUG
|
||||||
#define PPP_DEBUG LWIP_DBG_ON
|
#define PPP_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define PPP_DEBUG LWIP_DBG_OFF
|
#define PPP_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_MEM_DEBUG
|
#ifdef LWIP_MEM_DEBUG
|
||||||
#define MEM_DEBUG LWIP_DBG_ON
|
#define MEM_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define MEM_DEBUG LWIP_DBG_OFF
|
#define MEM_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_MEMP_DEBUG
|
#ifdef LWIP_MEMP_DEBUG
|
||||||
#define MEMP_DEBUG LWIP_DBG_ON
|
#define MEMP_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define MEMP_DEBUG LWIP_DBG_OFF
|
#define MEMP_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_PBUF_DEBUG
|
#ifdef LWIP_PBUF_DEBUG
|
||||||
#define PBUF_DEBUG LWIP_DBG_ON
|
#define PBUF_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define PBUF_DEBUG LWIP_DBG_OFF
|
#define PBUF_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_API_LIB_DEBUG
|
#ifdef LWIP_API_LIB_DEBUG
|
||||||
#define API_LIB_DEBUG LWIP_DBG_ON
|
#define API_LIB_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define API_LIB_DEBUG LWIP_DBG_OFF
|
#define API_LIB_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_API_MSG_DEBUG
|
#ifdef LWIP_API_MSG_DEBUG
|
||||||
#define API_MSG_DEBUG LWIP_DBG_ON
|
#define API_MSG_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define API_MSG_DEBUG LWIP_DBG_OFF
|
#define API_MSG_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_TCPIP_DEBUG
|
#ifdef LWIP_TCPIP_DEBUG
|
||||||
#define TCPIP_DEBUG LWIP_DBG_ON
|
#define TCPIP_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define TCPIP_DEBUG LWIP_DBG_OFF
|
#define TCPIP_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_NETIF_DEBUG
|
#ifdef LWIP_NETIF_DEBUG
|
||||||
#define NETIF_DEBUG LWIP_DBG_ON
|
#define NETIF_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define NETIF_DEBUG LWIP_DBG_OFF
|
#define NETIF_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_SOCKETS_DEBUG
|
#ifdef LWIP_SOCKETS_DEBUG
|
||||||
#define SOCKETS_DEBUG LWIP_DBG_ON
|
#define SOCKETS_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define SOCKETS_DEBUG LWIP_DBG_OFF
|
#define SOCKETS_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_DNS_DEBUG
|
#ifdef LWIP_DNS_DEBUG
|
||||||
#define DNS_DEBUG LWIP_DBG_ON
|
#define DNS_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define DNS_DEBUG LWIP_DBG_OFF
|
#define DNS_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_AUTOIP_DEBUG
|
#ifdef LWIP_AUTOIP_DEBUG
|
||||||
#define AUTOIP_DEBUG LWIP_DBG_ON
|
#define AUTOIP_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define AUTOIP_DEBUG LWIP_DBG_OFF
|
#define AUTOIP_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_DHCP_DEBUG
|
#ifdef LWIP_DHCP_DEBUG
|
||||||
#define DHCP_DEBUG LWIP_DBG_ON
|
#define DHCP_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define DHCP_DEBUG LWIP_DBG_OFF
|
#define DHCP_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_IP_DEBUG
|
#ifdef LWIP_IP_DEBUG
|
||||||
#define IP_DEBUG LWIP_DBG_ON
|
#define IP_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define IP_DEBUG LWIP_DBG_OFF
|
#define IP_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_IP_REASS_DEBUG
|
#ifdef LWIP_IP_REASS_DEBUG
|
||||||
#define IP_REASS_DEBUG LWIP_DBG_ON
|
#define IP_REASS_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define IP_REASS_DEBUG LWIP_DBG_OFF
|
#define IP_REASS_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_ICMP_DEBUG
|
#ifdef LWIP_ICMP_DEBUG
|
||||||
#define ICMP_DEBUG LWIP_DBG_ON
|
#define ICMP_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define ICMP_DEBUG LWIP_DBG_OFF
|
#define ICMP_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_IGMP_DEBUG
|
#ifdef LWIP_IGMP_DEBUG
|
||||||
#define IGMP_DEBUG LWIP_DBG_ON
|
#define IGMP_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define IGMP_DEBUG LWIP_DBG_OFF
|
#define IGMP_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_UDP_DEBUG
|
#ifdef LWIP_UDP_DEBUG
|
||||||
#define UDP_DEBUG LWIP_DBG_ON
|
#define UDP_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define UDP_DEBUG LWIP_DBG_OFF
|
#define UDP_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_TCP_DEBUG
|
#ifdef LWIP_TCP_DEBUG
|
||||||
#define TCP_DEBUG LWIP_DBG_ON
|
#define TCP_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define TCP_DEBUG LWIP_DBG_OFF
|
#define TCP_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_TCP_INPUT_DEBUG
|
#ifdef LWIP_TCP_INPUT_DEBUG
|
||||||
#define TCP_INPUT_DEBUG LWIP_DBG_ON
|
#define TCP_INPUT_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define TCP_INPUT_DEBUG LWIP_DBG_OFF
|
#define TCP_INPUT_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_TCP_OUTPUT_DEBUG
|
#ifdef LWIP_TCP_OUTPUT_DEBUG
|
||||||
#define TCP_OUTPUT_DEBUG LWIP_DBG_ON
|
#define TCP_OUTPUT_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
|
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_TCP_RTO_DEBUG
|
#ifdef LWIP_TCP_RTO_DEBUG
|
||||||
#define TCP_RTO_DEBUG LWIP_DBG_ON
|
#define TCP_RTO_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define TCP_RTO_DEBUG LWIP_DBG_OFF
|
#define TCP_RTO_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_TCP_CWND_DEBUG
|
#ifdef LWIP_TCP_CWND_DEBUG
|
||||||
#define TCP_CWND_DEBUG LWIP_DBG_ON
|
#define TCP_CWND_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define TCP_CWND_DEBUG LWIP_DBG_OFF
|
#define TCP_CWND_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_TCP_WND_DEBUG
|
#ifdef LWIP_TCP_WND_DEBUG
|
||||||
#define TCP_WND_DEBUG LWIP_DBG_ON
|
#define TCP_WND_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define TCP_WND_DEBUG LWIP_DBG_OFF
|
#define TCP_WND_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_TCP_FR_DEBUG
|
#ifdef LWIP_TCP_FR_DEBUG
|
||||||
#define TCP_FR_DEBUG LWIP_DBG_ON
|
#define TCP_FR_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define TCP_FR_DEBUG LWIP_DBG_OFF
|
#define TCP_FR_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_TCP_QLEN_DEBUG
|
#ifdef LWIP_TCP_QLEN_DEBUG
|
||||||
#define TCP_QLEN_DEBUG LWIP_DBG_ON
|
#define TCP_QLEN_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define TCP_QLEN_DEBUG LWIP_DBG_OFF
|
#define TCP_QLEN_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef LWIP_TCP_RST_DEBUG
|
#ifdef LWIP_TCP_RST_DEBUG
|
||||||
#define TCP_RST_DEBUG LWIP_DBG_ON
|
#define TCP_RST_DEBUG LWIP_DBG_ON
|
||||||
#else
|
#else
|
||||||
#define TCP_RST_DEBUG LWIP_DBG_OFF
|
#define TCP_RST_DEBUG LWIP_DBG_OFF
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* LWIP_DEBUG */
|
#endif /* LWIP_DEBUG */
|
||||||
|
|
||||||
|
#define LWIP_TIMEVAL_PRIVATE 0
|
||||||
|
#define LWIP_NO_UNISTD_H 0
|
||||||
|
#define LWIP_NO_STDDEF_H 0
|
||||||
|
#define LWIP_NO_STDINT_H 0
|
||||||
|
#define LWIP_NO_INTTYPES_H 0
|
||||||
|
#define LWIP_NO_LIMITS_H 0
|
||||||
|
#define LWIP_NO_CTYPE_H 0
|
||||||
|
#define LWIP_SOCKET_SELECT 1
|
||||||
|
#define LWIP_SOCKET_POLL 1
|
||||||
|
|
||||||
#define LWIP_TIMEVAL_PRIVATE 0
|
#define LWIP_DHCP_DOES_ACD_CHECK 0
|
||||||
#define LWIP_NO_UNISTD_H 0
|
|
||||||
#define LWIP_NO_STDDEF_H 0
|
|
||||||
#define LWIP_NO_STDINT_H 0
|
|
||||||
#define LWIP_NO_INTTYPES_H 0
|
|
||||||
#define LWIP_NO_LIMITS_H 0
|
|
||||||
#define LWIP_NO_CTYPE_H 0
|
|
||||||
#define LWIP_SOCKET_SELECT 1
|
|
||||||
#define LWIP_SOCKET_POLL 1
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain
|
* SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain
|
||||||
* critical regions during buffer allocation, deallocation and memory
|
* critical regions during buffer allocation, deallocation and memory
|
||||||
* allocation and deallocation.
|
* allocation and deallocation.
|
||||||
*/
|
*/
|
||||||
#define SYS_LIGHTWEIGHT_PROT 1
|
#define SYS_LIGHTWEIGHT_PROT 1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NO_SYS==1: Provides VERY minimal functionality. Otherwise,
|
* NO_SYS==1: Provides VERY minimal functionality. Otherwise,
|
||||||
* use lwIP facilities.
|
* use lwIP facilities.
|
||||||
*/
|
*/
|
||||||
#define NO_SYS 0
|
#define NO_SYS 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NO_SYS_NO_TIMERS==1: Drop support for sys_timeout when NO_SYS==1
|
* NO_SYS_NO_TIMERS==1: Drop support for sys_timeout when NO_SYS==1
|
||||||
* Mainly for compatibility to old versions.
|
* Mainly for compatibility to old versions.
|
||||||
*/
|
*/
|
||||||
#define NO_SYS_NO_TIMERS 0
|
#define NO_SYS_NO_TIMERS 0
|
||||||
|
|
||||||
/* ---------- Memory options ---------- */
|
/* ---------- Memory options ---------- */
|
||||||
/* MEM_ALIGNMENT: should be set to the alignment of the CPU for which
|
/* MEM_ALIGNMENT: should be set to the alignment of the CPU for which
|
||||||
lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2
|
lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2
|
||||||
byte alignment -> define MEM_ALIGNMENT to 2. */
|
byte alignment -> define MEM_ALIGNMENT to 2. */
|
||||||
#define MEM_ALIGNMENT 4
|
#ifndef RISCV_LWIP
|
||||||
|
#define MEM_ALIGNMENT 4
|
||||||
|
#else
|
||||||
|
#define MEM_ALIGNMENT 8
|
||||||
|
#endif
|
||||||
|
|
||||||
/* 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
|
||||||
should be set high. */
|
should be set high. */
|
||||||
#define MEMP_NUM_PBUF 32
|
#define MEMP_NUM_PBUF 32
|
||||||
/* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One
|
/* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One
|
||||||
per active UDP "connection". */
|
per active UDP "connection". */
|
||||||
#define MEMP_NUM_UDP_PCB 4
|
#define MEMP_NUM_UDP_PCB 4
|
||||||
/* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP
|
/* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP
|
||||||
connections. */
|
connections. */
|
||||||
#define MEMP_NUM_TCP_PCB 64
|
#define MEMP_NUM_TCP_PCB 64
|
||||||
/* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP
|
/* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP
|
||||||
connections. */
|
connections. */
|
||||||
#define MEMP_NUM_TCP_PCB_LISTEN 2
|
#define MEMP_NUM_TCP_PCB_LISTEN 2
|
||||||
/* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP
|
/* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP
|
||||||
segments. */
|
segments. */
|
||||||
#define MEMP_NUM_TCP_SEG 256
|
#define MEMP_NUM_TCP_SEG 256
|
||||||
/* 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
|
||||||
#define ARP_TABLE_SIZE 10
|
#define ARP_TABLE_SIZE 10
|
||||||
#define ARP_QUEUEING 1
|
#define ARP_QUEUEING 1
|
||||||
|
|
||||||
/* ---------- TCP options ---------- */
|
/* ---------- TCP options ---------- */
|
||||||
#define LWIP_TCP 1
|
#define LWIP_TCP 1
|
||||||
#define TCP_TTL 255
|
#define TCP_TTL 255
|
||||||
|
|
||||||
/* Controls if TCP should queue segments that arrive out of
|
/* Controls if TCP should queue segments that arrive out of
|
||||||
order. Define to 0 if your device is low on memory. */
|
order. Define to 0 if your device is low on memory. */
|
||||||
#define TCP_QUEUE_OOSEQ 1
|
#define TCP_QUEUE_OOSEQ 0
|
||||||
|
|
||||||
/* TCP Maximum segment size. */
|
/* TCP Maximum segment size. */
|
||||||
#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
|
||||||
|
|
||||||
/* Maximum number of retransmissions of SYN segments. */
|
/* Maximum number of retransmissions of SYN segments. */
|
||||||
#define TCP_SYNMAXRTX 4
|
#define TCP_SYNMAXRTX 4
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LWIP_TCP_KEEPALIVE==1: Enable TCP_KEEPIDLE, TCP_KEEPINTVL and TCP_KEEPCNT
|
* LWIP_TCP_KEEPALIVE==1: Enable TCP_KEEPIDLE, TCP_KEEPINTVL and TCP_KEEPCNT
|
||||||
|
@ -317,21 +333,21 @@ a lot of data that needs to be copied, this should be set high. */
|
||||||
* in seconds. (does not require sockets.c, and will affect tcp.c)
|
* in seconds. (does not require sockets.c, and will affect tcp.c)
|
||||||
*/
|
*/
|
||||||
#ifndef LWIP_TCP_KEEPALIVE
|
#ifndef LWIP_TCP_KEEPALIVE
|
||||||
#define LWIP_TCP_KEEPALIVE 1
|
#define LWIP_TCP_KEEPALIVE 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LWIP_NETIF_HOSTNAME==1: Support netif hostname
|
* LWIP_NETIF_HOSTNAME==1: Support netif hostname
|
||||||
*/
|
*/
|
||||||
#ifndef LWIP_NETIF_HOSTNAME
|
#ifndef LWIP_NETIF_HOSTNAME
|
||||||
#define LWIP_NETIF_HOSTNAME 1
|
#define LWIP_NETIF_HOSTNAME 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LWIP_NETIF_API==1: Support netif api (in netifapi.c)
|
* LWIP_NETIF_API==1: Support netif api (in netifapi.c)
|
||||||
*/
|
*/
|
||||||
#ifndef LWIP_NETIF_API
|
#ifndef LWIP_NETIF_API
|
||||||
#define LWIP_NETIF_API 1
|
#define LWIP_NETIF_API 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -339,7 +355,7 @@ a lot of data that needs to be copied, this should be set high. */
|
||||||
* SO_SNDTIMEO processing.
|
* SO_SNDTIMEO processing.
|
||||||
*/
|
*/
|
||||||
#ifndef LWIP_SO_SNDTIMEO
|
#ifndef LWIP_SO_SNDTIMEO
|
||||||
#define LWIP_SO_SNDTIMEO 1
|
#define LWIP_SO_SNDTIMEO 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -347,47 +363,44 @@ a lot of data that needs to be copied, this should be set high. */
|
||||||
* SO_RCVTIMEO processing.
|
* SO_RCVTIMEO processing.
|
||||||
*/
|
*/
|
||||||
#ifndef LWIP_SO_RCVTIMEO
|
#ifndef LWIP_SO_RCVTIMEO
|
||||||
#define LWIP_SO_RCVTIMEO 1
|
#define LWIP_SO_RCVTIMEO 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LWIP_SO_RCVBUF==1: Enable SO_RCVBUF processing.
|
* LWIP_SO_RCVBUF==1: Enable SO_RCVBUF processing.
|
||||||
*/
|
*/
|
||||||
#ifndef LWIP_SO_RCVBUF
|
#ifndef LWIP_SO_RCVBUF
|
||||||
#define LWIP_SO_RCVBUF 1
|
#define LWIP_SO_RCVBUF 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If LWIP_SO_RCVBUF is used, this is the default value for recv_bufsize.
|
* If LWIP_SO_RCVBUF is used, this is the default value for recv_bufsize.
|
||||||
*/
|
*/
|
||||||
#ifndef RECV_BUFSIZE_DEFAULT
|
#ifndef RECV_BUFSIZE_DEFAULT
|
||||||
#define RECV_BUFSIZE_DEFAULT 8192
|
#define RECV_BUFSIZE_DEFAULT 8192
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* ---------- 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
|
||||||
|
|
||||||
/* ---------- link callback options ---------- */
|
/* ---------- link callback options ---------- */
|
||||||
/* LWIP_NETIF_LINK_CALLBACK==1: Support a callback function from an interface
|
/* LWIP_NETIF_LINK_CALLBACK==1: Support a callback function from an interface
|
||||||
* whenever the link changes (i.e., link down)
|
* whenever the link changes (i.e., link down)
|
||||||
*/
|
*/
|
||||||
#define LWIP_NETIF_LINK_CALLBACK 0
|
#define LWIP_NETIF_LINK_CALLBACK 0
|
||||||
/*
|
/*
|
||||||
--------------------------------------
|
--------------------------------------
|
||||||
---------- Checksum options ----------
|
---------- Checksum options ----------
|
||||||
|
@ -399,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 ----------
|
||||||
|
@ -442,7 +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)
|
||||||
*/
|
*/
|
||||||
#define LWIP_NETCONN 1
|
// #ifndef RISCV_LWIP
|
||||||
|
// #define LWIP_NETCONN 1
|
||||||
|
// #else
|
||||||
|
#define LWIP_NETCONN 1
|
||||||
|
// #endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
------------------------------------
|
------------------------------------
|
||||||
|
@ -452,76 +468,74 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
|
||||||
/**
|
/**
|
||||||
* LWIP_SOCKET==1: Enable Socket API (require to use sockets.c)
|
* LWIP_SOCKET==1: Enable Socket API (require to use sockets.c)
|
||||||
*/
|
*/
|
||||||
#define LWIP_SOCKET 1
|
#define LWIP_SOCKET 1
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LWIP_SO_RCVBUF==1: Enable SO_RCVBUF processing.
|
* LWIP_SO_RCVBUF==1: Enable SO_RCVBUF processing.
|
||||||
*/
|
*/
|
||||||
#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.
|
||||||
*/
|
*/
|
||||||
#ifndef LWIP_SO_SNDTIMEO
|
#ifndef LWIP_SO_SNDTIMEO
|
||||||
#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.
|
||||||
*/
|
*/
|
||||||
#ifndef LWIP_SO_RCVTIMEO
|
#ifndef LWIP_SO_RCVTIMEO
|
||||||
#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
|
||||||
|
|
||||||
/* ---------- IP options ---------- */
|
/* ---------- IP options ---------- */
|
||||||
/* Define IP_FORWARD to 1 if you wish to have the ability to forward
|
/* Define IP_FORWARD to 1 if you wish to have the ability to forward
|
||||||
IP packets across network interfaces. If you are going to run lwIP
|
IP packets across network interfaces. If you are going to run lwIP
|
||||||
on a device with only one network interface, define this to 0. */
|
on a device with only one network interface, define this to 0. */
|
||||||
#define IP_FORWARD 0
|
#define IP_FORWARD 0
|
||||||
|
|
||||||
/* IP reassembly and segmentation.These are orthogonal even
|
/* IP reassembly and segmentation.These are orthogonal even
|
||||||
* if they both deal with IP fragments */
|
* if they both deal with IP fragments */
|
||||||
#ifdef LWIP_REASSEMBLY_FRAG
|
#ifdef LWIP_REASSEMBLY_FRAG
|
||||||
#define IP_REASSEMBLY 1
|
#define IP_REASSEMBLY 1
|
||||||
#define IP_FRAG 1
|
#define IP_FRAG 1
|
||||||
#define IP_REASS_MAX_PBUFS 10
|
#define IP_REASS_MAX_PBUFS 10
|
||||||
#define MEMP_NUM_REASSDATA 10
|
#define MEMP_NUM_REASSDATA 10
|
||||||
#else
|
#else
|
||||||
#define IP_REASSEMBLY 0
|
#define IP_REASSEMBLY 0
|
||||||
#define IP_FRAG 0
|
#define IP_FRAG 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* ---------- ICMP options ---------- */
|
/* ---------- ICMP options ---------- */
|
||||||
#define ICMP_TTL 255
|
#define ICMP_TTL 255
|
||||||
|
|
||||||
/* ---------- 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. */
|
interfaces. */
|
||||||
#define LWIP_DHCP 1
|
#define LWIP_DHCP 1
|
||||||
|
|
||||||
/* 1 if you want to do an ARP check on the offered address
|
/* 1 if you want to do an ARP check on the offered address
|
||||||
(recommended). */
|
(recommended). */
|
||||||
#define DHCP_DOES_ARP_CHECK (LWIP_DHCP)
|
#define DHCP_DOES_ARP_CHECK (LWIP_DHCP)
|
||||||
|
|
||||||
/* ---------- AUTOIP options ------- */
|
/* ---------- AUTOIP options ------- */
|
||||||
#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 UDP_TTL 255
|
|
||||||
|
|
||||||
|
#define LWIP_UDPLITE 0
|
||||||
|
#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
|
||||||
|
|
||||||
/*
|
/*
|
||||||
---------------------------------
|
---------------------------------
|
||||||
|
@ -529,17 +543,17 @@ 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
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -547,9 +561,9 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
|
||||||
---------- Lwip Debug options ----------
|
---------- Lwip Debug options ----------
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
*/
|
*/
|
||||||
#define LWIP_IPV4 1
|
#define LWIP_IPV4 1
|
||||||
#define LWIP_RAW 1
|
#define LWIP_RAW 1
|
||||||
#define LWIP_DNS 1
|
#define LWIP_DNS 1
|
||||||
|
|
||||||
#if LWIP_DNS
|
#if LWIP_DNS
|
||||||
#define LWIP_RAND rand
|
#define LWIP_RAND rand
|
||||||
|
@ -559,9 +573,8 @@ 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
|
|
||||||
|
|
||||||
#define lw_print KPrintf
|
#define lw_print KPrintf
|
||||||
#define lw_error KPrintf
|
#define lw_error KPrintf
|
||||||
|
@ -570,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****/
|
||||||
|
|
||||||
|
|
|
@ -338,11 +338,11 @@ void lwip_config_input(struct netif* net)
|
||||||
|
|
||||||
th_id = sys_thread_new("eth_input", ethernetif_input, net, LWIP_TASK_STACK_SIZE, 30);
|
th_id = sys_thread_new("eth_input", ethernetif_input, net, LWIP_TASK_STACK_SIZE, 30);
|
||||||
|
|
||||||
if (th_id >= 0) {
|
// if (th_id >= 0) {
|
||||||
lw_print("%s %d successfully!\n", __func__, th_id);
|
// lw_print("%s %d successfully!\n", __func__, th_id);
|
||||||
} else {
|
// } else {
|
||||||
lw_print("%s failed!\n", __func__);
|
// lw_print("%s failed!\n", __func__);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void lwip_config_tcp(uint8_t enet_port, char* ip, char* mask, char* gw)
|
void lwip_config_tcp(uint8_t enet_port, char* ip, char* mask, char* gw)
|
||||||
|
@ -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");
|
||||||
|
|
|
@ -200,7 +200,9 @@ typedef uintptr_t mem_ptr_t;
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
#else /* SSIZE_MAX */
|
#else /* SSIZE_MAX */
|
||||||
|
#ifndef RISCV_LWIP
|
||||||
typedef int ssize_t;
|
typedef int ssize_t;
|
||||||
|
#endif
|
||||||
#define SSIZE_MAX INT_MAX
|
#define SSIZE_MAX INT_MAX
|
||||||
#endif /* SSIZE_MAX */
|
#endif /* SSIZE_MAX */
|
||||||
|
|
||||||
|
|
|
@ -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_tcp(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
|
lwip_config_tcp(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;
|
||||||
|
|
|
@ -788,7 +788,7 @@ void OTA_Download(int size, int offset)
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* 函 数 名: app_ota_by_platform
|
* 函 数 名: app_ota_by_platform
|
||||||
* 功能描述: 通过命令来进行ota升级,该函数与升级的命令关联,通过云平台MQTT进行升级
|
* 功能描述: 通过云平台MQTT进行升级
|
||||||
* 形 参: 无
|
* 形 参: 无
|
||||||
* 返 回 值: 无
|
* 返 回 值: 无
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
|
@ -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