fixed the bug of lwip IRQ and optimize TCP and OPCUA demo

This commit is contained in:
wlyu
2022-01-12 18:49:36 +08:00
parent bb0425d1b2
commit c0de7ca44c
16 changed files with 256 additions and 218 deletions
@@ -216,7 +216,7 @@ void ethernetif_input(struct netif *netif)
/* pass all packets to ethernet_input, which decides what packets it supports */
if ((ret = netif->input(p, netif)) != ERR_OK)
{
// LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
lw_print("lw: [%s] ret %d p %p\n", __func__, ret, p);
pbuf_free(p);
p = NULL;
@@ -118,6 +118,8 @@ typedef struct EventGroupDef_t
struct EventGroupDef_t;
typedef struct EventGroupDef_t * EventGroupHandle_t;
#else
int lwip_sempahore;
#endif
#endif
@@ -130,8 +132,6 @@ typedef struct EventGroupDef_t * EventGroupHandle_t;
#include "sys_arch.h"
/*******************************************************************************
* Definitions
******************************************************************************/
@@ -166,6 +166,13 @@ struct ethernetif
* Code
******************************************************************************/
#if USE_RTOS && defined(FSL_RTOS_FREE_RTOS)
int32 lwip_obtain_semaphore(struct netif *netif)
{
struct ethernetif *ethernetif = netif->state;
return (KSemaphoreObtain(ethernetif->enetSemaphore, WAITING_FOREVER) == EOK);
}
#if FSL_FEATURE_ENET_QUEUE > 1
static void ethernet_callback(ENET_Type *base, enet_handle_t *handle, uint32_t ringId, enet_event_t event, void *param)
#else
@@ -176,21 +183,18 @@ static void ethernet_callback(ENET_Type *base, enet_handle_t *handle, enet_event
struct ethernetif *ethernetif = netif->state;
BaseType_t xResult;
lw_print("lw: [%s] input event %#x \n", __func__, event);
switch (event)
{
case kENET_RxEvent:
ethernetif_input(netif);
break;
case kENET_TxEvent:
{
portBASE_TYPE taskToWake = pdFALSE;
#ifdef FSL_RTOS_XIUOS
#else
{
portBASE_TYPE taskToWake = pdFALSE;
#ifdef __CA7_REV
if (SystemGetIRQNestingLevel())
#else
@@ -207,14 +211,15 @@ static void ethernet_callback(ENET_Type *base, enet_handle_t *handle, enet_event
{
xEventGroupSetBits(ethernetif->enetTransmitAccessEvent, ethernetif->txFlag);
}
#endif
}
#endif
break;
default:
break;
}
KSemaphoreAbandon(ethernetif->enetSemaphore);
// KSemaphoreAbandon(ethernetif->enetSemaphore);
KSemaphoreAbandon(lwip_sempahore);
}
#endif
@@ -315,7 +320,7 @@ err_t ethernetif_mld_mac_filter(struct netif *netif, const ip6_addr_t *group,
//
// for( ;; )
// {
// if (KSemaphoreObtain( s_xSemaphore, WAITING_FOREVER)==EOK)
// if (KSemaphoreObtain( lwip_sempahore, WAITING_FOREVER)==EOK)
// {
// p = low_level_input( s_pxNetIf );
//
@@ -392,6 +397,7 @@ void ethernetif_enet_init(struct netif *netif, struct ethernetif *ethernetif,
{
ethernetif->enetSemaphore = KSemaphoreCreate(0);
}
// lwip_sempahore = KSemaphoreCreate(0);
#else
ethernetif->enetTransmitAccessEvent = xEventGroupCreate();
#endif
@@ -458,7 +464,7 @@ static err_t enet_send_frame(struct ethernetif *ethernetif, unsigned char *data,
{
status_t result;
lw_print("lw: [%s] len %d\n", __func__, length);
lw_print("lw: [%s] len %d\n", __func__, length);
do
{
@@ -467,7 +473,8 @@ static err_t enet_send_frame(struct ethernetif *ethernetif, unsigned char *data,
if (result == kStatus_ENET_TxFrameBusy)
{
#ifdef FSL_RTOS_XIUOS
// KSemaphoreObtain(ethernetif->enetSemaphore, portMAX_DELAY);
KSemaphoreObtain(ethernetif->enetSemaphore, portMAX_DELAY);
// KSemaphoreObtain(lwip_sempahore, portMAX_DELAY);
#else
xEventGroupWaitBits(ethernetif->enetTransmitAccessEvent, ethernetif->txFlag, pdTRUE, (BaseType_t) false,
portMAX_DELAY);
@@ -582,11 +589,10 @@ struct pbuf *ethernetif_linkinput(struct netif *netif)
if (status == kStatus_ENET_RxFrameError)
{
#if 0 && defined(FSL_FEATURE_SOC_ENET_COUNT) && (FSL_FEATURE_SOC_ENET_COUNT > 0) /* Error statisctics */
enet_data_error_stats_t eErrStatic;
/* Get the error information of the received g_frame. */
ENET_GetRxErrBeforeReadFrame(&ethernetif->handle, &eErrStatic);
enet_data_error_stats_t eErrStatic;
/* Get the error information of the received g_frame. */
ENET_GetRxErrBeforeReadFrame(&ethernetif->handle, &eErrStatic);
#endif
/* Update the receive buffer. */
ENET_ReadFrame(ethernetif->base, &ethernetif->handle, NULL, 0U);
@@ -801,30 +801,30 @@ err_t ethernetif_linkoutput(struct netif *netif, struct pbuf *p)
}
}
if (copy)
if (copy)
{
/* Pbuf needs to be copied. */
p_copy = pbuf_alloc(PBUF_RAW, (uint16_t) p->tot_len, PBUF_POOL);
if (p_copy == NULL)
if (p_copy == NULL)
{
return ERR_MEM;
}
return ERR_MEM;
}
dst = (uint8_t *) p_copy->payload;
for (q = p; q != NULL; q = q->next)
dst = (uint8_t *) p_copy->payload;
for (q = p; q != NULL; q = q->next)
{
LWIP_ASSERT("Copied bytes would exceed p->tot_len",
(q->len + dst - (uint8_t *) p_copy->payload) <= p->tot_len);
memcpy(dst, (uint8_t *)q->payload, q->len);
dst += q->len;
}
dst += q->len;
}
LWIP_ASSERT("Copied bytes != p->tot_len",
(dst - (uint8_t *) p_copy->payload) == p->tot_len);
p_copy->len = p_copy->tot_len = p->tot_len;
p_copy->len = p_copy->tot_len = p->tot_len;
p = p_copy;
}
p = p_copy;
}
else
{
/*
@@ -1490,6 +1490,9 @@ static void ENET_UpdateReadBuffers(ENET_Type *base, enet_handle_t *handle, uint3
assert(handle);
assert(ringId < FSL_FEATURE_ENET_QUEUE);
// lw_print("lw: [%s] base %p handle %p ring %d\n", __func__, base, handle, ringId);
/* Clears status. */
handle->rxBdCurrent[ringId]->control &= ENET_BUFFDESCRIPTOR_RX_WRAP_MASK;
/* Sets the receive buffer descriptor with the empty flag. */
@@ -195,6 +195,8 @@ void ethernetif_input( struct netif *netif);
void ETH_BSP_Config(void);
int32 lwip_obtain_semaphore(struct netif *netif);
#if defined(__cplusplus)
}
#endif /* __cplusplus */