Skip to content

Commit 2994394

Browse files
Update Zynq portable for Xilinx SDT drivers (#1227)
* Update for xilinx sdt drivers * Formatting * Format and add spell word * Define XPAR_PS7_ETHERNET_1_DEVICE_ID and XPAR_PS7_ETHERNET_1_BASEADDR * Formatting --------- Co-authored-by: Tony Josi <[email protected]>
1 parent b3f586f commit 2994394

File tree

7 files changed

+78
-28
lines changed

7 files changed

+78
-28
lines changed

.github/.cSpellWords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,7 @@ XPBL
15931593
Xplorer
15941594
XPROT
15951595
xpsr
1596+
XSCUGIC
15961597
xtopology
15971598
xtopologyp
15981599
xzvf

source/portable/NetworkInterface/Zynq/NetworkInterface.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,21 +149,21 @@ struct xtopology_t xXTopologies[ XPAR_XEMACPS_NUM_INSTANCES ] =
149149
{
150150
[ 0 ] =
151151
{
152-
.emac_baseaddr = XPAR_PS7_ETHERNET_0_BASEADDR,
152+
.emac_baseaddr = ZYNQ_ETHERNET_0_BASEADDR,
153153
.emac_type = xemac_type_emacps,
154154
.intc_baseaddr = 0x0,
155155
.intc_emac_intr = 0x0,
156-
.scugic_baseaddr = XPAR_PS7_SCUGIC_0_BASEADDR,
156+
.scugic_baseaddr = ZYNQ_SCUGIC_0_BASEADDR,
157157
.scugic_emac_intr = 0x36,
158158
},
159159
#if ( XPAR_XEMACPS_NUM_INSTANCES > 1 )
160160
[ 1 ] =
161161
{
162-
.emac_baseaddr = XPAR_PS7_ETHERNET_1_BASEADDR,
162+
.emac_baseaddr = ZYNQ_ETHERNET_1_BASEADDR,
163163
.emac_type = xemac_type_emacps,
164164
.intc_baseaddr = 0x0,
165165
.intc_emac_intr = 0x0,
166-
.scugic_baseaddr = XPAR_PS7_SCUGIC_0_BASEADDR,
166+
.scugic_baseaddr = ZYNQ_SCUGIC_0_BASEADDR,
167167
.scugic_emac_intr = 0x4D, /* See "7.2.3 Shared Peripheral Interrupts (SPI)" */
168168
},
169169
#endif
@@ -173,14 +173,18 @@ XEmacPs_Config mac_configs[ XPAR_XEMACPS_NUM_INSTANCES ] =
173173
{
174174
[ 0 ] =
175175
{
176-
.DeviceId = XPAR_PS7_ETHERNET_0_DEVICE_ID, /**< Unique ID of device, used for 'xEMACIndex' */
177-
.BaseAddress = XPAR_PS7_ETHERNET_0_BASEADDR /**< Physical base address of IPIF registers */
176+
#ifndef SDT
177+
.DeviceId = XPAR_PS7_ETHERNET_0_DEVICE_ID, /**< Unique ID of device, used for 'xEMACIndex' */
178+
#endif
179+
.BaseAddress = ZYNQ_ETHERNET_0_BASEADDR /**< Physical base address of IPIF registers */
178180
},
179181
#if ( XPAR_XEMACPS_NUM_INSTANCES > 1 )
180182
[ 1 ] =
181183
{
182-
.DeviceId = XPAR_PS7_ETHERNET_1_DEVICE_ID, /**< Unique ID of device */
183-
.BaseAddress = XPAR_PS7_ETHERNET_1_BASEADDR /**< Physical base address of IPIF registers */
184+
#ifndef SDT
185+
.DeviceId = XPAR_PS7_ETHERNET_1_DEVICE_ID, /**< Unique ID of device */
186+
#endif
187+
.BaseAddress = ZYNQ_ETHERNET_1_BASEADDR /**< Physical base address of IPIF registers */
184188
},
185189
#endif
186190
};

source/portable/NetworkInterface/Zynq/uncached_memory.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@
8282
#ifndef uncMEMORY_SIZE
8383
#define uncMEMORY_SIZE uncMINIMAL_MEMORY_SIZE
8484
#endif
85-
#define DDR_MEMORY_END ( XPAR_PS7_DDR_0_S_AXI_HIGHADDR + 1 )
85+
#ifndef SDT
86+
#define DDR_MEMORY_END ( XPAR_PS7_DDR_0_S_AXI_HIGHADDR + 1 )
87+
#else
88+
#define DDR_MEMORY_END ( XPAR_PS7_DDR_0_HIGHADDRESS + 1 )
89+
#endif
8690
#define uncMEMORY_ATTRIBUTE 0x1C02
8791
#endif /* ( ipconfigULTRASCALE == 1 ) */
8892

source/portable/NetworkInterface/Zynq/x_emacpsif.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,25 @@
3838
extern "C" {
3939
#endif
4040

41-
#define XPAR_PS7_ETHERNET_1_DEVICE_ID 1
42-
#define XPAR_PS7_ETHERNET_1_BASEADDR 0xE000C000
41+
#ifdef SDT
42+
#define ZYNQ_SCUGIC_0_BASEADDR XPAR_XSCUGIC_0_BASEADDR
43+
#define ZYNQ_ETHERNET_0_BASEADDR XPAR_XEMACPS_0_BASEADDR
44+
#if ( XPAR_XEMACPS_NUM_INSTANCES > 1 )
45+
#define ZYNQ_ETHERNET_1_BASEADDR XPAR_XEMACPS_1_BASEADDR
46+
#endif
47+
#else
48+
#ifndef XPAR_PS7_ETHERNET_1_DEVICE_ID
49+
#define XPAR_PS7_ETHERNET_1_DEVICE_ID 1
50+
#endif
51+
#ifndef XPAR_PS7_ETHERNET_1_BASEADDR
52+
#define XPAR_PS7_ETHERNET_1_BASEADDR 0xE000C000
53+
#endif
54+
#define ZYNQ_SCUGIC_0_BASEADDR XPAR_PS7_SCUGIC_0_BASEADDR
55+
#define ZYNQ_ETHERNET_0_BASEADDR XPAR_PS7_ETHERNET_0_BASEADDR
56+
#if ( XPAR_XEMACPS_NUM_INSTANCES > 1 )
57+
#define ZYNQ_ETHERNET_1_BASEADDR XPAR_PS7_ETHERNET_1_BASEADDR
58+
#endif
59+
#endif /* ifdef SDT */
4360

4461
extern XEmacPs_Config mac_configs[ XPAR_XEMACPS_NUM_INSTANCES ];
4562

@@ -145,6 +162,8 @@
145162
void clean_dma_txdescs( xemacpsif_s * xemacpsif );
146163
void resetrx_on_no_rxdata( xemacpsif_s * xemacpsif );
147164

165+
BaseType_t get_xEMACIndex( const XEmacPs * xemacpsp );
166+
148167
/**
149168
* @brief Initialise the interface number 'xIndex'. Do not call directly.
150169
*/

source/portable/NetworkInterface/Zynq/x_emacpsif_dma.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static void prvPassEthMessages( NetworkBufferDescriptor_t * pxDescriptor );
129129
int is_tx_space_available( xemacpsif_s * xemacpsif )
130130
{
131131
size_t uxCount;
132-
BaseType_t xEMACIndex = xemacpsif->emacps.Config.DeviceId;
132+
BaseType_t xEMACIndex = get_xEMACIndex( &xemacpsif->emacps );
133133

134134
if( xTXDescriptorSemaphores[ xEMACIndex ] != NULL )
135135
{
@@ -147,7 +147,7 @@ void emacps_check_tx( xemacpsif_s * xemacpsif )
147147
{
148148
int tail = xemacpsif->txTail;
149149
int head = xemacpsif->txHead;
150-
BaseType_t xEMACIndex = xemacpsif->emacps.Config.DeviceId;
150+
BaseType_t xEMACIndex = get_xEMACIndex( &xemacpsif->emacps );
151151
size_t uxCount = ( ( UBaseType_t ) ipconfigNIC_N_TX_DESC ) - uxSemaphoreGetCount( xTXDescriptorSemaphores[ xEMACIndex ] );
152152

153153
/* uxCount is the number of TX descriptors that are in use by the DMA. */
@@ -210,7 +210,7 @@ void emacps_send_handler( void * arg )
210210
BaseType_t xEMACIndex;
211211

212212
xemacpsif = ( xemacpsif_s * ) arg;
213-
xEMACIndex = xemacpsif->emacps.Config.DeviceId;
213+
xEMACIndex = get_xEMACIndex( &xemacpsif->emacps );
214214

215215
/* This function is called from an ISR. The Xilinx ISR-handler has already
216216
* cleared the TXCOMPL and TXSR_USEDREAD status bits in the XEMACPS_TXSR register.
@@ -254,7 +254,7 @@ XStatus emacps_send_message( xemacpsif_s * xemacpsif,
254254
int txHead = xemacpsif->txHead;
255255
int iHasSent = 0;
256256
uint32_t ulBaseAddress = xemacpsif->emacps.Config.BaseAddress;
257-
BaseType_t xEMACIndex = xemacpsif->emacps.Config.DeviceId;
257+
BaseType_t xEMACIndex = get_xEMACIndex( &xemacpsif->emacps );
258258
TickType_t xBlockTimeTicks = pdMS_TO_TICKS( 5000U );
259259

260260
/* This driver wants to own all network buffers which are to be transmitted. */
@@ -362,7 +362,7 @@ void emacps_recv_handler( void * arg )
362362

363363
xemacpsif = ( xemacpsif_s * ) arg;
364364
xemacpsif->isr_events |= EMAC_IF_RX_EVENT;
365-
xEMACIndex = xemacpsif->emacps.Config.DeviceId;
365+
xEMACIndex = get_xEMACIndex( &xemacpsif->emacps );
366366

367367
/* The driver has already cleared the FRAMERX, BUFFNA and error bits
368368
* in the XEMACPS_RXSR register,
@@ -491,7 +491,7 @@ int emacps_check_rx( xemacpsif_s * xemacpsif,
491491
int rx_bytes;
492492
volatile int msgCount = 0;
493493
int rxHead = xemacpsif->rxHead;
494-
BaseType_t xEMACIndex = xemacpsif->emacps.Config.DeviceId;
494+
BaseType_t xEMACIndex = get_xEMACIndex( &xemacpsif->emacps );
495495
BaseType_t xAccepted;
496496

497497
#if ( ipconfigUSE_LINKED_RX_MESSAGES != 0 )
@@ -632,7 +632,7 @@ void clean_dma_txdescs( xemacpsif_s * xemacpsif )
632632
{
633633
int index;
634634
unsigned char * ucTxBuffer;
635-
BaseType_t xEMACIndex = xemacpsif->emacps.Config.DeviceId;
635+
BaseType_t xEMACIndex = get_xEMACIndex( &xemacpsif->emacps );
636636

637637
/* Clear all TX descriptors and assign uncached memory to each descriptor.
638638
* "tx_space" points to the first available TX buffer. */
@@ -653,7 +653,7 @@ void clean_dma_txdescs( xemacpsif_s * xemacpsif )
653653
XStatus init_dma( xemacpsif_s * xemacpsif )
654654
{
655655
NetworkBufferDescriptor_t * pxBuffer;
656-
BaseType_t xEMACIndex = xemacpsif->emacps.Config.DeviceId;
656+
BaseType_t xEMACIndex = get_xEMACIndex( &xemacpsif->emacps );
657657

658658
int iIndex;
659659
UBaseType_t xRxSize;

source/portable/NetworkInterface/Zynq/x_emacpsif_hw.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void emacps_error_handler( void * arg,
9191
BaseType_t xEMACIndex;
9292

9393
xemacpsif = ( xemacpsif_s * ) ( arg );
94-
xEMACIndex = xemacpsif->emacps.Config.DeviceId;
94+
xEMACIndex = get_xEMACIndex( &xemacpsif->emacps );
9595

9696
if( ( Direction != XEMACPS_SEND ) || ( ErrorWord != XEMACPS_TXSR_USEDREAD_MASK ) )
9797
{
@@ -158,7 +158,7 @@ static void emacps_handle_error( void * arg,
158158
xemacpsif = ( xemacpsif_s * ) ( arg );
159159

160160
xemacps = &xemacpsif->emacps;
161-
xEMACIndex = xemacps->Config.DeviceId;
161+
xEMACIndex = get_xEMACIndex( xemacps );
162162

163163
last_err_msg = NULL;
164164

@@ -253,3 +253,17 @@ void HandleTxErrors( xemacpsif_s * xemacpsif )
253253
}
254254
/*taskEXIT_CRITICAL( ); */
255255
}
256+
257+
BaseType_t get_xEMACIndex( const XEmacPs * xemacpsp )
258+
{
259+
#if ( XPAR_XEMACPS_NUM_INSTANCES == 1 )
260+
( void ) xemacpsp;
261+
return 0;
262+
#else
263+
#ifndef SDT
264+
return xemacpsp->Config.DeviceId;
265+
#else
266+
return xemacpsp->Config.BaseAddress != ZYNQ_ETHERNET_0_BASEADDR;
267+
#endif
268+
#endif
269+
}

source/portable/NetworkInterface/Zynq/x_emacpsif_physpeed.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static int detect_phy( XEmacPs * xemacpsp )
173173
{
174174
/* Found a valid PHY address */
175175
FreeRTOS_printf( ( "XEmacPs detect_phy: PHY detected at address %d.\n", ( unsigned ) phy_addr ) );
176-
phy_detected[ xemacpsp->Config.DeviceId ] = phy_addr;
176+
phy_detected[ get_xEMACIndex( xemacpsp ) ] = phy_addr;
177177
return phy_addr;
178178
}
179179
}
@@ -506,7 +506,7 @@ static void SetUpSLCRDivisors( int mac_baseaddr,
506506
volatile u32 slcrBaseAddress;
507507

508508
#ifndef PEEP
509-
u32 SlcrDiv0;
509+
u32 SlcrDiv0 = 0;
510510
u32 SlcrDiv1 = 0;
511511
u32 SlcrTxClkCntrl;
512512
#endif
@@ -591,11 +591,19 @@ static void SetUpSLCRDivisors( int mac_baseaddr,
591591
}
592592
}
593593

594-
SlcrTxClkCntrl = *( volatile unsigned int * ) ( slcrBaseAddress );
595-
SlcrTxClkCntrl &= EMACPS_SLCR_DIV_MASK;
596-
SlcrTxClkCntrl |= ( SlcrDiv1 << 20 );
597-
SlcrTxClkCntrl |= ( SlcrDiv0 << 8 );
598-
*( volatile unsigned int * ) ( slcrBaseAddress ) = SlcrTxClkCntrl;
594+
/* SDT drivers should not write to the register */
595+
#ifndef SDT
596+
SlcrTxClkCntrl = *( volatile unsigned int * ) ( slcrBaseAddress );
597+
SlcrTxClkCntrl &= EMACPS_SLCR_DIV_MASK;
598+
SlcrTxClkCntrl |= ( SlcrDiv1 << 20 );
599+
SlcrTxClkCntrl |= ( SlcrDiv0 << 8 );
600+
*( volatile unsigned int * ) ( slcrBaseAddress ) = SlcrTxClkCntrl;
601+
#else
602+
( void ) SlcrTxClkCntrl;
603+
( void ) SlcrDiv0;
604+
( void ) SlcrDiv1;
605+
( void ) slcrBaseAddress;
606+
#endif
599607
#endif /* ifdef PEEP */
600608
*( volatile unsigned int * ) ( SLCR_LOCK_ADDR ) = SLCR_LOCK_KEY_VALUE;
601609
}

0 commit comments

Comments
 (0)