fixed menu and complilation error

This commit is contained in:
wlyu
2021-12-20 16:44:44 +08:00
14 changed files with 718 additions and 752 deletions
@@ -426,8 +426,6 @@ void ENET_Init(ENET_Type *base,
/* Reset ENET module. */
ENET_Reset(base);
lw_print("lw: [%s] config %p %x\n", __func__, config, config->interrupt);
/* Initializes the ENET transmit buffer descriptors. */
ENET_SetTxBufferDescriptors(handle, config, bufferConfig);
@@ -504,9 +502,6 @@ static void ENET_SetHandler(ENET_Type *base,
handle->txBdCurrent[count] = buffCfg->txBdStartAddrAlign;
handle->txBuffSizeAlign[count] = buffCfg->txBuffSizeAlign;
lw_print("lw: [%s] %d instance %d ring %d %p IRQ %p %#x\n", __func__,
count, instance, handle->ringNum, buffCfg->rxBdStartAddrAlign, config, config->interrupt);
buffCfg++;
}
@@ -516,19 +511,16 @@ static void ENET_SetHandler(ENET_Type *base,
/* Set the IRQ handler when the interrupt is enabled. */
if (config->interrupt & ENET_TX_INTERRUPT)
{
lw_trace();
s_enetTxIsr = ENET_TransmitIRQHandler;
EnableIRQ(s_enetTxIrqId[instance]);
}
if (config->interrupt & ENET_RX_INTERRUPT)
{
lw_trace();
s_enetRxIsr = ENET_ReceiveIRQHandler;
EnableIRQ(s_enetRxIrqId[instance]);
}
if (config->interrupt & ENET_ERR_INTERRUPT)
{
lw_trace();
s_enetErrIsr = ENET_ErrorIRQHandler;
EnableIRQ(s_enetErrIrqId[instance]);
}
@@ -921,10 +913,6 @@ static void ENET_ActiveSend(ENET_Type *base, uint32_t ringId)
/* Ensure previous data update is completed with Data Synchronization Barrier before activing Tx BD. */
__DSB();
//tst by wly
// lw_print("lw: [%s] ring %d\n", __func__, ringId);
switch (ringId)
{
case kENET_Ring0:
@@ -1322,12 +1310,9 @@ status_t ENET_GetRxFrameSize(enet_handle_t *handle, uint32_t *length)
}
/* FCS is removed by MAC. */
*length = curBuffDescrip->length;
// lw_print("lw: [%s] %p %p ctrl %#x ok\n", __func__, curBuffDescrip, handle->rxBdCurrent[0], curBuffDescrip->control);
return kStatus_Success;
}
// lw_print("lw: [%s] %p %p ctrl %#x\n", __func__, curBuffDescrip, handle->rxBdCurrent[0], curBuffDescrip->control);
/* Increase the buffer descriptor, if it is the last one, increase to first one of the ring buffer. */
if (curBuffDescrip->control & ENET_BUFFDESCRIPTOR_RX_WRAP_MASK)
{
@@ -1396,8 +1381,6 @@ status_t ENET_ReadFrame(ENET_Type *base, enet_handle_t *handle, uint8_t *data, u
/* For data-NULL input, only update the buffer descriptor. */
if (!data)
{
// lw_print("lw: [%s] data %d ctrl %#x\n", __func__, length, handle->rxBdCurrent[0]->control);
do
{
/* Update the control flag. */
@@ -1418,8 +1401,6 @@ status_t ENET_ReadFrame(ENET_Type *base, enet_handle_t *handle, uint8_t *data, u
else
{
// lw_print("lw: [%s] data len %d ctrl %#x\n", __func__, length, handle->rxBdCurrent[0]->control);
/* A frame on one buffer or several receive buffers are both considered. */
#if defined(FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET) && FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET
address = MEMORY_ConvertMemoryMapAddress((uint32_t)curBuffDescrip->buffer, kMEMORY_DMA2Local);
@@ -1489,9 +1470,6 @@ status_t ENET_ReadFrame(ENET_Type *base, enet_handle_t *handle, uint8_t *data, u
/* Get the current buffer descriptor. */
curBuffDescrip = handle->rxBdCurrent[0];
// lw_print("lw: [%s] ctrl %#x\n", __func__, handle->rxBdCurrent[0]->control);
/* Add the cache invalidate maintain. */
#if defined(FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET) && FSL_FEATURE_MEMORY_HAS_ADDRESS_OFFSET
address = MEMORY_ConvertMemoryMapAddress((uint32_t)curBuffDescrip->buffer, kMEMORY_DMA2Local);
@@ -1517,8 +1495,6 @@ static void ENET_UpdateReadBuffers(ENET_Type *base, enet_handle_t *handle, uint3
/* Sets the receive buffer descriptor with the empty flag. */
handle->rxBdCurrent[ringId]->control |= ENET_BUFFDESCRIPTOR_RX_EMPTY_MASK;
// lw_print("lw: [%s] ring %d ctrl %#x\n", __func__, ringId, handle->rxBdCurrent[ringId]->control);
/* Increase current buffer descriptor to the next one. */
if (handle->rxBdCurrent[ringId]->control & ENET_BUFFDESCRIPTOR_RX_WRAP_MASK)
{
@@ -1529,8 +1505,6 @@ static void ENET_UpdateReadBuffers(ENET_Type *base, enet_handle_t *handle, uint3
handle->rxBdCurrent[ringId]++;
}
// lw_print("lw: [%s] ring %d changed ctrl %#x\n", __func__, ringId, handle->rxBdCurrent[ringId]->control);
/* Ensure previous data update is completed with Data Synchronization Barrier before activing Rx BD. */
__DSB();
@@ -1636,8 +1610,6 @@ status_t ENET_SendFrame(ENET_Type *base, enet_handle_t *handle, const uint8_t *d
handle->txBdCurrent[0]++;
}
// lw_print("lw: [%s] ctrl %#x\n", __func__, curBuffDescrip->control);
/* Active the transmit buffer descriptor. */
ENET_ActiveSend(base, 0);
@@ -3130,8 +3102,6 @@ void ENET_ReceiveIRQHandler(ENET_Type *base, enet_handle_t *handle)
assert(handle);
uint32_t mask = kENET_RxFrameInterrupt | kENET_RxBufferInterrupt;
lw_print("lw: [%s] input\n", __func__);
/* Check if the receive interrupt happen. */
#if FSL_FEATURE_ENET_QUEUE > 1
switch (ringId)
@@ -1,5 +1,3 @@
SRC_FILES += sys_arch.c \
tcp_echo_socket_demo.c \
udp_echo.c
SRC_FILES += sys_arch.c
include $(KERNEL_ROOT)/compiler.mk
@@ -1,68 +0,0 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under 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:
* http://license.coscl.org.cn/MulanPSL2
* 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,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file tcp_echo_socket_demo.c
* @brief One UDP demo based on LwIP
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-05-29
*/
#include <xiuos.h>
#include "udp_echo.h"
#include <connect_ethernet.h>
static void NetStackTaskCreate(void* param);
extern void TcpIpInit(void);
extern char* send_msg;
int UdpEchoSocketDemo(int argc, char *argv[])
{
if (argc == 2)
{
send_msg = argv[1];
}
ETH_BSP_Config();
int32 thr_id = KTaskCreate(
(const char* )"NetStackTaskCreate",
NetStackTaskCreate,
(void* )NULL,
(uint16_t )512,
15);
if(thr_id >= 0)
StartupKTask(thr_id);
else{
KPrintf("NetStackTaskCreate create failed !\n");
return -1;
}
}
#ifndef SEPARATE_COMPILE
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
UdpEchoSocketDemo, UdpEchoSocketDemo, tcp_echo_socket function );
#endif
static void NetStackTaskCreate(void* param)
{
TcpIpInit();
UdpEchoInit();
}
@@ -1,191 +0,0 @@
/*
* Copyright (c) 2001-2003 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>
*
*/
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiUOS is licensed under 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:
* http://license.coscl.org.cn/MulanPSL2
* 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,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
/**
* @file tcpecho.c
* @brief Add UDP client function
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021-05-29
*/
#include "udp_echo.h"
#include "lwip/opt.h"
#if LWIP_SOCKET
#include <lwip/sockets.h>
#include "lwip/sys.h"
#include "lwip/api.h"
#include <xs_ktask.h>
#define RECV_DATA (1024)
char* send_msg = "\n\nThis one is UDP pkg. Congratulations on you.\n\n";
static void UdpEchoThreadServer(void *arg)
{
KPrintf("UdpEchoThreadServer start.\n");
int sock = -1;
char *recv_data;
struct sockaddr_in udp_addr,seraddr;
int recv_data_len;
socklen_t addrlen;
while(1)
{
recv_data = (char *)malloc(RECV_DATA);
if (recv_data == NULL)
{
KPrintf("No memory\n");
goto __exit;
}
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0)
{
KPrintf("Socket error\n");
goto __exit;
}
udp_addr.sin_family = AF_INET;
udp_addr.sin_addr.s_addr = INADDR_ANY;
udp_addr.sin_port = htons(LOCAL_PORT_SERVER);
memset(&(udp_addr.sin_zero), 0, sizeof(udp_addr.sin_zero));
if (bind(sock, (struct sockaddr *)&udp_addr, sizeof(struct sockaddr)) == -1)
{
KPrintf("Unable to bind\n");
goto __exit;
}
KPrintf("UDP bind sucess, start to receive.\n");
KPrintf("\n\nLocal Port:%d\n\n", LOCAL_PORT_SERVER);
while(1)
{
memset(recv_data, 0, RECV_DATA);
recv_data_len=recvfrom(sock,recv_data,
RECV_DATA,0,
(struct sockaddr*)&seraddr,
&addrlen);
KPrintf("Receive from : %s\n",inet_ntoa(seraddr.sin_addr));
KPrintf("Recevce data : %s\n\n",recv_data);
sendto(sock,recv_data,
recv_data_len,0,
(struct sockaddr*)&seraddr,
addrlen);
}
__exit:
if (sock >= 0) closesocket(sock);
if (recv_data) free(recv_data);
}
}
static void UdpEchoThreadClient(void *arg)
{
KPrintf("UdpEchoThreadClient start.\n");
int sock_udp_send_once = -1;
sock_udp_send_once = socket(AF_INET, SOCK_DGRAM, 0);
if (sock_udp_send_once < 0)
{
KPrintf("Socket error\n");
goto __exit;
}
struct sockaddr_in udp_sock;
udp_sock.sin_family = AF_INET;
udp_sock.sin_port = htons(TARGET_PORT_CLIENT);
udp_sock.sin_addr.s_addr = PP_HTONL(LWIP_MAKEU32(IP_ADDR0_SERVER,IP_ADDR1_SERVER,IP_ADDR2_SERVER,IP_ADDR3_SERVER));
memset(&(udp_sock.sin_zero), 0, sizeof(udp_sock.sin_zero));
if (connect(sock_udp_send_once, (struct sockaddr *)&udp_sock, sizeof(struct sockaddr)))
{
KPrintf("Unable to connect\n");
goto __exit;
}
KPrintf("UDP connect sucess, start to send.\n");
KPrintf("\n\nTarget Port:%d\n\n", udp_sock.sin_port);
while (1)
{
KPrintf("Lwip client is running.\n");
sendto(sock_udp_send_once,send_msg,
strlen(send_msg),0,
(struct sockaddr*)&udp_sock,
sizeof(struct sockaddr));
KPrintf("Send UDP msg: %s ", send_msg);
MdelayKTask(1000);
}
__exit:
if (sock_udp_send_once >= 0) closesocket(sock_udp_send_once);
return;
}
void
UdpEchoInit(void)
{
#ifdef SET_AS_SERVER
sys_thread_new("UdpEchoThreadServer", UdpEchoThreadServer, NULL, 2048, 4);
#else
sys_thread_new("UdpEchoThreadClient", UdpEchoThreadClient, NULL, 2048, 4);
#endif
}
#endif /* LWIP_NETCONN */
@@ -1,40 +0,0 @@
/*
* Copyright (c) 2001-2003 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>
*
*/
#ifndef LWIP_TCPECHO_H
#define LWIP_TCPECHO_H
void UdpEchoInit(void);
#endif /* LWIP_TCPECHO_H */