23/08/01 Fit Wenbet to edu-arm32, use delay to counteract stuck by mass access.
This commit is contained in:
parent
73cac7e74b
commit
1ab331c9d0
|
@ -1 +1 @@
|
|||
Subproject commit 42a888a7e739a27f5301dae4d69470c7521e0887
|
||||
Subproject commit 2056a6d5876ac607052522b82134ee25071419f8
|
|
@ -130,6 +130,10 @@ uint32_t PrivGetTickTime()
|
|||
{
|
||||
return CalculateTimeMsFromTick(CurrentTicksGain());
|
||||
}
|
||||
uint32_t PrivGetTick()
|
||||
{
|
||||
return CurrentTicksGain();
|
||||
}
|
||||
#endif
|
||||
|
||||
/******************Soft Timer*********************/
|
||||
|
@ -164,7 +168,7 @@ int PrivTimerModify(timer_t timerid, int flags, const struct itimerspec *restric
|
|||
/*********************fs**************************/
|
||||
#ifdef FS_VFS
|
||||
/************************Driver Posix Transform***********************/
|
||||
int PrivOpen(const char *path, int flags)
|
||||
int PrivOpen(const char* path, int flags, ...)
|
||||
{
|
||||
return open(path, flags);
|
||||
}
|
||||
|
|
|
@ -424,10 +424,11 @@ void PrivTaskQuit(void *value_ptr);
|
|||
int PrivTaskDelay(int32_t ms);
|
||||
int PrivUserTaskSearch(void);
|
||||
uint32_t PrivGetTickTime();
|
||||
uint32_t PrivGetTick();
|
||||
|
||||
/*********************driver*************************/
|
||||
|
||||
int PrivOpen(const char *path, int flags);
|
||||
int PrivOpen(const char* path, int flags, ...);
|
||||
int PrivRead(int fd, void *buf, size_t len);
|
||||
int PrivWrite(int fd, const void *buf, size_t len);
|
||||
int PrivClose(int fd);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
*/
|
||||
|
||||
#include "include/mqueue.h"
|
||||
#include <xs_base.h>
|
||||
|
||||
mqd_t mq_open(const char* name, int oflag, mode_t mode, struct mq_attr* attr)
|
||||
{
|
||||
|
@ -45,7 +46,7 @@ ssize_t mq_receive(mqd_t mqdes, char* msg_ptr, size_t msg_len, unsigned* msg_pri
|
|||
ssize_t ret;
|
||||
|
||||
*msg_prio = 0;
|
||||
ret = UserMsgQueueRecv(mqdes, (void*)msg_ptr, msg_len, 100000);
|
||||
ret = UserMsgQueueRecv(mqdes, (void*)msg_ptr, msg_len, WAITING_FOREVER);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -74,8 +75,7 @@ ssize_t mq_timedreceive(mqd_t mqdes, char *msg_ptr, size_t msg_len,
|
|||
int ticks;
|
||||
|
||||
*msg_prio = 0;
|
||||
ticks = abstime->tv_sec * 1000 +
|
||||
(abstime->tv_nsec / 1000000 ) ;
|
||||
ticks = abstime->tv_sec * 1000 + (abstime->tv_nsec / 1000000);
|
||||
|
||||
ret = UserMsgQueueRecv(mqdes, msg_ptr, msg_len, ticks);
|
||||
return ret;
|
||||
|
@ -86,8 +86,7 @@ int mq_timedsend(mqd_t mqdes, const char *msg_ptr, size_t msg_len,
|
|||
{
|
||||
int ret;
|
||||
int ticks;
|
||||
ticks = abstime->tv_sec * 1000 +
|
||||
(abstime->tv_nsec / 1000000 ) ;
|
||||
ticks = abstime->tv_sec * 1000 + (abstime->tv_nsec / 1000000);
|
||||
|
||||
ret = UserMsgQueueSendwait(mqdes, (void *)msg_ptr, msg_len, ticks);
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ InterruptVectors:
|
|||
.long IsrEntry
|
||||
.long IsrEntry
|
||||
.long IsrEntry
|
||||
.long IsrEntry
|
||||
.long IRQ030_Handler
|
||||
.long IsrEntry
|
||||
.long IsrEntry
|
||||
.long IsrEntry
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
export CROSS_COMPILE ?=/usr/bin/arm-none-eabi-
|
||||
|
||||
export CFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -fgnu89-inline -Wa,-mimplicit-it=thumb -Werror
|
||||
export CFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Dgcc -O1 -fgnu89-inline -Wa,-mimplicit-it=thumb -Werror
|
||||
# export CFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -fgnu89-inline -Wa,-mimplicit-it=thumb -Werror
|
||||
export AFLAGS := -c -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -x assembler-with-cpp -Wa,-mimplicit-it=thumb -gdwarf-2
|
||||
export LFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi-edu-arm32.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link.lds
|
||||
export CXXFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -Werror
|
||||
export CXXFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Dgcc -O1 -Werror
|
||||
# export CXXFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -Werror
|
||||
|
||||
export APPLFLAGS := -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi-edu-arm32.map,-cref,-u, -T $(BSP_ROOT)/link_userspace.lds
|
||||
|
||||
|
|
|
@ -62,7 +62,6 @@ int32_t low_level_init(struct netif* netif)
|
|||
// EthHandle.stcCommInit.u32ChecksumMode = ETH_MAC_CHECKSUM_MD_SW;
|
||||
|
||||
// install irq
|
||||
sys_sem_new(get_eth_recv_sem(), 0);
|
||||
hc32_install_irq_handler(ð_irq_config, eth_irq_handler, ENABLE);
|
||||
|
||||
/* Configure ethernet peripheral */
|
||||
|
|
|
@ -133,6 +133,7 @@ int lwip_netdev_add(struct netif* lwip_netif)
|
|||
|
||||
// init netdev
|
||||
char netif_name[NETIF_NAME_LEN + 1];
|
||||
SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] Lwip netif name: %s\n", __func__, lwip_netif->name));
|
||||
strncpy(netif_name, lwip_netif->name, NETIF_NAME_LEN);
|
||||
// register netdev
|
||||
int result = netdev_register(netdev, netif_name, (void*)lwip_netif);
|
||||
|
|
|
@ -190,44 +190,6 @@ void Time_Update_LwIP(void)
|
|||
// no need to do
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Should be called at the beginning of the program to set up the network interface.
|
||||
* @param netif The network interface structure for this ethernetif.
|
||||
* @retval err_t:
|
||||
* - LL_OK: The IF is initialized
|
||||
* - LL_ERR: The IF is uninitialized
|
||||
*/
|
||||
err_t ethernetif_init(struct netif* netif)
|
||||
{
|
||||
#if LWIP_NETIF_HOSTNAME
|
||||
/* Initialize interface hostname */
|
||||
netif->hostname = "lwip";
|
||||
#endif /* LWIP_NETIF_HOSTNAME */
|
||||
netif->name[0] = IFNAME0;
|
||||
netif->name[1] = IFNAME1;
|
||||
|
||||
#ifndef ETHERNET_LOOPBACK_TEST
|
||||
/* We directly use etharp_output() here to save a function call.
|
||||
* You can instead declare your own function an call etharp_output()
|
||||
* from it if you have to do some checks before sending (e.g. if link
|
||||
* is available...) */
|
||||
netif->output = etharp_output;
|
||||
netif->linkoutput = low_level_output;
|
||||
#endif
|
||||
|
||||
/* initialize the hardware */
|
||||
if (LL_OK != low_level_init(netif)) {
|
||||
return LL_ERR;
|
||||
}
|
||||
|
||||
if (EOK != lwip_netdev_add(netif)) {
|
||||
SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] LWIP add netdev failed.\n", __func__));
|
||||
} else {
|
||||
printf("[%s] Add Netdev successful\n", __func__);
|
||||
}
|
||||
return LL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function should be called when a packet is ready to be read from the interface.
|
||||
* @param netif The network interface structure for this ethernetif.
|
||||
|
@ -267,6 +229,81 @@ void ethernetif_input(void* netif_arg)
|
|||
}
|
||||
}
|
||||
|
||||
err_t ethernetif_linkoutput(struct netif* netif, struct pbuf* p)
|
||||
{
|
||||
NULL_PARAM_CHECK(netif);
|
||||
|
||||
err_t ret = EOK;
|
||||
|
||||
struct eth_tx_msg msg;
|
||||
msg.netif = netif;
|
||||
msg.buf = p;
|
||||
// ret = sys_sem_new(&(msg.completion_sem), 0);
|
||||
// if (EOK != ret) {
|
||||
// return ret;
|
||||
// }
|
||||
|
||||
if (sys_mbox_trypost(get_eth_tx_mbox(), (void*)&msg) == EOK) {
|
||||
// sys_arch_sem_wait(&(msg.completion_sem), WAITING_FOREVER);
|
||||
}
|
||||
|
||||
// sys_sem_free(&(msg.completion_sem));
|
||||
// return msg.ret_val;
|
||||
return LL_OK;
|
||||
}
|
||||
|
||||
void ethernetif_output()
|
||||
{
|
||||
void* param_ptr;
|
||||
|
||||
while (true) {
|
||||
if (sys_arch_mbox_fetch(get_eth_tx_mbox(), ¶m_ptr, WAITING_FOREVER) != SYS_ARCH_TIMEOUT) {
|
||||
struct eth_tx_msg* msg = (struct eth_tx_msg*)param_ptr;
|
||||
msg->ret_val = low_level_output(msg->netif, msg->buf);
|
||||
// sys_sem_signal(&(msg->completion_sem));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Should be called at the beginning of the program to set up the network interface.
|
||||
* @param netif The network interface structure for this ethernetif.
|
||||
* @retval err_t:
|
||||
* - LL_OK: The IF is initialized
|
||||
* - LL_ERR: The IF is uninitialized
|
||||
*/
|
||||
err_t ethernetif_init(struct netif* netif)
|
||||
{
|
||||
#if LWIP_NETIF_HOSTNAME
|
||||
/* Initialize interface hostname */
|
||||
netif->hostname = "lwip";
|
||||
#endif /* LWIP_NETIF_HOSTNAME */
|
||||
netif->name[0] = IFNAME0;
|
||||
netif->name[1] = IFNAME1;
|
||||
|
||||
#ifndef ETHERNET_LOOPBACK_TEST
|
||||
/* We directly use etharp_output() here to save a function call.
|
||||
* You can instead declare your own function an call etharp_output()
|
||||
* from it if you have to do some checks before sending (e.g. if link
|
||||
* is available...) */
|
||||
netif->output = etharp_output;
|
||||
netif->linkoutput = low_level_output;
|
||||
// netif->linkoutput = ethernetif_linkoutput;
|
||||
#endif
|
||||
|
||||
/* initialize the hardware */
|
||||
if (LL_OK != low_level_init(netif)) {
|
||||
return LL_ERR;
|
||||
}
|
||||
|
||||
if (EOK != lwip_netdev_add(netif)) {
|
||||
SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] LWIP add netdev failed.\n", __func__));
|
||||
} else {
|
||||
printf("[%s] Add Netdev successful\n", __func__);
|
||||
}
|
||||
return LL_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check the netif link status.
|
||||
* @param netif the network interface
|
||||
|
|
|
@ -153,14 +153,14 @@ static uint32 SdioRead(void *dev, struct BusBlockReadParam *read_param)
|
|||
uint32 block_num = read_param->size;
|
||||
uint8 *read_buffer = (uint8 *)read_param->buffer;
|
||||
|
||||
KSemaphoreObtain(sd_lock, WAITING_FOREVER);
|
||||
// KSemaphoreObtain(sd_lock, WAITING_FOREVER);
|
||||
|
||||
if (LL_OK != SD_ReadBlocks(&gSdHandle, sector, block_num, read_buffer, 2000UL)) {
|
||||
KPrintf("Read data blocks failed.\r\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
KSemaphoreAbandon(sd_lock);
|
||||
// KSemaphoreAbandon(sd_lock);
|
||||
|
||||
return read_param->size;
|
||||
}
|
||||
|
@ -172,14 +172,14 @@ static uint32 SdioWrite(void *dev, struct BusBlockWriteParam *write_param)
|
|||
uint32 block_num = write_param->size;
|
||||
uint8 *write_buffer = (uint8 *)write_param->buffer;
|
||||
|
||||
KSemaphoreObtain(sd_lock, WAITING_FOREVER);
|
||||
// KSemaphoreObtain(sd_lock, WAITING_FOREVER);
|
||||
|
||||
if (LL_OK != SD_WriteBlocks(&gSdHandle, sector, block_num, write_buffer, 2000U)) {
|
||||
KPrintf("Write data blocks failed.\r\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
KSemaphoreAbandon(sd_lock);
|
||||
// KSemaphoreAbandon(sd_lock);
|
||||
|
||||
return write_param->size;
|
||||
}
|
||||
|
@ -289,7 +289,7 @@ int MountSDCard()
|
|||
{
|
||||
int sd_card_task = 0;
|
||||
sd_card_task = KTaskCreate("sd_card", SdCardTask, NONE,
|
||||
SD_CARD_STACK_SIZE, 8);
|
||||
SD_CARD_STACK_SIZE, 8);
|
||||
if(sd_card_task < 0) {
|
||||
KPrintf("sd_card_task create failed ...%s %d.\n", __FUNCTION__,__LINE__);
|
||||
return ERROR;
|
||||
|
|
|
@ -442,6 +442,7 @@ int open(const char *path, int flags, ...)
|
|||
|
||||
fd = NewFileDescriptor(&fdp);
|
||||
if (fd < 0) {
|
||||
SYS_ERR("%s: Failed to create new file descriptor.\n", __func__);
|
||||
KUpdateExstatus(ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
|
@ -473,7 +474,7 @@ int open(const char *path, int flags, ...)
|
|||
|
||||
ret = mp->fs->open(fdp, relpath);
|
||||
if (ret < 0) {
|
||||
SYS_ERR("%s: file open failed\n", __func__);
|
||||
SYS_ERR("%s: file open failed, err num: %d\n", __func__, ret);
|
||||
goto err;
|
||||
}
|
||||
|
||||
|
@ -540,7 +541,7 @@ int read(int fd, void *buf, size_t len)
|
|||
|
||||
ret = fdp->mntp->fs->read(fdp, buf, len);
|
||||
if (ret < 0) {
|
||||
SYS_ERR("%s: read file failed\n", __func__);
|
||||
SYS_ERR("%s: read file failed, fd: %s\n", __func__, fdp->path);
|
||||
KUpdateExstatus(ret);
|
||||
return -1;
|
||||
}
|
||||
|
@ -772,7 +773,8 @@ int stat(const char *path, struct stat *buf)
|
|||
|
||||
ret = mp->fs->stat(mp, relpath, &vfs_statbuf);
|
||||
if (ret < 0) {
|
||||
SYS_ERR("%s: stat file failed\n", __func__);
|
||||
// stat() is absolutely fine to check if a file exists
|
||||
// SYS_ERR("%s: stat file failed\n", __func__);
|
||||
goto err;
|
||||
}
|
||||
|
||||
|
@ -790,7 +792,6 @@ err:
|
|||
free(abspath);
|
||||
|
||||
if (ret < 0) {
|
||||
KUpdateExstatus(ret);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -43,6 +43,9 @@ extern "C" {
|
|||
#define KDBG_HOOK 0
|
||||
|
||||
#define MSGQUEUE_DEBUG 0
|
||||
#define FILESYS_DEBUG 0
|
||||
#define NETDEV_DEBUG 0
|
||||
#define WEBNET_DEBUG 0
|
||||
|
||||
#define SYS_KDEBUG_LOG(section, information) \
|
||||
do { \
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include <xizi.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MEM_STATS
|
||||
// #define MEM_STATS
|
||||
|
||||
/* Covert pointer to other structure */
|
||||
#define PTR2ALLOCNODE(pointer) (struct DynamicAllocNode *)(pointer)
|
||||
|
|
|
@ -137,11 +137,13 @@ static x_err_t _MsgQueueSend(struct MsgQueue* mq,
|
|||
|
||||
lock = CriticalAreaLock();
|
||||
|
||||
if (timeout > 0) {
|
||||
if (timeout != WAITING_FOREVER && timeout > 0) {
|
||||
tick_delta = CurrentTicksGain() - tick_delta;
|
||||
timeout -= tick_delta;
|
||||
if (timeout < 0)
|
||||
timeout = 0;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
} // end with lock here
|
||||
|
||||
|
@ -211,7 +213,12 @@ static x_err_t _MsgQueueRecv(struct MsgQueue* mq,
|
|||
|
||||
tick_delta = 0;
|
||||
task = GetKTaskDescriptor();
|
||||
timeout = CalculateTickFromTimeMs(msec);
|
||||
|
||||
if (msec == WAITING_FOREVER) {
|
||||
timeout = WAITING_FOREVER;
|
||||
} else {
|
||||
timeout = CalculateTickFromTimeMs(msec);
|
||||
}
|
||||
|
||||
lock = CriticalAreaLock();
|
||||
if (mq->index == 0 && timeout == 0) {
|
||||
|
@ -247,7 +254,7 @@ static x_err_t _MsgQueueRecv(struct MsgQueue* mq,
|
|||
|
||||
lock = CriticalAreaLock();
|
||||
|
||||
if (timeout > 0) {
|
||||
if (timeout != WAITING_FOREVER && timeout > 0) {
|
||||
tick_delta = CurrentTicksGain() - tick_delta;
|
||||
timeout -= tick_delta;
|
||||
if (timeout < 0)
|
||||
|
@ -498,7 +505,7 @@ x_err_t KMsgQueueSendwait(int32 id, const void *buffer, x_size_t size,int32 tim
|
|||
|
||||
mq = GetMsgQueueById(id);
|
||||
if (mq != NONE)
|
||||
return mq->Done->send(mq,buffer,size,timeout);
|
||||
return mq->Done->send(mq, buffer, size, timeout);
|
||||
else
|
||||
return -EINVALED;
|
||||
}
|
||||
|
|
|
@ -1828,7 +1828,8 @@ lwip_netconn_do_write(void *m)
|
|||
LWIP_ASSERT("msg->msg.w.len != 0", msg->msg.w.len != 0);
|
||||
msg->conn->current_msg = msg;
|
||||
#if LWIP_TCPIP_CORE_LOCKING
|
||||
if (lwip_netconn_do_writemore(msg->conn, 0) != ERR_OK) {
|
||||
err_t do_writemore_err = lwip_netconn_do_writemore(msg->conn, 0);
|
||||
if (do_writemore_err != ERR_OK) {
|
||||
LWIP_ASSERT("state!", msg->conn->state == NETCONN_WRITE);
|
||||
UNLOCK_TCPIP_CORE();
|
||||
sys_arch_sem_wait(LWIP_API_MSG_SEM(msg), 0);
|
||||
|
|
|
@ -952,9 +952,7 @@ lwip_recv_tcp(struct lwip_sock *sock, void *mem, size_t len, int flags)
|
|||
/* No data was left from the previous operation, so we try to get
|
||||
some from the network. */
|
||||
err = netconn_recv_tcp_pbuf_flags(sock->conn, &p, apiflags);
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recv_tcp: netconn_recv err=%d, pbuf=%p\n",
|
||||
err, (void *)p));
|
||||
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recv_tcp: netconn_recv err=%d, pbuf=%p\n", err, (void*)p));
|
||||
if (err != ERR_OK) {
|
||||
if (recvd > 0) {
|
||||
/* already received data, return that (this trusts in getting the same error from
|
||||
|
|
|
@ -34,7 +34,10 @@
|
|||
|
||||
/* ---------- Debug options ---------- */
|
||||
#ifndef LWIP_DEBUG
|
||||
#define LWIP_DEBUG 1
|
||||
#define LWIP_DEBUG 1
|
||||
// #define LWIP_TCP_OUTPUT_DEBUG
|
||||
// #define LWIP_SOCKETS_DEBUG
|
||||
// #define LWIP_TCP_QLEN_DEBUG
|
||||
#endif
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
|
@ -246,12 +249,12 @@
|
|||
|
||||
/* 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. */
|
||||
#define MEM_SIZE (64*1024)
|
||||
#define MEM_SIZE (64 * 1024)
|
||||
|
||||
/* 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
|
||||
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
|
||||
per active UDP "connection". */
|
||||
#define MEMP_NUM_UDP_PCB 4
|
||||
|
@ -271,7 +274,7 @@ a lot of data that needs to be copied, this should be set high. */
|
|||
|
||||
/* ---------- Pbuf options ---------- */
|
||||
/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */
|
||||
#define PBUF_POOL_SIZE 255
|
||||
#define PBUF_POOL_SIZE 400
|
||||
/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */
|
||||
// #define PBUF_POOL_BUFSIZE 1024
|
||||
#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+40+PBUF_LINK_ENCAPSULATION_HLEN+PBUF_LINK_HLEN)
|
||||
|
@ -293,12 +296,12 @@ a lot of data that needs to be copied, this should be set high. */
|
|||
#define TCP_MSS (1500 - 40) /* TCP_MSS = (Ethernet MTU - IP header size - TCP header size) */
|
||||
|
||||
/* TCP sender buffer space (bytes). */
|
||||
#define TCP_SND_BUF (11*TCP_MSS)
|
||||
#define TCP_SND_BUF (12 * TCP_MSS)
|
||||
|
||||
/* 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. */
|
||||
|
||||
#define TCP_SND_QUEUELEN (8* TCP_SND_BUF/TCP_MSS)
|
||||
#define TCP_SND_QUEUELEN (12 * TCP_SND_BUF / TCP_MSS)
|
||||
|
||||
/* TCP receive window. */
|
||||
#define TCP_WND 8192
|
||||
|
@ -540,7 +543,7 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
|
|||
#define TCPIP_THREAD_NAME "tcp"
|
||||
#define TCPIP_THREAD_STACKSIZE 2048
|
||||
#define TCPIP_MBOX_SIZE 16
|
||||
#define TCPIP_THREAD_PRIO 20
|
||||
#define TCPIP_THREAD_PRIO 29
|
||||
|
||||
/*
|
||||
----------------------------------------
|
||||
|
@ -563,7 +566,8 @@ typedef unsigned int nfds_t;
|
|||
#define MEMP_LIB_MALLOC 1
|
||||
#define MEMP_MEM_MALLOC 1
|
||||
|
||||
#define lw_print KPrintf
|
||||
// #define lw_print KPrintf
|
||||
#define lw_print
|
||||
#define lw_error KPrintf
|
||||
#define lw_notice KPrintf
|
||||
|
||||
|
|
|
@ -89,9 +89,20 @@ x_ticks_t lwip_sys_now;
|
|||
struct netif gnetif;
|
||||
sys_sem_t* get_eth_recv_sem()
|
||||
{
|
||||
static sys_sem_t g_recv_sem = 0;
|
||||
static sys_sem_t g_recv_sem = -1;
|
||||
return &g_recv_sem;
|
||||
}
|
||||
sys_mbox_t* get_eth_tx_mbox()
|
||||
{
|
||||
static sys_mbox_t g_eth_tx_mb = -1;
|
||||
return &g_eth_tx_mb;
|
||||
}
|
||||
|
||||
sys_mutex_t* get_eth_tcpip_sem()
|
||||
{
|
||||
static sys_sem_t g_tcpip_sem = -1;
|
||||
return &g_tcpip_sem;
|
||||
}
|
||||
|
||||
void sys_init(void)
|
||||
{
|
||||
|
@ -193,7 +204,7 @@ void sys_sem_signal(sys_sem_t* sem)
|
|||
err_t sys_mutex_new(sys_mutex_t* mutex)
|
||||
{
|
||||
*mutex = KMutexCreate();
|
||||
if (*mutex > SYS_MRTEX_NULL)
|
||||
if (*mutex > SYS_MUTEX_NULL)
|
||||
return ERR_OK;
|
||||
else {
|
||||
KPrintf("[sys_arch]:new mutex fail!\n");
|
||||
|
@ -208,7 +219,7 @@ void sys_mutex_free(sys_mutex_t* mutex)
|
|||
|
||||
void sys_mutex_set_invalid(sys_mutex_t* mutex)
|
||||
{
|
||||
*mutex = SYS_MRTEX_NULL;
|
||||
*mutex = SYS_MUTEX_NULL;
|
||||
}
|
||||
|
||||
void sys_mutex_lock(sys_mutex_t* mutex)
|
||||
|
@ -253,7 +264,6 @@ err_t sys_mbox_new(sys_mbox_t* mbox, int size)
|
|||
return ERR_MEM;
|
||||
}
|
||||
|
||||
lw_print("lw: [%s] alloc %d mbox %p ok!\n", __func__, size, mbox);
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
|
@ -286,6 +296,7 @@ err_t sys_mbox_trypost(sys_mbox_t* q, void* msg)
|
|||
if (KMsgQueueSend(*q, &msg, sizeof(void*)) == EOK)
|
||||
return ERR_OK;
|
||||
else
|
||||
printf("[%s] Error mbox trypost\n");
|
||||
return ERR_MEM;
|
||||
}
|
||||
|
||||
|
@ -334,12 +345,14 @@ ip4_addr_t gw;
|
|||
|
||||
void lwip_config_input(struct netif* net)
|
||||
{
|
||||
sys_thread_t th_id = 0;
|
||||
sys_thread_t eth_rx_th_id = -1, eth_tx_th_id = 0;
|
||||
|
||||
th_id = sys_thread_new("eth_input", ethernetif_input, net, LWIP_TASK_STACK_SIZE, 20);
|
||||
eth_rx_th_id = sys_thread_new("eth_rx_thd", ethernetif_input, net, LWIP_TASK_STACK_SIZE, 30);
|
||||
// eth_tx_th_id = sys_thread_new("eth_tx_thd", ethernetif_output, NULL, LWIP_TASK_STACK_SIZE, 30);
|
||||
|
||||
if (th_id >= 0) {
|
||||
lw_print("%s %d successfully!\n", __func__, th_id);
|
||||
if (eth_rx_th_id >= 0 && eth_tx_th_id >= 0) {
|
||||
lw_print("%s %d successfully!\n", __func__, eth_rx_th_id);
|
||||
// lw_print("%s %d and %d successfully!\n", __func__, eth_tx_th_id, eth_rx_th_id);
|
||||
} else {
|
||||
lw_print("%s failed!\n", __func__);
|
||||
}
|
||||
|
@ -347,6 +360,15 @@ void lwip_config_input(struct netif* net)
|
|||
|
||||
void lwip_config_tcp(uint8_t enet_port, char* ip, char* mask, char* gw)
|
||||
{
|
||||
static uint32_t g_eth_mbox_size = 16;
|
||||
if (*get_eth_tcpip_sem() == -1) {
|
||||
sys_sem_new(get_eth_tcpip_sem(), 1);
|
||||
}
|
||||
sys_sem_new(get_eth_recv_sem(), 0);
|
||||
// sys_mbox_new(get_eth_tx_mbox(), g_eth_mbox_size);
|
||||
|
||||
lwip_config_input(&gnetif);
|
||||
|
||||
ip4_addr_t net_ipaddr, net_netmask, net_gw;
|
||||
char* eth_cfg;
|
||||
|
||||
|
@ -393,8 +415,6 @@ void lwip_config_tcp(uint8_t enet_port, char* ip, char* mask, char* gw)
|
|||
lw_print(" IPv4 Gateway : %u.%u.%u.%u\r\n", ((u8_t*)&net_gw)[0], ((u8_t*)&net_gw)[1],
|
||||
((u8_t*)&net_gw)[2], ((u8_t*)&net_gw)[3]);
|
||||
lw_print("************************************************\r\n");
|
||||
|
||||
lwip_config_input(&gnetif);
|
||||
}
|
||||
|
||||
void lwip_config_net(uint8_t enet_port, char* ip, char* mask, char* gw)
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
/* USER CODE END 0 */
|
||||
#define SYS_MBOX_NULL -1
|
||||
#define SYS_SEM_NULL -1
|
||||
#define SYS_MRTEX_NULL SYS_SEM_NULL
|
||||
#define SYS_MUTEX_NULL SYS_SEM_NULL
|
||||
|
||||
typedef int32 sys_sem_t;
|
||||
typedef int32 sys_mutex_t;
|
||||
|
@ -100,7 +100,15 @@ extern char lwip_eth1_netmask[];
|
|||
extern char lwip_eth1_gwaddr[];
|
||||
|
||||
extern struct netif gnetif;
|
||||
struct eth_tx_msg {
|
||||
struct netif* netif;
|
||||
struct pbuf* buf;
|
||||
err_t ret_val;
|
||||
sys_sem_t completion_sem;
|
||||
};
|
||||
extern sys_sem_t* get_eth_recv_sem();
|
||||
extern sys_mbox_t* get_eth_tx_mbox();
|
||||
extern void ethernetif_output();
|
||||
|
||||
void lwip_tcp_init(void);
|
||||
void lwip_config_net(uint8_t enet_port, char *ip, char *mask, char *gw);
|
||||
|
|
|
@ -40,10 +40,11 @@
|
|||
|
||||
#if LWIP_STATS /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "lwip/def.h"
|
||||
#include "lwip/stats.h"
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/debug.h"
|
||||
#include "lwip/def.h"
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/stats.h"
|
||||
#include <shell.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
@ -165,5 +166,8 @@ stats_display(void)
|
|||
}
|
||||
#endif /* LWIP_STATS_DISPLAY */
|
||||
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(8),
|
||||
lwip_stats_display, stats_display, display lwip states);
|
||||
|
||||
#endif /* LWIP_STATS */
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@
|
|||
*/
|
||||
|
||||
#include "lwip/opt.h"
|
||||
#include <sys.h>
|
||||
|
||||
#if LWIP_TCP /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
|
@ -782,6 +783,7 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags)
|
|||
|
||||
LWIP_DEBUGF(TCP_QLEN_DEBUG, ("tcp_write: %"S16_F" (after enqueued)\n",
|
||||
pcb->snd_queuelen));
|
||||
sys_msleep(8);
|
||||
if (pcb->snd_queuelen != 0) {
|
||||
LWIP_ASSERT("tcp_write: valid queue length",
|
||||
pcb->unacked != NULL || pcb->unsent != NULL);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -337,7 +337,7 @@ void iperf_server_multithread(void *thread_param)
|
|||
|
||||
sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (sock < 0){
|
||||
KPrintf("[%s:%d] Socket error!\n", __FILE__, __LINE__);
|
||||
KPrintf("[%s:%d] Socket error!\n", __func__, __LINE__);
|
||||
goto __exit;
|
||||
}
|
||||
|
||||
|
|
|
@ -210,8 +210,8 @@ struct netdev* netdev_get_first_by_flags(uint16_t flags)
|
|||
|
||||
// get netdev from list
|
||||
x_base lock = DISABLE_INTERRUPT();
|
||||
struct netdev* current_dev = NETDEV_LISTHEAD;
|
||||
SINGLE_LINKLIST_FOR_EACH_ENTRY(current_dev, &(NETDEV_LISTHEAD->list), list)
|
||||
struct netdev* current_dev = NETDEV_FIRST_DEV;
|
||||
SINGLE_LINKLIST_FOR_EACH_ENTRY(current_dev, NETDEV_LISTHEAD, list)
|
||||
{
|
||||
if (NULL != current_dev && 0 != (current_dev->flags & flags)) {
|
||||
ENABLE_INTERRUPT(lock);
|
||||
|
@ -240,8 +240,8 @@ struct netdev* netdev_get_by_ipaddr(ip_addr_t* ip_addr)
|
|||
|
||||
// get netdev from list
|
||||
x_base lock = DISABLE_INTERRUPT();
|
||||
struct netdev* current_dev = NETDEV_LISTHEAD;
|
||||
SINGLE_LINKLIST_FOR_EACH_ENTRY(current_dev, &(NETDEV_LISTHEAD->list), list)
|
||||
struct netdev* current_dev = NETDEV_FIRST_DEV;
|
||||
SINGLE_LINKLIST_FOR_EACH_ENTRY(current_dev, NETDEV_LISTHEAD, list)
|
||||
{
|
||||
if (NULL != current_dev && ip_addr_cmp(&(current_dev->ip_addr), ip_addr)) {
|
||||
ENABLE_INTERRUPT(lock);
|
||||
|
@ -270,13 +270,17 @@ struct netdev* netdev_get_by_name(const char* name)
|
|||
|
||||
// get netdev from list
|
||||
x_base lock = DISABLE_INTERRUPT();
|
||||
struct netdev* current_dev = NETDEV_LISTHEAD;
|
||||
SINGLE_LINKLIST_FOR_EACH_ENTRY(current_dev, &(NETDEV_LISTHEAD->list), list)
|
||||
struct netdev* current_dev = NULL;
|
||||
|
||||
SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] Start looping\n", __func__));
|
||||
CHECK(NETDEV_LISTHEAD != NULL);
|
||||
SINGLE_LINKLIST_FOR_EACH_ENTRY(current_dev, NETDEV_LISTHEAD, list)
|
||||
{
|
||||
if (NULL == current_dev) {
|
||||
continue;
|
||||
}
|
||||
uint32_t name_len = strlen(current_dev->name);
|
||||
SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] CurrDev name: %s(%d), name to find: %s(%d)\n", __func__, current_dev->name, name_len, name, strlen(name)));
|
||||
if (NULL != current_dev && (strncmp(current_dev->name, name, strlen(current_dev->name) < NAME_NUM_MAX ? strlen(current_dev->name) : NAME_NUM_MAX) == 0)) {
|
||||
ENABLE_INTERRUPT(lock);
|
||||
return current_dev;
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
#include <xs_isr.h>
|
||||
#include <xs_kdbg.h>
|
||||
|
||||
struct netdev** get_netdev_listhead()
|
||||
SysSingleLinklistType* get_netdev_listhead()
|
||||
{
|
||||
static struct netdev* netdev_listhead = NULL;
|
||||
static SysSingleLinklistType netdev_listhead = { .node_next = NULL };
|
||||
return &netdev_listhead;
|
||||
}
|
||||
struct netdev** get_default_netdev()
|
||||
|
@ -57,6 +57,7 @@ int netdev_register(struct netdev* netdev, const char* name, void* user_data)
|
|||
|
||||
// validate name
|
||||
uint32_t name_len = strlen(name);
|
||||
SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] Get dev name: %s.\n", __func__, name));
|
||||
if (name_len < NAME_NUM_MAX) {
|
||||
strncpy(netdev->name, name, name_len);
|
||||
netdev->name[name_len] = '\0';
|
||||
|
@ -65,6 +66,7 @@ int netdev_register(struct netdev* netdev, const char* name, void* user_data)
|
|||
strncpy(netdev->name, name, NAME_NUM_MAX - 1);
|
||||
netdev->name[NAME_NUM_MAX - 1] = '\0';
|
||||
}
|
||||
SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] Netdev name: %s.\n", __func__, netdev->name));
|
||||
|
||||
netdev->user_data = user_data;
|
||||
|
||||
|
@ -72,16 +74,12 @@ int netdev_register(struct netdev* netdev, const char* name, void* user_data)
|
|||
|
||||
// insert netdev to global list
|
||||
x_base lock = DISABLE_INTERRUPT();
|
||||
if (NETDEV_LISTHEAD == NULL) {
|
||||
NETDEV_LISTHEAD = netdev;
|
||||
} else {
|
||||
SingleLinkListNodeInsert(&(NETDEV_LISTHEAD->list), &(netdev->list));
|
||||
}
|
||||
SingleLinkListNodeInsert(NETDEV_LISTHEAD, &(netdev->list));
|
||||
ENABLE_INTERRUPT(lock);
|
||||
|
||||
if (NETDEV_DEFAULT == NULL) {
|
||||
// set first met netdev to default netdev
|
||||
netdev_set_default(NETDEV_LISTHEAD);
|
||||
netdev_set_default(NETDEV_FIRST_DEV);
|
||||
}
|
||||
|
||||
if (g_netdev_register_callback) {
|
||||
|
@ -110,17 +108,12 @@ int netdev_unregister(struct netdev* netdev)
|
|||
|
||||
// remove netdev from netdev list
|
||||
x_base lock = DISABLE_INTERRUPT();
|
||||
struct netdev* current_dev = NETDEV_LISTHEAD;
|
||||
SINGLE_LINKLIST_FOR_EACH_ENTRY(current_dev, &(NETDEV_LISTHEAD->list), list)
|
||||
struct netdev* current_dev = NETDEV_FIRST_DEV;
|
||||
SINGLE_LINKLIST_FOR_EACH_ENTRY(current_dev, NETDEV_LISTHEAD, list)
|
||||
{
|
||||
// found netdev in list
|
||||
if (current_dev == netdev) {
|
||||
if (NETDEV_LISTHEAD == current_dev && NULL == SingleLinkListGetNextNode(&(current_dev->list))) {
|
||||
// netdev is the only one in list
|
||||
NETDEV_LISTHEAD = NULL;
|
||||
} else {
|
||||
SingleLinkListRmNode(&(NETDEV_LISTHEAD->list), &(current_dev->list));
|
||||
}
|
||||
SingleLinkListRmNode(NETDEV_LISTHEAD, &(current_dev->list));
|
||||
|
||||
// deal default netdev
|
||||
if (current_dev == NETDEV_DEFAULT) {
|
||||
|
@ -132,7 +125,7 @@ int netdev_unregister(struct netdev* netdev)
|
|||
ENABLE_INTERRUPT(lock);
|
||||
|
||||
if (NETDEV_DEFAULT == NULL) {
|
||||
netdev_set_default(NETDEV_LISTHEAD);
|
||||
netdev_set_default(NETDEV_FIRST_DEV);
|
||||
}
|
||||
|
||||
// clean netdev if found one
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define NETDEV_DEBUG true
|
||||
|
||||
#define NETDEV_DEBUG_PRINT_IP_INFO(ip, netmask, gw) \
|
||||
("[%s %d]ip: %u.%u.%u.%u, netmask: %u.%u.%u.%u, gw: %u.%u.%u.%u\n", \
|
||||
__func__, __LINE__, \
|
||||
|
@ -118,9 +116,10 @@ struct netdev {
|
|||
};
|
||||
|
||||
// netdev global list
|
||||
#define NETDEV_LISTHEAD (*get_netdev_listhead())
|
||||
#define NETDEV_LISTHEAD (get_netdev_listhead())
|
||||
#define NETDEV_FIRST_DEV (SYS_SINGLE_LINKLIST_ENTRY(NETDEV_LISTHEAD->node_next, struct netdev, list))
|
||||
#define NETDEV_DEFAULT (*get_default_netdev())
|
||||
extern struct netdev** get_netdev_listhead();
|
||||
extern SysSingleLinklistType* get_netdev_listhead();
|
||||
extern struct netdev** get_default_netdev();
|
||||
|
||||
// netdev register functions: netdev_register.c
|
||||
|
|
Loading…
Reference in New Issue