Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.

Commit 6d1cc7f

Browse files
authored
Merge pull request #14 from Infineon/topic/ferreije-fix_timeout_issue
2 parents 3354c8d + 22383ec commit 6d1cc7f

File tree

225 files changed

+27920
-151064
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

225 files changed

+27920
-151064
lines changed

libraries/freertos_plus/standard/freertos_plus_tcp/source/portable/NetworkInterface/XMC4/NetworkInterface.c

Lines changed: 92 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ static __ALIGNED(4) uint8_t eth_tx_buf[configNUM_TX_DESCRIPTORS][XMC_ETH_MAC_BUF
120120
#endif
121121
#endif
122122

123+
#define TX_BUFFER_FREE_WAIT ( pdMS_TO_TICKS( 5UL ) )
124+
#define MAX_TX_ATTEMPTS ( 10 )
123125

124126
/* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1, then the Ethernet
125127
driver will filter incoming packets and only pass the stack those packets it
@@ -148,30 +150,27 @@ void ETH0_0_IRQHandler(void)
148150
ulStatusRegister = XMC_ETH_MAC_GetEventStatus(&eth_mac);
149151
XMC_ETH_MAC_ClearEventStatus(&eth_mac, ulStatusRegister);
150152

151-
if (netif_task_handler != 0)
152-
{
153-
/* xHigherPriorityTaskWoken must be initialised to pdFALSE. If calling
154-
xTaskNotifyFromISR() unblocks the handling task, and the priority of
155-
the handling task is higher than the priority of the currently running task,
156-
then xHigherPriorityTaskWoken will automatically get set to pdTRUE. */
157-
xHigherPriorityTaskWoken = pdFALSE;
158-
159-
/* Unblock the handling task so the task can perform any processing necessitated
160-
by the interrupt. xHandlingTask is the task's handle, which was obtained
161-
when the task was created. The handling task's notification value
162-
is bitwise ORed with the interrupt status - ensuring bits that are already
163-
set are not overwritten. */
164-
xTaskNotifyFromISR(netif_task_handler, ulStatusRegister, eSetBits, &xHigherPriorityTaskWoken );
165-
166-
/* Force a context switch if xHigherPriorityTaskWoken is now set to pdTRUE.
167-
The macro used to do this is dependent on the port and may be called
168-
portEND_SWITCHING_ISR. */
169-
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
170-
}
153+
/* xHigherPriorityTaskWoken must be initialised to pdFALSE. If calling
154+
xTaskNotifyFromISR() unblocks the handling task, and the priority of
155+
the handling task is higher than the priority of the currently running task,
156+
then xHigherPriorityTaskWoken will automatically get set to pdTRUE. */
157+
xHigherPriorityTaskWoken = pdFALSE;
158+
159+
/* Unblock the handling task so the task can perform any processing necessitated
160+
by the interrupt. xHandlingTask is the task's handle, which was obtained
161+
when the task was created. The handling task's notification value
162+
is bitwise ORed with the interrupt status - ensuring bits that are already
163+
set are not overwritten. */
164+
xTaskNotifyFromISR(netif_task_handler, ulStatusRegister, eSetBits, &xHigherPriorityTaskWoken );
165+
166+
/* Force a context switch if xHigherPriorityTaskWoken is now set to pdTRUE.
167+
The macro used to do this is dependent on the port and may be called
168+
portEND_SWITCHING_ISR. */
169+
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
171170
}
172171

173172
#if (ipconfigZERO_COPY_RX_DRIVER == 0)
174-
static void prvNetworkInterfaceInput(void)
173+
static BaseType_t prvNetworkInterfaceInput(void)
175174
{
176175
uint32_t xReceivedLength;
177176
uint8_t *pucBuffer;
@@ -213,63 +212,79 @@ static void prvNetworkInterfaceInput(void)
213212
XMC_ETH_MAC_ReturnRxDescriptor(&eth_mac);
214213
XMC_ETH_MAC_ResumeRx(&eth_mac);
215214

215+
return ( xReceivedLength > 0 );
216+
216217
}
217218
#else
218-
static void prvNetworkInterfaceInput(void)
219+
static BaseType_t prvNetworkInterfaceInput(void)
219220
{
220221
uint32_t xReceivedLength;
221222
uint8_t *pucBuffer;
222-
NetworkBufferDescriptor_t *pxDescriptor;
223-
const TickType_t xDescriptorWaitTime = pdMS_TO_TICKS( 250 );
223+
NetworkBufferDescriptor_t *pxCurDescriptor;
224+
NetworkBufferDescriptor_t *pxNewDescriptor = NULL;
225+
224226
xIPStackEvent_t xRxEvent = { eNetworkRxEvent, NULL };
225227

226228
xReceivedLength = XMC_ETH_MAC_GetRxFrameSize(&eth_mac);
227-
if ((xReceivedLength > 0) && (xReceivedLength <= ipTOTAL_ETHERNET_FRAME_SIZE))
229+
if (xReceivedLength > 0)
228230
{
229-
pucBuffer = XMC_ETH_MAC_GetRxBuffer(&eth_mac);
230-
231-
if (ipCONSIDER_FRAME_FOR_PROCESSING(pucBuffer))
231+
/* Check if it is a valid frame */
232+
if (xReceivedLength <= ipTOTAL_ETHERNET_FRAME_SIZE)
232233
{
233-
/* Allocate a new network buffer descriptor that references an Ethernet
234-
frame large enough to hold the maximum network packet size (as defined
235-
in the FreeRTOSIPConfig.h header file). */
236-
pxDescriptor = pxGetNetworkBufferWithDescriptor(ipTOTAL_ETHERNET_FRAME_SIZE, xDescriptorWaitTime);
237-
if (pxDescriptor != NULL)
238-
{
239-
XMC_ETH_MAC_SetRxBuffer(&eth_mac, pxDescriptor->pucEthernetBuffer);
240-
241-
pxDescriptor->pucEthernetBuffer = pucBuffer;
242-
pxDescriptor->xDataLength = xReceivedLength;
243-
244-
*( ( NetworkBufferDescriptor_t ** )
245-
( pxDescriptor->pucEthernetBuffer - ipBUFFER_PADDING ) ) = pxDescriptor;
246-
247-
/*
248-
* The network buffer descriptor now points to the Ethernet buffer that
249-
* contains the received data, and the Ethernet DMA descriptor now points
250-
* to a newly allocated (and empty) Ethernet buffer ready to receive more
251-
* data. No data was copied. Only pointers to data were swapped.
252-
*/
234+
pucBuffer = XMC_ETH_MAC_GetRxBuffer(&eth_mac);
253235

254-
xRxEvent.pvData = ( void * )pxDescriptor;
255-
256-
/* Pass the data to the TCP/IP task for processing. */
257-
if (xSendEventStructToIPTask( &xRxEvent, xDescriptorWaitTime ) == pdFALSE)
236+
if (ipCONSIDER_FRAME_FOR_PROCESSING(pucBuffer))
237+
{
238+
/* Allocate a new network buffer descriptor that references an Ethernet
239+
frame large enough to hold the maximum network packet size (as defined
240+
in the FreeRTOSIPConfig.h header file). */
241+
pxNewDescriptor = pxGetNetworkBufferWithDescriptor(ipTOTAL_ETHERNET_FRAME_SIZE, 0);
242+
if (pxNewDescriptor != NULL)
258243
{
259-
/* Could not send the descriptor into the TCP/IP stack, it must be released. */
260-
vReleaseNetworkBufferAndDescriptor(pxDescriptor);
261-
iptraceETHERNET_RX_EVENT_LOST();
244+
XMC_ETH_MAC_SetRxBuffer(&eth_mac, pxNewDescriptor->pucEthernetBuffer);
245+
246+
pxCurDescriptor = pxPacketBuffer_to_NetworkBuffer( pucBuffer );
247+
configASSERT( pxCurDescriptor != NULL );
248+
249+
pxCurDescriptor->xDataLength = xReceivedLength;
250+
251+
/*
252+
* The network buffer descriptor now points to the Ethernet buffer that
253+
* contains the received data, and the Ethernet DMA descriptor now points
254+
* to a newly allocated (and empty) Ethernet buffer ready to receive more
255+
* data. No data was copied. Only pointers to data were swapped.
256+
*/
257+
258+
xRxEvent.pvData = ( void * )pxCurDescriptor;
259+
260+
/* Pass the data to the TCP/IP task for processing. */
261+
if (xSendEventStructToIPTask( &xRxEvent, 0 ) == pdFALSE)
262+
{
263+
/* Could not send the descriptor into the TCP/IP stack, it must be released. */
264+
vReleaseNetworkBufferAndDescriptor(pxCurDescriptor);
265+
iptraceETHERNET_RX_EVENT_LOST();
266+
}
267+
else
268+
{
269+
iptraceNETWORK_INTERFACE_RECEIVE();
270+
}
262271
}
263272
else
264273
{
265-
iptraceNETWORK_INTERFACE_RECEIVE();
274+
/* The event was lost because a network buffer was not available.
275+
Call the standard trace macro to log the occurrence. */
276+
iptraceETHERNET_RX_EVENT_LOST();
266277
}
267278
}
268279
}
280+
281+
XMC_ETH_MAC_ReturnRxDescriptor(&eth_mac);
269282
}
270283

271-
XMC_ETH_MAC_ReturnRxDescriptor(&eth_mac);
272284
XMC_ETH_MAC_ResumeRx(&eth_mac);
285+
286+
return ( xReceivedLength > 0 );
287+
273288
}
274289
#endif
275290

@@ -290,7 +305,7 @@ static void vClearTXBuffers()
290305
NetworkBufferDescriptor_t *pxDescriptor = pxPacketBuffer_to_NetworkBuffer(ucPayLoad);
291306
if (pxDescriptor != NULL)
292307
{
293-
vReleaseNetworkBufferAndDescriptor(pxDescriptor);
308+
vReleaseNetworkBufferAndDescriptor(pxDescriptor);
294309
}
295310
XMC_ETH_MAC_SetTxBufferEx(&eth_mac, ulTxDescriptorToClear, 0);
296311
}
@@ -320,7 +335,7 @@ static void set_link_up(void)
320335
XMC_ETH_MAC_SetLink(&eth_mac, speed, duplex);
321336

322337
/* Enable ethernet interrupts */
323-
XMC_ETH_MAC_EnableEvent(&eth_mac, (uint32_t)(XMC_ETH_MAC_EVENT_RECEIVE | XMC_ETH_MAC_EVENT_TRANSMIT));
338+
XMC_ETH_MAC_EnableEvent(&eth_mac, (uint32_t)(XMC_ETH_MAC_EVENT_RECEIVE | XMC_ETH_MAC_EVENT_RECEIVE_BUFFER_UNAVAILABLE | XMC_ETH_MAC_EVENT_TRANSMIT));
324339

325340
NVIC_SetPriority(ETH0_0_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 62U, 0U));
326341
NVIC_ClearPendingIRQ(ETH0_0_IRQn);
@@ -334,7 +349,7 @@ static void set_link_up(void)
334349

335350
static void set_link_down(void)
336351
{
337-
XMC_ETH_MAC_DisableEvent(&eth_mac, (uint32_t)(XMC_ETH_MAC_EVENT_RECEIVE | XMC_ETH_MAC_EVENT_TRANSMIT));
352+
XMC_ETH_MAC_DisableEvent(&eth_mac, (uint32_t)(XMC_ETH_MAC_EVENT_RECEIVE | XMC_ETH_MAC_EVENT_RECEIVE_BUFFER_UNAVAILABLE | XMC_ETH_MAC_EVENT_TRANSMIT));
338353
NVIC_DisableIRQ(ETH0_0_IRQn);
339354

340355
XMC_ETH_MAC_DisableTx(&eth_mac);
@@ -360,13 +375,9 @@ static void netif_task(void *arg)
360375
&ulInterruptStatus, /* Receives the notification value. */
361376
portMAX_DELAY); /* Block indefinitely. */
362377

363-
if ((ulInterruptStatus & XMC_ETH_MAC_EVENT_RECEIVE) != 0)
378+
if ((ulInterruptStatus & (XMC_ETH_MAC_EVENT_RECEIVE | XMC_ETH_MAC_EVENT_RECEIVE_BUFFER_UNAVAILABLE)) != 0)
364379
{
365-
/* Go through the application owned descriptors */
366-
while (XMC_ETH_MAC_IsRxDescriptorOwnedByDma(&eth_mac) == pdFALSE)
367-
{
368-
prvNetworkInterfaceInput();
369-
}
380+
while (prvNetworkInterfaceInput());
370381
}
371382

372383
if ((ulInterruptStatus & XMC_ETH_MAC_EVENT_TRANSMIT) != 0 )
@@ -516,8 +527,8 @@ BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxNetworkB
516527
BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxDescriptor, BaseType_t xReleaseAfterSend )
517528
{
518529
(void)xReleaseAfterSend;
519-
const TickType_t xBlockTimeTicks = pdMS_TO_TICKS(50u);
520530
BaseType_t xReturn = pdFAIL;
531+
int32_t x;
521532

522533
do
523534
{
@@ -526,9 +537,18 @@ BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxDescript
526537
break;
527538
}
528539

529-
if (xSemaphoreTake(xTXDescriptorSemaphore, xBlockTimeTicks) != pdPASS)
540+
for (x = 0; x < MAX_TX_ATTEMPTS; ++x)
541+
{
542+
if (xSemaphoreTake(xTXDescriptorSemaphore, 0) == pdPASS)
543+
{
544+
break;
545+
}
546+
iptraceWAITING_FOR_TX_DMA_DESCRIPTOR();
547+
vTaskDelay(TX_BUFFER_FREE_WAIT);
548+
}
549+
550+
if (x == MAX_TX_ATTEMPTS)
530551
{
531-
/* Time-out waiting for a free TX descriptor. */
532552
break;
533553
}
534554

@@ -586,6 +606,9 @@ void vNetworkInterfaceAllocateRAMToBuffers(
586606
/* pucEthernetBuffer is set to point ipBUFFER_PADDING bytes in from the
587607
beginning of the allocated buffer. */
588608
pxDescriptor[ x ].pucEthernetBuffer = &( ucBuffers[ x ][ ipBUFFER_PADDING ] );
609+
pxDescriptor[ x ].xDataLength = 0;
610+
pxDescriptor[ x ].usPort = 0;
611+
pxDescriptor[ x ].usBoundPort = 0;
589612

590613
/* The following line is also required, but will not be required in
591614
future versions. */

vendors/infineon/XMCLib/2.2.0/CMSIS/CHANGELOG.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,40 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [5.7.0-p1] - 2020-04-20
7+
## [5.7.0-p1] - 2020-11
88
Based on CMSIS 5.7.0 with Infineon specific files
99
See https://github.com/ARM-software/CMSIS_5/releases for changes on CMSIS 5.7.0
1010

11+
### Added
12+
- Option to generate own ISR handlers for interrupts instead of a single common default ISR
13+
- Scatter files for ARM compiler v5 and v6
1114
### Changed
1215
- Infineon specific files uses now the Boost Software License, https://www.boost.org/users/license.html
16+
- Device header files to avoid compilation warnings in Keil MDK
1317
### Fixed
1418
- system_XMC1400.c
1519
Fix seeting of ANAOSCHPCTRL accoring to OSC_CM.D001 in errata
1620
- system_XMC4100.c
21+
Fix clock setup when using internal oscillator as clock source for the system PLL
1722
- system_XMC4200.c
1823
Fix EXTCLKDIV macro definition
1924
Fix code for condition EXTCLK_PIN == EXTCLK_PIN_P1_15
2025
Fix clock setup when using internal oscillator as clock source for the system PLL
2126
- system_XMC4300.c
27+
Fix clock setup when using internal oscillator as clock source for the system PLL
2228
- system_XMC4400.c
29+
Fix clock setup when using internal oscillator as clock source for the system PLL
2330
- system_XMC4500.c
31+
Fix clock setup when using internal oscillator as clock source for the system PLL
2432
- system_XMC4700.c
33+
Fix clock setup when using internal oscillator as clock source for the system PLL
2534
- system_XMC4800.c
35+
Fix clock setup when using internal oscillator as clock source for the system PLL
36+
- Newlib/syscalls.c
37+
Fix C++ compilation
2638

2739
### Added
2840
- CMSIS Driver implementation
29-
- Device variants header files to avoid compilation warnings in Keil MDK
3041

3142
## [5.6.0-p1] - 2019-08-01
3243
Based on CMSIS 5.6.0 with Infineon specific files

0 commit comments

Comments
 (0)