mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-08-18 11:53:05 +08:00
add ethernet driver for zynqmp-r5-axu4ev
This commit is contained in:
+186
-23
@@ -23,6 +23,12 @@ CONFIG_IDLE_THREAD_STACK_SIZE=512
|
||||
CONFIG_RT_USING_TIMER_SOFT=y
|
||||
CONFIG_RT_TIMER_THREAD_PRIO=4
|
||||
CONFIG_RT_TIMER_THREAD_STACK_SIZE=512
|
||||
|
||||
#
|
||||
# kservice optimization
|
||||
#
|
||||
# CONFIG_RT_KSERVICE_USING_STDLIB is not set
|
||||
# CONFIG_RT_KSERVICE_USING_TINY_SIZE is not set
|
||||
CONFIG_RT_DEBUG=y
|
||||
# CONFIG_RT_DEBUG_COLOR is not set
|
||||
# CONFIG_RT_DEBUG_INIT_CONFIG is not set
|
||||
@@ -52,8 +58,9 @@ CONFIG_RT_USING_MESSAGEQUEUE=y
|
||||
CONFIG_RT_USING_MEMPOOL=y
|
||||
# CONFIG_RT_USING_MEMHEAP is not set
|
||||
# CONFIG_RT_USING_NOHEAP is not set
|
||||
CONFIG_RT_USING_SMALL_MEM=y
|
||||
# CONFIG_RT_USING_SLAB is not set
|
||||
# CONFIG_RT_USING_SMALL_MEM is not set
|
||||
CONFIG_RT_USING_SLAB=y
|
||||
# CONFIG_RT_USING_USERHEAP is not set
|
||||
# CONFIG_RT_USING_MEMTRACE is not set
|
||||
CONFIG_RT_USING_HEAP=y
|
||||
|
||||
@@ -66,7 +73,7 @@ CONFIG_RT_USING_DEVICE=y
|
||||
CONFIG_RT_USING_CONSOLE=y
|
||||
CONFIG_RT_CONSOLEBUF_SIZE=128
|
||||
CONFIG_RT_CONSOLE_DEVICE_NAME="uart0"
|
||||
CONFIG_RT_VER_NUM=0x40003
|
||||
CONFIG_RT_VER_NUM=0x40004
|
||||
# CONFIG_RT_USING_CPU_FFS is not set
|
||||
# CONFIG_ARCH_CPU_STACK_GROWS_UPWARD is not set
|
||||
|
||||
@@ -123,6 +130,11 @@ CONFIG_RT_DFS_ELM_WORD_ACCESS=y
|
||||
# CONFIG_RT_DFS_ELM_USE_LFN_2 is not set
|
||||
CONFIG_RT_DFS_ELM_USE_LFN_3=y
|
||||
CONFIG_RT_DFS_ELM_USE_LFN=3
|
||||
CONFIG_RT_DFS_ELM_LFN_UNICODE_0=y
|
||||
# CONFIG_RT_DFS_ELM_LFN_UNICODE_1 is not set
|
||||
# CONFIG_RT_DFS_ELM_LFN_UNICODE_2 is not set
|
||||
# CONFIG_RT_DFS_ELM_LFN_UNICODE_3 is not set
|
||||
CONFIG_RT_DFS_ELM_LFN_UNICODE=0
|
||||
CONFIG_RT_DFS_ELM_MAX_LFN=255
|
||||
CONFIG_RT_DFS_ELM_DRIVES=2
|
||||
CONFIG_RT_DFS_ELM_MAX_SECTOR_SIZE=512
|
||||
@@ -131,15 +143,16 @@ CONFIG_RT_DFS_ELM_REENTRANT=y
|
||||
CONFIG_RT_USING_DFS_DEVFS=y
|
||||
# CONFIG_RT_USING_DFS_ROMFS is not set
|
||||
# CONFIG_RT_USING_DFS_RAMFS is not set
|
||||
# CONFIG_RT_USING_DFS_UFFS is not set
|
||||
# CONFIG_RT_USING_DFS_JFFS2 is not set
|
||||
# CONFIG_RT_USING_DFS_NFS is not set
|
||||
|
||||
#
|
||||
# Device Drivers
|
||||
#
|
||||
CONFIG_RT_USING_DEVICE_IPC=y
|
||||
CONFIG_RT_PIPE_BUFSZ=512
|
||||
# CONFIG_RT_USING_SYSTEM_WORKQUEUE is not set
|
||||
CONFIG_RT_USING_SYSTEM_WORKQUEUE=y
|
||||
CONFIG_RT_SYSTEM_WORKQUEUE_STACKSIZE=2048
|
||||
CONFIG_RT_SYSTEM_WORKQUEUE_PRIORITY=23
|
||||
CONFIG_RT_USING_SERIAL=y
|
||||
CONFIG_RT_SERIAL_USING_DMA=y
|
||||
CONFIG_RT_SERIAL_RB_BUFSZ=64
|
||||
@@ -147,6 +160,7 @@ CONFIG_RT_SERIAL_RB_BUFSZ=64
|
||||
# CONFIG_RT_USING_HWTIMER is not set
|
||||
# CONFIG_RT_USING_CPUTIME is not set
|
||||
# CONFIG_RT_USING_I2C is not set
|
||||
# CONFIG_RT_USING_PHY is not set
|
||||
CONFIG_RT_USING_PIN=y
|
||||
# CONFIG_RT_USING_ADC is not set
|
||||
# CONFIG_RT_USING_DAC is not set
|
||||
@@ -172,11 +186,6 @@ CONFIG_RT_USING_PIN=y
|
||||
# CONFIG_RT_USING_USB_HOST is not set
|
||||
# CONFIG_RT_USING_USB_DEVICE is not set
|
||||
|
||||
#
|
||||
# Using RapidIO
|
||||
#
|
||||
# CONFIG_RT_USING_RAPIDIO is not set
|
||||
|
||||
#
|
||||
# POSIX layer and C standard library
|
||||
#
|
||||
@@ -188,6 +197,7 @@ CONFIG_RT_USING_POSIX=y
|
||||
# CONFIG_RT_USING_POSIX_GETLINE is not set
|
||||
# CONFIG_RT_USING_POSIX_AIO is not set
|
||||
# CONFIG_RT_USING_MODULE is not set
|
||||
CONFIG_RT_LIBC_FIXED_TIMEZONE=8
|
||||
|
||||
#
|
||||
# Network
|
||||
@@ -196,22 +206,91 @@ CONFIG_RT_USING_POSIX=y
|
||||
#
|
||||
# Socket abstraction layer
|
||||
#
|
||||
# CONFIG_RT_USING_SAL is not set
|
||||
CONFIG_RT_USING_SAL=y
|
||||
CONFIG_SAL_INTERNET_CHECK=y
|
||||
|
||||
#
|
||||
# protocol stack implement
|
||||
#
|
||||
CONFIG_SAL_USING_LWIP=y
|
||||
CONFIG_SAL_USING_POSIX=y
|
||||
|
||||
#
|
||||
# Network interface device
|
||||
#
|
||||
# CONFIG_RT_USING_NETDEV is not set
|
||||
CONFIG_RT_USING_NETDEV=y
|
||||
CONFIG_NETDEV_USING_IFCONFIG=y
|
||||
CONFIG_NETDEV_USING_PING=y
|
||||
CONFIG_NETDEV_USING_NETSTAT=y
|
||||
CONFIG_NETDEV_USING_AUTO_DEFAULT=y
|
||||
# CONFIG_NETDEV_USING_IPV6 is not set
|
||||
CONFIG_NETDEV_IPV4=1
|
||||
CONFIG_NETDEV_IPV6=0
|
||||
# CONFIG_NETDEV_IPV6_SCOPES is not set
|
||||
|
||||
#
|
||||
# light weight TCP/IP stack
|
||||
#
|
||||
# CONFIG_RT_USING_LWIP is not set
|
||||
CONFIG_RT_USING_LWIP=y
|
||||
# CONFIG_RT_USING_LWIP141 is not set
|
||||
CONFIG_RT_USING_LWIP202=y
|
||||
# CONFIG_RT_USING_LWIP212 is not set
|
||||
# CONFIG_RT_USING_LWIP_IPV6 is not set
|
||||
CONFIG_RT_LWIP_MEM_ALIGNMENT=32
|
||||
CONFIG_RT_LWIP_IGMP=y
|
||||
CONFIG_RT_LWIP_ICMP=y
|
||||
# CONFIG_RT_LWIP_SNMP is not set
|
||||
CONFIG_RT_LWIP_DNS=y
|
||||
CONFIG_RT_LWIP_DHCP=y
|
||||
CONFIG_IP_SOF_BROADCAST=1
|
||||
CONFIG_IP_SOF_BROADCAST_RECV=1
|
||||
|
||||
#
|
||||
# Static IPv4 Address
|
||||
#
|
||||
CONFIG_RT_LWIP_IPADDR="192.168.1.30"
|
||||
CONFIG_RT_LWIP_GWADDR="192.168.1.1"
|
||||
CONFIG_RT_LWIP_MSKADDR="255.255.255.0"
|
||||
CONFIG_RT_LWIP_UDP=y
|
||||
CONFIG_RT_LWIP_TCP=y
|
||||
CONFIG_RT_LWIP_RAW=y
|
||||
# CONFIG_RT_LWIP_PPP is not set
|
||||
CONFIG_RT_MEMP_NUM_NETCONN=8
|
||||
CONFIG_RT_LWIP_PBUF_NUM=256
|
||||
CONFIG_RT_LWIP_RAW_PCB_NUM=4
|
||||
CONFIG_RT_LWIP_UDP_PCB_NUM=4
|
||||
CONFIG_RT_LWIP_TCP_PCB_NUM=4
|
||||
CONFIG_RT_LWIP_TCP_SEG_NUM=40
|
||||
CONFIG_RT_LWIP_TCP_SND_BUF=8196
|
||||
CONFIG_RT_LWIP_TCP_WND=8196
|
||||
CONFIG_RT_LWIP_TCPTHREAD_PRIORITY=10
|
||||
CONFIG_RT_LWIP_TCPTHREAD_MBOX_SIZE=8
|
||||
CONFIG_RT_LWIP_TCPTHREAD_STACKSIZE=2048
|
||||
# CONFIG_LWIP_NO_RX_THREAD is not set
|
||||
# CONFIG_LWIP_NO_TX_THREAD is not set
|
||||
CONFIG_RT_LWIP_ETHTHREAD_PRIORITY=12
|
||||
CONFIG_RT_LWIP_ETHTHREAD_STACKSIZE=1024
|
||||
CONFIG_RT_LWIP_ETHTHREAD_MBOX_SIZE=8
|
||||
# CONFIG_RT_LWIP_REASSEMBLY_FRAG is not set
|
||||
CONFIG_LWIP_NETIF_STATUS_CALLBACK=1
|
||||
CONFIG_LWIP_NETIF_LINK_CALLBACK=1
|
||||
CONFIG_SO_REUSE=1
|
||||
CONFIG_LWIP_SO_RCVTIMEO=1
|
||||
CONFIG_LWIP_SO_SNDTIMEO=1
|
||||
CONFIG_LWIP_SO_RCVBUF=1
|
||||
CONFIG_LWIP_SO_LINGER=0
|
||||
# CONFIG_RT_LWIP_NETIF_LOOPBACK is not set
|
||||
CONFIG_LWIP_NETIF_LOOPBACK=0
|
||||
# CONFIG_RT_LWIP_STATS is not set
|
||||
# CONFIG_RT_LWIP_USING_HW_CHECKSUM is not set
|
||||
CONFIG_RT_LWIP_USING_PING=y
|
||||
# CONFIG_RT_LWIP_DEBUG is not set
|
||||
|
||||
#
|
||||
# AT commands
|
||||
#
|
||||
# CONFIG_RT_USING_AT is not set
|
||||
# CONFIG_LWIP_USING_DHCPD is not set
|
||||
|
||||
#
|
||||
# VBUS(Virtual Software BUS)
|
||||
@@ -225,6 +304,11 @@ CONFIG_RT_USING_POSIX=y
|
||||
# CONFIG_RT_USING_ULOG is not set
|
||||
# CONFIG_RT_USING_UTEST is not set
|
||||
|
||||
#
|
||||
# RT-Thread Utestcases
|
||||
#
|
||||
# CONFIG_RT_USING_UTESTCASES is not set
|
||||
|
||||
#
|
||||
# RT-Thread online packages
|
||||
#
|
||||
@@ -292,8 +376,6 @@ CONFIG_RT_USING_POSIX=y
|
||||
# CONFIG_PKG_USING_LIBRWS is not set
|
||||
# CONFIG_PKG_USING_TCPSERVER is not set
|
||||
# CONFIG_PKG_USING_PROTOBUF_C is not set
|
||||
# CONFIG_PKG_USING_ONNX_PARSER is not set
|
||||
# CONFIG_PKG_USING_ONNX_BACKEND is not set
|
||||
# CONFIG_PKG_USING_DLT645 is not set
|
||||
# CONFIG_PKG_USING_QXWZ is not set
|
||||
# CONFIG_PKG_USING_SMTP_CLIENT is not set
|
||||
@@ -307,6 +389,13 @@ CONFIG_RT_USING_POSIX=y
|
||||
# CONFIG_PKG_USING_PDULIB is not set
|
||||
# CONFIG_PKG_USING_BTSTACK is not set
|
||||
# CONFIG_PKG_USING_LORAWAN_ED_STACK is not set
|
||||
# CONFIG_PKG_USING_WAYZ_IOTKIT is not set
|
||||
# CONFIG_PKG_USING_MAVLINK is not set
|
||||
# CONFIG_PKG_USING_RAPIDJSON is not set
|
||||
# CONFIG_PKG_USING_BSAL is not set
|
||||
# CONFIG_PKG_USING_AGILE_MODBUS is not set
|
||||
# CONFIG_PKG_USING_AGILE_FTP is not set
|
||||
# CONFIG_PKG_USING_EMBEDDEDPROTO is not set
|
||||
|
||||
#
|
||||
# security packages
|
||||
@@ -332,8 +421,11 @@ CONFIG_RT_USING_POSIX=y
|
||||
# CONFIG_PKG_USING_STEMWIN is not set
|
||||
# CONFIG_PKG_USING_WAVPLAYER is not set
|
||||
# CONFIG_PKG_USING_TJPGD is not set
|
||||
# CONFIG_PKG_USING_PDFGEN is not set
|
||||
# CONFIG_PKG_USING_HELIX is not set
|
||||
# CONFIG_PKG_USING_AZUREGUIX is not set
|
||||
# CONFIG_PKG_USING_TOUCHGFX2RTT is not set
|
||||
# CONFIG_PKG_USING_NUEMWIN is not set
|
||||
|
||||
#
|
||||
# tools packages
|
||||
@@ -345,6 +437,8 @@ CONFIG_RT_USING_POSIX=y
|
||||
# CONFIG_PKG_USING_RDB is not set
|
||||
# CONFIG_PKG_USING_QRCODE is not set
|
||||
# CONFIG_PKG_USING_ULOG_EASYFLASH is not set
|
||||
# CONFIG_PKG_USING_ULOG_FILE is not set
|
||||
# CONFIG_PKG_USING_LOGMGR is not set
|
||||
# CONFIG_PKG_USING_ADBD is not set
|
||||
# CONFIG_PKG_USING_COREMARK is not set
|
||||
# CONFIG_PKG_USING_DHRYSTONE is not set
|
||||
@@ -357,6 +451,22 @@ CONFIG_RT_USING_POSIX=y
|
||||
# CONFIG_PKG_USING_URLENCODE is not set
|
||||
# CONFIG_PKG_USING_UMCN is not set
|
||||
# CONFIG_PKG_USING_LWRB2RTT is not set
|
||||
# CONFIG_PKG_USING_CPU_USAGE is not set
|
||||
# CONFIG_PKG_USING_GBK2UTF8 is not set
|
||||
# CONFIG_PKG_USING_VCONSOLE is not set
|
||||
# CONFIG_PKG_USING_KDB is not set
|
||||
# CONFIG_PKG_USING_WAMR is not set
|
||||
# CONFIG_PKG_USING_MICRO_XRCE_DDS_CLIENT is not set
|
||||
# CONFIG_PKG_USING_LWLOG is not set
|
||||
# CONFIG_PKG_USING_ANV_TRACE is not set
|
||||
# CONFIG_PKG_USING_ANV_MEMLEAK is not set
|
||||
# CONFIG_PKG_USING_ANV_TESTSUIT is not set
|
||||
# CONFIG_PKG_USING_ANV_BENCH is not set
|
||||
# CONFIG_PKG_USING_DEVMEM is not set
|
||||
# CONFIG_PKG_USING_REGEX is not set
|
||||
# CONFIG_PKG_USING_MEM_SANDBOX is not set
|
||||
# CONFIG_PKG_USING_SOLAR_TERMS is not set
|
||||
# CONFIG_PKG_USING_GAN_ZHI is not set
|
||||
|
||||
#
|
||||
# system packages
|
||||
@@ -364,7 +474,6 @@ CONFIG_RT_USING_POSIX=y
|
||||
# CONFIG_PKG_USING_GUIENGINE is not set
|
||||
# CONFIG_PKG_USING_CAIRO is not set
|
||||
# CONFIG_PKG_USING_PIXMAN is not set
|
||||
# CONFIG_PKG_USING_LWEXT4 is not set
|
||||
# CONFIG_PKG_USING_PARTITION is not set
|
||||
# CONFIG_PKG_USING_FAL is not set
|
||||
# CONFIG_PKG_USING_FLASHDB is not set
|
||||
@@ -374,6 +483,9 @@ CONFIG_RT_USING_POSIX=y
|
||||
# CONFIG_PKG_USING_CMSIS is not set
|
||||
# CONFIG_PKG_USING_DFS_YAFFS is not set
|
||||
# CONFIG_PKG_USING_LITTLEFS is not set
|
||||
# CONFIG_PKG_USING_DFS_JFFS2 is not set
|
||||
# CONFIG_PKG_USING_DFS_UFFS is not set
|
||||
# CONFIG_PKG_USING_LWEXT4 is not set
|
||||
# CONFIG_PKG_USING_THREAD_POOL is not set
|
||||
# CONFIG_PKG_USING_ROBOTS is not set
|
||||
# CONFIG_PKG_USING_EV is not set
|
||||
@@ -388,11 +500,21 @@ CONFIG_RT_USING_POSIX=y
|
||||
# Micrium: Micrium software products porting for RT-Thread
|
||||
#
|
||||
# CONFIG_PKG_USING_UCOSIII_WRAPPER is not set
|
||||
# CONFIG_PKG_USING_UCOSII_WRAPPER is not set
|
||||
# CONFIG_PKG_USING_UC_CRC is not set
|
||||
# CONFIG_PKG_USING_UC_CLK is not set
|
||||
# CONFIG_PKG_USING_UC_COMMON is not set
|
||||
# CONFIG_PKG_USING_UC_MODBUS is not set
|
||||
# CONFIG_PKG_USING_PPOOL is not set
|
||||
# CONFIG_PKG_USING_OPENAMP is not set
|
||||
# CONFIG_PKG_USING_RT_KPRINTF_THREADSAFE is not set
|
||||
# CONFIG_PKG_USING_RT_MEMCPY_CM is not set
|
||||
# CONFIG_PKG_USING_QFPLIB_M0_FULL is not set
|
||||
# CONFIG_PKG_USING_QFPLIB_M0_TINY is not set
|
||||
# CONFIG_PKG_USING_QFPLIB_M3 is not set
|
||||
# CONFIG_PKG_USING_LPM is not set
|
||||
# CONFIG_PKG_USING_TLSF is not set
|
||||
# CONFIG_PKG_USING_EVENT_RECORDER is not set
|
||||
|
||||
#
|
||||
# peripheral libraries and drivers
|
||||
@@ -401,6 +523,7 @@ CONFIG_RT_USING_POSIX=y
|
||||
# CONFIG_PKG_USING_REALTEK_AMEBA is not set
|
||||
# CONFIG_PKG_USING_SHT2X is not set
|
||||
# CONFIG_PKG_USING_SHT3X is not set
|
||||
# CONFIG_PKG_USING_AS7341 is not set
|
||||
# CONFIG_PKG_USING_STM32_SDIO is not set
|
||||
# CONFIG_PKG_USING_ICM20608 is not set
|
||||
# CONFIG_PKG_USING_U8G2 is not set
|
||||
@@ -449,6 +572,30 @@ CONFIG_RT_USING_POSIX=y
|
||||
# CONFIG_PKG_USING_DM9051 is not set
|
||||
# CONFIG_PKG_USING_SSD1306 is not set
|
||||
# CONFIG_PKG_USING_QKEY is not set
|
||||
# CONFIG_PKG_USING_RS485 is not set
|
||||
# CONFIG_PKG_USING_NES is not set
|
||||
# CONFIG_PKG_USING_VIRTUAL_SENSOR is not set
|
||||
# CONFIG_PKG_USING_VDEVICE is not set
|
||||
# CONFIG_PKG_USING_SGM706 is not set
|
||||
# CONFIG_PKG_USING_STM32WB55_SDK is not set
|
||||
# CONFIG_PKG_USING_RDA58XX is not set
|
||||
# CONFIG_PKG_USING_LIBNFC is not set
|
||||
# CONFIG_PKG_USING_MFOC is not set
|
||||
# CONFIG_PKG_USING_TMC51XX is not set
|
||||
# CONFIG_PKG_USING_TCA9534 is not set
|
||||
|
||||
#
|
||||
# AI packages
|
||||
#
|
||||
# CONFIG_PKG_USING_LIBANN is not set
|
||||
# CONFIG_PKG_USING_NNOM is not set
|
||||
# CONFIG_PKG_USING_ONNX_BACKEND is not set
|
||||
# CONFIG_PKG_USING_ONNX_PARSER is not set
|
||||
# CONFIG_PKG_USING_TENSORFLOWLITEMICRO is not set
|
||||
# CONFIG_PKG_USING_ELAPACK is not set
|
||||
# CONFIG_PKG_USING_ULAPACK is not set
|
||||
# CONFIG_PKG_USING_QUEST is not set
|
||||
# CONFIG_PKG_USING_NAXOS is not set
|
||||
|
||||
#
|
||||
# miscellaneous packages
|
||||
@@ -458,6 +605,7 @@ CONFIG_RT_USING_POSIX=y
|
||||
# CONFIG_PKG_USING_FASTLZ is not set
|
||||
# CONFIG_PKG_USING_MINILZO is not set
|
||||
# CONFIG_PKG_USING_QUICKLZ is not set
|
||||
# CONFIG_PKG_USING_LZMA is not set
|
||||
# CONFIG_PKG_USING_MULTIBUTTON is not set
|
||||
# CONFIG_PKG_USING_FLEXIBLE_BUTTON is not set
|
||||
# CONFIG_PKG_USING_CANFESTIVAL is not set
|
||||
@@ -479,19 +627,24 @@ CONFIG_RT_USING_POSIX=y
|
||||
# CONFIG_PKG_USING_HELLO is not set
|
||||
# CONFIG_PKG_USING_VI is not set
|
||||
# CONFIG_PKG_USING_KI is not set
|
||||
# CONFIG_PKG_USING_NNOM is not set
|
||||
# CONFIG_PKG_USING_LIBANN is not set
|
||||
# CONFIG_PKG_USING_ELAPACK is not set
|
||||
# CONFIG_PKG_USING_ARMv7M_DWT is not set
|
||||
# CONFIG_PKG_USING_VT100 is not set
|
||||
# CONFIG_PKG_USING_TETRIS is not set
|
||||
# CONFIG_PKG_USING_ULAPACK is not set
|
||||
# CONFIG_PKG_USING_UKAL is not set
|
||||
# CONFIG_PKG_USING_CRCLIB is not set
|
||||
|
||||
#
|
||||
# entertainment: terminal games and other interesting software packages
|
||||
#
|
||||
# CONFIG_PKG_USING_THREES is not set
|
||||
# CONFIG_PKG_USING_2048 is not set
|
||||
# CONFIG_PKG_USING_SNAKE is not set
|
||||
# CONFIG_PKG_USING_TETRIS is not set
|
||||
# CONFIG_PKG_USING_DONUT is not set
|
||||
# CONFIG_PKG_USING_ACLOCK is not set
|
||||
# CONFIG_PKG_USING_LWGPS is not set
|
||||
# CONFIG_PKG_USING_TENSORFLOWLITEMICRO is not set
|
||||
# CONFIG_PKG_USING_STATE_MACHINE is not set
|
||||
# CONFIG_PKG_USING_MCURSES is not set
|
||||
# CONFIG_PKG_USING_COWSAY is not set
|
||||
CONFIG_SOC_ZYNQMP_R5=y
|
||||
|
||||
#
|
||||
@@ -510,6 +663,16 @@ CONFIG_BSP_USING_UART0=y
|
||||
CONFIG_BSP_USING_SDIO=y
|
||||
CONFIG_BSP_USING_SD0=y
|
||||
|
||||
#
|
||||
# Please set RT_LWIP_PBUF_NUM is at least 256 if Enable Ethernet!
|
||||
#
|
||||
|
||||
#
|
||||
# Please set RT_LWIP_MEM_ALIGNMENT is at 32 if Enable Ethernet!
|
||||
#
|
||||
CONFIG_BSP_USING_ETH=y
|
||||
CONFIG_RT_LWIP_PBUF_POOL_BUFSIZE=1700
|
||||
|
||||
#
|
||||
# Board extended module Drivers
|
||||
#
|
||||
|
||||
@@ -35,6 +35,7 @@ Each peripheral supporting condition for this BSP is as follows:
|
||||
| UART | Support | UART0 |
|
||||
| TIMER | Support | TTC0 provides system clock |
|
||||
| EMMC | Support | SD0 Controller |
|
||||
| EMAC | Support | e0 Net Interface |
|
||||
|
||||
## Execution Instruction
|
||||
|
||||
@@ -99,14 +100,31 @@ msh />
|
||||
|
||||
This BSP enables EMMC driver and DFS file system by default. If you need to use a file system, you can format and mount it by yourself.
|
||||
|
||||
This BSP is enabled and configured with net interface driver and LwIP protocol stack by default, and note the following configuration:
|
||||
|
||||
1. Note that `RT_LWIP_PBUF_NUM` is set to at least 256
|
||||
|
||||
2. Note that `RT_ LWIP_ MEM_ Alignment` is set to 32. If the version other than lwip 2.0.2 in RTT is used, the `MEM_ALIGNMENT` in `lwipopts.h` needs to be modified manually because the macro is not used in other versions.
|
||||
|
||||
## BSP Migration
|
||||
|
||||
If you need to ported the BSP to another development board of Xilinx Zynq UltraScale+ MPSOC development platform, it is also convenient. The main modifications are as follows:
|
||||
|
||||
1. Memory: `psu_r5_ddr_0_MEM_0` in `zynqmp-r5.ld` (if DDR memory is less than 2G)
|
||||
1. Memory: `psu_r5_ddr_0_MEM_0` in `zynqmp-r5.ld` and `HEAP_END` in `board.h ` (if DDR memory is less than 2G)
|
||||
2. Main Frequency: `XPAR_CPU_CORTEXR5_0_CPU_CLK_FREQ_HZ` in `zynqmp-r5.h`
|
||||
3. Pin and Frequency of Serial Port: `rxmio`, `txmio` and `XPAR_PSU_UART_0_UART_CLK_FREQ_HZ` in `drv_uart.c`
|
||||
4. Timer Frequency: `XPAR_PSU_TTC_0_TTC_CLK_FREQ_HZ` in `drv_timer.c`
|
||||
5. SD Controller: Block device driver initialization in `drv_sdcard.c`
|
||||
6. Net interface: If the PHY chip used is not in the range of driver support, it may be necessary to realize the rate identification function of the corresponding chip in `xemacpsif_physpeed.c`. You can refer to the corresponding tutorial of Alinx.
|
||||
|
||||
The parameter macro definition in `xparameters.h` does not need to be modified manually. You can directly copy the `xparameters.h` file of the development board generated in Xilinx Vitis.
|
||||
|
||||
## Attention
|
||||
|
||||
-None
|
||||
|
||||
## Contact
|
||||
|
||||
Maintainer:
|
||||
|
||||
- [Wang Huachen](https://github.com/Wang-Huachen/)
|
||||
@@ -32,6 +32,7 @@ AXU4EV-E 开发板是 芯驿电子科技(上海)有限公司 推出的一款
|
||||
| UART | 支持 | UART0 |
|
||||
| TIMER | 支持 | TTC0提供系统时钟 |
|
||||
| EMMC | 支持 | SD0控制器 |
|
||||
| EMAC | 支持 | e0网卡 |
|
||||
|
||||
## 使用说明
|
||||
|
||||
@@ -107,16 +108,22 @@ msh />
|
||||
|
||||
此 BSP 默认开启了 EMMC 驱动和 DFS 文件系统,如果需要使用文件系统可以自行格式化并挂载。
|
||||
|
||||
此 BSP 默认开启并配置了网卡驱动及lwip协议栈,相关配置需要注意如下几点:
|
||||
|
||||
1. 注意将`RT_LWIP_PBUF_NUM`至少设置为256
|
||||
2. 注意将`RT_LWIP_MEM_ALIGNMENT`设置为32。若使用RTT中lwip 2.0.2以外的版本时,由于其他版本未使用该宏,需要手动修改`lwipopts.h`中的`MEM_ALIGNMENT`宏。
|
||||
|
||||
|
||||
## 板级移植
|
||||
|
||||
如果需要将BSP移植到其他 XILINX Zynq UltraScale+ MPSoCs 开发平台的开发板上也比较方便,主要修改的地方有以下几点:
|
||||
|
||||
1. 内存: 如果 DDR memory 小于 2G,需要修改`zynqmp-r5.ld`链接文件中的`psu_r5_ddr_0_MEM_0`
|
||||
1. 内存: 如果 DDR memory 小于 2G,需要修改`zynqmp-r5.ld`链接文件中的`psu_r5_ddr_0_MEM_0` 以及`board.h`中的`HEAP_END`
|
||||
2. 主频: `xparameters.h`中的`XPAR_CPU_CORTEXR5_0_CPU_CLK_FREQ_HZ`
|
||||
3. 串口引脚和频率:`drv_uart.c`中的`rxmio`, `txmio` 和`xparameters.h`中的`XPAR_PSU_UART_0_UART_CLK_FREQ_HZ`
|
||||
4. 定时器频率:`xparameters.h`中的`XPAR_PSU_TTC_0_TTC_CLK_FREQ_HZ`
|
||||
5. SD控制器:`drv_sdcard.c`中的块设备驱动初始化
|
||||
6. 网卡驱动:若使用的PHY芯片不在驱动支持范围内,可能需要在`xemacpsif_physpeed.c`中实现相应芯片的速率识别函数,可参考ALINX的相应教程。
|
||||
|
||||
以上需要修改的`xparameters.h`中的参数宏定义不需要手动修改,可以直接将Xilinx Vitis中产生的开发板的`xparameters.h`文件复制过来即可。
|
||||
|
||||
|
||||
@@ -24,6 +24,19 @@ menu "Hardware Drivers Config"
|
||||
bool "Enable SD0 EMMC"
|
||||
default y
|
||||
endif
|
||||
comment "Please set RT_LWIP_PBUF_NUM is at least 256 if Enable Ethernet!"
|
||||
comment "Please set RT_LWIP_MEM_ALIGNMENT is at 32 if Enable Ethernet!"
|
||||
menuconfig BSP_USING_ETH
|
||||
bool "Enable Ethernet"
|
||||
default n
|
||||
select RT_USING_NETDEV
|
||||
select RT_USING_LWIP
|
||||
if BSP_USING_ETH
|
||||
config RT_LWIP_PBUF_POOL_BUFSIZE
|
||||
int "The size of each pbuf in the pbuf pool"
|
||||
range 1500 2000
|
||||
default 1700
|
||||
endif
|
||||
|
||||
endmenu
|
||||
|
||||
|
||||
@@ -11,6 +11,9 @@ if GetDepend('BSP_USING_SDIO'):
|
||||
objs = objs + SConscript('sdps_v3_9/SConscript')
|
||||
if GetDepend('RT_USING_PIN'):
|
||||
objs = objs + SConscript('gpiops_v3_7/SConscript')
|
||||
if GetDepend('BSP_USING_ETH'):
|
||||
objs = objs + SConscript('emacps_v3_11/SConscript')
|
||||
objs = objs + SConscript('xemacpsif/SConscript')
|
||||
|
||||
objs = objs + group
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import rtconfig
|
||||
from building import *
|
||||
|
||||
# get current directory
|
||||
cwd = GetCurrentDir()
|
||||
CPPPATH = [cwd]
|
||||
|
||||
# The set of source files associated with this SConscript file.
|
||||
|
||||
src = Glob('*.c')
|
||||
path = cwd
|
||||
|
||||
group = DefineGroup('ZYNQMP_HAL', src, depend = [''], CPPPATH = CPPPATH)
|
||||
|
||||
Return('group')
|
||||
@@ -0,0 +1,480 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2010 - 2020 Xilinx, Inc. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
******************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* @file xemacps.c
|
||||
* @addtogroup emacps_v3_11
|
||||
* @{
|
||||
*
|
||||
* The XEmacPs driver. Functions in this file are the minimum required functions
|
||||
* for this driver. See xemacps.h for a detailed description of the driver.
|
||||
*
|
||||
* <pre>
|
||||
* MODIFICATION HISTORY:
|
||||
*
|
||||
* Ver Who Date Changes
|
||||
* ----- ---- -------- -------------------------------------------------------
|
||||
* 1.00a wsy 01/10/10 First release
|
||||
* 2.1 srt 07/15/14 Add support for Zynq Ultrascale Mp GEM specification and
|
||||
* 64-bit changes.
|
||||
* 3.00 kvn 02/13/15 Modified code for MISRA-C:2012 compliance.
|
||||
* 3.0 hk 02/20/15 Added support for jumbo frames. Increase AHB burst.
|
||||
* Disable extended mode. Perform all 64 bit changes under
|
||||
* check for arch64.
|
||||
* 3.1 hk 08/10/15 Update upper 32 bit tx and rx queue ptr registers
|
||||
* 3.5 hk 08/14/17 Update cache coherency information of the interface in
|
||||
* its config structure.
|
||||
* 3.8 hk 09/17/18 Cleanup stale comments.
|
||||
* 3.8 mus 11/05/18 Support 64 bit DMA addresses for Microblaze-X platform.
|
||||
* 3.10 hk 05/16/19 Clear status registers properly in reset
|
||||
* 3.11 sd 02/14/20 Add clock support
|
||||
*
|
||||
* </pre>
|
||||
******************************************************************************/
|
||||
|
||||
/***************************** Include Files *********************************/
|
||||
|
||||
#include "xemacps.h"
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
|
||||
|
||||
/**************************** Type Definitions *******************************/
|
||||
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
|
||||
|
||||
/************************** Function Prototypes ******************************/
|
||||
|
||||
void XEmacPs_StubHandler(void); /* Default handler routine */
|
||||
|
||||
/************************** Variable Definitions *****************************/
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* Initialize a specific XEmacPs instance/driver. The initialization entails:
|
||||
* - Initialize fields of the XEmacPs instance structure
|
||||
* - Reset hardware and apply default options
|
||||
* - Configure the DMA channels
|
||||
*
|
||||
* The PHY is setup independently from the device. Use the MII or whatever other
|
||||
* interface may be present for setup.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the instance to be worked on.
|
||||
* @param CfgPtr is the device configuration structure containing required
|
||||
* hardware build data.
|
||||
* @param EffectiveAddress is the base address of the device. If address
|
||||
* translation is not utilized, this parameter can be passed in using
|
||||
* CfgPtr->Config.BaseAddress to specify the physical base address.
|
||||
*
|
||||
* @return
|
||||
* - XST_SUCCESS if initialization was successful
|
||||
*
|
||||
******************************************************************************/
|
||||
LONG XEmacPs_CfgInitialize(XEmacPs *InstancePtr, XEmacPs_Config * CfgPtr,
|
||||
UINTPTR EffectiveAddress)
|
||||
{
|
||||
/* Verify arguments */
|
||||
Xil_AssertNonvoid(InstancePtr != NULL);
|
||||
Xil_AssertNonvoid(CfgPtr != NULL);
|
||||
|
||||
/* Set device base address and ID */
|
||||
InstancePtr->Config.DeviceId = CfgPtr->DeviceId;
|
||||
InstancePtr->Config.BaseAddress = EffectiveAddress;
|
||||
InstancePtr->Config.IsCacheCoherent = CfgPtr->IsCacheCoherent;
|
||||
#if defined (XCLOCKING)
|
||||
InstancePtr->Config.RefClk = CfgPtr->RefClk;
|
||||
#endif
|
||||
|
||||
/* Set callbacks to an initial stub routine */
|
||||
InstancePtr->SendHandler = ((XEmacPs_Handler)((void*)XEmacPs_StubHandler));
|
||||
InstancePtr->RecvHandler = ((XEmacPs_Handler)(void*)XEmacPs_StubHandler);
|
||||
InstancePtr->ErrorHandler = ((XEmacPs_ErrHandler)(void*)XEmacPs_StubHandler);
|
||||
|
||||
/* Reset the hardware and set default options */
|
||||
InstancePtr->IsReady = XIL_COMPONENT_IS_READY;
|
||||
XEmacPs_Reset(InstancePtr);
|
||||
|
||||
return (LONG)(XST_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* Start the Ethernet controller as follows:
|
||||
* - Enable transmitter if XTE_TRANSMIT_ENABLE_OPTION is set
|
||||
* - Enable receiver if XTE_RECEIVER_ENABLE_OPTION is set
|
||||
* - Start the SG DMA send and receive channels and enable the device
|
||||
* interrupt
|
||||
*
|
||||
* @param InstancePtr is a pointer to the instance to be worked on.
|
||||
*
|
||||
* @return N/A
|
||||
*
|
||||
* @note
|
||||
* Hardware is configured with scatter-gather DMA, the driver expects to start
|
||||
* the scatter-gather channels and expects that the user has previously set up
|
||||
* the buffer descriptor lists.
|
||||
*
|
||||
* This function makes use of internal resources that are shared between the
|
||||
* Start, Stop, and Set/ClearOptions functions. So if one task might be setting
|
||||
* device options while another is trying to start the device, the user is
|
||||
* required to provide protection of this shared data (typically using a
|
||||
* semaphore).
|
||||
*
|
||||
* This function must not be preempted by an interrupt that may service the
|
||||
* device.
|
||||
*
|
||||
******************************************************************************/
|
||||
void XEmacPs_Start(XEmacPs *InstancePtr)
|
||||
{
|
||||
u32 Reg;
|
||||
|
||||
/* Assert bad arguments and conditions */
|
||||
Xil_AssertVoid(InstancePtr != NULL);
|
||||
Xil_AssertVoid(InstancePtr->IsReady == (u32)XIL_COMPONENT_IS_READY);
|
||||
|
||||
#if defined (XCLOCKING)
|
||||
if (InstancePtr->IsStarted != (u32)XIL_COMPONENT_IS_STARTED) {
|
||||
Xil_ClockEnable(InstancePtr->Config.RefClk);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Start DMA */
|
||||
/* When starting the DMA channels, both transmit and receive sides
|
||||
* need an initialized BD list.
|
||||
*/
|
||||
if (InstancePtr->Version == 2) {
|
||||
Xil_AssertVoid(InstancePtr->RxBdRing.BaseBdAddr != 0);
|
||||
Xil_AssertVoid(InstancePtr->TxBdRing.BaseBdAddr != 0);
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_RXQBASE_OFFSET,
|
||||
InstancePtr->RxBdRing.BaseBdAddr);
|
||||
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_TXQBASE_OFFSET,
|
||||
InstancePtr->TxBdRing.BaseBdAddr);
|
||||
}
|
||||
|
||||
/* clear any existed int status */
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress, XEMACPS_ISR_OFFSET,
|
||||
XEMACPS_IXR_ALL_MASK);
|
||||
|
||||
/* Enable transmitter if not already enabled */
|
||||
if ((InstancePtr->Options & (u32)XEMACPS_TRANSMITTER_ENABLE_OPTION)!=0x00000000U) {
|
||||
Reg = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_NWCTRL_OFFSET);
|
||||
if ((!(Reg & XEMACPS_NWCTRL_TXEN_MASK))==TRUE) {
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_NWCTRL_OFFSET,
|
||||
Reg | (u32)XEMACPS_NWCTRL_TXEN_MASK);
|
||||
}
|
||||
}
|
||||
|
||||
/* Enable receiver if not already enabled */
|
||||
if ((InstancePtr->Options & XEMACPS_RECEIVER_ENABLE_OPTION) != 0x00000000U) {
|
||||
Reg = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_NWCTRL_OFFSET);
|
||||
if ((!(Reg & XEMACPS_NWCTRL_RXEN_MASK))==TRUE) {
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_NWCTRL_OFFSET,
|
||||
Reg | (u32)XEMACPS_NWCTRL_RXEN_MASK);
|
||||
}
|
||||
}
|
||||
|
||||
/* Enable TX and RX interrupts */
|
||||
XEmacPs_IntEnable(InstancePtr, (XEMACPS_IXR_TX_ERR_MASK |
|
||||
XEMACPS_IXR_RX_ERR_MASK | (u32)XEMACPS_IXR_FRAMERX_MASK |
|
||||
(u32)XEMACPS_IXR_TXCOMPL_MASK));
|
||||
|
||||
/* Enable TX Q1 Interrupts */
|
||||
if (InstancePtr->Version > 2)
|
||||
XEmacPs_IntQ1Enable(InstancePtr, XEMACPS_INTQ1_IXR_ALL_MASK);
|
||||
|
||||
/* Mark as started */
|
||||
InstancePtr->IsStarted = XIL_COMPONENT_IS_STARTED;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* Gracefully stop the Ethernet MAC as follows:
|
||||
* - Disable all interrupts from this device
|
||||
* - Stop DMA channels
|
||||
* - Disable the tansmitter and receiver
|
||||
*
|
||||
* Device options currently in effect are not changed.
|
||||
*
|
||||
* This function will disable all interrupts. Default interrupts settings that
|
||||
* had been enabled will be restored when XEmacPs_Start() is called.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the instance to be worked on.
|
||||
*
|
||||
* @note
|
||||
* This function makes use of internal resources that are shared between the
|
||||
* Start, Stop, SetOptions, and ClearOptions functions. So if one task might be
|
||||
* setting device options while another is trying to start the device, the user
|
||||
* is required to provide protection of this shared data (typically using a
|
||||
* semaphore).
|
||||
*
|
||||
* Stopping the DMA channels causes this function to block until the DMA
|
||||
* operation is complete.
|
||||
*
|
||||
******************************************************************************/
|
||||
void XEmacPs_Stop(XEmacPs *InstancePtr)
|
||||
{
|
||||
u32 Reg;
|
||||
|
||||
Xil_AssertVoid(InstancePtr != NULL);
|
||||
Xil_AssertVoid(InstancePtr->IsReady == (u32)XIL_COMPONENT_IS_READY);
|
||||
|
||||
/* Disable all interrupts */
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress, XEMACPS_IDR_OFFSET,
|
||||
XEMACPS_IXR_ALL_MASK);
|
||||
|
||||
/* Disable the receiver & transmitter */
|
||||
Reg = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_NWCTRL_OFFSET);
|
||||
Reg &= (u32)(~XEMACPS_NWCTRL_RXEN_MASK);
|
||||
Reg &= (u32)(~XEMACPS_NWCTRL_TXEN_MASK);
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_NWCTRL_OFFSET, Reg);
|
||||
|
||||
/* Mark as stopped */
|
||||
InstancePtr->IsStarted = 0U;
|
||||
#if defined (XCLOCKING)
|
||||
Xil_ClockDisable(InstancePtr->Config.RefClk);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* Perform a graceful reset of the Ethernet MAC. Resets the DMA channels, the
|
||||
* transmitter, and the receiver.
|
||||
*
|
||||
* Steps to reset
|
||||
* - Stops transmit and receive channels
|
||||
* - Stops DMA
|
||||
* - Configure transmit and receive buffer size to default
|
||||
* - Clear transmit and receive status register and counters
|
||||
* - Clear all interrupt sources
|
||||
* - Clear phy (if there is any previously detected) address
|
||||
* - Clear MAC addresses (1-4) as well as Type IDs and hash value
|
||||
*
|
||||
* All options are placed in their default state. Any frames in the
|
||||
* descriptor lists will remain in the lists. The side effect of doing
|
||||
* this is that after a reset and following a restart of the device, frames
|
||||
* were in the list before the reset may be transmitted or received.
|
||||
*
|
||||
* The upper layer software is responsible for re-configuring (if necessary)
|
||||
* and restarting the MAC after the reset. Note also that driver statistics
|
||||
* are not cleared on reset. It is up to the upper layer software to clear the
|
||||
* statistics if needed.
|
||||
*
|
||||
* When a reset is required, the driver notifies the upper layer software of
|
||||
* this need through the ErrorHandler callback and specific status codes.
|
||||
* The upper layer software is responsible for calling this Reset function
|
||||
* and then re-configuring the device.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the instance to be worked on.
|
||||
*
|
||||
******************************************************************************/
|
||||
void XEmacPs_Reset(XEmacPs *InstancePtr)
|
||||
{
|
||||
u32 Reg;
|
||||
u8 i;
|
||||
s8 EmacPs_zero_MAC[6] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 };
|
||||
|
||||
Xil_AssertVoid(InstancePtr != NULL);
|
||||
Xil_AssertVoid(InstancePtr->IsReady == (u32)XIL_COMPONENT_IS_READY);
|
||||
|
||||
/* Stop the device and reset hardware */
|
||||
XEmacPs_Stop(InstancePtr);
|
||||
InstancePtr->Options = XEMACPS_DEFAULT_OPTIONS;
|
||||
|
||||
InstancePtr->Version = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress, 0xFC);
|
||||
|
||||
InstancePtr->Version = (InstancePtr->Version >> 16) & 0xFFF;
|
||||
|
||||
InstancePtr->MaxMtuSize = XEMACPS_MTU;
|
||||
InstancePtr->MaxFrameSize = XEMACPS_MTU + XEMACPS_HDR_SIZE +
|
||||
XEMACPS_TRL_SIZE;
|
||||
InstancePtr->MaxVlanFrameSize = InstancePtr->MaxFrameSize +
|
||||
XEMACPS_HDR_VLAN_SIZE;
|
||||
InstancePtr->RxBufMask = XEMACPS_RXBUF_LEN_MASK;
|
||||
|
||||
/* Setup hardware with default values */
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_NWCTRL_OFFSET,
|
||||
(XEMACPS_NWCTRL_STATCLR_MASK |
|
||||
XEMACPS_NWCTRL_MDEN_MASK) &
|
||||
(u32)(~XEMACPS_NWCTRL_LOOPEN_MASK));
|
||||
|
||||
Reg = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_NWCFG_OFFSET);
|
||||
Reg &= XEMACPS_NWCFG_MDCCLKDIV_MASK;
|
||||
|
||||
Reg = Reg | (u32)XEMACPS_NWCFG_100_MASK |
|
||||
(u32)XEMACPS_NWCFG_FDEN_MASK |
|
||||
(u32)XEMACPS_NWCFG_UCASTHASHEN_MASK;
|
||||
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_NWCFG_OFFSET, Reg);
|
||||
if (InstancePtr->Version > 2) {
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress, XEMACPS_NWCFG_OFFSET,
|
||||
(XEmacPs_ReadReg(InstancePtr->Config.BaseAddress, XEMACPS_NWCFG_OFFSET) |
|
||||
XEMACPS_NWCFG_DWIDTH_64_MASK));
|
||||
}
|
||||
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_DMACR_OFFSET,
|
||||
(((((u32)XEMACPS_RX_BUF_SIZE / (u32)XEMACPS_RX_BUF_UNIT) +
|
||||
(((((u32)XEMACPS_RX_BUF_SIZE %
|
||||
(u32)XEMACPS_RX_BUF_UNIT))!=(u32)0) ? 1U : 0U)) <<
|
||||
(u32)(XEMACPS_DMACR_RXBUF_SHIFT)) &
|
||||
(u32)(XEMACPS_DMACR_RXBUF_MASK)) |
|
||||
(u32)XEMACPS_DMACR_RXSIZE_MASK |
|
||||
(u32)XEMACPS_DMACR_TXSIZE_MASK);
|
||||
|
||||
|
||||
if (InstancePtr->Version > 2) {
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress, XEMACPS_DMACR_OFFSET,
|
||||
(XEmacPs_ReadReg(InstancePtr->Config.BaseAddress, XEMACPS_DMACR_OFFSET) |
|
||||
#if defined(__aarch64__) || defined(__arch64__)
|
||||
(u32)XEMACPS_DMACR_ADDR_WIDTH_64 |
|
||||
#endif
|
||||
(u32)XEMACPS_DMACR_INCR16_AHB_BURST));
|
||||
}
|
||||
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_TXSR_OFFSET, XEMACPS_SR_ALL_MASK);
|
||||
|
||||
XEmacPs_SetQueuePtr(InstancePtr, 0, 0x00U, (u16)XEMACPS_SEND);
|
||||
if (InstancePtr->Version > 2)
|
||||
XEmacPs_SetQueuePtr(InstancePtr, 0, 0x01U, (u16)XEMACPS_SEND);
|
||||
XEmacPs_SetQueuePtr(InstancePtr, 0, 0x00U, (u16)XEMACPS_RECV);
|
||||
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_RXSR_OFFSET, XEMACPS_SR_ALL_MASK);
|
||||
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress, XEMACPS_IDR_OFFSET,
|
||||
XEMACPS_IXR_ALL_MASK);
|
||||
|
||||
Reg = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_ISR_OFFSET);
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress, XEMACPS_ISR_OFFSET,
|
||||
Reg);
|
||||
|
||||
XEmacPs_ClearHash(InstancePtr);
|
||||
|
||||
for (i = 1U; i < 5U; i++) {
|
||||
(void)XEmacPs_SetMacAddress(InstancePtr, EmacPs_zero_MAC, i);
|
||||
(void)XEmacPs_SetTypeIdCheck(InstancePtr, 0x00000000U, i);
|
||||
}
|
||||
|
||||
/* clear all counters */
|
||||
for (i = 0U; i < (u8)((XEMACPS_LAST_OFFSET - XEMACPS_OCTTXL_OFFSET) / 4U);
|
||||
i++) {
|
||||
(void)XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_OCTTXL_OFFSET + (u32)(((u32)i) * ((u32)4)));
|
||||
}
|
||||
|
||||
/* Disable the receiver */
|
||||
Reg = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_NWCTRL_OFFSET);
|
||||
Reg &= (u32)(~XEMACPS_NWCTRL_RXEN_MASK);
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_NWCTRL_OFFSET, Reg);
|
||||
|
||||
/* Sync default options with hardware but leave receiver and
|
||||
* transmitter disabled. They get enabled with XEmacPs_Start() if
|
||||
* XEMACPS_TRANSMITTER_ENABLE_OPTION and
|
||||
* XEMACPS_RECEIVER_ENABLE_OPTION are set.
|
||||
*/
|
||||
(void)XEmacPs_SetOptions(InstancePtr, InstancePtr->Options &
|
||||
~((u32)XEMACPS_TRANSMITTER_ENABLE_OPTION |
|
||||
(u32)XEMACPS_RECEIVER_ENABLE_OPTION));
|
||||
|
||||
(void)XEmacPs_ClearOptions(InstancePtr, ~InstancePtr->Options);
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
/**
|
||||
* This is a stub for the asynchronous callbacks. The stub is here in case the
|
||||
* upper layer forgot to set the handler(s). On initialization, all handlers are
|
||||
* set to this callback. It is considered an error for this handler to be
|
||||
* invoked.
|
||||
*
|
||||
******************************************************************************/
|
||||
void XEmacPs_StubHandler(void)
|
||||
{
|
||||
Xil_AssertVoidAlways();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* This function sets the start address of the transmit/receive buffer queue.
|
||||
*
|
||||
* @param InstancePtr is a pointer to the instance to be worked on.
|
||||
* @param QPtr is the address of the Queue to be written
|
||||
* @param QueueNum is the Buffer Queue Index
|
||||
* @param Direction indicates Transmit/Receive
|
||||
*
|
||||
* @note
|
||||
* The buffer queue addresses has to be set before starting the transfer, so
|
||||
* this function has to be called in prior to XEmacPs_Start()
|
||||
*
|
||||
******************************************************************************/
|
||||
void XEmacPs_SetQueuePtr(XEmacPs *InstancePtr, UINTPTR QPtr, u8 QueueNum,
|
||||
u16 Direction)
|
||||
{
|
||||
/* Assert bad arguments and conditions */
|
||||
Xil_AssertVoid(InstancePtr != NULL);
|
||||
Xil_AssertVoid(InstancePtr->IsReady == (u32)XIL_COMPONENT_IS_READY);
|
||||
|
||||
/* If already started, then there is nothing to do */
|
||||
if (InstancePtr->IsStarted == (u32)XIL_COMPONENT_IS_STARTED) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (QueueNum == 0x00U) {
|
||||
if (Direction == XEMACPS_SEND) {
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_TXQBASE_OFFSET,
|
||||
(QPtr & ULONG64_LO_MASK));
|
||||
} else {
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_RXQBASE_OFFSET,
|
||||
(QPtr & ULONG64_LO_MASK));
|
||||
}
|
||||
}
|
||||
else {
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_TXQ1BASE_OFFSET,
|
||||
(QPtr & ULONG64_LO_MASK));
|
||||
}
|
||||
#ifdef __aarch64__
|
||||
if (Direction == XEMACPS_SEND) {
|
||||
/* Set the MSB of TX Queue start address */
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_MSBBUF_TXQBASE_OFFSET,
|
||||
(u32)((QPtr & ULONG64_HI_MASK) >> 32U));
|
||||
} else {
|
||||
/* Set the MSB of RX Queue start address */
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_MSBBUF_RXQBASE_OFFSET,
|
||||
(u32)((QPtr & ULONG64_HI_MASK) >> 32U));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/** @} */
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,215 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2010 - 2020 Xilinx, Inc. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
******************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* @file xemacps_bdring.h
|
||||
* @addtogroup emacps_v3_11
|
||||
* @{
|
||||
*
|
||||
* The Xiline EmacPs Buffer Descriptor ring driver. This is part of EmacPs
|
||||
* DMA functionalities.
|
||||
*
|
||||
* <pre>
|
||||
* MODIFICATION HISTORY:
|
||||
*
|
||||
* Ver Who Date Changes
|
||||
* ----- ---- -------- -------------------------------------------------------
|
||||
* 1.00a wsy 01/10/10 First release
|
||||
* 2.1 srt 07/15/14 Add support for Zynq Ultrascale Mp architecture.
|
||||
* 3.0 kvn 02/13/15 Modified code for MISRA-C:2012 compliance.
|
||||
* 3.6 rb 09/08/17 HwCnt variable (in XEmacPs_BdRing structure) is
|
||||
* changed to volatile.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef XEMACPS_BDRING_H /* prevent curcular inclusions */
|
||||
#define XEMACPS_BDRING_H /* by using protection macros */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**************************** Type Definitions *******************************/
|
||||
|
||||
/** This is an internal structure used to maintain the DMA list */
|
||||
typedef struct {
|
||||
UINTPTR PhysBaseAddr;/**< Physical address of 1st BD in list */
|
||||
UINTPTR BaseBdAddr; /**< Virtual address of 1st BD in list */
|
||||
UINTPTR HighBdAddr; /**< Virtual address of last BD in the list */
|
||||
u32 Length; /**< Total size of ring in bytes */
|
||||
u32 RunState; /**< Flag to indicate DMA is started */
|
||||
u32 Separation; /**< Number of bytes between the starting address
|
||||
of adjacent BDs */
|
||||
XEmacPs_Bd *FreeHead;
|
||||
/**< First BD in the free group */
|
||||
XEmacPs_Bd *PreHead;/**< First BD in the pre-work group */
|
||||
XEmacPs_Bd *HwHead; /**< First BD in the work group */
|
||||
XEmacPs_Bd *HwTail; /**< Last BD in the work group */
|
||||
XEmacPs_Bd *PostHead;
|
||||
/**< First BD in the post-work group */
|
||||
XEmacPs_Bd *BdaRestart;
|
||||
/**< BDA to load when channel is started */
|
||||
|
||||
volatile u32 HwCnt; /**< Number of BDs in work group */
|
||||
u32 PreCnt; /**< Number of BDs in pre-work group */
|
||||
u32 FreeCnt; /**< Number of allocatable BDs in the free group */
|
||||
u32 PostCnt; /**< Number of BDs in post-work group */
|
||||
u32 AllCnt; /**< Total Number of BDs for channel */
|
||||
} XEmacPs_BdRing;
|
||||
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* Use this macro at initialization time to determine how many BDs will fit
|
||||
* in a BD list within the given memory constraints.
|
||||
*
|
||||
* The results of this macro can be provided to XEmacPs_BdRingCreate().
|
||||
*
|
||||
* @param Alignment specifies what byte alignment the BDs must fall on and
|
||||
* must be a power of 2 to get an accurate calculation (32, 64, 128,...)
|
||||
* @param Bytes is the number of bytes to be used to store BDs.
|
||||
*
|
||||
* @return Number of BDs that can fit in the given memory area
|
||||
*
|
||||
* @note
|
||||
* C-style signature:
|
||||
* u32 XEmacPs_BdRingCntCalc(u32 Alignment, u32 Bytes)
|
||||
*
|
||||
******************************************************************************/
|
||||
#define XEmacPs_BdRingCntCalc(Alignment, Bytes) \
|
||||
(u32)((Bytes) / (sizeof(XEmacPs_Bd)))
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* Use this macro at initialization time to determine how many bytes of memory
|
||||
* is required to contain a given number of BDs at a given alignment.
|
||||
*
|
||||
* @param Alignment specifies what byte alignment the BDs must fall on. This
|
||||
* parameter must be a power of 2 to get an accurate calculation (32, 64,
|
||||
* 128,...)
|
||||
* @param NumBd is the number of BDs to calculate memory size requirements for
|
||||
*
|
||||
* @return The number of bytes of memory required to create a BD list with the
|
||||
* given memory constraints.
|
||||
*
|
||||
* @note
|
||||
* C-style signature:
|
||||
* u32 XEmacPs_BdRingMemCalc(u32 Alignment, u32 NumBd)
|
||||
*
|
||||
******************************************************************************/
|
||||
#define XEmacPs_BdRingMemCalc(Alignment, NumBd) \
|
||||
(u32)(sizeof(XEmacPs_Bd) * (NumBd))
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
* Return the total number of BDs allocated by this channel with
|
||||
* XEmacPs_BdRingCreate().
|
||||
*
|
||||
* @param RingPtr is the DMA channel to operate on.
|
||||
*
|
||||
* @return The total number of BDs allocated for this channel.
|
||||
*
|
||||
* @note
|
||||
* C-style signature:
|
||||
* u32 XEmacPs_BdRingGetCnt(XEmacPs_BdRing* RingPtr)
|
||||
*
|
||||
*****************************************************************************/
|
||||
#define XEmacPs_BdRingGetCnt(RingPtr) ((RingPtr)->AllCnt)
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
* Return the number of BDs allocatable with XEmacPs_BdRingAlloc() for pre-
|
||||
* processing.
|
||||
*
|
||||
* @param RingPtr is the DMA channel to operate on.
|
||||
*
|
||||
* @return The number of BDs currently allocatable.
|
||||
*
|
||||
* @note
|
||||
* C-style signature:
|
||||
* u32 XEmacPs_BdRingGetFreeCnt(XEmacPs_BdRing* RingPtr)
|
||||
*
|
||||
*****************************************************************************/
|
||||
#define XEmacPs_BdRingGetFreeCnt(RingPtr) ((RingPtr)->FreeCnt)
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
* Return the next BD from BdPtr in a list.
|
||||
*
|
||||
* @param RingPtr is the DMA channel to operate on.
|
||||
* @param BdPtr is the BD to operate on.
|
||||
*
|
||||
* @return The next BD in the list relative to the BdPtr parameter.
|
||||
*
|
||||
* @note
|
||||
* C-style signature:
|
||||
* XEmacPs_Bd *XEmacPs_BdRingNext(XEmacPs_BdRing* RingPtr,
|
||||
* XEmacPs_Bd *BdPtr)
|
||||
*
|
||||
*****************************************************************************/
|
||||
#define XEmacPs_BdRingNext(RingPtr, BdPtr) \
|
||||
(((UINTPTR)((void *)(BdPtr)) >= (RingPtr)->HighBdAddr) ? \
|
||||
(XEmacPs_Bd*)((void*)(RingPtr)->BaseBdAddr) : \
|
||||
(XEmacPs_Bd*)((UINTPTR)((void *)(BdPtr)) + (RingPtr)->Separation))
|
||||
|
||||
/****************************************************************************/
|
||||
/**
|
||||
* Return the previous BD from BdPtr in the list.
|
||||
*
|
||||
* @param RingPtr is the DMA channel to operate on.
|
||||
* @param BdPtr is the BD to operate on
|
||||
*
|
||||
* @return The previous BD in the list relative to the BdPtr parameter.
|
||||
*
|
||||
* @note
|
||||
* C-style signature:
|
||||
* XEmacPs_Bd *XEmacPs_BdRingPrev(XEmacPs_BdRing* RingPtr,
|
||||
* XEmacPs_Bd *BdPtr)
|
||||
*
|
||||
*****************************************************************************/
|
||||
#define XEmacPs_BdRingPrev(RingPtr, BdPtr) \
|
||||
(((UINTPTR)(BdPtr) <= (RingPtr)->BaseBdAddr) ? \
|
||||
(XEmacPs_Bd*)(RingPtr)->HighBdAddr : \
|
||||
(XEmacPs_Bd*)((UINTPTR)(BdPtr) - (RingPtr)->Separation))
|
||||
|
||||
/************************** Function Prototypes ******************************/
|
||||
|
||||
/*
|
||||
* Scatter gather DMA related functions in xemacps_bdring.c
|
||||
*/
|
||||
LONG XEmacPs_BdRingCreate(XEmacPs_BdRing * RingPtr, UINTPTR PhysAddr,
|
||||
UINTPTR VirtAddr, u32 Alignment, u32 BdCount);
|
||||
LONG XEmacPs_BdRingClone(XEmacPs_BdRing * RingPtr, XEmacPs_Bd * SrcBdPtr,
|
||||
u8 Direction);
|
||||
LONG XEmacPs_BdRingAlloc(XEmacPs_BdRing * RingPtr, u32 NumBd,
|
||||
XEmacPs_Bd ** BdSetPtr);
|
||||
LONG XEmacPs_BdRingUnAlloc(XEmacPs_BdRing * RingPtr, u32 NumBd,
|
||||
XEmacPs_Bd * BdSetPtr);
|
||||
LONG XEmacPs_BdRingToHw(XEmacPs_BdRing * RingPtr, u32 NumBd,
|
||||
XEmacPs_Bd * BdSetPtr);
|
||||
LONG XEmacPs_BdRingFree(XEmacPs_BdRing * RingPtr, u32 NumBd,
|
||||
XEmacPs_Bd * BdSetPtr);
|
||||
u32 XEmacPs_BdRingFromHwTx(XEmacPs_BdRing * RingPtr, u32 BdLimit,
|
||||
XEmacPs_Bd ** BdSetPtr);
|
||||
u32 XEmacPs_BdRingFromHwRx(XEmacPs_BdRing * RingPtr, u32 BdLimit,
|
||||
XEmacPs_Bd ** BdSetPtr);
|
||||
LONG XEmacPs_BdRingCheck(XEmacPs_BdRing * RingPtr, u8 Direction);
|
||||
|
||||
void XEmacPs_BdRingPtrReset(XEmacPs_BdRing * RingPtr, void *virtaddrloc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* end of protection macros */
|
||||
/** @} */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,32 @@
|
||||
|
||||
/*******************************************************************
|
||||
*
|
||||
* CAUTION: This file is automatically generated by HSI.
|
||||
* Version: 2020.1
|
||||
* DO NOT EDIT.
|
||||
*
|
||||
* Copyright (C) 2010-2021 Xilinx, Inc. All Rights Reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
|
||||
*
|
||||
* Description: Driver configuration
|
||||
*
|
||||
*******************************************************************/
|
||||
|
||||
#include "xparameters.h"
|
||||
#include "xemacps.h"
|
||||
|
||||
/*
|
||||
* The configuration table for devices
|
||||
*/
|
||||
|
||||
XEmacPs_Config XEmacPs_ConfigTable[XPAR_XEMACPS_NUM_INSTANCES] =
|
||||
{
|
||||
{
|
||||
XPAR_PSU_ETHERNET_3_DEVICE_ID,
|
||||
XPAR_PSU_ETHERNET_3_BASEADDR,
|
||||
XPAR_PSU_ETHERNET_3_IS_CACHE_COHERENT
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2010 - 2020 Xilinx, Inc. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
******************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* @file xemacps_hw.c
|
||||
* @addtogroup emacps_v3_11
|
||||
* @{
|
||||
*
|
||||
* This file contains the implementation of the ethernet interface reset sequence
|
||||
*
|
||||
* <pre>
|
||||
* MODIFICATION HISTORY:
|
||||
*
|
||||
* Ver Who Date Changes
|
||||
* ----- ---- -------- -------------------------------------------------------
|
||||
* 1.05a kpc 28/06/13 First release
|
||||
* 3.00 kvn 02/13/15 Modified code for MISRA-C:2012 compliance.
|
||||
* </pre>
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/***************************** Include Files *********************************/
|
||||
|
||||
#include "xemacps_hw.h"
|
||||
#include "xparameters.h"
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
|
||||
|
||||
/**************************** Type Definitions *******************************/
|
||||
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
|
||||
|
||||
/************************** Function Prototypes ******************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* This function perform the reset sequence to the given emacps interface by
|
||||
* configuring the appropriate control bits in the emacps specific registers.
|
||||
* the emacps reset sequence involves the following steps
|
||||
* Disable all the interuupts
|
||||
* Clear the status registers
|
||||
* Disable Rx and Tx engines
|
||||
* Update the Tx and Rx descriptor queue registers with reset values
|
||||
* Update the other relevant control registers with reset value
|
||||
*
|
||||
* @param BaseAddr of the interface
|
||||
*
|
||||
* @return N/A
|
||||
*
|
||||
* @note
|
||||
* This function will not modify the slcr registers that are relevant for
|
||||
* emacps controller
|
||||
******************************************************************************/
|
||||
void XEmacPs_ResetHw(u32 BaseAddr)
|
||||
{
|
||||
u32 RegVal;
|
||||
|
||||
/* Disable the interrupts */
|
||||
XEmacPs_WriteReg(BaseAddr,XEMACPS_IDR_OFFSET,0x0U);
|
||||
|
||||
/* Stop transmission,disable loopback and Stop tx and Rx engines */
|
||||
RegVal = XEmacPs_ReadReg(BaseAddr,XEMACPS_NWCTRL_OFFSET);
|
||||
RegVal &= ~((u32)XEMACPS_NWCTRL_TXEN_MASK|
|
||||
(u32)XEMACPS_NWCTRL_RXEN_MASK|
|
||||
(u32)XEMACPS_NWCTRL_HALTTX_MASK|
|
||||
(u32)XEMACPS_NWCTRL_LOOPEN_MASK);
|
||||
/* Clear the statistic registers, flush the packets in DPRAM*/
|
||||
RegVal |= (XEMACPS_NWCTRL_STATCLR_MASK|
|
||||
XEMACPS_NWCTRL_FLUSH_DPRAM_MASK);
|
||||
XEmacPs_WriteReg(BaseAddr,XEMACPS_NWCTRL_OFFSET,RegVal);
|
||||
/* Clear the interrupt status */
|
||||
XEmacPs_WriteReg(BaseAddr,XEMACPS_ISR_OFFSET,XEMACPS_IXR_ALL_MASK);
|
||||
/* Clear the tx status */
|
||||
XEmacPs_WriteReg(BaseAddr,XEMACPS_TXSR_OFFSET,(XEMACPS_TXSR_ERROR_MASK|
|
||||
(u32)XEMACPS_TXSR_TXCOMPL_MASK|
|
||||
(u32)XEMACPS_TXSR_TXGO_MASK));
|
||||
/* Clear the rx status */
|
||||
XEmacPs_WriteReg(BaseAddr,XEMACPS_RXSR_OFFSET,
|
||||
XEMACPS_RXSR_FRAMERX_MASK);
|
||||
/* Clear the tx base address */
|
||||
XEmacPs_WriteReg(BaseAddr,XEMACPS_TXQBASE_OFFSET,0x0U);
|
||||
/* Clear the rx base address */
|
||||
XEmacPs_WriteReg(BaseAddr,XEMACPS_RXQBASE_OFFSET,0x0U);
|
||||
/* Update the network config register with reset value */
|
||||
XEmacPs_WriteReg(BaseAddr,XEMACPS_NWCFG_OFFSET,XEMACPS_NWCFG_RESET_MASK);
|
||||
/* Update the hash address registers with reset value */
|
||||
XEmacPs_WriteReg(BaseAddr,XEMACPS_HASHL_OFFSET,0x0U);
|
||||
XEmacPs_WriteReg(BaseAddr,XEMACPS_HASHH_OFFSET,0x0U);
|
||||
}
|
||||
/** @} */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,242 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2010 - 2020 Xilinx, Inc. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
******************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* @file xemacps_intr.c
|
||||
* @addtogroup emacps_v3_11
|
||||
* @{
|
||||
*
|
||||
* Functions in this file implement general purpose interrupt processing related
|
||||
* functionality. See xemacps.h for a detailed description of the driver.
|
||||
*
|
||||
* <pre>
|
||||
* MODIFICATION HISTORY:
|
||||
*
|
||||
* Ver Who Date Changes
|
||||
* ----- ---- -------- -------------------------------------------------------
|
||||
* 1.00a wsy 01/10/10 First release
|
||||
* 1.03a asa 01/24/13 Fix for CR #692702 which updates error handling for
|
||||
* Rx errors. Under heavy Rx traffic, there will be a large
|
||||
* number of errors related to receive buffer not available.
|
||||
* Because of a HW bug (SI #692601), under such heavy errors,
|
||||
* the Rx data path can become unresponsive. To reduce the
|
||||
* probabilities for hitting this HW bug, the SW writes to
|
||||
* bit 18 to flush a packet from Rx DPRAM immediately. The
|
||||
* changes for it are done in the function
|
||||
* XEmacPs_IntrHandler.
|
||||
* 2.1 srt 07/15/14 Add support for Zynq Ultrascale Mp GEM specification
|
||||
* and 64-bit changes.
|
||||
* 3.0 kvn 02/13/15 Modified code for MISRA-C:2012 compliance.
|
||||
* 3.1 hk 07/27/15 Do not call error handler with '0' error code when
|
||||
* there is no error. CR# 869403
|
||||
* </pre>
|
||||
******************************************************************************/
|
||||
|
||||
/***************************** Include Files *********************************/
|
||||
|
||||
#include "xemacps.h"
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
|
||||
|
||||
/**************************** Type Definitions *******************************/
|
||||
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
|
||||
|
||||
/************************** Function Prototypes ******************************/
|
||||
|
||||
|
||||
/************************** Variable Definitions *****************************/
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* Install an asynchronous handler function for the given HandlerType:
|
||||
*
|
||||
* @param InstancePtr is a pointer to the instance to be worked on.
|
||||
* @param HandlerType indicates what interrupt handler type is.
|
||||
* XEMACPS_HANDLER_DMASEND, XEMACPS_HANDLER_DMARECV and
|
||||
* XEMACPS_HANDLER_ERROR.
|
||||
* @param FuncPointer is the pointer to the callback function
|
||||
* @param CallBackRef is the upper layer callback reference passed back when
|
||||
* when the callback function is invoked.
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* None.
|
||||
*
|
||||
* @note
|
||||
* There is no assert on the CallBackRef since the driver doesn't know what
|
||||
* it is.
|
||||
*
|
||||
*****************************************************************************/
|
||||
LONG XEmacPs_SetHandler(XEmacPs *InstancePtr, u32 HandlerType,
|
||||
void *FuncPointer, void *CallBackRef)
|
||||
{
|
||||
LONG Status;
|
||||
Xil_AssertNonvoid(InstancePtr != NULL);
|
||||
Xil_AssertNonvoid(FuncPointer != NULL);
|
||||
Xil_AssertNonvoid(InstancePtr->IsReady == (u32)XIL_COMPONENT_IS_READY);
|
||||
|
||||
switch (HandlerType) {
|
||||
case XEMACPS_HANDLER_DMASEND:
|
||||
Status = (LONG)(XST_SUCCESS);
|
||||
InstancePtr->SendHandler = ((XEmacPs_Handler)(void *)FuncPointer);
|
||||
InstancePtr->SendRef = CallBackRef;
|
||||
break;
|
||||
case XEMACPS_HANDLER_DMARECV:
|
||||
Status = (LONG)(XST_SUCCESS);
|
||||
InstancePtr->RecvHandler = ((XEmacPs_Handler)(void *)FuncPointer);
|
||||
InstancePtr->RecvRef = CallBackRef;
|
||||
break;
|
||||
case XEMACPS_HANDLER_ERROR:
|
||||
Status = (LONG)(XST_SUCCESS);
|
||||
InstancePtr->ErrorHandler = ((XEmacPs_ErrHandler)(void *)FuncPointer);
|
||||
InstancePtr->ErrorRef = CallBackRef;
|
||||
break;
|
||||
default:
|
||||
Status = (LONG)(XST_INVALID_PARAM);
|
||||
break;
|
||||
}
|
||||
return Status;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* Master interrupt handler for EMAC driver. This routine will query the
|
||||
* status of the device, bump statistics, and invoke user callbacks.
|
||||
*
|
||||
* This routine must be connected to an interrupt controller using OS/BSP
|
||||
* specific methods.
|
||||
*
|
||||
* @param XEmacPsPtr is a pointer to the XEMACPS instance that has caused the
|
||||
* interrupt.
|
||||
*
|
||||
******************************************************************************/
|
||||
void XEmacPs_IntrHandler(void *XEmacPsPtr)
|
||||
{
|
||||
u32 RegISR;
|
||||
u32 RegSR;
|
||||
u32 RegCtrl;
|
||||
u32 RegQ1ISR = 0U;
|
||||
XEmacPs *InstancePtr = (XEmacPs *) XEmacPsPtr;
|
||||
|
||||
Xil_AssertVoid(InstancePtr != NULL);
|
||||
Xil_AssertVoid(InstancePtr->IsReady == (u32)XIL_COMPONENT_IS_READY);
|
||||
|
||||
/* This ISR will try to handle as many interrupts as it can in a single
|
||||
* call. However, in most of the places where the user's error handler
|
||||
* is called, this ISR exits because it is expected that the user will
|
||||
* reset the device in nearly all instances.
|
||||
*/
|
||||
RegISR = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_ISR_OFFSET);
|
||||
|
||||
/* Read Transmit Q1 ISR */
|
||||
|
||||
if (InstancePtr->Version > 2)
|
||||
RegQ1ISR = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_INTQ1_STS_OFFSET);
|
||||
|
||||
/* Clear the interrupt status register */
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress, XEMACPS_ISR_OFFSET,
|
||||
RegISR);
|
||||
|
||||
/* Receive complete interrupt */
|
||||
if ((RegISR & XEMACPS_IXR_FRAMERX_MASK) != 0x00000000U) {
|
||||
/* Clear RX status register RX complete indication but preserve
|
||||
* error bits if there is any */
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_RXSR_OFFSET,
|
||||
((u32)XEMACPS_RXSR_FRAMERX_MASK |
|
||||
(u32)XEMACPS_RXSR_BUFFNA_MASK));
|
||||
InstancePtr->RecvHandler(InstancePtr->RecvRef);
|
||||
}
|
||||
|
||||
/* Transmit Q1 complete interrupt */
|
||||
if ((InstancePtr->Version > 2) &&
|
||||
((RegQ1ISR & XEMACPS_INTQ1SR_TXCOMPL_MASK) != 0x00000000U)) {
|
||||
/* Clear TX status register TX complete indication but preserve
|
||||
* error bits if there is any */
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_INTQ1_STS_OFFSET,
|
||||
XEMACPS_INTQ1SR_TXCOMPL_MASK);
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_TXSR_OFFSET,
|
||||
((u32)XEMACPS_TXSR_TXCOMPL_MASK |
|
||||
(u32)XEMACPS_TXSR_USEDREAD_MASK));
|
||||
InstancePtr->SendHandler(InstancePtr->SendRef);
|
||||
}
|
||||
|
||||
/* Transmit complete interrupt */
|
||||
if ((RegISR & XEMACPS_IXR_TXCOMPL_MASK) != 0x00000000U) {
|
||||
/* Clear TX status register TX complete indication but preserve
|
||||
* error bits if there is any */
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_TXSR_OFFSET,
|
||||
((u32)XEMACPS_TXSR_TXCOMPL_MASK |
|
||||
(u32)XEMACPS_TXSR_USEDREAD_MASK));
|
||||
InstancePtr->SendHandler(InstancePtr->SendRef);
|
||||
}
|
||||
|
||||
/* Receive error conditions interrupt */
|
||||
if ((RegISR & XEMACPS_IXR_RX_ERR_MASK) != 0x00000000U) {
|
||||
/* Clear RX status register */
|
||||
RegSR = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_RXSR_OFFSET);
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_RXSR_OFFSET, RegSR);
|
||||
|
||||
/* Fix for CR # 692702. Write to bit 18 of net_ctrl
|
||||
* register to flush a packet out of Rx SRAM upon
|
||||
* an error for receive buffer not available. */
|
||||
if ((RegISR & XEMACPS_IXR_RXUSED_MASK) != 0x00000000U) {
|
||||
RegCtrl =
|
||||
XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_NWCTRL_OFFSET);
|
||||
RegCtrl |= (u32)XEMACPS_NWCTRL_FLUSH_DPRAM_MASK;
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_NWCTRL_OFFSET, RegCtrl);
|
||||
}
|
||||
|
||||
if(RegSR != 0) {
|
||||
InstancePtr->ErrorHandler(InstancePtr->ErrorRef,
|
||||
XEMACPS_RECV, RegSR);
|
||||
}
|
||||
}
|
||||
|
||||
/* When XEMACPS_IXR_TXCOMPL_MASK is flagged, XEMACPS_IXR_TXUSED_MASK
|
||||
* will be asserted the same time.
|
||||
* Have to distinguish this bit to handle the real error condition.
|
||||
*/
|
||||
/* Transmit Q1 error conditions interrupt */
|
||||
if ((InstancePtr->Version > 2) &&
|
||||
((RegQ1ISR & XEMACPS_INTQ1SR_TXERR_MASK) != 0x00000000U) &&
|
||||
((RegQ1ISR & XEMACPS_INTQ1SR_TXCOMPL_MASK) != 0x00000000U)) {
|
||||
/* Clear Interrupt Q1 status register */
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_INTQ1_STS_OFFSET, RegQ1ISR);
|
||||
InstancePtr->ErrorHandler(InstancePtr->ErrorRef, XEMACPS_SEND,
|
||||
RegQ1ISR);
|
||||
}
|
||||
|
||||
/* Transmit error conditions interrupt */
|
||||
if (((RegISR & XEMACPS_IXR_TX_ERR_MASK) != 0x00000000U) &&
|
||||
(!(RegISR & XEMACPS_IXR_TXCOMPL_MASK) != 0x00000000U)) {
|
||||
/* Clear TX status register */
|
||||
RegSR = XEmacPs_ReadReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_TXSR_OFFSET);
|
||||
XEmacPs_WriteReg(InstancePtr->Config.BaseAddress,
|
||||
XEMACPS_TXSR_OFFSET, RegSR);
|
||||
InstancePtr->ErrorHandler(InstancePtr->ErrorRef, XEMACPS_SEND,
|
||||
RegSR);
|
||||
}
|
||||
|
||||
}
|
||||
/** @} */
|
||||
@@ -0,0 +1,71 @@
|
||||
/******************************************************************************
|
||||
* Copyright (C) 2010 - 2020 Xilinx, Inc. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
******************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
*
|
||||
* @file xemacps_sinit.c
|
||||
* @addtogroup emacps_v3_11
|
||||
* @{
|
||||
*
|
||||
* This file contains lookup method by device ID when success, it returns
|
||||
* pointer to config table to be used to initialize the device.
|
||||
*
|
||||
* <pre>
|
||||
* MODIFICATION HISTORY:
|
||||
*
|
||||
* Ver Who Date Changes
|
||||
* ----- ---- -------- -------------------------------------------------------
|
||||
* 1.00a wsy 01/10/10 New
|
||||
* 3.00 kvn 02/13/15 Modified code for MISRA-C:2012 compliance.
|
||||
* </pre>
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/***************************** Include Files *********************************/
|
||||
|
||||
#include "xemacps.h"
|
||||
#include "xparameters.h"
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
|
||||
|
||||
/**************************** Type Definitions *******************************/
|
||||
|
||||
/*************************** Variable Definitions *****************************/
|
||||
extern XEmacPs_Config XEmacPs_ConfigTable[XPAR_XEMACPS_NUM_INSTANCES];
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
|
||||
|
||||
/************************** Function Prototypes ******************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* Lookup the device configuration based on the unique device ID. The table
|
||||
* contains the configuration info for each device in the system.
|
||||
*
|
||||
* @param DeviceId is the unique device ID of the device being looked up.
|
||||
*
|
||||
* @return
|
||||
* A pointer to the configuration table entry corresponding to the given
|
||||
* device ID, or NULL if no match is found.
|
||||
*
|
||||
******************************************************************************/
|
||||
XEmacPs_Config *XEmacPs_LookupConfig(u16 DeviceId)
|
||||
{
|
||||
XEmacPs_Config *CfgPtr = NULL;
|
||||
u32 i;
|
||||
|
||||
for (i = 0U; i < (u32)XPAR_XEMACPS_NUM_INSTANCES; i++) {
|
||||
if (XEmacPs_ConfigTable[i].DeviceId == DeviceId) {
|
||||
CfgPtr = &XEmacPs_ConfigTable[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (XEmacPs_Config *)(CfgPtr);
|
||||
}
|
||||
/** @} */
|
||||
@@ -21,7 +21,7 @@ static inline void usleep(unsigned long useconds)
|
||||
|
||||
static inline void sleep(unsigned int seconds)
|
||||
{
|
||||
rt_thread_delay(seconds);
|
||||
rt_thread_delay(seconds*RT_TICK_PER_SECOND);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import rtconfig
|
||||
from building import *
|
||||
|
||||
# get current directory
|
||||
cwd = GetCurrentDir()
|
||||
CPPPATH = [cwd]
|
||||
|
||||
# The set of source files associated with this SConscript file.
|
||||
|
||||
src = Glob('*.c')
|
||||
path = cwd
|
||||
|
||||
group = DefineGroup('ZYNQMP_HAL', src, depend = [''], CPPPATH = CPPPATH)
|
||||
|
||||
Return('group')
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (C) 2007 - 2019 Xilinx, Inc.
|
||||
* Copyright (C) 2021 WangHuachen.
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __XADAPTER_H_
|
||||
#define __XADAPTER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "lwipopts.h"
|
||||
|
||||
#if !NO_SYS
|
||||
#ifdef OS_IS_XILKERNEL
|
||||
#include "xmk.h"
|
||||
#endif
|
||||
#include "lwip/sys.h"
|
||||
#endif
|
||||
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/ip.h"
|
||||
|
||||
#include "netif/xtopology.h"
|
||||
#include <netif/ethernetif.h>
|
||||
|
||||
struct xemac_s {
|
||||
enum xemac_types type;
|
||||
int topology_index;
|
||||
void *state;
|
||||
#if 0
|
||||
sys_sem_t sem_rx_data_available;
|
||||
#else
|
||||
struct eth_device *rt_eth_device;
|
||||
#endif
|
||||
#if defined(OS_IS_FREERTOS) && defined(__arm__) && !defined(ARMR5)
|
||||
TimerHandle_t xTimer;
|
||||
#endif
|
||||
};
|
||||
|
||||
enum ethernet_link_status {
|
||||
ETH_LINK_UNDEFINED = 0,
|
||||
ETH_LINK_UP,
|
||||
ETH_LINK_DOWN,
|
||||
ETH_LINK_NEGOTIATING
|
||||
};
|
||||
|
||||
void eth_link_detect(struct netif *netif);
|
||||
void lwip_raw_init();
|
||||
int xemacif_input(struct netif *netif);
|
||||
void xemacif_input_thread(struct netif *netif);
|
||||
struct netif * xemac_add(struct netif *netif,
|
||||
ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw,
|
||||
unsigned char *mac_ethernet_address,
|
||||
unsigned mac_baseaddr);
|
||||
#if defined (__arm__) || defined (__aarch64__)
|
||||
void xemacpsif_resetrx_on_no_rxdata(struct netif *netif);
|
||||
#endif
|
||||
|
||||
/* global lwip debug variable used for debugging */
|
||||
extern int lwip_runtime_debug;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Copyright (C) 2010 - 2019 Xilinx, Inc.
|
||||
* Copyright (C) 2021 WangHuachen.
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __NETIF_XEMACPSIF_H__
|
||||
#define __NETIF_XEMACPSIF_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "xlwipconfig.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "netif/etharp.h"
|
||||
#include "lwip/sys.h"
|
||||
#include "netif/xadapter.h"
|
||||
|
||||
#include "xstatus.h"
|
||||
#include "sleep.h"
|
||||
#include "xparameters.h"
|
||||
#include "xparameters_ps.h" /* defines XPAR values */
|
||||
#include "xil_types.h"
|
||||
#include "xil_assert.h"
|
||||
#include "xil_io.h"
|
||||
// #include "xil_exception.h"
|
||||
// #include "xpseudo_asm.h"
|
||||
#include "xpseudo_asm_gcc.h"
|
||||
#include "xil_cache.h"
|
||||
#include "xil_printf.h"
|
||||
// #include "xscugic.h"
|
||||
#include "xemacps.h" /* defines XEmacPs API */
|
||||
|
||||
#include "netif/xpqueue.h"
|
||||
#include "xlwipconfig.h"
|
||||
|
||||
#if EL1_NONSECURE
|
||||
#include "xil_smc.h"
|
||||
#endif
|
||||
|
||||
#define ZYNQ_EMACPS_0_BASEADDR 0xE000B000
|
||||
#define ZYNQ_EMACPS_1_BASEADDR 0xE000C000
|
||||
|
||||
#define ZYNQMP_EMACPS_0_BASEADDR 0xFF0B0000
|
||||
#define ZYNQMP_EMACPS_1_BASEADDR 0xFF0C0000
|
||||
#define ZYNQMP_EMACPS_2_BASEADDR 0xFF0D0000
|
||||
#define ZYNQMP_EMACPS_3_BASEADDR 0xFF0E0000
|
||||
|
||||
#define CRL_APB_GEM0_REF_CTRL 0xFF5E0050
|
||||
#define CRL_APB_GEM1_REF_CTRL 0xFF5E0054
|
||||
#define CRL_APB_GEM2_REF_CTRL 0xFF5E0058
|
||||
#define CRL_APB_GEM3_REF_CTRL 0xFF5E005C
|
||||
|
||||
#define CRL_APB_GEM_DIV0_MASK 0x00003F00
|
||||
#define CRL_APB_GEM_DIV0_SHIFT 8
|
||||
#define CRL_APB_GEM_DIV1_MASK 0x003F0000
|
||||
#define CRL_APB_GEM_DIV1_SHIFT 16
|
||||
|
||||
#define VERSAL_EMACPS_0_BASEADDR 0xFF0C0000
|
||||
#define VERSAL_EMACPS_1_BASEADDR 0xFF0D0000
|
||||
|
||||
#define VERSAL_CRL_GEM0_REF_CTRL 0xFF5E0118
|
||||
#define VERSAL_CRL_GEM1_REF_CTRL 0xFF5E011C
|
||||
|
||||
#define VERSAL_CRL_GEM_DIV_MASK 0x0003FF00
|
||||
#define VERSAL_CRL_APB_GEM_DIV_SHIFT 8
|
||||
|
||||
#if defined (ARMR5) || (__aarch64__) || (ARMA53_32) || (__MICROBLAZE__)
|
||||
#if defined (USE_JUMBO_FRAMES)
|
||||
#define ZYNQMP_USE_JUMBO
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define GEM_VERSION_ZYNQMP 7
|
||||
#define GEM_VERSION_VERSAL 0x107
|
||||
|
||||
#define MAX_FRAME_SIZE_JUMBO (XEMACPS_MTU_JUMBO + XEMACPS_HDR_SIZE + XEMACPS_TRL_SIZE)
|
||||
|
||||
void xemacpsif_setmac(u32_t index, u8_t *addr);
|
||||
u8_t* xemacpsif_getmac(u32_t index);
|
||||
err_t xemacpsif_init(struct netif *netif);
|
||||
s32_t xemacpsif_input(struct netif *netif);
|
||||
|
||||
/* xaxiemacif_hw.c */
|
||||
void xemacps_error_handler(XEmacPs * Temac);
|
||||
|
||||
/* structure within each netif, encapsulating all information required for
|
||||
* using a particular temac instance
|
||||
*/
|
||||
typedef struct {
|
||||
XEmacPs emacps;
|
||||
|
||||
/* queue to store overflow packets */
|
||||
pq_queue_t *recv_q;
|
||||
pq_queue_t *send_q;
|
||||
|
||||
/* pointers to memory holding buffer descriptors (used only with SDMA) */
|
||||
void *rx_bdspace;
|
||||
void *tx_bdspace;
|
||||
|
||||
unsigned int last_rx_frms_cntr;
|
||||
|
||||
} xemacpsif_s;
|
||||
|
||||
extern xemacpsif_s xemacpsif;
|
||||
|
||||
s32_t is_tx_space_available(xemacpsif_s *emac);
|
||||
|
||||
/* xemacpsif_dma.c */
|
||||
|
||||
void process_sent_bds(xemacpsif_s *xemacpsif, XEmacPs_BdRing *txring);
|
||||
u32_t phy_setup_emacps (XEmacPs *xemacpsp, u32_t phy_addr);
|
||||
void detect_phy(XEmacPs *xemacpsp);
|
||||
void emacps_send_handler(void *arg);
|
||||
XStatus emacps_sgsend(xemacpsif_s *xemacpsif, struct pbuf *p);
|
||||
void emacps_recv_handler(void *arg);
|
||||
void emacps_error_handler(void *arg,u8 Direction, u32 ErrorWord);
|
||||
void setup_rx_bds(xemacpsif_s *xemacpsif, XEmacPs_BdRing *rxring);
|
||||
void HandleTxErrors(struct xemac_s *xemac);
|
||||
void HandleEmacPsError(struct xemac_s *xemac);
|
||||
XEmacPs_Config *xemacps_lookup_config(unsigned mac_base);
|
||||
void init_emacps(xemacpsif_s *xemacps, struct netif *netif);
|
||||
void setup_isr (struct xemac_s *xemac);
|
||||
XStatus init_dma(struct xemac_s *xemac);
|
||||
void start_emacps (xemacpsif_s *xemacps);
|
||||
void free_txrx_pbufs(xemacpsif_s *xemacpsif);
|
||||
void free_onlytx_pbufs(xemacpsif_s *xemacpsif);
|
||||
void init_emacps_on_error (xemacpsif_s *xemacps, struct netif *netif);
|
||||
void clean_dma_txdescs(struct xemac_s *xemac);
|
||||
void resetrx_on_no_rxdata(xemacpsif_s *xemacpsif);
|
||||
void reset_dma(struct xemac_s *xemac);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __NETIF_XAXIEMACIF_H__ */
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2007 - 2019 Xilinx, Inc.
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __LWIP_PBUF_QUEUE_H_
|
||||
#define __LWIP_PBUF_QUEUE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define PQ_QUEUE_SIZE 4096
|
||||
|
||||
typedef struct {
|
||||
void *data[PQ_QUEUE_SIZE];
|
||||
int head, tail, len;
|
||||
} pq_queue_t;
|
||||
|
||||
pq_queue_t* pq_create_queue();
|
||||
int pq_enqueue(pq_queue_t *q, void *p);
|
||||
void* pq_dequeue(pq_queue_t *q);
|
||||
int pq_qlength(pq_queue_t *q);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) 2007 - 2019 Xilinx, Inc.
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __XTOPOLOGY_H_
|
||||
#define __XTOPOLOGY_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum xemac_types { xemac_type_unknown = -1, xemac_type_xps_emaclite, xemac_type_xps_ll_temac, xemac_type_axi_ethernet, xemac_type_emacps };
|
||||
|
||||
struct xtopology_t {
|
||||
unsigned emac_baseaddr;
|
||||
enum xemac_types emac_type;
|
||||
unsigned intc_baseaddr;
|
||||
unsigned intc_emac_intr; /* valid only for xemac_type_xps_emaclite */
|
||||
unsigned scugic_baseaddr; /* valid only for Zynq */
|
||||
unsigned scugic_emac_intr; /* valid only for GEM */
|
||||
};
|
||||
|
||||
extern int xtopology_n_emacs;
|
||||
extern struct xtopology_t xtopology[];
|
||||
|
||||
int xtopology_find_index(unsigned base);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,432 @@
|
||||
/*
|
||||
* Copyright (C) 2007 - 2019 Xilinx, Inc.
|
||||
* Copyright (C) 2021 WangHuachen.
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "lwipopts.h"
|
||||
#include "xlwipconfig.h"
|
||||
#include "xemac_ieee_reg.h"
|
||||
|
||||
#if !NO_SYS
|
||||
#ifdef OS_IS_XILKERNEL
|
||||
#include "xmk.h"
|
||||
#include "sys/process.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "lwip/mem.h"
|
||||
#include "lwip/stats.h"
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/ip.h"
|
||||
#include "lwip/tcp.h"
|
||||
#include "lwip/udp.h"
|
||||
#include "lwip/priv/tcp_priv.h"
|
||||
|
||||
#include "netif/etharp.h"
|
||||
#include "netif/xadapter.h"
|
||||
|
||||
#ifdef XLWIP_CONFIG_INCLUDE_EMACLITE
|
||||
#include "netif/xemacliteif.h"
|
||||
#endif
|
||||
|
||||
#ifdef XLWIP_CONFIG_INCLUDE_AXI_ETHERNET
|
||||
#include "netif/xaxiemacif.h"
|
||||
#endif
|
||||
|
||||
#ifdef XLWIP_CONFIG_INCLUDE_GEM
|
||||
#include "netif/xemacpsif.h"
|
||||
#endif
|
||||
|
||||
#if !NO_SYS
|
||||
#include "lwip/tcpip.h"
|
||||
#endif
|
||||
|
||||
#ifdef OS_IS_FREERTOS
|
||||
#define THREAD_STACKSIZE 256
|
||||
#define LINK_DETECT_THREAD_INTERVAL 1000 /* one second */
|
||||
|
||||
void link_detect_thread(void *p);
|
||||
#endif
|
||||
|
||||
/* global lwip debug variable used for debugging */
|
||||
int lwip_runtime_debug = 0;
|
||||
|
||||
enum ethernet_link_status eth_link_status = ETH_LINK_UNDEFINED;
|
||||
u32_t phyaddrforemac;
|
||||
|
||||
void
|
||||
lwip_raw_init()
|
||||
{
|
||||
ip_init(); /* Doesn't do much, it should be called to handle future changes. */
|
||||
#if LWIP_UDP
|
||||
udp_init(); /* Clears the UDP PCB list. */
|
||||
#endif
|
||||
#if LWIP_TCP
|
||||
tcp_init(); /* Clears the TCP PCB list and clears some internal TCP timers. */
|
||||
/* Note: you must call tcp_fasttmr() and tcp_slowtmr() at the */
|
||||
/* predefined regular intervals after this initialization. */
|
||||
#endif
|
||||
}
|
||||
|
||||
static enum xemac_types
|
||||
find_mac_type(unsigned base)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < xtopology_n_emacs; i++) {
|
||||
if (xtopology[i].emac_baseaddr == base)
|
||||
return xtopology[i].emac_type;
|
||||
}
|
||||
|
||||
return xemac_type_unknown;
|
||||
}
|
||||
|
||||
int
|
||||
xtopology_find_index(unsigned base)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < xtopology_n_emacs; i++) {
|
||||
if (xtopology[i].emac_baseaddr == base)
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* xemac_add: this is a wrapper around lwIP's netif_add function.
|
||||
* The objective is to provide portability between the different Xilinx MAC's
|
||||
* This function can be used to add both xps_ethernetlite and xps_ll_temac
|
||||
* based interfaces
|
||||
*/
|
||||
struct netif *
|
||||
xemac_add(struct netif *netif,
|
||||
ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw,
|
||||
unsigned char *mac_ethernet_address,
|
||||
unsigned mac_baseaddr)
|
||||
{
|
||||
int i;
|
||||
|
||||
#ifdef OS_IS_FREERTOS
|
||||
/* Start thread to detect link periodically for Hot Plug autodetect */
|
||||
sys_thread_new("link_detect_thread", link_detect_thread, netif,
|
||||
THREAD_STACKSIZE, tskIDLE_PRIORITY);
|
||||
#endif
|
||||
|
||||
/* set mac address */
|
||||
netif->hwaddr_len = 6;
|
||||
for (i = 0; i < 6; i++)
|
||||
netif->hwaddr[i] = mac_ethernet_address[i];
|
||||
|
||||
/* initialize based on MAC type */
|
||||
switch (find_mac_type(mac_baseaddr)) {
|
||||
case xemac_type_xps_emaclite:
|
||||
#ifdef XLWIP_CONFIG_INCLUDE_EMACLITE
|
||||
return netif_add(netif, ipaddr, netmask, gw,
|
||||
(void*)(UINTPTR)mac_baseaddr,
|
||||
xemacliteif_init,
|
||||
#if NO_SYS
|
||||
ethernet_input
|
||||
#else
|
||||
tcpip_input
|
||||
#endif
|
||||
);
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
case xemac_type_axi_ethernet:
|
||||
#ifdef XLWIP_CONFIG_INCLUDE_AXI_ETHERNET
|
||||
return netif_add(netif, ipaddr, netmask, gw,
|
||||
(void*)(UINTPTR)mac_baseaddr,
|
||||
xaxiemacif_init,
|
||||
#if NO_SYS
|
||||
ethernet_input
|
||||
#else
|
||||
tcpip_input
|
||||
#endif
|
||||
);
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
#if defined (__arm__) || defined (__aarch64__)
|
||||
case xemac_type_emacps:
|
||||
#ifdef XLWIP_CONFIG_INCLUDE_GEM
|
||||
return netif_add(netif, ipaddr, netmask, gw,
|
||||
(void*)(UINTPTR)mac_baseaddr,
|
||||
xemacpsif_init,
|
||||
#if NO_SYS
|
||||
ethernet_input
|
||||
#else
|
||||
tcpip_input
|
||||
#endif
|
||||
|
||||
);
|
||||
#endif
|
||||
#endif
|
||||
default:
|
||||
xil_printf("unable to determine type of EMAC with baseaddress 0x%08x\r\n",
|
||||
mac_baseaddr);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*
|
||||
* The input thread calls lwIP to process any received packets.
|
||||
* This thread waits until a packet is received (sem_rx_data_available),
|
||||
* and then calls xemacif_input which processes 1 packet at a time.
|
||||
*/
|
||||
void
|
||||
xemacif_input_thread(struct netif *netif)
|
||||
{
|
||||
struct xemac_s *emac = (struct xemac_s *)netif->state;
|
||||
while (1) {
|
||||
/* sleep until there are packets to process
|
||||
* This semaphore is set by the packet receive interrupt
|
||||
* routine.
|
||||
*/
|
||||
sys_sem_wait(&emac->sem_rx_data_available);
|
||||
|
||||
/* move all received packets to lwIP */
|
||||
xemacif_input(netif);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
xemacif_input(struct netif *netif)
|
||||
{
|
||||
struct xemac_s *emac = (struct xemac_s *)netif->state;
|
||||
|
||||
int n_packets = 0;
|
||||
|
||||
switch (emac->type) {
|
||||
case xemac_type_xps_emaclite:
|
||||
#ifdef XLWIP_CONFIG_INCLUDE_EMACLITE
|
||||
n_packets = xemacliteif_input(netif);
|
||||
break;
|
||||
#else
|
||||
// print("incorrect configuration: xps_ethernetlite drivers not present?");
|
||||
while(1);
|
||||
return 0;
|
||||
#endif
|
||||
case xemac_type_axi_ethernet:
|
||||
#ifdef XLWIP_CONFIG_INCLUDE_AXI_ETHERNET
|
||||
n_packets = xaxiemacif_input(netif);
|
||||
break;
|
||||
#else
|
||||
// print("incorrect configuration: axi_ethernet drivers not present?");
|
||||
while(1);
|
||||
return 0;
|
||||
#endif
|
||||
#if defined (__arm__) || defined (__aarch64__)
|
||||
case xemac_type_emacps:
|
||||
#ifdef XLWIP_CONFIG_INCLUDE_GEM
|
||||
n_packets = xemacpsif_input(netif);
|
||||
break;
|
||||
#else
|
||||
xil_printf("incorrect configuration: ps7_ethernet drivers not present?\r\n");
|
||||
while(1);
|
||||
return 0;
|
||||
#endif
|
||||
#endif
|
||||
default:
|
||||
// print("incorrect configuration: unknown temac type");
|
||||
while(1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return n_packets;
|
||||
}
|
||||
|
||||
#if defined(XLWIP_CONFIG_INCLUDE_GEM)
|
||||
u32_t phy_link_detect(XEmacPs *xemacp, u32_t phy_addr)
|
||||
{
|
||||
u16_t status;
|
||||
|
||||
/* Read Phy Status register twice to get the confirmation of the current
|
||||
* link status.
|
||||
*/
|
||||
XEmacPs_PhyRead(xemacp, phy_addr, IEEE_STATUS_REG_OFFSET, &status);
|
||||
XEmacPs_PhyRead(xemacp, phy_addr, IEEE_STATUS_REG_OFFSET, &status);
|
||||
|
||||
if (status & IEEE_STAT_LINK_STATUS)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
#elif defined(XLWIP_CONFIG_INCLUDE_AXI_ETHERNET)
|
||||
static u32_t phy_link_detect(XAxiEthernet *xemacp, u32_t phy_addr)
|
||||
{
|
||||
u16_t status;
|
||||
|
||||
/* Read Phy Status register twice to get the confirmation of the current
|
||||
* link status.
|
||||
*/
|
||||
XAxiEthernet_PhyRead(xemacp, phy_addr, IEEE_STATUS_REG_OFFSET, &status);
|
||||
XAxiEthernet_PhyRead(xemacp, phy_addr, IEEE_STATUS_REG_OFFSET, &status);
|
||||
|
||||
if (status & IEEE_STAT_LINK_STATUS)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
#elif defined(XLWIP_CONFIG_INCLUDE_EMACLITE)
|
||||
static u32_t phy_link_detect(XEmacLite *xemacp, u32_t phy_addr)
|
||||
{
|
||||
u16_t status;
|
||||
|
||||
/* Read Phy Status register twice to get the confirmation of the current
|
||||
* link status.
|
||||
*/
|
||||
XEmacLite_PhyRead(xemacp, phy_addr, IEEE_STATUS_REG_OFFSET, &status);
|
||||
XEmacLite_PhyRead(xemacp, phy_addr, IEEE_STATUS_REG_OFFSET, &status);
|
||||
|
||||
if (status & IEEE_STAT_LINK_STATUS)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(XLWIP_CONFIG_INCLUDE_GEM)
|
||||
u32_t phy_autoneg_status(XEmacPs *xemacp, u32_t phy_addr)
|
||||
{
|
||||
u16_t status;
|
||||
|
||||
/* Read Phy Status register twice to get the confirmation of the current
|
||||
* link status.
|
||||
*/
|
||||
XEmacPs_PhyRead(xemacp, phy_addr, IEEE_STATUS_REG_OFFSET, &status);
|
||||
XEmacPs_PhyRead(xemacp, phy_addr, IEEE_STATUS_REG_OFFSET, &status);
|
||||
|
||||
if (status & IEEE_STAT_AUTONEGOTIATE_COMPLETE)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
#elif defined(XLWIP_CONFIG_INCLUDE_AXI_ETHERNET)
|
||||
static u32_t phy_autoneg_status(XAxiEthernet *xemacp, u32_t phy_addr)
|
||||
{
|
||||
u16_t status;
|
||||
|
||||
/* Read Phy Status register twice to get the confirmation of the current
|
||||
* link status.
|
||||
*/
|
||||
XAxiEthernet_PhyRead(xemacp, phy_addr, IEEE_STATUS_REG_OFFSET, &status);
|
||||
XAxiEthernet_PhyRead(xemacp, phy_addr, IEEE_STATUS_REG_OFFSET, &status);
|
||||
|
||||
if (status & IEEE_STAT_AUTONEGOTIATE_COMPLETE)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
#elif defined(XLWIP_CONFIG_INCLUDE_EMACLITE)
|
||||
static u32_t phy_autoneg_status(XEmacLite *xemacp, u32_t phy_addr)
|
||||
{
|
||||
u16_t status;
|
||||
|
||||
/* Read Phy Status register twice to get the confirmation of the current
|
||||
* link status.
|
||||
*/
|
||||
XEmacLite_PhyRead(xemacp, phy_addr, IEEE_STATUS_REG_OFFSET, &status);
|
||||
XEmacLite_PhyRead(xemacp, phy_addr, IEEE_STATUS_REG_OFFSET, &status);
|
||||
|
||||
if (status & IEEE_STAT_AUTONEGOTIATE_COMPLETE)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
void eth_link_detect(struct netif *netif)
|
||||
{
|
||||
u32_t link_speed, phy_link_status;
|
||||
struct xemac_s *xemac = (struct xemac_s *)(netif->state);
|
||||
|
||||
#if defined(XLWIP_CONFIG_INCLUDE_GEM)
|
||||
xemacpsif_s *xemacs = (xemacpsif_s *)(xemac->state);
|
||||
XEmacPs *xemacp = &xemacs->emacps;
|
||||
#elif defined(XLWIP_CONFIG_INCLUDE_AXI_ETHERNET)
|
||||
xaxiemacif_s *xemacs = (xaxiemacif_s *)(xemac->state);
|
||||
XAxiEthernet *xemacp = &xemacs->axi_ethernet;
|
||||
#elif defined(XLWIP_CONFIG_INCLUDE_EMACLITE)
|
||||
xemacliteif_s *xemacs = (xemacliteif_s *)(xemac->state);
|
||||
XEmacLite *xemacp = xemacs->instance;
|
||||
#endif
|
||||
|
||||
if ((xemacp->IsReady != (u32)XIL_COMPONENT_IS_READY) ||
|
||||
(eth_link_status == ETH_LINK_UNDEFINED))
|
||||
return;
|
||||
|
||||
phy_link_status = phy_link_detect(xemacp, phyaddrforemac);
|
||||
|
||||
if ((eth_link_status == ETH_LINK_UP) && (!phy_link_status))
|
||||
eth_link_status = ETH_LINK_DOWN;
|
||||
|
||||
switch (eth_link_status) {
|
||||
case ETH_LINK_UNDEFINED:
|
||||
case ETH_LINK_UP:
|
||||
return;
|
||||
case ETH_LINK_DOWN:
|
||||
netif_set_link_down(netif);
|
||||
eth_link_status = ETH_LINK_NEGOTIATING;
|
||||
xil_printf("Ethernet Link down\r\n");
|
||||
break;
|
||||
case ETH_LINK_NEGOTIATING:
|
||||
if (phy_link_status &&
|
||||
phy_autoneg_status(xemacp, phyaddrforemac)) {
|
||||
|
||||
/* Initiate Phy setup to get link speed */
|
||||
#if defined(XLWIP_CONFIG_INCLUDE_GEM)
|
||||
link_speed = phy_setup_emacps(xemacp,
|
||||
phyaddrforemac);
|
||||
XEmacPs_SetOperatingSpeed(xemacp, link_speed);
|
||||
#elif defined(XLWIP_CONFIG_INCLUDE_AXI_ETHERNET)
|
||||
link_speed = phy_setup_axiemac(xemacp);
|
||||
XAxiEthernet_SetOperatingSpeed(xemacp,
|
||||
link_speed);
|
||||
#endif
|
||||
netif_set_link_up(netif);
|
||||
eth_link_status = ETH_LINK_UP;
|
||||
xil_printf("Ethernet Link up\r\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef OS_IS_FREERTOS
|
||||
void link_detect_thread(void *p)
|
||||
{
|
||||
struct netif *netif = (struct netif *) p;
|
||||
|
||||
while (1) {
|
||||
/* Call eth_link_detect() every second to detect Ethernet link
|
||||
* change.
|
||||
*/
|
||||
eth_link_detect(netif);
|
||||
vTaskDelay(LINK_DETECT_THREAD_INTERVAL / portTICK_RATE_MS);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (C) 2018 - 2019 Xilinx, Inc.
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __XEMAC_IEEE_REGS_H_
|
||||
#define __XEMAC_IEEE_REGS_H_
|
||||
|
||||
/* Advertisement control register. */
|
||||
#define ADVERTISE_10HALF 0x0020 /* Try for 10mbps half-duplex */
|
||||
#define ADVERTISE_1000XFULL 0x0020 /* Try for 1000BASE-X full-duplex */
|
||||
#define ADVERTISE_10FULL 0x0040 /* Try for 10mbps full-duplex */
|
||||
#define ADVERTISE_1000XHALF 0x0040 /* Try for 1000BASE-X half-duplex */
|
||||
#define ADVERTISE_100HALF 0x0080 /* Try for 100mbps half-duplex */
|
||||
#define ADVERTISE_1000XPAUSE 0x0080 /* Try for 1000BASE-X pause */
|
||||
#define ADVERTISE_100FULL 0x0100 /* Try for 100mbps full-duplex */
|
||||
#define ADVERTISE_1000XPSE_ASYM 0x0100 /* Try for 1000BASE-X asym pause */
|
||||
#define ADVERTISE_100BASE4 0x0200 /* Try for 100mbps 4k packets */
|
||||
|
||||
|
||||
#define ADVERTISE_100_AND_10 (ADVERTISE_10FULL | ADVERTISE_100FULL | \
|
||||
ADVERTISE_10HALF | ADVERTISE_100HALF)
|
||||
#define ADVERTISE_100 (ADVERTISE_100FULL | ADVERTISE_100HALF)
|
||||
#define ADVERTISE_10 (ADVERTISE_10FULL | ADVERTISE_10HALF)
|
||||
|
||||
#define ADVERTISE_1000 0x0300
|
||||
|
||||
|
||||
#define IEEE_CONTROL_REG_OFFSET 0
|
||||
#define IEEE_STATUS_REG_OFFSET 1
|
||||
#define IEEE_AUTONEGO_ADVERTISE_REG 4
|
||||
#define IEEE_PARTNER_ABILITIES_1_REG_OFFSET 5
|
||||
#define IEEE_PARTNER_ABILITIES_2_REG_OFFSET 8
|
||||
#define IEEE_PARTNER_ABILITIES_3_REG_OFFSET 10
|
||||
#define IEEE_1000_ADVERTISE_REG_OFFSET 9
|
||||
#define IEEE_MMD_ACCESS_CONTROL_REG 13
|
||||
#define IEEE_MMD_ACCESS_ADDRESS_DATA_REG 14
|
||||
#define IEEE_COPPER_SPECIFIC_CONTROL_REG 16
|
||||
#define IEEE_SPECIFIC_STATUS_REG 17
|
||||
#define IEEE_COPPER_SPECIFIC_STATUS_REG_2 19
|
||||
#define IEEE_EXT_PHY_SPECIFIC_CONTROL_REG 20
|
||||
#define IEEE_CONTROL_REG_MAC 21
|
||||
#define IEEE_PAGE_ADDRESS_REGISTER 22
|
||||
|
||||
#define IEEE_CTRL_1GBPS_LINKSPEED_MASK 0x2040
|
||||
#define IEEE_CTRL_LINKSPEED_MASK 0x0040
|
||||
#define IEEE_CTRL_LINKSPEED_1000M 0x0040
|
||||
#define IEEE_CTRL_LINKSPEED_100M 0x2000
|
||||
#define IEEE_CTRL_LINKSPEED_10M 0x0000
|
||||
#define IEEE_CTRL_FULL_DUPLEX 0x100
|
||||
#define IEEE_CTRL_RESET_MASK 0x8000
|
||||
#define IEEE_CTRL_AUTONEGOTIATE_ENABLE 0x1000
|
||||
#define IEEE_STAT_AUTONEGOTIATE_CAPABLE 0x0008
|
||||
#define IEEE_STAT_AUTONEGOTIATE_COMPLETE 0x0020
|
||||
#define IEEE_STAT_AUTONEGOTIATE_RESTART 0x0200
|
||||
#define IEEE_STAT_LINK_STATUS 0x0004
|
||||
#define IEEE_STAT_1GBPS_EXTENSIONS 0x0100
|
||||
#define IEEE_AN1_ABILITY_MASK 0x1FE0
|
||||
#define IEEE_AN3_ABILITY_MASK_1GBPS 0x0C00
|
||||
#define IEEE_AN1_ABILITY_MASK_100MBPS 0x0380
|
||||
#define IEEE_AN1_ABILITY_MASK_10MBPS 0x0060
|
||||
#define IEEE_RGMII_TXRX_CLOCK_DELAYED_MASK 0x0030
|
||||
|
||||
#define IEEE_SPEED_MASK 0xC000
|
||||
#define IEEE_SPEED_1000 0x8000
|
||||
#define IEEE_SPEED_100 0x4000
|
||||
|
||||
#define IEEE_ASYMMETRIC_PAUSE_MASK 0x0800
|
||||
#define IEEE_PAUSE_MASK 0x0400
|
||||
#define IEEE_AUTONEG_ERROR_MASK 0x8000
|
||||
|
||||
#define IEEE_MMD_ACCESS_CTRL_DEVAD_MASK 0x1F
|
||||
#define IEEE_MMD_ACCESS_CTRL_PIDEVAD_MASK 0x801F
|
||||
#define IEEE_MMD_ACCESS_CTRL_NOPIDEVAD_MASK 0x401F
|
||||
|
||||
#endif /* __XEMAC_IEEE_REGS_H_ */
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,276 @@
|
||||
/*
|
||||
* Copyright (C) 2010 - 2019 Xilinx, Inc.
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "netif/xemacpsif.h"
|
||||
#include "lwipopts.h"
|
||||
|
||||
#if XPAR_GIGE_PCS_PMA_1000BASEX_CORE_PRESENT == 1 || \
|
||||
XPAR_GIGE_PCS_PMA_SGMII_CORE_PRESENT == 1
|
||||
#define PCM_PMA_CORE_PRESENT
|
||||
#else
|
||||
#undef PCM_PMA_CORE_PRESENT
|
||||
#endif
|
||||
|
||||
u32_t link_speed = 100;
|
||||
extern XEmacPs_Config XEmacPs_ConfigTable[];
|
||||
extern u32_t phymapemac0[32];
|
||||
extern u32_t phymapemac1[32];
|
||||
extern u32_t phyaddrforemac;
|
||||
extern enum ethernet_link_status eth_link_status;
|
||||
|
||||
#ifdef OS_IS_FREERTOS
|
||||
extern long xInsideISR;
|
||||
#endif
|
||||
|
||||
XEmacPs_Config *xemacps_lookup_config(unsigned mac_base)
|
||||
{
|
||||
XEmacPs_Config *cfgptr = NULL;
|
||||
s32_t i;
|
||||
|
||||
for (i = 0; i < XPAR_XEMACPS_NUM_INSTANCES; i++) {
|
||||
if (XEmacPs_ConfigTable[i].BaseAddress == mac_base) {
|
||||
cfgptr = &XEmacPs_ConfigTable[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return (cfgptr);
|
||||
}
|
||||
|
||||
void init_emacps(xemacpsif_s *xemacps, struct netif *netif)
|
||||
{
|
||||
XEmacPs *xemacpsp;
|
||||
s32_t status = XST_SUCCESS;
|
||||
u32_t i;
|
||||
u32_t phyfoundforemac0 = FALSE;
|
||||
u32_t phyfoundforemac1 = FALSE;
|
||||
|
||||
xemacpsp = &xemacps->emacps;
|
||||
|
||||
#ifdef ZYNQMP_USE_JUMBO
|
||||
XEmacPs_SetOptions(xemacpsp, XEMACPS_JUMBO_ENABLE_OPTION);
|
||||
#endif
|
||||
|
||||
#ifdef LWIP_IGMP
|
||||
XEmacPs_SetOptions(xemacpsp, XEMACPS_MULTICAST_OPTION);
|
||||
#endif
|
||||
|
||||
/* set mac address */
|
||||
status = XEmacPs_SetMacAddress(xemacpsp, (void*)(netif->hwaddr), 1);
|
||||
if (status != XST_SUCCESS) {
|
||||
xil_printf("In %s:Emac Mac Address set failed...\r\n",__func__);
|
||||
}
|
||||
|
||||
XEmacPs_SetMdioDivisor(xemacpsp, MDC_DIV_224);
|
||||
|
||||
/* Please refer to file header comments for the file xemacpsif_physpeed.c
|
||||
* to know more about the PHY programming sequence.
|
||||
* For PCS PMA core, phy_setup_emacps is called with the predefined PHY address
|
||||
* exposed through xaparemeters.h
|
||||
* For RGMII case, assuming multiple PHYs can be present on the MDIO bus,
|
||||
* detect_phy is called to get the addresses of the PHY present on
|
||||
* a particular MDIO bus (emac0 or emac1). This address map is populated
|
||||
* in phymapemac0 or phymapemac1.
|
||||
* phy_setup_emacps is then called for each PHY present on the MDIO bus.
|
||||
*/
|
||||
#ifdef PCM_PMA_CORE_PRESENT
|
||||
#ifdef XPAR_GIGE_PCS_PMA_1000BASEX_CORE_PRESENT
|
||||
link_speed = phy_setup_emacps(xemacpsp, XPAR_PCSPMA_1000BASEX_PHYADDR);
|
||||
#elif XPAR_GIGE_PCS_PMA_SGMII_CORE_PRESENT
|
||||
link_speed = phy_setup_emacps(xemacpsp, XPAR_PCSPMA_SGMII_PHYADDR);
|
||||
#endif
|
||||
#else
|
||||
detect_phy(xemacpsp);
|
||||
for (i = 31; i > 0; i--) {
|
||||
if (xemacpsp->Config.BaseAddress == XPAR_XEMACPS_0_BASEADDR) {
|
||||
if (phymapemac0[i] == TRUE) {
|
||||
link_speed = phy_setup_emacps(xemacpsp, i);
|
||||
phyfoundforemac0 = TRUE;
|
||||
phyaddrforemac = i;
|
||||
}
|
||||
} else {
|
||||
if (phymapemac1[i] == TRUE) {
|
||||
link_speed = phy_setup_emacps(xemacpsp, i);
|
||||
phyfoundforemac1 = TRUE;
|
||||
phyaddrforemac = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* If no PHY was detected, use broadcast PHY address of 0 */
|
||||
if (xemacpsp->Config.BaseAddress == XPAR_XEMACPS_0_BASEADDR) {
|
||||
if (phyfoundforemac0 == FALSE)
|
||||
link_speed = phy_setup_emacps(xemacpsp, 0);
|
||||
} else {
|
||||
if (phyfoundforemac1 == FALSE)
|
||||
link_speed = phy_setup_emacps(xemacpsp, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (link_speed == XST_FAILURE) {
|
||||
eth_link_status = ETH_LINK_DOWN;
|
||||
xil_printf("Phy setup failure %s \n\r",__func__);
|
||||
return;
|
||||
} else {
|
||||
eth_link_status = ETH_LINK_UP;
|
||||
}
|
||||
|
||||
XEmacPs_SetOperatingSpeed(xemacpsp, link_speed);
|
||||
/* Setting the operating speed of the MAC needs a delay. */
|
||||
{
|
||||
volatile s32_t wait;
|
||||
for (wait=0; wait < 20000; wait++);
|
||||
}
|
||||
}
|
||||
|
||||
void init_emacps_on_error (xemacpsif_s *xemacps, struct netif *netif)
|
||||
{
|
||||
XEmacPs *xemacpsp;
|
||||
s32_t status = XST_SUCCESS;
|
||||
|
||||
xemacpsp = &xemacps->emacps;
|
||||
|
||||
/* set mac address */
|
||||
status = XEmacPs_SetMacAddress(xemacpsp, (void*)(netif->hwaddr), 1);
|
||||
if (status != XST_SUCCESS) {
|
||||
xil_printf("In %s:Emac Mac Address set failed...\r\n",__func__);
|
||||
}
|
||||
|
||||
XEmacPs_SetOperatingSpeed(xemacpsp, link_speed);
|
||||
|
||||
/* Setting the operating speed of the MAC needs a delay. */
|
||||
{
|
||||
volatile s32_t wait;
|
||||
for (wait=0; wait < 20000; wait++);
|
||||
}
|
||||
}
|
||||
|
||||
void setup_isr (struct xemac_s *xemac)
|
||||
{
|
||||
xemacpsif_s *xemacpsif;
|
||||
|
||||
xemacpsif = (xemacpsif_s *)(xemac->state);
|
||||
/*
|
||||
* Setup callbacks
|
||||
*/
|
||||
XEmacPs_SetHandler(&xemacpsif->emacps, XEMACPS_HANDLER_DMASEND,
|
||||
(void *) emacps_send_handler,
|
||||
(void *) xemac);
|
||||
|
||||
XEmacPs_SetHandler(&xemacpsif->emacps, XEMACPS_HANDLER_DMARECV,
|
||||
(void *) emacps_recv_handler,
|
||||
(void *) xemac);
|
||||
|
||||
XEmacPs_SetHandler(&xemacpsif->emacps, XEMACPS_HANDLER_ERROR,
|
||||
(void *) emacps_error_handler,
|
||||
(void *) xemac);
|
||||
}
|
||||
|
||||
void start_emacps (xemacpsif_s *xemacps)
|
||||
{
|
||||
/* start the temac */
|
||||
XEmacPs_Start(&xemacps->emacps);
|
||||
}
|
||||
|
||||
void restart_emacps_transmitter (xemacpsif_s *xemacps) {
|
||||
u32_t Reg;
|
||||
Reg = XEmacPs_ReadReg(xemacps->emacps.Config.BaseAddress,
|
||||
XEMACPS_NWCTRL_OFFSET);
|
||||
Reg = Reg & (~XEMACPS_NWCTRL_TXEN_MASK);
|
||||
XEmacPs_WriteReg(xemacps->emacps.Config.BaseAddress,
|
||||
XEMACPS_NWCTRL_OFFSET, Reg);
|
||||
|
||||
Reg = XEmacPs_ReadReg(xemacps->emacps.Config.BaseAddress,
|
||||
XEMACPS_NWCTRL_OFFSET);
|
||||
Reg = Reg | (XEMACPS_NWCTRL_TXEN_MASK);
|
||||
XEmacPs_WriteReg(xemacps->emacps.Config.BaseAddress,
|
||||
XEMACPS_NWCTRL_OFFSET, Reg);
|
||||
}
|
||||
|
||||
void emacps_error_handler(void *arg,u8 Direction, u32 ErrorWord)
|
||||
{
|
||||
struct xemac_s *xemac;
|
||||
xemacpsif_s *xemacpsif;
|
||||
XEmacPs_BdRing *rxring;
|
||||
XEmacPs_BdRing *txring;
|
||||
#ifdef OS_IS_FREERTOS
|
||||
xInsideISR++;
|
||||
#endif
|
||||
|
||||
xemac = (struct xemac_s *)(arg);
|
||||
xemacpsif = (xemacpsif_s *)(xemac->state);
|
||||
rxring = &XEmacPs_GetRxRing(&xemacpsif->emacps);
|
||||
txring = &XEmacPs_GetTxRing(&xemacpsif->emacps);
|
||||
|
||||
if (ErrorWord != 0) {
|
||||
switch (Direction) {
|
||||
case XEMACPS_RECV:
|
||||
if (ErrorWord & XEMACPS_RXSR_HRESPNOK_MASK) {
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("Receive DMA error\r\n"));
|
||||
HandleEmacPsError(xemac);
|
||||
}
|
||||
if (ErrorWord & XEMACPS_RXSR_RXOVR_MASK) {
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("Receive over run\r\n"));
|
||||
emacps_recv_handler(arg);
|
||||
setup_rx_bds(xemacpsif, rxring);
|
||||
}
|
||||
if (ErrorWord & XEMACPS_RXSR_BUFFNA_MASK) {
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("Receive buffer not available\r\n"));
|
||||
emacps_recv_handler(arg);
|
||||
setup_rx_bds(xemacpsif, rxring);
|
||||
}
|
||||
break;
|
||||
case XEMACPS_SEND:
|
||||
if (ErrorWord & XEMACPS_TXSR_HRESPNOK_MASK) {
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("Transmit DMA error\r\n"));
|
||||
HandleEmacPsError(xemac);
|
||||
}
|
||||
if (ErrorWord & XEMACPS_TXSR_URUN_MASK) {
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("Transmit under run\r\n"));
|
||||
HandleTxErrors(xemac);
|
||||
}
|
||||
if (ErrorWord & XEMACPS_TXSR_BUFEXH_MASK) {
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("Transmit buffer exhausted\r\n"));
|
||||
HandleTxErrors(xemac);
|
||||
}
|
||||
if (ErrorWord & XEMACPS_TXSR_RXOVR_MASK) {
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("Transmit retry excessed limits\r\n"));
|
||||
HandleTxErrors(xemac);
|
||||
}
|
||||
if (ErrorWord & XEMACPS_TXSR_FRAMERX_MASK) {
|
||||
LWIP_DEBUGF(NETIF_DEBUG, ("Transmit collision\r\n"));
|
||||
// process_sent_bds(xemacpsif, txring);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
#ifdef OS_IS_FREERTOS
|
||||
xInsideISR--;
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2010 - 2019 Xilinx, Inc.
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __XEMACPSIF_HW_H_
|
||||
#define __XEMACPSIF_HW_H_
|
||||
|
||||
#include "netif/xemacpsif.h"
|
||||
#include "lwip/netif.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
XEmacPs_Config * lookup_config(unsigned mac_base);
|
||||
|
||||
void init_emacps(xemacpsif_s *xemacpsif, struct netif *netif);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2002 Swedish Institute of Computer Science.
|
||||
* Copyright (C) 2007 - 2018 Xilinx, Inc.
|
||||
* 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 __XLWIPCONFIG_H_
|
||||
#define __XLWIPCONFIG_H_
|
||||
|
||||
|
||||
/* This is a generated file - do not edit */
|
||||
|
||||
#define XLWIP_CONFIG_INCLUDE_GEM 1
|
||||
#define XLWIP_CONFIG_EMAC_NUMBER 0
|
||||
#define XLWIP_CONFIG_N_TX_DESC 64
|
||||
#define XLWIP_CONFIG_N_RX_DESC 64
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (C) 2007 - 2019 Xilinx, Inc.
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "netif/xpqueue.h"
|
||||
#include "xil_printf.h"
|
||||
|
||||
#define NUM_QUEUES 2
|
||||
|
||||
pq_queue_t pq_queue[NUM_QUEUES];
|
||||
|
||||
pq_queue_t *
|
||||
pq_create_queue()
|
||||
{
|
||||
static int i;
|
||||
pq_queue_t *q = NULL;
|
||||
|
||||
if (i >= NUM_QUEUES) {
|
||||
xil_printf("ERR: Max Queues allocated\n\r");
|
||||
return q;
|
||||
}
|
||||
|
||||
q = &pq_queue[i++];
|
||||
|
||||
if (!q)
|
||||
return q;
|
||||
|
||||
q->head = q->tail = q->len = 0;
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
int
|
||||
pq_enqueue(pq_queue_t *q, void *p)
|
||||
{
|
||||
if (q->len == PQ_QUEUE_SIZE)
|
||||
return -1;
|
||||
|
||||
q->data[q->head] = p;
|
||||
q->head = (q->head + 1)%PQ_QUEUE_SIZE;
|
||||
q->len++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void*
|
||||
pq_dequeue(pq_queue_t *q)
|
||||
{
|
||||
int ptail;
|
||||
|
||||
if (q->len == 0)
|
||||
return NULL;
|
||||
|
||||
ptail = q->tail;
|
||||
q->tail = (q->tail + 1)%PQ_QUEUE_SIZE;
|
||||
q->len--;
|
||||
|
||||
return q->data[ptail];
|
||||
}
|
||||
|
||||
int
|
||||
pq_qlength(pq_queue_t *q)
|
||||
{
|
||||
return q->len;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#include "netif/xtopology.h"
|
||||
#include "xparameters.h"
|
||||
|
||||
struct xtopology_t xtopology[] = {
|
||||
{
|
||||
0xFF0E0000,
|
||||
xemac_type_emacps,
|
||||
0x0,
|
||||
0x0,
|
||||
0xF8F00100,
|
||||
XPAR_XEMACPS_3_INTR,
|
||||
},
|
||||
};
|
||||
|
||||
int xtopology_n_emacs = 1;
|
||||
@@ -54,6 +54,9 @@ typedef long LONG;
|
||||
typedef unsigned long ULONG;
|
||||
#endif
|
||||
|
||||
#define ULONG64_HI_MASK 0xFFFFFFFF00000000U
|
||||
#define ULONG64_LO_MASK ~ULONG64_HI_MASK
|
||||
|
||||
/** @{ */
|
||||
/**
|
||||
* This data type defines an interrupt handler for a device.
|
||||
|
||||
@@ -0,0 +1,349 @@
|
||||
/*
|
||||
* Copyright (c) 2021, WangHuachen
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-5-10 WangHuachen the first version
|
||||
*/
|
||||
|
||||
|
||||
#include "board.h"
|
||||
#include <netif/ethernetif.h>
|
||||
#include "lwipopts.h"
|
||||
#include "lwip/opt.h"
|
||||
#include "drv_eth.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "netif/xadapter.h"
|
||||
#include "netif/xemacpsif.h"
|
||||
#include "xparameters.h"
|
||||
#include "xemacps.h"
|
||||
|
||||
#define DBG_TAG "drv.emac"
|
||||
#define DBG_LEVEL DBG_INFO
|
||||
#include <rtdbg.h>
|
||||
|
||||
#define MAC_BASE_ADDR XPAR_PSU_ETHERNET_3_BASEADDR
|
||||
#define MAX_ADDR_LEN 6
|
||||
|
||||
struct rt_zynqmp_eth
|
||||
{
|
||||
/* inherit from ethernet device */
|
||||
struct eth_device parent;
|
||||
|
||||
/* interface address info, hw address */
|
||||
rt_uint8_t dev_addr[MAX_ADDR_LEN];
|
||||
|
||||
struct xemac_s *xemac;
|
||||
};
|
||||
|
||||
static struct rt_zynqmp_eth zynqmp_eth_device;
|
||||
extern XEmacPs_Config *mac_config;
|
||||
extern struct netif *NetIf;
|
||||
|
||||
static void rt_hw_eth_isr(int irqno, void *param)
|
||||
{
|
||||
struct rt_zynqmp_eth *eth_dev = (struct rt_zynqmp_eth *)param;
|
||||
xemacpsif_s *xemacpsif = (xemacpsif_s *)eth_dev->xemac->state;
|
||||
XEmacPs_IntrHandler(&xemacpsif->emacps);
|
||||
}
|
||||
|
||||
extern enum ethernet_link_status eth_link_status;
|
||||
extern u32_t phy_link_detect(XEmacPs *xemacp, u32_t phy_addr);
|
||||
extern u32_t phy_autoneg_status(XEmacPs *xemacp, u32_t phy_addr);
|
||||
extern u32_t phyaddrforemac;
|
||||
|
||||
void rt_zynqmp_eth_link_detect(struct rt_zynqmp_eth *eth_dev)
|
||||
{
|
||||
u32_t link_speed, phy_link_status;
|
||||
struct xemac_s *xemac = eth_dev->xemac;
|
||||
xemacpsif_s *xemacs = (xemacpsif_s *)(xemac->state);
|
||||
XEmacPs *xemacp = &xemacs->emacps;
|
||||
|
||||
if ((xemacp->IsReady != (u32)XIL_COMPONENT_IS_READY) ||
|
||||
(eth_link_status == ETH_LINK_UNDEFINED))
|
||||
return;
|
||||
|
||||
phy_link_status = phy_link_detect(xemacp, phyaddrforemac);
|
||||
|
||||
if ((eth_link_status == ETH_LINK_UP) && (!phy_link_status))
|
||||
eth_link_status = ETH_LINK_DOWN;
|
||||
|
||||
switch (eth_link_status) {
|
||||
case ETH_LINK_UNDEFINED:
|
||||
case ETH_LINK_UP:
|
||||
return;
|
||||
case ETH_LINK_DOWN:
|
||||
eth_device_linkchange(&zynqmp_eth_device.parent, RT_FALSE);
|
||||
eth_link_status = ETH_LINK_NEGOTIATING;
|
||||
LOG_D("Ethernet Link down");
|
||||
break;
|
||||
case ETH_LINK_NEGOTIATING:
|
||||
if (phy_link_status &&
|
||||
phy_autoneg_status(xemacp, phyaddrforemac)) {
|
||||
|
||||
/* Initiate Phy setup to get link speed */
|
||||
link_speed = phy_setup_emacps(xemacp,
|
||||
phyaddrforemac);
|
||||
XEmacPs_SetOperatingSpeed(xemacp, link_speed);
|
||||
|
||||
eth_device_linkchange(&zynqmp_eth_device.parent, RT_TRUE);
|
||||
eth_link_status = ETH_LINK_UP;
|
||||
LOG_D("Ethernet Link up");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void phy_monitor_thread(void *parameter)
|
||||
{
|
||||
struct rt_zynqmp_eth *eth_dev = (struct rt_zynqmp_eth *)parameter;
|
||||
|
||||
while (1)
|
||||
{
|
||||
rt_zynqmp_eth_link_detect(eth_dev);
|
||||
rt_thread_delay(RT_TICK_PER_SECOND);
|
||||
}
|
||||
}
|
||||
|
||||
static rt_err_t rt_zynqmp_eth_init(rt_device_t dev)
|
||||
{
|
||||
struct rt_zynqmp_eth *eth_dev = (struct rt_zynqmp_eth *)dev->user_data;
|
||||
struct netif *netif = eth_dev->parent.netif;
|
||||
struct xemac_s *xemac;
|
||||
xemacpsif_s *xemacpsif;
|
||||
u32 dmacrreg;
|
||||
s32_t status = XST_SUCCESS;
|
||||
struct xtopology_t *xtopologyp;
|
||||
|
||||
if (eth_dev->xemac != RT_NULL)
|
||||
{
|
||||
LOG_W("rt_zynqmp_eth_init: device has been initialized");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
NetIf = netif;
|
||||
|
||||
xemacpsif = rt_malloc(sizeof *xemacpsif);
|
||||
if (xemacpsif == NULL)
|
||||
{
|
||||
LOG_E("rt_zynqmp_eth_init: out of memory");
|
||||
return -RT_ENOMEM;
|
||||
}
|
||||
|
||||
xemac = rt_malloc(sizeof *xemac);
|
||||
if (xemac == NULL)
|
||||
{
|
||||
LOG_E("rt_zynqmp_eth_init: out of memory");
|
||||
return -RT_ENOMEM;
|
||||
}
|
||||
|
||||
xemac->state = (void *)xemacpsif;
|
||||
xemac->topology_index = xtopology_find_index(MAC_BASE_ADDR);
|
||||
xemac->type = xemac_type_emacps;
|
||||
xemac->rt_eth_device = ð_dev->parent;
|
||||
|
||||
xemacpsif->send_q = NULL;
|
||||
xemacpsif->recv_q = pq_create_queue();
|
||||
if (!xemacpsif->recv_q)
|
||||
return -RT_ENOMEM;
|
||||
|
||||
eth_dev->xemac = xemac;
|
||||
|
||||
/* obtain config of this emac */
|
||||
mac_config = (XEmacPs_Config *)xemacps_lookup_config(MAC_BASE_ADDR);
|
||||
|
||||
status = XEmacPs_CfgInitialize(&xemacpsif->emacps, mac_config,
|
||||
mac_config->BaseAddress);
|
||||
if (status != XST_SUCCESS)
|
||||
{
|
||||
LOG_W("In %s:EmacPs Configuration Failed....", __func__);
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
/* initialize the mac */
|
||||
init_emacps(xemacpsif, netif);
|
||||
|
||||
dmacrreg = XEmacPs_ReadReg(xemacpsif->emacps.Config.BaseAddress,
|
||||
XEMACPS_DMACR_OFFSET);
|
||||
dmacrreg = dmacrreg | (0x00000010);
|
||||
XEmacPs_WriteReg(xemacpsif->emacps.Config.BaseAddress,
|
||||
XEMACPS_DMACR_OFFSET, dmacrreg);
|
||||
|
||||
setup_isr(xemac);
|
||||
init_dma(xemac);
|
||||
|
||||
xtopologyp = &xtopology[xemac->topology_index];
|
||||
/*
|
||||
* Connect the device driver handler that will be called when an
|
||||
* interrupt for the device occurs, the handler defined above performs
|
||||
* the specific interrupt processing for the device.
|
||||
*/
|
||||
rt_hw_interrupt_install(xtopologyp->scugic_emac_intr, rt_hw_eth_isr, (void *)eth_dev, "eth");
|
||||
/*
|
||||
* Enable the interrupt for emacps.
|
||||
*/
|
||||
rt_hw_interrupt_umask(xtopologyp->scugic_emac_intr);
|
||||
|
||||
start_emacps(xemacpsif);
|
||||
|
||||
if (eth_link_status == ETH_LINK_UP)
|
||||
eth_device_linkchange(ð_dev->parent, RT_TRUE);
|
||||
|
||||
rt_thread_t tid;
|
||||
tid = rt_thread_create("phylnk",
|
||||
phy_monitor_thread,
|
||||
eth_dev,
|
||||
1024,
|
||||
RT_THREAD_PRIORITY_MAX - 2,
|
||||
2);
|
||||
if (tid != RT_NULL)
|
||||
rt_thread_startup(tid);
|
||||
else
|
||||
return -RT_ERROR;
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t rt_zynqmp_eth_open(rt_device_t dev, rt_uint16_t oflag)
|
||||
{
|
||||
LOG_D("emac open");
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t rt_zynqmp_eth_close(rt_device_t dev)
|
||||
{
|
||||
LOG_D("emac close");
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_size_t rt_zynqmp_eth_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
|
||||
{
|
||||
LOG_D("emac read");
|
||||
rt_set_errno(-RT_ENOSYS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static rt_size_t rt_zynqmp_eth_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
|
||||
{
|
||||
LOG_D("emac write");
|
||||
rt_set_errno(-RT_ENOSYS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static rt_err_t rt_zynqmp_eth_control(rt_device_t dev, int cmd, void *args)
|
||||
{
|
||||
struct rt_zynqmp_eth *eth_dev = (struct rt_zynqmp_eth *)dev->user_data;
|
||||
switch (cmd)
|
||||
{
|
||||
case NIOCTL_GADDR:
|
||||
/* get mac address */
|
||||
if (args) rt_memcpy(args, eth_dev->dev_addr, 6);
|
||||
else return -RT_ERROR;
|
||||
break;
|
||||
|
||||
default :
|
||||
break;
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
extern err_t _unbuffered_low_level_output(xemacpsif_s *xemacpsif, struct pbuf *p);
|
||||
rt_err_t rt_zynqmp_eth_tx(rt_device_t dev, struct pbuf *p)
|
||||
{
|
||||
rt_base_t lev;
|
||||
rt_err_t err;
|
||||
XEmacPs_BdRing *txring;
|
||||
|
||||
struct rt_zynqmp_eth *eth_dev = (struct rt_zynqmp_eth *)dev->user_data;
|
||||
struct xemac_s *xemac = eth_dev->xemac;
|
||||
xemacpsif_s *xemacpsif = (xemacpsif_s *)(xemac->state);
|
||||
|
||||
lev = rt_hw_interrupt_disable();
|
||||
|
||||
txring = &(XEmacPs_GetTxRing(&xemacpsif->emacps));
|
||||
process_sent_bds(xemacpsif, txring);
|
||||
|
||||
if (is_tx_space_available(xemacpsif))
|
||||
{
|
||||
_unbuffered_low_level_output(xemacpsif, p);
|
||||
err = RT_EOK;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if LINK_STATS
|
||||
lwip_stats.link.drop++;
|
||||
#endif
|
||||
LOG_D("pack dropped, no space");
|
||||
err = -RT_ENOMEM;
|
||||
}
|
||||
|
||||
rt_hw_interrupt_enable(lev);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
struct pbuf *rt_zynqmp_eth_rx(rt_device_t dev)
|
||||
{
|
||||
rt_base_t lev;
|
||||
struct rt_zynqmp_eth *eth_dev = (struct rt_zynqmp_eth *)dev->user_data;
|
||||
struct xemac_s *xemac = eth_dev->xemac;
|
||||
xemacpsif_s *xemacpsif = (xemacpsif_s *)(xemac->state);
|
||||
struct pbuf *p;
|
||||
|
||||
lev = rt_hw_interrupt_disable();
|
||||
|
||||
/* see if there is data to process */
|
||||
if (pq_qlength(xemacpsif->recv_q) == 0)
|
||||
return NULL;
|
||||
|
||||
/* return one packet from receive q */
|
||||
p = (struct pbuf *)pq_dequeue(xemacpsif->recv_q);
|
||||
|
||||
rt_hw_interrupt_enable(lev);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
static int rt_hw_zynqmp_eth_init(void)
|
||||
{
|
||||
rt_err_t state = RT_EOK;
|
||||
|
||||
zynqmp_eth_device.xemac = RT_NULL;
|
||||
|
||||
zynqmp_eth_device.dev_addr[0] = 0x00;
|
||||
zynqmp_eth_device.dev_addr[1] = 0x0A;
|
||||
zynqmp_eth_device.dev_addr[2] = 0x35;
|
||||
zynqmp_eth_device.dev_addr[3] = 0x00;
|
||||
zynqmp_eth_device.dev_addr[4] = 0x01;
|
||||
zynqmp_eth_device.dev_addr[5] = 0x02;
|
||||
|
||||
zynqmp_eth_device.parent.parent.init = rt_zynqmp_eth_init;
|
||||
zynqmp_eth_device.parent.parent.open = rt_zynqmp_eth_open;
|
||||
zynqmp_eth_device.parent.parent.close = rt_zynqmp_eth_close;
|
||||
zynqmp_eth_device.parent.parent.read = rt_zynqmp_eth_read;
|
||||
zynqmp_eth_device.parent.parent.write = rt_zynqmp_eth_write;
|
||||
zynqmp_eth_device.parent.parent.control = rt_zynqmp_eth_control;
|
||||
zynqmp_eth_device.parent.parent.user_data = &zynqmp_eth_device;
|
||||
|
||||
zynqmp_eth_device.parent.eth_rx = rt_zynqmp_eth_rx;
|
||||
zynqmp_eth_device.parent.eth_tx = rt_zynqmp_eth_tx;
|
||||
|
||||
/* register eth device */
|
||||
state = eth_device_init(&(zynqmp_eth_device.parent), "e0");
|
||||
if (RT_EOK == state)
|
||||
{
|
||||
LOG_D("emac device init success");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_E("emac device init faild: %d", state);
|
||||
state = -RT_ERROR;
|
||||
return state;
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
INIT_DEVICE_EXPORT(rt_hw_zynqmp_eth_init);
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef __DRV_ETH_H__
|
||||
#define __DRV_ETH_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -19,6 +19,9 @@
|
||||
#define RT_USING_TIMER_SOFT
|
||||
#define RT_TIMER_THREAD_PRIO 4
|
||||
#define RT_TIMER_THREAD_STACK_SIZE 512
|
||||
|
||||
/* kservice optimization */
|
||||
|
||||
#define RT_DEBUG
|
||||
|
||||
/* Inter-Thread communication */
|
||||
@@ -32,7 +35,7 @@
|
||||
/* Memory Management */
|
||||
|
||||
#define RT_USING_MEMPOOL
|
||||
#define RT_USING_SMALL_MEM
|
||||
#define RT_USING_SLAB
|
||||
#define RT_USING_HEAP
|
||||
|
||||
/* Kernel Device Object */
|
||||
@@ -41,7 +44,7 @@
|
||||
#define RT_USING_CONSOLE
|
||||
#define RT_CONSOLEBUF_SIZE 128
|
||||
#define RT_CONSOLE_DEVICE_NAME "uart0"
|
||||
#define RT_VER_NUM 0x40003
|
||||
#define RT_VER_NUM 0x40004
|
||||
|
||||
/* RT-Thread Components */
|
||||
|
||||
@@ -83,6 +86,8 @@
|
||||
#define RT_DFS_ELM_WORD_ACCESS
|
||||
#define RT_DFS_ELM_USE_LFN_3
|
||||
#define RT_DFS_ELM_USE_LFN 3
|
||||
#define RT_DFS_ELM_LFN_UNICODE_0
|
||||
#define RT_DFS_ELM_LFN_UNICODE 0
|
||||
#define RT_DFS_ELM_MAX_LFN 255
|
||||
#define RT_DFS_ELM_DRIVES 2
|
||||
#define RT_DFS_ELM_MAX_SECTOR_SIZE 512
|
||||
@@ -93,6 +98,9 @@
|
||||
|
||||
#define RT_USING_DEVICE_IPC
|
||||
#define RT_PIPE_BUFSZ 512
|
||||
#define RT_USING_SYSTEM_WORKQUEUE
|
||||
#define RT_SYSTEM_WORKQUEUE_STACKSIZE 2048
|
||||
#define RT_SYSTEM_WORKQUEUE_PRIORITY 23
|
||||
#define RT_USING_SERIAL
|
||||
#define RT_SERIAL_USING_DMA
|
||||
#define RT_SERIAL_RB_BUFSZ 64
|
||||
@@ -101,24 +109,77 @@
|
||||
/* Using USB */
|
||||
|
||||
|
||||
/* Using RapidIO */
|
||||
|
||||
|
||||
/* POSIX layer and C standard library */
|
||||
|
||||
#define RT_USING_LIBC
|
||||
#define RT_USING_POSIX
|
||||
#define RT_LIBC_FIXED_TIMEZONE 8
|
||||
|
||||
/* Network */
|
||||
|
||||
/* Socket abstraction layer */
|
||||
|
||||
#define RT_USING_SAL
|
||||
#define SAL_INTERNET_CHECK
|
||||
|
||||
/* protocol stack implement */
|
||||
|
||||
#define SAL_USING_LWIP
|
||||
#define SAL_USING_POSIX
|
||||
|
||||
/* Network interface device */
|
||||
|
||||
#define RT_USING_NETDEV
|
||||
#define NETDEV_USING_IFCONFIG
|
||||
#define NETDEV_USING_PING
|
||||
#define NETDEV_USING_NETSTAT
|
||||
#define NETDEV_USING_AUTO_DEFAULT
|
||||
#define NETDEV_IPV4 1
|
||||
#define NETDEV_IPV6 0
|
||||
|
||||
/* light weight TCP/IP stack */
|
||||
|
||||
#define RT_USING_LWIP
|
||||
#define RT_USING_LWIP202
|
||||
#define RT_LWIP_MEM_ALIGNMENT 32
|
||||
#define RT_LWIP_IGMP
|
||||
#define RT_LWIP_ICMP
|
||||
#define RT_LWIP_DNS
|
||||
#define RT_LWIP_DHCP
|
||||
#define IP_SOF_BROADCAST 1
|
||||
#define IP_SOF_BROADCAST_RECV 1
|
||||
|
||||
/* Static IPv4 Address */
|
||||
|
||||
#define RT_LWIP_IPADDR "192.168.1.30"
|
||||
#define RT_LWIP_GWADDR "192.168.1.1"
|
||||
#define RT_LWIP_MSKADDR "255.255.255.0"
|
||||
#define RT_LWIP_UDP
|
||||
#define RT_LWIP_TCP
|
||||
#define RT_LWIP_RAW
|
||||
#define RT_MEMP_NUM_NETCONN 8
|
||||
#define RT_LWIP_PBUF_NUM 256
|
||||
#define RT_LWIP_RAW_PCB_NUM 4
|
||||
#define RT_LWIP_UDP_PCB_NUM 4
|
||||
#define RT_LWIP_TCP_PCB_NUM 4
|
||||
#define RT_LWIP_TCP_SEG_NUM 40
|
||||
#define RT_LWIP_TCP_SND_BUF 8196
|
||||
#define RT_LWIP_TCP_WND 8196
|
||||
#define RT_LWIP_TCPTHREAD_PRIORITY 10
|
||||
#define RT_LWIP_TCPTHREAD_MBOX_SIZE 8
|
||||
#define RT_LWIP_TCPTHREAD_STACKSIZE 2048
|
||||
#define RT_LWIP_ETHTHREAD_PRIORITY 12
|
||||
#define RT_LWIP_ETHTHREAD_STACKSIZE 1024
|
||||
#define RT_LWIP_ETHTHREAD_MBOX_SIZE 8
|
||||
#define LWIP_NETIF_STATUS_CALLBACK 1
|
||||
#define LWIP_NETIF_LINK_CALLBACK 1
|
||||
#define SO_REUSE 1
|
||||
#define LWIP_SO_RCVTIMEO 1
|
||||
#define LWIP_SO_SNDTIMEO 1
|
||||
#define LWIP_SO_RCVBUF 1
|
||||
#define LWIP_SO_LINGER 0
|
||||
#define LWIP_NETIF_LOOPBACK 0
|
||||
#define RT_LWIP_USING_PING
|
||||
|
||||
/* AT commands */
|
||||
|
||||
@@ -129,6 +190,9 @@
|
||||
/* Utilities */
|
||||
|
||||
|
||||
/* RT-Thread Utestcases */
|
||||
|
||||
|
||||
/* RT-Thread online packages */
|
||||
|
||||
/* IoT - internet of things */
|
||||
@@ -166,11 +230,17 @@
|
||||
/* peripheral libraries and drivers */
|
||||
|
||||
|
||||
/* AI packages */
|
||||
|
||||
|
||||
/* miscellaneous packages */
|
||||
|
||||
|
||||
/* samples: kernel and components samples */
|
||||
|
||||
|
||||
/* entertainment: terminal games and other interesting software packages */
|
||||
|
||||
#define SOC_ZYNQMP_R5
|
||||
|
||||
/* Hardware Drivers Config */
|
||||
@@ -184,6 +254,13 @@
|
||||
#define BSP_USING_SDIO
|
||||
#define BSP_USING_SD0
|
||||
|
||||
/* Please set RT_LWIP_PBUF_NUM is at least 256 if Enable Ethernet! */
|
||||
|
||||
/* Please set RT_LWIP_MEM_ALIGNMENT is at 32 if Enable Ethernet! */
|
||||
|
||||
#define BSP_USING_ETH
|
||||
#define RT_LWIP_PBUF_POOL_BUFSIZE 1700
|
||||
|
||||
/* Board extended module Drivers */
|
||||
|
||||
|
||||
|
||||
+270
-27
@@ -1,11 +1,13 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
* Copyright (c) 2014 - 2020 Xilinx, Inc. All rights reserved.
|
||||
* Copyright (c) 2021 WangHuachen. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2020-03-19 WangHuachen first version
|
||||
* 2021-05-10 WangHuachen add more functions
|
||||
*/
|
||||
#include <rthw.h>
|
||||
#include <rtdef.h>
|
||||
@@ -44,41 +46,85 @@ typedef rt_uint32_t u32;
|
||||
XREG_CP15_INVAL_IC_LINE_MVA_POU :: "r" (param))
|
||||
#endif
|
||||
|
||||
void Xil_DCacheEnable(void);
|
||||
void Xil_DCacheDisable(void);
|
||||
void Xil_DCacheInvalidate(void);
|
||||
void Xil_DCacheInvalidateRange(INTPTR adr, u32 len);
|
||||
void Xil_DCacheFlush(void);
|
||||
void Xil_DCacheFlushRange(INTPTR adr, u32 len);
|
||||
void Xil_DCacheInvalidateLine(INTPTR adr);
|
||||
void Xil_DCacheFlushLine(INTPTR adr);
|
||||
void Xil_DCacheStoreLine(INTPTR adr);
|
||||
void Xil_ICacheEnable(void);
|
||||
void Xil_ICacheDisable(void);
|
||||
void Xil_ICacheInvalidate(void);
|
||||
void Xil_ICacheInvalidateRange(INTPTR adr, u32 len);
|
||||
void Xil_ICacheInvalidateLine(INTPTR adr);
|
||||
|
||||
void Xil_ICacheInvalidateRange(INTPTR adr, u32 len)
|
||||
void Xil_DCacheEnable(void)
|
||||
{
|
||||
register u32 CtrlReg;
|
||||
|
||||
/* enable caches only if they are disabled */
|
||||
#if defined (__GNUC__)
|
||||
CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
|
||||
#elif defined (__ICCARM__)
|
||||
mfcp(XREG_CP15_SYS_CONTROL,CtrlReg);
|
||||
#endif
|
||||
if ((CtrlReg & XREG_CP15_CONTROL_C_BIT)==0x00000000U) {
|
||||
/* invalidate the Data cache */
|
||||
Xil_DCacheInvalidate();
|
||||
|
||||
/* enable the Data cache */
|
||||
CtrlReg |= (XREG_CP15_CONTROL_C_BIT);
|
||||
|
||||
mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
|
||||
}
|
||||
}
|
||||
|
||||
void Xil_DCacheDisable(void)
|
||||
{
|
||||
register u32 CtrlReg;
|
||||
|
||||
/* clean and invalidate the Data cache */
|
||||
Xil_DCacheFlush();
|
||||
|
||||
/* disable the Data cache */
|
||||
#if defined (__GNUC__)
|
||||
CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
|
||||
#elif defined (__ICCARM__)
|
||||
mfcp(XREG_CP15_SYS_CONTROL,CtrlReg);
|
||||
#endif
|
||||
|
||||
CtrlReg &= ~(XREG_CP15_CONTROL_C_BIT);
|
||||
|
||||
mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
|
||||
}
|
||||
|
||||
void Xil_DCacheInvalidate(void)
|
||||
{
|
||||
u32 LocalAddr = adr;
|
||||
const u32 cacheline = 32U;
|
||||
u32 end;
|
||||
u32 currmask;
|
||||
|
||||
currmask = mfcpsr();
|
||||
mtcpsr(currmask | IRQ_FIQ_MASK);
|
||||
if (len != 0x00000000U) {
|
||||
/* Back the starting address up to the start of a cache line
|
||||
* perform cache operations until adr+len
|
||||
*/
|
||||
end = LocalAddr + len;
|
||||
LocalAddr = LocalAddr & ~(cacheline - 1U);
|
||||
|
||||
/* Select cache L0 I-cache in CSSR */
|
||||
mtcp(XREG_CP15_CACHE_SIZE_SEL, 1U);
|
||||
#if 0
|
||||
stack_end = (u32 )&_stack_end;
|
||||
stack_start = (u32 )&__undef_stack;
|
||||
stack_size = stack_start-stack_end;
|
||||
|
||||
while (LocalAddr < end) {
|
||||
/* Flush stack memory to save return address */
|
||||
Xil_DCacheFlushRange(stack_end, stack_size);
|
||||
#endif
|
||||
mtcp(XREG_CP15_CACHE_SIZE_SEL, 0);
|
||||
|
||||
/* Invalidate L1 I-cache line */
|
||||
asm_inval_ic_line_mva_pou(LocalAddr);
|
||||
/*invalidate all D cache*/
|
||||
mtcp(XREG_CP15_INVAL_DC_ALL, 0);
|
||||
|
||||
LocalAddr += cacheline;
|
||||
}
|
||||
}
|
||||
|
||||
/* Wait for invalidate to complete */
|
||||
dsb();
|
||||
mtcpsr(currmask);
|
||||
}
|
||||
|
||||
void Xil_DCacheFlushLine(INTPTR adr)
|
||||
void Xil_DCacheInvalidateLine(INTPTR adr)
|
||||
{
|
||||
u32 currmask;
|
||||
|
||||
@@ -86,11 +132,11 @@ void Xil_DCacheFlushLine(INTPTR adr)
|
||||
mtcpsr(currmask | IRQ_FIQ_MASK);
|
||||
|
||||
mtcp(XREG_CP15_CACHE_SIZE_SEL, 0);
|
||||
mtcp(XREG_CP15_INVAL_DC_LINE_MVA_POC, (adr & (~0x1F)));
|
||||
|
||||
mtcp(XREG_CP15_CLEAN_INVAL_DC_LINE_MVA_POC, (adr & (~0x1F)));
|
||||
|
||||
/* Wait for flush to complete */
|
||||
/* Wait for invalidate to complete */
|
||||
dsb();
|
||||
|
||||
mtcpsr(currmask);
|
||||
}
|
||||
|
||||
@@ -135,6 +181,79 @@ void Xil_DCacheInvalidateRange(INTPTR adr, u32 len)
|
||||
mtcpsr(currmask);
|
||||
}
|
||||
|
||||
void Xil_DCacheFlush(void)
|
||||
{
|
||||
register u32 CsidReg, C7Reg;
|
||||
u32 CacheSize, LineSize, NumWays;
|
||||
u32 Way, WayIndex, Set, SetIndex, NumSet;
|
||||
u32 currmask;
|
||||
|
||||
currmask = mfcpsr();
|
||||
mtcpsr(currmask | IRQ_FIQ_MASK);
|
||||
|
||||
/* Select cache level 0 and D cache in CSSR */
|
||||
mtcp(XREG_CP15_CACHE_SIZE_SEL, 0);
|
||||
|
||||
#if defined (__GNUC__)
|
||||
CsidReg = mfcp(XREG_CP15_CACHE_SIZE_ID);
|
||||
#elif defined (__ICCARM__)
|
||||
mfcp(XREG_CP15_CACHE_SIZE_ID,CsidReg);
|
||||
#endif
|
||||
/* Determine Cache Size */
|
||||
|
||||
CacheSize = (CsidReg >> 13U) & 0x000001FFU;
|
||||
CacheSize += 0x00000001U;
|
||||
CacheSize *= (u32)128; /* to get number of bytes */
|
||||
|
||||
/* Number of Ways */
|
||||
NumWays = (CsidReg & 0x000003ffU) >> 3U;
|
||||
NumWays += 0x00000001U;
|
||||
|
||||
/* Get the cacheline size, way size, index size from csidr */
|
||||
LineSize = (CsidReg & 0x00000007U) + 0x00000004U;
|
||||
|
||||
NumSet = CacheSize/NumWays;
|
||||
NumSet /= (0x00000001U << LineSize);
|
||||
|
||||
Way = 0U;
|
||||
Set = 0U;
|
||||
|
||||
/* Invalidate all the cachelines */
|
||||
for (WayIndex = 0U; WayIndex < NumWays; WayIndex++) {
|
||||
for (SetIndex = 0U; SetIndex < NumSet; SetIndex++) {
|
||||
C7Reg = Way | Set;
|
||||
/* Flush by Set/Way */
|
||||
asm_clean_inval_dc_line_sw(C7Reg);
|
||||
|
||||
Set += (0x00000001U << LineSize);
|
||||
}
|
||||
Set = 0U;
|
||||
Way += 0x40000000U;
|
||||
}
|
||||
|
||||
/* Wait for flush to complete */
|
||||
dsb();
|
||||
mtcpsr(currmask);
|
||||
|
||||
mtcpsr(currmask);
|
||||
}
|
||||
|
||||
void Xil_DCacheFlushLine(INTPTR adr)
|
||||
{
|
||||
u32 currmask;
|
||||
|
||||
currmask = mfcpsr();
|
||||
mtcpsr(currmask | IRQ_FIQ_MASK);
|
||||
|
||||
mtcp(XREG_CP15_CACHE_SIZE_SEL, 0);
|
||||
|
||||
mtcp(XREG_CP15_CLEAN_INVAL_DC_LINE_MVA_POC, (adr & (~0x1F)));
|
||||
|
||||
/* Wait for flush to complete */
|
||||
dsb();
|
||||
mtcpsr(currmask);
|
||||
}
|
||||
|
||||
void Xil_DCacheFlushRange(INTPTR adr, u32 len)
|
||||
{
|
||||
u32 LocalAddr = adr;
|
||||
@@ -163,6 +282,130 @@ void Xil_DCacheFlushRange(INTPTR adr, u32 len)
|
||||
mtcpsr(currmask);
|
||||
}
|
||||
|
||||
void Xil_DCacheStoreLine(INTPTR adr)
|
||||
{
|
||||
u32 currmask;
|
||||
|
||||
currmask = mfcpsr();
|
||||
mtcpsr(currmask | IRQ_FIQ_MASK);
|
||||
|
||||
mtcp(XREG_CP15_CACHE_SIZE_SEL, 0);
|
||||
mtcp(XREG_CP15_CLEAN_DC_LINE_MVA_POC, (adr & (~0x1F)));
|
||||
|
||||
/* Wait for store to complete */
|
||||
dsb();
|
||||
isb();
|
||||
|
||||
mtcpsr(currmask);
|
||||
}
|
||||
|
||||
void Xil_ICacheEnable(void)
|
||||
{
|
||||
register u32 CtrlReg;
|
||||
|
||||
/* enable caches only if they are disabled */
|
||||
#if defined (__GNUC__)
|
||||
CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
|
||||
#elif defined (__ICCARM__)
|
||||
mfcp(XREG_CP15_SYS_CONTROL, CtrlReg);
|
||||
#endif
|
||||
if ((CtrlReg & XREG_CP15_CONTROL_I_BIT)==0x00000000U) {
|
||||
/* invalidate the instruction cache */
|
||||
mtcp(XREG_CP15_INVAL_IC_POU, 0);
|
||||
|
||||
/* enable the instruction cache */
|
||||
CtrlReg |= (XREG_CP15_CONTROL_I_BIT);
|
||||
|
||||
mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
|
||||
}
|
||||
}
|
||||
|
||||
void Xil_ICacheDisable(void)
|
||||
{
|
||||
register u32 CtrlReg;
|
||||
|
||||
dsb();
|
||||
|
||||
/* invalidate the instruction cache */
|
||||
mtcp(XREG_CP15_INVAL_IC_POU, 0);
|
||||
|
||||
/* disable the instruction cache */
|
||||
#if defined (__GNUC__)
|
||||
CtrlReg = mfcp(XREG_CP15_SYS_CONTROL);
|
||||
#elif defined (__ICCARM__)
|
||||
mfcp(XREG_CP15_SYS_CONTROL,CtrlReg);
|
||||
#endif
|
||||
|
||||
CtrlReg &= ~(XREG_CP15_CONTROL_I_BIT);
|
||||
|
||||
mtcp(XREG_CP15_SYS_CONTROL, CtrlReg);
|
||||
}
|
||||
|
||||
void Xil_ICacheInvalidate(void)
|
||||
{
|
||||
u32 currmask;
|
||||
|
||||
currmask = mfcpsr();
|
||||
mtcpsr(currmask | IRQ_FIQ_MASK);
|
||||
|
||||
mtcp(XREG_CP15_CACHE_SIZE_SEL, 1);
|
||||
|
||||
/* invalidate the instruction cache */
|
||||
mtcp(XREG_CP15_INVAL_IC_POU, 0);
|
||||
|
||||
/* Wait for invalidate to complete */
|
||||
dsb();
|
||||
mtcpsr(currmask);
|
||||
}
|
||||
|
||||
void Xil_ICacheInvalidateLine(INTPTR adr)
|
||||
{
|
||||
u32 currmask;
|
||||
|
||||
currmask = mfcpsr();
|
||||
mtcpsr(currmask | IRQ_FIQ_MASK);
|
||||
|
||||
mtcp(XREG_CP15_CACHE_SIZE_SEL, 1);
|
||||
mtcp(XREG_CP15_INVAL_IC_LINE_MVA_POU, (adr & (~0x1F)));
|
||||
|
||||
/* Wait for invalidate to complete */
|
||||
dsb();
|
||||
mtcpsr(currmask);
|
||||
}
|
||||
|
||||
void Xil_ICacheInvalidateRange(INTPTR adr, u32 len)
|
||||
{
|
||||
u32 LocalAddr = adr;
|
||||
const u32 cacheline = 32U;
|
||||
u32 end;
|
||||
u32 currmask;
|
||||
|
||||
currmask = mfcpsr();
|
||||
mtcpsr(currmask | IRQ_FIQ_MASK);
|
||||
if (len != 0x00000000U) {
|
||||
/* Back the starting address up to the start of a cache line
|
||||
* perform cache operations until adr+len
|
||||
*/
|
||||
end = LocalAddr + len;
|
||||
LocalAddr = LocalAddr & ~(cacheline - 1U);
|
||||
|
||||
/* Select cache L0 I-cache in CSSR */
|
||||
mtcp(XREG_CP15_CACHE_SIZE_SEL, 1U);
|
||||
|
||||
while (LocalAddr < end) {
|
||||
|
||||
/* Invalidate L1 I-cache line */
|
||||
asm_inval_ic_line_mva_pou(LocalAddr);
|
||||
|
||||
LocalAddr += cacheline;
|
||||
}
|
||||
}
|
||||
|
||||
/* Wait for invalidate to complete */
|
||||
dsb();
|
||||
mtcpsr(currmask);
|
||||
}
|
||||
|
||||
void rt_hw_cpu_icache_ops(int ops, void *addr, int size)
|
||||
{
|
||||
if (ops == RT_HW_CACHE_INVALIDATE)
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2020-03-19 WangHuachen first version
|
||||
* 2021-05-11 WangHuachen Added call to Xil_InitializeExistingMPURegConfig to
|
||||
* initialize the MPU configuration table with the MPU
|
||||
* configurations already set in Init_Mpu function.
|
||||
*/
|
||||
|
||||
.equ Mode_USR, 0x10
|
||||
@@ -234,6 +237,7 @@ ctor_loop:
|
||||
b ctor_loop
|
||||
ctor_end:
|
||||
|
||||
bl Xil_InitializeExistingMPURegConfig /* Initialize MPU config */
|
||||
/* start RT-Thread Kernel */
|
||||
ldr pc, _entry
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/******************************************************************************
|
||||
* Copyright (c) 2015 - 2020 Xilinx, Inc. All rights reserved.
|
||||
* SPDX-License-Identifier: MIT
|
||||
******************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @file xil_mmu.h
|
||||
* This file only includes xil_mpu.h which contains Xil_SetTlbAttributes API
|
||||
* defined for MPU in R5. R5 does not have mmu and for usage of similar API
|
||||
* the file has been created.
|
||||
*
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* MODIFICATION HISTORY:
|
||||
*
|
||||
* Ver Who Date Changes
|
||||
* ----- ---- -------- ---------------------------------------------------
|
||||
* 5.0 pkp 2/12/15 Initial version
|
||||
* </pre>
|
||||
*
|
||||
* @note
|
||||
*
|
||||
* None.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef XIL_MMU_H
|
||||
#define XIL_MMU_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/***************************** Include Files *********************************/
|
||||
|
||||
#include "xil_mpu.h"
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
|
||||
/**************************** Type Definitions *******************************/
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
|
||||
/************************** Variable Definitions *****************************/
|
||||
|
||||
/************************** Function Prototypes ******************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* XIL_MMU_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,129 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2014 - 2017 Xilinx, Inc. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @file xil_mmu.h
|
||||
*
|
||||
* @addtogroup r5_mpu_apis Cortex R5 Processor MPU specific APIs
|
||||
*
|
||||
* MPU functions provides access to MPU operations such as enable MPU, disable
|
||||
* MPU and set attribute for section of memory.
|
||||
* Boot code invokes Init_MPU function to configure the MPU. A total of 10 MPU
|
||||
* regions are allocated with another 6 being free for users. Overview of the
|
||||
* memory attributes for different MPU regions is as given below,
|
||||
*
|
||||
*| | Memory Range | Attributes of MPURegion |
|
||||
*|-----------------------|-------------------------|-----------------------------|
|
||||
*| DDR | 0x00000000 - 0x7FFFFFFF | Normal write-back Cacheable |
|
||||
*| PL | 0x80000000 - 0xBFFFFFFF | Strongly Ordered |
|
||||
*| QSPI | 0xC0000000 - 0xDFFFFFFF | Device Memory |
|
||||
*| PCIe | 0xE0000000 - 0xEFFFFFFF | Device Memory |
|
||||
*| STM_CORESIGHT | 0xF8000000 - 0xF8FFFFFF | Device Memory |
|
||||
*| RPU_R5_GIC | 0xF9000000 - 0xF90FFFFF | Device memory |
|
||||
*| FPS | 0xFD000000 - 0xFDFFFFFF | Device Memory |
|
||||
*| LPS | 0xFE000000 - 0xFFFFFFFF | Device Memory |
|
||||
*| OCM | 0xFFFC0000 - 0xFFFFFFFF | Normal write-back Cacheable |
|
||||
*
|
||||
*
|
||||
* @note
|
||||
* For a system where DDR is less than 2GB, region after DDR and before PL is
|
||||
* marked as undefined in translation table. Memory range 0xFE000000-0xFEFFFFFF is
|
||||
* allocated for upper LPS slaves, where as memory region 0xFF000000-0xFFFFFFFF is
|
||||
* allocated for lower LPS slaves.
|
||||
*
|
||||
* @{
|
||||
* <pre>
|
||||
* MODIFICATION HISTORY:
|
||||
*
|
||||
* Ver Who Date Changes
|
||||
* ----- ---- -------- ---------------------------------------------------
|
||||
* 5.00 pkp 02/10/14 Initial version
|
||||
* 6.4 asa 08/16/17 Added many APIs for MPU access to make MPU usage
|
||||
* user-friendly. The APIs added are: Xil_UpdateMPUConfig,
|
||||
* Xil_GetMPUConfig, Xil_GetNumOfFreeRegions,
|
||||
* Xil_GetNextMPURegion, Xil_DisableMPURegionByRegNum,
|
||||
* Xil_GetMPUFreeRegMask, Xil_SetMPURegionByRegNum, and
|
||||
* Xil_InitializeExistingMPURegConfig.
|
||||
* Added a new array of structure of type XMpuConfig to
|
||||
* represent the MPU configuration table.
|
||||
* </pre>
|
||||
*
|
||||
|
||||
*
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef XIL_MPU_H
|
||||
#define XIL_MPU_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#include "xil_types.h"
|
||||
/***************************** Include Files *********************************/
|
||||
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
#define MPU_REG_DISABLED 0U
|
||||
#define MPU_REG_ENABLED 1U
|
||||
#define MAX_POSSIBLE_MPU_REGS 16U
|
||||
/**************************** Type Definitions *******************************/
|
||||
struct XMpuConfig{
|
||||
u32 RegionStatus; /* Enabled or disabled */
|
||||
INTPTR BaseAddress;/* MPU region base address */
|
||||
u64 Size; /* MPU region size address */
|
||||
u32 Attribute; /* MPU region size attribute */
|
||||
};
|
||||
|
||||
typedef struct XMpuConfig XMpu_Config[MAX_POSSIBLE_MPU_REGS];
|
||||
|
||||
extern XMpu_Config Mpu_Config;
|
||||
/************************** Constant Definitions *****************************/
|
||||
|
||||
/************************** Variable Definitions *****************************/
|
||||
|
||||
/************************** Function Prototypes ******************************/
|
||||
|
||||
void Xil_SetTlbAttributes(INTPTR Addr, u32 attrib);
|
||||
void Xil_EnableMPU(void);
|
||||
void Xil_DisableMPU(void);
|
||||
u32 Xil_SetMPURegion(INTPTR addr, u64 size, u32 attrib);
|
||||
u32 Xil_UpdateMPUConfig(u32 reg_num, INTPTR address, u32 size, u32 attrib);
|
||||
void Xil_GetMPUConfig (XMpu_Config mpuconfig);
|
||||
u32 Xil_GetNumOfFreeRegions (void);
|
||||
u32 Xil_GetNextMPURegion(void);
|
||||
u32 Xil_DisableMPURegionByRegNum (u32 reg_num);
|
||||
u16 Xil_GetMPUFreeRegMask (void);
|
||||
u32 Xil_SetMPURegionByRegNum (u32 reg_num, INTPTR addr, u64 size, u32 attrib);
|
||||
void* Xil_MemMap(UINTPTR Physaddr, size_t size, u32 flags);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* XIL_MPU_H */
|
||||
/**
|
||||
* @} End of "addtogroup r5_mpu_apis".
|
||||
*/
|
||||
Reference in New Issue
Block a user