forked from xuos/xiuos
				
			Merge branch 'prepare_for_master' of https://git.trustie.net/xuos/xiuos into mqtt
This commit is contained in:
		
						commit
						e29eb633ca
					
				| 
						 | 
					@ -36,5 +36,9 @@ ifeq ($(CONFIG_ADD_XIZI_FEATURES),y)
 | 
				
			||||||
        SRC_DIR += control_app
 | 
					        SRC_DIR += control_app
 | 
				
			||||||
    endif
 | 
					    endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ifeq ($(CONFIG_APP_USING_WEBNET),y)
 | 
				
			||||||
 | 
					        SRC_DIR += webnet
 | 
				
			||||||
 | 
					    endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    include $(KERNEL_ROOT)/compiler.mk
 | 
					    include $(KERNEL_ROOT)/compiler.mk
 | 
				
			||||||
endif
 | 
					endif
 | 
				
			||||||
| 
						 | 
					@ -15,7 +15,6 @@
 | 
				
			||||||
// #include <user_api.h>
 | 
					// #include <user_api.h>
 | 
				
			||||||
#include <transform.h>
 | 
					#include <transform.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
extern int FrameworkInit();
 | 
					extern int FrameworkInit();
 | 
				
			||||||
extern void ApplicationOtaTaskInit(void);
 | 
					extern void ApplicationOtaTaskInit(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,3 @@
 | 
				
			||||||
 | 
					SRC_DIR += WebNet_XiUOS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include $(KERNEL_ROOT)/compiler.mk
 | 
				
			||||||
| 
						 | 
					@ -1 +1 @@
 | 
				
			||||||
Subproject commit 956eafa24bb65f5bb84d293ab35bf27084473edf
 | 
					Subproject commit 60a8a500b93b47876c6eaff600e4cf2b8bf7b283
 | 
				
			||||||
| 
						 | 
					@ -164,7 +164,7 @@ int PrivTimerModify(timer_t timerid, int flags, const struct itimerspec *restric
 | 
				
			||||||
/*********************fs**************************/
 | 
					/*********************fs**************************/
 | 
				
			||||||
#ifdef FS_VFS
 | 
					#ifdef FS_VFS
 | 
				
			||||||
/************************Driver Posix Transform***********************/
 | 
					/************************Driver Posix Transform***********************/
 | 
				
			||||||
int PrivOpen(const char *path, int flags)
 | 
					int PrivOpen(const char *path, int flags, ...)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return open(path, flags);
 | 
					    return open(path, flags);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -427,7 +427,7 @@ uint32_t PrivGetTickTime();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*********************driver*************************/
 | 
					/*********************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 PrivRead(int fd, void *buf, size_t len);
 | 
				
			||||||
int PrivWrite(int fd, const void *buf, size_t len);
 | 
					int PrivWrite(int fd, const void *buf, size_t len);
 | 
				
			||||||
int PrivClose(int fd);
 | 
					int PrivClose(int fd);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -40,7 +40,8 @@ struct mq_attr {
 | 
				
			||||||
    long mq_curmsgs;  /* number of messages currently queued */
 | 
					    long mq_curmsgs;  /* number of messages currently queued */
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
mqd_t   mq_open(const char *name, int oflag, ...);
 | 
					// mqd_t   mq_open(const char *name, int oflag, ...);
 | 
				
			||||||
 | 
					mqd_t mq_open(const char *name, int oflag, mode_t mode, struct mq_attr *attr);
 | 
				
			||||||
int     mq_close(mqd_t mqdes);
 | 
					int     mq_close(mqd_t mqdes);
 | 
				
			||||||
ssize_t mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio);
 | 
					ssize_t mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio);
 | 
				
			||||||
int     mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio);
 | 
					int     mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,12 +21,13 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "include/mqueue.h"
 | 
					#include "include/mqueue.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
mqd_t mq_open(const char *name, int oflag, ...)
 | 
					mqd_t mq_open(const char* name, int oflag, mode_t mode, struct mq_attr* attr)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    mqd_t mq;
 | 
					    mqd_t mq;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    mq = UserMsgQueueCreate( DEFAULT_MQUEUE_SIZE, DEFAULT_MAX_MSG_SIZE);
 | 
					    // Todo: config mq by mode
 | 
				
			||||||
 | 
					    mq = UserMsgQueueCreate(attr->mq_msgsize, attr->mq_maxmsg);
 | 
				
			||||||
    if (mq < 0) {
 | 
					    if (mq < 0) {
 | 
				
			||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -39,12 +40,12 @@ int mq_close(mqd_t mqdes)
 | 
				
			||||||
    return UserMsgQueueDelete(mqdes);
 | 
					    return UserMsgQueueDelete(mqdes);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ssize_t mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio)
 | 
					ssize_t mq_receive(mqd_t mqdes, char* msg_ptr, size_t msg_len, unsigned* msg_prio)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ssize_t ret;
 | 
					    ssize_t ret;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    *msg_prio = 0;
 | 
					    *msg_prio = 0;
 | 
				
			||||||
    ret = UserMsgQueueRecv(mqdes, msg_ptr, (unsigned long)&msg_len, 0);
 | 
					    ret = UserMsgQueueRecv(mqdes, (void*)msg_ptr, msg_len, WAITING_FOREVER);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return ret;
 | 
					    return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1 +1 @@
 | 
				
			||||||
Subproject commit d21965b1cbcfa99b2d36acd029a37f3f2eba612e
 | 
					Subproject commit a94c007cb4ee726cc29b10626f8bbfc19c989b89
 | 
				
			||||||
| 
						 | 
					@ -1 +1 @@
 | 
				
			||||||
Subproject commit 2896d7234688de77992e7e1872a7e67a9456b420
 | 
					Subproject commit 254754bc7d06011cbec4655cd229c8ccfb95240b
 | 
				
			||||||
| 
						 | 
					@ -91,7 +91,7 @@ InterruptVectors:
 | 
				
			||||||
                .long       IsrEntry
 | 
					                .long       IsrEntry
 | 
				
			||||||
                .long       IsrEntry
 | 
					                .long       IsrEntry
 | 
				
			||||||
                .long       IsrEntry
 | 
					                .long       IsrEntry
 | 
				
			||||||
                .long       IsrEntry
 | 
					                .long       IRQ030_Handler
 | 
				
			||||||
                .long       IsrEntry
 | 
					                .long       IsrEntry
 | 
				
			||||||
                .long       IsrEntry
 | 
					                .long       IsrEntry
 | 
				
			||||||
                .long       IsrEntry
 | 
					                .long       IsrEntry
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -188,7 +188,7 @@ sudo apt install gdb-multiarch
 | 
				
			||||||
qemu-system-arm -machine  lm3s6965evb -nographic -kernel build/XiZi-cortex-m3-emulator.elf -s -S
 | 
					qemu-system-arm -machine  lm3s6965evb -nographic -kernel build/XiZi-cortex-m3-emulator.elf -s -S
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
然后要重新开启另一个linux系统终端一个终端,执行`riscv-none-embed-gdb`命令
 | 
					然后要重新开启另一个linux系统终端一个终端,执行命令
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
gdb-multiarch build/XiZi-cortex-m3-emulator.elf -ex "target remote localhost:1234" 
 | 
					gdb-multiarch build/XiZi-cortex-m3-emulator.elf -ex "target remote localhost:1234" 
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,9 +1,11 @@
 | 
				
			||||||
export CROSS_COMPILE ?=/usr/bin/arm-none-eabi-
 | 
					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 -O0 -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 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 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 -O0 -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 := 
 | 
					export APPLFLAGS := 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,3 @@
 | 
				
			||||||
SRC_FILES := ethernetif.c eth_driver.c
 | 
					SRC_FILES := ethernetif.c eth_driver.c eth_netdev.c 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
include $(KERNEL_ROOT)/compiler.mk
 | 
					include $(KERNEL_ROOT)/compiler.mk
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,21 +1,22 @@
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
* @file ethernetif.c
 | 
					 * @file ethernetif.c
 | 
				
			||||||
* @brief support edu-arm32-board ethernetif function and register to Lwip
 | 
					 * @brief support hc32f4a0-board ethernetif function and register to Lwip
 | 
				
			||||||
* @version 3.0 
 | 
					 * @version 3.0
 | 
				
			||||||
* @author AIIT XUOS Lab
 | 
					 * @author AIIT XUOS Lab
 | 
				
			||||||
* @date 2022-12-05
 | 
					 * @date 2022-12-05
 | 
				
			||||||
*/
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <connect_ethernet.h>
 | 
					#include <connect_ethernet.h>
 | 
				
			||||||
 | 
					#include <hc32_ll_fcg.h>
 | 
				
			||||||
#include <hc32_ll_gpio.h>
 | 
					#include <hc32_ll_gpio.h>
 | 
				
			||||||
#include <hc32_ll_utility.h>
 | 
					#include <hc32_ll_utility.h>
 | 
				
			||||||
#include <hc32_ll_fcg.h>
 | 
					 | 
				
			||||||
#include <lwip/timeouts.h>
 | 
					#include <lwip/timeouts.h>
 | 
				
			||||||
#include <netif/etharp.h>
 | 
					#include <netif/etharp.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <sys_arch.h>
 | 
					#include <sys_arch.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void eth_irq_handler(void) {
 | 
					void eth_irq_handler(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    static x_base eth_irq_lock;
 | 
					    static x_base eth_irq_lock;
 | 
				
			||||||
    eth_irq_lock = DISABLE_INTERRUPT();
 | 
					    eth_irq_lock = DISABLE_INTERRUPT();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -35,7 +36,7 @@ void eth_irq_handler(void) {
 | 
				
			||||||
 *           - LL_OK: Initialize success
 | 
					 *           - LL_OK: Initialize success
 | 
				
			||||||
 *           - LL_ERR: Initialize failed
 | 
					 *           - LL_ERR: Initialize failed
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
int32_t low_level_init(struct netif *netif)
 | 
					int32_t low_level_init(struct netif* netif)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int32_t i32Ret = LL_ERR;
 | 
					    int32_t i32Ret = LL_ERR;
 | 
				
			||||||
    stc_eth_init_t stcEthInit;
 | 
					    stc_eth_init_t stcEthInit;
 | 
				
			||||||
| 
						 | 
					@ -137,19 +138,19 @@ int32_t low_level_init(struct netif *netif)
 | 
				
			||||||
 *           - LL_OK: The packet could be sent
 | 
					 *           - LL_OK: The packet could be sent
 | 
				
			||||||
 *           - LL_ERR: The packet couldn't be sent
 | 
					 *           - LL_ERR: The packet couldn't be sent
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
err_t low_level_output(struct netif *netif, struct pbuf *p)
 | 
					err_t low_level_output(struct netif* netif, struct pbuf* p)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    err_t i32Ret;
 | 
					    err_t i32Ret;
 | 
				
			||||||
    struct pbuf *q;
 | 
					    struct pbuf* q;
 | 
				
			||||||
    uint8_t *txBuffer;
 | 
					    uint8_t* txBuffer;
 | 
				
			||||||
    __IO stc_eth_dma_desc_t *DmaTxDesc;
 | 
					    __IO stc_eth_dma_desc_t* DmaTxDesc;
 | 
				
			||||||
    uint32_t byteCnt;
 | 
					    uint32_t byteCnt;
 | 
				
			||||||
    uint32_t frameLength = 0UL;
 | 
					    uint32_t frameLength = 0UL;
 | 
				
			||||||
    uint32_t bufferOffset;
 | 
					    uint32_t bufferOffset;
 | 
				
			||||||
    uint32_t payloadOffset;
 | 
					    uint32_t payloadOffset;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    DmaTxDesc = EthHandle.stcTxDesc;
 | 
					    DmaTxDesc = EthHandle.stcTxDesc;
 | 
				
			||||||
    txBuffer = (uint8_t *)((EthHandle.stcTxDesc)->u32Buf1Addr);
 | 
					    txBuffer = (uint8_t*)((EthHandle.stcTxDesc)->u32Buf1Addr);
 | 
				
			||||||
    bufferOffset = 0UL;
 | 
					    bufferOffset = 0UL;
 | 
				
			||||||
    /* Copy frame from pbufs to driver buffers */
 | 
					    /* Copy frame from pbufs to driver buffers */
 | 
				
			||||||
    for (q = p; q != NULL; q = q->next) {
 | 
					    for (q = p; q != NULL; q = q->next) {
 | 
				
			||||||
| 
						 | 
					@ -165,28 +166,28 @@ err_t low_level_output(struct netif *netif, struct pbuf *p)
 | 
				
			||||||
        /* Check if the length of data to copy is bigger than Tx buffer size */
 | 
					        /* Check if the length of data to copy is bigger than Tx buffer size */
 | 
				
			||||||
        while ((byteCnt + bufferOffset) > ETH_TX_BUF_SIZE) {
 | 
					        while ((byteCnt + bufferOffset) > ETH_TX_BUF_SIZE) {
 | 
				
			||||||
            /* Copy data to Tx buffer*/
 | 
					            /* Copy data to Tx buffer*/
 | 
				
			||||||
            (void)memcpy((uint8_t *) & (txBuffer[bufferOffset]), (uint8_t *) & (((uint8_t *)q->payload)[payloadOffset]), (ETH_TX_BUF_SIZE - bufferOffset));
 | 
					            (void)memcpy((uint8_t*)&(txBuffer[bufferOffset]), (uint8_t*)&(((uint8_t*)q->payload)[payloadOffset]), (ETH_TX_BUF_SIZE - bufferOffset));
 | 
				
			||||||
            /* Point to next descriptor */
 | 
					            /* Point to next descriptor */
 | 
				
			||||||
            DmaTxDesc = (stc_eth_dma_desc_t *)(DmaTxDesc->u32Buf2NextDescAddr);
 | 
					            DmaTxDesc = (stc_eth_dma_desc_t*)(DmaTxDesc->u32Buf2NextDescAddr);
 | 
				
			||||||
            /* Check if the buffer is available */
 | 
					            /* Check if the buffer is available */
 | 
				
			||||||
            if (0UL != (DmaTxDesc->u32ControlStatus & ETH_DMA_TXDESC_OWN)) {
 | 
					            if (0UL != (DmaTxDesc->u32ControlStatus & ETH_DMA_TXDESC_OWN)) {
 | 
				
			||||||
                i32Ret = (err_t)ERR_USE;
 | 
					                i32Ret = (err_t)ERR_USE;
 | 
				
			||||||
                goto error;
 | 
					                goto error;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            txBuffer = (uint8_t *)(DmaTxDesc->u32Buf1Addr);
 | 
					            txBuffer = (uint8_t*)(DmaTxDesc->u32Buf1Addr);
 | 
				
			||||||
            byteCnt = byteCnt - (ETH_TX_BUF_SIZE - bufferOffset);
 | 
					            byteCnt = byteCnt - (ETH_TX_BUF_SIZE - bufferOffset);
 | 
				
			||||||
            payloadOffset = payloadOffset + (ETH_TX_BUF_SIZE - bufferOffset);
 | 
					            payloadOffset = payloadOffset + (ETH_TX_BUF_SIZE - bufferOffset);
 | 
				
			||||||
            frameLength = frameLength + (ETH_TX_BUF_SIZE - bufferOffset);
 | 
					            frameLength = frameLength + (ETH_TX_BUF_SIZE - bufferOffset);
 | 
				
			||||||
            bufferOffset = 0UL;
 | 
					            bufferOffset = 0UL;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        /* Copy the remaining bytes */
 | 
					        /* Copy the remaining bytes */
 | 
				
			||||||
        (void)memcpy((uint8_t *) & (txBuffer[bufferOffset]), (uint8_t *) & (((uint8_t *)q->payload)[payloadOffset]), byteCnt);
 | 
					        (void)memcpy((uint8_t*)&(txBuffer[bufferOffset]), (uint8_t*)&(((uint8_t*)q->payload)[payloadOffset]), byteCnt);
 | 
				
			||||||
        bufferOffset = bufferOffset + byteCnt;
 | 
					        bufferOffset = bufferOffset + byteCnt;
 | 
				
			||||||
        frameLength = frameLength + byteCnt;
 | 
					        frameLength = frameLength + byteCnt;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    /* Prepare transmit descriptors to give to DMA */
 | 
					    /* Prepare transmit descriptors to give to DMA */
 | 
				
			||||||
    if(LL_OK != ETH_DMA_SetTransFrame(&EthHandle, frameLength)) {
 | 
					    if (LL_OK != ETH_DMA_SetTransFrame(&EthHandle, frameLength)) {
 | 
				
			||||||
        KPrintf("[%s] Error sending eth DMA frame\n", __func__);
 | 
					        KPrintf("[%s] Error sending eth DMA frame\n", __func__);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    i32Ret = (err_t)ERR_OK;
 | 
					    i32Ret = (err_t)ERR_OK;
 | 
				
			||||||
| 
						 | 
					@ -208,13 +209,13 @@ error:
 | 
				
			||||||
 * @param  netif                        The network interface structure for this ethernetif.
 | 
					 * @param  netif                        The network interface structure for this ethernetif.
 | 
				
			||||||
 * @retval A pbuf filled with the received packet (including MAC header) or NULL on memory error.
 | 
					 * @retval A pbuf filled with the received packet (including MAC header) or NULL on memory error.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
struct pbuf *low_level_input(struct netif *netif)
 | 
					struct pbuf* low_level_input(struct netif* netif)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    struct pbuf *p = NULL;
 | 
					    struct pbuf* p = NULL;
 | 
				
			||||||
    struct pbuf *q;
 | 
					    struct pbuf* q;
 | 
				
			||||||
    uint32_t len;
 | 
					    uint32_t len;
 | 
				
			||||||
    uint8_t *rxBuffer;
 | 
					    uint8_t* rxBuffer;
 | 
				
			||||||
    __IO stc_eth_dma_desc_t *DmaRxDesc;
 | 
					    __IO stc_eth_dma_desc_t* DmaRxDesc;
 | 
				
			||||||
    uint32_t byteCnt;
 | 
					    uint32_t byteCnt;
 | 
				
			||||||
    uint32_t bufferOffset;
 | 
					    uint32_t bufferOffset;
 | 
				
			||||||
    uint32_t payloadOffset;
 | 
					    uint32_t payloadOffset;
 | 
				
			||||||
| 
						 | 
					@ -227,7 +228,7 @@ struct pbuf *low_level_input(struct netif *netif)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Obtain the size of the packet */
 | 
					    /* Obtain the size of the packet */
 | 
				
			||||||
    len = (EthHandle.stcRxFrame).u32Len;
 | 
					    len = (EthHandle.stcRxFrame).u32Len;
 | 
				
			||||||
    rxBuffer = (uint8_t *)(EthHandle.stcRxFrame).u32Buf;
 | 
					    rxBuffer = (uint8_t*)(EthHandle.stcRxFrame).u32Buf;
 | 
				
			||||||
    if (len > 0UL) {
 | 
					    if (len > 0UL) {
 | 
				
			||||||
        /* Allocate a pbuf chain of pbufs from the buffer */
 | 
					        /* Allocate a pbuf chain of pbufs from the buffer */
 | 
				
			||||||
        p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
 | 
					        p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
 | 
				
			||||||
| 
						 | 
					@ -243,17 +244,17 @@ struct pbuf *low_level_input(struct netif *netif)
 | 
				
			||||||
            /* Check if the length of bytes to copy in current pbuf is bigger than Rx buffer size */
 | 
					            /* Check if the length of bytes to copy in current pbuf is bigger than Rx buffer size */
 | 
				
			||||||
            while ((byteCnt + bufferOffset) > ETH_RX_BUF_SIZE) {
 | 
					            while ((byteCnt + bufferOffset) > ETH_RX_BUF_SIZE) {
 | 
				
			||||||
                /* Copy data to pbuf */
 | 
					                /* Copy data to pbuf */
 | 
				
			||||||
                (void)memcpy((uint8_t *) & (((uint8_t *)q->payload)[payloadOffset]), (uint8_t *) & (rxBuffer[bufferOffset]), (ETH_RX_BUF_SIZE - bufferOffset));
 | 
					                (void)memcpy((uint8_t*)&(((uint8_t*)q->payload)[payloadOffset]), (uint8_t*)&(rxBuffer[bufferOffset]), (ETH_RX_BUF_SIZE - bufferOffset));
 | 
				
			||||||
                /* Point to next descriptor */
 | 
					                /* Point to next descriptor */
 | 
				
			||||||
                DmaRxDesc = (stc_eth_dma_desc_t *)(DmaRxDesc->u32Buf2NextDescAddr);
 | 
					                DmaRxDesc = (stc_eth_dma_desc_t*)(DmaRxDesc->u32Buf2NextDescAddr);
 | 
				
			||||||
                rxBuffer = (uint8_t *)(DmaRxDesc->u32Buf1Addr);
 | 
					                rxBuffer = (uint8_t*)(DmaRxDesc->u32Buf1Addr);
 | 
				
			||||||
                byteCnt = byteCnt - (ETH_RX_BUF_SIZE - bufferOffset);
 | 
					                byteCnt = byteCnt - (ETH_RX_BUF_SIZE - bufferOffset);
 | 
				
			||||||
                payloadOffset = payloadOffset + (ETH_RX_BUF_SIZE - bufferOffset);
 | 
					                payloadOffset = payloadOffset + (ETH_RX_BUF_SIZE - bufferOffset);
 | 
				
			||||||
                bufferOffset = 0UL;
 | 
					                bufferOffset = 0UL;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            /* Copy remaining data in pbuf */
 | 
					            /* Copy remaining data in pbuf */
 | 
				
			||||||
            (void)memcpy((uint8_t *) & (((uint8_t *)q->payload)[payloadOffset]), (uint8_t *) & (rxBuffer[bufferOffset]), byteCnt);
 | 
					            (void)memcpy((uint8_t*)&(((uint8_t*)q->payload)[payloadOffset]), (uint8_t*)&(rxBuffer[bufferOffset]), byteCnt);
 | 
				
			||||||
            bufferOffset = bufferOffset + byteCnt;
 | 
					            bufferOffset = bufferOffset + byteCnt;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -261,7 +262,7 @@ struct pbuf *low_level_input(struct netif *netif)
 | 
				
			||||||
    DmaRxDesc = (EthHandle.stcRxFrame).pstcFSDesc;
 | 
					    DmaRxDesc = (EthHandle.stcRxFrame).pstcFSDesc;
 | 
				
			||||||
    for (i = 0UL; i < (EthHandle.stcRxFrame).u32SegCount; i++) {
 | 
					    for (i = 0UL; i < (EthHandle.stcRxFrame).u32SegCount; i++) {
 | 
				
			||||||
        DmaRxDesc->u32ControlStatus |= ETH_DMA_RXDESC_OWN;
 | 
					        DmaRxDesc->u32ControlStatus |= ETH_DMA_RXDESC_OWN;
 | 
				
			||||||
        DmaRxDesc = (stc_eth_dma_desc_t *)(DmaRxDesc->u32Buf2NextDescAddr);
 | 
					        DmaRxDesc = (stc_eth_dma_desc_t*)(DmaRxDesc->u32Buf2NextDescAddr);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    /* Clear Segment_Count */
 | 
					    /* Clear Segment_Count */
 | 
				
			||||||
    (EthHandle.stcRxFrame).u32SegCount = 0UL;
 | 
					    (EthHandle.stcRxFrame).u32SegCount = 0UL;
 | 
				
			||||||
| 
						 | 
					@ -277,11 +278,10 @@ struct pbuf *low_level_input(struct netif *netif)
 | 
				
			||||||
    return p;
 | 
					    return p;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern void LwipSetIPTest(int argc, char *argv[]);
 | 
					extern void LwipSetIPTest(int argc, char* argv[]);
 | 
				
			||||||
int HwEthInit(void) {
 | 
					int HwEthInit(void)
 | 
				
			||||||
//   lwip_config_tcp(0, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
 | 
					{
 | 
				
			||||||
 | 
					    //   lwip_config_tcp(0, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
 | 
				
			||||||
    LwipSetIPTest(1, NULL);
 | 
					    LwipSetIPTest(1, NULL);
 | 
				
			||||||
    return EOK;
 | 
					    return EOK;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,200 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
 | 
				
			||||||
 | 
					 * All rights reserved.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Redistribution and use in source and binary forms, with or without modification,
 | 
				
			||||||
 | 
					 * are permitted provided that the following conditions are met:
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * 1. Redistributions of source code must retain the above copyright notice,
 | 
				
			||||||
 | 
					 *    this list of conditions and the following disclaimer.
 | 
				
			||||||
 | 
					 * 2. Redistributions in binary form must reproduce the above copyright notice,
 | 
				
			||||||
 | 
					 *    this list of conditions and the following disclaimer in the documentation
 | 
				
			||||||
 | 
					 *    and/or other materials provided with the distribution.
 | 
				
			||||||
 | 
					 * 3. The name of the author may not be used to endorse or promote products
 | 
				
			||||||
 | 
					 *    derived from this software without specific prior written permission.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 | 
				
			||||||
 | 
					 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 | 
				
			||||||
 | 
					 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
 | 
				
			||||||
 | 
					 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 | 
				
			||||||
 | 
					 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 | 
				
			||||||
 | 
					 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 | 
				
			||||||
 | 
					 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 | 
				
			||||||
 | 
					 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 | 
				
			||||||
 | 
					 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 | 
				
			||||||
 | 
					 * OF SUCH DAMAGE.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This file is part of the lwIP TCP/IP stack.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Author: Adam Dunkels <adam@sics.se>
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					* @file eth_netdev.c
 | 
				
			||||||
 | 
					* @brief register net dev function for lwip
 | 
				
			||||||
 | 
					* @version 3.0 
 | 
				
			||||||
 | 
					* @author AIIT XUOS Lab
 | 
				
			||||||
 | 
					* @date 2023-08-07
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <connect_ethernet.h>
 | 
				
			||||||
 | 
					#include <inet.h>
 | 
				
			||||||
 | 
					#include <lwip/dhcp.h>
 | 
				
			||||||
 | 
					#include <lwip/netif.h>
 | 
				
			||||||
 | 
					#include <netdev.h>
 | 
				
			||||||
 | 
					#include <xs_kdbg.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const uint32_t NETIF_NAME_LEN = 2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int lwip_netdev_set_up(struct netdev* netdev)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    netif_set_up((struct netif*)netdev->user_data);
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int lwip_netdev_set_down(struct netdev* netif)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    netif_set_down((struct netif*)netif->user_data);
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef ip_2_ip4
 | 
				
			||||||
 | 
					#define ip_2_ip4(ipaddr) (ipaddr)
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					static int lwip_netdev_set_addr_info(struct netdev* netdev, ip_addr_t* ip_addr, ip_addr_t* netmask, ip_addr_t* gw)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (ip_addr && netmask && gw) {
 | 
				
			||||||
 | 
					        netif_set_addr((struct netif*)netdev->user_data, ip_2_ip4(ip_addr), ip_2_ip4(netmask), ip_2_ip4(gw));
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        if (ip_addr) {
 | 
				
			||||||
 | 
					            netif_set_ipaddr((struct netif*)netdev->user_data, ip_2_ip4(ip_addr));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (netmask) {
 | 
				
			||||||
 | 
					            netif_set_netmask((struct netif*)netdev->user_data, ip_2_ip4(netmask));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (gw) {
 | 
				
			||||||
 | 
					            netif_set_gw((struct netif*)netdev->user_data, ip_2_ip4(gw));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef LWIP_DNS
 | 
				
			||||||
 | 
					static int lwip_netdev_set_dns_server(struct netdev* netdev, uint8_t dns_num, ip_addr_t* dns_server)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					#if LWIP_VERSION_MAJOR == 1U /* v1.x */
 | 
				
			||||||
 | 
					    extern void dns_setserver(u8_t numdns, ip_addr_t * dnsserver);
 | 
				
			||||||
 | 
					#else /* >=2.x */
 | 
				
			||||||
 | 
					    extern void dns_setserver(uint8_t dns_num, const ip_addr_t* dns_server);
 | 
				
			||||||
 | 
					#endif /* LWIP_VERSION_MAJOR == 1U */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    dns_setserver(dns_num, dns_server);
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef LWIP_DHCP
 | 
				
			||||||
 | 
					static int lwip_netdev_set_dhcp(struct netdev* netdev, bool is_enabled)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    netdev_low_level_set_dhcp_status(netdev, is_enabled);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (true == is_enabled) {
 | 
				
			||||||
 | 
					        dhcp_start((struct netif*)netdev->user_data);
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        dhcp_stop((struct netif*)netdev->user_data);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int lwip_netdev_set_default(struct netdev* netdev)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    netif_set_default((struct netif*)netdev->user_data);
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const struct netdev_ops lwip_netdev_ops = {
 | 
				
			||||||
 | 
					    .set_up = lwip_netdev_set_up,
 | 
				
			||||||
 | 
					    .set_down = lwip_netdev_set_down,
 | 
				
			||||||
 | 
					    .set_addr_info = lwip_netdev_set_addr_info,
 | 
				
			||||||
 | 
					#ifdef LWIP_DNS
 | 
				
			||||||
 | 
					    .set_dns_server = lwip_netdev_set_dns_server,
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#ifdef LWIP_DHCP
 | 
				
			||||||
 | 
					    .set_dhcp = lwip_netdev_set_dhcp,
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					    .set_default = lwip_netdev_set_default,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int netdev_set_flags(struct netif* lwip_netif)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    CHECK(lwip_netif);
 | 
				
			||||||
 | 
					    struct netdev* netdev = netdev_get_by_name(lwip_netif->name);
 | 
				
			||||||
 | 
					    if (netdev == NULL) {
 | 
				
			||||||
 | 
					        return -ERR_IF;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    netdev->mtu = lwip_netif->mtu;
 | 
				
			||||||
 | 
					    // set flags
 | 
				
			||||||
 | 
					    if (lwip_netif->flags | NETIF_FLAG_BROADCAST) {
 | 
				
			||||||
 | 
					        netdev->flags |= NETDEV_FLAG_BROADCAST;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (lwip_netif->flags | NETIF_FLAG_ETHARP) {
 | 
				
			||||||
 | 
					        netdev->flags |= NETDEV_FLAG_ETHARP;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (lwip_netif->flags | NETIF_FLAG_IGMP) {
 | 
				
			||||||
 | 
					        netdev->flags |= NETDEV_FLAG_IGMP;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					#if LWIP_VERSION_MAJOR >= 2U /* >= v2.x */
 | 
				
			||||||
 | 
					    if (lwip_netif->flags & NETIF_FLAG_MLD6) {
 | 
				
			||||||
 | 
					        netdev->flags |= NETDEV_FLAG_MLD6;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					#endif /* LWIP_VERSION_MAJOR >= 2U */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if LWIP_DHCP
 | 
				
			||||||
 | 
					    netdev_low_level_set_dhcp_status(netdev, true);
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					    netdev_low_level_set_dhcp_status(netdev, false);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int lwip_netdev_add(struct netif* lwip_netif)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    CHECK(lwip_netif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    struct netdev* netdev = calloc(1, sizeof(struct netdev));
 | 
				
			||||||
 | 
					    if (netdev == NULL) {
 | 
				
			||||||
 | 
					        return -ERR_IF;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // init netdev
 | 
				
			||||||
 | 
					    char netif_name[NETIF_NAME_LEN + 1];
 | 
				
			||||||
 | 
					    strncpy(netif_name, lwip_netif->name, NETIF_NAME_LEN);
 | 
				
			||||||
 | 
					    // register netdev
 | 
				
			||||||
 | 
					    int result = netdev_register(netdev, netif_name, (void*)lwip_netif);
 | 
				
			||||||
 | 
					    // set values of netdev
 | 
				
			||||||
 | 
					    netdev_set_flags(lwip_netif);
 | 
				
			||||||
 | 
					    netdev->ops = &lwip_netdev_ops;
 | 
				
			||||||
 | 
					    netdev->hwaddr_len = lwip_netif->hwaddr_len;
 | 
				
			||||||
 | 
					    memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
 | 
				
			||||||
 | 
					    netdev->ip_addr = lwip_netif->ip_addr;
 | 
				
			||||||
 | 
					    netdev->gw = lwip_netif->gw;
 | 
				
			||||||
 | 
					    netdev->netmask = lwip_netif->netmask;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return result;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void lwip_netdev_del(struct netif* lwip_netif)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    char name[NETIF_NAME_LEN + 1];
 | 
				
			||||||
 | 
					    struct netdev* netdev;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    CHECK(lwip_netif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    strncpy(name, lwip_netif->name, NETIF_NAME_LEN);
 | 
				
			||||||
 | 
					    netdev = netdev_get_by_name(name);
 | 
				
			||||||
 | 
					    netdev_unregister(netdev);
 | 
				
			||||||
 | 
					    free(netdev);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -19,12 +19,12 @@
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
* @file ethernetif.c
 | 
					 * @file ethernetif.c
 | 
				
			||||||
* @brief support edu-arm32-board ethernetif function and register to Lwip
 | 
					 * @brief support hc32f4a0-board ethernetif function and register to Lwip
 | 
				
			||||||
* @version 3.0 
 | 
					 * @version 3.0
 | 
				
			||||||
* @author AIIT XUOS Lab
 | 
					 * @author AIIT XUOS Lab
 | 
				
			||||||
* @date 2022-12-05
 | 
					 * @date 2022-12-05
 | 
				
			||||||
*/
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*************************************************
 | 
					/*************************************************
 | 
				
			||||||
File name: ethernetif.c
 | 
					File name: ethernetif.c
 | 
				
			||||||
| 
						 | 
					@ -47,13 +47,15 @@ Modification:
 | 
				
			||||||
 * Include files
 | 
					 * Include files
 | 
				
			||||||
 ******************************************************************************/
 | 
					 ******************************************************************************/
 | 
				
			||||||
#include <connect_ethernet.h>
 | 
					#include <connect_ethernet.h>
 | 
				
			||||||
 | 
					#include <hc32_ll_fcg.h>
 | 
				
			||||||
#include <hc32_ll_gpio.h>
 | 
					#include <hc32_ll_gpio.h>
 | 
				
			||||||
#include <hc32_ll_utility.h>
 | 
					#include <hc32_ll_utility.h>
 | 
				
			||||||
#include <hc32_ll_fcg.h>
 | 
					 | 
				
			||||||
#include <lwip/timeouts.h>
 | 
					#include <lwip/timeouts.h>
 | 
				
			||||||
#include <netif/etharp.h>
 | 
					#include <netif/etharp.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <netdev.h>
 | 
				
			||||||
#include <xs_isr.h>
 | 
					#include <xs_isr.h>
 | 
				
			||||||
 | 
					#include <xs_kdbg.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @addtogroup HC32F4A0_DDL_Examples
 | 
					 * @addtogroup HC32F4A0_DDL_Examples
 | 
				
			||||||
| 
						 | 
					@ -73,7 +75,6 @@ Modification:
 | 
				
			||||||
 * Local pre-processor symbols/macros ('#define')
 | 
					 * Local pre-processor symbols/macros ('#define')
 | 
				
			||||||
 ******************************************************************************/
 | 
					 ******************************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
/*******************************************************************************
 | 
					/*******************************************************************************
 | 
				
			||||||
 * Global variable definitions (declared in header file with 'extern')
 | 
					 * Global variable definitions (declared in header file with 'extern')
 | 
				
			||||||
 ******************************************************************************/
 | 
					 ******************************************************************************/
 | 
				
			||||||
| 
						 | 
					@ -86,7 +87,6 @@ Modification:
 | 
				
			||||||
 * Local variable definitions ('static')
 | 
					 * Local variable definitions ('static')
 | 
				
			||||||
 ******************************************************************************/
 | 
					 ******************************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
/*******************************************************************************
 | 
					/*******************************************************************************
 | 
				
			||||||
 * Function implementation - global ('extern') and local ('static')
 | 
					 * Function implementation - global ('extern') and local ('static')
 | 
				
			||||||
 ******************************************************************************/
 | 
					 ******************************************************************************/
 | 
				
			||||||
| 
						 | 
					@ -180,41 +180,14 @@ void Ethernet_GpioInit(void)
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *ethernetif_config_enet_set(uint8_t enet_port) {
 | 
					void* ethernetif_config_enet_set(uint8_t enet_port)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return NONE;
 | 
					    return NONE;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Time_Update_LwIP(void) {
 | 
					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
 | 
					    // no need to do
 | 
				
			||||||
    /* 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 */
 | 
					 | 
				
			||||||
    return low_level_init(netif);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
| 
						 | 
					@ -222,16 +195,16 @@ err_t ethernetif_init(struct netif *netif)
 | 
				
			||||||
 * @param  netif                        The network interface structure for this ethernetif.
 | 
					 * @param  netif                        The network interface structure for this ethernetif.
 | 
				
			||||||
 * @retval None
 | 
					 * @retval None
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void ethernetif_input(void *netif_arg)
 | 
					void ethernetif_input(void* netif_arg)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    struct pbuf *p;
 | 
					    struct pbuf* p;
 | 
				
			||||||
    struct netif *netif = (struct netif *)netif_arg;
 | 
					    struct netif* netif = (struct netif*)netif_arg;
 | 
				
			||||||
    x_base critical_lock;
 | 
					    x_base critical_lock;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* Move received packet into a new pbuf */
 | 
					    /* Move received packet into a new pbuf */
 | 
				
			||||||
    while (1) {
 | 
					    while (1) {
 | 
				
			||||||
        sys_arch_sem_wait(get_eth_recv_sem(), WAITING_FOREVER);
 | 
					        sys_arch_sem_wait(get_eth_recv_sem(), WAITING_FOREVER);
 | 
				
			||||||
        while(1) {
 | 
					        while (1) {
 | 
				
			||||||
            p = low_level_input(netif);
 | 
					            p = low_level_input(netif);
 | 
				
			||||||
#ifndef ETHERNET_LOOPBACK_TEST
 | 
					#ifndef ETHERNET_LOOPBACK_TEST
 | 
				
			||||||
            /* Entry point to the LwIP stack */
 | 
					            /* Entry point to the LwIP stack */
 | 
				
			||||||
| 
						 | 
					@ -256,12 +229,51 @@ void ethernetif_input(void *netif_arg)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * @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.
 | 
					 * @brief  Check the netif link status.
 | 
				
			||||||
 * @param  netif the network interface
 | 
					 * @param  netif the network interface
 | 
				
			||||||
 * @retval None
 | 
					 * @retval None
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void EthernetIF_CheckLink(struct netif *netif)
 | 
					void EthernetIF_CheckLink(struct netif* netif)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    uint16_t u16RegVal = 0U;
 | 
					    uint16_t u16RegVal = 0U;
 | 
				
			||||||
    static uint8_t u8PreStatus = 0U;
 | 
					    static uint8_t u8PreStatus = 0U;
 | 
				
			||||||
| 
						 | 
					@ -296,7 +308,7 @@ void EthernetIF_CheckLink(struct netif *netif)
 | 
				
			||||||
 * @param  netif                        The network interface.
 | 
					 * @param  netif                        The network interface.
 | 
				
			||||||
 * @retval None
 | 
					 * @retval None
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void EthernetIF_UpdateLink(struct netif *netif)
 | 
					void EthernetIF_UpdateLink(struct netif* netif)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    uint16_t u16RegVal;
 | 
					    uint16_t u16RegVal;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -337,7 +349,7 @@ void EthernetIF_UpdateLink(struct netif *netif)
 | 
				
			||||||
 * @param  netif                        The network interface
 | 
					 * @param  netif                        The network interface
 | 
				
			||||||
 * @retval None
 | 
					 * @retval None
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void EthernetIF_PeriodicHandle(struct netif *netif)
 | 
					void EthernetIF_PeriodicHandle(struct netif* netif)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#ifndef ETH_INTERFACE_RMII
 | 
					#ifndef ETH_INTERFACE_RMII
 | 
				
			||||||
    uint32_t curTick;
 | 
					    uint32_t curTick;
 | 
				
			||||||
| 
						 | 
					@ -358,7 +370,7 @@ void EthernetIF_PeriodicHandle(struct netif *netif)
 | 
				
			||||||
 * @param  netif                        The network interface
 | 
					 * @param  netif                        The network interface
 | 
				
			||||||
 * @retval None
 | 
					 * @retval None
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void EthernetIF_LinkCallback(struct netif *netif)
 | 
					void EthernetIF_LinkCallback(struct netif* netif)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    __IO uint32_t tickStart = 0UL;
 | 
					    __IO uint32_t tickStart = 0UL;
 | 
				
			||||||
    uint16_t u16RegVal = 0U;
 | 
					    uint16_t u16RegVal = 0U;
 | 
				
			||||||
| 
						 | 
					@ -405,8 +417,7 @@ void EthernetIF_LinkCallback(struct netif *netif)
 | 
				
			||||||
            CLR_REG16_BIT(u16RegVal, PHY_FULLDUPLEX_100M);
 | 
					            CLR_REG16_BIT(u16RegVal, PHY_FULLDUPLEX_100M);
 | 
				
			||||||
            /* Set MAC Speed and Duplex Mode to PHY */
 | 
					            /* Set MAC Speed and Duplex Mode to PHY */
 | 
				
			||||||
            (void)ETH_PHY_WriteReg(&EthHandle, PHY_BCR,
 | 
					            (void)ETH_PHY_WriteReg(&EthHandle, PHY_BCR,
 | 
				
			||||||
                                   ((uint16_t)((EthHandle.stcCommInit).u32DuplexMode >> 3U) |
 | 
					                ((uint16_t)((EthHandle.stcCommInit).u32DuplexMode >> 3U) | (uint16_t)((EthHandle.stcCommInit).u32Speed >> 1U) | u16RegVal));
 | 
				
			||||||
                                    (uint16_t)((EthHandle.stcCommInit).u32Speed >> 1U) | u16RegVal));
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        /* ETH MAC Re-Configuration */
 | 
					        /* ETH MAC Re-Configuration */
 | 
				
			||||||
        ETH_MAC_SetDuplexSpeed((EthHandle.stcCommInit).u32DuplexMode, (EthHandle.stcCommInit).u32Speed);
 | 
					        ETH_MAC_SetDuplexSpeed((EthHandle.stcCommInit).u32DuplexMode, (EthHandle.stcCommInit).u32Speed);
 | 
				
			||||||
| 
						 | 
					@ -427,7 +438,7 @@ void EthernetIF_LinkCallback(struct netif *netif)
 | 
				
			||||||
 *           - LL_OK: The IF is link up
 | 
					 *           - LL_OK: The IF is link up
 | 
				
			||||||
 *           - LL_ERR: The IF is link down
 | 
					 *           - LL_ERR: The IF is link down
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
int32_t EthernetIF_IsLinkUp(struct netif *netif)
 | 
					int32_t EthernetIF_IsLinkUp(struct netif* netif)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return (0U != u8PhyLinkStatus) ? LL_OK : LL_ERR;
 | 
					    return (0U != u8PhyLinkStatus) ? LL_OK : LL_ERR;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -437,7 +448,7 @@ int32_t EthernetIF_IsLinkUp(struct netif *netif)
 | 
				
			||||||
 * @param  netif                        The network interface
 | 
					 * @param  netif                        The network interface
 | 
				
			||||||
 * @retval None
 | 
					 * @retval None
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
__WEAKDEF void EthernetIF_NotifyLinkChange(struct netif *netif)
 | 
					__WEAKDEF void EthernetIF_NotifyLinkChange(struct netif* netif)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    /* This is function could be implemented in user file when the callback is needed */
 | 
					    /* This is function could be implemented in user file when the callback is needed */
 | 
				
			||||||
    if (LL_OK == EthernetIF_IsLinkUp(netif)) {
 | 
					    if (LL_OK == EthernetIF_IsLinkUp(netif)) {
 | 
				
			||||||
| 
						 | 
					@ -453,7 +464,8 @@ __WEAKDEF void EthernetIF_NotifyLinkChange(struct netif *netif)
 | 
				
			||||||
 * @param  p                            The MAC packet to receive
 | 
					 * @param  p                            The MAC packet to receive
 | 
				
			||||||
 * @retval None
 | 
					 * @retval None
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
__WEAKDEF void EthernetIF_InputCallback(struct netif *netif, struct pbuf *p) {
 | 
					__WEAKDEF void EthernetIF_InputCallback(struct netif* netif, struct pbuf* p)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    /* This is function could be implemented in user file when the callback is needed */
 | 
					    /* This is function could be implemented in user file when the callback is needed */
 | 
				
			||||||
#ifdef ETHERNET_LOOPBACK_TEST
 | 
					#ifdef ETHERNET_LOOPBACK_TEST
 | 
				
			||||||
    if ((0 == (memcmp(p->payload, txPbuf.payload, p->len))) && (p->len == txPbuf.len)) {
 | 
					    if ((0 == (memcmp(p->payload, txPbuf.payload, p->len))) && (p->len == txPbuf.len)) {
 | 
				
			||||||
| 
						 | 
					@ -479,7 +491,7 @@ __WEAKDEF void EthernetIF_InputCallback(struct netif *netif, struct pbuf *p) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef ETHERNET_LOOPBACK_TEST
 | 
					#ifdef ETHERNET_LOOPBACK_TEST
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void EthLoopBackTask(void *parameter)
 | 
					static void EthLoopBackTask(void* parameter)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    while (1) {
 | 
					    while (1) {
 | 
				
			||||||
        if (RESET == GPIO_ReadInputPins(USER_KEY_PORT, USER_KEY_PIN)) {
 | 
					        if (RESET == GPIO_ReadInputPins(USER_KEY_PORT, USER_KEY_PIN)) {
 | 
				
			||||||
| 
						 | 
					@ -489,7 +501,7 @@ static void EthLoopBackTask(void *parameter)
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //KPrintf("ready to receive eth loop back data\n");
 | 
					        // KPrintf("ready to receive eth loop back data\n");
 | 
				
			||||||
        /* Read a received packet */
 | 
					        /* Read a received packet */
 | 
				
			||||||
        ethernetif_input(&testnetif);
 | 
					        ethernetif_input(&testnetif);
 | 
				
			||||||
        /* Handle periodic timers */
 | 
					        /* Handle periodic timers */
 | 
				
			||||||
| 
						 | 
					@ -521,8 +533,8 @@ static void EthLoopBackTest(void)
 | 
				
			||||||
    int eth_loopback_task = 0;
 | 
					    int eth_loopback_task = 0;
 | 
				
			||||||
    eth_loopback_task = KTaskCreate("eth_loopback", EthLoopBackTask, NONE,
 | 
					    eth_loopback_task = KTaskCreate("eth_loopback", EthLoopBackTask, NONE,
 | 
				
			||||||
        2048, 8);
 | 
					        2048, 8);
 | 
				
			||||||
    if(eth_loopback_task < 0) {		
 | 
					    if (eth_loopback_task < 0) {
 | 
				
			||||||
		KPrintf("eth_loopback_task create failed ...%s %d.\n", __FUNCTION__,__LINE__);
 | 
					        KPrintf("eth_loopback_task create failed ...%s %d.\n", __FUNCTION__, __LINE__);
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -530,8 +542,8 @@ static void EthLoopBackTest(void)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
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),
 | 
				
			||||||
EthLoopBackTest, EthLoopBackTest, EthLoopBackTest);
 | 
					    EthLoopBackTest, EthLoopBackTest, EthLoopBackTest);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,37 +1,36 @@
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
* Copyright (c) 2021 AIIT XUOS Lab
 | 
					 * Copyright (c) 2021 AIIT XUOS Lab
 | 
				
			||||||
* XiUOS is licensed under Mulan PSL v2.
 | 
					 * XiUOS is licensed under Mulan PSL v2.
 | 
				
			||||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
 | 
					 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 | 
				
			||||||
* You may obtain a copy of Mulan PSL v2 at:
 | 
					 * You may obtain a copy of Mulan PSL v2 at:
 | 
				
			||||||
*        http://license.coscl.org.cn/MulanPSL2
 | 
					 *        http://license.coscl.org.cn/MulanPSL2
 | 
				
			||||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 | 
					 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 | 
				
			||||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 | 
					 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 | 
				
			||||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 | 
					 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 | 
				
			||||||
* See the Mulan PSL v2 for more details.
 | 
					 * See the Mulan PSL v2 for more details.
 | 
				
			||||||
*/
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
* @file connect_ethernet.h
 | 
					 * @file connect_ethernet.h
 | 
				
			||||||
* @brief Adapted network software protocol stack and hardware operation functions
 | 
					 * @brief Adapted network software protocol stack and hardware operation functions
 | 
				
			||||||
* @version 2.0
 | 
					 * @version 2.0
 | 
				
			||||||
* @author AIIT XUOS Lab
 | 
					 * @author AIIT XUOS Lab
 | 
				
			||||||
* @date 2022-12-05
 | 
					 * @date 2022-12-05
 | 
				
			||||||
*/
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef CONNECT_ETHERNET_H
 | 
					#ifndef CONNECT_ETHERNET_H
 | 
				
			||||||
#define CONNECT_ETHERNET_H
 | 
					#define CONNECT_ETHERNET_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "hardware_ethernetif.h"
 | 
					#include "hardware_ethernetif.h"
 | 
				
			||||||
#include <sys_arch.h>
 | 
					 | 
				
			||||||
#include <hc32_ll_eth.h>
 | 
					 | 
				
			||||||
#include <hardware_irq.h>
 | 
					#include <hardware_irq.h>
 | 
				
			||||||
 | 
					#include <hc32_ll_eth.h>
 | 
				
			||||||
 | 
					#include <sys_arch.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 extern "C" {
 | 
					extern "C" {
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct hc32_irq_config
 | 
					struct hc32_irq_config {
 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    IRQn_Type irq_num;
 | 
					    IRQn_Type irq_num;
 | 
				
			||||||
    uint32_t irq_prio;
 | 
					    uint32_t irq_prio;
 | 
				
			||||||
    en_int_src_t int_src;
 | 
					    en_int_src_t int_src;
 | 
				
			||||||
| 
						 | 
					@ -58,16 +57,17 @@ static struct Hc32IrqConfig eth_irq_config = {
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Ethernet_GpioInit(void);
 | 
					void Ethernet_GpioInit(void);
 | 
				
			||||||
int32_t low_level_init(struct netif *netif);
 | 
					int32_t low_level_init(struct netif* netif);
 | 
				
			||||||
err_t low_level_output(struct netif *netif, struct pbuf *p);
 | 
					err_t low_level_output(struct netif* netif, struct pbuf* p);
 | 
				
			||||||
struct pbuf *low_level_input(struct netif *netif);
 | 
					struct pbuf* low_level_input(struct netif* netif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int lwip_netdev_add(struct netif* lwip_netif);
 | 
				
			||||||
 | 
					void lwip_netdev_del(struct netif* lwip_netif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int HwEthInit(void);
 | 
					int HwEthInit(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,3 @@
 | 
				
			||||||
SRC_FILES := enet_ethernetif.c enet_ethernetif_kinetis.c fsl_enet.c fsl_enet_qos.c
 | 
					SRC_FILES := enet_ethernetif.c enet_ethernetif_kinetis.c fsl_enet.c fsl_enet_qos.c eth_netdev.c
 | 
				
			||||||
SRC_DIR := phy mdio
 | 
					SRC_DIR := phy mdio
 | 
				
			||||||
include $(KERNEL_ROOT)/compiler.mk
 | 
					include $(KERNEL_ROOT)/compiler.mk
 | 
				
			||||||
| 
						 | 
					@ -353,5 +353,11 @@ err_t ethernetif_init(struct netif *netif,
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
 | 
					#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] Adding netdev.\n", __func__));
 | 
				
			||||||
 | 
					    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 ERR_OK;
 | 
					    return ERR_OK;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,201 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
 | 
				
			||||||
 | 
					 * All rights reserved.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Redistribution and use in source and binary forms, with or without modification,
 | 
				
			||||||
 | 
					 * are permitted provided that the following conditions are met:
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * 1. Redistributions of source code must retain the above copyright notice,
 | 
				
			||||||
 | 
					 *    this list of conditions and the following disclaimer.
 | 
				
			||||||
 | 
					 * 2. Redistributions in binary form must reproduce the above copyright notice,
 | 
				
			||||||
 | 
					 *    this list of conditions and the following disclaimer in the documentation
 | 
				
			||||||
 | 
					 *    and/or other materials provided with the distribution.
 | 
				
			||||||
 | 
					 * 3. The name of the author may not be used to endorse or promote products
 | 
				
			||||||
 | 
					 *    derived from this software without specific prior written permission.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 | 
				
			||||||
 | 
					 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 | 
				
			||||||
 | 
					 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
 | 
				
			||||||
 | 
					 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 | 
				
			||||||
 | 
					 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 | 
				
			||||||
 | 
					 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 | 
				
			||||||
 | 
					 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 | 
				
			||||||
 | 
					 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 | 
				
			||||||
 | 
					 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 | 
				
			||||||
 | 
					 * OF SUCH DAMAGE.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This file is part of the lwIP TCP/IP stack.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Author: Adam Dunkels <adam@sics.se>
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					* @file eth_netdev.c
 | 
				
			||||||
 | 
					* @brief register net dev function for lwip
 | 
				
			||||||
 | 
					* @version 3.0 
 | 
				
			||||||
 | 
					* @author AIIT XUOS Lab
 | 
				
			||||||
 | 
					* @date 2023-08-07
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <connect_ethernet.h>
 | 
				
			||||||
 | 
					#include <inet.h>
 | 
				
			||||||
 | 
					#include <lwip/dhcp.h>
 | 
				
			||||||
 | 
					#include <lwip/netif.h>
 | 
				
			||||||
 | 
					#include <netdev.h>
 | 
				
			||||||
 | 
					#include <xs_kdbg.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const uint32_t NETIF_NAME_LEN = 2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int lwip_netdev_set_up(struct netdev* netdev)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    netif_set_up((struct netif*)netdev->user_data);
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int lwip_netdev_set_down(struct netdev* netif)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    netif_set_down((struct netif*)netif->user_data);
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef ip_2_ip4
 | 
				
			||||||
 | 
					#define ip_2_ip4(ipaddr) (ipaddr)
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					static int lwip_netdev_set_addr_info(struct netdev* netdev, ip_addr_t* ip_addr, ip_addr_t* netmask, ip_addr_t* gw)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (ip_addr && netmask && gw) {
 | 
				
			||||||
 | 
					        netif_set_addr((struct netif*)netdev->user_data, ip_2_ip4(ip_addr), ip_2_ip4(netmask), ip_2_ip4(gw));
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        if (ip_addr) {
 | 
				
			||||||
 | 
					            netif_set_ipaddr((struct netif*)netdev->user_data, ip_2_ip4(ip_addr));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (netmask) {
 | 
				
			||||||
 | 
					            netif_set_netmask((struct netif*)netdev->user_data, ip_2_ip4(netmask));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (gw) {
 | 
				
			||||||
 | 
					            netif_set_gw((struct netif*)netdev->user_data, ip_2_ip4(gw));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef LWIP_DNS
 | 
				
			||||||
 | 
					static int lwip_netdev_set_dns_server(struct netdev* netdev, uint8_t dns_num, ip_addr_t* dns_server)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					#if LWIP_VERSION_MAJOR == 1U /* v1.x */
 | 
				
			||||||
 | 
					    extern void dns_setserver(u8_t numdns, ip_addr_t * dnsserver);
 | 
				
			||||||
 | 
					#else /* >=2.x */
 | 
				
			||||||
 | 
					    extern void dns_setserver(uint8_t dns_num, const ip_addr_t* dns_server);
 | 
				
			||||||
 | 
					#endif /* LWIP_VERSION_MAJOR == 1U */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    dns_setserver(dns_num, dns_server);
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef LWIP_DHCP
 | 
				
			||||||
 | 
					static int lwip_netdev_set_dhcp(struct netdev* netdev, bool is_enabled)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    netdev_low_level_set_dhcp_status(netdev, is_enabled);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (true == is_enabled) {
 | 
				
			||||||
 | 
					        dhcp_start((struct netif*)netdev->user_data);
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        dhcp_stop((struct netif*)netdev->user_data);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int lwip_netdev_set_default(struct netdev* netdev)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    netif_set_default((struct netif*)netdev->user_data);
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const struct netdev_ops lwip_netdev_ops = {
 | 
				
			||||||
 | 
					    .set_up = lwip_netdev_set_up,
 | 
				
			||||||
 | 
					    .set_down = lwip_netdev_set_down,
 | 
				
			||||||
 | 
					    .set_addr_info = lwip_netdev_set_addr_info,
 | 
				
			||||||
 | 
					#ifdef LWIP_DNS
 | 
				
			||||||
 | 
					    .set_dns_server = lwip_netdev_set_dns_server,
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#ifdef LWIP_DHCP
 | 
				
			||||||
 | 
					    .set_dhcp = lwip_netdev_set_dhcp,
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					    .set_default = lwip_netdev_set_default,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int netdev_set_flags(struct netif* lwip_netif)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    CHECK(lwip_netif);
 | 
				
			||||||
 | 
					    struct netdev* netdev = netdev_get_by_name(lwip_netif->name);
 | 
				
			||||||
 | 
					    if (netdev == NULL) {
 | 
				
			||||||
 | 
					        return -ERR_IF;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    netdev->mtu = lwip_netif->mtu;
 | 
				
			||||||
 | 
					    // set flags
 | 
				
			||||||
 | 
					    if (lwip_netif->flags | NETIF_FLAG_BROADCAST) {
 | 
				
			||||||
 | 
					        netdev->flags |= NETDEV_FLAG_BROADCAST;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (lwip_netif->flags | NETIF_FLAG_ETHARP) {
 | 
				
			||||||
 | 
					        netdev->flags |= NETDEV_FLAG_ETHARP;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (lwip_netif->flags | NETIF_FLAG_IGMP) {
 | 
				
			||||||
 | 
					        netdev->flags |= NETDEV_FLAG_IGMP;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					#if LWIP_VERSION_MAJOR >= 2U /* >= v2.x */
 | 
				
			||||||
 | 
					    if (lwip_netif->flags & NETIF_FLAG_MLD6) {
 | 
				
			||||||
 | 
					        netdev->flags |= NETDEV_FLAG_MLD6;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					#endif /* LWIP_VERSION_MAJOR >= 2U */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if LWIP_DHCP
 | 
				
			||||||
 | 
					    netdev_low_level_set_dhcp_status(netdev, true);
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					    netdev_low_level_set_dhcp_status(netdev, false);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int lwip_netdev_add(struct netif* lwip_netif)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    CHECK(lwip_netif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    struct netdev* netdev = calloc(1, sizeof(struct netdev));
 | 
				
			||||||
 | 
					    if (netdev == NULL) {
 | 
				
			||||||
 | 
					        return -ERR_IF;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // 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);
 | 
				
			||||||
 | 
					    // set values of netdev
 | 
				
			||||||
 | 
					    netdev_set_flags(lwip_netif);
 | 
				
			||||||
 | 
					    netdev->ops = &lwip_netdev_ops;
 | 
				
			||||||
 | 
					    netdev->hwaddr_len = lwip_netif->hwaddr_len;
 | 
				
			||||||
 | 
					    memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
 | 
				
			||||||
 | 
					    netdev->ip_addr = lwip_netif->ip_addr;
 | 
				
			||||||
 | 
					    netdev->gw = lwip_netif->gw;
 | 
				
			||||||
 | 
					    netdev->netmask = lwip_netif->netmask;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return result;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void lwip_netdev_del(struct netif* lwip_netif)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    char name[NETIF_NAME_LEN + 1];
 | 
				
			||||||
 | 
					    struct netdev* netdev;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    CHECK(lwip_netif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    strncpy(name, lwip_netif->name, NETIF_NAME_LEN);
 | 
				
			||||||
 | 
					    netdev = netdev_get_by_name(name);
 | 
				
			||||||
 | 
					    netdev_unregister(netdev);
 | 
				
			||||||
 | 
					    free(netdev);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -33,6 +33,8 @@
 | 
				
			||||||
#define sourceClock CLOCK_GetFreq(kCLOCK_CoreSysClk)
 | 
					#define sourceClock CLOCK_GetFreq(kCLOCK_CoreSysClk)
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int lwip_netdev_add(struct netif* lwip_netif);
 | 
				
			||||||
 | 
					void lwip_netdev_del(struct netif* lwip_netif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -164,6 +164,9 @@ void ethernetif_input( void *netif_arg);
 | 
				
			||||||
int ETH_BSP_Config(void);
 | 
					int ETH_BSP_Config(void);
 | 
				
			||||||
void *ethernetif_config_enet_set(uint8_t enet_port);
 | 
					void *ethernetif_config_enet_set(uint8_t enet_port);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int lwip_netdev_add(struct netif* lwip_netif);
 | 
				
			||||||
 | 
					void lwip_netdev_del(struct netif* lwip_netif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(__cplusplus)
 | 
					#if defined(__cplusplus)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif /* __cplusplus */
 | 
					#endif /* __cplusplus */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,3 @@
 | 
				
			||||||
SRC_FILES := enet_ethernetif.c enet_ethernetif_kinetis.c fsl_enet.c
 | 
					SRC_FILES := enet_ethernetif.c enet_ethernetif_kinetis.c fsl_enet.c eth_netdev.c
 | 
				
			||||||
SRC_DIR := ksz8081
 | 
					SRC_DIR := ksz8081
 | 
				
			||||||
include $(KERNEL_ROOT)/compiler.mk
 | 
					include $(KERNEL_ROOT)/compiler.mk
 | 
				
			||||||
| 
						 | 
					@ -68,6 +68,7 @@
 | 
				
			||||||
#include "fsl_gpio.h"
 | 
					#include "fsl_gpio.h"
 | 
				
			||||||
#include "fsl_iomuxc.h"
 | 
					#include "fsl_iomuxc.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "netdev.h"
 | 
				
			||||||
#include "sys_arch.h"
 | 
					#include "sys_arch.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*******************************************************************************
 | 
					/*******************************************************************************
 | 
				
			||||||
| 
						 | 
					@ -319,6 +320,12 @@ err_t ethernetif_init(struct netif *netif, struct ethernetif *ethernetif,
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
 | 
					#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] Adding netdev.\n", __func__));
 | 
				
			||||||
 | 
					    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 ERR_OK;
 | 
					    return ERR_OK;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,201 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
 | 
				
			||||||
 | 
					 * All rights reserved.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Redistribution and use in source and binary forms, with or without modification,
 | 
				
			||||||
 | 
					 * are permitted provided that the following conditions are met:
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * 1. Redistributions of source code must retain the above copyright notice,
 | 
				
			||||||
 | 
					 *    this list of conditions and the following disclaimer.
 | 
				
			||||||
 | 
					 * 2. Redistributions in binary form must reproduce the above copyright notice,
 | 
				
			||||||
 | 
					 *    this list of conditions and the following disclaimer in the documentation
 | 
				
			||||||
 | 
					 *    and/or other materials provided with the distribution.
 | 
				
			||||||
 | 
					 * 3. The name of the author may not be used to endorse or promote products
 | 
				
			||||||
 | 
					 *    derived from this software without specific prior written permission.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 | 
				
			||||||
 | 
					 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 | 
				
			||||||
 | 
					 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
 | 
				
			||||||
 | 
					 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 | 
				
			||||||
 | 
					 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 | 
				
			||||||
 | 
					 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 | 
				
			||||||
 | 
					 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 | 
				
			||||||
 | 
					 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 | 
				
			||||||
 | 
					 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 | 
				
			||||||
 | 
					 * OF SUCH DAMAGE.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This file is part of the lwIP TCP/IP stack.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Author: Adam Dunkels <adam@sics.se>
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					* @file eth_netdev.c
 | 
				
			||||||
 | 
					* @brief register net dev function for lwip
 | 
				
			||||||
 | 
					* @version 3.0 
 | 
				
			||||||
 | 
					* @author AIIT XUOS Lab
 | 
				
			||||||
 | 
					* @date 2023-08-07
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <connect_ethernet.h>
 | 
				
			||||||
 | 
					#include <inet.h>
 | 
				
			||||||
 | 
					#include <lwip/dhcp.h>
 | 
				
			||||||
 | 
					#include <lwip/netif.h>
 | 
				
			||||||
 | 
					#include <netdev.h>
 | 
				
			||||||
 | 
					#include <xs_kdbg.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const uint32_t NETIF_NAME_LEN = 2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int lwip_netdev_set_up(struct netdev* netdev)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    netif_set_up((struct netif*)netdev->user_data);
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int lwip_netdev_set_down(struct netdev* netif)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    netif_set_down((struct netif*)netif->user_data);
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef ip_2_ip4
 | 
				
			||||||
 | 
					#define ip_2_ip4(ipaddr) (ipaddr)
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					static int lwip_netdev_set_addr_info(struct netdev* netdev, ip_addr_t* ip_addr, ip_addr_t* netmask, ip_addr_t* gw)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (ip_addr && netmask && gw) {
 | 
				
			||||||
 | 
					        netif_set_addr((struct netif*)netdev->user_data, ip_2_ip4(ip_addr), ip_2_ip4(netmask), ip_2_ip4(gw));
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        if (ip_addr) {
 | 
				
			||||||
 | 
					            netif_set_ipaddr((struct netif*)netdev->user_data, ip_2_ip4(ip_addr));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (netmask) {
 | 
				
			||||||
 | 
					            netif_set_netmask((struct netif*)netdev->user_data, ip_2_ip4(netmask));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (gw) {
 | 
				
			||||||
 | 
					            netif_set_gw((struct netif*)netdev->user_data, ip_2_ip4(gw));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef LWIP_DNS
 | 
				
			||||||
 | 
					static int lwip_netdev_set_dns_server(struct netdev* netdev, uint8_t dns_num, ip_addr_t* dns_server)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					#if LWIP_VERSION_MAJOR == 1U /* v1.x */
 | 
				
			||||||
 | 
					    extern void dns_setserver(u8_t numdns, ip_addr_t * dnsserver);
 | 
				
			||||||
 | 
					#else /* >=2.x */
 | 
				
			||||||
 | 
					    extern void dns_setserver(uint8_t dns_num, const ip_addr_t* dns_server);
 | 
				
			||||||
 | 
					#endif /* LWIP_VERSION_MAJOR == 1U */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    dns_setserver(dns_num, dns_server);
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef LWIP_DHCP
 | 
				
			||||||
 | 
					static int lwip_netdev_set_dhcp(struct netdev* netdev, bool is_enabled)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    netdev_low_level_set_dhcp_status(netdev, is_enabled);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (true == is_enabled) {
 | 
				
			||||||
 | 
					        dhcp_start((struct netif*)netdev->user_data);
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        dhcp_stop((struct netif*)netdev->user_data);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int lwip_netdev_set_default(struct netdev* netdev)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    netif_set_default((struct netif*)netdev->user_data);
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const struct netdev_ops lwip_netdev_ops = {
 | 
				
			||||||
 | 
					    .set_up = lwip_netdev_set_up,
 | 
				
			||||||
 | 
					    .set_down = lwip_netdev_set_down,
 | 
				
			||||||
 | 
					    .set_addr_info = lwip_netdev_set_addr_info,
 | 
				
			||||||
 | 
					#ifdef LWIP_DNS
 | 
				
			||||||
 | 
					    .set_dns_server = lwip_netdev_set_dns_server,
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#ifdef LWIP_DHCP
 | 
				
			||||||
 | 
					    .set_dhcp = lwip_netdev_set_dhcp,
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					    .set_default = lwip_netdev_set_default,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int netdev_set_flags(struct netif* lwip_netif)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    CHECK(lwip_netif);
 | 
				
			||||||
 | 
					    struct netdev* netdev = netdev_get_by_name(lwip_netif->name);
 | 
				
			||||||
 | 
					    if (netdev == NULL) {
 | 
				
			||||||
 | 
					        return -ERR_IF;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    netdev->mtu = lwip_netif->mtu;
 | 
				
			||||||
 | 
					    // set flags
 | 
				
			||||||
 | 
					    if (lwip_netif->flags | NETIF_FLAG_BROADCAST) {
 | 
				
			||||||
 | 
					        netdev->flags |= NETDEV_FLAG_BROADCAST;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (lwip_netif->flags | NETIF_FLAG_ETHARP) {
 | 
				
			||||||
 | 
					        netdev->flags |= NETDEV_FLAG_ETHARP;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (lwip_netif->flags | NETIF_FLAG_IGMP) {
 | 
				
			||||||
 | 
					        netdev->flags |= NETDEV_FLAG_IGMP;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					#if LWIP_VERSION_MAJOR >= 2U /* >= v2.x */
 | 
				
			||||||
 | 
					    if (lwip_netif->flags & NETIF_FLAG_MLD6) {
 | 
				
			||||||
 | 
					        netdev->flags |= NETDEV_FLAG_MLD6;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					#endif /* LWIP_VERSION_MAJOR >= 2U */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if LWIP_DHCP
 | 
				
			||||||
 | 
					    netdev_low_level_set_dhcp_status(netdev, true);
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					    netdev_low_level_set_dhcp_status(netdev, false);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int lwip_netdev_add(struct netif* lwip_netif)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    CHECK(lwip_netif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    struct netdev* netdev = calloc(1, sizeof(struct netdev));
 | 
				
			||||||
 | 
					    if (netdev == NULL) {
 | 
				
			||||||
 | 
					        return -ERR_IF;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // 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);
 | 
				
			||||||
 | 
					    // set values of netdev
 | 
				
			||||||
 | 
					    netdev_set_flags(lwip_netif);
 | 
				
			||||||
 | 
					    netdev->ops = &lwip_netdev_ops;
 | 
				
			||||||
 | 
					    netdev->hwaddr_len = lwip_netif->hwaddr_len;
 | 
				
			||||||
 | 
					    memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
 | 
				
			||||||
 | 
					    netdev->ip_addr = lwip_netif->ip_addr;
 | 
				
			||||||
 | 
					    netdev->gw = lwip_netif->gw;
 | 
				
			||||||
 | 
					    netdev->netmask = lwip_netif->netmask;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return result;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void lwip_netdev_del(struct netif* lwip_netif)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    char name[NETIF_NAME_LEN + 1];
 | 
				
			||||||
 | 
					    struct netdev* netdev;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    CHECK(lwip_netif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    strncpy(name, lwip_netif->name, NETIF_NAME_LEN);
 | 
				
			||||||
 | 
					    netdev = netdev_get_by_name(name);
 | 
				
			||||||
 | 
					    netdev_unregister(netdev);
 | 
				
			||||||
 | 
					    free(netdev);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -33,6 +33,8 @@
 | 
				
			||||||
#define sourceClock CLOCK_GetFreq(kCLOCK_CoreSysClk)
 | 
					#define sourceClock CLOCK_GetFreq(kCLOCK_CoreSysClk)
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int lwip_netdev_add(struct netif* lwip_netif);
 | 
				
			||||||
 | 
					void lwip_netdev_del(struct netif* lwip_netif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -181,11 +181,14 @@ err_t ethernetif1_init(struct netif *netif);
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
void ethernetif_input( void *netif_arg);
 | 
					void ethernetif_input( void *netif_arg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void ETH_BSP_Config(void);
 | 
					int ETH_BSP_Config(void);
 | 
				
			||||||
void *ethernetif_config_enet_set(uint8_t enet_port);
 | 
					void *ethernetif_config_enet_set(uint8_t enet_port);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int32 lwip_obtain_semaphore(struct netif *netif);
 | 
					int32 lwip_obtain_semaphore(struct netif *netif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int lwip_netdev_add(struct netif* lwip_netif);
 | 
				
			||||||
 | 
					void lwip_netdev_del(struct netif* lwip_netif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define NETIF_ENET0_INIT_FUNC ethernetif0_init
 | 
					#define NETIF_ENET0_INIT_FUNC ethernetif0_init
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(__cplusplus)
 | 
					#if defined(__cplusplus)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,3 @@
 | 
				
			||||||
SRC_FILES := enet_ethernetif.c enet_ethernetif_kinetis.c fsl_enet.c
 | 
					SRC_FILES := enet_ethernetif.c enet_ethernetif_kinetis.c fsl_enet.c eth_netdev.c
 | 
				
			||||||
SRC_DIR := lan8720
 | 
					SRC_DIR := lan8720
 | 
				
			||||||
include $(KERNEL_ROOT)/compiler.mk
 | 
					include $(KERNEL_ROOT)/compiler.mk
 | 
				
			||||||
| 
						 | 
					@ -68,6 +68,7 @@
 | 
				
			||||||
#include "fsl_gpio.h"
 | 
					#include "fsl_gpio.h"
 | 
				
			||||||
#include "fsl_iomuxc.h"
 | 
					#include "fsl_iomuxc.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "netdev.h"
 | 
				
			||||||
#include "sys_arch.h"
 | 
					#include "sys_arch.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*******************************************************************************
 | 
					/*******************************************************************************
 | 
				
			||||||
| 
						 | 
					@ -319,6 +320,12 @@ err_t ethernetif_init(struct netif *netif, struct ethernetif *ethernetif,
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
 | 
					#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] Adding netdev.\n", __func__));
 | 
				
			||||||
 | 
					    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 ERR_OK;
 | 
					    return ERR_OK;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,201 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
 | 
				
			||||||
 | 
					 * All rights reserved.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Redistribution and use in source and binary forms, with or without modification,
 | 
				
			||||||
 | 
					 * are permitted provided that the following conditions are met:
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * 1. Redistributions of source code must retain the above copyright notice,
 | 
				
			||||||
 | 
					 *    this list of conditions and the following disclaimer.
 | 
				
			||||||
 | 
					 * 2. Redistributions in binary form must reproduce the above copyright notice,
 | 
				
			||||||
 | 
					 *    this list of conditions and the following disclaimer in the documentation
 | 
				
			||||||
 | 
					 *    and/or other materials provided with the distribution.
 | 
				
			||||||
 | 
					 * 3. The name of the author may not be used to endorse or promote products
 | 
				
			||||||
 | 
					 *    derived from this software without specific prior written permission.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 | 
				
			||||||
 | 
					 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 | 
				
			||||||
 | 
					 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
 | 
				
			||||||
 | 
					 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 | 
				
			||||||
 | 
					 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 | 
				
			||||||
 | 
					 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 | 
				
			||||||
 | 
					 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 | 
				
			||||||
 | 
					 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 | 
				
			||||||
 | 
					 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 | 
				
			||||||
 | 
					 * OF SUCH DAMAGE.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This file is part of the lwIP TCP/IP stack.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Author: Adam Dunkels <adam@sics.se>
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					* @file eth_netdev.c
 | 
				
			||||||
 | 
					* @brief register net dev function for lwip
 | 
				
			||||||
 | 
					* @version 3.0 
 | 
				
			||||||
 | 
					* @author AIIT XUOS Lab
 | 
				
			||||||
 | 
					* @date 2023-08-07
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <connect_ethernet.h>
 | 
				
			||||||
 | 
					#include <inet.h>
 | 
				
			||||||
 | 
					#include <lwip/dhcp.h>
 | 
				
			||||||
 | 
					#include <lwip/netif.h>
 | 
				
			||||||
 | 
					#include <netdev.h>
 | 
				
			||||||
 | 
					#include <xs_kdbg.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const uint32_t NETIF_NAME_LEN = 2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int lwip_netdev_set_up(struct netdev* netdev)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    netif_set_up((struct netif*)netdev->user_data);
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int lwip_netdev_set_down(struct netdev* netif)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    netif_set_down((struct netif*)netif->user_data);
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef ip_2_ip4
 | 
				
			||||||
 | 
					#define ip_2_ip4(ipaddr) (ipaddr)
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					static int lwip_netdev_set_addr_info(struct netdev* netdev, ip_addr_t* ip_addr, ip_addr_t* netmask, ip_addr_t* gw)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (ip_addr && netmask && gw) {
 | 
				
			||||||
 | 
					        netif_set_addr((struct netif*)netdev->user_data, ip_2_ip4(ip_addr), ip_2_ip4(netmask), ip_2_ip4(gw));
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        if (ip_addr) {
 | 
				
			||||||
 | 
					            netif_set_ipaddr((struct netif*)netdev->user_data, ip_2_ip4(ip_addr));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (netmask) {
 | 
				
			||||||
 | 
					            netif_set_netmask((struct netif*)netdev->user_data, ip_2_ip4(netmask));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (gw) {
 | 
				
			||||||
 | 
					            netif_set_gw((struct netif*)netdev->user_data, ip_2_ip4(gw));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef LWIP_DNS
 | 
				
			||||||
 | 
					static int lwip_netdev_set_dns_server(struct netdev* netdev, uint8_t dns_num, ip_addr_t* dns_server)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					#if LWIP_VERSION_MAJOR == 1U /* v1.x */
 | 
				
			||||||
 | 
					    extern void dns_setserver(u8_t numdns, ip_addr_t * dnsserver);
 | 
				
			||||||
 | 
					#else /* >=2.x */
 | 
				
			||||||
 | 
					    extern void dns_setserver(uint8_t dns_num, const ip_addr_t* dns_server);
 | 
				
			||||||
 | 
					#endif /* LWIP_VERSION_MAJOR == 1U */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    dns_setserver(dns_num, dns_server);
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef LWIP_DHCP
 | 
				
			||||||
 | 
					static int lwip_netdev_set_dhcp(struct netdev* netdev, bool is_enabled)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    netdev_low_level_set_dhcp_status(netdev, is_enabled);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (true == is_enabled) {
 | 
				
			||||||
 | 
					        dhcp_start((struct netif*)netdev->user_data);
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        dhcp_stop((struct netif*)netdev->user_data);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int lwip_netdev_set_default(struct netdev* netdev)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    netif_set_default((struct netif*)netdev->user_data);
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const struct netdev_ops lwip_netdev_ops = {
 | 
				
			||||||
 | 
					    .set_up = lwip_netdev_set_up,
 | 
				
			||||||
 | 
					    .set_down = lwip_netdev_set_down,
 | 
				
			||||||
 | 
					    .set_addr_info = lwip_netdev_set_addr_info,
 | 
				
			||||||
 | 
					#ifdef LWIP_DNS
 | 
				
			||||||
 | 
					    .set_dns_server = lwip_netdev_set_dns_server,
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#ifdef LWIP_DHCP
 | 
				
			||||||
 | 
					    .set_dhcp = lwip_netdev_set_dhcp,
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					    .set_default = lwip_netdev_set_default,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int netdev_set_flags(struct netif* lwip_netif)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    CHECK(lwip_netif);
 | 
				
			||||||
 | 
					    struct netdev* netdev = netdev_get_by_name(lwip_netif->name);
 | 
				
			||||||
 | 
					    if (netdev == NULL) {
 | 
				
			||||||
 | 
					        return -ERR_IF;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    netdev->mtu = lwip_netif->mtu;
 | 
				
			||||||
 | 
					    // set flags
 | 
				
			||||||
 | 
					    if (lwip_netif->flags | NETIF_FLAG_BROADCAST) {
 | 
				
			||||||
 | 
					        netdev->flags |= NETDEV_FLAG_BROADCAST;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (lwip_netif->flags | NETIF_FLAG_ETHARP) {
 | 
				
			||||||
 | 
					        netdev->flags |= NETDEV_FLAG_ETHARP;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (lwip_netif->flags | NETIF_FLAG_IGMP) {
 | 
				
			||||||
 | 
					        netdev->flags |= NETDEV_FLAG_IGMP;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					#if LWIP_VERSION_MAJOR >= 2U /* >= v2.x */
 | 
				
			||||||
 | 
					    if (lwip_netif->flags & NETIF_FLAG_MLD6) {
 | 
				
			||||||
 | 
					        netdev->flags |= NETDEV_FLAG_MLD6;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					#endif /* LWIP_VERSION_MAJOR >= 2U */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if LWIP_DHCP
 | 
				
			||||||
 | 
					    netdev_low_level_set_dhcp_status(netdev, true);
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					    netdev_low_level_set_dhcp_status(netdev, false);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int lwip_netdev_add(struct netif* lwip_netif)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    CHECK(lwip_netif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    struct netdev* netdev = calloc(1, sizeof(struct netdev));
 | 
				
			||||||
 | 
					    if (netdev == NULL) {
 | 
				
			||||||
 | 
					        return -ERR_IF;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // 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);
 | 
				
			||||||
 | 
					    // set values of netdev
 | 
				
			||||||
 | 
					    netdev_set_flags(lwip_netif);
 | 
				
			||||||
 | 
					    netdev->ops = &lwip_netdev_ops;
 | 
				
			||||||
 | 
					    netdev->hwaddr_len = lwip_netif->hwaddr_len;
 | 
				
			||||||
 | 
					    memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
 | 
				
			||||||
 | 
					    netdev->ip_addr = lwip_netif->ip_addr;
 | 
				
			||||||
 | 
					    netdev->gw = lwip_netif->gw;
 | 
				
			||||||
 | 
					    netdev->netmask = lwip_netif->netmask;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return result;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void lwip_netdev_del(struct netif* lwip_netif)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    char name[NETIF_NAME_LEN + 1];
 | 
				
			||||||
 | 
					    struct netdev* netdev;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    CHECK(lwip_netif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    strncpy(name, lwip_netif->name, NETIF_NAME_LEN);
 | 
				
			||||||
 | 
					    netdev = netdev_get_by_name(name);
 | 
				
			||||||
 | 
					    netdev_unregister(netdev);
 | 
				
			||||||
 | 
					    free(netdev);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -33,6 +33,8 @@
 | 
				
			||||||
#define sourceClock CLOCK_GetFreq(kCLOCK_CoreSysClk)
 | 
					#define sourceClock CLOCK_GetFreq(kCLOCK_CoreSysClk)
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int lwip_netdev_add(struct netif* lwip_netif);
 | 
				
			||||||
 | 
					void lwip_netdev_del(struct netif* lwip_netif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -185,6 +185,9 @@ int ETH_BSP_Config(void);
 | 
				
			||||||
void *ethernetif_config_enet_set(uint8_t enet_port);
 | 
					void *ethernetif_config_enet_set(uint8_t enet_port);
 | 
				
			||||||
int32 lwip_obtain_semaphore(struct netif *netif);
 | 
					int32 lwip_obtain_semaphore(struct netif *netif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int lwip_netdev_add(struct netif* lwip_netif);
 | 
				
			||||||
 | 
					void lwip_netdev_del(struct netif* lwip_netif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define NETIF_ENET0_INIT_FUNC ethernetif0_init
 | 
					#define NETIF_ENET0_INIT_FUNC ethernetif0_init
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(__cplusplus)
 | 
					#if defined(__cplusplus)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,3 @@
 | 
				
			||||||
SRC_FILES := enet_ethernetif.c enet_ethernetif_kinetis.c fsl_enet.c
 | 
					SRC_FILES := enet_ethernetif.c enet_ethernetif_kinetis.c fsl_enet.c eth_netdev.c
 | 
				
			||||||
SRC_DIR := lan8720
 | 
					SRC_DIR := lan8720
 | 
				
			||||||
include $(KERNEL_ROOT)/compiler.mk
 | 
					include $(KERNEL_ROOT)/compiler.mk
 | 
				
			||||||
| 
						 | 
					@ -68,6 +68,7 @@
 | 
				
			||||||
#include "fsl_gpio.h"
 | 
					#include "fsl_gpio.h"
 | 
				
			||||||
#include "fsl_iomuxc.h"
 | 
					#include "fsl_iomuxc.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "netdev.h"
 | 
				
			||||||
#include "sys_arch.h"
 | 
					#include "sys_arch.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*******************************************************************************
 | 
					/*******************************************************************************
 | 
				
			||||||
| 
						 | 
					@ -319,6 +320,12 @@ err_t ethernetif_init(struct netif *netif, struct ethernetif *ethernetif,
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
 | 
					#endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] Adding netdev.\n", __func__));
 | 
				
			||||||
 | 
					    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 ERR_OK;
 | 
					    return ERR_OK;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,201 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
 | 
				
			||||||
 | 
					 * All rights reserved.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Redistribution and use in source and binary forms, with or without modification,
 | 
				
			||||||
 | 
					 * are permitted provided that the following conditions are met:
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * 1. Redistributions of source code must retain the above copyright notice,
 | 
				
			||||||
 | 
					 *    this list of conditions and the following disclaimer.
 | 
				
			||||||
 | 
					 * 2. Redistributions in binary form must reproduce the above copyright notice,
 | 
				
			||||||
 | 
					 *    this list of conditions and the following disclaimer in the documentation
 | 
				
			||||||
 | 
					 *    and/or other materials provided with the distribution.
 | 
				
			||||||
 | 
					 * 3. The name of the author may not be used to endorse or promote products
 | 
				
			||||||
 | 
					 *    derived from this software without specific prior written permission.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 | 
				
			||||||
 | 
					 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 | 
				
			||||||
 | 
					 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
 | 
				
			||||||
 | 
					 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 | 
				
			||||||
 | 
					 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 | 
				
			||||||
 | 
					 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 | 
				
			||||||
 | 
					 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 | 
				
			||||||
 | 
					 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 | 
				
			||||||
 | 
					 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 | 
				
			||||||
 | 
					 * OF SUCH DAMAGE.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * This file is part of the lwIP TCP/IP stack.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Author: Adam Dunkels <adam@sics.se>
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					* @file eth_netdev.c
 | 
				
			||||||
 | 
					* @brief register net dev function for lwip
 | 
				
			||||||
 | 
					* @version 3.0 
 | 
				
			||||||
 | 
					* @author AIIT XUOS Lab
 | 
				
			||||||
 | 
					* @date 2023-08-07
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <connect_ethernet.h>
 | 
				
			||||||
 | 
					#include <inet.h>
 | 
				
			||||||
 | 
					#include <lwip/dhcp.h>
 | 
				
			||||||
 | 
					#include <lwip/netif.h>
 | 
				
			||||||
 | 
					#include <netdev.h>
 | 
				
			||||||
 | 
					#include <xs_kdbg.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const uint32_t NETIF_NAME_LEN = 2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int lwip_netdev_set_up(struct netdev* netdev)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    netif_set_up((struct netif*)netdev->user_data);
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int lwip_netdev_set_down(struct netdev* netif)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    netif_set_down((struct netif*)netif->user_data);
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef ip_2_ip4
 | 
				
			||||||
 | 
					#define ip_2_ip4(ipaddr) (ipaddr)
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					static int lwip_netdev_set_addr_info(struct netdev* netdev, ip_addr_t* ip_addr, ip_addr_t* netmask, ip_addr_t* gw)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (ip_addr && netmask && gw) {
 | 
				
			||||||
 | 
					        netif_set_addr((struct netif*)netdev->user_data, ip_2_ip4(ip_addr), ip_2_ip4(netmask), ip_2_ip4(gw));
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        if (ip_addr) {
 | 
				
			||||||
 | 
					            netif_set_ipaddr((struct netif*)netdev->user_data, ip_2_ip4(ip_addr));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (netmask) {
 | 
				
			||||||
 | 
					            netif_set_netmask((struct netif*)netdev->user_data, ip_2_ip4(netmask));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (gw) {
 | 
				
			||||||
 | 
					            netif_set_gw((struct netif*)netdev->user_data, ip_2_ip4(gw));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef LWIP_DNS
 | 
				
			||||||
 | 
					static int lwip_netdev_set_dns_server(struct netdev* netdev, uint8_t dns_num, ip_addr_t* dns_server)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					#if LWIP_VERSION_MAJOR == 1U /* v1.x */
 | 
				
			||||||
 | 
					    extern void dns_setserver(u8_t numdns, ip_addr_t * dnsserver);
 | 
				
			||||||
 | 
					#else /* >=2.x */
 | 
				
			||||||
 | 
					    extern void dns_setserver(uint8_t dns_num, const ip_addr_t* dns_server);
 | 
				
			||||||
 | 
					#endif /* LWIP_VERSION_MAJOR == 1U */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    dns_setserver(dns_num, dns_server);
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef LWIP_DHCP
 | 
				
			||||||
 | 
					static int lwip_netdev_set_dhcp(struct netdev* netdev, bool is_enabled)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    netdev_low_level_set_dhcp_status(netdev, is_enabled);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (true == is_enabled) {
 | 
				
			||||||
 | 
					        dhcp_start((struct netif*)netdev->user_data);
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        dhcp_stop((struct netif*)netdev->user_data);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int lwip_netdev_set_default(struct netdev* netdev)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    netif_set_default((struct netif*)netdev->user_data);
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const struct netdev_ops lwip_netdev_ops = {
 | 
				
			||||||
 | 
					    .set_up = lwip_netdev_set_up,
 | 
				
			||||||
 | 
					    .set_down = lwip_netdev_set_down,
 | 
				
			||||||
 | 
					    .set_addr_info = lwip_netdev_set_addr_info,
 | 
				
			||||||
 | 
					#ifdef LWIP_DNS
 | 
				
			||||||
 | 
					    .set_dns_server = lwip_netdev_set_dns_server,
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#ifdef LWIP_DHCP
 | 
				
			||||||
 | 
					    .set_dhcp = lwip_netdev_set_dhcp,
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					    .set_default = lwip_netdev_set_default,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline int netdev_set_flags(struct netif* lwip_netif)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    CHECK(lwip_netif);
 | 
				
			||||||
 | 
					    struct netdev* netdev = netdev_get_by_name(lwip_netif->name);
 | 
				
			||||||
 | 
					    if (netdev == NULL) {
 | 
				
			||||||
 | 
					        return -ERR_IF;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    netdev->mtu = lwip_netif->mtu;
 | 
				
			||||||
 | 
					    // set flags
 | 
				
			||||||
 | 
					    if (lwip_netif->flags | NETIF_FLAG_BROADCAST) {
 | 
				
			||||||
 | 
					        netdev->flags |= NETDEV_FLAG_BROADCAST;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (lwip_netif->flags | NETIF_FLAG_ETHARP) {
 | 
				
			||||||
 | 
					        netdev->flags |= NETDEV_FLAG_ETHARP;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (lwip_netif->flags | NETIF_FLAG_IGMP) {
 | 
				
			||||||
 | 
					        netdev->flags |= NETDEV_FLAG_IGMP;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					#if LWIP_VERSION_MAJOR >= 2U /* >= v2.x */
 | 
				
			||||||
 | 
					    if (lwip_netif->flags & NETIF_FLAG_MLD6) {
 | 
				
			||||||
 | 
					        netdev->flags |= NETDEV_FLAG_MLD6;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					#endif /* LWIP_VERSION_MAJOR >= 2U */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if LWIP_DHCP
 | 
				
			||||||
 | 
					    netdev_low_level_set_dhcp_status(netdev, true);
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					    netdev_low_level_set_dhcp_status(netdev, false);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return ERR_OK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int lwip_netdev_add(struct netif* lwip_netif)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    CHECK(lwip_netif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    struct netdev* netdev = calloc(1, sizeof(struct netdev));
 | 
				
			||||||
 | 
					    if (netdev == NULL) {
 | 
				
			||||||
 | 
					        return -ERR_IF;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // 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);
 | 
				
			||||||
 | 
					    // set values of netdev
 | 
				
			||||||
 | 
					    netdev_set_flags(lwip_netif);
 | 
				
			||||||
 | 
					    netdev->ops = &lwip_netdev_ops;
 | 
				
			||||||
 | 
					    netdev->hwaddr_len = lwip_netif->hwaddr_len;
 | 
				
			||||||
 | 
					    memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
 | 
				
			||||||
 | 
					    netdev->ip_addr = lwip_netif->ip_addr;
 | 
				
			||||||
 | 
					    netdev->gw = lwip_netif->gw;
 | 
				
			||||||
 | 
					    netdev->netmask = lwip_netif->netmask;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return result;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void lwip_netdev_del(struct netif* lwip_netif)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    char name[NETIF_NAME_LEN + 1];
 | 
				
			||||||
 | 
					    struct netdev* netdev;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    CHECK(lwip_netif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    strncpy(name, lwip_netif->name, NETIF_NAME_LEN);
 | 
				
			||||||
 | 
					    netdev = netdev_get_by_name(name);
 | 
				
			||||||
 | 
					    netdev_unregister(netdev);
 | 
				
			||||||
 | 
					    free(netdev);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1,22 +1,22 @@
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
* Copyright (c) 2021 AIIT XUOS Lab
 | 
					 * Copyright (c) 2021 AIIT XUOS Lab
 | 
				
			||||||
* XiUOS is licensed under Mulan PSL v2.
 | 
					 * XiUOS is licensed under Mulan PSL v2.
 | 
				
			||||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
 | 
					 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 | 
				
			||||||
* You may obtain a copy of Mulan PSL v2 at:
 | 
					 * You may obtain a copy of Mulan PSL v2 at:
 | 
				
			||||||
*        http://license.coscl.org.cn/MulanPSL2
 | 
					 *        http://license.coscl.org.cn/MulanPSL2
 | 
				
			||||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 | 
					 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 | 
				
			||||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 | 
					 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 | 
				
			||||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 | 
					 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 | 
				
			||||||
* See the Mulan PSL v2 for more details.
 | 
					 * See the Mulan PSL v2 for more details.
 | 
				
			||||||
*/
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
* @file connect_ethernet.h
 | 
					 * @file connect_ethernet.h
 | 
				
			||||||
* @brief Adapted network software protocol stack and hardware operation functions
 | 
					 * @brief Adapted network software protocol stack and hardware operation functions
 | 
				
			||||||
* @version 1.0
 | 
					 * @version 1.0
 | 
				
			||||||
* @author AIIT XUOS Lab
 | 
					 * @author AIIT XUOS Lab
 | 
				
			||||||
* @date 2021-12-7
 | 
					 * @date 2021-12-7
 | 
				
			||||||
*/
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef __CONNECT_ETHERNET_H_
 | 
					#ifndef __CONNECT_ETHERNET_H_
 | 
				
			||||||
#define __CONNECT_ETHERNET_H_
 | 
					#define __CONNECT_ETHERNET_H_
 | 
				
			||||||
| 
						 | 
					@ -25,17 +25,18 @@
 | 
				
			||||||
#include "enet_ethernetif_priv.h"
 | 
					#include "enet_ethernetif_priv.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 extern "C" {
 | 
					extern "C" {
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef sourceClock
 | 
					#ifndef sourceClock
 | 
				
			||||||
#define sourceClock CLOCK_GetFreq(kCLOCK_CoreSysClk)
 | 
					#define sourceClock CLOCK_GetFreq(kCLOCK_CoreSysClk)
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int lwip_netdev_add(struct netif* lwip_netif);
 | 
				
			||||||
 | 
					void lwip_netdev_del(struct netif* lwip_netif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -185,6 +185,9 @@ int ETH_BSP_Config(void);
 | 
				
			||||||
void *ethernetif_config_enet_set(uint8_t enet_port);
 | 
					void *ethernetif_config_enet_set(uint8_t enet_port);
 | 
				
			||||||
int32 lwip_obtain_semaphore(struct netif *netif);
 | 
					int32 lwip_obtain_semaphore(struct netif *netif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int lwip_netdev_add(struct netif* lwip_netif);
 | 
				
			||||||
 | 
					void lwip_netdev_del(struct netif* lwip_netif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define NETIF_ENET0_INIT_FUNC ethernetif0_init
 | 
					#define NETIF_ENET0_INIT_FUNC ethernetif0_init
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(__cplusplus)
 | 
					#if defined(__cplusplus)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -772,7 +772,8 @@ int stat(const char *path, struct stat *buf)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ret = mp->fs->stat(mp, relpath, &vfs_statbuf);
 | 
					    ret = mp->fs->stat(mp, relpath, &vfs_statbuf);
 | 
				
			||||||
    if (ret < 0) {
 | 
					    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;
 | 
					        goto err;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -790,7 +791,6 @@ err:
 | 
				
			||||||
    free(abspath);
 | 
					    free(abspath);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (ret < 0) {
 | 
					    if (ret < 0) {
 | 
				
			||||||
        KUpdateExstatus(ret);
 | 
					 | 
				
			||||||
        return -1;
 | 
					        return -1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,23 +1,23 @@
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
* Copyright (c) 2020 AIIT XUOS Lab
 | 
					 * Copyright (c) 2020 AIIT XUOS Lab
 | 
				
			||||||
* XiUOS is licensed under Mulan PSL v2.
 | 
					 * XiUOS is licensed under Mulan PSL v2.
 | 
				
			||||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
 | 
					 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 | 
				
			||||||
* You may obtain a copy of Mulan PSL v2 at:
 | 
					 * You may obtain a copy of Mulan PSL v2 at:
 | 
				
			||||||
*        http://license.coscl.org.cn/MulanPSL2
 | 
					 *        http://license.coscl.org.cn/MulanPSL2
 | 
				
			||||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 | 
					 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 | 
				
			||||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 | 
					 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 | 
				
			||||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 | 
					 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 | 
				
			||||||
* See the Mulan PSL v2 for more details.
 | 
					 * See the Mulan PSL v2 for more details.
 | 
				
			||||||
*/
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
* @file:    xs_kdbg.h
 | 
					 * @file:    xs_kdbg.h
 | 
				
			||||||
* @brief:   function declaration and structure defintion of kernel debug
 | 
					 * @brief:   function declaration and structure defintion of kernel debug
 | 
				
			||||||
* @version: 1.0
 | 
					 * @version: 1.0
 | 
				
			||||||
* @author:  AIIT XUOS Lab
 | 
					 * @author:  AIIT XUOS Lab
 | 
				
			||||||
* @date:    2020/4/20
 | 
					 * @date:    2020/4/20
 | 
				
			||||||
*
 | 
					 *
 | 
				
			||||||
*/
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifndef XS_KDBG_H
 | 
					#ifndef XS_KDBG_H
 | 
				
			||||||
#define XS_KDBG_H
 | 
					#define XS_KDBG_H
 | 
				
			||||||
| 
						 | 
					@ -28,6 +28,8 @@
 | 
				
			||||||
extern "C" {
 | 
					extern "C" {
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define KERNEL_DEBUG
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef KERNEL_DEBUG
 | 
					#ifdef KERNEL_DEBUG
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*Kernel Section Debug Define*/
 | 
					/*Kernel Section Debug Define*/
 | 
				
			||||||
| 
						 | 
					@ -40,13 +42,17 @@ extern "C" {
 | 
				
			||||||
#define KDBG_IPC 0
 | 
					#define KDBG_IPC 0
 | 
				
			||||||
#define KDBG_HOOK 0
 | 
					#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) \
 | 
					#define SYS_KDEBUG_LOG(section, information) \
 | 
				
			||||||
    do                                               \
 | 
					    do {                                     \
 | 
				
			||||||
    {                                                \
 | 
					        if (section) {                       \
 | 
				
			||||||
        if(section) {                                \
 | 
					 | 
				
			||||||
            KPrintf information;             \
 | 
					            KPrintf information;             \
 | 
				
			||||||
        }                                    \
 | 
					        }                                    \
 | 
				
			||||||
    }while (0)                                       
 | 
					    } while (0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define KDYN_NONE 0
 | 
					#define KDYN_NONE 0
 | 
				
			||||||
#define KDYN_DBG 1
 | 
					#define KDYN_DBG 1
 | 
				
			||||||
| 
						 | 
					@ -64,10 +70,8 @@ extern "C" {
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define KDYNAMIC_LOG(level, args, ...)    \
 | 
					#define KDYNAMIC_LOG(level, args, ...)    \
 | 
				
			||||||
    do                                             \
 | 
					    do {                                  \
 | 
				
			||||||
    {                                              \
 | 
					        switch (level) {                  \
 | 
				
			||||||
        switch(level)                              \
 | 
					 | 
				
			||||||
        {                                          \
 | 
					 | 
				
			||||||
        case KDYN_NONE:                   \
 | 
					        case KDYN_NONE:                   \
 | 
				
			||||||
            break;                        \
 | 
					            break;                        \
 | 
				
			||||||
        case KDYN_DBG:                    \
 | 
					        case KDYN_DBG:                    \
 | 
				
			||||||
| 
						 | 
					@ -85,34 +89,31 @@ extern "C" {
 | 
				
			||||||
        default:                          \
 | 
					        default:                          \
 | 
				
			||||||
            break;                        \
 | 
					            break;                        \
 | 
				
			||||||
        }                                 \
 | 
					        }                                 \
 | 
				
			||||||
    }while (0)                                     
 | 
					    } while (0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define NULL_PARAM_CHECK(param)                                                                   \
 | 
					#define NULL_PARAM_CHECK(param)                                                                   \
 | 
				
			||||||
    do                                     \
 | 
					    do {                                                                                          \
 | 
				
			||||||
    {                                      \
 | 
					        if (param == NONE) {                                                                      \
 | 
				
			||||||
        if(param == NONE) {                \
 | 
					            KPrintf("PARAM CHECK FAILED ...%s %d %s is NULL.\n", __FUNCTION__, __LINE__, #param); \
 | 
				
			||||||
            KPrintf("PARAM CHECK FAILED ...%s %d %s is NULL.\n",__FUNCTION__,__LINE__,#param); \
 | 
					            while (RET_TRUE)                                                                      \
 | 
				
			||||||
            while(RET_TRUE);               \
 | 
					                ;                                                                                 \
 | 
				
			||||||
        }                                                                                         \
 | 
					        }                                                                                         \
 | 
				
			||||||
    }while (0)                             
 | 
					    } while (0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define CHECK(TRUE_CONDITION)                                                                                            \
 | 
					#define CHECK(TRUE_CONDITION)                                                                                            \
 | 
				
			||||||
    do                                            \
 | 
					    do {                                                                                                                 \
 | 
				
			||||||
    {                                             \
 | 
					        if (!(TRUE_CONDITION)) {                                                                                         \
 | 
				
			||||||
        if(!(TRUE_CONDITION)) {                   \
 | 
					            KPrintf("%s CHECK condition is false at line[%d] of [%s] func.\n", #TRUE_CONDITION, __LINE__, __FUNCTION__); \
 | 
				
			||||||
            KPrintf("%s CHECK condition is false at line[%d] of [%s] func.\n",#TRUE_CONDITION,__LINE__,__FUNCTION__);\
 | 
					            while (RET_TRUE)                                                                                             \
 | 
				
			||||||
            while(RET_TRUE);                             \
 | 
					                ;                                                                                                        \
 | 
				
			||||||
        }                                                                                                                \
 | 
					        }                                                                                                                \
 | 
				
			||||||
    } while(0)                                       
 | 
					    } while (0)
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define KDEBUG_NOT_IN_INTERRUPT                                              \
 | 
					#define KDEBUG_NOT_IN_INTERRUPT                                              \
 | 
				
			||||||
    do                                            \
 | 
					    do {                                                                     \
 | 
				
			||||||
    {                                             \
 | 
					 | 
				
			||||||
        x_base level;                                                        \
 | 
					        x_base level;                                                        \
 | 
				
			||||||
        level = DISABLE_INTERRUPT();                                         \
 | 
					        level = DISABLE_INTERRUPT();                                         \
 | 
				
			||||||
        if (isrManager.done->getCounter() != 0)   \
 | 
					        if (isrManager.done->getCounter() != 0) {                            \
 | 
				
			||||||
        {                                         \
 | 
					 | 
				
			||||||
            KPrintf("Function[%s] is not supported in ISR\n", __FUNCTION__); \
 | 
					            KPrintf("Function[%s] is not supported in ISR\n", __FUNCTION__); \
 | 
				
			||||||
            CHECK(0);                                                        \
 | 
					            CHECK(0);                                                        \
 | 
				
			||||||
        }                                                                    \
 | 
					        }                                                                    \
 | 
				
			||||||
| 
						 | 
					@ -120,12 +121,10 @@ extern "C" {
 | 
				
			||||||
    } while (0)
 | 
					    } while (0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define KDEBUG_IN_KTASK_CONTEXT                                                          \
 | 
					#define KDEBUG_IN_KTASK_CONTEXT                                                          \
 | 
				
			||||||
    do                                           \
 | 
					    do {                                                                                 \
 | 
				
			||||||
    {                                            \
 | 
					 | 
				
			||||||
        x_base level;                                                                    \
 | 
					        x_base level;                                                                    \
 | 
				
			||||||
        level = DISABLE_INTERRUPT();                                                     \
 | 
					        level = DISABLE_INTERRUPT();                                                     \
 | 
				
			||||||
        if (GetKTaskDescriptor() == NONE)        \
 | 
					        if (GetKTaskDescriptor() == NONE) {                                              \
 | 
				
			||||||
        {                                        \
 | 
					 | 
				
			||||||
            KPrintf("Function[%s] is not supported before task assign\n", __FUNCTION__); \
 | 
					            KPrintf("Function[%s] is not supported before task assign\n", __FUNCTION__); \
 | 
				
			||||||
            CHECK(0);                                                                    \
 | 
					            CHECK(0);                                                                    \
 | 
				
			||||||
        }                                                                                \
 | 
					        }                                                                                \
 | 
				
			||||||
| 
						 | 
					@ -135,7 +134,7 @@ extern "C" {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define NOT_IN_CRITICAL_AREA                                                                   \
 | 
					#define NOT_IN_CRITICAL_AREA                                                                   \
 | 
				
			||||||
    do {                                                                                       \
 | 
					    do {                                                                                       \
 | 
				
			||||||
        if(GetOsAssignLockLevel() != 0){     \
 | 
					        if (GetOsAssignLockLevel() != 0) {                                                     \
 | 
				
			||||||
            KPrintf("Function[%s] is not supported switch in critical area.\n", __FUNCTION__); \
 | 
					            KPrintf("Function[%s] is not supported switch in critical area.\n", __FUNCTION__); \
 | 
				
			||||||
            CHECK(0);                                                                          \
 | 
					            CHECK(0);                                                                          \
 | 
				
			||||||
        }                                                                                      \
 | 
					        }                                                                                      \
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -35,6 +35,7 @@
 | 
				
			||||||
#define ADDR                                  0x44                                      /* slave address */
 | 
					#define ADDR                                  0x44                                      /* slave address */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct Bus *i2c_bus = NONE;     /* I2C bus handle */
 | 
					static struct Bus *i2c_bus = NONE;     /* I2C bus handle */
 | 
				
			||||||
 | 
					static char addr = 0x44;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct Hs300xData
 | 
					typedef struct Hs300xData
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -50,6 +51,9 @@ static x_err_t WriteReg(struct HardwareDev *dev)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    struct BusBlockWriteParam write_param;
 | 
					    struct BusBlockWriteParam write_param;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    write_param.buffer = &addr;
 | 
				
			||||||
 | 
					    write_param.size = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* use I2C device API transfer data */
 | 
					    /* use I2C device API transfer data */
 | 
				
			||||||
    if(1 == BusDevWriteData(dev, &write_param)) {
 | 
					    if(1 == BusDevWriteData(dev, &write_param)) {
 | 
				
			||||||
        return EOK;
 | 
					        return EOK;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -53,8 +53,10 @@
 | 
				
			||||||
#define ALLOC_BLOCK_MASK                     0xc0000000
 | 
					#define ALLOC_BLOCK_MASK                     0xc0000000
 | 
				
			||||||
#define DYNAMIC_REMAINING_MASK               0x3fffffff
 | 
					#define DYNAMIC_REMAINING_MASK               0x3fffffff
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define SIZEOF_32B	                (32)
 | 
					enum SmallSizeAllocSize {
 | 
				
			||||||
#define SIZEOF_64B	                (64)
 | 
						SIZEOF_32B = 32,
 | 
				
			||||||
 | 
						SIZEOF_64B = 64,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#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*/
 | 
				
			||||||
| 
						 | 
					@ -143,7 +145,7 @@ struct ByteMemory
 | 
				
			||||||
struct StaticMemoryDone
 | 
					struct StaticMemoryDone
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	void (*init)(struct ByteMemory *byte_memory);
 | 
						void (*init)(struct ByteMemory *byte_memory);
 | 
				
			||||||
	void* (*malloc)(struct ByteMemory *byte_memory, x_size_t size);
 | 
						void* (*malloc)(struct ByteMemory *byte_memory, enum SmallSizeAllocSize size);
 | 
				
			||||||
	void (*release)(void *pointer);
 | 
						void (*release)(void *pointer);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -182,7 +184,7 @@ static int JudgeValidAddressRange(struct DynamicBuddyMemory *dynamic_buddy, void
 | 
				
			||||||
	NULL_PARAM_CHECK(pointer);
 | 
						NULL_PARAM_CHECK(pointer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* the given address is between the physical start address and physical end address */
 | 
					    /* the given address is between the physical start address and physical end address */
 | 
				
			||||||
    if(((struct DynamicAllocNode *)pointer > dynamic_buddy->mm_dynamic_start[0]) && ((struct DynamicAllocNode *)pointer < dynamic_buddy->mm_dynamic_end[0])) {
 | 
					    if (((struct DynamicAllocNode *)pointer > dynamic_buddy->mm_dynamic_start[0]) && ((struct DynamicAllocNode *)pointer < dynamic_buddy->mm_dynamic_end[0])) {
 | 
				
			||||||
        return RET_TRUE;
 | 
					        return RET_TRUE;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    /* invalid address */
 | 
					    /* invalid address */
 | 
				
			||||||
| 
						 | 
					@ -349,11 +351,18 @@ static void* BigMemMalloc(struct DynamicBuddyMemory *dynamic_buddy, x_size_t siz
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* best-fit method */
 | 
						/* best-fit method */
 | 
				
			||||||
	 for (node = dynamic_buddy->mm_freenode_list[ndx].next;
 | 
						node = dynamic_buddy->mm_freenode_list[ndx].next;
 | 
				
			||||||
	 		 (ndx < MEM_LINKNRS ) && (node->size < allocsize);
 | 
						while(ndx < MEM_LINKNRS && (NONE == node || node->size < allocsize)) {
 | 
				
			||||||
	 		 node = node->next) {
 | 
							if (NONE == node) { 
 | 
				
			||||||
			ndx++;
 | 
								ndx++;
 | 
				
			||||||
	 };
 | 
								if (ndx == MEM_LINKNRS) { // no space to allocate
 | 
				
			||||||
 | 
									return NONE;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								node = dynamic_buddy->mm_freenode_list[ndx].next;
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								node = node->next;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	/* get the best-fit freeNode */
 | 
						/* get the best-fit freeNode */
 | 
				
			||||||
	if (node && (node->size >= allocsize)) {
 | 
						if (node && (node->size >= allocsize)) {
 | 
				
			||||||
		struct DynamicFreeNode *remainder;
 | 
							struct DynamicFreeNode *remainder;
 | 
				
			||||||
| 
						 | 
					@ -385,13 +394,12 @@ static void* BigMemMalloc(struct DynamicBuddyMemory *dynamic_buddy, x_size_t siz
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* handle the case of an exact size match */
 | 
							/* handle the case of an exact size match */
 | 
				
			||||||
 | 
					 | 
				
			||||||
		node->flag = extsram_mask;
 | 
							node->flag = extsram_mask;
 | 
				
			||||||
        result = (void *)((char *)node + SIZEOF_DYNAMICALLOCNODE_MEM);
 | 
					        result = (void *)((char *)node + SIZEOF_DYNAMICALLOCNODE_MEM);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* failure allocation */
 | 
						/* failure allocation */
 | 
				
			||||||
	if(result == NONE) {
 | 
						if (result == NONE) {
 | 
				
			||||||
#ifndef MEM_EXTERN_SRAM
 | 
					#ifndef MEM_EXTERN_SRAM
 | 
				
			||||||
	    KPrintf("%s: allocation failed, size %d.\n", __func__, size);
 | 
						    KPrintf("%s: allocation failed, size %d.\n", __func__, size);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					@ -429,9 +437,9 @@ static void BigMemFree( struct ByteMemory *byte_memory, void *pointer)
 | 
				
			||||||
    byte_memory->dynamic_buddy_manager.active_memory -= node->size;
 | 
					    byte_memory->dynamic_buddy_manager.active_memory -= node->size;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
	/* get the next sibling freeNode */
 | 
						/* get the next sibling freeNode */
 | 
				
			||||||
	next = PTR2FREENODE((char*)node+node->size);
 | 
						next = PTR2FREENODE((char*)node + node->size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(((next->flag & DYNAMIC_BLOCK_MASK) == 0)) {
 | 
						if (((next->flag & DYNAMIC_BLOCK_MASK) == 0)) {
 | 
				
			||||||
		struct DynamicAllocNode *andbeyond;
 | 
							struct DynamicAllocNode *andbeyond;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		andbeyond = PTR2ALLOCNODE((char*)next + next->size);
 | 
							andbeyond = PTR2ALLOCNODE((char*)next + next->size);
 | 
				
			||||||
| 
						 | 
					@ -446,7 +454,7 @@ static void BigMemFree( struct ByteMemory *byte_memory, void *pointer)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
    /* get the prev sibling freeNode */
 | 
					    /* get the prev sibling freeNode */
 | 
				
			||||||
	prev = (struct DynamicFreeNode*)((char*)node - node->prev_adj_size );
 | 
						prev = (struct DynamicFreeNode*)((char*)node - node->prev_adj_size );
 | 
				
			||||||
	if((prev->flag & DYNAMIC_BLOCK_MASK)==0) {
 | 
						if ((prev->flag & DYNAMIC_BLOCK_MASK) == 0) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		prev->prev->next=prev->next;
 | 
							prev->prev->next=prev->next;
 | 
				
			||||||
		if(prev->next){
 | 
							if(prev->next){
 | 
				
			||||||
| 
						 | 
					@ -459,7 +467,7 @@ static void BigMemFree( struct ByteMemory *byte_memory, void *pointer)
 | 
				
			||||||
	node->flag = 0;
 | 
						node->flag = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* insert freeNode into dynamic buddy memory */
 | 
						/* insert freeNode into dynamic buddy memory */
 | 
				
			||||||
	AddNewNodeIntoBuddy(&byte_memory->dynamic_buddy_manager,node);
 | 
						AddNewNodeIntoBuddy(&byte_memory->dynamic_buddy_manager, node);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct DynamicBuddyMemoryDone DynamicDone = {
 | 
					static struct DynamicBuddyMemoryDone DynamicDone = {
 | 
				
			||||||
| 
						 | 
					@ -545,12 +553,14 @@ static void SmallMemFree(void *pointer)
 | 
				
			||||||
	NULL_PARAM_CHECK(pointer);
 | 
						NULL_PARAM_CHECK(pointer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* get the allocNode */
 | 
						/* get the allocNode */
 | 
				
			||||||
	node = PTR2ALLOCNODE((char*)pointer-SIZEOF_DYNAMICALLOCNODE_MEM);
 | 
						node = PTR2ALLOCNODE((char*)pointer - SIZEOF_DYNAMICALLOCNODE_MEM);
 | 
				
			||||||
    static_segment = (struct segment*)(x_size_t)node->size;
 | 
					    static_segment = (struct segment*)(x_size_t)node->size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* update the statistic information of static_segment */
 | 
					    /* update the statistic information of static_segment */
 | 
				
			||||||
	node->size = (x_size_t)static_segment->freelist;
 | 
						node->size = (x_size_t)static_segment->freelist;
 | 
				
			||||||
    static_segment->freelist = (uint8 *)node;
 | 
					    static_segment->freelist = (uint8 *)node;
 | 
				
			||||||
 | 
						node->flag = 0; // it's unnecessary, actually
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static_segment->block_free_count++;
 | 
					    static_segment->block_free_count++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* parameter detection */
 | 
					    /* parameter detection */
 | 
				
			||||||
| 
						 | 
					@ -565,7 +575,7 @@ static void SmallMemFree(void *pointer)
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @return pointer address on success; NULL on failure
 | 
					 * @return pointer address on success; NULL on failure
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
static void *SmallMemMalloc(struct ByteMemory *byte_memory, x_size_t size)
 | 
					static void *SmallMemMalloc(struct ByteMemory *byte_memory, enum SmallSizeAllocSize size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	uint8 i = 0;
 | 
						uint8 i = 0;
 | 
				
			||||||
	void *result = NONE;
 | 
						void *result = NONE;
 | 
				
			||||||
| 
						 | 
					@ -580,7 +590,7 @@ static void *SmallMemMalloc(struct ByteMemory *byte_memory, x_size_t size)
 | 
				
			||||||
	   static_segment = &byte_memory->static_manager[1];
 | 
						   static_segment = &byte_memory->static_manager[1];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* current static segment has free static memory block */
 | 
						/* current static segment has free static memory block */
 | 
				
			||||||
	if(static_segment->block_free_count>0) {
 | 
						if(static_segment->block_free_count > 0) {
 | 
				
			||||||
	    /* get the head static memory block */
 | 
						    /* get the head static memory block */
 | 
				
			||||||
        result = static_segment->freelist;
 | 
					        result = static_segment->freelist;
 | 
				
			||||||
        node = PTR2ALLOCNODE(static_segment->freelist);
 | 
					        node = PTR2ALLOCNODE(static_segment->freelist);
 | 
				
			||||||
| 
						 | 
					@ -592,27 +602,14 @@ static void *SmallMemMalloc(struct ByteMemory *byte_memory, x_size_t size)
 | 
				
			||||||
		node->size = (long)static_segment;
 | 
							node->size = (long)static_segment;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(result) {
 | 
						if (NONE != result) {
 | 
				
			||||||
	    /* return static memory block */
 | 
						    /* return static memory block */
 | 
				
			||||||
		return (char*)result + SIZEOF_DYNAMICALLOCNODE_MEM;
 | 
							return (char*)result + SIZEOF_DYNAMICALLOCNODE_MEM;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* the static memory block is exhausted, now turn to dynamic buddy memory for allocation. */
 | 
						/* the static memory block is exhausted, now turn to dynamic buddy memory for allocation. */
 | 
				
			||||||
    result = byte_memory->dynamic_buddy_manager.done->malloc(&byte_memory->dynamic_buddy_manager, size, DYNAMIC_BLOCK_NO_EXTMEM_MASK);
 | 
						// fall to dynamic allocation
 | 
				
			||||||
#ifdef MEM_EXTERN_SRAM
 | 
						return NONE;
 | 
				
			||||||
	if(NONE == result) {
 | 
					 | 
				
			||||||
		for(i = 0; i < EXTSRAM_MAX_NUM; i++) {
 | 
					 | 
				
			||||||
			if(NONE != ExtByteManager[i].done) {
 | 
					 | 
				
			||||||
				result = ExtByteManager[i].dynamic_buddy_manager.done->malloc(&ExtByteManager[i].dynamic_buddy_manager, size, DYNAMIC_BLOCK_EXTMEMn_MASK(i + 1));
 | 
					 | 
				
			||||||
				if (result){
 | 
					 | 
				
			||||||
					CHECK(ExtByteManager[i].dynamic_buddy_manager.done->JudgeLegal(&ExtByteManager[i].dynamic_buddy_manager, ret - SIZEOF_DYNAMICALLOCNODE_MEM));
 | 
					 | 
				
			||||||
					break;
 | 
					 | 
				
			||||||
				}	
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
	return result;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct StaticMemoryDone StaticDone = {
 | 
					static struct StaticMemoryDone StaticDone = {
 | 
				
			||||||
| 
						 | 
					@ -634,41 +631,46 @@ void *x_malloc(x_size_t size)
 | 
				
			||||||
	void *ret = NONE;
 | 
						void *ret = NONE;
 | 
				
			||||||
	register x_base lock = 0;
 | 
						register x_base lock = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	 /* parameter detection */
 | 
						/* hold lock before allocation */
 | 
				
			||||||
 | 
						lock = CriticalAreaLock();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* alignment */
 | 
				
			||||||
 | 
						size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* parameter detection */
 | 
				
			||||||
#ifdef MEM_EXTERN_SRAM
 | 
					#ifdef MEM_EXTERN_SRAM
 | 
				
			||||||
		/* parameter detection */
 | 
							/* parameter detection */
 | 
				
			||||||
	if(size == 0 ){
 | 
						if(size == 0 ){
 | 
				
			||||||
 | 
							CriticalAreaUnLock(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)){
 | 
				
			||||||
		lock = CriticalAreaLock();
 | 
					 | 
				
			||||||
		/* 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);
 | 
				
			||||||
	    return NONE;
 | 
						    return NONE;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
	/* hold lock before allocation */
 | 
					
 | 
				
			||||||
	lock = CriticalAreaLock();
 | 
					 | 
				
			||||||
    /* alignment */
 | 
					 | 
				
			||||||
	size = ALIGN_MEN_UP(size, MEM_ALIGN_SIZE);
 | 
					 | 
				
			||||||
	/* 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);
 | 
				
			||||||
	} else
 | 
						} 
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
	{
 | 
					
 | 
				
			||||||
 | 
						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:
 | 
				
			||||||
| 
						 | 
					@ -686,6 +688,7 @@ try_extmem:
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* release lock */
 | 
						/* release lock */
 | 
				
			||||||
	CriticalAreaUnLock(lock);
 | 
						CriticalAreaUnLock(lock);
 | 
				
			||||||
  	return ret;
 | 
					  	return ret;
 | 
				
			||||||
| 
						 | 
					@ -781,14 +784,20 @@ void x_free(void *pointer)
 | 
				
			||||||
	struct DynamicAllocNode *node = NONE;
 | 
						struct DynamicAllocNode *node = NONE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* parameter detection */
 | 
					    /* parameter detection */
 | 
				
			||||||
	if (pointer == NONE)
 | 
						if (pointer == NONE) {
 | 
				
			||||||
		return ;
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
    CHECK(ByteManager.dynamic_buddy_manager.done->JudgeLegal(&ByteManager.dynamic_buddy_manager,pointer));
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* hold lock before release */
 | 
					    /* hold lock before release */
 | 
				
			||||||
	lock = CriticalAreaLock();
 | 
						lock = CriticalAreaLock();
 | 
				
			||||||
	node = PTR2ALLOCNODE((char*)pointer-SIZEOF_DYNAMICALLOCNODE_MEM);
 | 
					
 | 
				
			||||||
 | 
					    if (!ByteManager.dynamic_buddy_manager.done->JudgeLegal(&ByteManager.dynamic_buddy_manager, pointer)) {
 | 
				
			||||||
 | 
							CriticalAreaUnLock(lock);
 | 
				
			||||||
 | 
							SYS_ERR("[%s] Freeing a unallocated address.\n", __func__);
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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 */
 | 
				
			||||||
| 
						 | 
					@ -809,9 +818,10 @@ void x_free(void *pointer)
 | 
				
			||||||
			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);
 | 
						CriticalAreaUnLock(lock);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -888,6 +898,7 @@ void InitBoardMemory(void *start_phy_address, void *end_phy_address)
 | 
				
			||||||
    /* 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));
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,7 +30,7 @@
 | 
				
			||||||
DoubleLinklistType xiaoshan_delay_head = {&xiaoshan_delay_head, &xiaoshan_delay_head};
 | 
					DoubleLinklistType xiaoshan_delay_head = {&xiaoshan_delay_head, &xiaoshan_delay_head};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * This function will delay a task with sone ticks.
 | 
					 * This function will delay a task with some ticks.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @param task the task needed to be delayed
 | 
					 * @param task the task needed to be delayed
 | 
				
			||||||
 * @param ticks delay timeout
 | 
					 * @param ticks delay timeout
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,6 +21,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <xizi.h>
 | 
					#include <xizi.h>
 | 
				
			||||||
#include <xs_delay.h>
 | 
					#include <xs_delay.h>
 | 
				
			||||||
 | 
					#include <xs_kdbg.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
DECLARE_ID_MANAGER(k_mq_id_manager, ID_NUM_MAX);
 | 
					DECLARE_ID_MANAGER(k_mq_id_manager, ID_NUM_MAX);
 | 
				
			||||||
DoubleLinklistType k_mq_list = {&k_mq_list, &k_mq_list};
 | 
					DoubleLinklistType k_mq_list = {&k_mq_list, &k_mq_list};
 | 
				
			||||||
| 
						 | 
					@ -41,17 +42,17 @@ static struct MsgQueue *GetMsgQueueById(int32 id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    lock = CriticalAreaLock();
 | 
					    lock = CriticalAreaLock();
 | 
				
			||||||
    idnode = IdGetObj(&k_mq_id_manager, id);
 | 
					    idnode = IdGetObj(&k_mq_id_manager, id);
 | 
				
			||||||
    if (idnode == NONE){
 | 
					    if (idnode == NONE) {
 | 
				
			||||||
       CriticalAreaUnLock(lock);
 | 
					       CriticalAreaUnLock(lock);
 | 
				
			||||||
       return NONE;
 | 
					       return NONE;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    mq = CONTAINER_OF(idnode, struct MsgQueue, id);
 | 
					    mq = CONTAINER_OF(idnode, struct MsgQueue, id);
 | 
				
			||||||
    CriticalAreaUnLock(lock);
 | 
					    CriticalAreaUnLock(lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return mq;
 | 
					    return mq;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static x_err_t _InitMsgQueue( struct MsgQueue *mq ,x_size_t   msg_size,
 | 
					static x_err_t _InitMsgQueue(struct MsgQueue* mq, x_size_t msg_size, x_size_t max_msgs)
 | 
				
			||||||
                            x_size_t   max_msgs )
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    x_base lock = 0;
 | 
					    x_base lock = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -62,10 +63,12 @@ static x_err_t _InitMsgQueue( struct MsgQueue *mq ,x_size_t   msg_size,
 | 
				
			||||||
    mq->each_len = ALIGN_MEN_UP(msg_size, MEM_ALIGN_SIZE);
 | 
					    mq->each_len = ALIGN_MEN_UP(msg_size, MEM_ALIGN_SIZE);
 | 
				
			||||||
    mq->index = 0;
 | 
					    mq->index = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    SYS_KDEBUG_LOG(MSGQUEUE_DEBUG, ("[%s] Msg attr, max_msg_num: %d, block size: %d\n", __func__, mq->max_msgs, mq->each_len));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    InitDoubleLinkList(&mq->send_pend_list);
 | 
					    InitDoubleLinkList(&mq->send_pend_list);
 | 
				
			||||||
    InitDoubleLinkList(&(mq->recv_pend_list));
 | 
					    InitDoubleLinkList(&(mq->recv_pend_list));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    mq->msg_buf = x_malloc( mq->each_len * mq->max_msgs);
 | 
					    mq->msg_buf = x_malloc(mq->each_len * mq->max_msgs);
 | 
				
			||||||
    if (mq->msg_buf == NONE) {
 | 
					    if (mq->msg_buf == NONE) {
 | 
				
			||||||
        lock = CriticalAreaLock();
 | 
					        lock = CriticalAreaLock();
 | 
				
			||||||
        DoubleLinkListRmNode(&(mq->link));
 | 
					        DoubleLinkListRmNode(&(mq->link));
 | 
				
			||||||
| 
						 | 
					@ -77,26 +80,28 @@ static x_err_t _InitMsgQueue( struct MsgQueue *mq ,x_size_t   msg_size,
 | 
				
			||||||
    return EOK;
 | 
					    return EOK;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static x_err_t _MsgQueueSend(struct MsgQueue *mq,
 | 
					static x_err_t _MsgQueueSend(struct MsgQueue* mq,
 | 
				
			||||||
                              const void *buffer,
 | 
					    const void* buffer,
 | 
				
			||||||
    x_size_t size,
 | 
					    x_size_t size,
 | 
				
			||||||
    int32 msec)
 | 
					    int32 msec)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    x_ubase lock = 0;
 | 
					    x_ubase lock = 0;
 | 
				
			||||||
    uint32 tick_delta = 0;
 | 
					    uint32 tick_delta = 0;
 | 
				
			||||||
    int32  timeout = 0;
 | 
					    int32  timeout = 0;
 | 
				
			||||||
     uint8 *msg = NONE;
 | 
					    uint8* msg = NONE;
 | 
				
			||||||
    struct TaskDescriptor *task = NONE;
 | 
					    struct TaskDescriptor *task = NONE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    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));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (size > mq->each_len)
 | 
					    if (size > mq->each_len)
 | 
				
			||||||
        return -ERROR;
 | 
					        return -ERROR;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    tick_delta = 0;
 | 
					    tick_delta = 0;
 | 
				
			||||||
    task = GetKTaskDescriptor();
 | 
					    task = GetKTaskDescriptor();
 | 
				
			||||||
    if(WAITING_FOREVER == msec)
 | 
					    if (WAITING_FOREVER == msec)
 | 
				
			||||||
        timeout = WAITING_FOREVER;
 | 
					        timeout = WAITING_FOREVER;
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        timeout = CalculateTickFromTimeMs(msec);
 | 
					        timeout = CalculateTickFromTimeMs(msec);
 | 
				
			||||||
| 
						 | 
					@ -107,8 +112,7 @@ static x_err_t _MsgQueueSend(struct MsgQueue *mq,
 | 
				
			||||||
        return -EFULL;
 | 
					        return -EFULL;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    while(mq->num_msgs >= mq->max_msgs ) {
 | 
					    while (mq->num_msgs >= mq->max_msgs) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
        task->exstatus = EOK;
 | 
					        task->exstatus = EOK;
 | 
				
			||||||
        if (timeout == 0) {
 | 
					        if (timeout == 0) {
 | 
				
			||||||
            CriticalAreaUnLock(lock);
 | 
					            CriticalAreaUnLock(lock);
 | 
				
			||||||
| 
						 | 
					@ -121,7 +125,7 @@ static x_err_t _MsgQueueSend(struct MsgQueue *mq,
 | 
				
			||||||
            tick_delta = CurrentTicksGain();
 | 
					            tick_delta = CurrentTicksGain();
 | 
				
			||||||
            SYS_KDEBUG_LOG(KDBG_IPC, ("mq_send_wait: start timer of task:%s\n",
 | 
					            SYS_KDEBUG_LOG(KDBG_IPC, ("mq_send_wait: start timer of task:%s\n",
 | 
				
			||||||
                                        task->task_base_info.name));
 | 
					                                        task->task_base_info.name));
 | 
				
			||||||
            KTaskSetDelay(task,timeout);
 | 
					            KTaskSetDelay(task, timeout);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        CriticalAreaUnLock(lock);
 | 
					        CriticalAreaUnLock(lock);
 | 
				
			||||||
| 
						 | 
					@ -139,19 +143,19 @@ static x_err_t _MsgQueueSend(struct MsgQueue *mq,
 | 
				
			||||||
            if (timeout < 0)
 | 
					            if (timeout < 0)
 | 
				
			||||||
                timeout = 0;
 | 
					                timeout = 0;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    } // end with lock here
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    msg = mq->msg_buf + ( ( mq->index + mq->num_msgs ) % mq->max_msgs ) * mq->each_len ;
 | 
					    msg = mq->msg_buf + ((mq->index + mq->num_msgs) % mq->max_msgs) * mq->each_len;
 | 
				
			||||||
    memcpy(msg, buffer, size);
 | 
					    memcpy(msg, buffer, size);
 | 
				
			||||||
    mq->num_msgs ++;
 | 
					    mq->num_msgs++;
 | 
				
			||||||
    if (!IsDoubleLinkListEmpty(&mq->recv_pend_list)) {
 | 
					    if (!IsDoubleLinkListEmpty(&mq->recv_pend_list)) {
 | 
				
			||||||
        LinklistResume(&(mq->recv_pend_list));
 | 
					        LinklistResume(&(mq->recv_pend_list));
 | 
				
			||||||
        CriticalAreaUnLock(lock);
 | 
					        CriticalAreaUnLock(lock);
 | 
				
			||||||
        DO_KTASK_ASSIGN;
 | 
					        DO_KTASK_ASSIGN;
 | 
				
			||||||
        return EOK;
 | 
					        return EOK;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					 | 
				
			||||||
    CriticalAreaUnLock(lock);
 | 
					    CriticalAreaUnLock(lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return EOK;
 | 
					    return EOK;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -191,15 +195,15 @@ static x_err_t _MsgQueueUrgentSend(struct MsgQueue *mq, const void *buffer, x_si
 | 
				
			||||||
    return EOK;
 | 
					    return EOK;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static x_err_t _MsgQueueRecv(struct MsgQueue *mq,
 | 
					static x_err_t _MsgQueueRecv(struct MsgQueue* mq,
 | 
				
			||||||
                          void *buffer,
 | 
					    void* buffer,
 | 
				
			||||||
    x_size_t size,
 | 
					    x_size_t size,
 | 
				
			||||||
    int32 msec)
 | 
					    int32 msec)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    x_ubase lock = 0;
 | 
					    x_ubase lock = 0;
 | 
				
			||||||
    uint32 tick_delta = 0;
 | 
					    uint32 tick_delta = 0;
 | 
				
			||||||
    int32 timeout = 0;
 | 
					    int32 timeout = 0;
 | 
				
			||||||
    struct MqMessage *msg = NONE;
 | 
					    uint8* msg = NONE;
 | 
				
			||||||
    struct TaskDescriptor *task = NONE;
 | 
					    struct TaskDescriptor *task = NONE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    NULL_PARAM_CHECK(mq);
 | 
					    NULL_PARAM_CHECK(mq);
 | 
				
			||||||
| 
						 | 
					@ -208,14 +212,14 @@ static x_err_t _MsgQueueRecv(struct MsgQueue *mq,
 | 
				
			||||||
    tick_delta = 0;
 | 
					    tick_delta = 0;
 | 
				
			||||||
    task = GetKTaskDescriptor();
 | 
					    task = GetKTaskDescriptor();
 | 
				
			||||||
    timeout = CalculateTickFromTimeMs(msec);
 | 
					    timeout = CalculateTickFromTimeMs(msec);
 | 
				
			||||||
    lock = CriticalAreaLock();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    lock = CriticalAreaLock();
 | 
				
			||||||
    if (mq->index == 0 && timeout == 0) {
 | 
					    if (mq->index == 0 && timeout == 0) {
 | 
				
			||||||
        CriticalAreaUnLock(lock);
 | 
					        CriticalAreaUnLock(lock);
 | 
				
			||||||
        return -ETIMEOUT;
 | 
					        return -ETIMEOUT;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for( ; mq->num_msgs <= 0 ; ) {
 | 
					    while (mq->num_msgs <= 0) {
 | 
				
			||||||
        KDEBUG_IN_KTASK_CONTEXT;
 | 
					        KDEBUG_IN_KTASK_CONTEXT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        task->exstatus = EOK;
 | 
					        task->exstatus = EOK;
 | 
				
			||||||
| 
						 | 
					@ -225,19 +229,16 @@ static x_err_t _MsgQueueRecv(struct MsgQueue *mq,
 | 
				
			||||||
            return -ETIMEOUT;
 | 
					            return -ETIMEOUT;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        LinklistSuspend(&(mq->recv_pend_list),
 | 
					        LinklistSuspend(&(mq->recv_pend_list), task, LINKLIST_FLAG_FIFO);
 | 
				
			||||||
                            task,
 | 
					 | 
				
			||||||
                            LINKLIST_FLAG_FIFO);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (timeout > 0) {
 | 
					        if (timeout > 0) {
 | 
				
			||||||
            tick_delta = CurrentTicksGain();
 | 
					            tick_delta = CurrentTicksGain();
 | 
				
			||||||
            SYS_KDEBUG_LOG(KDBG_IPC, ("set task:%s to timer list\n",
 | 
					            SYS_KDEBUG_LOG(KDBG_IPC, ("set task:%s to timer list\n",
 | 
				
			||||||
                                        task->task_base_info.name));
 | 
					                                        task->task_base_info.name));
 | 
				
			||||||
            KTaskSetDelay(task,timeout);
 | 
					            KTaskSetDelay(task, timeout);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        CriticalAreaUnLock(lock);
 | 
					        CriticalAreaUnLock(lock);
 | 
				
			||||||
 | 
					 | 
				
			||||||
        DO_KTASK_ASSIGN;
 | 
					        DO_KTASK_ASSIGN;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (task->exstatus != EOK) {
 | 
					        if (task->exstatus != EOK) {
 | 
				
			||||||
| 
						 | 
					@ -256,8 +257,8 @@ static x_err_t _MsgQueueRecv(struct MsgQueue *mq,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    msg = mq->msg_buf + mq->index * mq->each_len;
 | 
					    msg = mq->msg_buf + mq->index * mq->each_len;
 | 
				
			||||||
    mq->index = (mq->index + 1) % mq->max_msgs;
 | 
					    mq->index = (mq->index + 1) % mq->max_msgs;
 | 
				
			||||||
    memcpy(buffer, msg , size > mq->each_len ? mq->each_len : size);
 | 
					    memcpy(buffer, msg, size > mq->each_len ? mq->each_len : size);
 | 
				
			||||||
    mq->num_msgs --;
 | 
					    mq->num_msgs--;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!IsDoubleLinkListEmpty(&(mq->send_pend_list))) {
 | 
					    if (!IsDoubleLinkListEmpty(&(mq->send_pend_list))) {
 | 
				
			||||||
        LinklistResume(&(mq->send_pend_list));
 | 
					        LinklistResume(&(mq->send_pend_list));
 | 
				
			||||||
| 
						 | 
					@ -326,8 +327,7 @@ static struct MsgQueueDone Done = {
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @return id on success;ENOMEMORY/ERROR on failure
 | 
					 * @return id on success;ENOMEMORY/ERROR on failure
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
int32 KCreateMsgQueue(x_size_t   msg_size,
 | 
					int32 KCreateMsgQueue(x_size_t msg_size, x_size_t max_msgs)
 | 
				
			||||||
                            x_size_t   max_msgs)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int32 id = 0;
 | 
					    int32 id = 0;
 | 
				
			||||||
    x_base temp = 0;
 | 
					    x_base temp = 0;
 | 
				
			||||||
| 
						 | 
					@ -337,11 +337,12 @@ int32 KCreateMsgQueue(x_size_t   msg_size,
 | 
				
			||||||
    mq = (struct MsgQueue *)x_malloc(sizeof(struct MsgQueue));
 | 
					    mq = (struct MsgQueue *)x_malloc(sizeof(struct MsgQueue));
 | 
				
			||||||
    if (mq == NONE)
 | 
					    if (mq == NONE)
 | 
				
			||||||
        return -ENOMEMORY;
 | 
					        return -ENOMEMORY;
 | 
				
			||||||
    memset(mq,0x0,sizeof(struct MsgQueue));
 | 
					    memset(mq, 0x0, sizeof(struct MsgQueue));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    lock = CriticalAreaLock();
 | 
					    lock = CriticalAreaLock();
 | 
				
			||||||
    id = IdInsertObj(&k_mq_id_manager, &mq->id);
 | 
					    id = IdInsertObj(&k_mq_id_manager, &mq->id);
 | 
				
			||||||
    CriticalAreaUnLock(lock);
 | 
					    CriticalAreaUnLock(lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (id < 0) {
 | 
					    if (id < 0) {
 | 
				
			||||||
        x_free(mq);
 | 
					        x_free(mq);
 | 
				
			||||||
        return -ENOMEMORY;
 | 
					        return -ENOMEMORY;
 | 
				
			||||||
| 
						 | 
					@ -350,8 +351,9 @@ int32 KCreateMsgQueue(x_size_t   msg_size,
 | 
				
			||||||
    lock = CriticalAreaLock();
 | 
					    lock = CriticalAreaLock();
 | 
				
			||||||
    DoubleLinkListInsertNodeAfter(&k_mq_list, &mq->link);
 | 
					    DoubleLinkListInsertNodeAfter(&k_mq_list, &mq->link);
 | 
				
			||||||
    CriticalAreaUnLock(lock);
 | 
					    CriticalAreaUnLock(lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    mq->Done = &Done;
 | 
					    mq->Done = &Done;
 | 
				
			||||||
    if( mq->Done->init(mq, msg_size,max_msgs) == EOK )
 | 
					    if (mq->Done->init(mq, msg_size, max_msgs) == EOK)
 | 
				
			||||||
        return mq->id.id;
 | 
					        return mq->id.id;
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        return -ERROR;
 | 
					        return -ERROR;
 | 
				
			||||||
| 
						 | 
					@ -401,7 +403,7 @@ x_err_t KMsgQueueRecv(int32 id,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    mq = GetMsgQueueById(id);
 | 
					    mq = GetMsgQueueById(id);
 | 
				
			||||||
    if (mq != NONE)
 | 
					    if (mq != NONE)
 | 
				
			||||||
       return mq->Done->recv(mq,buffer,size,timeout);
 | 
					       return mq->Done->recv(mq, buffer, size, timeout);
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
      return -EINVALED;
 | 
					      return -EINVALED;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -471,10 +473,11 @@ x_err_t KMsgQueueSend(int32 id, const void *buffer, x_size_t size)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    mq = GetMsgQueueById(id);
 | 
					    mq = GetMsgQueueById(id);
 | 
				
			||||||
    if (mq != NONE)
 | 
					    if (mq != NONE)
 | 
				
			||||||
      return mq->Done->send(mq,buffer,size,0);
 | 
					      return mq->Done->send(mq, buffer, size, WAITING_FOREVER);
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
      return -EINVALED;
 | 
					      return -EINVALED;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * send message with waiting time,current suspend task will be resumed
 | 
					 * send message with waiting time,current suspend task will be resumed
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,6 +8,9 @@ ifeq ($(CONFIG_APP_SELECT_NEWLIB), y)
 | 
				
			||||||
	APPPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/lib/app_newlib/include #
 | 
						APPPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/lib/app_newlib/include #
 | 
				
			||||||
endif
 | 
					endif
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 | 
					ifeq ($(CONFIG_APP_USING_WEBNET),y)
 | 
				
			||||||
 | 
						APPPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Applications/webnet/WebNet_XiUOS/inc #
 | 
				
			||||||
 | 
					endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ifeq ($(CONFIG_ADD_XIZI_FEATURES), y)
 | 
					ifeq ($(CONFIG_ADD_XIZI_FEATURES), y)
 | 
				
			||||||
APPPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Framework/transform_layer/xizi \
 | 
					APPPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Framework/transform_layer/xizi \
 | 
				
			||||||
| 
						 | 
					@ -36,6 +39,7 @@ ifeq ($(CONFIG_CRYPTO), y)
 | 
				
			||||||
APPPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Framework/security/crypto/include #
 | 
					APPPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Framework/security/crypto/include #
 | 
				
			||||||
endif
 | 
					endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# COMPILE_APP:
 | 
					# COMPILE_APP:
 | 
				
			||||||
# 	@$(eval CPPPATHS=$(APPPATHS))
 | 
					# 	@$(eval CPPPATHS=$(APPPATHS))
 | 
				
			||||||
# 	@echo $(SRC_APP_DIR)
 | 
					# 	@echo $(SRC_APP_DIR)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -52,6 +52,8 @@ KERNELPATHS += \
 | 
				
			||||||
	-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/priv \
 | 
						-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/priv \
 | 
				
			||||||
	-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/prot \
 | 
						-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/prot \
 | 
				
			||||||
	-I$(KERNEL_ROOT)/resources/ethernet/LwIP/arch 
 | 
						-I$(KERNEL_ROOT)/resources/ethernet/LwIP/arch 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					KERNELPATHS += -I$(KERNEL_ROOT)/resources/include/netdev
 | 
				
			||||||
endif 
 | 
					endif 
 | 
				
			||||||
endif
 | 
					endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -86,6 +88,8 @@ KERNELPATHS += \
 | 
				
			||||||
	-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/priv \
 | 
						-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/priv \
 | 
				
			||||||
	-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/prot \
 | 
						-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/prot \
 | 
				
			||||||
	-I$(KERNEL_ROOT)/resources/ethernet/LwIP/arch 
 | 
						-I$(KERNEL_ROOT)/resources/ethernet/LwIP/arch 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					KERNELPATHS += -I$(KERNEL_ROOT)/resources/include/netdev
 | 
				
			||||||
endif 
 | 
					endif 
 | 
				
			||||||
endif
 | 
					endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -334,6 +338,8 @@ KERNELPATHS += \
 | 
				
			||||||
	-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/priv \
 | 
						-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/priv \
 | 
				
			||||||
	-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/prot \
 | 
						-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/prot \
 | 
				
			||||||
	-I$(KERNEL_ROOT)/resources/ethernet/LwIP/arch 
 | 
						-I$(KERNEL_ROOT)/resources/ethernet/LwIP/arch 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					KERNELPATHS += -I$(KERNEL_ROOT)/resources/include/netdev
 | 
				
			||||||
endif
 | 
					endif
 | 
				
			||||||
endif
 | 
					endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -365,6 +371,8 @@ KERNELPATHS += \
 | 
				
			||||||
	-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/priv \
 | 
						-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/priv \
 | 
				
			||||||
	-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/prot \
 | 
						-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/prot \
 | 
				
			||||||
	-I$(KERNEL_ROOT)/resources/ethernet/LwIP/arch 
 | 
						-I$(KERNEL_ROOT)/resources/ethernet/LwIP/arch 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					KERNELPATHS += -I$(KERNEL_ROOT)/resources/include/netdev
 | 
				
			||||||
endif
 | 
					endif
 | 
				
			||||||
endif
 | 
					endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -419,6 +427,8 @@ KERNELPATHS += \
 | 
				
			||||||
	-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/priv \
 | 
						-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/priv \
 | 
				
			||||||
	-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/prot \
 | 
						-I$(KERNEL_ROOT)/resources/ethernet/LwIP/include/lwip/prot \
 | 
				
			||||||
	-I$(KERNEL_ROOT)/resources/ethernet/LwIP/arch 
 | 
						-I$(KERNEL_ROOT)/resources/ethernet/LwIP/arch 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					KERNELPATHS += -I$(KERNEL_ROOT)/resources/include/netdev
 | 
				
			||||||
endif 
 | 
					endif 
 | 
				
			||||||
endif
 | 
					endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -554,6 +564,12 @@ endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
endif
 | 
					endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ifeq ($(CONFIG_APP_USING_WEBNET),y)
 | 
				
			||||||
 | 
						KERNELPATHS += -I$(KERNEL_ROOT)/../../APP_Framework/Applications/webnet/WebNet_XiUOS/inc \
 | 
				
			||||||
 | 
									   -I$(KERNEL_ROOT)/../../APP_Framework/Applications/webnet/WebNet_XiUOS/samples #
 | 
				
			||||||
 | 
					endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ifeq ($(CONFIG_TOOL_SHELL), y)
 | 
					ifeq ($(CONFIG_TOOL_SHELL), y)
 | 
				
			||||||
KERNELPATHS +=-I$(KERNEL_ROOT)/tool/shell/letter-shell \
 | 
					KERNELPATHS +=-I$(KERNEL_ROOT)/tool/shell/letter-shell \
 | 
				
			||||||
	-I$(KERNEL_ROOT)/tool/shell/letter-shell/file_ext #
 | 
						-I$(KERNEL_ROOT)/tool/shell/letter-shell/file_ext #
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -31,55 +31,54 @@
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
* @file sys_arch.c
 | 
					 * @file sys_arch.c
 | 
				
			||||||
* @brief In order to adapt to XiZi, some changes have been made to implement the LwIP interface.
 | 
					 * @brief In order to adapt to XiZi, some changes have been made to implement the LwIP interface.
 | 
				
			||||||
* @version 1.0
 | 
					 * @version 1.0
 | 
				
			||||||
* @author AIIT XUOS Lab
 | 
					 * @author AIIT XUOS Lab
 | 
				
			||||||
* @date 2021-05-29
 | 
					 * @date 2021-05-29
 | 
				
			||||||
*/
 | 
					 */
 | 
				
			||||||
#include "debug.h"
 | 
					#include "debug.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <lwip/opt.h>
 | 
					 | 
				
			||||||
#include <lwip/arch.h>
 | 
					#include <lwip/arch.h>
 | 
				
			||||||
 | 
					#include <lwip/opt.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "tcpip.h"
 | 
					#include "lwip/dhcp.h"
 | 
				
			||||||
#include "lwip/init.h"
 | 
					#include "lwip/init.h"
 | 
				
			||||||
#include "lwip/netif.h"
 | 
					#include "lwip/netif.h"
 | 
				
			||||||
#include "lwip/sio.h"
 | 
					#include "lwip/sio.h"
 | 
				
			||||||
#include <lwip/stats.h>
 | 
					#include "tcpip.h"
 | 
				
			||||||
#include <lwip/debug.h>
 | 
					 | 
				
			||||||
#include <lwip/sys.h>
 | 
					 | 
				
			||||||
#include "lwip/dhcp.h"
 | 
					 | 
				
			||||||
#include "tcpip_priv.h"
 | 
					#include "tcpip_priv.h"
 | 
				
			||||||
 | 
					#include <lwip/debug.h>
 | 
				
			||||||
 | 
					#include <lwip/stats.h>
 | 
				
			||||||
 | 
					#include <lwip/sys.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if !NO_SYS
 | 
					#if !NO_SYS
 | 
				
			||||||
#include "sys_arch.h"
 | 
					#include "sys_arch.h"
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					#include <xs_assign.h>
 | 
				
			||||||
#include <xs_ktask.h>
 | 
					#include <xs_ktask.h>
 | 
				
			||||||
#include <xs_ktick.h>
 | 
					#include <xs_ktick.h>
 | 
				
			||||||
#include <xs_assign.h>
 | 
					 | 
				
			||||||
#include <xs_sem.h>
 | 
					 | 
				
			||||||
#include <xs_mutex.h>
 | 
					 | 
				
			||||||
#include <xs_ktask.h>
 | 
					 | 
				
			||||||
#include <xs_msg.h>
 | 
					#include <xs_msg.h>
 | 
				
			||||||
 | 
					#include <xs_mutex.h>
 | 
				
			||||||
 | 
					#include <xs_sem.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "board.h"
 | 
					#include "board.h"
 | 
				
			||||||
#include "ethernet.h"
 | 
					 | 
				
			||||||
#include "connect_ethernet.h"
 | 
					#include "connect_ethernet.h"
 | 
				
			||||||
 | 
					#include "ethernet.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char lwip_ipaddr[20] = {192, 168, 130, 77};
 | 
					char lwip_ipaddr[20] = { 192, 168, 130, 77 };
 | 
				
			||||||
char lwip_netmask[20] = {255, 255, 254, 0};
 | 
					char lwip_netmask[20] = { 255, 255, 254, 0 };
 | 
				
			||||||
char lwip_gwaddr[20] = {192, 168, 130, 1};
 | 
					char lwip_gwaddr[20] = { 192, 168, 130, 1 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char lwip_eth0_ipaddr[20] = {192, 168, 130, 77};
 | 
					char lwip_eth0_ipaddr[20] = { 192, 168, 130, 77 };
 | 
				
			||||||
char lwip_eth0_netmask[20] = {255, 255, 254, 0};
 | 
					char lwip_eth0_netmask[20] = { 255, 255, 254, 0 };
 | 
				
			||||||
char lwip_eth0_gwaddr[20] = {192, 168, 130, 1};
 | 
					char lwip_eth0_gwaddr[20] = { 192, 168, 130, 1 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char lwip_eth1_ipaddr[20] = {192, 168, 130, 99};
 | 
					char lwip_eth1_ipaddr[20] = { 192, 168, 130, 99 };
 | 
				
			||||||
char lwip_eth1_netmask[20] = {255, 255, 254, 0};
 | 
					char lwip_eth1_netmask[20] = { 255, 255, 254, 0 };
 | 
				
			||||||
char lwip_eth1_gwaddr[20] = {192, 168, 130, 23};
 | 
					char lwip_eth1_gwaddr[20] = { 192, 168, 130, 23 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char lwip_flag = 0;
 | 
					char lwip_flag = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -88,39 +87,43 @@ x_ticks_t lwip_sys_now;
 | 
				
			||||||
#define SYS_THREAD_MAX 4
 | 
					#define SYS_THREAD_MAX 4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct netif gnetif;
 | 
					struct netif gnetif;
 | 
				
			||||||
sys_sem_t* get_eth_recv_sem() {
 | 
					sys_sem_t* get_eth_recv_sem()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    static sys_sem_t g_recv_sem = 0;
 | 
					    static sys_sem_t g_recv_sem = 0;
 | 
				
			||||||
    return &g_recv_sem;
 | 
					    return &g_recv_sem;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void sys_init(void) {
 | 
					void sys_init(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    // do nothing
 | 
					    // do nothing
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
u32_t
 | 
					u32_t sys_jiffies(void)
 | 
				
			||||||
sys_jiffies(void) {
 | 
					{
 | 
				
			||||||
    lwip_sys_now = CurrentTicksGain();
 | 
					    lwip_sys_now = CurrentTicksGain();
 | 
				
			||||||
    return lwip_sys_now;
 | 
					    return lwip_sys_now;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
u32_t
 | 
					u32_t sys_now(void)
 | 
				
			||||||
sys_now(void) {
 | 
					{
 | 
				
			||||||
    lwip_sys_now = CurrentTicksGain();
 | 
					    lwip_sys_now = CurrentTicksGain();
 | 
				
			||||||
    return CalculateTimeMsFromTick(lwip_sys_now);
 | 
					    return CalculateTimeMsFromTick(lwip_sys_now);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sys_prot_t sys_arch_protect(void) {
 | 
					sys_prot_t sys_arch_protect(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return CriticalAreaLock();
 | 
					    return CriticalAreaLock();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void sys_arch_unprotect(sys_prot_t pval) {
 | 
					void sys_arch_unprotect(sys_prot_t pval)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    CriticalAreaUnLock(pval);
 | 
					    CriticalAreaUnLock(pval);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if !NO_SYS
 | 
					#if !NO_SYS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
err_t
 | 
					err_t sys_sem_new(sys_sem_t* sem, u8_t count)
 | 
				
			||||||
sys_sem_new(sys_sem_t *sem, u8_t count) {
 | 
					{
 | 
				
			||||||
    *sem = KSemaphoreCreate((uint16)count);
 | 
					    *sem = KSemaphoreCreate((uint16)count);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if SYS_STATS
 | 
					#if SYS_STATS
 | 
				
			||||||
| 
						 | 
					@ -130,7 +133,7 @@ sys_sem_new(sys_sem_t *sem, u8_t count) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#endif /* SYS_STATS */
 | 
					#endif /* SYS_STATS */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if(*sem >= 0)
 | 
					    if (*sem >= 0)
 | 
				
			||||||
        return ERR_OK;
 | 
					        return ERR_OK;
 | 
				
			||||||
    else {
 | 
					    else {
 | 
				
			||||||
#if SYS_STATS
 | 
					#if SYS_STATS
 | 
				
			||||||
| 
						 | 
					@ -141,8 +144,8 @@ sys_sem_new(sys_sem_t *sem, u8_t count) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void sys_sem_free(sys_sem_t* sem)
 | 
				
			||||||
sys_sem_free(sys_sem_t *sem) {
 | 
					{
 | 
				
			||||||
#if SYS_STATS
 | 
					#if SYS_STATS
 | 
				
			||||||
    --lwip_stats.sys.sem.used;
 | 
					    --lwip_stats.sys.sem.used;
 | 
				
			||||||
#endif /* SYS_STATS */
 | 
					#endif /* SYS_STATS */
 | 
				
			||||||
| 
						 | 
					@ -150,24 +153,24 @@ sys_sem_free(sys_sem_t *sem) {
 | 
				
			||||||
    *sem = SYS_SEM_NULL;
 | 
					    *sem = SYS_SEM_NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int sys_sem_valid(sys_sem_t *sem) {
 | 
					int sys_sem_valid(sys_sem_t* sem)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return (*sem > SYS_SEM_NULL);
 | 
					    return (*sem > SYS_SEM_NULL);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void sys_sem_set_invalid(sys_sem_t* sem)
 | 
				
			||||||
sys_sem_set_invalid(sys_sem_t *sem) {
 | 
					{
 | 
				
			||||||
    *sem = SYS_SEM_NULL;
 | 
					    *sem = SYS_SEM_NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout) {
 | 
					u32_t sys_arch_sem_wait(sys_sem_t* sem, u32_t timeout)
 | 
				
			||||||
  x_ticks_t start_tick = 0 ;
 | 
					{
 | 
				
			||||||
 | 
					    x_ticks_t start_tick = 0;
 | 
				
			||||||
    int32 wait_time = 0;
 | 
					    int32 wait_time = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (*sem == SYS_SEM_NULL)
 | 
				
			||||||
  if(*sem == SYS_SEM_NULL)
 | 
					 | 
				
			||||||
        return SYS_ARCH_TIMEOUT;
 | 
					        return SYS_ARCH_TIMEOUT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    start_tick = CurrentTicksGain();
 | 
					    start_tick = CurrentTicksGain();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (0 == timeout)
 | 
					    if (0 == timeout)
 | 
				
			||||||
| 
						 | 
					@ -175,19 +178,20 @@ u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout) {
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        wait_time = timeout;
 | 
					        wait_time = timeout;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (KSemaphoreObtain(*sem, wait_time) == EOK)
 | 
				
			||||||
  if(KSemaphoreObtain(*sem, wait_time) == EOK)
 | 
					        return CalculateTimeMsFromTick(CurrentTicksGain() - start_tick);
 | 
				
			||||||
    return CalculateTimeMsFromTick(CurrentTicksGain()-start_tick);
 | 
					 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        return SYS_ARCH_TIMEOUT;
 | 
					        return SYS_ARCH_TIMEOUT;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void sys_sem_signal(sys_sem_t *sem) {
 | 
					void sys_sem_signal(sys_sem_t* sem)
 | 
				
			||||||
  if(KSemaphoreAbandon(*sem) != EOK)
 | 
					{
 | 
				
			||||||
 | 
					    if (KSemaphoreAbandon(*sem) != EOK)
 | 
				
			||||||
        KPrintf("[sys_arch]:sem signal fail!\n");
 | 
					        KPrintf("[sys_arch]:sem signal fail!\n");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
err_t sys_mutex_new(sys_mutex_t *mutex) {
 | 
					err_t sys_mutex_new(sys_mutex_t* mutex)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    *mutex = KMutexCreate();
 | 
					    *mutex = KMutexCreate();
 | 
				
			||||||
    if (*mutex > SYS_MRTEX_NULL)
 | 
					    if (*mutex > SYS_MRTEX_NULL)
 | 
				
			||||||
        return ERR_OK;
 | 
					        return ERR_OK;
 | 
				
			||||||
| 
						 | 
					@ -197,24 +201,28 @@ err_t sys_mutex_new(sys_mutex_t *mutex) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void sys_mutex_free(sys_mutex_t *mutex) {
 | 
					void sys_mutex_free(sys_mutex_t* mutex)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    KMutexDelete(*mutex);
 | 
					    KMutexDelete(*mutex);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void sys_mutex_set_invalid(sys_mutex_t *mutex) {
 | 
					void sys_mutex_set_invalid(sys_mutex_t* mutex)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    *mutex = SYS_MRTEX_NULL;
 | 
					    *mutex = SYS_MRTEX_NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void sys_mutex_lock(sys_mutex_t *mutex) {
 | 
					void sys_mutex_lock(sys_mutex_t* mutex)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    KMutexObtain(*mutex, WAITING_FOREVER);
 | 
					    KMutexObtain(*mutex, WAITING_FOREVER);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void sys_mutex_unlock(sys_mutex_t *mutex) {
 | 
					void sys_mutex_unlock(sys_mutex_t* mutex)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    KMutexAbandon(*mutex);
 | 
					    KMutexAbandon(*mutex);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					sys_thread_t sys_thread_new(const char* name, lwip_thread_fn function, void* arg, int stacksize, int prio)
 | 
				
			||||||
sys_thread_t sys_thread_new(const char *name, lwip_thread_fn function, void *arg, int stacksize, int prio) {
 | 
					{
 | 
				
			||||||
    sys_thread_t handle = -1;
 | 
					    sys_thread_t handle = -1;
 | 
				
			||||||
    handle = KTaskCreate(name,
 | 
					    handle = KTaskCreate(name,
 | 
				
			||||||
        function,
 | 
					        function,
 | 
				
			||||||
| 
						 | 
					@ -230,8 +238,9 @@ sys_thread_t sys_thread_new(const char *name, lwip_thread_fn function, void *arg
 | 
				
			||||||
    return -ERROR;
 | 
					    return -ERROR;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
err_t sys_mbox_new(sys_mbox_t *mbox, int size) {
 | 
					err_t sys_mbox_new(sys_mbox_t* mbox, int size)
 | 
				
			||||||
  *mbox = KCreateMsgQueue(sizeof(void *), size);
 | 
					{
 | 
				
			||||||
 | 
					    *mbox = KCreateMsgQueue(sizeof(void*), size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if SYS_STATS
 | 
					#if SYS_STATS
 | 
				
			||||||
    ++lwip_stats.sys.mbox.used;
 | 
					    ++lwip_stats.sys.mbox.used;
 | 
				
			||||||
| 
						 | 
					@ -239,7 +248,7 @@ err_t sys_mbox_new(sys_mbox_t *mbox, int size) {
 | 
				
			||||||
        lwip_stats.sys.mbox.max = lwip_stats.sys.mbox.used;
 | 
					        lwip_stats.sys.mbox.max = lwip_stats.sys.mbox.used;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
#endif /* SYS_STATS */
 | 
					#endif /* SYS_STATS */
 | 
				
			||||||
  if(*mbox < 0) {
 | 
					    if (*mbox < 0) {
 | 
				
			||||||
        lw_print("lw: [%s] alloc %d mbox %p failed\n", __func__, size, mbox);
 | 
					        lw_print("lw: [%s] alloc %d mbox %p failed\n", __func__, size, mbox);
 | 
				
			||||||
        return ERR_MEM;
 | 
					        return ERR_MEM;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -248,39 +257,46 @@ err_t sys_mbox_new(sys_mbox_t *mbox, int size) {
 | 
				
			||||||
    return ERR_OK;
 | 
					    return ERR_OK;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void sys_mbox_free(sys_mbox_t *mbox) {
 | 
					void sys_mbox_free(sys_mbox_t* mbox)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    KDeleteMsgQueue(*mbox);
 | 
					    KDeleteMsgQueue(*mbox);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int sys_mbox_valid(sys_mbox_t *mbox) {
 | 
					int sys_mbox_valid(sys_mbox_t* mbox)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    if (*mbox <= SYS_MBOX_NULL)
 | 
					    if (*mbox <= SYS_MBOX_NULL)
 | 
				
			||||||
        return 0;
 | 
					        return 0;
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        return 1;
 | 
					        return 1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void sys_mbox_set_invalid(sys_mbox_t *mbox) {
 | 
					void sys_mbox_set_invalid(sys_mbox_t* mbox)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    *mbox = SYS_MBOX_NULL;
 | 
					    *mbox = SYS_MBOX_NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void sys_mbox_post(sys_mbox_t *q, void *msg) {
 | 
					void sys_mbox_post(sys_mbox_t* q, void* msg)
 | 
				
			||||||
  KMsgQueueSendwait(*q, &msg, sizeof(void *), WAITING_FOREVER);
 | 
					{
 | 
				
			||||||
 | 
					    KMsgQueueSendwait(*q, &msg, sizeof(void*), WAITING_FOREVER);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
err_t sys_mbox_trypost(sys_mbox_t *q, void *msg) {
 | 
					err_t sys_mbox_trypost(sys_mbox_t* q, void* msg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    // if(KMsgQueueSend(*q, &msg, sizeof(void *)) == EOK)
 | 
					    // if(KMsgQueueSend(*q, &msg, sizeof(void *)) == EOK)
 | 
				
			||||||
  if(KMsgQueueSend(*q, &msg, sizeof(void *)) == EOK)
 | 
					    if (KMsgQueueSend(*q, &msg, sizeof(void*)) == EOK)
 | 
				
			||||||
        return ERR_OK;
 | 
					        return ERR_OK;
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        return ERR_MEM;
 | 
					        return ERR_MEM;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
err_t sys_mbox_trypost_fromisr(sys_mbox_t *q, void *msg) {
 | 
					err_t sys_mbox_trypost_fromisr(sys_mbox_t* q, void* msg)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    return sys_mbox_trypost(q, msg);
 | 
					    return sys_mbox_trypost(q, msg);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
u32_t sys_arch_mbox_fetch(sys_mbox_t *q, void **msg, u32_t timeout) {
 | 
					u32_t sys_arch_mbox_fetch(sys_mbox_t* q, void** msg, u32_t timeout)
 | 
				
			||||||
  x_ticks_t start_tick = 0 ;
 | 
					{
 | 
				
			||||||
 | 
					    x_ticks_t start_tick = 0;
 | 
				
			||||||
    int32 wait_time = 0;
 | 
					    int32 wait_time = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    start_tick = CurrentTicksGain();
 | 
					    start_tick = CurrentTicksGain();
 | 
				
			||||||
| 
						 | 
					@ -290,15 +306,16 @@ u32_t sys_arch_mbox_fetch(sys_mbox_t *q, void **msg, u32_t timeout) {
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        wait_time = timeout;
 | 
					        wait_time = timeout;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if(KMsgQueueRecv(*q, &(*msg), sizeof(void *), wait_time) == EOK) {
 | 
					    if (KMsgQueueRecv(*q, &(*msg), sizeof(void*), wait_time) == EOK) {
 | 
				
			||||||
        return CalculateTimeMsFromTick(CurrentTicksGain() - start_tick);
 | 
					        return CalculateTimeMsFromTick(CurrentTicksGain() - start_tick);
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        return SYS_ARCH_TIMEOUT;
 | 
					        return SYS_ARCH_TIMEOUT;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
u32_t sys_arch_mbox_tryfetch(sys_mbox_t *q, void **msg) {
 | 
					u32_t sys_arch_mbox_tryfetch(sys_mbox_t* q, void** msg)
 | 
				
			||||||
  if (KMsgQueueRecv(*q, &(*msg), sizeof(void *), 0) == EOK)
 | 
					{
 | 
				
			||||||
 | 
					    if (KMsgQueueRecv(*q, &(*msg), sizeof(void*), 0) == EOK)
 | 
				
			||||||
        return ERR_OK;
 | 
					        return ERR_OK;
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        return SYS_MBOX_EMPTY;
 | 
					        return SYS_MBOX_EMPTY;
 | 
				
			||||||
| 
						 | 
					@ -315,7 +332,8 @@ ip4_addr_t ipaddr;
 | 
				
			||||||
ip4_addr_t netmask;
 | 
					ip4_addr_t netmask;
 | 
				
			||||||
ip4_addr_t gw;
 | 
					ip4_addr_t gw;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void lwip_config_input(struct netif *net) {
 | 
					void lwip_config_input(struct netif* net)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
    sys_thread_t th_id = 0;
 | 
					    sys_thread_t th_id = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    th_id = sys_thread_new("eth_input", ethernetif_input, net, LWIP_TASK_STACK_SIZE, 20);
 | 
					    th_id = sys_thread_new("eth_input", ethernetif_input, net, LWIP_TASK_STACK_SIZE, 20);
 | 
				
			||||||
| 
						 | 
					@ -327,13 +345,16 @@ void lwip_config_input(struct netif *net) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
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)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    sys_sem_new(get_eth_recv_sem(), 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ip4_addr_t net_ipaddr, net_netmask, net_gw;
 | 
					    ip4_addr_t net_ipaddr, net_netmask, net_gw;
 | 
				
			||||||
    char* eth_cfg;
 | 
					    char* eth_cfg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    eth_cfg = ethernetif_config_enet_set(enet_port);
 | 
					    eth_cfg = ethernetif_config_enet_set(enet_port);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if(chk_lwip_bit(LWIP_INIT_FLAG)) {
 | 
					    if (chk_lwip_bit(LWIP_INIT_FLAG)) {
 | 
				
			||||||
        lw_print("lw: [%s] already ...\n", __func__);
 | 
					        lw_print("lw: [%s] already ...\n", __func__);
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -367,25 +388,25 @@ void lwip_config_tcp(uint8_t enet_port, char *ip, char *mask, char *gw) {
 | 
				
			||||||
    lw_print("\r\n************************************************\r\n");
 | 
					    lw_print("\r\n************************************************\r\n");
 | 
				
			||||||
    lw_print(" Network Configuration\r\n");
 | 
					    lw_print(" Network Configuration\r\n");
 | 
				
			||||||
    lw_print("************************************************\r\n");
 | 
					    lw_print("************************************************\r\n");
 | 
				
			||||||
  lw_print(" IPv4 Address   : %u.%u.%u.%u\r\n", ((u8_t *)&net_ipaddr)[0], ((u8_t *)&net_ipaddr)[1],
 | 
					    lw_print(" IPv4 Address   : %u.%u.%u.%u\r\n", ((u8_t*)&net_ipaddr)[0], ((u8_t*)&net_ipaddr)[1],
 | 
				
			||||||
       ((u8_t *)&net_ipaddr)[2], ((u8_t *)&net_ipaddr)[3]);
 | 
					        ((u8_t*)&net_ipaddr)[2], ((u8_t*)&net_ipaddr)[3]);
 | 
				
			||||||
  lw_print(" IPv4 Subnet mask : %u.%u.%u.%u\r\n", ((u8_t *)&net_netmask)[0], ((u8_t *)&net_netmask)[1],
 | 
					    lw_print(" IPv4 Subnet mask : %u.%u.%u.%u\r\n", ((u8_t*)&net_netmask)[0], ((u8_t*)&net_netmask)[1],
 | 
				
			||||||
       ((u8_t *)&net_netmask)[2], ((u8_t *)&net_netmask)[3]);
 | 
					        ((u8_t*)&net_netmask)[2], ((u8_t*)&net_netmask)[3]);
 | 
				
			||||||
  lw_print(" IPv4 Gateway   : %u.%u.%u.%u\r\n", ((u8_t *)&net_gw)[0], ((u8_t *)&net_gw)[1],
 | 
					    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]);
 | 
					        ((u8_t*)&net_gw)[2], ((u8_t*)&net_gw)[3]);
 | 
				
			||||||
    lw_print("************************************************\r\n");
 | 
					    lw_print("************************************************\r\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    lwip_config_input(&gnetif);
 | 
					    lwip_config_input(&gnetif);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void lwip_config_net(uint8_t enet_port, char* ip, char* mask, char* gw)
 | 
				
			||||||
void lwip_config_net(uint8_t enet_port, char *ip, char *mask, char *gw) {
 | 
					{
 | 
				
			||||||
    ip4_addr_t net_ipaddr, net_netmask, net_gw;
 | 
					    ip4_addr_t net_ipaddr, net_netmask, net_gw;
 | 
				
			||||||
    char* eth_cfg;
 | 
					    char* eth_cfg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    eth_cfg = ethernetif_config_enet_set(enet_port);
 | 
					    eth_cfg = ethernetif_config_enet_set(enet_port);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if(chk_lwip_bit(LWIP_INIT_FLAG)) {
 | 
					    if (chk_lwip_bit(LWIP_INIT_FLAG)) {
 | 
				
			||||||
        lw_print("lw: [%s] already ...\n", __func__);
 | 
					        lw_print("lw: [%s] already ...\n", __func__);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        IP4_ADDR(&net_ipaddr, ip[0], ip[1], ip[2], ip[3]);
 | 
					        IP4_ADDR(&net_ipaddr, ip[0], ip[1], ip[2], ip[3]);
 | 
				
			||||||
| 
						 | 
					@ -410,7 +431,7 @@ void lwip_config_net(uint8_t enet_port, char *ip, char *mask, char *gw) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    lwip_init();
 | 
					    lwip_init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if(0 == enet_port) {
 | 
					    if (0 == enet_port) {
 | 
				
			||||||
#ifdef NETIF_ENET0_INIT_FUNC
 | 
					#ifdef NETIF_ENET0_INIT_FUNC
 | 
				
			||||||
        netif_add(&gnetif, &net_ipaddr, &net_netmask, &net_gw, eth_cfg, NETIF_ENET0_INIT_FUNC,
 | 
					        netif_add(&gnetif, &net_ipaddr, &net_netmask, &net_gw, eth_cfg, NETIF_ENET0_INIT_FUNC,
 | 
				
			||||||
            ethernet_input);
 | 
					            ethernet_input);
 | 
				
			||||||
| 
						 | 
					@ -425,18 +446,17 @@ void lwip_config_net(uint8_t enet_port, char *ip, char *mask, char *gw) {
 | 
				
			||||||
    netif_set_default(&gnetif);
 | 
					    netif_set_default(&gnetif);
 | 
				
			||||||
    netif_set_up(&gnetif);
 | 
					    netif_set_up(&gnetif);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if(chk_lwip_bit(LWIP_PRINT_FLAG)) {
 | 
					    if (chk_lwip_bit(LWIP_PRINT_FLAG)) {
 | 
				
			||||||
        lw_notice("\r\n************************************************\r\n");
 | 
					        lw_notice("\r\n************************************************\r\n");
 | 
				
			||||||
        lw_notice(" Network Configuration\r\n");
 | 
					        lw_notice(" Network Configuration\r\n");
 | 
				
			||||||
        lw_notice("************************************************\r\n");
 | 
					        lw_notice("************************************************\r\n");
 | 
				
			||||||
    lw_notice(" IPv4 Address   : %u.%u.%u.%u\r\n", ((u8_t *)&net_ipaddr)[0], ((u8_t *)&net_ipaddr)[1],
 | 
					        lw_notice(" IPv4 Address   : %u.%u.%u.%u\r\n", ((u8_t*)&net_ipaddr)[0], ((u8_t*)&net_ipaddr)[1],
 | 
				
			||||||
         ((u8_t *)&net_ipaddr)[2], ((u8_t *)&net_ipaddr)[3]);
 | 
					            ((u8_t*)&net_ipaddr)[2], ((u8_t*)&net_ipaddr)[3]);
 | 
				
			||||||
    lw_notice(" IPv4 Subnet mask : %u.%u.%u.%u\r\n", ((u8_t *)&net_netmask)[0], ((u8_t *)&net_netmask)[1],
 | 
					        lw_notice(" IPv4 Subnet mask : %u.%u.%u.%u\r\n", ((u8_t*)&net_netmask)[0], ((u8_t*)&net_netmask)[1],
 | 
				
			||||||
         ((u8_t *)&net_netmask)[2], ((u8_t *)&net_netmask)[3]);
 | 
					            ((u8_t*)&net_netmask)[2], ((u8_t*)&net_netmask)[3]);
 | 
				
			||||||
    lw_notice(" IPv4 Gateway   : %u.%u.%u.%u\r\n", ((u8_t *)&net_gw)[0], ((u8_t *)&net_gw)[1],
 | 
					        lw_notice(" 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]);
 | 
					            ((u8_t*)&net_gw)[2], ((u8_t*)&net_gw)[3]);
 | 
				
			||||||
        lw_notice("************************************************\r\n");
 | 
					        lw_notice("************************************************\r\n");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    lwip_config_input(&gnetif);
 | 
					    lwip_config_input(&gnetif);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -314,7 +314,7 @@ ip4addr_ntoa_r(const ip4_addr_t *addr, char *buf, int buflen)
 | 
				
			||||||
    *rp++ = '.';
 | 
					    *rp++ = '.';
 | 
				
			||||||
    ap++;
 | 
					    ap++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  *--rp = 0;
 | 
					  *--rp = '\0';
 | 
				
			||||||
  return buf;
 | 
					  return buf;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,4 @@
 | 
				
			||||||
SRC_DIR += cmd_lwip
 | 
					SRC_DIR += cmd_lwip netdev
 | 
				
			||||||
LWIP_DIR := LwIP 
 | 
					LWIP_DIR := LwIP 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
include $(KERNEL_ROOT)/compiler.mk
 | 
					include $(KERNEL_ROOT)/compiler.mk
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,4 @@
 | 
				
			||||||
SRC_FILES := ping.c lwip_ping_demo.c lwip_tcp_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_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_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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -50,7 +50,7 @@ static void iperf_udp_client(void *thread_param)
 | 
				
			||||||
    send_size = IPERF_BUFSZ > 1470 ? 1470 : IPERF_BUFSZ;
 | 
					    send_size = IPERF_BUFSZ > 1470 ? 1470 : IPERF_BUFSZ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    sock = socket(PF_INET, SOCK_DGRAM, 0);
 | 
					    sock = socket(PF_INET, SOCK_DGRAM, 0);
 | 
				
			||||||
    if(sock < 0){
 | 
					    if(sock < 0) {
 | 
				
			||||||
        KPrintf("[%s:%d] can't create socket! exit!\n", __FILE__, __LINE__);
 | 
					        KPrintf("[%s:%d] can't create socket! exit!\n", __FILE__, __LINE__);
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -60,21 +60,21 @@ static void iperf_udp_client(void *thread_param)
 | 
				
			||||||
    server.sin_addr.s_addr = inet_addr(param.host);
 | 
					    server.sin_addr.s_addr = inet_addr(param.host);
 | 
				
			||||||
    memset(&(server.sin_zero), 0, sizeof(server.sin_zero));
 | 
					    memset(&(server.sin_zero), 0, sizeof(server.sin_zero));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (connect(sock, (struct sockaddr *)&server, sizeof(struct sockaddr))){
 | 
					    if (connect(sock, (struct sockaddr *)&server, sizeof(struct sockaddr))) {
 | 
				
			||||||
        lw_error("Unable to connect\n");
 | 
					        lw_error("Unable to connect\n");
 | 
				
			||||||
        closesocket(sock);
 | 
					        closesocket(sock);
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    buffer = malloc(IPERF_BUFSZ);
 | 
					    buffer = malloc(IPERF_BUFSZ);
 | 
				
			||||||
    if (buffer == NULL){
 | 
					    if (buffer == NULL) {
 | 
				
			||||||
        printf("[%s:%d] malloc failed\n", __FILE__, __LINE__);
 | 
					        printf("[%s:%d] malloc failed\n", __FILE__, __LINE__);
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    memset(buffer, 0x00, IPERF_BUFSZ);
 | 
					    memset(buffer, 0x00, IPERF_BUFSZ);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    KPrintf("iperf udp mode run...\n");
 | 
					    KPrintf("iperf udp mode run...\n");
 | 
				
			||||||
    while (param.mode != IPERF_MODE_STOP){
 | 
					    while (param.mode != IPERF_MODE_STOP) {
 | 
				
			||||||
        packet_count++;
 | 
					        packet_count++;
 | 
				
			||||||
        tick = CurrentTicksGain();
 | 
					        tick = CurrentTicksGain();
 | 
				
			||||||
        buffer[0] = htonl(packet_count);
 | 
					        buffer[0] = htonl(packet_count);
 | 
				
			||||||
| 
						 | 
					@ -101,12 +101,12 @@ static void iperf_udp_server(void *thread_param)
 | 
				
			||||||
    struct timeval timeout;
 | 
					    struct timeval timeout;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    buffer = malloc(IPERF_BUFSZ);
 | 
					    buffer = malloc(IPERF_BUFSZ);
 | 
				
			||||||
    if (buffer == NULL){
 | 
					    if (buffer == NULL) {
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    sock = socket(PF_INET, SOCK_DGRAM, 0);
 | 
					    sock = socket(PF_INET, SOCK_DGRAM, 0);
 | 
				
			||||||
    if(sock < 0){
 | 
					    if(sock < 0) {
 | 
				
			||||||
        KPrintf("can't create socket! exit!");
 | 
					        KPrintf("can't create socket! exit!");
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -117,35 +117,34 @@ static void iperf_udp_server(void *thread_param)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    timeout.tv_sec = 2;
 | 
					    timeout.tv_sec = 2;
 | 
				
			||||||
    timeout.tv_usec = 0;
 | 
					    timeout.tv_usec = 0;
 | 
				
			||||||
    if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) == -1){
 | 
					    if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) == -1) {
 | 
				
			||||||
        KPrintf("setsockopt failed!");
 | 
					        KPrintf("setsockopt failed!");
 | 
				
			||||||
        closesocket(sock);
 | 
					        closesocket(sock);
 | 
				
			||||||
        free(buffer);
 | 
					        free(buffer);
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (bind(sock, (struct sockaddr *)&server, sizeof(struct sockaddr_in)) < 0){
 | 
					    if (bind(sock, (struct sockaddr *)&server, sizeof(struct sockaddr_in)) < 0) {
 | 
				
			||||||
        KPrintf("iperf server bind failed! exit!");
 | 
					        KPrintf("iperf server bind failed! exit!");
 | 
				
			||||||
        closesocket(sock);
 | 
					        closesocket(sock);
 | 
				
			||||||
        free(buffer);
 | 
					        free(buffer);
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    while (param.mode != IPERF_MODE_STOP){
 | 
					    while (param.mode != IPERF_MODE_STOP) {
 | 
				
			||||||
        tick1 = CurrentTicksGain();
 | 
					        tick1 = CurrentTicksGain();
 | 
				
			||||||
        tick2 = tick1;
 | 
					        tick2 = tick1;
 | 
				
			||||||
        lost = 0;
 | 
					        lost = 0;
 | 
				
			||||||
        total = 0;
 | 
					        total = 0;
 | 
				
			||||||
        sentlen = 0;
 | 
					        sentlen = 0;
 | 
				
			||||||
        while ((tick2 - tick1) < (TICK_PER_SECOND * 5)){
 | 
					        while ((tick2 - tick1) < (TICK_PER_SECOND * 5)) {
 | 
				
			||||||
            r_size = recvfrom(sock, buffer, IPERF_BUFSZ, 0, (struct sockaddr *)&sender, (socklen_t*)&sender_len);
 | 
					            r_size = recvfrom(sock, buffer, IPERF_BUFSZ, 0, (struct sockaddr *)&sender, (socklen_t*)&sender_len);
 | 
				
			||||||
            if (r_size > 12){
 | 
					            if (r_size > 12) {
 | 
				
			||||||
                pcount = ntohl(buffer[0]);
 | 
					                pcount = ntohl(buffer[0]);
 | 
				
			||||||
                if (last_pcount < pcount){
 | 
					                if (last_pcount < pcount) {
 | 
				
			||||||
                    lost += pcount - last_pcount - 1;
 | 
					                    lost += pcount - last_pcount - 1;
 | 
				
			||||||
                    total += pcount - last_pcount;
 | 
					                    total += pcount - last_pcount;
 | 
				
			||||||
                }
 | 
					                } else {
 | 
				
			||||||
                else{
 | 
					 | 
				
			||||||
                    last_pcount = pcount;
 | 
					                    last_pcount = pcount;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                last_pcount = pcount;
 | 
					                last_pcount = pcount;
 | 
				
			||||||
| 
						 | 
					@ -153,7 +152,7 @@ static void iperf_udp_server(void *thread_param)
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            tick2 = CurrentTicksGain();
 | 
					            tick2 = CurrentTicksGain();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (sentlen > 0){
 | 
					        if (sentlen > 0) {
 | 
				
			||||||
            long data;
 | 
					            long data;
 | 
				
			||||||
            int integer, decimal;
 | 
					            int integer, decimal;
 | 
				
			||||||
            KTaskDescriptorType tid;
 | 
					            KTaskDescriptorType tid;
 | 
				
			||||||
| 
						 | 
					@ -186,10 +185,9 @@ static void iperf_client(void *thread_param)
 | 
				
			||||||
    for (i = 0; i < IPERF_BUFSZ; i ++)
 | 
					    for (i = 0; i < IPERF_BUFSZ; i ++)
 | 
				
			||||||
        send_buf[i] = i & 0xff;
 | 
					        send_buf[i] = i & 0xff;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    while (param.mode != IPERF_MODE_STOP)
 | 
					    while (param.mode != IPERF_MODE_STOP) {
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        sock = socket(AF_INET, SOCK_STREAM, 0);
 | 
					        sock = socket(AF_INET, SOCK_STREAM, 0);
 | 
				
			||||||
        if (sock < 0){
 | 
					        if (sock < 0) {
 | 
				
			||||||
            KPrintf("create socket failed!");
 | 
					            KPrintf("create socket failed!");
 | 
				
			||||||
            DelayKTask(TICK_PER_SECOND);
 | 
					            DelayKTask(TICK_PER_SECOND);
 | 
				
			||||||
            continue;
 | 
					            continue;
 | 
				
			||||||
| 
						 | 
					@ -200,8 +198,8 @@ static void iperf_client(void *thread_param)
 | 
				
			||||||
        addr.sin_addr.s_addr = inet_addr((char *)param.host);
 | 
					        addr.sin_addr.s_addr = inet_addr((char *)param.host);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        ret = connect(sock, (const struct sockaddr *)&addr, sizeof(addr));
 | 
					        ret = connect(sock, (const struct sockaddr *)&addr, sizeof(addr));
 | 
				
			||||||
        if (ret == -1){
 | 
					        if (ret == -1) {
 | 
				
			||||||
            if (tips){
 | 
					            if (tips) {
 | 
				
			||||||
                KPrintf("Connect to iperf server faile, Waiting for the server to open!");
 | 
					                KPrintf("Connect to iperf server faile, Waiting for the server to open!");
 | 
				
			||||||
                tips = 0;
 | 
					                tips = 0;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
| 
						 | 
					@ -224,9 +222,9 @@ static void iperf_client(void *thread_param)
 | 
				
			||||||
        sentlen = 0;
 | 
					        sentlen = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        tick1 = CurrentTicksGain();
 | 
					        tick1 = CurrentTicksGain();
 | 
				
			||||||
        while (param.mode != IPERF_MODE_STOP){
 | 
					        while (param.mode != IPERF_MODE_STOP) {
 | 
				
			||||||
            tick2 = CurrentTicksGain();
 | 
					            tick2 = CurrentTicksGain();
 | 
				
			||||||
            if (tick2 - tick1 >= TICK_PER_SECOND * 5){
 | 
					            if (tick2 - tick1 >= TICK_PER_SECOND * 5) {
 | 
				
			||||||
                double speed;
 | 
					                double speed;
 | 
				
			||||||
                // int integer, decimal;
 | 
					                // int integer, decimal;
 | 
				
			||||||
                KTaskDescriptorType tid;
 | 
					                KTaskDescriptorType tid;
 | 
				
			||||||
| 
						 | 
					@ -240,7 +238,7 @@ static void iperf_client(void *thread_param)
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            ret = send(sock, send_buf, IPERF_BUFSZ, 0);
 | 
					            ret = send(sock, send_buf, IPERF_BUFSZ, 0);
 | 
				
			||||||
            if (ret > 0){
 | 
					            if (ret > 0) {
 | 
				
			||||||
                sentlen += ret;
 | 
					                sentlen += ret;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -264,7 +262,7 @@ struct sock_conn_cb {
 | 
				
			||||||
    int parent_id;
 | 
					    int parent_id;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void iperf_sever_worker(void* arg) {
 | 
					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;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -287,7 +285,7 @@ void iperf_sever_worker(void* arg) {
 | 
				
			||||||
    int cur_tid = GetKTaskDescriptor()->id.id;
 | 
					    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);
 | 
				
			||||||
        if (bytes_received == 0) {
 | 
					        if (bytes_received == 0) {
 | 
				
			||||||
            KPrintf("client disconnected (%s, %d)\n",
 | 
					            KPrintf("client disconnected (%s, %d)\n",
 | 
				
			||||||
| 
						 | 
					@ -336,7 +334,7 @@ void iperf_server_multithread(void *thread_param)
 | 
				
			||||||
    struct timeval timeout;
 | 
					    struct timeval timeout;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    sock = socket(AF_INET, SOCK_STREAM, 0);
 | 
					    sock = socket(AF_INET, SOCK_STREAM, 0);
 | 
				
			||||||
    if (sock < 0){
 | 
					    if (sock < 0) {
 | 
				
			||||||
        KPrintf("[%s:%d] Socket error!\n", __FILE__, __LINE__);
 | 
					        KPrintf("[%s:%d] Socket error!\n", __FILE__, __LINE__);
 | 
				
			||||||
        goto __exit;
 | 
					        goto __exit;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -346,12 +344,12 @@ void iperf_server_multithread(void *thread_param)
 | 
				
			||||||
    server_addr.sin_addr.s_addr = INADDR_ANY;
 | 
					    server_addr.sin_addr.s_addr = INADDR_ANY;
 | 
				
			||||||
    memset(&(server_addr.sin_zero), 0x0, sizeof(server_addr.sin_zero));
 | 
					    memset(&(server_addr.sin_zero), 0x0, sizeof(server_addr.sin_zero));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (bind(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1){
 | 
					    if (bind(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1) {
 | 
				
			||||||
        KPrintf("Unable to bind!\n");
 | 
					        KPrintf("Unable to bind!\n");
 | 
				
			||||||
        goto __exit;
 | 
					        goto __exit;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (listen(sock, 5) == -1){
 | 
					    if (listen(sock, 5) == -1) {
 | 
				
			||||||
        KPrintf("Listen error!\n");
 | 
					        KPrintf("Listen error!\n");
 | 
				
			||||||
        goto __exit;
 | 
					        goto __exit;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -360,7 +358,7 @@ void iperf_server_multithread(void *thread_param)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    timeout.tv_sec = 5;
 | 
					    timeout.tv_sec = 5;
 | 
				
			||||||
    timeout.tv_usec = 0;
 | 
					    timeout.tv_usec = 0;
 | 
				
			||||||
    while (param.mode != IPERF_MODE_STOP){
 | 
					    while (param.mode != IPERF_MODE_STOP) {
 | 
				
			||||||
        FD_ZERO(&readset);
 | 
					        FD_ZERO(&readset);
 | 
				
			||||||
        FD_SET(sock, &readset);
 | 
					        FD_SET(sock, &readset);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -379,8 +377,8 @@ void iperf_server_multithread(void *thread_param)
 | 
				
			||||||
        sccb->client_addr = client_addr;
 | 
					        sccb->client_addr = client_addr;
 | 
				
			||||||
        sccb->server_addr = server_addr;
 | 
					        sccb->server_addr = server_addr;
 | 
				
			||||||
        sccb->parent_id = cur_tid;
 | 
					        sccb->parent_id = cur_tid;
 | 
				
			||||||
        int tid = KTaskCreate("iperf server", iperf_sever_worker, sccb, LWIP_TASK_STACK_SIZE, 20);
 | 
					        int tid = KTaskCreate("iperf server", iperf_server_worker, sccb, LWIP_TASK_STACK_SIZE, 20);
 | 
				
			||||||
        // iperf_sever_worker(sccb);
 | 
					        // iperf_server_worker(sccb);
 | 
				
			||||||
        if (tid) {
 | 
					        if (tid) {
 | 
				
			||||||
            StartupKTask(tid);
 | 
					            StartupKTask(tid);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
| 
						 | 
					@ -405,13 +403,13 @@ void iperf_server(void *thread_param)
 | 
				
			||||||
    struct timeval timeout;
 | 
					    struct timeval timeout;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    sock = socket(AF_INET, SOCK_STREAM, 0);
 | 
					    sock = socket(AF_INET, SOCK_STREAM, 0);
 | 
				
			||||||
    if (sock < 0){
 | 
					    if (sock < 0) {
 | 
				
			||||||
        KPrintf("[%s:%d] Socket error!\n", __FILE__, __LINE__);
 | 
					        KPrintf("[%s:%d] Socket error!\n", __FILE__, __LINE__);
 | 
				
			||||||
        goto __exit;
 | 
					        goto __exit;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    recv_data = (uint8_t *)malloc(IPERF_BUFSZ);
 | 
					    recv_data = (uint8_t *)malloc(IPERF_BUFSZ);
 | 
				
			||||||
    if (recv_data == NULL){
 | 
					    if (recv_data == NULL) {
 | 
				
			||||||
        KPrintf("No memory!\n");
 | 
					        KPrintf("No memory!\n");
 | 
				
			||||||
        goto __exit;
 | 
					        goto __exit;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -421,12 +419,12 @@ void iperf_server(void *thread_param)
 | 
				
			||||||
    server_addr.sin_addr.s_addr = INADDR_ANY;
 | 
					    server_addr.sin_addr.s_addr = INADDR_ANY;
 | 
				
			||||||
    memset(&(server_addr.sin_zero), 0x0, sizeof(server_addr.sin_zero));
 | 
					    memset(&(server_addr.sin_zero), 0x0, sizeof(server_addr.sin_zero));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (bind(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1){
 | 
					    if (bind(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1) {
 | 
				
			||||||
        KPrintf("Unable to bind!\n");
 | 
					        KPrintf("Unable to bind!\n");
 | 
				
			||||||
        goto __exit;
 | 
					        goto __exit;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (listen(sock, 5) == -1){
 | 
					    if (listen(sock, 5) == -1) {
 | 
				
			||||||
        KPrintf("Listen error!\n");
 | 
					        KPrintf("Listen error!\n");
 | 
				
			||||||
        goto __exit;
 | 
					        goto __exit;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -434,7 +432,7 @@ void iperf_server(void *thread_param)
 | 
				
			||||||
    timeout.tv_sec = 3;
 | 
					    timeout.tv_sec = 3;
 | 
				
			||||||
    timeout.tv_usec = 0;
 | 
					    timeout.tv_usec = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    while (param.mode != IPERF_MODE_STOP){
 | 
					    while (param.mode != IPERF_MODE_STOP) {
 | 
				
			||||||
        FD_ZERO(&readset);
 | 
					        FD_ZERO(&readset);
 | 
				
			||||||
        FD_SET(sock, &readset);
 | 
					        FD_SET(sock, &readset);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -458,7 +456,7 @@ void iperf_server(void *thread_param)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        recvlen = 0;
 | 
					        recvlen = 0;
 | 
				
			||||||
        tick1 = CurrentTicksGain();
 | 
					        tick1 = CurrentTicksGain();
 | 
				
			||||||
        while (param.mode != IPERF_MODE_STOP){
 | 
					        while (param.mode != IPERF_MODE_STOP) {
 | 
				
			||||||
            bytes_received = recv(connected, recv_data, IPERF_BUFSZ, 0);
 | 
					            bytes_received = recv(connected, recv_data, IPERF_BUFSZ, 0);
 | 
				
			||||||
            if (bytes_received == 0) {
 | 
					            if (bytes_received == 0) {
 | 
				
			||||||
                KPrintf("client disconnected (%s, %d)\n",
 | 
					                KPrintf("client disconnected (%s, %d)\n",
 | 
				
			||||||
| 
						 | 
					@ -526,48 +524,37 @@ int iperf(int argc, char **argv)
 | 
				
			||||||
    int use_udp = 0;
 | 
					    int use_udp = 0;
 | 
				
			||||||
    int index = 1;
 | 
					    int index = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (argc == 1)
 | 
					    if (argc == 1) {
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        goto __usage;
 | 
					        goto __usage;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (strcmp(argv[1], "-u") == 0)
 | 
					    if (strcmp(argv[1], "-u") == 0) {
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        index = 2;
 | 
					        index = 2;
 | 
				
			||||||
        use_udp = 1;
 | 
					        use_udp = 1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (strcmp(argv[index], "-h") == 0) goto __usage;
 | 
					    if (strcmp(argv[index], "-h") == 0) goto __usage;
 | 
				
			||||||
    else if (strcmp(argv[index], "--stop") == 0)
 | 
					    else if (strcmp(argv[index], "--stop") == 0) {
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        /* stop iperf */
 | 
					        /* stop iperf */
 | 
				
			||||||
        param.mode = IPERF_MODE_STOP;
 | 
					        param.mode = IPERF_MODE_STOP;
 | 
				
			||||||
        printf("iperf stop.\n");
 | 
					        printf("iperf stop.\n");
 | 
				
			||||||
        return 0;
 | 
					        return 0;
 | 
				
			||||||
    }
 | 
					    } else if (strcmp(argv[index], "-s") == 0) {
 | 
				
			||||||
    else if (strcmp(argv[index], "-s") == 0)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        mode = IPERF_MODE_SERVER; /* server mode */
 | 
					        mode = IPERF_MODE_SERVER; /* server mode */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* iperf -s -p 5000 */
 | 
					        /* iperf -s -p 5000 */
 | 
				
			||||||
        if (argc >= 4)
 | 
					        if (argc >= 4) {
 | 
				
			||||||
        {
 | 
					            if (strcmp(argv[index + 1], "-p") == 0) {
 | 
				
			||||||
            if (strcmp(argv[index + 1], "-p") == 0)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                port = atoi(argv[index + 2]);
 | 
					                port = atoi(argv[index + 2]);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else goto __usage;
 | 
					            else goto __usage;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    } else if (strcmp(argv[index], "-c") == 0) {
 | 
				
			||||||
    else if (strcmp(argv[index], "-c") == 0)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        mode = IPERF_MODE_CLIENT; /* client mode */
 | 
					        mode = IPERF_MODE_CLIENT; /* client mode */
 | 
				
			||||||
        if (argc < 3) goto __usage;
 | 
					        if (argc < 3) goto __usage;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        host = argv[index + 1];
 | 
					        host = argv[index + 1];
 | 
				
			||||||
        if (argc >= 5)
 | 
					        if (argc >= 5) {
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            /* iperf -c host -p port */
 | 
					            /* iperf -c host -p port */
 | 
				
			||||||
            if (strcmp(argv[index + 2], "-p") == 0)
 | 
					            if (strcmp(argv[index + 2], "-p") == 0) {
 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                port = atoi(argv[index + 3]);
 | 
					                port = atoi(argv[index + 3]);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else goto __usage;
 | 
					            else goto __usage;
 | 
				
			||||||
| 
						 | 
					@ -575,57 +562,43 @@ int iperf(int argc, char **argv)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else goto __usage;
 | 
					    else goto __usage;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (argc >= 7)
 | 
					    if (argc >= 7) {
 | 
				
			||||||
    {
 | 
					        if(strcmp(argv[argc - 2], "-m") == 0) {
 | 
				
			||||||
        if(strcmp(argv[argc - 2], "-m") == 0)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            numtid = atoi(argv[argc - 1]);
 | 
					            numtid = atoi(argv[argc - 1]);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else  goto __usage;
 | 
					        else  goto __usage;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* start iperf */
 | 
					    /* start iperf */
 | 
				
			||||||
    if (param.mode == IPERF_MODE_STOP)
 | 
					    if (param.mode == IPERF_MODE_STOP) {
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        int i = 0;
 | 
					        int i = 0;
 | 
				
			||||||
        char tid_name[NAME_NUM_MAX + 1] = {0};
 | 
					        char tid_name[NAME_NUM_MAX + 1] = {0};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        param.mode = mode;
 | 
					        param.mode = mode;
 | 
				
			||||||
        param.port = port;
 | 
					        param.port = port;
 | 
				
			||||||
        if (param.host)
 | 
					        if (param.host) {
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            free(param.host);
 | 
					            free(param.host);
 | 
				
			||||||
            param.host = NULL;
 | 
					            param.host = NULL;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (host) param.host = strdup(host);
 | 
					        if (host) param.host = strdup(host);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (i = 0; i < numtid; i++)
 | 
					        for (i = 0; i < numtid; i++) {
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            int32 tid = 0;
 | 
					            int32 tid = 0;
 | 
				
			||||||
            void (*function)(void *parameter);
 | 
					            void (*function)(void *parameter);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (use_udp)
 | 
					            if (use_udp) {
 | 
				
			||||||
            {
 | 
					                if (mode == IPERF_MODE_CLIENT) {
 | 
				
			||||||
                if (mode == IPERF_MODE_CLIENT)
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    snprintf(tid_name, sizeof(tid_name), "iperfc%02d", i + 1);
 | 
					                    snprintf(tid_name, sizeof(tid_name), "iperfc%02d", i + 1);
 | 
				
			||||||
                    function = iperf_udp_client;
 | 
					                    function = iperf_udp_client;
 | 
				
			||||||
                }
 | 
					                } else if (mode == IPERF_MODE_SERVER) {
 | 
				
			||||||
                else if (mode == IPERF_MODE_SERVER)
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    snprintf(tid_name, sizeof(tid_name), "iperfd%02d", i + 1);
 | 
					                    snprintf(tid_name, sizeof(tid_name), "iperfd%02d", i + 1);
 | 
				
			||||||
                    function = iperf_udp_server;
 | 
					                    function = iperf_udp_server;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            } else {
 | 
				
			||||||
            else
 | 
					                if (mode == IPERF_MODE_CLIENT) {
 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                if (mode == IPERF_MODE_CLIENT)
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    snprintf(tid_name, sizeof(tid_name), "iperfc%02d", i + 1);
 | 
					                    snprintf(tid_name, sizeof(tid_name), "iperfc%02d", i + 1);
 | 
				
			||||||
                    function = iperf_client;
 | 
					                    function = iperf_client;
 | 
				
			||||||
                }
 | 
					                } else if (mode == IPERF_MODE_SERVER) {
 | 
				
			||||||
                else if (mode == IPERF_MODE_SERVER)
 | 
					 | 
				
			||||||
                {
 | 
					 | 
				
			||||||
                    snprintf(tid_name, sizeof(tid_name), "iperfd%02d", i + 1);
 | 
					                    snprintf(tid_name, sizeof(tid_name), "iperfd%02d", i + 1);
 | 
				
			||||||
                    function = iperf_server_multithread;
 | 
					                    function = iperf_server_multithread;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
| 
						 | 
					@ -634,9 +607,7 @@ int iperf(int argc, char **argv)
 | 
				
			||||||
            tid = KTaskCreate(tid_name, function, NULL, LWIP_TASK_STACK_SIZE, 20);
 | 
					            tid = KTaskCreate(tid_name, function, NULL, LWIP_TASK_STACK_SIZE, 20);
 | 
				
			||||||
            if (tid) StartupKTask(tid);
 | 
					            if (tid) StartupKTask(tid);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    } else {
 | 
				
			||||||
    else
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        KPrintf("Please stop iperf firstly, by:\n");
 | 
					        KPrintf("Please stop iperf firstly, by:\n");
 | 
				
			||||||
        KPrintf("iperf --stop\n");
 | 
					        KPrintf("iperf --stop\n");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,48 +19,45 @@
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <board.h>
 | 
					#include <board.h>
 | 
				
			||||||
#include <sys_arch.h>
 | 
					 | 
				
			||||||
#include <shell.h>
 | 
					#include <shell.h>
 | 
				
			||||||
#include <sys.h>
 | 
					 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					#include <sys.h>
 | 
				
			||||||
 | 
					#include <sys_arch.h>
 | 
				
			||||||
 | 
					#include <xs_kdbg.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <netdev.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/******************************************************************************/
 | 
					/******************************************************************************/
 | 
				
			||||||
uint8_t enet_id = 0;
 | 
					uint8_t enet_id = 0;
 | 
				
			||||||
static void LwipSetIPTask(void *param)
 | 
					static void LwipSetIPTask(void* param)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    uint8_t enet_port = *(uint8_t *)param; ///< test enet port 
 | 
					    uint8_t enet_port = *(uint8_t*)param; ///< test enet port
 | 
				
			||||||
    printf("lw: [%s] config netport id[%d]\n", __func__, enet_port);
 | 
					    printf("lw: [%s] config netport id[%d]\n", __func__, enet_port);
 | 
				
			||||||
    // lwip_config_net(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
 | 
					    // lwip_config_net(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
 | 
				
			||||||
    lwip_config_tcp(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
 | 
					    lwip_config_tcp(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void LwipSetIPTest(int argc, char *argv[])
 | 
					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], "%d.%d.%d.%d", &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], "%d.%d.%d.%d", &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], "%d.%d.%d.%d", &lwip_gwaddr[0], &lwip_gwaddr[1], &lwip_gwaddr[2], &lwip_gwaddr[3]);
 | 
				
			||||||
        sscanf(argv[4], "%d", &enet_id);
 | 
					        sscanf(argv[4], "%d", &enet_id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if(0 == enet_id)
 | 
					        if (0 == enet_id) {
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            printf("save eth0 info\n");
 | 
					            printf("save eth0 info\n");
 | 
				
			||||||
            memcpy(lwip_eth0_ipaddr, lwip_ipaddr, 20);
 | 
					            memcpy(lwip_eth0_ipaddr, lwip_ipaddr, 20);
 | 
				
			||||||
            memcpy(lwip_eth0_netmask, lwip_netmask, 20);
 | 
					            memcpy(lwip_eth0_netmask, lwip_netmask, 20);
 | 
				
			||||||
            memcpy(lwip_eth0_gwaddr, lwip_gwaddr, 20);
 | 
					            memcpy(lwip_eth0_gwaddr, lwip_gwaddr, 20);
 | 
				
			||||||
        }
 | 
					        } else if (1 == enet_id) {
 | 
				
			||||||
        else if(1 == enet_id)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            printf("save eth1 info\n");
 | 
					            printf("save eth1 info\n");
 | 
				
			||||||
            memcpy(lwip_eth1_ipaddr, lwip_ipaddr, 20);
 | 
					            memcpy(lwip_eth1_ipaddr, lwip_ipaddr, 20);
 | 
				
			||||||
            memcpy(lwip_eth1_netmask, lwip_netmask, 20);
 | 
					            memcpy(lwip_eth1_netmask, lwip_netmask, 20);
 | 
				
			||||||
            memcpy(lwip_eth1_gwaddr, lwip_gwaddr, 20);
 | 
					            memcpy(lwip_eth1_gwaddr, lwip_gwaddr, 20);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    } 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], "%d.%d.%d.%d", &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));
 | 
				
			||||||
| 
						 | 
					@ -70,39 +67,56 @@ void LwipSetIPTest(int argc, char *argv[])
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(5),
 | 
					SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(5),
 | 
				
			||||||
     setip, LwipSetIPTest, setip [IP] [Netmask] [Gateway] [port]);
 | 
					    setip, LwipSetIPTest, setip[IP][Netmask][Gateway][port]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void LwipShowIPTask(int argc, char* argv[])
 | 
				
			||||||
void LwipShowIPTask(int argc, char *argv[])
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#ifdef configMAC_ADDR
 | 
					#ifdef configMAC_ADDR
 | 
				
			||||||
    char mac_addr0[] = configMAC_ADDR;
 | 
					    char mac_addr0[] = configMAC_ADDR;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // find default netdev
 | 
				
			||||||
 | 
					    struct netdev* netdev = netdev_get_by_name("en\0");
 | 
				
			||||||
 | 
					    if (netdev == NULL) {
 | 
				
			||||||
 | 
					        lw_notice("[%s] Netdev not found by name en\n");
 | 
				
			||||||
 | 
					        struct netdev* default_netdev = NETDEV_DEFAULT;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    lw_notice("\r\n************************************************\r\n");
 | 
					    lw_notice("\r\n************************************************\r\n");
 | 
				
			||||||
    lw_notice(" Network Configuration\r\n");
 | 
					    lw_notice(" Network Configuration\r\n");
 | 
				
			||||||
    lw_notice("************************************************\r\n");
 | 
					    lw_notice("************************************************\r\n");
 | 
				
			||||||
    lw_notice(" ETH0 IPv4 Address   : %u.%u.%u.%u\r\n", ((u8_t *)&lwip_eth0_ipaddr)[0], ((u8_t *)&lwip_eth0_ipaddr)[1],
 | 
					    //     lw_notice(" ETH0 IPv4 Address   : %u.%u.%u.%u\r\n", ((u8_t*)&lwip_eth0_ipaddr)[0], ((u8_t*)&lwip_eth0_ipaddr)[1],
 | 
				
			||||||
        ((u8_t *)&lwip_eth0_ipaddr)[2], ((u8_t *)&lwip_eth0_ipaddr)[3]);
 | 
					    //         ((u8_t*)&lwip_eth0_ipaddr)[2], ((u8_t*)&lwip_eth0_ipaddr)[3]);
 | 
				
			||||||
    lw_notice(" ETH0 IPv4 Subnet mask : %u.%u.%u.%u\r\n", ((u8_t *)&lwip_eth0_netmask)[0], ((u8_t *)&lwip_eth0_netmask)[1],
 | 
					    //     lw_notice(" ETH0 IPv4 Subnet mask : %u.%u.%u.%u\r\n", ((u8_t*)&lwip_eth0_netmask)[0], ((u8_t*)&lwip_eth0_netmask)[1],
 | 
				
			||||||
        ((u8_t *)&lwip_eth0_netmask)[2], ((u8_t *)&lwip_eth0_netmask)[3]);
 | 
					    //         ((u8_t*)&lwip_eth0_netmask)[2], ((u8_t*)&lwip_eth0_netmask)[3]);
 | 
				
			||||||
    lw_notice(" ETH0 IPv4 Gateway   : %u.%u.%u.%u\r\n", ((u8_t *)&lwip_gwaddr)[0], ((u8_t *)&lwip_eth0_gwaddr)[1],
 | 
					    //     lw_notice(" ETH0 IPv4 Gateway   : %u.%u.%u.%u\r\n", ((u8_t*)&lwip_gwaddr)[0], ((u8_t*)&lwip_eth0_gwaddr)[1],
 | 
				
			||||||
        ((u8_t *)&lwip_eth0_gwaddr)[2], ((u8_t *)&lwip_eth0_gwaddr)[3]);
 | 
					    //         ((u8_t*)&lwip_eth0_gwaddr)[2], ((u8_t*)&lwip_eth0_gwaddr)[3]);
 | 
				
			||||||
 | 
					    // #ifdef configMAC_ADDR
 | 
				
			||||||
 | 
					    //     lw_notice(" ETH0 MAC Address    : %x:%x:%x:%x:%x:%x\r\n", mac_addr0[0], mac_addr0[1], mac_addr0[2],
 | 
				
			||||||
 | 
					    //         mac_addr0[3], mac_addr0[4], mac_addr0[5]);
 | 
				
			||||||
 | 
					    // #endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    lw_notice(" ETH0 IPv4 Address   : %u.%u.%u.%u\r\n", ((u8_t*)&lwip_eth0_ipaddr)[0], ((u8_t*)&lwip_eth0_ipaddr)[1],
 | 
				
			||||||
 | 
					        ((u8_t*)&lwip_eth0_ipaddr)[2], ((u8_t*)&lwip_eth0_ipaddr)[3]);
 | 
				
			||||||
 | 
					    lw_notice(" ETH0 IPv4 Subnet mask : %u.%u.%u.%u\r\n", ((u8_t*)&lwip_eth0_netmask)[0], ((u8_t*)&lwip_eth0_netmask)[1],
 | 
				
			||||||
 | 
					        ((u8_t*)&lwip_eth0_netmask)[2], ((u8_t*)&lwip_eth0_netmask)[3]);
 | 
				
			||||||
 | 
					    lw_notice(" ETH0 IPv4 Gateway   : %u.%u.%u.%u\r\n", ((u8_t*)&lwip_gwaddr)[0], ((u8_t*)&lwip_eth0_gwaddr)[1],
 | 
				
			||||||
 | 
					        ((u8_t*)&lwip_eth0_gwaddr)[2], ((u8_t*)&lwip_eth0_gwaddr)[3]);
 | 
				
			||||||
#ifdef configMAC_ADDR
 | 
					#ifdef configMAC_ADDR
 | 
				
			||||||
    lw_notice(" ETH0 MAC Address    : %x:%x:%x:%x:%x:%x\r\n", mac_addr0[0], mac_addr0[1], mac_addr0[2],
 | 
					    lw_notice(" ETH0 MAC Address    : %x:%x:%x:%x:%x:%x\r\n", mac_addr0[0], mac_addr0[1], mac_addr0[2],
 | 
				
			||||||
        mac_addr0[3], mac_addr0[4], mac_addr0[5]);
 | 
					        mac_addr0[3], mac_addr0[4], mac_addr0[5]);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef BOARD_NET_COUNT
 | 
					#ifdef BOARD_NET_COUNT
 | 
				
			||||||
    if(BOARD_NET_COUNT > 1)
 | 
					    if (BOARD_NET_COUNT > 1) {
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        char mac_addr1[] = configMAC_ADDR_ETH1;
 | 
					        char mac_addr1[] = configMAC_ADDR_ETH1;
 | 
				
			||||||
        lw_notice("\r\n");
 | 
					        lw_notice("\r\n");
 | 
				
			||||||
        lw_notice(" ETH1 IPv4 Address   : %u.%u.%u.%u\r\n", ((u8_t *)&lwip_eth1_ipaddr)[0], ((u8_t *)&lwip_eth1_ipaddr)[1],
 | 
					        lw_notice(" ETH1 IPv4 Address   : %u.%u.%u.%u\r\n", ((u8_t*)&lwip_eth1_ipaddr)[0], ((u8_t*)&lwip_eth1_ipaddr)[1],
 | 
				
			||||||
            ((u8_t *)&lwip_eth1_ipaddr)[2], ((u8_t *)&lwip_eth1_ipaddr)[3]);
 | 
					            ((u8_t*)&lwip_eth1_ipaddr)[2], ((u8_t*)&lwip_eth1_ipaddr)[3]);
 | 
				
			||||||
        lw_notice(" ETH1 IPv4 Subnet mask : %u.%u.%u.%u\r\n", ((u8_t *)&lwip_eth1_netmask)[0], ((u8_t *)&lwip_eth1_netmask)[1],
 | 
					        lw_notice(" ETH1 IPv4 Subnet mask : %u.%u.%u.%u\r\n", ((u8_t*)&lwip_eth1_netmask)[0], ((u8_t*)&lwip_eth1_netmask)[1],
 | 
				
			||||||
            ((u8_t *)&lwip_eth1_netmask)[2], ((u8_t *)&lwip_eth1_netmask)[3]);
 | 
					            ((u8_t*)&lwip_eth1_netmask)[2], ((u8_t*)&lwip_eth1_netmask)[3]);
 | 
				
			||||||
        lw_notice(" ETH1 IPv4 Gateway   : %u.%u.%u.%u\r\n", ((u8_t *)&lwip_eth1_gwaddr)[0], ((u8_t *)&lwip_eth1_gwaddr)[1],
 | 
					        lw_notice(" ETH1 IPv4 Gateway   : %u.%u.%u.%u\r\n", ((u8_t*)&lwip_eth1_gwaddr)[0], ((u8_t*)&lwip_eth1_gwaddr)[1],
 | 
				
			||||||
            ((u8_t *)&lwip_eth1_gwaddr)[2], ((u8_t *)&lwip_eth1_gwaddr)[3]);
 | 
					            ((u8_t*)&lwip_eth1_gwaddr)[2], ((u8_t*)&lwip_eth1_gwaddr)[3]);
 | 
				
			||||||
        lw_notice(" ETH1 MAC Address    : %x:%x:%x:%x:%x:%x\r\n", mac_addr1[0], mac_addr1[1], mac_addr1[2],
 | 
					        lw_notice(" ETH1 MAC Address    : %x:%x:%x:%x:%x:%x\r\n", mac_addr1[0], mac_addr1[1], mac_addr1[2],
 | 
				
			||||||
            mac_addr1[3], mac_addr1[4], mac_addr1[5]);
 | 
					            mac_addr1[3], mac_addr1[4], mac_addr1[5]);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -111,5 +125,4 @@ void LwipShowIPTask(int argc, char *argv[])
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
 | 
					SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
 | 
				
			||||||
     showip, LwipShowIPTask, GetIp [IP] [Netmask] [Gateway]);
 | 
					    showip, LwipShowIPTask, GetIp[IP][Netmask][Gateway]);
 | 
				
			||||||
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -27,8 +27,8 @@
 | 
				
			||||||
#include "lwip/sockets.h"
 | 
					#include "lwip/sockets.h"
 | 
				
			||||||
#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_demo_ip[] = {192, 168, 250, 252};
 | 
					char tcp_server_ip[] = {192, 168, 130, 2};
 | 
				
			||||||
u16_t tcp_demo_port = 80;
 | 
					u16_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;
 | 
				
			||||||
| 
						 | 
					@ -39,14 +39,14 @@ static void LwipTcpSendTask(void *arg)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int fd = -1;
 | 
					    int fd = -1;
 | 
				
			||||||
    fd = socket(AF_INET, SOCK_STREAM, 0);
 | 
					    fd = socket(AF_INET, SOCK_STREAM, 0);
 | 
				
			||||||
    if (fd < 0)
 | 
					    if (fd < 0) {
 | 
				
			||||||
    {
 | 
					        KPrintf("Socket error\n");
 | 
				
			||||||
        lw_error("Socket error\n");
 | 
					 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    LwipTcpSocketParamType *param = (LwipTcpSocketParamType *)arg;
 | 
					    LwipTcpSocketParamType *param = (LwipTcpSocketParamType *)arg;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //configure tcp client param
 | 
				
			||||||
    struct sockaddr_in tcp_sock;
 | 
					    struct sockaddr_in tcp_sock;
 | 
				
			||||||
    tcp_sock.sin_family = AF_INET;
 | 
					    tcp_sock.sin_family = AF_INET;
 | 
				
			||||||
    tcp_sock.sin_port = htons(param->port);
 | 
					    tcp_sock.sin_port = htons(param->port);
 | 
				
			||||||
| 
						 | 
					@ -55,24 +55,22 @@ static void LwipTcpSendTask(void *arg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (connect(fd, (struct sockaddr *)&tcp_sock, sizeof(struct sockaddr)))
 | 
					    if (connect(fd, (struct sockaddr *)&tcp_sock, sizeof(struct sockaddr)))
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        lw_error("Unable to connect\n");
 | 
					        KPrintf("Unable to connect\n");
 | 
				
			||||||
        closesocket(fd);
 | 
					        closesocket(fd);
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    lw_notice("tcp connect success, start to send.\n");
 | 
					    KPrintf("tcp connect success, start to send.\n");
 | 
				
			||||||
    lw_notice("\n\nTarget Port:%d\n\n", tcp_sock.sin_port);
 | 
					    KPrintf("\n\nTarget Port:%d\n\n", tcp_sock.sin_port);
 | 
				
			||||||
    tcp_send_task_on = 1;
 | 
					    tcp_send_task_on = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    while(tcp_send_num > 0 || tcp_send_num == -1)
 | 
					    while(tcp_send_num > 0 || tcp_send_num == -1) {
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        sendto(fd, tcp_demo_msg, strlen(tcp_demo_msg), 0, (struct sockaddr*)&tcp_sock, sizeof(struct sockaddr));
 | 
					        sendto(fd, tcp_demo_msg, strlen(tcp_demo_msg), 0, (struct sockaddr*)&tcp_sock, sizeof(struct sockaddr));
 | 
				
			||||||
        lw_notice("Send tcp msg: %s \n", tcp_demo_msg);
 | 
					        KPrintf("Send tcp msg: %s \n", tcp_demo_msg);
 | 
				
			||||||
        if(tcp_send_num > 0)
 | 
					        if(tcp_send_num > 0) {
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            tcp_send_num--;
 | 
					            tcp_send_num--;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        DelayKTask(tcp_interval);
 | 
					        MdelayKTask(tcp_interval);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    closesocket(fd);
 | 
					    closesocket(fd);
 | 
				
			||||||
| 
						 | 
					@ -82,41 +80,39 @@ static void LwipTcpSendTask(void *arg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void LwipTcpSendTest(int argc, char *argv[])
 | 
					void LwipTcpSendTest(int argc, char *argv[])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if(tcp_send_task_on){
 | 
					    if(tcp_send_task_on) {
 | 
				
			||||||
        tcp_send_num = 0;
 | 
					        tcp_send_num = 0;
 | 
				
			||||||
        printf("waitting send task exit...\n");
 | 
					        printf("waitting send task exit...\n");
 | 
				
			||||||
        while(tcp_send_task_on){
 | 
					        while(tcp_send_task_on) {
 | 
				
			||||||
            DelayKTask(1000);
 | 
					            MdelayKTask(1000);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        tcp_send_num = 1;
 | 
					        tcp_send_num = 1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    LwipTcpSocketParamType param;
 | 
					    LwipTcpSocketParamType param;
 | 
				
			||||||
    uint8_t enet_port = 0;
 | 
					    uint8_t enet_port = 0;
 | 
				
			||||||
    memset(tcp_demo_msg, 0, LWIP_TEST_MSG_SIZE);
 | 
					    memset(tcp_demo_msg, 0, LWIP_TEST_MSG_SIZE);
 | 
				
			||||||
    if(argc >= 2)
 | 
					    if(argc >= 2) {
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        strncpy(tcp_demo_msg, argv[1], strlen(argv[1]));
 | 
					        strncpy(tcp_demo_msg, argv[1], strlen(argv[1]));
 | 
				
			||||||
    }
 | 
					    } else {
 | 
				
			||||||
    else
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        strncpy(tcp_demo_msg, "hello world", strlen("hello world"));
 | 
					        strncpy(tcp_demo_msg, "hello world", strlen("hello world"));
 | 
				
			||||||
 | 
					        tcp_send_num = 10;//send 10 msg to server
 | 
				
			||||||
 | 
					        tcp_interval = 100;//100ms
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    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], "%d.%d.%d.%d:%d", &tcp_demo_ip[0], &tcp_demo_ip[1], &tcp_demo_ip[2], &tcp_demo_ip[3], &tcp_demo_port) == EOK)
 | 
					            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[2], "%d.%d.%d.%d", &tcp_demo_ip[0], &tcp_demo_ip[1], &tcp_demo_ip[2], &tcp_demo_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);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    lw_notice("get ipaddr %d.%d.%d.%d:%d send msg %d times\n", tcp_demo_ip[0], tcp_demo_ip[1], tcp_demo_ip[2], tcp_demo_ip[3], tcp_demo_port, tcp_send_num);
 | 
					    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);
 | 
				
			||||||
    lwip_config_tcp(enet_port, lwip_ipaddr, lwip_netmask, tcp_demo_ip);
 | 
					    lwip_config_tcp(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    memcpy(param.ip, tcp_demo_ip, 4);
 | 
					    memcpy(param.ip, tcp_server_ip, 4);
 | 
				
			||||||
    param.port = tcp_demo_port;
 | 
					    param.port = tcp_server_port;
 | 
				
			||||||
    param.buf = malloc(LWIP_TEST_MSG_SIZE);
 | 
					    param.buf = malloc(LWIP_TEST_MSG_SIZE);
 | 
				
			||||||
    memcpy(param.buf, tcp_demo_msg, LWIP_TEST_MSG_SIZE);
 | 
					    memcpy(param.buf, tcp_demo_msg, LWIP_TEST_MSG_SIZE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -131,7 +127,96 @@ void LwipTcpRecvTest(void)
 | 
				
			||||||
    uint8_t enet_port = 0; ///< test enet port 0
 | 
					    uint8_t enet_port = 0; ///< test enet port 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    lwip_config_net(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
 | 
					    lwip_config_net(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
 | 
				
			||||||
    tcpecho_raw_init();
 | 
					
 | 
				
			||||||
 | 
					    uint8_t *recv_data;
 | 
				
			||||||
 | 
					    socklen_t sin_size;
 | 
				
			||||||
 | 
					    int sock = -1, connected, bytes_received, i;
 | 
				
			||||||
 | 
					    struct sockaddr_in server_addr, client_addr;
 | 
				
			||||||
 | 
					    fd_set readset;
 | 
				
			||||||
 | 
					    struct timeval timeout;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    sock = socket(AF_INET, SOCK_STREAM, 0);
 | 
				
			||||||
 | 
					    if (sock < 0) {
 | 
				
			||||||
 | 
					        KPrintf("[%s:%d] Socket error!\n", __FILE__, __LINE__);
 | 
				
			||||||
 | 
					        goto __exit;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    recv_data = (uint8_t *)malloc(128);
 | 
				
			||||||
 | 
					    if (recv_data == NULL) {
 | 
				
			||||||
 | 
					        KPrintf("No memory!\n");
 | 
				
			||||||
 | 
					        goto __exit;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //configure tcp server param
 | 
				
			||||||
 | 
					    server_addr.sin_family = AF_INET;
 | 
				
			||||||
 | 
					    server_addr.sin_port = htons(tcp_server_port);
 | 
				
			||||||
 | 
					    server_addr.sin_addr.s_addr = INADDR_ANY;
 | 
				
			||||||
 | 
					    memset(&(server_addr.sin_zero), 0x0, sizeof(server_addr.sin_zero));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (bind(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1) {
 | 
				
			||||||
 | 
					        KPrintf("Unable to bind!\n");
 | 
				
			||||||
 | 
					        goto __exit;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (listen(sock, 5) == -1){
 | 
				
			||||||
 | 
					        KPrintf("Listen error!\n");
 | 
				
			||||||
 | 
					        goto __exit;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    timeout.tv_sec = 30;
 | 
				
			||||||
 | 
					    timeout.tv_usec = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) == -1) {
 | 
				
			||||||
 | 
					        KPrintf("setsockopt failed!");
 | 
				
			||||||
 | 
					        goto __exit;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    while (1) {
 | 
				
			||||||
 | 
					        FD_ZERO(&readset);
 | 
				
			||||||
 | 
					        FD_SET(sock, &readset);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (select(sock + 1, &readset, NULL, NULL, &timeout) == 0) {
 | 
				
			||||||
 | 
					            continue;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        sin_size = sizeof(struct sockaddr_in);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        connected = accept(sock, (struct sockaddr *)&client_addr, &sin_size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        while (1) {
 | 
				
			||||||
 | 
					            bytes_received = recv(connected, recv_data, 128, 0);
 | 
				
			||||||
 | 
					            if (bytes_received == 0) {
 | 
				
			||||||
 | 
					                KPrintf("client disconnected (%s, %d)\n",
 | 
				
			||||||
 | 
					                    inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            } else if (bytes_received < 0) {
 | 
				
			||||||
 | 
					                KPrintf("recv error, client: (%s, %d)\n",
 | 
				
			||||||
 | 
					                    inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                KPrintf("new client connected from (%s, %d)\n",
 | 
				
			||||||
 | 
					                    inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
 | 
				
			||||||
 | 
					                KPrintf("recv data length %d Bytes\n", bytes_received);
 | 
				
			||||||
 | 
					                for (i = 0; i < bytes_received; i ++) {
 | 
				
			||||||
 | 
					                    KPrintf("data 0x%x\n", recv_data[i]);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                if (i = bytes_received) {
 | 
				
			||||||
 | 
					                    KPrintf("\r\n");
 | 
				
			||||||
 | 
					                    memset(recv_data, 0, sizeof(recv_data));
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (connected >= 0) {
 | 
				
			||||||
 | 
					            closesocket(connected);
 | 
				
			||||||
 | 
					            connected = -1;
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					__exit:
 | 
				
			||||||
 | 
					    if (sock >= 0) closesocket(sock);
 | 
				
			||||||
 | 
					    if (recv_data) free(recv_data);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
 | 
					SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,8 +30,8 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct udp_pcb *udpecho_raw_pcb;
 | 
					static struct udp_pcb *udpecho_raw_pcb;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char udp_demo_ip[] = {192, 168, 131, 1};
 | 
					char udp_server_ip[] = {192, 168, 130, 2};
 | 
				
			||||||
u16_t udp_demo_port = LWIP_TARGET_PORT;
 | 
					u16_t udp_server_port = LWIP_TARGET_PORT;
 | 
				
			||||||
int32 udp_send_num = 0;
 | 
					int32 udp_send_num = 0;
 | 
				
			||||||
int8 udp_send_task_on = 0;
 | 
					int8 udp_send_task_on = 0;
 | 
				
			||||||
uint32 udp_interval = 50;
 | 
					uint32 udp_interval = 50;
 | 
				
			||||||
| 
						 | 
					@ -45,38 +45,35 @@ static void LwipUDPSendTask(void *arg)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int cnt = LWIP_DEMO_TIMES;
 | 
					    int cnt = LWIP_DEMO_TIMES;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    lw_print("udp_send_demo start.\n");
 | 
					    KPrintf("udp_send_demo start.\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int socket_fd = -1;
 | 
					    int socket_fd = -1;
 | 
				
			||||||
    socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
 | 
					    socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
 | 
				
			||||||
    if (socket_fd < 0)
 | 
					    if (socket_fd < 0) {
 | 
				
			||||||
    {
 | 
					        KPrintf("Socket error\n");
 | 
				
			||||||
        lw_error("Socket error\n");
 | 
					 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    struct sockaddr_in udp_sock;
 | 
					    struct sockaddr_in udp_sock;
 | 
				
			||||||
    udp_sock.sin_family = AF_INET;
 | 
					    udp_sock.sin_family = AF_INET;
 | 
				
			||||||
    udp_sock.sin_port = htons(udp_demo_port);
 | 
					    udp_sock.sin_port = htons(udp_server_port);
 | 
				
			||||||
    udp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(udp_demo_ip[0], udp_demo_ip[1], udp_demo_ip[2], udp_demo_ip[3]));
 | 
					    udp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(udp_server_ip[0], udp_server_ip[1], udp_server_ip[2], udp_server_ip[3]));
 | 
				
			||||||
    memset(&(udp_sock.sin_zero), 0, sizeof(udp_sock.sin_zero));
 | 
					    memset(&(udp_sock.sin_zero), 0, sizeof(udp_sock.sin_zero));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (connect(socket_fd, (struct sockaddr *)&udp_sock, sizeof(struct sockaddr)))
 | 
					    if (connect(socket_fd, (struct sockaddr *)&udp_sock, sizeof(struct sockaddr))) {
 | 
				
			||||||
    {
 | 
					        KPrintf("Unable to connect\n");
 | 
				
			||||||
        lw_error("Unable to connect\n");
 | 
					 | 
				
			||||||
        closesocket(socket_fd);
 | 
					        closesocket(socket_fd);
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    lw_notice("UDP connect success, start to send.\n");
 | 
					    KPrintf("UDP connect success, start to send.\n");
 | 
				
			||||||
    lw_notice("\n\nTarget Port:%d\n\n", udp_sock.sin_port);
 | 
					    KPrintf("\n\nTarget Port:%d\n\n", udp_sock.sin_port);
 | 
				
			||||||
    udp_send_task_on = 1;
 | 
					    udp_send_task_on = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    while(udp_send_num > 0 || udp_send_num == -1)
 | 
					    while(udp_send_num > 0 || udp_send_num == -1) {
 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        sendto(socket_fd, udp_demo_msg, strlen(udp_demo_msg), 0, (struct sockaddr*)&udp_sock, sizeof(struct sockaddr));
 | 
					        sendto(socket_fd, udp_demo_msg, strlen(udp_demo_msg), 0, (struct sockaddr*)&udp_sock, sizeof(struct sockaddr));
 | 
				
			||||||
        lw_notice("Send UDP msg: %s \n", udp_demo_msg);
 | 
					        KPrintf("Send UDP msg: %s \n", udp_demo_msg);
 | 
				
			||||||
        DelayKTask(udp_interval);
 | 
					        MdelayKTask(udp_interval);
 | 
				
			||||||
        udp_send_num--;
 | 
					        udp_send_num--;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    closesocket(socket_fd);
 | 
					    closesocket(socket_fd);
 | 
				
			||||||
| 
						 | 
					@ -86,11 +83,11 @@ static void LwipUDPSendTask(void *arg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *LwipUdpSendTest(int argc, char *argv[])
 | 
					void *LwipUdpSendTest(int argc, char *argv[])
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if(udp_send_task_on){
 | 
					    if(udp_send_task_on) {
 | 
				
			||||||
        udp_send_num = 0;
 | 
					        udp_send_num = 0;
 | 
				
			||||||
        printf("waitting send task exit...\n");
 | 
					        printf("waitting send task exit...\n");
 | 
				
			||||||
        while(udp_send_task_on){
 | 
					        while(udp_send_task_on){
 | 
				
			||||||
            DelayKTask(1000);
 | 
					            MdelayKTask(1000);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        udp_send_num = 1;
 | 
					        udp_send_num = 1;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -98,89 +95,105 @@ void *LwipUdpSendTest(int argc, char *argv[])
 | 
				
			||||||
    uint8_t enet_port = 0; ///< test enet port 0
 | 
					    uint8_t enet_port = 0; ///< test enet port 0
 | 
				
			||||||
    memset(udp_demo_msg, 0, sizeof(udp_demo_msg));
 | 
					    memset(udp_demo_msg, 0, sizeof(udp_demo_msg));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if(argc == 1)
 | 
					    if(argc == 1) {
 | 
				
			||||||
    {
 | 
					        KPrintf("lw: [%s] gw %d.%d.%d.%d:%d\n", __func__, udp_server_ip[0], udp_server_ip[1], udp_server_ip[2], udp_server_ip[3], udp_server_port);
 | 
				
			||||||
        lw_print("lw: [%s] gw %d.%d.%d.%d:%d\n", __func__, udp_demo_ip[0], udp_demo_ip[1], udp_demo_ip[2], udp_demo_ip[3], udp_demo_port);
 | 
					 | 
				
			||||||
        strncpy(udp_demo_msg, hello_str, strlen(hello_str));
 | 
					        strncpy(udp_demo_msg, hello_str, strlen(hello_str));
 | 
				
			||||||
    }
 | 
					        udp_send_num = 10;
 | 
				
			||||||
    else
 | 
					        udp_interval = 100;
 | 
				
			||||||
    {
 | 
					    } else {
 | 
				
			||||||
        strncpy(udp_demo_msg, argv[1], strlen(argv[1]));
 | 
					        strncpy(udp_demo_msg, argv[1], strlen(argv[1]));
 | 
				
			||||||
        strncat(udp_demo_msg, "\r\n", 2);
 | 
					        strncat(udp_demo_msg, "\r\n", 2);
 | 
				
			||||||
        if(argc == 3)
 | 
					        if(argc == 3) {
 | 
				
			||||||
        {
 | 
					            sscanf(argv[2], "%d.%d.%d.%d:%d", &udp_server_ip[0], &udp_server_ip[1], &udp_server_ip[2], &udp_server_ip[3], &udp_server_port);
 | 
				
			||||||
            sscanf(argv[2], "%d.%d.%d.%d:%d", &udp_demo_ip[0], &udp_demo_ip[1], &udp_demo_ip[2], &udp_demo_ip[3], &udp_demo_port);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if(argc > 3)
 | 
					        if(argc > 3) {
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            sscanf(argv[3], "%d", &udp_send_num);
 | 
					            sscanf(argv[3], "%d", &udp_send_num);
 | 
				
			||||||
            sscanf(argv[4], "%d", &udp_interval);
 | 
					            sscanf(argv[4], "%d", &udp_interval);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    lw_print("lw: [%s] gw %d.%d.%d.%d:%d send time %d udp_interval %d\n", __func__, udp_demo_ip[0], udp_demo_ip[1], udp_demo_ip[2], udp_demo_ip[3], udp_demo_port, udp_send_num, udp_interval);
 | 
					    KPrintf("lw: [%s] gw %d.%d.%d.%d:%d send time %d udp_interval %d\n", __func__, udp_server_ip[0], udp_server_ip[1], udp_server_ip[2], udp_server_ip[3], udp_server_port, udp_send_num, udp_interval);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    lwip_config_net(enet_port, lwip_ipaddr, lwip_netmask, udp_demo_ip);
 | 
					    //init lwip and net dirver
 | 
				
			||||||
 | 
					    lwip_config_net(enet_port, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
 | 
				
			||||||
    sys_thread_new("udp send", LwipUDPSendTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
 | 
					    sys_thread_new("udp send", LwipUDPSendTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
 | 
					SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3),
 | 
				
			||||||
     UDPSend, LwipUdpSendTest, UDPSend msg [ip:port [num [interval]]]);
 | 
					     UDPSend, LwipUdpSendTest, UDPSend msg [ip:port [num [interval]]]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void LwipUdpRecvTask(void *arg, struct udp_pcb *upcb, struct pbuf *p,
 | 
					 | 
				
			||||||
                 const ip_addr_t *addr, u16_t port)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    int udp_len;
 | 
					 | 
				
			||||||
    err_t err;
 | 
					 | 
				
			||||||
    struct pbuf* udp_buf;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    LWIP_UNUSED_ARG(arg);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (p == NULL)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        return;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    udp_len = p->tot_len;
 | 
					 | 
				
			||||||
    lw_notice("Receive data :%dB\r\n", udp_len);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if(udp_len <= 80)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        lw_notice("%.*s\r\n", udp_len, (char *)(p->payload));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    udp_buf = pbuf_alloc(PBUF_TRANSPORT, PBUF_SIZE, PBUF_RAM);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    memset(udp_buf->payload, 0, PBUF_SIZE);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    err = pbuf_take(udp_buf, "Client receive success!\r\n", 27);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /* send received packet back to sender */
 | 
					 | 
				
			||||||
    udp_sendto(upcb, udp_buf, addr, port);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /* free the pbuf */
 | 
					 | 
				
			||||||
    pbuf_free(p);
 | 
					 | 
				
			||||||
    pbuf_free(udp_buf);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void LwipUdpRecvTest(void)
 | 
					void LwipUdpRecvTest(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    err_t err;
 | 
					 | 
				
			||||||
    uint8_t enet_port = 0; ///< test enet port 0
 | 
					    uint8_t enet_port = 0; ///< test enet port 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //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);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    udpecho_raw_pcb = udp_new_ip_type(IPADDR_TYPE_ANY);
 | 
					    uint8_t *recv_data;
 | 
				
			||||||
    if (udpecho_raw_pcb == NULL)
 | 
					    socklen_t sin_size;
 | 
				
			||||||
    {
 | 
					    int sock = -1, connected, bytes_received, i;
 | 
				
			||||||
        return;
 | 
					    struct sockaddr_in server_addr, client_addr;
 | 
				
			||||||
 | 
					    fd_set readset;
 | 
				
			||||||
 | 
					    struct timeval timeout;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    sock = socket(PF_INET, SOCK_DGRAM, 0);
 | 
				
			||||||
 | 
					    if (sock < 0) {
 | 
				
			||||||
 | 
					        KPrintf("[%s:%d] Socket error!\n", __FILE__, __LINE__);
 | 
				
			||||||
 | 
					        goto __exit;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    err = udp_bind(udpecho_raw_pcb, IP_ANY_TYPE, LWIP_LOCAL_PORT);
 | 
					    recv_data = (uint8_t *)malloc(128);
 | 
				
			||||||
    if (err == ERR_OK)
 | 
					    if (recv_data == NULL) {
 | 
				
			||||||
    {
 | 
					        KPrintf("No memory!\n");
 | 
				
			||||||
        udp_recv(udpecho_raw_pcb, LwipUdpRecvTask, NULL);
 | 
					        goto __exit;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //configure udp server param
 | 
				
			||||||
 | 
					    server_addr.sin_family = PF_INET;
 | 
				
			||||||
 | 
					    server_addr.sin_port = htons(udp_server_port);
 | 
				
			||||||
 | 
					    server_addr.sin_addr.s_addr = INADDR_ANY;
 | 
				
			||||||
 | 
					    memset(&(server_addr.sin_zero), 0x0, sizeof(server_addr.sin_zero));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (bind(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1) {
 | 
				
			||||||
 | 
					        KPrintf("Unable to bind!\n");
 | 
				
			||||||
 | 
					        goto __exit;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    timeout.tv_sec = 30;
 | 
				
			||||||
 | 
					    timeout.tv_usec = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) == -1) {
 | 
				
			||||||
 | 
					        KPrintf("setsockopt failed!");
 | 
				
			||||||
 | 
					        goto __exit;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    while (1) {
 | 
				
			||||||
 | 
					        bytes_received = recvfrom(sock, recv_data, 128, 0, (struct sockaddr *)&client_addr, (socklen_t*)&sin_size);
 | 
				
			||||||
 | 
					        if (bytes_received == 0) {
 | 
				
			||||||
 | 
					            KPrintf("client disconnected (%s, %d)\n",
 | 
				
			||||||
 | 
					                inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        } else if (bytes_received < 0) {
 | 
				
			||||||
 | 
					            KPrintf("recv error, client: (%s, %d)\n",
 | 
				
			||||||
 | 
					                inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            KPrintf("new client connected from (%s, %d)\n",
 | 
				
			||||||
 | 
					                inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
 | 
				
			||||||
 | 
					            KPrintf("recv data length %d Bytes\n", bytes_received);
 | 
				
			||||||
 | 
					            for (i = 0; i < bytes_received; i ++) {
 | 
				
			||||||
 | 
					                KPrintf("data 0x%x\n", recv_data[i]);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if (i = bytes_received) {
 | 
				
			||||||
 | 
					                KPrintf("\r\n");
 | 
				
			||||||
 | 
					                memset(recv_data, 0, sizeof(recv_data));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					__exit:
 | 
				
			||||||
 | 
					    if (sock >= 0) closesocket(sock);
 | 
				
			||||||
 | 
					    if (recv_data) free(recv_data);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
 | 
					SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,4 @@
 | 
				
			||||||
 | 
					SRC_FILES += netdev_register.c netdev_manipulate.c netdev_lowlevel.c
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					include $(KERNEL_ROOT)/compiler.mk
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,250 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (c) 2006-2022, RT-Thread Development Team
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * SPDX-License-Identifier: Apache-2.0
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Change Logs:
 | 
				
			||||||
 | 
					 * Date           Author       Notes
 | 
				
			||||||
 | 
					 * 2019-03-18     ChenYong     First version
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					* @file netdev_lowlevel.c
 | 
				
			||||||
 | 
					* @brief register low-level net dev function
 | 
				
			||||||
 | 
					* @version 3.0 
 | 
				
			||||||
 | 
					* @author AIIT XUOS Lab
 | 
				
			||||||
 | 
					* @date 2023-08-07
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*************************************************
 | 
				
			||||||
 | 
					File name: netdev_lowlevel.c
 | 
				
			||||||
 | 
					Description: register low-level net dev function
 | 
				
			||||||
 | 
					Others: take RT-Thread v4.0.2/components/driver/serial/serial.c for references
 | 
				
			||||||
 | 
					                https://github.com/RT-Thread/rt-thread/tree/v4.0.2
 | 
				
			||||||
 | 
					History: 
 | 
				
			||||||
 | 
					1. Date: 2023-08-07
 | 
				
			||||||
 | 
					Author: AIIT XUOS Lab
 | 
				
			||||||
 | 
					Modification: 
 | 
				
			||||||
 | 
					1. support low-level net dev set-ip, set-netmask, set-gw, set-status, set-link-status, set-dns-server and set-dhcp-status
 | 
				
			||||||
 | 
					*************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <netdev.h>
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					#include <xs_kdbg.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This function will set network interface device IP address.
 | 
				
			||||||
 | 
					 * @NOTE it can only be called in the network interface device driver.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param netdev the network interface device to change
 | 
				
			||||||
 | 
					 * @param ip_addr the new IP address
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void netdev_low_level_set_ipaddr(struct netdev* netdev, const ip_addr_t* ip_addr)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    CHECK(ip_addr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (netdev && ip_addr_cmp(&(netdev->ip_addr), ip_addr) == 0) {
 | 
				
			||||||
 | 
					        ip_addr_copy(netdev->ip_addr, *ip_addr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* execute IP address change callback function */
 | 
				
			||||||
 | 
					        if (netdev->addr_callback) {
 | 
				
			||||||
 | 
					            netdev->addr_callback(netdev, NETDEV_CB_ADDR_IP);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This function will set network interface device netmask address.
 | 
				
			||||||
 | 
					 * @NOTE it can only be called in the network interface device driver.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param netdev the network interface device to change
 | 
				
			||||||
 | 
					 * @param netmask the new netmask address
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void netdev_low_level_set_netmask(struct netdev* netdev, const ip_addr_t* netmask)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    CHECK(netmask);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (netdev && ip_addr_cmp(&(netdev->netmask), netmask) == 0) {
 | 
				
			||||||
 | 
					        ip_addr_copy(netdev->netmask, *netmask);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* execute netmask address change callback function */
 | 
				
			||||||
 | 
					        if (netdev->addr_callback) {
 | 
				
			||||||
 | 
					            netdev->addr_callback(netdev, NETDEV_CB_ADDR_NETMASK);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This function will set network interface device gateway address.
 | 
				
			||||||
 | 
					 * @NOTE it can only be called in the network interface device driver.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param netdev the network interface device to change
 | 
				
			||||||
 | 
					 * @param gw the new gateway address
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void netdev_low_level_set_gw(struct netdev* netdev, const ip_addr_t* gw)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    CHECK(gw);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (netdev && ip_addr_cmp(&(netdev->gw), gw) == 0) {
 | 
				
			||||||
 | 
					        ip_addr_copy(netdev->gw, *gw);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* execute gateway address change callback function */
 | 
				
			||||||
 | 
					        if (netdev->addr_callback) {
 | 
				
			||||||
 | 
					            netdev->addr_callback(netdev, NETDEV_CB_ADDR_GATEWAY);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This function will set network interface device DNS server address.
 | 
				
			||||||
 | 
					 * @NOTE it can only be called in the network interface device driver.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param netdev the network interface device to change
 | 
				
			||||||
 | 
					 * @param dns_num the number of the DNS server
 | 
				
			||||||
 | 
					 * @param dns_server the new DNS server address
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void netdev_low_level_set_dns_server(struct netdev* netdev, uint8_t dns_num, const ip_addr_t* dns_server)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    unsigned int index;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    CHECK(dns_server);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (netdev == NULL) {
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    /* check DNS servers is exist */
 | 
				
			||||||
 | 
					    for (index = 0; index < NETDEV_DNS_SERVERS_NUM; index++) {
 | 
				
			||||||
 | 
					        if (ip_addr_cmp(&(netdev->dns_servers[index]), dns_server)) {
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (dns_num < NETDEV_DNS_SERVERS_NUM) {
 | 
				
			||||||
 | 
					        ip_addr_copy(netdev->dns_servers[dns_num], *dns_server);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* execute DNS servers address change callback function */
 | 
				
			||||||
 | 
					        if (netdev->addr_callback) {
 | 
				
			||||||
 | 
					            netdev->addr_callback(netdev, NETDEV_CB_ADDR_DNS_SERVER);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* Change to the first link_up network interface device automatically */
 | 
				
			||||||
 | 
					static void netdev_auto_change_default(struct netdev* netdev)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    struct netdev* new_netdev = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (netdev->flags & NETDEV_FLAG_LINK_UP) {
 | 
				
			||||||
 | 
					        if (!(NETDEV_DEFAULT->flags & NETDEV_FLAG_LINK_UP)) {
 | 
				
			||||||
 | 
					            netdev_set_default(netdev);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (memcmp(netdev, NETDEV_DEFAULT, sizeof(struct netdev)) == 0) {
 | 
				
			||||||
 | 
					        new_netdev = netdev_get_first_by_flags(NETDEV_FLAG_LINK_UP);
 | 
				
			||||||
 | 
					        if (new_netdev) {
 | 
				
			||||||
 | 
					            netdev_set_default(new_netdev);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This function will set network interface device status.
 | 
				
			||||||
 | 
					 * @NOTE it can only be called in the network interface device driver.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param netdev the network interface device to change
 | 
				
			||||||
 | 
					 * @param is_up the new status
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void netdev_low_level_set_status(struct netdev* netdev, bool is_up)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (netdev && netdev_is_up(netdev) != is_up) {
 | 
				
			||||||
 | 
					        if (is_up) {
 | 
				
			||||||
 | 
					            netdev->flags |= NETDEV_FLAG_UP;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            netdev->flags &= ~NETDEV_FLAG_UP;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            /* change to the first link_up network interface device automatically */
 | 
				
			||||||
 | 
					            netdev_auto_change_default(netdev);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* execute  network interface device status change callback function */
 | 
				
			||||||
 | 
					        if (netdev->status_callback) {
 | 
				
			||||||
 | 
					            netdev->status_callback(netdev, is_up ? NETDEV_CB_STATUS_UP : NETDEV_CB_STATUS_DOWN);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This function will set network interface device active link status.
 | 
				
			||||||
 | 
					 * @NOTE it can only be called in the network interface device driver.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param netdev the network interface device to change
 | 
				
			||||||
 | 
					 * @param is_up the new link status
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void netdev_low_level_set_link_status(struct netdev* netdev, bool is_up)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (netdev && netdev_is_link_up(netdev) != is_up) {
 | 
				
			||||||
 | 
					        if (is_up) {
 | 
				
			||||||
 | 
					            netdev->flags |= NETDEV_FLAG_LINK_UP;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            netdev->flags &= ~NETDEV_FLAG_LINK_UP;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            /* set network interface device flags to internet down */
 | 
				
			||||||
 | 
					            netdev->flags &= ~NETDEV_FLAG_INTERNET_UP;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            netdev_auto_change_default(netdev);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* execute link status change callback function */
 | 
				
			||||||
 | 
					        if (netdev->status_callback) {
 | 
				
			||||||
 | 
					            netdev->status_callback(netdev, is_up ? NETDEV_CB_STATUS_LINK_UP : NETDEV_CB_STATUS_LINK_DOWN);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This function will set network interface device active internet status.
 | 
				
			||||||
 | 
					 * @NOTE it can only be called in the network interface device driver.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param netdev the network interface device to change
 | 
				
			||||||
 | 
					 * @param is_up the new internet status
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void netdev_low_level_set_internet_status(struct netdev* netdev, bool is_up)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (netdev && netdev_is_internet_up(netdev) != is_up) {
 | 
				
			||||||
 | 
					        if (is_up) {
 | 
				
			||||||
 | 
					            netdev->flags |= NETDEV_FLAG_INTERNET_UP;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            netdev->flags &= ~NETDEV_FLAG_INTERNET_UP;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* execute  network interface device status change callback function */
 | 
				
			||||||
 | 
					        if (netdev->status_callback) {
 | 
				
			||||||
 | 
					            netdev->status_callback(netdev, is_up ? NETDEV_CB_STATUS_INTERNET_UP : NETDEV_CB_STATUS_INTERNET_DOWN);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This function will set network interface device DHCP status.
 | 
				
			||||||
 | 
					 * @NOTE it can only be called in the network interface device driver.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param netdev the network interface device to change
 | 
				
			||||||
 | 
					 * @param is_up the new DHCP status
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void netdev_low_level_set_dhcp_status(struct netdev* netdev, bool is_enable)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (netdev && netdev_is_dhcp_enabled(netdev) != is_enable) {
 | 
				
			||||||
 | 
					        if (is_enable) {
 | 
				
			||||||
 | 
					            netdev->flags |= NETDEV_FLAG_DHCP;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            netdev->flags &= ~NETDEV_FLAG_DHCP;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /* execute DHCP status change callback function */
 | 
				
			||||||
 | 
					        if (netdev->status_callback) {
 | 
				
			||||||
 | 
					            netdev->status_callback(netdev, is_enable ? NETDEV_CB_STATUS_DHCP_ENABLE : NETDEV_CB_STATUS_DHCP_DISABLE);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,318 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (c) 2006-2022, RT-Thread Development Team
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * SPDX-License-Identifier: Apache-2.0
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Change Logs:
 | 
				
			||||||
 | 
					 * Date           Author       Notes
 | 
				
			||||||
 | 
					 * 2019-03-18     ChenYong     First version
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					* @file netdev_manipulate.c
 | 
				
			||||||
 | 
					* @brief register net dev function
 | 
				
			||||||
 | 
					* @version 3.0 
 | 
				
			||||||
 | 
					* @author AIIT XUOS Lab
 | 
				
			||||||
 | 
					* @date 2023-08-07
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*************************************************
 | 
				
			||||||
 | 
					File name: netdev_manipulate.c
 | 
				
			||||||
 | 
					Description: register net dev function
 | 
				
			||||||
 | 
					Others: take RT-Thread v4.0.2/components/driver/serial/serial.c for references
 | 
				
			||||||
 | 
					                https://github.com/RT-Thread/rt-thread/tree/v4.0.2
 | 
				
			||||||
 | 
					History: 
 | 
				
			||||||
 | 
					1. Date: 2023-08-07
 | 
				
			||||||
 | 
					Author: AIIT XUOS Lab
 | 
				
			||||||
 | 
					Modification: 
 | 
				
			||||||
 | 
					1. support net dev set-ip, set-netmask, set-gw, set-addr-callback, set-status-callback, set-up and set-down
 | 
				
			||||||
 | 
					*************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <netdev.h>
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					#include <xs_isr.h>
 | 
				
			||||||
 | 
					#include <xs_kdbg.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					inline int netdev_check_set_addr_condition(struct netdev* netdev)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (NULL == netdev->ops || NULL == netdev->ops->set_addr_info) {
 | 
				
			||||||
 | 
					        SYS_KDEBUG_LOG(NETDEV_DEBUG, ("The network interface device(%s) not support to set IP address.\n", netdev->name));
 | 
				
			||||||
 | 
					        return -ERROR;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // check whether dhcp enabled
 | 
				
			||||||
 | 
					    if (netdev_is_dhcp_enabled(netdev)) {
 | 
				
			||||||
 | 
					        SYS_KDEBUG_LOG(NETDEV_DEBUG, ("The network interface device(%s) DHCP capability is enable, not support set IP address.\n", netdev->name));
 | 
				
			||||||
 | 
					        return -ERROR;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return EOK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This function will set network interface device IP address.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param netdev the network interface device to change
 | 
				
			||||||
 | 
					 * @param ip_addr the new IP address
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @return  0: set IP address successfully
 | 
				
			||||||
 | 
					 *         -1: set IP address failed
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int netdev_set_ipaddr(struct netdev* netdev, const ip_addr_t* ipaddr)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    CHECK(netdev);
 | 
				
			||||||
 | 
					    CHECK(ipaddr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (EOK != netdev_check_set_addr_condition(netdev)) {
 | 
				
			||||||
 | 
					        return -ERROR;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return netdev->ops->set_addr_info(netdev, (ip_addr_t*)ipaddr, NULL, NULL);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This function will set network interface device netmask address.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param netdev the network interface device to change
 | 
				
			||||||
 | 
					 * @param netmask the new netmask address
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @return  0: set netmask address successfully
 | 
				
			||||||
 | 
					 *         -1: set netmask address failed
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int netdev_set_netmask(struct netdev* netdev, const ip_addr_t* netmask)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    CHECK(netdev);
 | 
				
			||||||
 | 
					    CHECK(netmask);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (EOK != netdev_check_set_addr_condition(netdev)) {
 | 
				
			||||||
 | 
					        return -ERROR;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return netdev->ops->set_addr_info(netdev, NULL, (ip_addr_t*)netmask, NULL);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This function will set network interface device gateway address.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param netdev the network interface device to change
 | 
				
			||||||
 | 
					 * @param gw the new gateway address
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @return  0: set gateway address successfully
 | 
				
			||||||
 | 
					 *         -1: set gateway address failed
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int netdev_set_gw(struct netdev* netdev, const ip_addr_t* gw)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    CHECK(netdev);
 | 
				
			||||||
 | 
					    CHECK(gw);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (EOK != netdev_check_set_addr_condition(netdev)) {
 | 
				
			||||||
 | 
					        return -ERROR;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* execute network interface device set gateway address operations */
 | 
				
			||||||
 | 
					    return netdev->ops->set_addr_info(netdev, NULL, NULL, (ip_addr_t*)gw);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This function will set network interface device DNS server address.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param netdev the network interface device to change
 | 
				
			||||||
 | 
					 * @param dns_num the number of the DNS server
 | 
				
			||||||
 | 
					 * @param dns_server the new DNS server address
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @return  0: set netmask address successfully
 | 
				
			||||||
 | 
					 *         -1: set netmask address failed
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int netdev_set_dns_server(struct netdev* netdev, uint8_t dns_num, const ip_addr_t* dns_server)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    CHECK(netdev);
 | 
				
			||||||
 | 
					    CHECK(dns_server);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // check dns server number
 | 
				
			||||||
 | 
					    if (dns_num >= NETDEV_DNS_SERVERS_NUM) {
 | 
				
			||||||
 | 
					        SYS_KDEBUG_LOG(NETDEV_DEBUG, ("The number of DNS servers(%d) set exceeds the maximum number(%d).\n", dns_num + 1, NETDEV_DNS_SERVERS_NUM));
 | 
				
			||||||
 | 
					        return -ERROR;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // check dns set function existence
 | 
				
			||||||
 | 
					    if (NULL == netdev->ops || NULL == netdev->ops->set_dns_server) {
 | 
				
			||||||
 | 
					        SYS_KDEBUG_LOG(NETDEV_DEBUG, ("The network interface device(%s) not support to set DNS server address.\n", netdev->name));
 | 
				
			||||||
 | 
					        return -ERROR;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return netdev->ops->set_dns_server(netdev, dns_num, (ip_addr_t*)dns_server);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This function will set callback to be called when the network interface device status has been changed.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param netdev the network interface device to change
 | 
				
			||||||
 | 
					 * @param status_callback the callback be called when the status has been changed.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void netdev_set_status_callback(struct netdev* netdev, netdev_callback_fn status_callback)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    CHECK(netdev);
 | 
				
			||||||
 | 
					    CHECK(status_callback);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    netdev->status_callback = status_callback;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This function will set callback to be called when the network interface device address has been changed.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param netdev the network interface device to change
 | 
				
			||||||
 | 
					 * @param addr_callback the callback be called when the address has been changed.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void netdev_set_addr_callback(struct netdev* netdev, netdev_callback_fn addr_callback)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    CHECK(netdev);
 | 
				
			||||||
 | 
					    CHECK(addr_callback);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    netdev->addr_callback = addr_callback;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This function will enable network interface device .
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param netdev the network interface device to change
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @return  0: set status successfully
 | 
				
			||||||
 | 
					 *         -1: set status failed
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int netdev_set_up(struct netdev* netdev)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    CHECK(netdev);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!netdev->ops || !netdev->ops->set_up) {
 | 
				
			||||||
 | 
					        SYS_KDEBUG_LOG(NETDEV_DEBUG, ("The network interface device(%s) not support to set status.\n", netdev->name));
 | 
				
			||||||
 | 
					        return -ERROR;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* network interface device status flags check */
 | 
				
			||||||
 | 
					    if (netdev_is_up(netdev)) {
 | 
				
			||||||
 | 
					        return EOK;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* execute enable network interface device operations by network interface device driver */
 | 
				
			||||||
 | 
					    return netdev->ops->set_up(netdev);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This function will disable network interface device.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param netdev the network interface device to change
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @return  0: set status successfully
 | 
				
			||||||
 | 
					 *         -1: set sttaus failed
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int netdev_set_down(struct netdev* netdev)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    CHECK(netdev);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (!netdev->ops || !netdev->ops->set_down) {
 | 
				
			||||||
 | 
					        SYS_KDEBUG_LOG(NETDEV_DEBUG, ("The network interface device(%s) not support to set status.\n", netdev->name));
 | 
				
			||||||
 | 
					        return -ERROR;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* network interface device status flags check */
 | 
				
			||||||
 | 
					    if (!netdev_is_up(netdev)) {
 | 
				
			||||||
 | 
					        return EOK;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* execute disable network interface device operations by network interface driver */
 | 
				
			||||||
 | 
					    return netdev->ops->set_down(netdev);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This function will get the first network interface device
 | 
				
			||||||
 | 
					 * with the flags in network interface device list.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param flags the network interface device flags
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @return != NULL: network interface device object
 | 
				
			||||||
 | 
					 *            NULL: get failed
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct netdev* netdev_get_first_by_flags(uint16_t flags)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (NETDEV_LISTHEAD == NULL) {
 | 
				
			||||||
 | 
					        return NULL;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // 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)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        if (NULL != current_dev && 0 != (current_dev->flags & flags)) {
 | 
				
			||||||
 | 
					            ENABLE_INTERRUPT(lock);
 | 
				
			||||||
 | 
					            return current_dev;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    ENABLE_INTERRUPT(lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return NULL;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This function will get the first network interface device
 | 
				
			||||||
 | 
					 * in network interface device list by IP address.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param ip_addr the network interface device IP address
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @return != NULL: network interface device object
 | 
				
			||||||
 | 
					 *            NULL: get failed
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct netdev* netdev_get_by_ipaddr(ip_addr_t* ip_addr)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (NETDEV_LISTHEAD == NULL) {
 | 
				
			||||||
 | 
					        return NULL;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // 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)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        if (NULL != current_dev && ip_addr_cmp(&(current_dev->ip_addr), ip_addr)) {
 | 
				
			||||||
 | 
					            ENABLE_INTERRUPT(lock);
 | 
				
			||||||
 | 
					            return current_dev;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    ENABLE_INTERRUPT(lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return NULL;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This function will get network interface device
 | 
				
			||||||
 | 
					 * in network interface device list by netdev name.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param name the network interface device name
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @return != NULL: network interface device object
 | 
				
			||||||
 | 
					 *            NULL: get failed
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					struct netdev* netdev_get_by_name(const char* name)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (NETDEV_LISTHEAD == NULL) {
 | 
				
			||||||
 | 
					        return NULL;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // 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)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        if (NULL == current_dev) {
 | 
				
			||||||
 | 
					            continue;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        uint32_t name_len = strlen(current_dev->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;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    ENABLE_INTERRUPT(lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return NULL;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,213 @@
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Copyright (c) 2006-2022, RT-Thread Development Team
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * SPDX-License-Identifier: Apache-2.0
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Change Logs:
 | 
				
			||||||
 | 
					 * Date           Author       Notes
 | 
				
			||||||
 | 
					 * 2019-03-18     ChenYong     First version
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					* @file netdev_register.c
 | 
				
			||||||
 | 
					* @brief register net dev function for net driver
 | 
				
			||||||
 | 
					* @version 3.0 
 | 
				
			||||||
 | 
					* @author AIIT XUOS Lab
 | 
				
			||||||
 | 
					* @date 2023-08-07
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*************************************************
 | 
				
			||||||
 | 
					File name: netdev_register.c
 | 
				
			||||||
 | 
					Description: register net dev function for net driver
 | 
				
			||||||
 | 
					Others: take RT-Thread v4.0.2/components/driver/serial/serial.c for references
 | 
				
			||||||
 | 
					                https://github.com/RT-Thread/rt-thread/tree/v4.0.2
 | 
				
			||||||
 | 
					History: 
 | 
				
			||||||
 | 
					1. Date: 2023-08-07
 | 
				
			||||||
 | 
					Author: AIIT XUOS Lab
 | 
				
			||||||
 | 
					Modification: 
 | 
				
			||||||
 | 
					1. support net dev register, unregister function
 | 
				
			||||||
 | 
					*************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <assert.h>
 | 
				
			||||||
 | 
					#include <def.h>
 | 
				
			||||||
 | 
					#include <netdev.h>
 | 
				
			||||||
 | 
					#include <netdev_ipaddr.h>
 | 
				
			||||||
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					#include <xs_isr.h>
 | 
				
			||||||
 | 
					#include <xs_kdbg.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct netdev** get_netdev_listhead()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    static struct netdev* netdev_listhead = NULL;
 | 
				
			||||||
 | 
					    return &netdev_listhead;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					struct netdev** get_default_netdev()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    static struct netdev* netdev_default = NULL;
 | 
				
			||||||
 | 
					    return &netdev_default;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					static netdev_callback_fn g_netdev_register_callback = NULL;
 | 
				
			||||||
 | 
					static netdev_callback_fn g_netdev_default_change_callback = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int netdev_register(struct netdev* netdev, const char* name, void* user_data)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    CHECK(netdev != NULL);
 | 
				
			||||||
 | 
					    CHECK(name != NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // set flag mask, assert network is down
 | 
				
			||||||
 | 
					    uint16_t flag_mask = 0;
 | 
				
			||||||
 | 
					    flag_mask = NETDEV_FLAG_UP | NETDEV_FLAG_LINK_UP | NETDEV_FLAG_INTERNET_UP | NETDEV_FLAG_DHCP;
 | 
				
			||||||
 | 
					    netdev->flags &= ~flag_mask;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // clear dev setting
 | 
				
			||||||
 | 
					    ip_addr_set_zero(&(netdev->ip_addr));
 | 
				
			||||||
 | 
					    ip_addr_set_zero(&(netdev->netmask));
 | 
				
			||||||
 | 
					    ip_addr_set_zero(&(netdev->gw));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    IP_SET_TYPE_VAL(netdev->ip_addr, IPADDR_TYPE_V4);
 | 
				
			||||||
 | 
					    IP_SET_TYPE_VAL(netdev->netmask, IPADDR_TYPE_V4);
 | 
				
			||||||
 | 
					    IP_SET_TYPE_VAL(netdev->gw, IPADDR_TYPE_V4);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if NETDEV_IPV6
 | 
				
			||||||
 | 
					    for (index = 0; index < NETDEV_IPV6_NUM_ADDRESSES; index++) {
 | 
				
			||||||
 | 
					        ip_addr_set_zero(&(netdev->ip6_addr[index]));
 | 
				
			||||||
 | 
					        IP_SET_TYPE_VAL(netdev->ip_addr, IPADDR_TYPE_V6);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					#endif /* NETDEV_IPV6 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // clear DNS servers
 | 
				
			||||||
 | 
					    for (uint16_t idx = 0; idx < NETDEV_DNS_SERVERS_NUM; idx++) {
 | 
				
			||||||
 | 
					        ip_addr_set_zero(&(netdev->dns_servers[idx]));
 | 
				
			||||||
 | 
					        IP_SET_TYPE_VAL(netdev->ip_addr, IPADDR_TYPE_V4);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    // clear callback fn
 | 
				
			||||||
 | 
					    netdev->addr_callback = NULL;
 | 
				
			||||||
 | 
					    netdev->status_callback = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // validate name
 | 
				
			||||||
 | 
					    uint32_t name_len = strlen(name);
 | 
				
			||||||
 | 
					    if (name_len < NAME_NUM_MAX) {
 | 
				
			||||||
 | 
					        strncpy(netdev->name, name, name_len);
 | 
				
			||||||
 | 
					        netdev->name[name_len] = '\0';
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        SYS_KDEBUG_LOG(NETDEV_DEBUG, ("[%s] name too long.\n", __func__));
 | 
				
			||||||
 | 
					        strncpy(netdev->name, name, NAME_NUM_MAX - 1);
 | 
				
			||||||
 | 
					        netdev->name[NAME_NUM_MAX - 1] = '\0';
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    netdev->user_data = user_data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    InitSingleLinkList(&(netdev->list));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // insert netdev to global list
 | 
				
			||||||
 | 
					    x_base lock = DISABLE_INTERRUPT();
 | 
				
			||||||
 | 
					    if (NETDEV_LISTHEAD == NULL) {
 | 
				
			||||||
 | 
					        NETDEV_LISTHEAD = netdev;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        SingleLinkListNodeInsert(&(NETDEV_LISTHEAD->list), &(netdev->list));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    ENABLE_INTERRUPT(lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (NETDEV_DEFAULT == NULL) {
 | 
				
			||||||
 | 
					        // set first met netdev to default netdev
 | 
				
			||||||
 | 
					        netdev_set_default(NETDEV_LISTHEAD);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (g_netdev_register_callback) {
 | 
				
			||||||
 | 
					        g_netdev_register_callback(netdev, NETDEV_CB_REGISTER);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return EOK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This function will unregister network interface device and
 | 
				
			||||||
 | 
					 * delete it from network interface device list.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param netdev the network interface device object
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @return  0: unregistered successfully
 | 
				
			||||||
 | 
					 *         -1: unregistered failed
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int netdev_unregister(struct netdev* netdev)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    CHECK(netdev);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (NETDEV_LISTHEAD == NULL) {
 | 
				
			||||||
 | 
					        return -ERROR;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // 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)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        // 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));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // deal default netdev
 | 
				
			||||||
 | 
					            if (current_dev == NETDEV_DEFAULT) {
 | 
				
			||||||
 | 
					                NETDEV_DEFAULT = NULL;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    ENABLE_INTERRUPT(lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (NETDEV_DEFAULT == NULL) {
 | 
				
			||||||
 | 
					        netdev_set_default(NETDEV_LISTHEAD);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // clean netdev if found one
 | 
				
			||||||
 | 
					    if (current_dev == netdev) {
 | 
				
			||||||
 | 
					        memset(netdev, 0, sizeof(*netdev));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return EOK;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This function will set default network interface device.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param netdev the network interface device to change
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void netdev_set_default(struct netdev* netdev)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (netdev && (netdev != NETDEV_DEFAULT)) {
 | 
				
			||||||
 | 
					        NETDEV_DEFAULT = netdev;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // set default function
 | 
				
			||||||
 | 
					        if (netdev->ops && netdev->ops->set_default) {
 | 
				
			||||||
 | 
					            netdev->ops->set_default(netdev);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // default change callback
 | 
				
			||||||
 | 
					        if (g_netdev_default_change_callback) {
 | 
				
			||||||
 | 
					            g_netdev_default_change_callback(netdev, NETDEV_CB_DEFAULT_CHANGE);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        SYS_KDEBUG_LOG(NETDEV_DEBUG, ("Setting default network interface device name(%s) successfully.\n", netdev->name));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * This function will set register callback
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param register_callback the network register callback
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					void netdev_set_register_callback(netdev_callback_fn register_callback)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    g_netdev_register_callback = register_callback;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void netdev_set_default_change_callback(netdev_callback_fn default_change_cb)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    g_netdev_default_change_callback = default_change_cb;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,181 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef __NETDEV_H__
 | 
				
			||||||
 | 
					#define __NETDEV_H__
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <netdev_ipaddr.h>
 | 
				
			||||||
 | 
					#include <stdbool.h>
 | 
				
			||||||
 | 
					#include <xs_klist.h>
 | 
				
			||||||
 | 
					#include <xs_kdbg.h>
 | 
				
			||||||
 | 
					#include <xsconfig.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
					extern "C" {
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#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__, \
 | 
				
			||||||
 | 
					        ((u8_t*)&ip)[0], ((u8_t*)&ip)[1], ((u8_t*)&ip)[2], ((u8_t*)&ip)[3], \
 | 
				
			||||||
 | 
					        ((u8_t*)&netmask)[0], ((u8_t*)&netmask)[1], ((u8_t*)&netmask)[2], ((u8_t*)&netmask)[3], \
 | 
				
			||||||
 | 
					        ((u8_t*)&gw)[0], ((u8_t*)&gw)[1], ((u8_t*)&gw)[2], ((u8_t*)&gw)[3])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* the maximum of all used hardware address lengths */
 | 
				
			||||||
 | 
					#ifndef NETDEV_HWADDR_MAX_LEN
 | 
				
			||||||
 | 
					#define NETDEV_HWADDR_MAX_LEN 8U
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* the maximum of dns server number supported */
 | 
				
			||||||
 | 
					#ifndef NETDEV_DNS_SERVERS_NUM
 | 
				
			||||||
 | 
					#define NETDEV_DNS_SERVERS_NUM 2U
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* whether the network interface device is 'up' (set by the network interface driver or application) */
 | 
				
			||||||
 | 
					#define NETDEV_FLAG_UP 0x01U
 | 
				
			||||||
 | 
					/* if set, the network interface device has broadcast capability, only supported in the 'lwIP' stack */
 | 
				
			||||||
 | 
					#define NETDEV_FLAG_BROADCAST 0x02U
 | 
				
			||||||
 | 
					/* if set, the network interface device has an active link (set by the network interface driver) */
 | 
				
			||||||
 | 
					#define NETDEV_FLAG_LINK_UP 0x04U
 | 
				
			||||||
 | 
					/* if set, the network interface device is an ethernet device using ARP, only supported in the 'lwIP' stack */
 | 
				
			||||||
 | 
					#define NETDEV_FLAG_ETHARP 0x08U
 | 
				
			||||||
 | 
					/* if set, the network interface device is an ethernet device, only supported in the 'lwIP' stack */
 | 
				
			||||||
 | 
					#define NETDEV_FLAG_ETHERNET 0x10U
 | 
				
			||||||
 | 
					/* if set, the network interface device has IGMP capability, only supported in the 'lwIP' stack */
 | 
				
			||||||
 | 
					#define NETDEV_FLAG_IGMP 0x20U
 | 
				
			||||||
 | 
					/* if set, the network interface device has MLD6 capability, only supported in the 'lwIP' stack */
 | 
				
			||||||
 | 
					#define NETDEV_FLAG_MLD6 0x40U
 | 
				
			||||||
 | 
					/* if set, the network interface device connected to internet successfully (set by the network interface driver) */
 | 
				
			||||||
 | 
					#define NETDEV_FLAG_INTERNET_UP 0x80U
 | 
				
			||||||
 | 
					/* if set, the network interface device has DHCP capability (set by the network interface device driver or application) */
 | 
				
			||||||
 | 
					#define NETDEV_FLAG_DHCP 0x100U
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enum netdev_cb_type {
 | 
				
			||||||
 | 
					    NETDEV_CB_ADDR_IP, /* IP address */
 | 
				
			||||||
 | 
					    NETDEV_CB_ADDR_NETMASK, /* subnet mask */
 | 
				
			||||||
 | 
					    NETDEV_CB_ADDR_GATEWAY, /* netmask */
 | 
				
			||||||
 | 
					    NETDEV_CB_ADDR_DNS_SERVER, /* dns server */
 | 
				
			||||||
 | 
					    NETDEV_CB_STATUS_UP, /* changed to 'up' */
 | 
				
			||||||
 | 
					    NETDEV_CB_STATUS_DOWN, /* changed to 'down' */
 | 
				
			||||||
 | 
					    NETDEV_CB_STATUS_LINK_UP, /* changed to 'link up' */
 | 
				
			||||||
 | 
					    NETDEV_CB_STATUS_LINK_DOWN, /* changed to 'link down' */
 | 
				
			||||||
 | 
					    NETDEV_CB_STATUS_INTERNET_UP, /* changed to 'internet up' */
 | 
				
			||||||
 | 
					    NETDEV_CB_STATUS_INTERNET_DOWN, /* changed to 'internet down' */
 | 
				
			||||||
 | 
					    NETDEV_CB_STATUS_DHCP_ENABLE, /* enable DHCP capability */
 | 
				
			||||||
 | 
					    NETDEV_CB_STATUS_DHCP_DISABLE, /* disable DHCP capability */
 | 
				
			||||||
 | 
					    NETDEV_CB_REGISTER, /* netdev register */
 | 
				
			||||||
 | 
					    NETDEV_CB_DEFAULT_CHANGE, /* netdev default change */
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct netdev;
 | 
				
			||||||
 | 
					typedef void (*netdev_callback_fn)(struct netdev* netdev, enum netdev_cb_type type);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct netdev_ops {
 | 
				
			||||||
 | 
					    /* set network interface device hardware status operations */
 | 
				
			||||||
 | 
					    int (*set_up)(struct netdev* netdev);
 | 
				
			||||||
 | 
					    int (*set_down)(struct netdev* netdev);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* set network interface device address information operations */
 | 
				
			||||||
 | 
					    int (*set_addr_info)(struct netdev* netdev, ip_addr_t* ip_addr, ip_addr_t* netmask, ip_addr_t* gw);
 | 
				
			||||||
 | 
					    int (*set_dns_server)(struct netdev* netdev, uint8_t dns_num, ip_addr_t* dns_server);
 | 
				
			||||||
 | 
					    int (*set_dhcp)(struct netdev* netdev, bool is_enabled);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef RT_USING_FINSH
 | 
				
			||||||
 | 
					    /* set network interface device common network interface device operations */
 | 
				
			||||||
 | 
					    int (*ping)(struct netdev* netdev, const char* host, size_t data_len, uint32_t timeout, struct netdev_ping_resp* ping_resp);
 | 
				
			||||||
 | 
					    void (*netstat)(struct netdev* netdev);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* set default network interface device in current network stack*/
 | 
				
			||||||
 | 
					    int (*set_default)(struct netdev* netdev);
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* network interface device object */
 | 
				
			||||||
 | 
					struct netdev {
 | 
				
			||||||
 | 
					    SysSingleLinklistType list;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    char name[NAME_NUM_MAX]; /* network interface device name */
 | 
				
			||||||
 | 
					    ip_addr_t ip_addr; /* IP address */
 | 
				
			||||||
 | 
					    ip_addr_t netmask; /* subnet mask */
 | 
				
			||||||
 | 
					    ip_addr_t gw; /* gateway */
 | 
				
			||||||
 | 
					#if NETDEV_IPV6
 | 
				
			||||||
 | 
					    ip_addr_t ip6_addr[NETDEV_IPV6_NUM_ADDRESSES]; /* array of IPv6 addresses */
 | 
				
			||||||
 | 
					#endif /* NETDEV_IPV6 */
 | 
				
			||||||
 | 
					    ip_addr_t dns_servers[NETDEV_DNS_SERVERS_NUM]; /* DNS server */
 | 
				
			||||||
 | 
					    uint8_t hwaddr_len; /* hardware address length */
 | 
				
			||||||
 | 
					    uint8_t hwaddr[NETDEV_HWADDR_MAX_LEN]; /* hardware address */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    uint16_t flags; /* network interface device status flag */
 | 
				
			||||||
 | 
					    uint16_t mtu; /* maximum transfer unit (in bytes) */
 | 
				
			||||||
 | 
					    const struct netdev_ops* ops; /* network interface device operations */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    netdev_callback_fn status_callback; /* network interface device flags change callback */
 | 
				
			||||||
 | 
					    netdev_callback_fn addr_callback; /* network interface device address information change callback */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef RT_USING_SAL
 | 
				
			||||||
 | 
					    void* sal_user_data; /* user-specific data for SAL */
 | 
				
			||||||
 | 
					#endif /* RT_USING_SAL */
 | 
				
			||||||
 | 
					    void* user_data; /* user-specific data */
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// netdev global list
 | 
				
			||||||
 | 
					#define NETDEV_LISTHEAD (*get_netdev_listhead())
 | 
				
			||||||
 | 
					#define NETDEV_DEFAULT (*get_default_netdev())
 | 
				
			||||||
 | 
					extern struct netdev** get_netdev_listhead();
 | 
				
			||||||
 | 
					extern struct netdev** get_default_netdev();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// netdev register functions: netdev_register.c
 | 
				
			||||||
 | 
					int netdev_register(struct netdev* netdev, const char* name, void* user_data);
 | 
				
			||||||
 | 
					int netdev_unregister(struct netdev* netdev);
 | 
				
			||||||
 | 
					void netdev_set_default(struct netdev* netdev);
 | 
				
			||||||
 | 
					void netdev_set_register_callback(netdev_callback_fn status_callback);
 | 
				
			||||||
 | 
					void netdev_set_default_change_callback(netdev_callback_fn default_change_cb);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// netdev manipulate functions: netdev_manipulate.c
 | 
				
			||||||
 | 
					struct netdev* netdev_get_first_by_flags(uint16_t flags);
 | 
				
			||||||
 | 
					struct netdev* netdev_get_by_ipaddr(ip_addr_t* ip_addr);
 | 
				
			||||||
 | 
					struct netdev* netdev_get_by_name(const char* name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int netdev_set_ipaddr(struct netdev* netdev, const ip_addr_t* ipaddr);
 | 
				
			||||||
 | 
					int netdev_set_netmask(struct netdev* netdev, const ip_addr_t* netmask);
 | 
				
			||||||
 | 
					int netdev_set_gw(struct netdev* netdev, const ip_addr_t* gw);
 | 
				
			||||||
 | 
					int netdev_set_dns_server(struct netdev* netdev, uint8_t dns_num, const ip_addr_t* dns_server);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void netdev_set_status_callback(struct netdev* netdev, netdev_callback_fn status_callback);
 | 
				
			||||||
 | 
					void netdev_set_addr_callback(struct netdev* netdev, netdev_callback_fn addr_callback);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*  Set network interface device status */
 | 
				
			||||||
 | 
					int netdev_set_up(struct netdev* netdev);
 | 
				
			||||||
 | 
					int netdev_set_down(struct netdev* netdev);
 | 
				
			||||||
 | 
					int netdev_dhcp_enabled(struct netdev* netdev, bool is_enabled);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// low level functions which should only be called by net drivers
 | 
				
			||||||
 | 
					void netdev_low_level_set_ipaddr(struct netdev* netdev, const ip_addr_t* ipaddr);
 | 
				
			||||||
 | 
					void netdev_low_level_set_netmask(struct netdev* netdev, const ip_addr_t* netmask);
 | 
				
			||||||
 | 
					void netdev_low_level_set_gw(struct netdev* netdev, const ip_addr_t* gw);
 | 
				
			||||||
 | 
					void netdev_low_level_set_dns_server(struct netdev* netdev, uint8_t dns_num, const ip_addr_t* dns_server);
 | 
				
			||||||
 | 
					void netdev_low_level_set_status(struct netdev* netdev, bool is_up);
 | 
				
			||||||
 | 
					void netdev_low_level_set_link_status(struct netdev* netdev, bool is_up);
 | 
				
			||||||
 | 
					void netdev_low_level_set_internet_status(struct netdev* netdev, bool is_up);
 | 
				
			||||||
 | 
					void netdev_low_level_set_dhcp_status(struct netdev* netdev, bool is_enable);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline bool netdev_is_dhcp_enabled(struct netdev* netdev)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return (netdev->flags & NETDEV_FLAG_DHCP) ? true : false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					static inline bool netdev_is_up(struct netdev* netdev)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return (netdev->flags & NETDEV_FLAG_UP) ? true : false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					static inline bool netdev_is_internet_up(struct netdev* netdev)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return (netdev->flags & NETDEV_FLAG_INTERNET_UP) ? true : false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					static inline bool netdev_is_link_up(struct netdev* netdev)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return (netdev->flags & NETDEV_FLAG_LINK_UP) ? true : false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,124 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef LWIP_HDR_IP4_ADDR_H
 | 
				
			||||||
 | 
					#ifndef __NETDEV_IPADDR_H__
 | 
				
			||||||
 | 
					#define __NETDEV_IPADDR_H__
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <def.h>
 | 
				
			||||||
 | 
					#include <stdbool.h>
 | 
				
			||||||
 | 
					#include <stdint.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
					extern "C" {
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Currently using netdev ipv4
 | 
				
			||||||
 | 
					#define NETDEV_IPV4 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* IP address types for use in ip_addr_t.type member */
 | 
				
			||||||
 | 
					enum netdev_ip_addr_type {
 | 
				
			||||||
 | 
					    /** IPv4 */
 | 
				
			||||||
 | 
					    IPADDR_TYPE_V4 = 0U,
 | 
				
			||||||
 | 
					    /** IPv6 */
 | 
				
			||||||
 | 
					    IPADDR_TYPE_V6 = 6U,
 | 
				
			||||||
 | 
					    /** IPv4+IPv6 ("dual-stack") */
 | 
				
			||||||
 | 
					    IPADDR_TYPE_ANY = 46U
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if (NETDEV_IPV4 && NETDEV_IPV6) /* Both IPV4 and IPV6 */
 | 
				
			||||||
 | 
					// Todo
 | 
				
			||||||
 | 
					#elif NETDEV_IPV4 /* NETDEV_IPV4 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define IP_SET_TYPE_VAL(ipaddr, iptype)
 | 
				
			||||||
 | 
					#define IP_SET_TYPE(ipaddr, iptype)
 | 
				
			||||||
 | 
					#define IP_GET_TYPE(ipaddr) IPADDR_TYPE_V4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define ip_addr_copy(dest, src) ip4_addr_copy(dest, src)
 | 
				
			||||||
 | 
					#define ip_addr_cmp(addr1, addr2) ip4_addr_cmp(addr1, addr2)
 | 
				
			||||||
 | 
					#define ip_addr_set(dest, src) ip4_addr_set(dest, src)
 | 
				
			||||||
 | 
					#define ip_addr_set_zero(ipaddr) ip4_addr_set_zero(ipaddr)
 | 
				
			||||||
 | 
					#define ip_addr_set_any(is_ipv6, ipaddr) ip4_addr_set_any(ipaddr)
 | 
				
			||||||
 | 
					#define ip_addr_isany_val(ipaddr) ip4_addr_isany_val(ipaddr)
 | 
				
			||||||
 | 
					#define ip_addr_isany(ipaddr) ip4_addr_isany(ipaddr)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* directly map this to the lwip internal functions */
 | 
				
			||||||
 | 
					#define inet_addr(cp) netdev_ipaddr_addr(cp)
 | 
				
			||||||
 | 
					#define inet_aton(cp, addr) netdev_ip4addr_aton(cp, (ip4_addr_t*)addr)
 | 
				
			||||||
 | 
					#define inet_ntoa(addr) netdev_ip4addr_ntoa((const ip4_addr_t*)&(addr))
 | 
				
			||||||
 | 
					#define inet_ntoa_r(addr, buf, buflen) netdev_ip4addr_ntoa_r((const ip4_addr_t*)&(addr), buf, buflen)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#else /* NETDEV_IPV6 */
 | 
				
			||||||
 | 
					// Todo
 | 
				
			||||||
 | 
					#endif /* NTDEV_IPV4 && NTDEV_IPV6 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef NETDEV_IPV4
 | 
				
			||||||
 | 
					/** IPv4 only: set the IP address given as an u32_t */
 | 
				
			||||||
 | 
					#define ip4_addr_set_u32(dest_ipaddr, src_u32) ((dest_ipaddr)->addr = (src_u32))
 | 
				
			||||||
 | 
					/** IPv4 only: get the IP address as an u32_t */
 | 
				
			||||||
 | 
					#define ip4_addr_get_u32(src_ipaddr) ((src_ipaddr)->addr)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** 255.255.255.255 */
 | 
				
			||||||
 | 
					#define IPADDR_NONE ((uint32_t)0xffffffffUL)
 | 
				
			||||||
 | 
					/** 127.0.0.1 */
 | 
				
			||||||
 | 
					#define IPADDR_LOOPBACK ((uint32_t)0x7f000001UL)
 | 
				
			||||||
 | 
					/** 0.0.0.0 */
 | 
				
			||||||
 | 
					#define IPADDR_ANY ((uint32_t)0x00000000UL)
 | 
				
			||||||
 | 
					/** 255.255.255.255 */
 | 
				
			||||||
 | 
					#define IPADDR_BROADCAST ((uint32_t)0xffffffffUL)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define IP4ADDR_STRLEN_MAX 16
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#if !defined(in_addr_t) && !defined(IN_ADDR_T_DEFINED)
 | 
				
			||||||
 | 
					typedef uint32_t in_addr_t;
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct in_addr {
 | 
				
			||||||
 | 
					    in_addr_t s_addr;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef struct ip4_addr {
 | 
				
			||||||
 | 
					    uint32_t addr;
 | 
				
			||||||
 | 
					} ip4_addr_t;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					typedef ip4_addr_t ip_addr_t;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** Copy IP address - faster than ip4_addr_set: no NULL check */
 | 
				
			||||||
 | 
					static inline void ip4_addr_copy(ip4_addr_t dest_addr, const ip4_addr_t src_addr)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    dest_addr.addr = src_addr.addr;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					static inline bool ip4_addr_cmp(const ip4_addr_t* left_addr, const ip4_addr_t* right_addr)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return left_addr->addr == right_addr->addr;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					/** Safely copy one IP address to another (src may be NULL) */
 | 
				
			||||||
 | 
					static inline void ip4_addr_set(ip4_addr_t* dest_addr, const ip4_addr_t* src_addr)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    dest_addr->addr = (src_addr == NULL) ? 0 : src_addr->addr;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					/** Set complete address to zero */
 | 
				
			||||||
 | 
					static inline void ip4_addr_set_zero(ip4_addr_t* ip4_addr)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    ip4_addr->addr = 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					/** Set address to IPADDR_ANY (no need for htonl()) */
 | 
				
			||||||
 | 
					static inline void ip4_addr_set_any(ip4_addr_t* ipaddr)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    ipaddr->addr = IPADDR_ANY;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					static inline bool ip4_addr_isany_val(const ip4_addr_t ipaddr)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return ipaddr.addr == IPADDR_ANY;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					static inline bool ip4_addr_isany(const ip4_addr_t* ipaddr)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return ipaddr == NULL || ip4_addr_isany_val(*ipaddr);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
		Loading…
	
		Reference in New Issue