Skip to content

Commit a9f7c9a

Browse files
authored
Use vTaskDelay for sleep in the network-interface of xilinx_ultrascale (#698)
The issue here is that, the FreeRTOS IP-task would block all other tasks during PHY-link speed negotiations, as it was using busy waiting. However this is not really ideal. A much more suitable function for such a task would be `vTaskDelay`.
1 parent 68c70a3 commit a9f7c9a

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

source/portable/NetworkInterface/xilinx_ultrascale/x_emacpsif_physpeed.c

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -71,26 +71,10 @@
7171
#include "FreeRTOS_IP_Private.h"
7272
#include "NetworkBufferManagement.h"
7373

74-
#define NOP() asm ( "nop" );
75-
7674
#define phyMIN_PHY_ADDRESS 0
7775
#define phyMAX_PHY_ADDRESS 31
7876

79-
void test_sleep( uint32_t uxTicks )
80-
{
81-
for( uint32_t j = 0U; j < uxTicks; j++ )
82-
{
83-
for( uint32_t i = 0U; i < 100000000U; i++ )
84-
{
85-
NOP();
86-
}
87-
}
88-
}
89-
90-
void my_sleep( uint32_t uxTicks )
91-
{
92-
sleep( uxTicks );
93-
}
77+
#define MINIMUM_SLEEP_TIME ( ( TickType_t ) 1 * configTICK_RATE_HZ )
9478

9579
/*** IMPORTANT: Define PEEP in xemacpsif.h and sys_arch_raw.c
9680
*** to run it on a PEEP board
@@ -474,7 +458,7 @@ static uint32_t get_TI_phy_speed( XEmacPs * xemacpsp,
474458

475459
while( !( status & IEEE_STAT_AUTONEGOTIATE_COMPLETE ) )
476460
{
477-
my_sleep( 1 );
461+
vTaskDelay( MINIMUM_SLEEP_TIME );
478462
timeout_counter++;
479463

480464
if( timeout_counter == 30 )
@@ -572,7 +556,7 @@ static uint32_t get_Marvell_phy_speed( XEmacPs * xemacpsp,
572556

573557
while( !( status & IEEE_STAT_AUTONEGOTIATE_COMPLETE ) )
574558
{
575-
my_sleep( 1 );
559+
vTaskDelay( MINIMUM_SLEEP_TIME );
576560
XEmacPs_PhyRead( xemacpsp, phy_addr,
577561
IEEE_COPPER_SPECIFIC_STATUS_REG_2, &temp );
578562
timeout_counter++;
@@ -663,7 +647,7 @@ static uint32_t get_Realtek_phy_speed( XEmacPs * xemacpsp,
663647

664648
while( !( status & IEEE_STAT_AUTONEGOTIATE_COMPLETE ) )
665649
{
666-
my_sleep( 1 );
650+
vTaskDelay( MINIMUM_SLEEP_TIME );
667651
timeout_counter++;
668652

669653
if( timeout_counter == 30 )
@@ -804,7 +788,7 @@ static uint32_t get_AR8035_phy_speed( XEmacPs * xemacpsp,
804788
while( pdTRUE )
805789
{
806790
uint32_t status;
807-
my_sleep( 1 );
791+
vTaskDelay( MINIMUM_SLEEP_TIME );
808792

809793
timeout_counter++;
810794

@@ -967,6 +951,7 @@ static uint32_t get_IEEE_phy_speed_US( XEmacPs * xemacpsp,
967951
&phy_identity );
968952

969953
const char * pcPHYName = pcGetPHIName( phy_identity );
954+
970955
FreeRTOS_printf( ( "Start %s PHY autonegotiation. ID = 0x%04X\n", pcPHYName, phy_identity ) );
971956

972957
/* Just to prevent compiler warnings about unused variablies. */
@@ -1377,19 +1362,19 @@ u32 Phy_Setup_US( XEmacPs * xemacpsp,
13771362
link_speed = 1000;
13781363
configure_IEEE_phy_speed_US( xemacpsp, link_speed );
13791364
convspeeddupsetting = XEMACPS_GMII2RGMII_SPEED1000_FD;
1380-
my_sleep( 1 );
1365+
vTaskDelay( MINIMUM_SLEEP_TIME );
13811366
#elif defined( ipconfigNIC_LINKSPEED100 )
13821367
SetUpSLCRDivisors( xemacpsp->Config.BaseAddress, 100 );
13831368
link_speed = 100;
13841369
configure_IEEE_phy_speed_US( xemacpsp, link_speed, phy_addr );
13851370
convspeeddupsetting = XEMACPS_GMII2RGMII_SPEED100_FD;
1386-
my_sleep( 1 );
1371+
vTaskDelay( MINIMUM_SLEEP_TIME );
13871372
#elif defined( ipconfigNIC_LINKSPEED10 )
13881373
SetUpSLCRDivisors( xemacpsp->Config.BaseAddress, 10 );
13891374
link_speed = 10;
13901375
configure_IEEE_phy_speed_US( xemacpsp, link_speed, , phy_addr );
13911376
convspeeddupsetting = XEMACPS_GMII2RGMII_SPEED10_FD;
1392-
my_sleep( 1 );
1377+
vTaskDelay( MINIMUM_SLEEP_TIME );
13931378
#endif /* ifdef ipconfigNIC_LINKSPEED_AUTODETECT */
13941379

13951380
if( conv_present )

0 commit comments

Comments
 (0)