Browse Source

[bsp]support cvitek sdhci drvier (#8849)

support cvitek sdhci drvier
flyingcys 1 year ago
parent
commit
2c8c4ccc47

+ 4 - 0
bsp/cvitek/README.md

@@ -60,6 +60,10 @@ $ scons
 | i2c  | 支持 |  |
 | adc | 支持 |  |
 | spi | 支持 | 默认CS引脚,每个数据之间CS会拉高,请根据时序选择GPIO作为CS。若读取数据,tx需持续dummy数据。|
+| pwm | 支持 |  |
+| timer | 支持 |  |
+| wdt | 支持 |  |
+| sdio | 支持 |  |
 
 ## 支持开发板
 - milk-v duo: [https://milkv.io/duo](https://milkv.io/duo)

+ 172 - 41
bsp/cvitek/cv18xx_risc-v/.config

@@ -1,7 +1,3 @@
-#
-# Automatically generated file; DO NOT EDIT.
-# RT-Thread Project Configuration
-#
 
 #
 # RT-Thread Kernel
@@ -33,11 +29,17 @@ CONFIG_RT_TIMER_THREAD_STACK_SIZE=8192
 #
 # kservice optimization
 #
-CONFIG_RT_KSERVICE_USING_STDLIB=y
-# CONFIG_RT_KSERVICE_USING_STDLIB_MEMORY is not set
-# CONFIG_RT_KSERVICE_USING_TINY_SIZE is not set
 # CONFIG_RT_USING_TINY_FFS is not set
-CONFIG_RT_KPRINTF_USING_LONGLONG=y
+# end of kservice optimization
+
+#
+# klibc optimization
+#
+# CONFIG_RT_KLIBC_USING_STDLIB is not set
+# CONFIG_RT_KLIBC_USING_TINY_SIZE is not set
+CONFIG_RT_KLIBC_USING_PRINTF_LONGLONG=y
+# end of klibc optimization
+
 CONFIG_RT_USING_DEBUG=y
 CONFIG_RT_DEBUGING_COLOR=y
 CONFIG_RT_DEBUGING_CONTEXT=y
@@ -54,6 +56,7 @@ CONFIG_RT_USING_MAILBOX=y
 CONFIG_RT_USING_MESSAGEQUEUE=y
 # CONFIG_RT_USING_MESSAGEQUEUE_PRIORITY is not set
 # CONFIG_RT_USING_SIGNALS is not set
+# end of Inter-Thread communication
 
 #
 # Memory Management
@@ -71,6 +74,8 @@ CONFIG_RT_USING_SMALL_MEM_AS_HEAP=y
 # CONFIG_RT_USING_MEMTRACE is not set
 # CONFIG_RT_USING_HEAP_ISR is not set
 CONFIG_RT_USING_HEAP=y
+# end of Memory Management
+
 CONFIG_RT_USING_DEVICE=y
 CONFIG_RT_USING_DEVICE_OPS=y
 # CONFIG_RT_USING_INTERRUPT_INFO is not set
@@ -79,15 +84,13 @@ CONFIG_RT_USING_DEVICE_OPS=y
 CONFIG_RT_USING_CONSOLE=y
 CONFIG_RT_CONSOLEBUF_SIZE=256
 CONFIG_RT_CONSOLE_DEVICE_NAME="uart0"
-CONFIG_RT_VER_NUM=0x50100
+CONFIG_RT_VER_NUM=0x50200
 CONFIG_RT_USING_STDC_ATOMIC=y
 CONFIG_RT_BACKTRACE_LEVEL_MAX_NR=32
+# end of RT-Thread Kernel
+
 CONFIG_ARCH_CPU_64BIT=y
 CONFIG_RT_USING_CACHE=y
-# CONFIG_RT_USING_HW_ATOMIC is not set
-# CONFIG_ARCH_ARM_BOOTWITH_FLUSH_CACHE is not set
-# CONFIG_ARCH_CPU_STACK_GROWS_UPWARD is not set
-# CONFIG_RT_USING_CPU_FFS is not set
 CONFIG_ARCH_MM_MMU=y
 CONFIG_ARCH_RISCV=y
 CONFIG_ARCH_RISCV64=y
@@ -126,12 +129,40 @@ CONFIG_DFS_USING_WORKDIR=y
 CONFIG_DFS_FD_MAX=16
 # CONFIG_RT_USING_DFS_V1 is not set
 CONFIG_RT_USING_DFS_V2=y
-# CONFIG_RT_USING_DFS_ELMFAT is not set
+CONFIG_RT_USING_DFS_ELMFAT=y
+
+#
+# elm-chan's FatFs, Generic FAT Filesystem Module
+#
+CONFIG_RT_DFS_ELM_CODE_PAGE=437
+CONFIG_RT_DFS_ELM_WORD_ACCESS=y
+# CONFIG_RT_DFS_ELM_USE_LFN_0 is not set
+# CONFIG_RT_DFS_ELM_USE_LFN_1 is not set
+# 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
+# CONFIG_RT_DFS_ELM_USE_ERASE is not set
+CONFIG_RT_DFS_ELM_REENTRANT=y
+CONFIG_RT_DFS_ELM_MUTEX_TIMEOUT=3000
+# CONFIG_RT_DFS_ELM_USE_EXFAT is not set
+# end of elm-chan's FatFs, Generic FAT Filesystem Module
+
 CONFIG_RT_USING_DFS_DEVFS=y
-# CONFIG_RT_USING_DFS_ROMFS is not set
+CONFIG_RT_USING_DFS_ROMFS=y
+# CONFIG_RT_USING_DFS_ROMFS_USER_ROOT is not set
 # CONFIG_RT_USING_DFS_CROMFS is not set
 # CONFIG_RT_USING_DFS_TMPFS is not set
 # CONFIG_RT_USING_DFS_MQUEUE is not set
+# end of DFS: device virtual file system
+
 # CONFIG_RT_USING_FAL is not set
 
 #
@@ -164,7 +195,13 @@ CONFIG_RT_USING_RANDOM=y
 CONFIG_RT_USING_RTC=y
 # CONFIG_RT_USING_ALARM is not set
 # CONFIG_RT_USING_SOFT_RTC is not set
-# CONFIG_RT_USING_SDIO is not set
+CONFIG_RT_USING_SDIO=y
+CONFIG_RT_SDIO_STACK_SIZE=4096
+CONFIG_RT_SDIO_THREAD_PRIORITY=15
+CONFIG_RT_MMCSD_STACK_SIZE=4096
+CONFIG_RT_MMCSD_THREAD_PREORITY=22
+CONFIG_RT_MMCSD_MAX_PARTITION=16
+# CONFIG_RT_SDIO_DEBUG is not set
 # CONFIG_RT_USING_SPI is not set
 # CONFIG_RT_USING_WDT is not set
 # CONFIG_RT_USING_AUDIO is not set
@@ -184,9 +221,10 @@ CONFIG_RT_USING_KTIME=y
 #
 # Using USB
 #
-# CONFIG_RT_USING_USB is not set
 # CONFIG_RT_USING_USB_HOST is not set
 # CONFIG_RT_USING_USB_DEVICE is not set
+# end of Using USB
+# end of Device Drivers
 
 #
 # C/C++ and POSIX layer
@@ -204,6 +242,8 @@ CONFIG_RT_LIBC_USING_LIGHT_TZ_DST=y
 CONFIG_RT_LIBC_TZ_DEFAULT_HOUR=8
 CONFIG_RT_LIBC_TZ_DEFAULT_MIN=0
 CONFIG_RT_LIBC_TZ_DEFAULT_SEC=0
+# end of Timezone and Daylight Saving Time
+# end of ISO-ANSI C layer
 
 #
 # POSIX (Portable Operating System Interface) layer
@@ -235,7 +275,11 @@ CONFIG_RT_USING_POSIX_TIMER=y
 #
 # Socket is in the 'Network' category
 #
+# end of Interprocess Communication (IPC)
+# end of POSIX (Portable Operating System Interface) layer
+
 # CONFIG_RT_USING_CPLUSPLUS is not set
+# end of C/C++ and POSIX layer
 
 #
 # Network
@@ -244,12 +288,14 @@ CONFIG_RT_USING_POSIX_TIMER=y
 # CONFIG_RT_USING_NETDEV is not set
 # CONFIG_RT_USING_LWIP is not set
 # CONFIG_RT_USING_AT is not set
+# end of Network
 
 #
 # Memory protection
 #
 # CONFIG_RT_USING_MEM_PROTECTION is not set
 # CONFIG_RT_USING_HW_STACK_GUARD is not set
+# end of Memory protection
 
 #
 # Utilities
@@ -265,12 +311,16 @@ CONFIG_RT_USING_ADT_BITMAP=y
 CONFIG_RT_USING_ADT_HASHMAP=y
 CONFIG_RT_USING_ADT_REF=y
 # CONFIG_RT_USING_RT_LINK is not set
+# end of Utilities
+
 # CONFIG_RT_USING_VBUS is not set
+# end of RT-Thread Components
 
 #
 # RT-Thread Utestcases
 #
 # CONFIG_RT_USING_UTESTCASES is not set
+# end of RT-Thread Utestcases
 
 #
 # RT-Thread online packages
@@ -279,7 +329,6 @@ CONFIG_RT_USING_ADT_REF=y
 #
 # IoT - internet of things
 #
-# CONFIG_PKG_USING_LWIP is not set
 # CONFIG_PKG_USING_LORAWAN_DRIVER is not set
 # CONFIG_PKG_USING_PAHOMQTT is not set
 # CONFIG_PKG_USING_UMQTT is not set
@@ -301,27 +350,35 @@ CONFIG_RT_USING_ADT_REF=y
 # Marvell WiFi
 #
 # CONFIG_PKG_USING_WLANMARVELL is not set
+# end of Marvell WiFi
 
 #
 # Wiced WiFi
 #
 # CONFIG_PKG_USING_WLAN_WICED is not set
+# end of Wiced WiFi
+
 # CONFIG_PKG_USING_RW007 is not set
 
 #
 # CYW43012 WiFi
 #
 # CONFIG_PKG_USING_WLAN_CYW43012 is not set
+# end of CYW43012 WiFi
 
 #
 # BL808 WiFi
 #
 # CONFIG_PKG_USING_WLAN_BL808 is not set
+# end of BL808 WiFi
 
 #
 # CYW43439 WiFi
 #
 # CONFIG_PKG_USING_WLAN_CYW43439 is not set
+# end of CYW43439 WiFi
+# end of Wi-Fi
+
 # CONFIG_PKG_USING_COAP is not set
 # CONFIG_PKG_USING_NOPOLL is not set
 # CONFIG_PKG_USING_NETUTILS is not set
@@ -344,6 +401,8 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_UCLOUD_IOT_SDK is not set
 # CONFIG_PKG_USING_JOYLINK is not set
 # CONFIG_PKG_USING_IOTSHARP_SDK is not set
+# end of IoT Cloud
+
 # CONFIG_PKG_USING_NIMBLE is not set
 # CONFIG_PKG_USING_LLSYNC_SDK_ADAPTER is not set
 # CONFIG_PKG_USING_OTA_DOWNLOADER is not set
@@ -364,6 +423,7 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_PDULIB is not set
 # CONFIG_PKG_USING_BTSTACK is not set
 # CONFIG_PKG_USING_BT_CYW43012 is not set
+# CONFIG_PKG_USING_CYW43XX 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
@@ -385,6 +445,7 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_ZEPHYR_POLLING is not set
 # CONFIG_PKG_USING_MATTER_ADAPTATION_LAYER is not set
 # CONFIG_PKG_USING_LHC_MODBUS is not set
+# end of IoT - internet of things
 
 #
 # security packages
@@ -395,6 +456,7 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_TINYCRYPT is not set
 # CONFIG_PKG_USING_TFM is not set
 # CONFIG_PKG_USING_YD_CRYPTO is not set
+# end of security packages
 
 #
 # language packages
@@ -410,18 +472,22 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_JSMN is not set
 # CONFIG_PKG_USING_AGILE_JSMN is not set
 # CONFIG_PKG_USING_PARSON is not set
+# end of JSON: JavaScript Object Notation, a lightweight data-interchange format
 
 #
 # XML: Extensible Markup Language
 #
 # CONFIG_PKG_USING_SIMPLE_XML is not set
 # CONFIG_PKG_USING_EZXML is not set
+# end of XML: Extensible Markup Language
+
 # CONFIG_PKG_USING_LUATOS_SOC is not set
 # CONFIG_PKG_USING_LUA is not set
 # CONFIG_PKG_USING_JERRYSCRIPT is not set
 # CONFIG_PKG_USING_MICROPYTHON is not set
 # CONFIG_PKG_USING_PIKASCRIPT is not set
 # CONFIG_PKG_USING_RTT_RUST is not set
+# end of language packages
 
 #
 # multimedia packages
@@ -433,12 +499,15 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_LVGL is not set
 # CONFIG_PKG_USING_LV_MUSIC_DEMO is not set
 # CONFIG_PKG_USING_GUI_GUIDER_DEMO is not set
+# end of LVGL: powerful and easy-to-use embedded GUI library
 
 #
 # u8g2: a monochrome graphic library
 #
 # CONFIG_PKG_USING_U8G2_OFFICIAL is not set
 # CONFIG_PKG_USING_U8G2 is not set
+# end of u8g2: a monochrome graphic library
+
 # CONFIG_PKG_USING_OPENMV is not set
 # CONFIG_PKG_USING_MUPDF is not set
 # CONFIG_PKG_USING_STEMWIN is not set
@@ -458,6 +527,7 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_QRCODE is not set
 # CONFIG_PKG_USING_GUIENGINE is not set
 # CONFIG_PKG_USING_3GPP_AMRNB is not set
+# end of multimedia packages
 
 #
 # tools packages
@@ -506,6 +576,7 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_ARMV7M_DWT_TOOL is not set
 # CONFIG_PKG_USING_VOFA_PLUS is not set
 # CONFIG_PKG_USING_ZDEBUG is not set
+# end of tools packages
 
 #
 # system packages
@@ -517,6 +588,7 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_RT_MEMCPY_CM is not set
 # CONFIG_PKG_USING_RT_KPRINTF_THREADSAFE is not set
 # CONFIG_PKG_USING_RT_VSNPRINTF_FULL is not set
+# end of enhanced kernel services
 
 #
 # acceleration: Assembly language or algorithmic acceleration packages
@@ -524,13 +596,18 @@ CONFIG_RT_USING_ADT_REF=y
 # 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
+# end of acceleration: Assembly language or algorithmic acceleration packages
 
 #
 # CMSIS: ARM Cortex-M Microcontroller Software Interface Standard
 #
 # CONFIG_PKG_USING_CMSIS_5 is not set
+# CONFIG_PKG_USING_CMSIS_CORE is not set
+# CONFIG_PKG_USING_CMSIS_DSP is not set
+# CONFIG_PKG_USING_CMSIS_NN is not set
 # CONFIG_PKG_USING_CMSIS_RTOS1 is not set
 # CONFIG_PKG_USING_CMSIS_RTOS2 is not set
+# end of CMSIS: ARM Cortex-M Microcontroller Software Interface Standard
 
 #
 # Micrium: Micrium software products porting for RT-Thread
@@ -541,6 +618,8 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_UC_CLK is not set
 # CONFIG_PKG_USING_UC_COMMON is not set
 # CONFIG_PKG_USING_UC_MODBUS is not set
+# end of Micrium: Micrium software products porting for RT-Thread
+
 # CONFIG_PKG_USING_FREERTOS_WRAPPER is not set
 # CONFIG_PKG_USING_LITEOS_SDK is not set
 # CONFIG_PKG_USING_TZ_DATABASE is not set
@@ -548,6 +627,8 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_PIXMAN is not set
 # CONFIG_PKG_USING_PARTITION is not set
 # CONFIG_PKG_USING_PERF_COUNTER is not set
+# CONFIG_PKG_USING_FILEX is not set
+# CONFIG_PKG_USING_LEVELX is not set
 # CONFIG_PKG_USING_FLASHDB is not set
 # CONFIG_PKG_USING_SQLITE is not set
 # CONFIG_PKG_USING_RTI is not set
@@ -586,11 +667,41 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_RTP is not set
 # CONFIG_PKG_USING_REB is not set
 # CONFIG_PKG_USING_R_RHEALSTONE is not set
+# end of system packages
 
 #
 # peripheral libraries and drivers
 #
 
+#
+# HAL & SDK Drivers
+#
+
+#
+# STM32 HAL & SDK Drivers
+#
+# CONFIG_PKG_USING_STM32L4XX_HAL_DRIVER is not set
+# CONFIG_PKG_USING_STM32WB55_SDK is not set
+# CONFIG_PKG_USING_STM32_SDIO is not set
+# end of STM32 HAL & SDK Drivers
+
+# CONFIG_PKG_USING_BLUETRUM_SDK is not set
+# CONFIG_PKG_USING_EMBARC_BSP is not set
+# CONFIG_PKG_USING_ESP_IDF is not set
+
+#
+# Kendryte SDK
+#
+# CONFIG_PKG_USING_K210_SDK is not set
+# CONFIG_PKG_USING_KENDRYTE_SDK is not set
+# end of Kendryte SDK
+
+# CONFIG_PKG_USING_NRF5X_SDK is not set
+# CONFIG_PKG_USING_NRFX is not set
+# CONFIG_PKG_USING_NUCLEI_SDK is not set
+# CONFIG_PKG_USING_RASPBERRYPI_PICO_SDK is not set
+# end of HAL & SDK Drivers
+
 #
 # sensors drivers
 #
@@ -659,6 +770,7 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_ICM20608 is not set
 # CONFIG_PKG_USING_PAJ7620 is not set
 # CONFIG_PKG_USING_STHS34PF80 is not set
+# end of sensors drivers
 
 #
 # touch drivers
@@ -672,9 +784,10 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_FT6236 is not set
 # CONFIG_PKG_USING_XPT2046_TOUCH is not set
 # CONFIG_PKG_USING_CST816X is not set
+# CONFIG_PKG_USING_CST812T is not set
+# end of touch drivers
+
 # CONFIG_PKG_USING_REALTEK_AMEBA is not set
-# CONFIG_PKG_USING_STM32_SDIO is not set
-# CONFIG_PKG_USING_ESP_IDF is not set
 # CONFIG_PKG_USING_BUTTON is not set
 # CONFIG_PKG_USING_PCF8574 is not set
 # CONFIG_PKG_USING_SX12XX is not set
@@ -682,14 +795,6 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_LEDBLINK is not set
 # CONFIG_PKG_USING_LITTLED is not set
 # CONFIG_PKG_USING_LKDGUI is not set
-# CONFIG_PKG_USING_NRF5X_SDK is not set
-# CONFIG_PKG_USING_NRFX is not set
-
-#
-# Kendryte SDK
-#
-# CONFIG_PKG_USING_K210_SDK is not set
-# CONFIG_PKG_USING_KENDRYTE_SDK is not set
 # CONFIG_PKG_USING_INFRARED is not set
 # CONFIG_PKG_USING_MULTI_INFRARED is not set
 # CONFIG_PKG_USING_AGILE_BUTTON is not set
@@ -704,14 +809,12 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_AS608 is not set
 # CONFIG_PKG_USING_RC522 is not set
 # CONFIG_PKG_USING_WS2812B is not set
-# CONFIG_PKG_USING_EMBARC_BSP is not set
 # CONFIG_PKG_USING_EXTERN_RTC_DRIVERS is not set
 # CONFIG_PKG_USING_MULTI_RTIMER is not set
 # CONFIG_PKG_USING_MAX7219 is not set
 # CONFIG_PKG_USING_BEEP is not set
 # CONFIG_PKG_USING_EASYBLINK is not set
 # CONFIG_PKG_USING_PMS_SERIES is not set
-# CONFIG_PKG_USING_NUCLEI_SDK is not set
 # CONFIG_PKG_USING_CAN_YMODEM is not set
 # CONFIG_PKG_USING_LORA_RADIO_DRIVER is not set
 # CONFIG_PKG_USING_QLED is not set
@@ -728,7 +831,6 @@ CONFIG_RT_USING_ADT_REF=y
 # 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
@@ -738,7 +840,6 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_ROSSERIAL is not set
 # CONFIG_PKG_USING_MICRO_ROS is not set
 # CONFIG_PKG_USING_MCP23008 is not set
-# CONFIG_PKG_USING_BLUETRUM_SDK is not set
 # CONFIG_PKG_USING_MISAKA_AT24CXX is not set
 # CONFIG_PKG_USING_MISAKA_RGB_BLING is not set
 # CONFIG_PKG_USING_LORA_MODEM_DRIVER is not set
@@ -746,7 +847,6 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_MB85RS16 is not set
 # CONFIG_PKG_USING_RFM300 is not set
 # CONFIG_PKG_USING_IO_INPUT_FILTER is not set
-# CONFIG_PKG_USING_RASPBERRYPI_PICO_SDK is not set
 # CONFIG_PKG_USING_LRF_NV7LIDAR is not set
 # CONFIG_PKG_USING_AIP650 is not set
 # CONFIG_PKG_USING_FINGERPRINT is not set
@@ -756,7 +856,10 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_VS1003 is not set
 # CONFIG_PKG_USING_X9555 is not set
 # CONFIG_PKG_USING_SYSTEM_RUN_LED is not set
+# CONFIG_PKG_USING_BT_MX01 is not set
+# CONFIG_PKG_USING_RGPOWER is not set
 # CONFIG_PKG_USING_SPI_TOOLS is not set
+# end of peripheral libraries and drivers
 
 #
 # AI packages
@@ -771,6 +874,7 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_QUEST is not set
 # CONFIG_PKG_USING_NAXOS is not set
 # CONFIG_PKG_USING_R_TINYMAIX is not set
+# end of AI packages
 
 #
 # Signal Processing and Control Algorithm Packages
@@ -780,6 +884,7 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_UKAL is not set
 # CONFIG_PKG_USING_DIGITALCTRL is not set
 # CONFIG_PKG_USING_KISSFFT is not set
+# end of Signal Processing and Control Algorithm Packages
 
 #
 # miscellaneous packages
@@ -788,6 +893,7 @@ CONFIG_RT_USING_ADT_REF=y
 #
 # project laboratory
 #
+# end of project laboratory
 
 #
 # samples: kernel and components samples
@@ -796,6 +902,7 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_FILESYSTEM_SAMPLES is not set
 # CONFIG_PKG_USING_NETWORK_SAMPLES is not set
 # CONFIG_PKG_USING_PERIPHERAL_SAMPLES is not set
+# end of samples: kernel and components samples
 
 #
 # entertainment: terminal games and other interesting software packages
@@ -811,6 +918,8 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_DONUT is not set
 # CONFIG_PKG_USING_COWSAY is not set
 # CONFIG_PKG_USING_MORSE is not set
+# end of entertainment: terminal games and other interesting software packages
+
 # CONFIG_PKG_USING_LIBCSV is not set
 # CONFIG_PKG_USING_OPTPARSE is not set
 # CONFIG_PKG_USING_FASTLZ is not set
@@ -844,6 +953,7 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_SOEM is not set
 # CONFIG_PKG_USING_QPARAM is not set
 # CONFIG_PKG_USING_CorevMCU_CLI is not set
+# end of miscellaneous packages
 
 #
 # Arduino libraries
@@ -854,21 +964,24 @@ CONFIG_RT_USING_ADT_REF=y
 # Projects and Demos
 #
 # CONFIG_PKG_USING_ARDUINO_MSGQ_C_CPP_DEMO is not set
+# CONFIG_PKG_USING_ARDUINO_SKETCH_LOADER_DEMO is not set
 # CONFIG_PKG_USING_ARDUINO_ULTRASOUND_RADAR is not set
+# CONFIG_PKG_USING_ARDUINO_NINEINONE_SENSOR_SHIELD is not set
 # CONFIG_PKG_USING_ARDUINO_SENSOR_KIT is not set
 # CONFIG_PKG_USING_ARDUINO_MATLAB_SUPPORT is not set
+# end of Projects and Demos
 
 #
 # Sensors
 #
 # CONFIG_PKG_USING_ARDUINO_SENSOR_DEVICE_DRIVERS is not set
-# CONFIG_PKG_USING_ARDUINO_CAPACITIVESENSOR is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SENSOR is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SENSORLAB is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_ADXL375 is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_VL53L0X is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_VL53L1X is not set
-# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SENSOR is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_VL6180X is not set
-# CONFIG_PKG_USING_ADAFRUIT_MAX31855 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MAX31855 is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MAX31865 is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MAX31856 is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MAX6675 is not set
@@ -913,7 +1026,7 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_LIS3MDL is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MLX90640 is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MMA8451 is not set
-# CONFIG_PKG_USING_ADAFRUIT_MSA301 is not set
+# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MSA301 is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MPL115A2 is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_BNO08X is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_BNO08X_RVC is not set
@@ -952,7 +1065,6 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_HTU21DF is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_AS7341 is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_HTU31D is not set
-# CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SENSORLAB is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_INA260 is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_TMP007_LIBRARY is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_L3GD20 is not set
@@ -975,7 +1087,7 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_ARDUINO_SEEED_TSL2561 is not set
 # CONFIG_PKG_USING_ARDUINO_SEEED_PAJ7620 is not set
 # CONFIG_PKG_USING_ARDUINO_SEEED_VL53L0X is not set
-# CONFIG_PKG_USING_SEEED_ITG3200 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_ITG3200 is not set
 # CONFIG_PKG_USING_ARDUINO_SEEED_SHT31 is not set
 # CONFIG_PKG_USING_ARDUINO_SEEED_HP20X is not set
 # CONFIG_PKG_USING_ARDUINO_SEEED_DRV2605L is not set
@@ -983,7 +1095,7 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_ARDUINO_SEEED_HMC5883L is not set
 # CONFIG_PKG_USING_ARDUINO_SEEED_LSM303DLH is not set
 # CONFIG_PKG_USING_ARDUINO_SEEED_TCS3414CS is not set
-# CONFIG_PKG_USING_SEEED_MP503 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_MP503 is not set
 # CONFIG_PKG_USING_ARDUINO_SEEED_BMP085 is not set
 # CONFIG_PKG_USING_ARDUINO_SEEED_HIGHTEMP is not set
 # CONFIG_PKG_USING_ARDUINO_SEEED_VEML6070 is not set
@@ -996,6 +1108,9 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_ARDUINO_SEEED_MCP9600 is not set
 # CONFIG_PKG_USING_ARDUINO_SEEED_LTC2941 is not set
 # CONFIG_PKG_USING_ARDUINO_SEEED_LDC1612 is not set
+# CONFIG_PKG_USING_ARDUINO_CAPACITIVESENSOR is not set
+# CONFIG_PKG_USING_ARDUINO_JARZEBSKI_MPU6050 is not set
+# end of Sensors
 
 #
 # Display
@@ -1007,6 +1122,7 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SSD1306 is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_ILI9341 is not set
 # CONFIG_PKG_USING_SEEED_TM1637 is not set
+# end of Display
 
 #
 # Timing
@@ -1015,12 +1131,16 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_ARDUINO_MSTIMER2 is not set
 # CONFIG_PKG_USING_ARDUINO_TICKER is not set
 # CONFIG_PKG_USING_ARDUINO_TASKSCHEDULER is not set
+# end of Timing
 
 #
 # Data Processing
 #
 # CONFIG_PKG_USING_ARDUINO_KALMANFILTER is not set
 # CONFIG_PKG_USING_ARDUINO_ARDUINOJSON is not set
+# CONFIG_PKG_USING_ARDUINO_TENSORFLOW_LITE_MICRO is not set
+# CONFIG_PKG_USING_ARDUINO_RUNNINGMEDIAN is not set
+# end of Data Processing
 
 #
 # Data Storage
@@ -1031,23 +1151,26 @@ CONFIG_RT_USING_ADT_REF=y
 #
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_PN532 is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SI4713 is not set
+# end of Communication
 
 #
 # Device Control
 #
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_PCF8574 is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_PCA9685 is not set
-# CONFIG_PKG_USING_ARDUINO_SEEED_PCF85063TP is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_TPA2016 is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_DRV2605 is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_DS1841 is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_DS3502 is not set
+# CONFIG_PKG_USING_ARDUINO_SEEED_PCF85063TP is not set
+# end of Device Control
 
 #
 # Other
 #
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MFRC630 is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_SI5351 is not set
+# end of Other
 
 #
 # Signal IO
@@ -1060,10 +1183,13 @@ CONFIG_RT_USING_ADT_REF=y
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MCP3008 is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_MCP4725 is not set
 # CONFIG_PKG_USING_ARDUINO_ADAFRUIT_BD3491FS is not set
+# end of Signal IO
 
 #
 # Uncategorized
 #
+# end of Arduino libraries
+# end of RT-Thread online packages
 
 #
 # General Drivers Configuration
@@ -1078,10 +1204,15 @@ CONFIG_UART_IRQ_BASE=44
 # CONFIG_BSP_USING_ADC is not set
 # CONFIG_BSP_USING_SPI is not set
 # CONFIG_BSP_USING_PWM is not set
+# CONFIG_BSP_USING_SDH is not set
+# end of General Drivers Configuration
+
 CONFIG_BSP_USING_CV18XX=y
 CONFIG_C906_PLIC_PHY_ADDR=0x70000000
 CONFIG_IRQ_MAX_NR=64
 CONFIG_TIMER_CLK_FREQ=25000000
 CONFIG___STACKSIZE__=8192
 # CONFIG_BOARD_TYPE_MILKV_DUO is not set
+# CONFIG_BOARD_TYPE_MILKV_DUO_SPINOR is not set
 CONFIG_BOARD_TYPE_MILKV_DUO256M=y
+# CONFIG_BOARD_TYPE_MILKV_DUO256M_SPINOR is not set

+ 8 - 0
bsp/cvitek/cv18xx_risc-v/board/Kconfig

@@ -66,4 +66,12 @@ menu "General Drivers Configuration"
             
         endif
 
+    config BSP_USING_SDH
+        select RT_USING_SDIO
+        select RT_USING_DFS
+        select RT_USING_DFS_ELMFAT
+        select RT_USING_DFS_ROMFS
+        bool "Enable Secure Digital Host Controller"
+        default n
+        
 endmenu

+ 101 - 9
bsp/cvitek/cv18xx_risc-v/rtconfig.h

@@ -1,9 +1,6 @@
 #ifndef RT_CONFIG_H__
 #define RT_CONFIG_H__
 
-/* Automatically generated file; DO NOT EDIT. */
-/* RT-Thread Project Configuration */
-
 /* RT-Thread Kernel */
 
 #define RT_NAME_MAX 8
@@ -24,8 +21,12 @@
 
 /* kservice optimization */
 
-#define RT_KSERVICE_USING_STDLIB
-#define RT_KPRINTF_USING_LONGLONG
+/* end of kservice optimization */
+
+/* klibc optimization */
+
+#define RT_KLIBC_USING_PRINTF_LONGLONG
+/* end of klibc optimization */
 #define RT_USING_DEBUG
 #define RT_DEBUGING_COLOR
 #define RT_DEBUGING_CONTEXT
@@ -37,6 +38,7 @@
 #define RT_USING_EVENT
 #define RT_USING_MAILBOX
 #define RT_USING_MESSAGEQUEUE
+/* end of Inter-Thread communication */
 
 /* Memory Management */
 
@@ -45,14 +47,16 @@
 #define RT_USING_SMALL_MEM
 #define RT_USING_SMALL_MEM_AS_HEAP
 #define RT_USING_HEAP
+/* end of Memory Management */
 #define RT_USING_DEVICE
 #define RT_USING_DEVICE_OPS
 #define RT_USING_CONSOLE
 #define RT_CONSOLEBUF_SIZE 256
 #define RT_CONSOLE_DEVICE_NAME "uart0"
-#define RT_VER_NUM 0x50100
+#define RT_VER_NUM 0x50200
 #define RT_USING_STDC_ATOMIC
 #define RT_BACKTRACE_LEVEL_MAX_NR 32
+/* end of RT-Thread Kernel */
 #define ARCH_CPU_64BIT
 #define RT_USING_CACHE
 #define ARCH_MM_MMU
@@ -87,7 +91,25 @@
 #define DFS_USING_WORKDIR
 #define DFS_FD_MAX 16
 #define RT_USING_DFS_V2
+#define RT_USING_DFS_ELMFAT
+
+/* elm-chan's FatFs, Generic FAT Filesystem Module */
+
+#define RT_DFS_ELM_CODE_PAGE 437
+#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
+#define RT_DFS_ELM_REENTRANT
+#define RT_DFS_ELM_MUTEX_TIMEOUT 3000
+/* end of elm-chan's FatFs, Generic FAT Filesystem Module */
 #define RT_USING_DFS_DEVFS
+#define RT_USING_DFS_ROMFS
+/* end of DFS: device virtual file system */
 
 /* Device Drivers */
 
@@ -104,11 +126,19 @@
 #define RT_USING_ZERO
 #define RT_USING_RANDOM
 #define RT_USING_RTC
+#define RT_USING_SDIO
+#define RT_SDIO_STACK_SIZE 4096
+#define RT_SDIO_THREAD_PRIORITY 15
+#define RT_MMCSD_STACK_SIZE 4096
+#define RT_MMCSD_THREAD_PREORITY 22
+#define RT_MMCSD_MAX_PARTITION 16
 #define RT_USING_PIN
 #define RT_USING_KTIME
 
 /* Using USB */
 
+/* end of Using USB */
+/* end of Device Drivers */
 
 /* C/C++ and POSIX layer */
 
@@ -120,6 +150,8 @@
 #define RT_LIBC_TZ_DEFAULT_HOUR 8
 #define RT_LIBC_TZ_DEFAULT_MIN 0
 #define RT_LIBC_TZ_DEFAULT_SEC 0
+/* end of Timezone and Daylight Saving Time */
+/* end of ISO-ANSI C layer */
 
 /* POSIX (Portable Operating System Interface) layer */
 
@@ -137,12 +169,17 @@
 
 /* Socket is in the 'Network' category */
 
+/* end of Interprocess Communication (IPC) */
+/* end of POSIX (Portable Operating System Interface) layer */
+/* end of C/C++ and POSIX layer */
 
 /* Network */
 
+/* end of Network */
 
 /* Memory protection */
 
+/* end of Memory protection */
 
 /* Utilities */
 
@@ -152,9 +189,12 @@
 #define RT_USING_ADT_BITMAP
 #define RT_USING_ADT_HASHMAP
 #define RT_USING_ADT_REF
+/* end of Utilities */
+/* end of RT-Thread Components */
 
 /* RT-Thread Utestcases */
 
+/* end of RT-Thread Utestcases */
 
 /* RT-Thread online packages */
 
@@ -165,124 +205,176 @@
 
 /* Marvell WiFi */
 
+/* end of Marvell WiFi */
 
 /* Wiced WiFi */
 
+/* end of Wiced WiFi */
 
 /* CYW43012 WiFi */
 
+/* end of CYW43012 WiFi */
 
 /* BL808 WiFi */
 
+/* end of BL808 WiFi */
 
 /* CYW43439 WiFi */
 
+/* end of CYW43439 WiFi */
+/* end of Wi-Fi */
 
 /* IoT Cloud */
 
+/* end of IoT Cloud */
+/* end of IoT - internet of things */
 
 /* security packages */
 
+/* end of security packages */
 
 /* language packages */
 
 /* JSON: JavaScript Object Notation, a lightweight data-interchange format */
 
+/* end of JSON: JavaScript Object Notation, a lightweight data-interchange format */
 
 /* XML: Extensible Markup Language */
 
+/* end of XML: Extensible Markup Language */
+/* end of language packages */
 
 /* multimedia packages */
 
 /* LVGL: powerful and easy-to-use embedded GUI library */
 
+/* end of LVGL: powerful and easy-to-use embedded GUI library */
 
 /* u8g2: a monochrome graphic library */
 
+/* end of u8g2: a monochrome graphic library */
+/* end of multimedia packages */
 
 /* tools packages */
 
+/* end of tools packages */
 
 /* system packages */
 
 /* enhanced kernel services */
 
+/* end of enhanced kernel services */
 
 /* acceleration: Assembly language or algorithmic acceleration packages */
 
+/* end of acceleration: Assembly language or algorithmic acceleration packages */
 
 /* CMSIS: ARM Cortex-M Microcontroller Software Interface Standard */
 
+/* end of CMSIS: ARM Cortex-M Microcontroller Software Interface Standard */
 
 /* Micrium: Micrium software products porting for RT-Thread */
 
+/* end of Micrium: Micrium software products porting for RT-Thread */
+/* end of system packages */
 
 /* peripheral libraries and drivers */
 
-/* sensors drivers */
+/* HAL & SDK Drivers */
 
+/* STM32 HAL & SDK Drivers */
 
-/* touch drivers */
-
+/* end of STM32 HAL & SDK Drivers */
 
 /* Kendryte SDK */
 
+/* end of Kendryte SDK */
+/* end of HAL & SDK Drivers */
+
+/* sensors drivers */
+
+/* end of sensors drivers */
+
+/* touch drivers */
+
+/* end of touch drivers */
+/* end of peripheral libraries and drivers */
 
 /* AI packages */
 
+/* end of AI packages */
 
 /* Signal Processing and Control Algorithm Packages */
 
+/* end of Signal Processing and Control Algorithm Packages */
 
 /* miscellaneous packages */
 
 /* project laboratory */
 
+/* end of project laboratory */
+
 /* samples: kernel and components samples */
 
+/* end of samples: kernel and components samples */
 
 /* entertainment: terminal games and other interesting software packages */
 
+/* end of entertainment: terminal games and other interesting software packages */
+/* end of miscellaneous packages */
 
 /* Arduino libraries */
 
 
 /* Projects and Demos */
 
+/* end of Projects and Demos */
 
 /* Sensors */
 
+/* end of Sensors */
 
 /* Display */
 
+/* end of Display */
 
 /* Timing */
 
+/* end of Timing */
 
 /* Data Processing */
 
+/* end of Data Processing */
 
 /* Data Storage */
 
 /* Communication */
 
+/* end of Communication */
 
 /* Device Control */
 
+/* end of Device Control */
 
 /* Other */
 
+/* end of Other */
 
 /* Signal IO */
 
+/* end of Signal IO */
 
 /* Uncategorized */
 
+/* end of Arduino libraries */
+/* end of RT-Thread online packages */
+
 /* General Drivers Configuration */
 
 #define BSP_USING_UART
 #define RT_USING_UART0
 #define UART_IRQ_BASE 44
+/* end of General Drivers Configuration */
 #define BSP_USING_CV18XX
 #define C906_PLIC_PHY_ADDR 0x70000000
 #define IRQ_MAX_NR 64

+ 1 - 1
bsp/cvitek/cv18xx_risc-v/rtconfig.py

@@ -41,7 +41,7 @@ if PLATFORM == 'gcc':
     OBJDUMP = PREFIX + 'objdump'
     OBJCPY  = PREFIX + 'objcopy'
 
-    DEVICE  = ' -mcmodel=medany -march=rv64imafdc -mabi=lp64'
+    DEVICE  = ' -mcmodel=medany -mcpu=c906fdv -mabi=lp64'
     CFLAGS  = DEVICE + ' -Wno-cpp -fvar-tracking -ffreestanding -fno-common -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -D_POSIX_SOURCE '
     AFLAGS  = ' -c' + DEVICE + ' -x assembler-with-cpp -D__ASSEMBLY__'
     LFLAGS  = DEVICE + ' -nostartfiles -Wl,--gc-sections,-Map=rtthread.map,-cref,-u,_start -T link.lds' + ' -lsupc++ -lgcc -static'

+ 5 - 1
bsp/cvitek/drivers/SConscript

@@ -36,7 +36,11 @@ if GetDepend(['BSP_USING_SPI']):
 if GetDepend('BSP_USING_PWM'):
     src += ['drv_pwm.c']
     CPPPATH += [cwd + r'/libraries/cv180x/pwm']
-    
+
+if GetDepend('BSP_USING_SDH'):
+    src += ['drv_sdhci.c', 'port/mnt.c']
+    CPPPATH += [cwd + r'/libraries/sdif']
+
 CPPDEFINES += ['-DCONFIG_64BIT']
 
 if GetDepend('BSP_USING_RTC'):

+ 1091 - 0
bsp/cvitek/drivers/drv_sdhci.c

@@ -0,0 +1,1091 @@
+/*
+ * Copyright (c) 2006-2024, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2024/04/05     flyingcys    first version
+ */
+#include <rthw.h>
+#include <rtthread.h>
+#include <rtdevice.h>
+#include "stdbool.h"
+
+#include "board.h"
+
+#define DBG_TAG     "drv.sdio"
+#define DBG_LEVEL   DBG_INFO
+#include <rtdbg.h>
+
+#include <drivers/mmcsd_core.h>
+#include <drivers/sdio.h>
+
+#include "drv_sdhci.h"
+
+#define SDMMC_DMA_ALIGN_CACHE 64
+
+struct rthw_sdhci
+{
+    struct rt_mmcsd_host *host;
+    rt_uint32_t *base;
+    rt_uint32_t irq;
+    volatile rt_err_t cmd_error;
+    volatile rt_err_t data_error;
+    rt_uint32_t response_type;
+    volatile rt_uint32_t response[4];
+    char name[RT_NAME_MAX];
+    rt_sem_t sem_cmd;
+    rt_sem_t sem_data;
+};
+
+static uint32_t sdhci_set_card_clock(rt_uint32_t *base, uint32_t srcClock_Hz, uint32_t target_HZ)
+{
+    uintptr_t BASE = (uintptr_t)base;
+    uint32_t divider = 1U;
+    uint32_t i;
+
+    RT_ASSERT(target_HZ > 0);
+
+    if (srcClock_Hz <= target_HZ )
+    {
+        divider = 0;
+    }
+    else
+    {
+        for (divider = 0x1; divider < 0x3FF; divider++)
+        {
+            if(srcClock_Hz / (2*divider) <= target_HZ)
+                break;
+        }
+
+        if(divider == 0x3FF)
+        {
+            LOG_D("Warning: Can't set the freq to %d, divider is filled!!!", target_HZ);
+        }
+    }
+
+    RT_ASSERT(divider <= 0x3FF);
+
+    if (mmio_read_16(BASE + SDIF_HOST_CONTROL2) & 1<<15)
+    {
+        LOG_D("Use SDCLK Preset Value.");
+    }
+    else
+    {
+        mmio_write_16(BASE + SDIF_CLK_CTRL,
+                mmio_read_16(BASE + SDIF_CLK_CTRL) & ~0x9); // disable INTERNAL_CLK_EN and PLL_ENABLE
+        mmio_write_16(BASE + SDIF_CLK_CTRL,
+                (mmio_read_16(BASE + SDIF_CLK_CTRL) & 0x3F) | ((divider & 0xff) << 8) | ((divider & 0x300) >> 2)); // set clk div
+
+        mmio_write_16(BASE + SDIF_CLK_CTRL,
+                mmio_read_16(BASE + SDIF_CLK_CTRL) | 0x1); // set INTERNAL_CLK_EN
+
+        for (i = 0; i <= 150000; i += 100)
+        {
+            if (mmio_read_16(BASE + SDIF_CLK_CTRL) & 0x2)
+            {
+                break;
+            }
+
+            rt_hw_us_delay(100);
+        }
+
+        if (i > 150000)
+        {
+            LOG_D("SD INTERNAL_CLK_EN seting FAILED!");
+            RT_ASSERT(0);
+        }
+
+        mmio_write_16(BASE + SDIF_CLK_CTRL,
+                mmio_read_16(BASE + SDIF_CLK_CTRL) | 0x8); // set PLL_ENABLE
+
+        for (i = 0; i <= 150000; i += 100)
+        {
+            if (mmio_read_16(BASE + SDIF_CLK_CTRL) & 0x2)
+            {
+                return target_HZ;
+            }
+
+            rt_hw_us_delay(100);
+        }
+    }
+
+    LOG_E("SD PLL seting FAILED!\n");
+    return -1;
+}
+
+static uint32_t SDIF_ChangeCardClock(rt_uint32_t *base, uint32_t srcClock_Hz, uint32_t target_HZ)
+{
+    uintptr_t BASE = (uintptr_t)base;
+    uint32_t divider = 1U;
+    uint32_t i;
+
+    if (target_HZ <= 0)
+    {
+        mmio_write_16(BASE + SDIF_CLK_CTRL, mmio_read_32(BASE + SDIF_CLK_CTRL) & ~(0x1<<2)); // stop SD clock
+//      mmio_write_16(BASE + 0x31e, 0x00);
+        return -1;
+    }
+
+    if (srcClock_Hz <= target_HZ )
+    {
+        divider = 0;
+    }
+    else
+    {
+        for (divider = 0x1; divider < 0x3FF; divider++)
+        {
+            if(srcClock_Hz / (2*divider) <= target_HZ)
+                break;
+        }
+
+        if(divider == 0x3FF)
+        {
+            LOG_D("Warning: Can't set the freq to %d, divider is filled!!!", target_HZ);
+        }
+    }
+
+    RT_ASSERT(divider <= 0x3FF);
+
+    mmio_write_16(BASE + SDIF_CLK_CTRL, mmio_read_16(BASE + SDIF_CLK_CTRL) & ~(0x1<<2)); // stop SD clock
+
+//  mmio_write_16(BASE + 0x31e, 0x10);
+    mmio_write_16(BASE + SDIF_CLK_CTRL, mmio_read_16(BASE + SDIF_CLK_CTRL) & ~0x8); // disable  PLL_ENABLE
+
+    if (mmio_read_16(BASE + SDIF_HOST_CONTROL2) & 1<<15)
+    {
+        LOG_D("Use SDCLK Preset Value.");
+        // 4 need recheck?
+        mmio_write_16(BASE + SDIF_HOST_CONTROL2, mmio_read_16(BASE + SDIF_HOST_CONTROL2) & ~0x7); // clr UHS_MODE_SEL
+    }
+    else
+    {
+        mmio_write_16(BASE + SDIF_CLK_CTRL, (mmio_read_16(BASE + SDIF_CLK_CTRL) & 0x3F) | ((divider & 0xff) << 8) | ((divider & 0x300) >> 2)); // set clk div
+        mmio_write_16(BASE + SDIF_CLK_CTRL, mmio_read_16(BASE + SDIF_CLK_CTRL) & ~(0x1 << 5)); // CLK_GEN_SELECT
+    }
+
+    mmio_write_16(BASE + SDIF_CLK_CTRL, mmio_read_16(BASE + SDIF_CLK_CTRL) | 0xc); // enable  PLL_ENABLE
+
+    //LOG_D("mmio_read_16(BASE + SDIF_CLK_CTRL) = 0x%x", mmio_read_16(BASE + SDIF_CLK_CTRL));
+
+    for (i = 0; i <= 150000; i += 100)
+    {
+        if (mmio_read_16(BASE + SDIF_CLK_CTRL) & 0x2)
+        {
+            return target_HZ;
+        }
+
+        rt_hw_us_delay(100);
+    }
+
+    LOG_E("SD PLL seting FAILED!\n");
+
+    return -1;
+}
+
+static void sdhci_wait_cmd_complete(struct rthw_sdhci *sdhci)
+{
+    rt_err_t ret = RT_EOK;
+    rt_uint32_t intmask;
+    uintptr_t BASE = (uintptr_t)sdhci->base;
+
+    ret = rt_sem_take(sdhci->sem_cmd, rt_tick_from_millisecond(3000));
+    if (ret != RT_EOK)
+    {
+        LOG_E("wait cmd complete timeout ...");
+        sdhci->cmd_error = -RT_ETIMEOUT;
+        return;
+    }
+}
+
+static void sdhci_wait_data_complete(struct rthw_sdhci *sdhci)
+{
+    rt_err_t ret = RT_EOK;
+    rt_uint32_t intmask;
+    uintptr_t BASE = (uintptr_t)sdhci->base;
+
+    ret = rt_sem_take(sdhci->sem_data, rt_tick_from_millisecond(3000));
+    if (ret != RT_EOK)
+    {
+        LOG_E("wait data complete timeout ...");
+        sdhci->data_error = -RT_ETIMEOUT;
+        return;
+    }
+}
+
+uint32_t sdhci_prepare_data(struct rthw_sdhci *sdhci, struct rt_mmcsd_cmd *cmd, struct rt_mmcsd_data *data, sdhci_dma_config_t *dma_config)
+{
+    uintptr_t BASE = (uintptr_t)sdhci->base;
+
+    uint64_t load_addr;
+    uint32_t block_cnt, blksz;
+    uint8_t tmp;
+
+    blksz = data->blksize;
+    block_cnt = data->blks;
+
+    load_addr = (uint64_t)dma_config->dma_des_buffer_start_addr;
+
+    csi_dcache_clean_invalid_range((uint64_t *)load_addr, dma_config->dma_des_buffer_len);
+
+    mmio_write_32(BASE + SDIF_ADMA_SA_LOW, load_addr);
+    mmio_write_32(BASE + SDIF_ADMA_SA_HIGH, (load_addr >> 32));
+
+    mmio_write_32(BASE + SDIF_DMA_ADDRESS, block_cnt);
+    mmio_write_16(BASE + SDIF_BLOCK_COUNT, 0);
+
+    mmio_write_16(BASE + SDIF_BLOCK_SIZE, SDIF_MAKE_BLKSZ(7, blksz));
+
+    // select SDMA
+    tmp = mmio_read_8(BASE + SDIF_HOST_CONTROL);
+    tmp &= ~SDIF_CTRL_DMA_MASK;
+    tmp |= SDIF_CTRL_SDMA;
+
+    mmio_write_8(BASE + SDIF_HOST_CONTROL, tmp);
+
+    return 0;
+}
+
+static inline void *align_alloc(uint64_t align, uint32_t size, void **mem_unalign)
+{
+    void *mem;
+    uint64_t offset;
+    size+=2*align;
+
+    *mem_unalign = (void *)rt_malloc(size);
+
+    if (!*mem_unalign)
+    {
+        LOG_E("sdio memalign error!\n");
+        return NULL;
+    }
+
+    offset = (uint64_t)*mem_unalign % align;
+
+    if (offset == 0)
+        mem = (void *)*mem_unalign;
+    else
+        mem = (void *)(*mem_unalign + (align - offset));
+
+    return mem;
+}
+
+static rt_err_t sdhci_send_data_cmd(struct rthw_sdhci *sdhci, struct rt_mmcsd_cmd *cmd, struct rt_mmcsd_data *data)
+{
+    uintptr_t BASE = (uintptr_t)sdhci->base;
+    uint32_t mode = 0;
+    uint32_t flags = 0;
+    int end_time = 0;
+    int start_time = rt_tick_get_millisecond();
+    sdhci_dma_config_t dma_config;
+
+    while(1)
+    {
+        if (!(mmio_read_32(BASE + SDIF_PRESENT_STATE) & SDIF_CMD_INHIBIT))
+            break;
+        end_time = rt_tick_get_millisecond();
+        if (end_time - start_time >= 2000)
+            return -RT_ETIMEOUT;
+    }
+
+    void *src_align = NULL;
+    void *src_unalign = NULL;
+
+    if (data)
+    {
+        dma_config.dma_des_buffer_len = data->blksize * data->blks;
+        if (data->flags & DATA_DIR_READ)
+        {
+            if ((uint64_t)data->buf & (SDMMC_DMA_ALIGN_CACHE - 1))
+            {
+                src_align = align_alloc(SDMMC_DMA_ALIGN_CACHE, dma_config.dma_des_buffer_len, (void **)&src_unalign);
+                dma_config.dma_des_buffer_start_addr = (uint32_t *)src_align;
+            }
+            else
+            {
+                dma_config.dma_des_buffer_start_addr = (uint32_t *)data->buf;
+            }
+        }
+        else
+        {
+            dma_config.dma_des_buffer_start_addr = (uint32_t *)data->buf;
+        }
+
+        sdhci_prepare_data(sdhci, cmd, data, &dma_config);
+
+        mode = SDIF_TRNS_DMA;
+        if (mmc_op_multi(cmd->cmd_code) || data->blks > 1)
+            mode |= SDIF_TRNS_MULTI | SDIF_TRNS_BLK_CNT_EN;
+
+        if (data->flags & DATA_DIR_READ)
+            mode |= SDIF_TRNS_READ;
+        else
+            mode &= ~SDIF_TRNS_READ;
+
+        mmio_write_16(BASE + SDIF_TRANSFER_MODE, mode);
+    }
+
+    // set cmd flags
+    if (resp_type(cmd) == RESP_NONE)
+            flags |= SDIF_CMD_RESP_NONE;
+    else if (resp_type(cmd) == RESP_R2)
+        flags |= SDIF_CMD_RESP_LONG;
+    else if (resp_type(cmd) == RESP_R1B)
+        flags |= SDIF_CMD_RESP_SHORT_BUSY;
+   else
+        flags |= SDIF_CMD_RESP_SHORT;
+
+    if (data)
+    {
+        flags |= SDIF_CMD_CRC;
+        flags |= SDIF_CMD_INDEX;
+        flags |= SDIF_CMD_DATA;
+    }
+
+    mmio_write_32(BASE + SDIF_ARGUMENT, cmd->arg);
+    // issue the cmd
+    mmio_write_16(BASE + SDIF_COMMAND, SDIF_MAKE_CMD(cmd->cmd_code, flags));
+
+    sdhci_wait_cmd_complete(sdhci);
+    if (sdhci->cmd_error != RT_EOK)
+    {
+        LOG_E("cmd error: %d\n", sdhci->cmd_error);
+        return sdhci->cmd_error;
+    }
+
+    memcpy((void *)cmd->resp, (void *)sdhci->response, sizeof(sdhci->response));
+
+    if (data)
+    {
+        sdhci_wait_data_complete(sdhci);
+        if (sdhci->data_error != RT_EOK)
+        {
+            LOG_E("sdio data error!\n");
+            return sdhci->data_error;
+        }
+
+        if (data->flags & DATA_DIR_READ)
+        {
+            csi_dcache_invalid_range((uint64_t *)dma_config.dma_des_buffer_start_addr, dma_config.dma_des_buffer_len);
+            if (src_unalign)
+            {
+                memcpy((void *)data->buf, src_align, dma_config.dma_des_buffer_len);
+                rt_free(src_unalign);
+                src_align = NULL;
+                src_unalign = NULL;
+            }
+        }
+    }
+
+    return RT_EOK;
+}
+
+static void sdhci_cmd_irq(struct rthw_sdhci *sdhci, uint32_t intmask)
+{
+    int i;
+    uintptr_t BASE = (uintptr_t)sdhci->base;
+
+    if (intmask & (SDIF_INT_TIMEOUT | SDIF_INT_CRC |
+               SDIF_INT_END_BIT | SDIF_INT_INDEX))
+    {
+        if (intmask & SDIF_INT_TIMEOUT)
+        {
+            sdhci->cmd_error = -RT_ETIMEOUT;
+            LOG_E("SDIF_INT_TIMEOUT");
+        }
+
+        return;
+    }
+
+    if (intmask & SDIF_INT_RESPONSE)
+    {
+        sdhci->cmd_error = RT_EOK;
+        if (sdhci->response_type == RESP_R2)
+        {
+            /* CRC is stripped so we need to do some shifting. */
+            for (i = 0; i < 4; i++) {
+                sdhci->response[i] = mmio_read_32(BASE + SDIF_RESPONSE_01 + (3-i)*4) << 8;
+                if (i != 3)
+                    sdhci->response[i] |= mmio_read_8(BASE + SDIF_RESPONSE_01 + (3-i)*4-1);
+            }
+            LOG_D("sdhci->response: [%08x %08x %08x %08x]", sdhci->response[0], sdhci->response[1], sdhci->response[2], sdhci->response[3]);
+        }
+        else
+        {
+            sdhci->response[0] = mmio_read_32(BASE + SDIF_RESPONSE_01);
+            LOG_D("sdhci->response: [%08x]", sdhci->response[0]);
+        }
+    }
+}
+
+static void sdhci_data_irq(struct rthw_sdhci *sdhci, uint32_t intmask)
+{
+    uintptr_t BASE = (uintptr_t)sdhci->base;
+    uint32_t command;
+
+    /* CMD19 generates _only_ Buffer Read Ready interrupt */
+    if (intmask & SDIF_INT_DATA_AVAIL)
+    {
+        command = SDIF_GET_CMD(mmio_read_16(BASE + SDIF_COMMAND));
+        if (command == MMC_CMD19 ||
+            command == MMC_CMD21) {
+            //host->tuning_done = 1;
+            return;
+        }
+    }
+
+    if ((intmask & SDIF_INT_DATA_TIMEOUT) || (intmask & SDIF_INT_DATA_END_BIT) || (intmask & SDIF_INT_DATA_CRC) || (intmask & SDIF_INT_ADMA_ERROR))
+    {
+        sdhci->data_error = -RT_ERROR;
+        return;
+    }
+
+    if (intmask & SDIF_INT_DATA_END)
+    {
+        sdhci->data_error = RT_EOK;
+        return;
+    }
+
+    if (intmask & SDIF_INT_DMA_END)
+    {
+        uint64_t dma_addr;
+        dma_addr = mmio_read_32(BASE + SDIF_ADMA_SA_LOW);
+        mmio_write_32(BASE + SDIF_ADMA_SA_LOW, dma_addr);
+        mmio_write_32(BASE + SDIF_ADMA_SA_HIGH, 0);
+    }
+
+    return;
+}
+
+static void sdhci_transfer_handle_irq(int irqno, void *param)
+{
+    struct rthw_sdhci *sdhci = (struct rthw_sdhci *)param;
+    uintptr_t BASE = (uintptr_t)sdhci->base;
+    int max_loop = 16;
+    uint32_t intmask;
+    uint32_t mask;
+    uint32_t unexpected;
+
+    intmask = mmio_read_32(BASE + SDIF_INT_STATUS);
+
+    if (!intmask || intmask == 0xffffffff)
+    {
+        LOG_E("never be here!\n");
+        return;
+    }
+
+    do
+    {
+        mask = intmask & (SDIF_INT_CMD_MASK | SDIF_INT_DATA_MASK | SDIF_INT_BUS_POWER);
+        mmio_write_32(BASE + SDIF_INT_STATUS, mask);
+
+        if (intmask & SDIF_INT_CMD_MASK)
+        {
+            sdhci_cmd_irq(sdhci, intmask & SDIF_INT_CMD_MASK);
+            rt_sem_release(sdhci->sem_cmd);
+        }
+
+        if (intmask & SDIF_INT_DMA_END)
+        {
+            uint64_t dma_addr;
+            dma_addr = mmio_read_32(BASE + SDIF_ADMA_SA_LOW);
+            mmio_write_32(BASE + SDIF_ADMA_SA_LOW, dma_addr);
+            mmio_write_32(BASE + SDIF_ADMA_SA_HIGH, 0);
+            return;
+        }
+
+        if (intmask & SDIF_INT_DATA_MASK)
+        {
+            sdhci_data_irq(sdhci, intmask & SDIF_INT_DATA_MASK);
+            rt_sem_release(sdhci->sem_data);
+        }
+
+        if (intmask & SDIF_INT_CARD_INT)
+        {
+            LOG_D("init_card_init");
+        }
+
+        intmask &= ~(SDIF_INT_CARD_INSERT | SDIF_INT_CARD_REMOVE |
+                SDIF_INT_CMD_MASK | SDIF_INT_DATA_MASK |
+                SDIF_INT_ERROR | SDIF_INT_BUS_POWER |
+                SDIF_INT_RETUNE | SDIF_INT_CARD_INT);
+
+        if (intmask)
+        {
+            unexpected = intmask;
+            mmio_write_32(BASE + SDIF_INT_STATUS, intmask);
+            LOG_D("unexpected interrupt: 0x%08x.", unexpected);
+        }
+
+        intmask = mmio_read_32(BASE + SDIF_INT_STATUS);
+    } while (intmask && --max_loop);
+}
+
+static uint32_t sdhci_set_clock(rt_uint32_t *base, uint32_t target_hz)
+{
+    uint32_t source_clock_hz;
+    uint32_t ret;
+
+    source_clock_hz = 375 * 1000 * 1000;
+    if (target_hz <= 400000)
+        ret = sdhci_set_card_clock(base, source_clock_hz, target_hz);
+    else
+        ret = SDIF_ChangeCardClock(base, source_clock_hz, target_hz);
+
+    return ret;
+}
+
+static void sdhci_set_bus_width(rt_uint32_t *base, uint8_t bus_width)
+{
+    uintptr_t BASE = (uintptr_t)base;
+    uint32_t ctrl;
+    uint16_t ctrl_2;
+
+    ctrl = mmio_read_8(BASE + SDIF_HOST_CONTROL);
+    if (bus_width == MMCSD_BUS_WIDTH_1)
+        ctrl &= ~SDIF_DAT_XFER_WIDTH;
+    else if (bus_width == MMCSD_BUS_WIDTH_4)
+        ctrl |= SDIF_DAT_XFER_WIDTH;
+    ctrl |= SDIF_CTRL_HISPD;
+
+    ctrl_2 = mmio_read_16(BASE + SDIF_HOST_CONTROL2);
+    ctrl_2 &= ~SDIF_CTRL_UHS_MASK;
+    ctrl_2 |= SDIF_CTRL_UHS_SDR25;
+    mmio_write_16(BASE + SDIF_HOST_CONTROL2, ctrl_2);
+
+    rt_thread_mdelay(1);
+
+    mmio_write_8(BASE + SDIF_HOST_CONTROL, ctrl);
+}
+
+static void sdhci_enable_card_power(rt_uint32_t *base, bool enable)
+{
+    uintptr_t BASE = (uintptr_t)base;
+
+    if (enable)
+    {
+        mmio_write_8(BASE + SDIF_PWR_CONTROL,mmio_read_8(BASE + SDIF_PWR_CONTROL) | 0x1);
+    }
+    else
+    {
+        mmio_write_8(BASE + SDIF_PWR_CONTROL,mmio_read_8(BASE+ SDIF_PWR_CONTROL) & ~0x1);
+    }
+}
+
+static uint32_t sdhci_detect_card_insert(rt_uint32_t *base, bool data3)
+{
+    uintptr_t BASE = (uintptr_t)base;
+    if (data3)
+    {
+        return (mmio_read_32(BASE+SDIF_PRESENT_STATE) & SDIF_CARD_STABLE) == SDIF_CARD_STABLE ? 0U : 1U;
+    }
+    else
+    {
+        return (mmio_read_32(BASE+SDIF_PRESENT_STATE) & SDIF_CARD_INSERTED) == SDIF_CARD_INSERTED ? 1U : 0U;
+    }
+}
+
+static void sdhci_enable_card_clock(rt_uint32_t *base, bool enable)
+{
+    uintptr_t BASE = (uintptr_t)base;
+    if (enable)
+    {
+         mmio_write_16(BASE + SDIF_CLK_CTRL, mmio_read_32(BASE + SDIF_CLK_CTRL) | (0x1<<2)); // stop SD clock
+    }
+    else
+    {
+        mmio_write_16(BASE + SDIF_CLK_CTRL, mmio_read_32(BASE + SDIF_CLK_CTRL) & ~(0x1<<2)); // stop SD clock
+    }
+}
+
+static void sdhci_hw_reset(rt_uint32_t *base)
+{
+    uintptr_t BASE = (uintptr_t)base;
+
+    mmio_write_16(BASE + SDIF_CLK_CTRL, (mmio_read_16(BASE + SDIF_CLK_CTRL) & 0x3F) | DEFAULT_DIV_SD_INIT_CLOCK << 8);
+
+    rt_thread_mdelay(1);
+
+    mmio_write_8(BASE + SDIF_SOFTWARE_RESET, 0x7);
+    while (mmio_read_8(BASE + SDIF_SOFTWARE_RESET));
+}
+
+#define REG_TOP_SD_PWRSW_CTRL       (0x1F4)
+
+static void sdhci_pad_setting(rt_uint32_t *base)
+{
+    uintptr_t BASE = (uintptr_t)base;
+
+    if (BASE == SDIO0_BASE)
+    {
+        //set power for sd0
+        mmio_write_32(TOP_BASE + REG_TOP_SD_PWRSW_CTRL, 0x9);
+        rt_thread_mdelay(1);
+
+        //set pu/down
+        mmio_write_32(REG_SDIO0_CD_PAD_REG, (mmio_read_32(REG_SDIO0_CD_PAD_REG) & REG_SDIO0_PAD_MASK) | REG_SDIO0_CD_PAD_VALUE << REG_SDIO0_PAD_SHIFT);
+        mmio_write_32(REG_SDIO0_PWR_EN_PAD_REG, (mmio_read_32(REG_SDIO0_PWR_EN_PAD_REG) & REG_SDIO0_PAD_MASK) | REG_SDIO0_PWR_EN_PAD_VALUE << REG_SDIO0_PAD_SHIFT);
+        mmio_write_32(REG_SDIO0_CLK_PAD_REG, (mmio_read_32(REG_SDIO0_CLK_PAD_REG) & REG_SDIO0_PAD_MASK) | REG_SDIO0_CLK_PAD_VALUE << REG_SDIO0_PAD_SHIFT);
+        mmio_write_32(REG_SDIO0_CMD_PAD_REG, (mmio_read_32(REG_SDIO0_CMD_PAD_REG) & REG_SDIO0_PAD_MASK) | REG_SDIO0_CMD_PAD_VALUE << REG_SDIO0_PAD_SHIFT);
+        mmio_write_32(REG_SDIO0_DAT1_PAD_REG, (mmio_read_32(REG_SDIO0_DAT1_PAD_REG) & REG_SDIO0_PAD_MASK) | REG_SDIO0_DAT1_PAD_VALUE << REG_SDIO0_PAD_SHIFT);
+        mmio_write_32(REG_SDIO0_DAT0_PAD_REG, (mmio_read_32(REG_SDIO0_DAT0_PAD_REG) & REG_SDIO0_PAD_MASK) | REG_SDIO0_DAT0_PAD_VALUE << REG_SDIO0_PAD_SHIFT);
+        mmio_write_32(REG_SDIO0_DAT2_PAD_REG, (mmio_read_32(REG_SDIO0_DAT2_PAD_REG) & REG_SDIO0_PAD_MASK) | REG_SDIO0_DAT2_PAD_VALUE << REG_SDIO0_PAD_SHIFT);
+        mmio_write_32(REG_SDIO0_DAT3_PAD_REG, (mmio_read_32(REG_SDIO0_DAT3_PAD_REG) & REG_SDIO0_PAD_MASK) | REG_SDIO0_DAT3_PAD_VALUE << REG_SDIO0_PAD_SHIFT);
+
+        //set pinmux
+        mmio_write_8(REG_SDIO0_CD_PIO_REG, REG_SDIO0_CD_PIO_VALUE);
+        mmio_write_8(REG_SDIO0_PWR_EN_PIO_REG, REG_SDIO0_PWR_EN_PIO_VALUE);
+        mmio_write_8(REG_SDIO0_CLK_PIO_REG, REG_SDIO0_CLK_PIO_VALUE);
+        mmio_write_8(REG_SDIO0_CMD_PIO_REG, REG_SDIO0_CMD_PIO_VALUE);
+        mmio_write_8(REG_SDIO0_DAT0_PIO_REG, REG_SDIO0_DAT0_PIO_VALUE);
+        mmio_write_8(REG_SDIO0_DAT1_PIO_REG, REG_SDIO0_DAT1_PIO_VALUE);
+        mmio_write_8(REG_SDIO0_DAT2_PIO_REG, REG_SDIO0_DAT2_PIO_VALUE);
+        mmio_write_8(REG_SDIO0_DAT3_PIO_REG, REG_SDIO0_DAT3_PIO_VALUE);
+    }
+    else if(BASE == SDIO1_BASE)
+    {
+        // set rtc sdio1 related register
+        mmio_write_32(RTCSYS_CTRL, 0x1);
+        mmio_write_32(RTCSYS_CLKMUX, 0x10);
+        mmio_write_32(RTCSYS_CLKBYP, 0xfffffffc);
+        //mmio_write_32(RTCSYS_MCU51_ICTRL1, 0x0);
+
+        mmio_write_32(REG_SDIO1_CLK_PAD_REG, (mmio_read_32(REG_SDIO1_CLK_PAD_REG) & REG_SDIO1_PAD_MASK) | REG_SDIO1_CLK_PAD_VALUE << REG_SDIO1_PAD_SHIFT);
+        mmio_write_32(REG_SDIO1_CMD_PAD_REG, (mmio_read_32(REG_SDIO1_CMD_PAD_REG) & REG_SDIO1_PAD_MASK) | REG_SDIO1_CMD_PAD_VALUE << REG_SDIO1_PAD_SHIFT);
+        mmio_write_32(REG_SDIO1_DAT1_PAD_REG, (mmio_read_32(REG_SDIO1_DAT1_PAD_REG) & REG_SDIO1_PAD_MASK) | REG_SDIO1_DAT1_PAD_VALUE << REG_SDIO1_PAD_SHIFT);
+        mmio_write_32(REG_SDIO1_DAT0_PAD_REG, (mmio_read_32(REG_SDIO1_DAT0_PAD_REG) & REG_SDIO1_PAD_MASK) | REG_SDIO1_DAT0_PAD_VALUE << REG_SDIO1_PAD_SHIFT);
+        mmio_write_32(REG_SDIO1_DAT2_PAD_REG, (mmio_read_32(REG_SDIO1_DAT2_PAD_REG) & REG_SDIO1_PAD_MASK) | REG_SDIO1_DAT2_PAD_VALUE << REG_SDIO1_PAD_SHIFT);
+        mmio_write_32(REG_SDIO1_DAT3_PAD_REG, (mmio_read_32(REG_SDIO1_DAT3_PAD_REG) & REG_SDIO1_PAD_MASK) | REG_SDIO1_DAT3_PAD_VALUE << REG_SDIO1_PAD_SHIFT);
+        mmio_write_32(RTCSYS_CTRL, 0x1);                                    // enable rtc2ap_ahb;
+
+        //set pinmux
+        mmio_write_32(TOP_BASE + 0x294, (mmio_read_32(TOP_BASE + 0x294) & 0xFFFFFBFF));
+        mmio_write_8(REG_SDIO1_CLK_PIO_REG, REG_SDIO1_CLK_PIO_VALUE);
+        mmio_write_8(REG_SDIO1_CMD_PIO_REG, REG_SDIO1_CMD_PIO_VALUE);
+        mmio_write_8(REG_SDIO1_DAT0_PIO_REG, REG_SDIO1_DAT0_PIO_VALUE);
+        mmio_write_8(REG_SDIO1_DAT1_PIO_REG, REG_SDIO1_DAT1_PIO_VALUE);
+        mmio_write_8(REG_SDIO1_DAT2_PIO_REG, REG_SDIO1_DAT2_PIO_VALUE);
+        mmio_write_8(REG_SDIO1_DAT3_PIO_REG, REG_SDIO1_DAT3_PIO_VALUE);
+    }
+    else if(BASE == SDIO2_BASE)
+    {
+        //set pu/down
+        mmio_write_32(REG_SDIO2_RSTN_PAD_REG, (mmio_read_32(REG_SDIO2_RSTN_PAD_REG) & REG_SDIO2_PAD_MASK) | REG_SDIO2_RSTN_PAD_VALUE << REG_SDIO2_PAD_SHIFT);
+        mmio_write_32(REG_SDIO2_CLK_PAD_REG, (mmio_read_32(REG_SDIO2_CLK_PAD_REG) & REG_SDIO2_PAD_MASK) | REG_SDIO2_CLK_PAD_VALUE << REG_SDIO2_PAD_SHIFT);
+        mmio_write_32(REG_SDIO2_CMD_PAD_REG, (mmio_read_32(REG_SDIO2_CMD_PAD_REG) & REG_SDIO2_PAD_MASK) | REG_SDIO2_CMD_PAD_VALUE << REG_SDIO2_PAD_SHIFT);
+        mmio_write_32(REG_SDIO2_DAT0_PAD_REG, (mmio_read_32(REG_SDIO2_DAT0_PAD_REG) & REG_SDIO2_PAD_MASK) | REG_SDIO2_DAT0_PAD_VALUE << REG_SDIO2_PAD_SHIFT);
+        mmio_write_32(REG_SDIO2_DAT1_PAD_REG, (mmio_read_32(REG_SDIO2_DAT1_PAD_REG) & REG_SDIO2_PAD_MASK) | REG_SDIO2_DAT1_PAD_VALUE << REG_SDIO2_PAD_SHIFT);
+        mmio_write_32(REG_SDIO2_DAT2_PAD_REG, (mmio_read_32(REG_SDIO2_DAT2_PAD_REG) & REG_SDIO2_PAD_MASK) | REG_SDIO2_DAT2_PAD_VALUE << REG_SDIO2_PAD_SHIFT);
+        mmio_write_32(REG_SDIO2_DAT3_PAD_REG, (mmio_read_32(REG_SDIO2_DAT3_PAD_REG) & REG_SDIO2_PAD_MASK) | REG_SDIO2_DAT3_PAD_VALUE << REG_SDIO2_PAD_SHIFT);
+
+        //set pinmux
+        mmio_write_8(REG_SDIO2_RSTN_PIO_REG, REG_SDIO2_RSTN_PIO_VALUE);
+        mmio_write_8(REG_SDIO2_CLK_PIO_REG, REG_SDIO2_CLK_PIO_VALUE);
+        mmio_write_8(REG_SDIO2_CMD_PIO_REG, REG_SDIO2_CMD_PIO_VALUE);
+        mmio_write_8(REG_SDIO2_DAT0_PIO_REG, REG_SDIO2_DAT0_PIO_VALUE);
+        mmio_write_8(REG_SDIO2_DAT1_PIO_REG, REG_SDIO2_DAT1_PIO_VALUE);
+        mmio_write_8(REG_SDIO2_DAT2_PIO_REG, REG_SDIO2_DAT2_PIO_VALUE);
+        mmio_write_8(REG_SDIO2_DAT3_PIO_REG, REG_SDIO2_DAT3_PIO_VALUE);
+    }
+}
+
+static void sdhci_phy_init(rt_uint32_t *base)
+{
+    uintptr_t BASE = (uintptr_t)base;
+
+    uintptr_t vendor_base = BASE + (mmio_read_16(BASE + P_VENDOR_SPECIFIC_AREA) & ((1<<12)-1));
+
+    sdhci_hw_reset(base);
+
+    rt_thread_mdelay(3);
+
+    sdhci_pad_setting(base);
+
+    if (BASE == SDIO2_BASE)
+    {
+        //reg_0x200[0] = 1 for sd2
+        mmio_write_32(vendor_base, mmio_read_32(vendor_base) | BIT(0));
+    }
+
+    //reg_0x200[1] = 1
+    mmio_write_32(vendor_base, mmio_read_32(vendor_base) | BIT(1));
+
+    if (BASE == SDIO1_BASE)
+    {
+        //reg_0x200[16] = 1 for sd1
+        mmio_write_32(vendor_base, mmio_read_32(vendor_base) | BIT(16));
+    }
+
+    mmio_write_32(vendor_base + SDIF_PHY_CONFIG, mmio_read_32(vendor_base + SDIF_PHY_CONFIG) | BIT(0));
+
+    mmio_write_32(vendor_base + SDIF_PHY_TX_RX_DLY, 0x1000100);
+}
+
+static void sdhci_init(rt_uint32_t *base)
+{
+    uintptr_t BASE = (uintptr_t)base;
+
+    mmio_write_8(BASE + SDIF_SOFTWARE_RESET, 0x6);
+
+    mmio_write_8(BASE + SDIF_PWR_CONTROL, (0x7 << 1));
+    mmio_write_8(BASE + SDIF_TOUT_CTRL, 0xe);
+    mmio_write_16(BASE + SDIF_HOST_CONTROL2, mmio_read_16(BASE + SDIF_HOST_CONTROL2) | 1<<11);
+    mmio_write_16(BASE + SDIF_CLK_CTRL, mmio_read_16(BASE + SDIF_CLK_CTRL) & ~(0x1 << 5));
+    mmio_write_16(BASE + SDIF_HOST_CONTROL2, mmio_read_16(BASE + SDIF_HOST_CONTROL2) | SDIF_HOST_VER4_ENABLE);
+
+    mmio_write_16(BASE + SDIF_HOST_CONTROL2, mmio_read_16(BASE + SDIF_HOST_CONTROL2) | 0x1<<13);
+
+    if (mmio_read_32(BASE + SDIF_CAPABILITIES1) & (0x1<<29))
+    {
+        mmio_write_16(BASE + SDIF_HOST_CONTROL2, mmio_read_16(BASE + SDIF_HOST_CONTROL2) | (0x1<<14)); // enable async int
+    }
+
+    rt_thread_mdelay(20);
+
+    mmio_write_16(BASE + SDIF_HOST_CONTROL2, mmio_read_16(BASE + SDIF_HOST_CONTROL2) & ~(0x1<<8)); // clr UHS2_IF_ENABLE
+    mmio_write_8(BASE + SDIF_PWR_CONTROL, mmio_read_8(BASE + SDIF_PWR_CONTROL) | 0x1); // set SD_BUS_PWR_VDD1
+    mmio_write_16(BASE + SDIF_HOST_CONTROL2, mmio_read_16(BASE + SDIF_HOST_CONTROL2) & ~0x7); // clr UHS_MODE_SEL
+
+    rt_thread_mdelay(50);
+
+    mmio_write_16(BASE + SDIF_CLK_CTRL, mmio_read_16(BASE + SDIF_CLK_CTRL) | (0x1<<2)); // supply SD clock
+
+    rt_hw_us_delay(400); // wait for voltage ramp up time at least 74 cycle, 400us is 80 cycles for 200Khz
+
+    mmio_write_16(BASE + SDIF_INT_STATUS, mmio_read_16(BASE + SDIF_INT_STATUS) | (0x1 << 6));
+
+    mmio_write_16(BASE + SDIF_INT_STATUS_EN, mmio_read_16(BASE + SDIF_INT_STATUS_EN) | 0xFFFF);
+    mmio_write_16(BASE + SDIF_ERR_INT_STATUS_EN, mmio_read_16(BASE + SDIF_ERR_INT_STATUS_EN) | 0xFFFF);
+
+}
+
+void rthw_sdhci_set_config(struct rthw_sdhci *sdhci)
+{
+    uint32_t pio_irqs = SDIF_INT_DATA_AVAIL | SDIF_INT_SPACE_AVAIL;
+    uint32_t dma_irqs = SDIF_INT_DMA_END | SDIF_INT_ADMA_ERROR;
+    uint32_t int_status;
+    uintptr_t BASE = (uintptr_t)sdhci->base;
+
+    static bool sd0_clock_state = false;
+    static bool sd1_clock_state = false;
+    static bool sd2_clock_state = false;
+
+    if (BASE == SDIO0_BASE)
+    {
+        LOG_D("MMC_FLAG_SDCARD.");
+        if (sd0_clock_state == false)
+        {
+            mmio_write_32(MMC_SDIO0_PLL_REGISTER, MMC_MAX_CLOCK_DIV_VALUE);
+            mmio_clrbits_32(CLOCK_BYPASS_SELECT_REGISTER, BIT(6));
+            sd0_clock_state = true;
+        }
+    }
+    else if (BASE == SDIO1_BASE)
+    {
+        LOG_D("MMC_FLAG_SDIO.");
+        if (sd1_clock_state == false)
+        {
+            mmio_write_32(MMC_SDIO1_PLL_REGISTER, MMC_MAX_CLOCK_DIV_VALUE);
+            mmio_clrbits_32(CLOCK_BYPASS_SELECT_REGISTER, BIT(7));
+            sd1_clock_state = true;
+        }
+    }
+    else if (BASE == SDIO2_BASE)
+    {
+        LOG_D("MMC_FLAG_EMMC.");
+        if (sd2_clock_state == false)
+        {
+            mmio_write_32(MMC_SDIO2_PLL_REGISTER, MMC_MAX_CLOCK_DIV_VALUE);
+            mmio_clrbits_32(CLOCK_BYPASS_SELECT_REGISTER, BIT(5));
+            sd2_clock_state = true;
+        }
+    }
+
+    sdhci_phy_init(sdhci->base);
+    sdhci_init(sdhci->base);
+
+    int_status = SDIF_INT_BUS_POWER | SDIF_INT_DATA_END_BIT |
+        SDIF_INT_DATA_CRC | SDIF_INT_DATA_TIMEOUT |
+        SDIF_INT_INDEX | SDIF_INT_END_BIT | SDIF_INT_CRC |
+        SDIF_INT_TIMEOUT | SDIF_INT_DATA_END | SDIF_INT_RESPONSE;
+
+    int_status = (int_status & ~pio_irqs) | dma_irqs;
+
+    if (int_status)
+    {
+        rt_hw_interrupt_install(sdhci->irq, sdhci_transfer_handle_irq, sdhci, sdhci->name);
+        rt_hw_interrupt_umask(sdhci->irq);
+
+        mmio_write_32(BASE + SDIF_SIGNAL_ENABLE, int_status);
+    }
+    else
+    {
+        mmio_write_32(BASE + SDIF_SIGNAL_ENABLE, 0);
+    }
+
+}
+
+static void rthw_sdhci_request(struct rt_mmcsd_host *host, struct rt_mmcsd_req *req)
+{
+    RT_ASSERT(host != RT_NULL);
+    RT_ASSERT(req != RT_NULL);
+
+    rt_err_t ret = RT_EOK;
+    struct rthw_sdhci *sdhci = (struct rthw_sdhci *)host->private_data;
+
+    if (req->cmd != RT_NULL)
+    {
+        struct rt_mmcsd_cmd *cmd = req->cmd;
+        struct rt_mmcsd_data *data = req->data;
+
+        LOG_D("[%s%s%s%s%s]REQ: CMD:%d ARG:0x%08x RES:%s%s%s%s%s%s%s%s%s rw:%c addr:%08x, blks:%d, blksize:%d datalen:%d",
+                (host->card == RT_NULL) ? "Unknown" : "",
+                (host->card) && (host->card->card_type == CARD_TYPE_MMC) ? "MMC" : "",
+                (host->card) && (host->card->card_type == CARD_TYPE_SD) ? "SD" : "",
+                (host->card) && (host->card->card_type == CARD_TYPE_SDIO) ? "SDIO" : "",
+                (host->card) && (host->card->card_type == CARD_TYPE_SDIO_COMBO) ? "SDIO_COMBO" : "",
+                cmd->cmd_code,
+                cmd->arg,
+                resp_type(cmd) == RESP_NONE ? "NONE"  : "",
+                resp_type(cmd) == RESP_R1  ? "R1"  : "",
+                resp_type(cmd) == RESP_R1B ? "R1B"  : "",
+                resp_type(cmd) == RESP_R2  ? "R2"  : "",
+                resp_type(cmd) == RESP_R3  ? "R3"  : "",
+                resp_type(cmd) == RESP_R4  ? "R4"  : "",
+                resp_type(cmd) == RESP_R5  ? "R5"  : "",
+                resp_type(cmd) == RESP_R6  ? "R6"  : "",
+                resp_type(cmd) == RESP_R7  ? "R7"  : "",
+                data ? (data->flags & DATA_DIR_WRITE ?  'w' : 'r') : '-',
+                data ? data->buf : 0,
+                data ? data->blks : 0,
+                data ? data->blksize : 0,
+                data ? data->blks * data->blksize : 0);
+
+        if (cmd->cmd_code == 5)
+        {
+            cmd->err = -RT_ERROR;
+
+            mmcsd_req_complete(host);
+            return;
+        }
+
+        sdhci->response_type = resp_type(cmd);
+        sdhci->cmd_error = RT_EOK;
+        sdhci->data_error = RT_EOK;
+        memset((void *)sdhci->response, 0, sizeof(sdhci->response));
+        memset(cmd->resp, 0, sizeof(cmd->resp));
+
+        ret = sdhci_send_data_cmd(sdhci, cmd, data);
+        if (ret != RT_EOK)
+        {
+            memset(cmd->resp, 0, sizeof(cmd->resp));
+        }
+        cmd->err = ret;
+    }
+
+    if (req->stop != RT_NULL)
+    {
+        struct rt_mmcsd_cmd *stop = req->stop;
+
+        stop->err = sdhci_send_data_cmd(sdhci, stop, RT_NULL);
+    }
+
+    mmcsd_req_complete(host);
+}
+
+static void rthw_sdhci_iocfg(struct rt_mmcsd_host *host, struct rt_mmcsd_io_cfg *io_cfg)
+{
+    RT_ASSERT(host != RT_NULL);
+    RT_ASSERT(io_cfg != RT_NULL);
+
+    struct rthw_sdhci *sdhci = (struct rthw_sdhci *)host->private_data;
+    rt_uint32_t clk = io_cfg->clock;
+
+    LOG_D("clk:%d width:%s%s%s power:%s%s%s",
+          clk,
+          io_cfg->bus_width == MMCSD_BUS_WIDTH_8 ? "8" : "",
+          io_cfg->bus_width == MMCSD_BUS_WIDTH_4 ? "4" : "",
+          io_cfg->bus_width == MMCSD_BUS_WIDTH_1 ? "1" : "",
+          io_cfg->power_mode == MMCSD_POWER_OFF ? "OFF" : "",
+          io_cfg->power_mode == MMCSD_POWER_UP ? "UP" : "",
+          io_cfg->power_mode == MMCSD_POWER_ON ? "ON" : ""
+         );
+
+    if (clk > host->freq_max)
+        clk = host->freq_max;
+
+    if (clk < host->freq_min)
+        clk = host->freq_min;
+
+    sdhci_set_clock(sdhci->base, clk);
+
+    /* power mode */
+    switch (io_cfg->power_mode)
+    {
+        case MMCSD_POWER_UP:
+        case MMCSD_POWER_ON:
+            sdhci_enable_card_power(sdhci->base, true);
+            break;
+
+        case MMCSD_POWER_OFF:
+            sdhci_enable_card_power(sdhci->base, false);
+            break;
+
+        default:
+            break;
+    }
+
+    /* bus width */
+    switch (io_cfg->bus_width)
+    {
+        case MMCSD_BUS_WIDTH_1:
+        case MMCSD_BUS_WIDTH_4:
+            sdhci_set_bus_width(sdhci->base, io_cfg->bus_width);
+            break;
+
+        case MMCSD_BUS_WIDTH_8:
+        default:
+            LOG_E("invalid bus_width: %d", io_cfg->bus_width);
+            break;
+    }
+}
+
+
+static const struct rt_mmcsd_host_ops ops = {
+    rthw_sdhci_request,
+    rthw_sdhci_iocfg,
+    RT_NULL,
+    RT_NULL,
+};
+
+static int rthw_sdhci_init(void)
+{
+    rt_err_t ret = RT_EOK;
+
+    struct rt_mmcsd_host *host;
+    struct rthw_sdhci *sdhci = RT_NULL;
+
+    sdhci = rt_malloc(sizeof(struct rthw_sdhci));
+    if (sdhci == RT_NULL)
+    {
+        LOG_E("malloc rthw_sdhci faile...");
+    }
+    rt_memset(sdhci, 0, sizeof(struct rthw_sdhci));
+
+    sdhci->sem_cmd = rt_sem_create("sem_cmd", 0, RT_IPC_FLAG_FIFO);
+    if (sdhci->sem_cmd == RT_NULL)
+    {
+        LOG_E("rt_sem_create sdhci event failed...");
+        rt_free(sdhci);
+        sdhci = RT_NULL;
+        return ret;
+    }
+
+    sdhci->sem_data = rt_sem_create("sem_data", 0, RT_IPC_FLAG_FIFO);
+    if (sdhci->sem_data == RT_NULL)
+    {
+        LOG_E("rt_sem_create sdhci event failed...");
+        rt_sem_delete(sdhci->sem_cmd);
+        rt_free(sdhci);
+        sdhci = RT_NULL;
+        return ret;
+    }
+
+    sdhci->base = (rt_uint32_t *)SDIO0_BASE;
+    sdhci->irq = SDIO0_IRQ;
+    strcpy(sdhci->name, "sdio0");
+    rthw_sdhci_set_config(sdhci);
+
+    host = mmcsd_alloc_host();
+    RT_ASSERT(host != RT_NULL);
+
+    /* set host default attributes */
+    host->ops = &ops;
+    host->freq_min = 400000;
+    host->freq_max = 40000000;
+    host->valid_ocr = VDD_31_32 | VDD_32_33 | VDD_33_34;
+    host->flags = MMCSD_BUSWIDTH_4 | MMCSD_MUTBLKWRITE | MMCSD_SUP_HIGHSPEED;
+    host->max_seg_size = 512;
+    host->max_dma_segs = 1;
+    host->max_blk_size= 512;
+    host->max_blk_count = 512;
+
+    sdhci->host = host;
+    host->private_data = sdhci;
+
+    /* ready to change */
+    mmcsd_change(host);
+
+    return RT_EOK;
+}
+INIT_DEVICE_EXPORT(rthw_sdhci_init);
+
+void sdhci_register_dump(uint8_t argc, char **argv)
+{
+    rt_uint32_t *base;
+    if (argc < 2)
+    {
+        rt_kprintf("Usage: sdhci_register_dump 0/1/2\n");
+        return;
+    }
+
+    if (0 == atoi(argv[1]))
+        base = (void *)(rt_uint32_t *)SDIO0_BASE;
+    else if (1 == atoi(argv[1]))
+        base = (void *)(rt_uint32_t *)SDIO1_BASE;
+    else
+        base = (void *)(rt_uint32_t *)SDIO2_BASE;
+
+    uintptr_t BASE = (uintptr_t)base;
+
+    rt_kprintf("============ SDHCI REGISTER DUMP ===========\n");
+
+    rt_kprintf("Sys addr:  0x%08x | Version:  0x%08x\n",
+           mmio_read_32(BASE + SDIF_DMA_ADDRESS),
+           mmio_read_16(BASE + SDIF_HOST_VERSION));
+    rt_kprintf("Blk size:  0x%08x | Blk cnt:  0x%08x\n",
+           mmio_read_16(BASE + SDIF_BLOCK_SIZE),
+           mmio_read_16(BASE + SDIF_BLOCK_COUNT));
+    rt_kprintf("Argument:  0x%08x | Trn mode: 0x%08x\n",
+           mmio_read_32(BASE + SDIF_ARGUMENT),
+           mmio_read_16(BASE + SDIF_TRANSFER_MODE));
+    rt_kprintf("Present:   0x%08x | Host ctl: 0x%08x\n",
+           mmio_read_32(BASE + SDIF_PRESENT_STATE),
+           mmio_read_8(BASE + SDIF_HOST_CONTROL));
+    rt_kprintf("Power:     0x%08x | Blk gap:  0x%08x\n",
+           mmio_read_8(BASE + SDIF_PWR_CONTROL),
+           mmio_read_8(BASE + SDIF_BLOCK_GAP_CONTROL));
+    rt_kprintf("Wake-up:   0x%08x | Clock:    0x%08x\n",
+           mmio_read_8(BASE + SDIF_WAKE_UP_CONTROL),
+           mmio_read_16(BASE + SDIF_CLK_CTRL));
+    rt_kprintf("Timeout:   0x%08x | Int stat: 0x%08x\n",
+           mmio_read_8(BASE + SDIF_TOUT_CTRL),
+           mmio_read_32(BASE + SDIF_INT_STATUS));
+    rt_kprintf("Int enab:  0x%08x | Sig enab: 0x%08x\n",
+           mmio_read_32(BASE + SDIF_INT_ENABLE),
+           mmio_read_32(BASE + SDIF_SIGNAL_ENABLE));
+    rt_kprintf("ACmd stat: 0x%08x | Slot int: 0x%08x\n",
+           mmio_read_16(BASE + SDIF_AUTO_CMD_STATUS),
+           mmio_read_16(BASE + SDIF_SLOT_INT_STATUS));
+    rt_kprintf("Caps:      0x%08x | Caps_1:   0x%08x\n",
+           mmio_read_32(BASE + SDIF_CAPABILITIES),
+           mmio_read_32(BASE + SDIF_CAPABILITIES_1));
+    rt_kprintf("Cmd:       0x%08x | Max curr: 0x%08x\n",
+           mmio_read_16(BASE + SDIF_COMMAND),
+           mmio_read_32(BASE + SDIF_MAX_CURRENT));
+    rt_kprintf("Resp[0]:   0x%08x | Resp[1]:  0x%08x\n",
+           mmio_read_32(BASE + SDIF_RESPONSE),
+           mmio_read_32(BASE + SDIF_RESPONSE + 4));
+    rt_kprintf("Resp[2]:   0x%08x | Resp[3]:  0x%08x\n",
+           mmio_read_32(BASE + SDIF_RESPONSE + 8),
+           mmio_read_32(BASE + SDIF_RESPONSE + 12));
+    rt_kprintf("Host ctl2: 0x%08x\n",
+           mmio_read_16(BASE + SDIF_HOST_CONTROL2));
+    rt_kprintf("ADMA Err:  0x%08x | ADMA Ptr: 0x%08x%08x\n",
+           mmio_read_32(BASE + SDIF_ADMA_ERROR),
+           mmio_read_32(BASE + SDIF_ADMA_ADDRESS_HI),
+           mmio_read_32(BASE + SDIF_ADMA_ADDRESS));
+    rt_kprintf("============================================\n");
+}
+MSH_CMD_EXPORT(sdhci_register_dump, Dump SDHCI register);

+ 44 - 0
bsp/cvitek/drivers/drv_sdhci.h

@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2006-2024, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2024/04/05     flyingcys    first version
+ */
+#ifndef __DRV_SDHCI_H__
+#define __DRV_SDHCI_H__
+
+#include "mmio.h"
+#include "dw_sdmmc.h"
+#include "dw_mmc_reg.h"
+
+#include "core_rv64.h"
+
+#ifndef BIT
+#define BIT(nr)      (UINT64_C(1) << (nr))
+#endif
+
+typedef enum {
+    SDIF_CHAIN_DMA_MODE = 0x01U, ///< one descriptor with one buffer,but one descriptor point to another
+    SDIF_DUAL_DMA_MODE  = 0x02U,  ///< dual mode is one descriptor with two buffer
+} sdhci_dma_mode_e;
+
+typedef struct {
+    bool            enable_fix_burst_len;           ///< fix burst len enable/disable flag,When set, the AHB will
+    ///  use only SINGLE, INCR4, INCR8 or INCR16 during start of
+    ///  normal burst transfers. When reset, the AHB will use SINGLE
+    ///  and INCR burst transfer operations
+
+    sdhci_dma_mode_e mode;                           ///< define the DMA mode */
+
+
+    uint32_t        *dma_des_buffer_start_addr;     ///< internal DMA descriptor start address
+    uint32_t        dma_des_buffer_len;             ///  internal DMA buffer descriptor buffer len ,user need to pay attention to the
+    ///  dma descriptor buffer length if it is bigger enough for your transfer
+    uint8_t         dma_dws_skip_len;               ///< define the descriptor skip length ,the length between two descriptor
+    ///  this field is special for dual DMA mode
+} sdhci_dma_config_t;
+
+#endif /* __DRV_SDHCI_H__ */

+ 1314 - 0
bsp/cvitek/drivers/libraries/core_rv64.h

@@ -0,0 +1,1314 @@
+/*
+ * Copyright (C) 2017-2019 Alibaba Group Holding Limited
+ */
+
+
+/******************************************************************************
+ * @file     core_rv64.h
+ * @brief    CSI RV32 Core Peripheral Access Layer Header File
+ * @version  V1.0
+ * @date     01. Sep 2018
+ ******************************************************************************/
+
+#ifndef __CORE_RV64_H_GENERIC
+#define __CORE_RV64_H_GENERIC
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*******************************************************************************
+ *                 CSI definitions
+ ******************************************************************************/
+/**
+  \ingroup RV32
+  @{
+ */
+
+#ifndef __RV64
+#define __RV64                (0x01U)
+#endif
+
+/** __FPU_USED indicates whether an FPU is used or not.
+    This core does not support an FPU at all
+*/
+#define __FPU_USED       0U
+
+#if defined ( __GNUC__ )
+#if defined (__VFP_FP__) && !defined(__SOFTFP__)
+#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
+#endif
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CORE_RV32_H_GENERIC */
+
+#ifndef __CSI_GENERIC
+
+#ifndef __CORE_RV32_H_DEPENDANT
+#define __CORE_RV32_H_DEPENDANT
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* check device defines and use defaults */
+#ifndef __RV64_REV
+#define __RV64_REV               0x0000U
+#endif
+
+#ifndef __VIC_PRIO_BITS
+#define __VIC_PRIO_BITS           2U
+#endif
+
+#ifndef __Vendor_SysTickConfig
+#define __Vendor_SysTickConfig    1U
+#endif
+
+#ifndef __MPU_PRESENT
+#define __MPU_PRESENT             1U
+#endif
+
+#ifndef __ICACHE_PRESENT
+#define __ICACHE_PRESENT          1U
+#endif
+
+#ifndef __DCACHE_PRESENT
+#define __DCACHE_PRESENT          1U
+#endif
+
+
+#ifndef __L2CACHE_PRESENT
+#define __L2CACHE_PRESENT          1U
+#endif
+
+#include <csi_rv64_gcc.h>
+
+/* IO definitions (access restrictions to peripheral registers) */
+/**
+    \defgroup CSI_glob_defs CSI Global Defines
+
+    <strong>IO Type Qualifiers</strong> are used
+    \li to specify the access to peripheral variables.
+    \li for automatic generation of peripheral register debug information.
+*/
+#ifdef __cplusplus
+#define     __I      volatile             /*!< Defines 'read only' permissions */
+#else
+#define     __I      volatile const       /*!< Defines 'read only' permissions */
+#endif
+#define     __O      volatile             /*!< Defines 'write only' permissions */
+#define     __IO     volatile             /*!< Defines 'read / write' permissions */
+
+/* following defines should be used for structure members */
+#define     __IM     volatile const       /*! Defines 'read only' structure member permissions */
+#define     __OM     volatile             /*! Defines 'write only' structure member permissions */
+#define     __IOM    volatile             /*! Defines 'read / write' structure member permissions */
+
+/*@} end of group C906 */
+
+/*******************************************************************************
+ *                 Register Abstraction
+  Core Register contain:
+  - Core Register
+  - Core CLINT Register
+ ******************************************************************************/
+/**
+  \defgroup CSI_core_register Defines and Type Definitions
+  \brief Type definitions and defines for CK80X processor based devices.
+*/
+
+/**
+  \ingroup    CSI_core_register
+  \defgroup   CSI_CORE  Status and Control Registers
+  \brief      Core Register type definitions.
+  @{
+ */
+
+/**
+  \ingroup    CSI_core_register
+  \defgroup   CSI_CLINT Core-Local Interrupt Controller (CLINT)
+  \brief      Type definitions for the CLINT Registers
+  @{
+ */
+
+/**
+  \brief Access to the structure of a vector interrupt controller.
+ */
+
+typedef struct {
+    uint32_t RESERVED0;                 /*!< Offset: 0x000 (R/W)  CLINT configure register */
+    __IOM uint32_t PLIC_PRIO[1023];
+    __IOM uint32_t PLIC_IP[32];
+    uint32_t RESERVED1[3972 / 4 - 1];
+    __IOM uint32_t PLIC_H0_MIE[32];
+    __IOM uint32_t PLIC_H0_SIE[32];
+    __IOM uint32_t PLIC_H1_MIE[32];
+    __IOM uint32_t PLIC_H1_SIE[32];
+    __IOM uint32_t PLIC_H2_MIE[32];
+    __IOM uint32_t PLIC_H2_SIE[32];
+    __IOM uint32_t PLIC_H3_MIE[32];
+    __IOM uint32_t PLIC_H3_SIE[32];
+    uint32_t RESERVED2[(0x01FFFFC - 0x00023FC) / 4 - 1];
+    __IOM uint32_t PLIC_PER;
+    __IOM uint32_t PLIC_H0_MTH;
+    __IOM uint32_t PLIC_H0_MCLAIM;
+    uint32_t RESERVED3[0xFFC / 4 - 1];
+    __IOM uint32_t PLIC_H0_STH;
+    __IOM uint32_t PLIC_H0_SCLAIM;
+    uint32_t RESERVED4[0xFFC / 4 - 1];
+
+    __IOM uint32_t PLIC_H1_MTH;
+    __IOM uint32_t PLIC_H1_MCLAIM;
+    uint32_t RESERVED5[0xFFC / 4 - 1];
+    __IOM uint32_t PLIC_H1_STH;
+    __IOM uint32_t PLIC_H1_SCLAIM;
+    uint32_t RESERVED6[0xFFC / 4 - 1];
+
+    __IOM uint32_t PLIC_H2_MTH;
+    __IOM uint32_t PLIC_H2_MCLAIM;
+    uint32_t RESERVED7[0xFFC / 4 - 1];
+    __IOM uint32_t PLIC_H2_STH;
+    __IOM uint32_t PLIC_H2_SCLAIM;
+    uint32_t RESERVED8[0xFFC / 4 - 1];
+
+    __IOM uint32_t PLIC_H3_MTH;
+    __IOM uint32_t PLIC_H3_MCLAIM;
+    uint32_t RESERVED9[0xFFC / 4 - 1];
+    __IOM uint32_t PLIC_H3_STH;
+    __IOM uint32_t PLIC_H3_SCLAIM;
+    uint32_t RESERVED10[0xFFC / 4 - 1];
+} PLIC_Type;
+
+
+/**
+  \ingroup    CSI_core_register
+  \defgroup   CSI_PMP Physical Memory Protection (PMP)
+  \brief      Type definitions for the PMP Registers
+  @{
+ */
+
+#define PMP_PMPCFG_R_Pos                       0U                                    /*!< PMP PMPCFG: R Position */
+#define PMP_PMPCFG_R_Msk                       (0x1UL << PMP_PMPCFG_R_Pos)           /*!< PMP PMPCFG: R Mask */
+
+#define PMP_PMPCFG_W_Pos                       1U                                    /*!< PMP PMPCFG: W Position */
+#define PMP_PMPCFG_W_Msk                       (0x1UL << PMP_PMPCFG_W_Pos)           /*!< PMP PMPCFG: W Mask */
+
+#define PMP_PMPCFG_X_Pos                       2U                                    /*!< PMP PMPCFG: X Position */
+#define PMP_PMPCFG_X_Msk                       (0x1UL << PMP_PMPCFG_X_Pos)           /*!< PMP PMPCFG: X Mask */
+
+#define PMP_PMPCFG_A_Pos                       3U                                    /*!< PMP PMPCFG: A Position */
+#define PMP_PMPCFG_A_Msk                       (0x3UL << PMP_PMPCFG_A_Pos)           /*!< PMP PMPCFG: A Mask */
+
+#define PMP_PMPCFG_L_Pos                       7U                                    /*!< PMP PMPCFG: L Position */
+#define PMP_PMPCFG_L_Msk                       (0x1UL << PMP_PMPCFG_L_Pos)           /*!< PMP PMPCFG: L Mask */
+
+typedef enum {
+    REGION_SIZE_4B       = -1,
+    REGION_SIZE_8B       = 0,
+    REGION_SIZE_16B      = 1,
+    REGION_SIZE_32B      = 2,
+    REGION_SIZE_64B      = 3,
+    REGION_SIZE_128B     = 4,
+    REGION_SIZE_256B     = 5,
+    REGION_SIZE_512B     = 6,
+    REGION_SIZE_1KB      = 7,
+    REGION_SIZE_2KB      = 8,
+    REGION_SIZE_4KB      = 9,
+    REGION_SIZE_8KB      = 10,
+    REGION_SIZE_16KB     = 11,
+    REGION_SIZE_32KB     = 12,
+    REGION_SIZE_64KB     = 13,
+    REGION_SIZE_128KB    = 14,
+    REGION_SIZE_256KB    = 15,
+    REGION_SIZE_512KB    = 16,
+    REGION_SIZE_1MB      = 17,
+    REGION_SIZE_2MB      = 18,
+    REGION_SIZE_4MB      = 19,
+    REGION_SIZE_8MB      = 20,
+    REGION_SIZE_16MB     = 21,
+    REGION_SIZE_32MB     = 22,
+    REGION_SIZE_64MB     = 23,
+    REGION_SIZE_128MB    = 24,
+    REGION_SIZE_256MB    = 25,
+    REGION_SIZE_512MB    = 26,
+    REGION_SIZE_1GB      = 27,
+    REGION_SIZE_2GB      = 28,
+    REGION_SIZE_4GB      = 29,
+    REGION_SIZE_8GB      = 30,
+    REGION_SIZE_16GB     = 31
+} region_size_e;
+
+typedef enum {
+    ADDRESS_MATCHING_TOR   = 1,
+    ADDRESS_MATCHING_NAPOT = 3
+} address_matching_e;
+
+typedef struct {
+    uint32_t r: 1;           /* readable enable */
+    uint32_t w: 1;           /* writeable enable */
+    uint32_t x: 1;           /* execable enable */
+    address_matching_e a: 2; /* address matching mode */
+    uint32_t reserved: 2;    /* reserved */
+    uint32_t l: 1;           /* lock enable */
+} mpu_region_attr_t;
+
+/*@} end of group CSI_PMP */
+
+/* CACHE Register Definitions */
+#define CACHE_MHCR_WBR_Pos                     8U                                            /*!< CACHE MHCR: WBR Position */
+#define CACHE_MHCR_WBR_Msk                     (0x1UL << CACHE_MHCR_WBR_Pos)                 /*!< CACHE MHCR: WBR Mask */
+
+#define CACHE_MHCR_IBPE_Pos                    7U                                            /*!< CACHE MHCR: IBPE Position */
+#define CACHE_MHCR_IBPE_Msk                    (0x1UL << CACHE_MHCR_IBPE_Pos)                /*!< CACHE MHCR: IBPE Mask */
+
+#define CACHE_MHCR_L0BTB_Pos                   6U                                            /*!< CACHE MHCR: L0BTB Position */
+#define CACHE_MHCR_L0BTB_Msk                   (0x1UL << CACHE_MHCR_L0BTB_Pos)               /*!< CACHE MHCR: BTB Mask */
+
+#define CACHE_MHCR_BPE_Pos                     5U                                            /*!< CACHE MHCR: BPE Position */
+#define CACHE_MHCR_BPE_Msk                     (0x1UL << CACHE_MHCR_BPE_Pos)                 /*!< CACHE MHCR: BPE Mask */
+
+#define CACHE_MHCR_RS_Pos                      4U                                            /*!< CACHE MHCR: RS Position */
+#define CACHE_MHCR_RS_Msk                      (0x1UL << CACHE_MHCR_RS_Pos)                  /*!< CACHE MHCR: RS Mask */
+
+#define CACHE_MHCR_WB_Pos                      3U                                            /*!< CACHE MHCR: WB Position */
+#define CACHE_MHCR_WB_Msk                      (0x1UL << CACHE_MHCR_WB_Pos)                  /*!< CACHE MHCR: WB Mask */
+
+#define CACHE_MHCR_WA_Pos                      2U                                            /*!< CACHE MHCR: WA Position */
+#define CACHE_MHCR_WA_Msk                      (0x1UL << CACHE_MHCR_WA_Pos)                  /*!< CACHE MHCR: WA Mask */
+
+#define CACHE_MHCR_DE_Pos                      1U                                            /*!< CACHE MHCR: DE Position */
+#define CACHE_MHCR_DE_Msk                      (0x1UL << CACHE_MHCR_DE_Pos)                  /*!< CACHE MHCR: DE Mask */
+
+#define CACHE_MHCR_IE_Pos                      0U                                            /*!< CACHE MHCR: IE Position */
+#define CACHE_MHCR_IE_Msk                      (0x1UL << CACHE_MHCR_IE_Pos)                  /*!< CACHE MHCR: IE Mask */
+
+#define CACHE_INV_ADDR_Pos                     6U
+#define CACHE_INV_ADDR_Msk                     (0xFFFFFFFFUL << CACHE_INV_ADDR_Pos)
+
+/*@} end of group CSI_CACHE */
+
+// MSTATUS Register
+#define MSTATUS_TVM_MASK (1L << 20)     // mstatus.TVM                      [20]
+#define MSTATUS_MPP_MASK (3L << 11)     // mstatus.SPP                      [11:12]
+#define MSTATUS_MPP_M    (3L << 11)     // Machine mode                     11
+#define MSTATUS_MPP_S    (1L << 11)     // Supervisor mode                  01
+#define MSTATUS_MPP_U    (0L << 11)     // User mode                        00
+
+// SSTATUS Register
+#define SSTATUS_SPP_MASK (3L << 8)      // sstatus.SPP                      [8:9]
+#define SSTATUS_SPP_S    (1L << 8)      // Supervisor mode                  01
+#define SSTATUS_SPP_U    (0L << 8)      // User mode                        00
+
+typedef enum {
+    USER_MODE        = 0,
+    SUPERVISOR_MODE  = 1,
+    MACHINE_MODE     = 3,
+} cpu_work_mode_t;
+/**
+  \ingroup  CSI_core_register
+  \defgroup CSI_CINT     Core Local Interrupt (CLINT)
+  \brief    Type definitions for the Core Local Interrupt Registers.
+  @{
+ */
+
+/**
+  \brief  The data structure of the access Clint.
+ */
+typedef struct {
+    __IOM uint32_t MSIP0;
+    __IOM uint32_t MSIP1;
+    __IOM uint32_t MSIP2;
+    __IOM uint32_t MSIP3;
+    uint32_t RESERVED0[(0x4004000 - 0x400000C) / 4 - 1];
+    __IOM uint32_t MTIMECMPL0;
+    __IOM uint32_t MTIMECMPH0;
+    __IOM uint32_t MTIMECMPL1;
+    __IOM uint32_t MTIMECMPH1;
+    __IOM uint32_t MTIMECMPL2;
+    __IOM uint32_t MTIMECMPH2;
+    __IOM uint32_t MTIMECMPL3;
+    __IOM uint32_t MTIMECMPH3;
+    uint32_t RESERVED1[(0x400C000 - 0x400401C) / 4 - 1];
+    __IOM uint32_t SSIP0;
+    __IOM uint32_t SSIP1;
+    __IOM uint32_t SSIP2;
+    __IOM uint32_t SSIP3;
+    uint32_t RESERVED2[(0x400D000 - 0x400C00C) / 4 - 1];
+    __IOM uint32_t STIMECMPL0;
+    __IOM uint32_t STIMECMPH0;
+    __IOM uint32_t STIMECMPL1;
+    __IOM uint32_t STIMECMPH1;
+    __IOM uint32_t STIMECMPL2;
+    __IOM uint32_t STIMECMPH2;
+    __IOM uint32_t STIMECMPL3;
+    __IOM uint32_t STIMECMPH3;
+} CLINT_Type;
+/*@} end of group CSI_SysTick */
+
+
+/**
+  \ingroup    CSI_core_register
+  \defgroup   CSI_core_bitfield     Core register bit field macros
+  \brief      Macros for use with bit field definitions (xxx_Pos, xxx_Msk).
+  @{
+ */
+
+/**
+  \brief   Mask and shift a bit field value for use in a register bit range.
+  \param[in] field  Name of the register bit field.
+  \param[in] value  Value of the bit field.
+  \return           Masked and shifted value.
+*/
+#define _VAL2FLD(field, value)    ((value << field ## _Pos) & field ## _Msk)
+
+/**
+  \brief     Mask and shift a register value to extract a bit filed value.
+  \param[in] field  Name of the register bit field.
+  \param[in] value  Value of register.
+  \return           Masked and shifted bit field value.
+*/
+#define _FLD2VAL(field, value)    ((value & field ## _Msk) >> field ## _Pos)
+
+/*@} end of group CSI_core_bitfield */
+
+/**
+  \ingroup    CSI_core_register
+  \defgroup   CSI_core_base     Core Definitions
+  \brief      Definitions for base addresses, unions, and structures.
+  @{
+ */
+
+/*@} */
+
+/*******************************************************************************
+ *                Hardware Abstraction Layer
+  Core Function Interface contains:
+  - Core VIC Functions
+  - Core CORET Functions
+  - Core Register Access Functions
+ ******************************************************************************/
+/**
+  \defgroup CSI_Core_FunctionInterface Functions and Instructions Reference
+*/
+
+/* ##########################   VIC functions  #################################### */
+/**
+  \ingroup  CSI_Core_FunctionInterface
+  \defgroup CSI_Core_VICFunctions VIC Functions
+  \brief    Functions that manage interrupts and exceptions via the VIC.
+  @{
+ */
+
+/* The following MACROS handle generation of the register offset and byte masks */
+#define _BIT_SHIFT(IRQn)         (  ((((uint32_t)(int32_t)(IRQn))         )      &  0x03UL) * 8UL)
+#define _IP_IDX(IRQn)            (   (((uint32_t)(int32_t)(IRQn))                >>    5UL)      )
+#define _IP2_IDX(IRQn)            (   (((uint32_t)(int32_t)(IRQn))                >>    2UL)      )
+
+/**
+  \brief   Enable External Interrupt
+  \details Enable a device-specific interrupt in the VIC interrupt controller.
+  \param [in]      IRQn  External interrupt number. Value cannot be negative.
+ */
+__STATIC_INLINE void csi_plic_enable_irq(uint64_t plic_base, int32_t IRQn)
+{
+    PLIC_Type *plic = (PLIC_Type *)plic_base;
+#if defined(CONFIG_RISCV_SMODE) && CONFIG_RISCV_SMODE
+    plic->PLIC_H0_SIE[IRQn/32] = plic->PLIC_H0_SIE[IRQn/32] | (0x1 << (IRQn%32));
+#else
+    plic->PLIC_H0_MIE[IRQn/32] = plic->PLIC_H0_MIE[IRQn/32] | (0x1 << (IRQn%32));
+#endif
+}
+
+/**
+  \brief   Disable External Interrupt
+  \details Disable a device-specific interrupt in the VIC interrupt controller.
+  \param [in]      IRQn  External interrupt number. Value cannot be negative.
+ */
+__STATIC_INLINE void csi_plic_disable_irq(uint64_t plic_base, int32_t IRQn)
+{
+    PLIC_Type *plic = (PLIC_Type *)plic_base;
+#if defined(CONFIG_RISCV_SMODE) && CONFIG_RISCV_SMODE
+    plic->PLIC_H0_SIE[IRQn/32] = plic->PLIC_H0_SIE[IRQn/32] & (~(0x1 << (IRQn%32)));
+#else
+    plic->PLIC_H0_MIE[IRQn/32] = plic->PLIC_H0_MIE[IRQn/32] & (~(0x1 << (IRQn%32)));
+#endif
+}
+
+/**
+  \brief   Enable External Secure Interrupt
+  \details Enable a secure device-specific interrupt in the VIC interrupt controller.
+  \param [in]      IRQn  External interrupt number. Value cannot be negative.
+ */
+__STATIC_INLINE void csi_plic_enable_sirq(uint64_t plic_base, int32_t IRQn)
+{
+    csi_plic_enable_irq(plic_base, IRQn);
+}
+
+/**
+  \brief   Disable External Secure Interrupt
+  \details Disable a secure device-specific interrupt in the VIC interrupt controller.
+  \param [in]      IRQn  External interrupt number. Value cannot be negative.
+ */
+__STATIC_INLINE void csi_plic_disable_sirq(uint64_t plic_base, int32_t IRQn)
+{
+    csi_plic_disable_irq(plic_base, IRQn);
+}
+
+/**
+  \brief   Check Interrupt is Enabled or not
+  \details Read the enabled register in the VIC and returns the pending bit for the specified interrupt.
+  \param [in]      IRQn  Interrupt number.
+  \return             0  Interrupt status is not enabled.
+  \return             1  Interrupt status is enabled.
+ */
+__STATIC_INLINE uint32_t csi_plic_get_enabled_irq(uint64_t plic_base, int32_t IRQn)
+{
+    PLIC_Type *plic = (PLIC_Type *)plic_base;
+#if defined(CONFIG_RISCV_SMODE) && CONFIG_RISCV_SMODE
+    return (uint32_t)((plic->PLIC_H0_SIE[IRQn/32] >> IRQn%32) & 0x1);
+#else
+    return (uint32_t)((plic->PLIC_H0_MIE[IRQn/32] >> IRQn%32) & 0x1);
+#endif
+}
+
+/**
+  \brief   Check Interrupt is Pending or not
+  \details Read the pending register in the VIC and returns the pending bit for the specified interrupt.
+  \param [in]      IRQn  Interrupt number.
+  \return             0  Interrupt status is not pending.
+  \return             1  Interrupt status is pending.
+ */
+__STATIC_INLINE uint32_t csi_plic_get_pending_irq(uint64_t plic_base, int32_t IRQn)
+{
+    PLIC_Type *plic = (PLIC_Type *)plic_base;
+    return (uint32_t)((plic->PLIC_IP[IRQn/32] >> IRQn%32) & 0x1);
+}
+
+/**
+  \brief   Set Pending Interrupt
+  \details Set the pending bit of an external interrupt.
+  \param [in]      IRQn  Interrupt number. Value cannot be negative.
+ */
+__STATIC_INLINE void csi_plic_set_pending_irq(uint64_t plic_base, int32_t IRQn)
+{
+    PLIC_Type *plic = (PLIC_Type *)plic_base;
+    plic->PLIC_IP[IRQn/32] = plic->PLIC_IP[IRQn/32] | (0x1 << (IRQn%32));
+}
+
+/**
+  \brief   Clear Pending Interrupt
+  \details Clear the pending bit of an external interrupt.
+  \param [in]      IRQn  External interrupt number. Value cannot be negative.
+ */
+__STATIC_INLINE void csi_plic_clear_pending_irq(uint64_t plic_base, int32_t IRQn)
+{
+    PLIC_Type *plic = (PLIC_Type *)plic_base;
+    plic->PLIC_H0_SCLAIM = IRQn;
+}
+
+/**
+  \brief   Set Interrupt Priority
+  \details Set the priority of an interrupt.
+  \note    The priority cannot be set for every core interrupt.
+  \param [in]      IRQn  Interrupt number.
+  \param [in]  priority  Priority to set.
+ */
+__STATIC_INLINE void csi_plic_set_prio(uint64_t plic_base, int32_t IRQn, uint32_t priority)
+{
+    PLIC_Type *plic = (PLIC_Type *)plic_base;
+    plic->PLIC_PRIO[IRQn] = priority;
+}
+
+/**
+  \brief   Get Interrupt Priority
+  \details Read the priority of an interrupt.
+           The interrupt number can be positive to specify an external (device specific) interrupt,
+           or negative to specify an internal (core) interrupt.
+  \param [in]   IRQn  Interrupt number.
+  \return             Interrupt Priority.
+                      Value is aligned automatically to the implemented priority bits of the microcontroller.
+ */
+__STATIC_INLINE uint32_t csi_plic_get_prio(uint64_t plic_base, int32_t IRQn)
+{
+    PLIC_Type *plic = (PLIC_Type *)plic_base;
+    uint32_t prio = plic->PLIC_PRIO[IRQn];
+    return prio;
+}
+
+/**
+  \brief   Set interrupt handler
+  \details Set the interrupt handler according to the interrupt num, the handler will be filled in irq vectors.
+  \param [in]      IRQn  Interrupt number.
+  \param [in]   handler  Interrupt handler.
+ */
+__STATIC_INLINE void csi_plic_set_vector(int32_t IRQn, uint64_t handler)
+{
+    if (IRQn >= 0 && IRQn < 1024) {
+        uint64_t *vectors = (uint64_t *)__get_MTVT();
+        vectors[IRQn] = handler;
+    }
+}
+
+/**
+  \brief   Get interrupt handler
+  \details Get the address of interrupt handler function.
+  \param [in]      IRQn  Interrupt number.
+ */
+__STATIC_INLINE uint32_t csi_plic_get_vector(int32_t IRQn)
+{
+    if (IRQn >= 0 && IRQn < 1024) {
+        uint64_t *vectors = (uint64_t *)__get_MTVT();
+        return (uint32_t)vectors[IRQn];
+    }
+
+    return 0;
+}
+
+/*@} end of CSI_Core_VICFunctions */
+
+/* ##########################   PMP functions  #################################### */
+/**
+  \ingroup  CSI_Core_FunctionInterface
+  \defgroup CSI_Core_PMPFunctions PMP Functions
+  \brief    Functions that manage interrupts and exceptions via the VIC.
+  @{
+ */
+
+/**
+  \brief  configure memory protected region.
+  \details
+  \param [in]  idx        memory protected region (0, 1, 2, ..., 15).
+  \param [in]  base_addr  base address must be aligned with page size.
+  \param [in]  size       \ref region_size_e. memory protected region size.
+  \param [in]  attr       \ref region_size_t. memory protected region attribute.
+  \param [in]  enable     enable or disable memory protected region.
+  */
+__STATIC_INLINE void csi_mpu_config_region(uint32_t idx, uint32_t base_addr, region_size_e size,
+        mpu_region_attr_t attr, uint32_t enable)
+{
+    uint8_t  pmpxcfg = 0;
+    uint32_t addr = 0;
+
+    if (idx > 15) {
+        return;
+    }
+
+    if (!enable) {
+        attr.a = (address_matching_e)0;
+    }
+
+    if (attr.a == ADDRESS_MATCHING_TOR) {
+        addr = base_addr >> 2;
+    } else {
+        if (size == REGION_SIZE_4B) {
+            addr = base_addr >> 2;
+            attr.a = (address_matching_e)2;
+        } else {
+            addr = ((base_addr >> 2) & (0xFFFFFFFFU - ((1 << (size + 1)) - 1))) | ((1 << size) - 1);
+        }
+    }
+
+    __set_PMPADDRx(idx, addr);
+
+    pmpxcfg |= (attr.r << PMP_PMPCFG_R_Pos) | (attr.w << PMP_PMPCFG_W_Pos) |
+               (attr.x << PMP_PMPCFG_X_Pos) | (attr.a << PMP_PMPCFG_A_Pos) |
+               (attr.l << PMP_PMPCFG_L_Pos);
+
+    __set_PMPxCFG(idx, pmpxcfg);
+}
+
+/**
+  \brief  disable mpu region by idx.
+  \details
+  \param [in]  idx        memory protected region (0, 1, 2, ..., 15).
+  */
+__STATIC_INLINE void csi_mpu_disable_region(uint32_t idx)
+{
+    __set_PMPxCFG(idx, __get_PMPxCFG(idx) & (~PMP_PMPCFG_A_Msk));
+}
+
+/*@} end of CSI_Core_PMPFunctions */
+
+/* ##################################    SysTick function  ############################################ */
+/**
+  \ingroup  CSI_Core_FunctionInterface
+  \defgroup CSI_Core_SysTickFunctions SysTick Functions
+  \brief    Functions that configure the System.
+  @{
+ */
+
+
+/**
+  \brief   CORE timer Configuration
+  \details Initializes the System Timer and its interrupt, and starts the System Tick Timer.
+           Counter is in free running mode to generate periodic interrupts.
+  \param [in]  ticks  Number of ticks between two interrupts.
+  \param [in]  IRQn   core timer Interrupt number.
+  \return          0  Function succeeded.
+  \return          1  Function failed.
+  \note    When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the
+           function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b>
+           must contain a vendor-specific implementation of this function.
+ */
+__STATIC_INLINE uint32_t csi_clint_config(uint64_t clint_base, uint32_t ticks, int32_t IRQn)
+{
+    CLINT_Type *clint = (CLINT_Type *)clint_base;
+#ifdef __QEMU_RUN
+    uint64_t value = (((uint64_t)clint->MTIMECMPH0) << 32) + (uint64_t)clint->MTIMECMPL0;
+
+    value = value + (uint64_t)ticks;
+    clint->MTIMECMPH0 = (uint32_t)(value >> 32);
+    clint->MTIMECMPL0 = (uint32_t)value;
+#else
+#if defined(CONFIG_RISCV_SMODE) && CONFIG_RISCV_SMODE
+    uint64_t value = (((uint64_t)clint->STIMECMPH0) << 32) + (uint64_t)clint->STIMECMPL0;
+
+    if ((value != 0) && (value != 0xffffffffffffffff)) {
+        value = value + (uint64_t)ticks;
+    } else {
+        value = __get_MTIME() + ticks;
+    }
+    clint->STIMECMPH0 = (uint32_t)(value >> 32);
+    clint->STIMECMPL0 = (uint32_t)value;
+#else
+    uint64_t value = (((uint64_t)clint->MTIMECMPH0) << 32) + (uint64_t)clint->MTIMECMPL0;
+
+    if ((value != 0) && (value != 0xffffffffffffffff)) {
+        value = value + (uint64_t)ticks;
+    } else {
+        value = __get_MTIME() + ticks;
+    }
+    clint->MTIMECMPH0 = (uint32_t)(value >> 32);
+    clint->MTIMECMPL0 = (uint32_t)value;
+#endif
+#endif /*__QEMU_RUN*/
+
+    return (0UL);
+}
+
+__STATIC_INLINE void csi_coret_reset_value(uint64_t clint_base)
+{
+    uint32_t value = 0x0;
+    CLINT_Type *clint = (CLINT_Type *)clint_base;
+
+#if defined(CONFIG_RISCV_SMODE) && CONFIG_RISCV_SMODE
+    clint->STIMECMPH0 = (uint32_t)value;
+    clint->STIMECMPL0 = (uint32_t)value;
+#else
+    clint->MTIMECMPH0 = (uint32_t)value;
+    clint->MTIMECMPL0 = (uint32_t)value;
+#endif
+}
+
+/**
+  \brief   get CORE timer reload value
+  \return          CORE timer counter value.
+ */
+__STATIC_INLINE uint64_t csi_clint_get_load(uint64_t clint_base)
+{
+    CLINT_Type *clint = (CLINT_Type *)clint_base;
+#if defined(CONFIG_RISCV_SMODE) && CONFIG_RISCV_SMODE
+    uint64_t value = (((uint64_t)clint->STIMECMPH0) << 32) + (uint64_t)clint->STIMECMPL0;
+#else
+    uint64_t value = (((uint64_t)clint->MTIMECMPH0) << 32) + (uint64_t)clint->MTIMECMPL0;
+#endif
+
+    return value;
+}
+
+/**
+  \brief   get CORE timer reload high value
+  \return          CORE timer counter value.
+ */
+__STATIC_INLINE uint32_t csi_clint_get_loadh(uint64_t clint_base)
+{
+    CLINT_Type *clint = (CLINT_Type *)clint_base;
+#if defined(CONFIG_RISCV_SMODE) && CONFIG_RISCV_SMODE
+    uint64_t value = (((uint64_t)clint->STIMECMPH0) << 32) + (uint64_t)clint->STIMECMPL0;
+#else
+    uint64_t value = (((uint64_t)clint->MTIMECMPH0) << 32) + (uint64_t)clint->MTIMECMPL0;
+#endif
+
+    return (value >> 32) & 0xFFFFFFFF;
+}
+
+/**
+  \brief   get CORE timer counter value
+  \return          CORE timer counter value.
+ */
+__STATIC_INLINE uint64_t csi_clint_get_value(void)
+{
+    uint64_t result;
+    __ASM volatile("csrr %0, 0xc01" : "=r"(result));
+    return result;
+}
+
+/**
+  \brief   get CORE timer counter high value
+  \return          CORE timer counter value.
+ */
+__STATIC_INLINE uint32_t csi_clint_get_valueh(void)
+{
+    uint64_t result;
+    __ASM volatile("csrr %0, time" : "=r"(result));
+    return (result >> 32) & 0xFFFFFFFF;
+}
+
+/*@} end of CSI_core_DebugFunctions */
+
+/* ##########################  Cache functions  #################################### */
+/**
+  \ingroup  CSI_Core_FunctionInterface
+  \defgroup CSI_Core_CacheFunctions Cache Functions
+  \brief    Functions that configure Instruction and Data cache.
+  @{
+ */
+
+/**
+  \brief   whether I-Cache enable
+  */
+__STATIC_INLINE int csi_icache_is_enable()
+{
+    uint32_t cache = __get_MHCR();
+    return (cache & CACHE_MHCR_IE_Msk) >> CACHE_MHCR_IE_Pos;
+}
+
+/**
+  \brief   Enable I-Cache
+  \details Turns on I-Cache
+  */
+__STATIC_INLINE void csi_icache_enable(void)
+{
+#if (__ICACHE_PRESENT == 1U)
+    if (!csi_icache_is_enable()) {
+        uint32_t cache;
+        __DSB();
+        __ISB();
+        __ICACHE_IALL();
+        cache = __get_MHCR();
+        cache |= CACHE_MHCR_IE_Msk;
+        __set_MHCR(cache);
+        __DSB();
+        __ISB();
+    }
+#endif
+}
+
+
+/**
+  \brief   Disable I-Cache
+  \details Turns off I-Cache
+  */
+__STATIC_INLINE void csi_icache_disable(void)
+{
+#if (__ICACHE_PRESENT == 1U)
+    if (csi_icache_is_enable()) {
+        uint32_t cache;
+        __DSB();
+        __ISB();
+        cache = __get_MHCR();
+        cache &= ~CACHE_MHCR_IE_Msk;            /* disable icache */
+        __set_MHCR(cache);
+        __ICACHE_IALL();                        /* invalidate all icache */
+        __DSB();
+        __ISB();
+    }
+#endif
+}
+
+
+/**
+  \brief   Invalidate I-Cache
+  \details Invalidates I-Cache
+  */
+__STATIC_INLINE void csi_icache_invalid(void)
+{
+#if (__ICACHE_PRESENT == 1U)
+    __DSB();
+    __ISB();
+    __ICACHE_IALL();                        /* invalidate all icache */
+    __DSB();
+    __ISB();
+#endif
+}
+
+/**
+  \brief   whether D-Cache enable
+  */
+__STATIC_INLINE int csi_dcache_is_enable()
+{
+    uint32_t cache = __get_MHCR();
+    return (cache & CACHE_MHCR_DE_Msk) >> CACHE_MHCR_DE_Pos;
+}
+
+/**
+  \brief   Enable D-Cache
+  \details Turns on D-Cache
+  \note    I-Cache also turns on.
+  */
+__STATIC_INLINE void csi_dcache_enable(void)
+{
+#if (__DCACHE_PRESENT == 1U)
+    if (!csi_dcache_is_enable()) {
+        uint32_t cache;
+        __DSB();
+        __ISB();
+        __DCACHE_IALL();                        /* invalidate all dcache */
+        cache = __get_MHCR();
+        cache |= (CACHE_MHCR_DE_Msk | CACHE_MHCR_WB_Msk | CACHE_MHCR_WA_Msk | CACHE_MHCR_RS_Msk | CACHE_MHCR_BPE_Msk | CACHE_MHCR_L0BTB_Msk | CACHE_MHCR_IBPE_Msk | CACHE_MHCR_WBR_Msk);      /* enable all Cache */
+        __set_MHCR(cache);
+
+        __DSB();
+        __ISB();
+    }
+#endif
+}
+
+
+/**
+  \brief   Disable D-Cache
+  \details Turns off D-Cache
+  \note    I-Cache also turns off.
+  */
+__STATIC_INLINE void csi_dcache_disable(void)
+{
+#if (__DCACHE_PRESENT == 1U)
+    if (csi_dcache_is_enable()) {
+        uint32_t cache;
+        __DSB();
+        __ISB();
+        cache = __get_MHCR();
+        cache &= ~(uint32_t)CACHE_MHCR_DE_Msk; /* disable all Cache */
+        __set_MHCR(cache);
+        __DCACHE_IALL();                             /* invalidate all Cache */
+        __DSB();
+        __ISB();
+    }
+#endif
+}
+
+/**
+  \brief   Invalidate D-Cache
+  \details Invalidates D-Cache
+  \note    I-Cache also invalid
+  */
+__STATIC_INLINE void csi_dcache_invalid(void)
+{
+#if (__DCACHE_PRESENT == 1U)
+    __DSB();
+    __ISB();
+    __DCACHE_IALL();                            /* invalidate all Cache */
+    __DSB();
+    __ISB();
+#endif
+}
+
+
+/**
+  \brief   Clean D-Cache
+  \details Cleans D-Cache
+  \note    I-Cache also cleans
+  */
+__STATIC_INLINE void csi_dcache_clean(void)
+{
+#if (__DCACHE_PRESENT == 1U)
+    __DSB();
+    __ISB();
+    __DCACHE_CALL();                                     /* clean all Cache */
+    __DSB();
+    __ISB();
+#endif
+}
+
+
+/**
+  \brief   Clean & Invalidate D-Cache
+  \details Cleans and Invalidates D-Cache
+  \note    I-Cache also flush.
+  */
+__STATIC_INLINE void csi_dcache_clean_invalid(void)
+{
+#if (__DCACHE_PRESENT == 1U)
+    __DSB();
+    __ISB();
+    __DCACHE_CIALL();                                   /* clean and inv all Cache */
+    __DSB();
+    __ISB();
+#endif
+}
+
+
+/**
+  \brief   Invalidate L2-Cache
+  \details Invalidates L2-Cache
+  \note
+  */
+__STATIC_INLINE void csi_l2cache_invalid(void)
+{
+#if (__L2CACHE_PRESENT == 1U)
+    __DSB();
+    __ISB();
+    __L2CACHE_IALL();                            /* invalidate l2 Cache */
+    __DSB();
+    __ISB();
+#endif
+}
+
+
+/**
+  \brief   Clean L2-Cache
+  \details Cleans L2-Cache
+  \note
+  */
+__STATIC_INLINE void csi_l2cache_clean(void)
+{
+#if (__L2CACHE_PRESENT == 1U)
+    __DSB();
+    __ISB();
+    __L2CACHE_CALL();                                     /* clean l2 Cache */
+    __DSB();
+    __ISB();
+#endif
+}
+
+
+/**
+  \brief   Clean & Invalidate L2-Cache
+  \details Cleans and Invalidates L2-Cache
+  \note
+  */
+__STATIC_INLINE void csi_l2cache_clean_invalid(void)
+{
+#if (__L2CACHE_PRESENT == 1U)
+    __DSB();
+    __ISB();
+    __L2CACHE_CIALL();                                   /* clean and inv l2 Cache */
+    __DSB();
+    __ISB();
+#endif
+}
+
+/**
+  \brief   D-Cache Invalidate by address
+  \details Invalidates D-Cache for the given address
+  \param[in]   addr    address (aligned to 64-byte boundary)
+  \param[in]   dsize   size of memory block (in number of bytes)
+*/
+__STATIC_INLINE void csi_dcache_invalid_range(uint64_t *addr, int64_t dsize)
+{
+#if (__DCACHE_PRESENT == 1U)
+    int64_t op_size = dsize + (uint64_t)addr % 64;
+    uint64_t op_addr = (uint64_t)addr;
+    int64_t linesize = 64;
+    cpu_work_mode_t cpu_work_mode;
+    cpu_work_mode = (cpu_work_mode_t)__get_CPU_WORK_MODE();
+
+    __DSB();
+
+    if (cpu_work_mode == MACHINE_MODE) {
+        while (op_size > 0) {
+            __DCACHE_IPA(op_addr);
+            op_addr += linesize;
+            op_size -= linesize;
+        }
+    } else if (cpu_work_mode == SUPERVISOR_MODE) {
+        while (op_size > 0) {
+            __DCACHE_IVA(op_addr);
+            op_addr += linesize;
+            op_size -= linesize;
+        }
+    }
+
+    __SYNC_IS();
+    __DSB();
+#endif
+}
+
+
+/**
+  \brief   D-Cache Clean by address
+  \details Cleans D-Cache for the given address
+  \param[in]   addr    address (aligned to 64-byte boundary)
+  \param[in]   dsize   size of memory block (in number of bytes)
+*/
+__STATIC_INLINE void csi_dcache_clean_range(uint64_t *addr, int64_t dsize)
+{
+
+#if (__DCACHE_PRESENT == 1)
+    int64_t op_size = dsize + (uint64_t)addr % 64;
+    uint64_t op_addr = (uint64_t) addr & CACHE_INV_ADDR_Msk;
+    int64_t linesize = 64;
+    cpu_work_mode_t cpu_work_mode;
+    cpu_work_mode = (cpu_work_mode_t)__get_CPU_WORK_MODE();
+
+    __DSB();
+
+    if (cpu_work_mode == MACHINE_MODE) {
+        while (op_size > 0) {
+            __DCACHE_CPA(op_addr);
+            op_addr += linesize;
+            op_size -= linesize;
+        }
+    } else if (cpu_work_mode == SUPERVISOR_MODE) {
+        while (op_size > 0) {
+            __DCACHE_CVA(op_addr);
+            op_addr += linesize;
+            op_size -= linesize;
+        }
+    }
+
+    __SYNC_IS();
+    __DSB();
+#endif
+
+}
+
+
+/**
+  \brief   D-Cache Clean and Invalidate by address
+  \details Cleans and invalidates D_Cache for the given address
+  \param[in]   addr    address (aligned to 64-byte boundary)
+  \param[in]   dsize   size of memory block (aligned to 64-byte boundary)
+*/
+__STATIC_INLINE void csi_dcache_clean_invalid_range(uint64_t *addr, int64_t dsize)
+{
+#if (__DCACHE_PRESENT == 1U)
+    int64_t op_size = dsize + (uint64_t)addr % 64;
+    uint64_t op_addr = (uint64_t) addr;
+    int64_t linesize = 64;
+    cpu_work_mode_t cpu_work_mode;
+    cpu_work_mode = (cpu_work_mode_t)__get_CPU_WORK_MODE();
+
+    __DSB();
+
+    if (cpu_work_mode == MACHINE_MODE) {
+        while (op_size > 0) {
+            __DCACHE_CIPA(op_addr);
+            op_addr += linesize;
+            op_size -= linesize;
+        }
+    } else if (cpu_work_mode == SUPERVISOR_MODE) {
+        while (op_size > 0) {
+            __DCACHE_CIVA(op_addr);
+            op_addr += linesize;
+            op_size -= linesize;
+        }
+    }
+
+    __SYNC_IS();
+    __DSB();
+#endif
+}
+
+/**
+  \brief   setup cacheable range Cache
+  \details setup Cache range
+  */
+__STATIC_INLINE void csi_cache_set_range (uint64_t index, uint64_t baseAddr, uint64_t size, uint64_t enable)
+{
+    ;
+}
+
+/**
+  \brief   Enable cache profile
+  \details Turns on Cache profile
+  */
+__STATIC_INLINE void csi_cache_enable_profile(void)
+{
+    ;
+}
+
+/**
+  \brief   Disable cache profile
+  \details Turns off Cache profile
+  */
+__STATIC_INLINE void csi_cache_disable_profile(void)
+{
+    ;
+}
+
+/**
+  \brief   Reset cache profile
+  \details Reset Cache profile
+  */
+__STATIC_INLINE void csi_cache_reset_profile(void)
+{
+    ;
+}
+
+/**
+  \brief   cache access times
+  \details Cache access times
+  \note    every 256 access add 1.
+  \return          cache access times, actual times should be multiplied by 256
+  */
+__STATIC_INLINE uint64_t csi_cache_get_access_time(void)
+{
+    return 0;
+}
+
+/**
+  \brief   cache miss times
+  \details Cache miss times
+  \note    every 256 miss add 1.
+  \return          cache miss times, actual times should be multiplied by 256
+  */
+__STATIC_INLINE uint64_t csi_cache_get_miss_time(void)
+{
+    return 0;
+}
+
+/*@} end of CSI_Core_CacheFunctions */
+
+
+/* ##########################  MMU functions  #################################### */
+/**
+  \ingroup  CSI_Core_FunctionInterface
+  \defgroup CSI_Core_MMUFunctions MMU Functions
+  \brief    Functions that configure MMU.
+  @{
+  */
+
+typedef enum {
+    PAGE_SIZE_4KB   = 0x1000,
+    PAGE_SIZE_2MB   = 0x200000,
+    PAGE_SIZE_1GB   = 0x40000000,
+} page_size_e;
+
+
+typedef enum {
+    MMU_MODE_39   = 0x8,
+    MMU_MODE_48   = 0x9,
+    MMU_MODE_57   = 0xa,
+    MMU_MODE_64   = 0xb,
+} mmu_mode_e;
+
+/**
+  \brief  enable mmu
+  \details
+  */
+__STATIC_INLINE void csi_mmu_enable(mmu_mode_e mode)
+{
+    __set_SATP(__get_SATP() | ((uint64_t)mode << 60));
+}
+
+/**
+  \brief  disable mmu
+  \details
+  */
+__STATIC_INLINE void csi_mmu_disable(void)
+{
+    __set_SATP(__get_SATP() & (~((uint64_t)0xf << 60)));
+}
+
+/**
+  \brief  flush all mmu tlb.
+  \details
+  */
+__STATIC_INLINE void csi_mmu_invalid_tlb_all(void)
+{
+    __ASM volatile("sfence.vma" : : : "memory");
+}
+
+/**
+  \brief  flush mmu tlb by asid.
+  \details
+  */
+__STATIC_INLINE void csi_mmu_invalid_tlb_by_asid(unsigned long asid)
+{
+    __ASM volatile("sfence.vma zero, %0"
+                   :
+                   : "r"(asid)
+                   : "memory");
+}
+
+/**
+  \brief  flush mmu tlb by page.
+  \details
+  */
+__STATIC_INLINE void csi_mmu_invalid_tlb_by_page(unsigned long asid, unsigned long addr)
+{
+    __ASM volatile("sfence.vma %0, %1"
+                   :
+                   : "r"(addr), "r"(asid)
+                   : "memory");
+}
+
+/**
+  \brief  flush mmu tlb by range.
+  \details
+  */
+__STATIC_INLINE void csi_mmu_invalid_tlb_by_range(unsigned long asid, page_size_e page_size, unsigned long start_addr, unsigned long end_addr)
+{
+    start_addr &= ~(page_size - 1);
+    end_addr += page_size - 1;
+    end_addr &= ~(page_size - 1);
+
+    while(start_addr < end_addr) {
+        __ASM volatile("sfence.vma %0, %1"
+                       :
+                       : "r"(start_addr), "r"(asid)
+                       : "memory");
+    }
+}
+
+/*@} end of CSI_Core_MMUFunctions */
+
+/* ##################################    IRQ Functions  ############################################ */
+
+/**
+  \brief   Save the Irq context
+  \details save the psr result before disable irq.
+ */
+__STATIC_INLINE uint64_t csi_irq_save(void)
+{
+    uint64_t result;
+#if defined(CONFIG_RISCV_SMODE) && CONFIG_RISCV_SMODE
+    result = __get_SSTATUS();
+#else
+    result = __get_MSTATUS();
+#endif
+    __disable_irq();
+    return(result);
+}
+
+/**
+  \brief   Restore the Irq context
+  \details restore saved primask state.
+  \param [in]      irq_state  psr irq state.
+ */
+__STATIC_INLINE void csi_irq_restore(uint64_t irq_state)
+{
+#if defined(CONFIG_RISCV_SMODE) && CONFIG_RISCV_SMODE
+    __set_SSTATUS(irq_state);
+#else
+    __set_MSTATUS(irq_state);
+#endif
+}
+
+/*@} end of IRQ Functions */
+
+/**
+  \brief   Get the byte-width of vector register
+  \return  the byte-width of vector register
+ */
+__STATIC_INLINE int csi_vlenb_get_value(void)
+{
+    int result;
+    __ASM volatile("csrr %0, vlenb" : "=r"(result) : : "memory");
+    return result;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CORE_RV32_H_DEPENDANT */
+
+#endif /* __CSI_GENERIC */

+ 3340 - 0
bsp/cvitek/drivers/libraries/csi_rv64_gcc.h

@@ -0,0 +1,3340 @@
+/*
+ * Copyright (C) 2017-2019 Alibaba Group Holding Limited
+ */
+
+
+/******************************************************************************
+ * @file     csi_rv64_gcc.h
+ * @brief    CSI Header File for GCC.
+ * @version  V1.0
+ * @date     01. Sep 2018
+ ******************************************************************************/
+
+#ifndef _CSI_RV64_GCC_H_
+#define _CSI_RV64_GCC_H_
+
+#include <stdlib.h>
+
+#ifndef __ASM
+#define __ASM                   __asm     /*!< asm keyword for GNU Compiler */
+#endif
+
+#ifndef __INLINE
+#define __INLINE                inline    /*!< inline keyword for GNU Compiler */
+#endif
+
+#ifndef __ALWAYS_STATIC_INLINE
+#define __ALWAYS_STATIC_INLINE  __attribute__((always_inline)) static inline
+#endif
+
+#ifndef __STATIC_INLINE
+#define __STATIC_INLINE         static inline
+#endif
+
+#ifndef __NO_RETURN
+#define __NO_RETURN             __attribute__((__noreturn__))
+#endif
+
+#ifndef __USED
+#define __USED                  __attribute__((used))
+#endif
+
+#ifndef __WEAK
+#define __WEAK                  __attribute__((weak))
+#endif
+
+#ifndef __PACKED
+#define __PACKED                __attribute__((packed, aligned(1)))
+#endif
+
+#ifndef __PACKED_STRUCT
+#define __PACKED_STRUCT         struct __attribute__((packed, aligned(1)))
+#endif
+
+#ifndef __PACKED_UNION
+#define __PACKED_UNION          union __attribute__((packed, aligned(1)))
+#endif
+
+
+/* ###########################  Core Function Access  ########################### */
+/** \ingroup  CSI_Core_FunctionInterface
+    \defgroup CSI_Core_RegAccFunctions CSI Core Register Access Functions
+  @{
+ */
+/**
+  \brief   Enable IRQ Interrupts
+  \details Enables IRQ interrupts by setting the IE-bit in the PSR.
+           Can only be executed in Privileged modes.
+ */
+__ALWAYS_STATIC_INLINE void __enable_irq(void)
+{
+#if defined(CONFIG_RISCV_SMODE) && CONFIG_RISCV_SMODE
+    __ASM volatile("csrs sstatus, 2");
+    __ASM volatile("li a0, 0x222");
+    __ASM volatile("csrs sie, a0");
+#else
+    __ASM volatile("csrs mstatus, 8");
+    __ASM volatile("li a0, 0x888");
+    __ASM volatile("csrs mie, a0");
+#endif
+}
+
+/**
+  \brief   Enable supervisor IRQ Interrupts
+  \details Enables IRQ interrupts by setting the IE-bit in the PSR.
+           Can only be executed in Privileged modes.
+ */
+__ALWAYS_STATIC_INLINE void __enable_supervisor_irq(void)
+{
+    __ASM volatile("csrs sstatus, 2");
+    __ASM volatile("li a0, 0x222");
+    __ASM volatile("csrs sie, a0");
+}
+
+/**
+  \brief   Disable IRQ Interrupts
+  \details Disables IRQ interrupts by clearing the IE-bit in the PSR.
+  Can only be executed in Privileged modes.
+ */
+__ALWAYS_STATIC_INLINE void __disable_irq(void)
+{
+#if defined(CONFIG_RISCV_SMODE) && CONFIG_RISCV_SMODE
+    __ASM volatile("csrc sstatus, 2");
+#else
+    __ASM volatile("csrc mstatus, 8");
+#endif
+}
+
+/**
+  \brief   Disable supervisor IRQ Interrupts
+  \details Disables supervisor IRQ interrupts by clearing the IE-bit in the PSR.
+  Can only be executed in Privileged modes.
+ */
+__ALWAYS_STATIC_INLINE void __disable_supervisor_irq(void)
+{
+    __ASM volatile("csrc sstatus, 2");
+}
+
+/**
+  \brief   Get MXSTATUS
+  \details Returns the content of the MXSTATUS Register.
+  \return               MXSTATUS Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MXSTATUS(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, mxstatus" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Get SXSTATUS
+  \details Returns the content of the SXSTATUS Register.
+  \return               SXSTATUS Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_SXSTATUS(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, sxstatus" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Get CPU WORK MODE
+  \details Returns CPU WORK MODE.
+  \return  CPU WORK MODE
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_CPU_WORK_MODE(void)
+{
+    uint64_t result;
+    __ASM volatile("csrr %0, sxstatus" : "=r"(result));
+    return ((result >> 30U) & 0x3U);
+}
+
+/**
+  \brief   Get SATP
+  \details Returns the content of the SATP Register.
+  \return               SATP Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_SATP(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, satp" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Set SATP
+  \details Writes the given value to the SATP Register.
+  \param [in]    satp  SATP Register value to set
+ */
+__ALWAYS_STATIC_INLINE void __set_SATP(uint64_t satp)
+{
+    __ASM volatile("csrw satp, %0" : : "r"(satp));
+}
+
+/**
+  \brief   Set MEPC
+  \details Writes the given value to the MEPC Register.
+  \param [in]    mstatus  MEPC Register value to set
+ */
+__ALWAYS_STATIC_INLINE void __set_MEPC(uint64_t mepc)
+{
+    __ASM volatile("csrw mepc, %0" : : "r"(mepc));
+}
+
+
+/**
+  \brief   Set MXSTATUS
+  \details Writes the given value to the MXSTATUS Register.
+  \param [in]    mxstatus  MXSTATUS Register value to set
+ */
+__ALWAYS_STATIC_INLINE void __set_MXSTATUS(uint64_t mxstatus)
+{
+    __ASM volatile("csrw mxstatus, %0" : : "r"(mxstatus));
+}
+
+/**
+  \brief   Get MSTATUS
+  \details Returns the content of the MSTATUS Register.
+  \return               MSTATUS Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MSTATUS(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, mstatus" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Set MSTATUS
+  \details Writes the given value to the MSTATUS Register.
+  \param [in]    mstatus  MSTATUS Register value to set
+ */
+__ALWAYS_STATIC_INLINE void __set_MSTATUS(uint64_t mstatus)
+{
+    __ASM volatile("csrw mstatus, %0" : : "r"(mstatus));
+}
+
+/**
+  \brief   Get MCOR
+  \details Returns the content of the MCOR Register.
+  \return               MCOR Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MCOR(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, mcor" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Set MCOR
+  \details Writes the given value to the MCOR Register.
+  \param [in]    mstatus  MCOR Register value to set
+ */
+__ALWAYS_STATIC_INLINE void __set_MCOR(uint64_t mcor)
+{
+    __ASM volatile("csrw mcor, %0" : : "r"(mcor));
+}
+
+/**
+  \brief   Get MHCR
+  \details Returns the content of the MHCR Register.
+  \return               MHCR Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MHCR(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, mhcr" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Set MHCR
+  \details Writes the given value to the MHCR Register.
+  \param [in]    mstatus  MHCR Register value to set
+ */
+__ALWAYS_STATIC_INLINE void __set_MHCR(uint64_t mhcr)
+{
+    __ASM volatile("csrw mhcr, %0" : : "r"(mhcr));
+}
+
+/**
+  \brief   Get MHINT
+  \details Returns the content of the MHINT Register.
+  \return               MHINT Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MHINT(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, mhint" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Set MHINT
+  \details Writes the given value to the MHINT Register.
+  \param [in]    mstatus  MHINT Register value to set
+ */
+__ALWAYS_STATIC_INLINE void __set_MHINT(uint64_t mhint)
+{
+    __ASM volatile("csrw mhint, %0" : : "r"(mhint));
+}
+
+/**
+  \brief   Get MCCR2
+  \details Returns the content of the MCCR2 Register.
+  \return               MCCR2 Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MCCR2(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, mccr2" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Set MCCR2
+  \details Writes the given value to the MCCR2 Register.
+  \param [in]    mstatus  MCCR2 Register value to set
+ */
+__ALWAYS_STATIC_INLINE void __set_MCCR2(uint64_t mccr2)
+{
+    __ASM volatile("csrw mccr2, %0" : : "r"(mccr2));
+}
+
+/**
+  \brief   Get MISA Register
+  \details Returns the content of the MISA Register.
+  \return               MISA Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MISA(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, misa" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Set MISA
+  \details Writes the given value to the MISA Register.
+  \param [in]    misa  MISA Register value to set
+ */
+__ALWAYS_STATIC_INLINE void __set_MISA(uint64_t misa)
+{
+    __ASM volatile("csrw misa, %0" : : "r"(misa));
+}
+
+/**
+  \brief   Get MIE Register
+  \details Returns the content of the MIE Register.
+  \return               MIE Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MIE(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, mie" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Set MIE
+  \details Writes the given value to the MIE Register.
+  \param [in]    mie  MIE Register value to set
+ */
+__ALWAYS_STATIC_INLINE void __set_MIE(uint64_t mie)
+{
+    __ASM volatile("csrw mie, %0" : : "r"(mie));
+}
+
+/**
+  \brief   Get MTVEC Register
+  \details Returns the content of the MTVEC Register.
+  \return               MTVEC Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MTVEC(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, mtvec" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Set MTVEC
+  \details Writes the given value to the MTVEC Register.
+  \param [in]    mtvec  MTVEC Register value to set
+ */
+__ALWAYS_STATIC_INLINE void __set_MTVEC(uint64_t mtvec)
+{
+    __ASM volatile("csrw mtvec, %0" : : "r"(mtvec));
+}
+
+/**
+  \brief   Set MTVT
+  \details Writes the given value to the MTVT Register.
+  \param [in]    mtvt  MTVT Register value to set
+ */
+__ALWAYS_STATIC_INLINE void __set_MTVT(uint64_t mtvt)
+{
+    __ASM volatile("csrw mtvt, %0" : : "r"(mtvt));
+}
+
+/**
+  \brief   Get MTVT Register
+  \details Returns the content of the MTVT Register.
+  \return               MTVT Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MTVT(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, mtvt" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Get MTIME
+  \details Returns the content of the MTIME Register.
+  \return               MTIME Register value
+  */
+__ALWAYS_STATIC_INLINE uint64_t __get_MTIME(void)
+{
+    uint64_t result;
+
+    __ASM volatile("rdtime %0" : "=r"(result));
+    //__ASM volatile("csrr %0, 0xc01" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Get SP
+  \details Returns the content of the SP Register.
+  \return               SP Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_SP(void)
+{
+    uint64_t result;
+
+    __ASM volatile("mv %0, sp" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Set SP
+  \details Writes the given value to the SP Register.
+  \param [in]    sp  SP Register value to set
+ */
+__ALWAYS_STATIC_INLINE void __set_SP(uint64_t sp)
+{
+    __ASM volatile("mv sp, %0" : : "r"(sp): "sp");
+}
+
+/**
+  \brief   Get MSCRATCH Register
+  \details Returns the content of the MSCRATCH Register.
+  \return               MSCRATCH Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MSCRATCH(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, mscratch" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Set MSCRATCH
+  \details Writes the given value to the MSCRATCH Register.
+  \param [in]    mscratch  MSCRATCH Register value to set
+ */
+__ALWAYS_STATIC_INLINE void __set_MSCRATCH(uint64_t mscratch)
+{
+    __ASM volatile("csrw mscratch, %0" : : "r"(mscratch));
+}
+
+/**
+  \brief   Get MCAUSE Register
+  \details Returns the content of the MCAUSE Register.
+  \return               MCAUSE Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MCAUSE(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, mcause" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Get SCAUSE Register
+  \details Returns the content of the SCAUSE Register.
+  \return               SCAUSE Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_SCAUSE(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, scause" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Get MNXTI Register
+  \details Returns the content of the MNXTI Register.
+  \return               MNXTI Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MNXTI(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, mnxti" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Set MNXTI
+  \details Writes the given value to the MNXTI Register.
+  \param [in]    mnxti  MNXTI Register value to set
+ */
+__ALWAYS_STATIC_INLINE void __set_MNXTI(uint64_t mnxti)
+{
+    __ASM volatile("csrw mnxti, %0" : : "r"(mnxti));
+}
+
+/**
+  \brief   Get MINTSTATUS Register
+  \details Returns the content of the MINTSTATUS Register.
+  \return               MINTSTATUS Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MINTSTATUS(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, mintstatus" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Get MTVAL Register
+  \details Returns the content of the MTVAL Register.
+  \return               MTVAL Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MTVAL(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, mtval" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Get MIP Register
+  \details Returns the content of the MIP Register.
+  \return               MIP Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MIP(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, mip" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Set MIP
+  \details Writes the given value to the MIP Register.
+  \param [in]    mip  MIP Register value to set
+ */
+__ALWAYS_STATIC_INLINE void __set_MIP(uint64_t mip)
+{
+    __ASM volatile("csrw mip, %0" : : "r"(mip));
+}
+
+/**
+  \brief   Get MCYCLEL Register
+  \details Returns the content of the MCYCLEL Register.
+  \return               MCYCLE Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MCYCLE(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, mcycle" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Get MCYCLEH Register
+  \details Returns the content of the MCYCLEH Register.
+  \return               MCYCLEH Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MCYCLEH(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, mcycleh" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Get MINSTRET Register
+  \details Returns the content of the MINSTRET Register.
+  \return               MINSTRET Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MINSTRET(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, minstret" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Get MINSTRETH Register
+  \details Returns the content of the MINSTRETH Register.
+  \return               MINSTRETH Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MINSTRETH(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, minstreth" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Get MVENDORID Register
+  \details Returns the content of the MVENDROID Register.
+  \return               MVENDORID Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MVENDORID(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, mvendorid" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Get MARCHID Register
+  \details Returns the content of the MARCHID Register.
+  \return               MARCHID Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MARCHID(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, marchid" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Get MIMPID Register
+  \details Returns the content of the MIMPID Register.
+  \return               MIMPID Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MIMPID(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, mimpid" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Get MHARTID Register
+  \details Returns the content of the MHARTID Register.
+  \return               MHARTID Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MHARTID(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, mhartid" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Get PMPCFGx Register
+  \details Returns the content of the PMPCFGx Register.
+  \return               PMPCFGx Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_PMPCFG0(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, pmpcfg0" : "=r"(result));
+    return (result);
+}
+
+__ALWAYS_STATIC_INLINE uint64_t __get_PMPCFG1(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, pmpcfg1" : "=r"(result));
+    return (result);
+}
+
+__ALWAYS_STATIC_INLINE uint64_t __get_PMPCFG2(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, pmpcfg2" : "=r"(result));
+    return (result);
+}
+
+__ALWAYS_STATIC_INLINE uint64_t __get_PMPCFG3(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, pmpcfg3" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Get PMPxCFG Register by index
+  \details Returns the content of the PMPxCFG Register.
+  \param [in]    idx    PMP region index
+  \return               PMPxCFG Register value
+ */
+__STATIC_INLINE uint8_t __get_PMPxCFG(uint64_t idx)
+{
+    uint64_t pmpcfgx = 0;
+
+    if (idx < 4) {
+        pmpcfgx = __get_PMPCFG0();
+    } else if (idx >= 4 && idx < 8) {
+        idx -= 4;
+        pmpcfgx = __get_PMPCFG1();
+    } else if (idx >= 8 && idx < 12) {
+        idx -= 8;
+        pmpcfgx = __get_PMPCFG2();
+    } else if (idx >= 12 && idx < 16) {
+        idx -= 12;
+        pmpcfgx = __get_PMPCFG3();
+    } else {
+        return 0;
+    }
+
+    return (uint8_t)((pmpcfgx & (0xFF << (idx << 3))) >> (idx << 3));
+}
+
+/**
+  \brief   Set PMPCFGx
+  \details Writes the given value to the PMPCFGx Register.
+  \param [in]    pmpcfg  PMPCFGx Register value to set
+ */
+__ALWAYS_STATIC_INLINE void __set_PMPCFG0(uint64_t pmpcfg)
+{
+    __ASM volatile("csrw pmpcfg0, %0" : : "r"(pmpcfg));
+}
+
+__ALWAYS_STATIC_INLINE void __set_PMPCFG1(uint64_t pmpcfg)
+{
+    __ASM volatile("csrw pmpcfg1, %0" : : "r"(pmpcfg));
+}
+
+__ALWAYS_STATIC_INLINE void __set_PMPCFG2(uint64_t pmpcfg)
+{
+    __ASM volatile("csrw pmpcfg2, %0" : : "r"(pmpcfg));
+}
+
+__ALWAYS_STATIC_INLINE void __set_PMPCFG3(uint64_t pmpcfg)
+{
+    __ASM volatile("csrw pmpcfg3, %0" : : "r"(pmpcfg));
+}
+
+/**
+  \brief   Set PMPxCFG by index
+  \details Writes the given value to the PMPxCFG Register.
+  \param [in]    idx      PMPx region index
+  \param [in]    pmpxcfg  PMPxCFG Register value to set
+ */
+__STATIC_INLINE void __set_PMPxCFG(uint64_t idx, uint8_t pmpxcfg)
+{
+    uint64_t pmpcfgx = 0;
+
+    if (idx < 4) {
+        pmpcfgx = __get_PMPCFG0();
+        pmpcfgx = (pmpcfgx & ~(0xFF << (idx << 3))) | ((uint64_t)(pmpxcfg) << (idx << 3));
+        __set_PMPCFG0(pmpcfgx);
+    } else if (idx >= 4 && idx < 8) {
+        idx -= 4;
+        pmpcfgx = __get_PMPCFG1();
+        pmpcfgx = (pmpcfgx & ~(0xFF << (idx << 3))) | ((uint64_t)(pmpxcfg) << (idx << 3));
+        __set_PMPCFG1(pmpcfgx);
+    } else if (idx >= 8 && idx < 12) {
+        idx -= 8;
+        pmpcfgx = __get_PMPCFG2();
+        pmpcfgx = (pmpcfgx & ~(0xFF << (idx << 3))) | ((uint64_t)(pmpxcfg) << (idx << 3));
+        __set_PMPCFG2(pmpcfgx);
+    } else if (idx >= 12 && idx < 16) {
+        idx -= 12;
+        pmpcfgx = __get_PMPCFG3();
+        pmpcfgx = (pmpcfgx & ~(0xFF << (idx << 3))) | ((uint64_t)(pmpxcfg) << (idx << 3));
+        __set_PMPCFG3(pmpcfgx);
+    } else {
+        return;
+    }
+}
+
+/**
+  \brief   Get PMPADDRx Register
+  \details Returns the content of the PMPADDRx Register.
+  \return               PMPADDRx Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_PMPADDR0(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, pmpaddr0" : "=r"(result));
+    return (result);
+}
+
+__ALWAYS_STATIC_INLINE uint64_t __get_PMPADDR1(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, pmpaddr1" : "=r"(result));
+    return (result);
+}
+
+__ALWAYS_STATIC_INLINE uint64_t __get_PMPADDR2(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, pmpaddr2" : "=r"(result));
+    return (result);
+}
+
+__ALWAYS_STATIC_INLINE uint64_t __get_PMPADDR3(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, pmpaddr3" : "=r"(result));
+    return (result);
+}
+
+__ALWAYS_STATIC_INLINE uint64_t __get_PMPADDR4(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, pmpaddr4" : "=r"(result));
+    return (result);
+}
+
+__ALWAYS_STATIC_INLINE uint64_t __get_PMPADDR5(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, pmpaddr5" : "=r"(result));
+    return (result);
+}
+
+__ALWAYS_STATIC_INLINE uint64_t __get_PMPADDR6(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, pmpaddr6" : "=r"(result));
+    return (result);
+}
+
+__ALWAYS_STATIC_INLINE uint64_t __get_PMPADDR7(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, pmpaddr7" : "=r"(result));
+    return (result);
+}
+
+__ALWAYS_STATIC_INLINE uint64_t __get_PMPADDR8(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, pmpaddr8" : "=r"(result));
+    return (result);
+}
+
+__ALWAYS_STATIC_INLINE uint64_t __get_PMPADDR9(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, pmpaddr9" : "=r"(result));
+    return (result);
+}
+
+__ALWAYS_STATIC_INLINE uint64_t __get_PMPADDR10(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, pmpaddr10" : "=r"(result));
+    return (result);
+}
+
+__ALWAYS_STATIC_INLINE uint64_t __get_PMPADDR11(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, pmpaddr11" : "=r"(result));
+    return (result);
+}
+
+__ALWAYS_STATIC_INLINE uint64_t __get_PMPADDR12(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, pmpaddr12" : "=r"(result));
+    return (result);
+}
+
+__ALWAYS_STATIC_INLINE uint64_t __get_PMPADDR13(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, pmpaddr13" : "=r"(result));
+    return (result);
+}
+
+__ALWAYS_STATIC_INLINE uint64_t __get_PMPADDR14(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, pmpaddr14" : "=r"(result));
+    return (result);
+}
+
+__ALWAYS_STATIC_INLINE uint64_t __get_PMPADDR15(void)
+{
+    uint64_t result;
+
+    __ASM volatile("csrr %0, pmpaddr15" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Get PMPADDRx Register by index
+  \details Returns the content of the PMPADDRx Register.
+  \param [in]    idx    PMP region index
+  \return               PMPADDRx Register value
+ */
+__STATIC_INLINE uint64_t __get_PMPADDRx(uint64_t idx)
+{
+    switch (idx) {
+        case 0:
+            return __get_PMPADDR0();
+
+        case 1:
+            return __get_PMPADDR1();
+
+        case 2:
+            return __get_PMPADDR2();
+
+        case 3:
+            return __get_PMPADDR3();
+
+        case 4:
+            return __get_PMPADDR4();
+
+        case 5:
+            return __get_PMPADDR5();
+
+        case 6:
+            return __get_PMPADDR6();
+
+        case 7:
+            return __get_PMPADDR7();
+
+        case 8:
+            return __get_PMPADDR8();
+
+        case 9:
+            return __get_PMPADDR9();
+
+        case 10:
+            return __get_PMPADDR10();
+
+        case 11:
+            return __get_PMPADDR11();
+
+        case 12:
+            return __get_PMPADDR12();
+
+        case 13:
+            return __get_PMPADDR13();
+
+        case 14:
+            return __get_PMPADDR14();
+
+        case 15:
+            return __get_PMPADDR15();
+
+        default:
+            return 0;
+    }
+}
+
+/**
+  \brief   Set PMPADDRx
+  \details Writes the given value to the PMPADDRx Register.
+  \param [in]    pmpaddr  PMPADDRx Register value to set
+ */
+__ALWAYS_STATIC_INLINE void __set_PMPADDR0(uint64_t pmpaddr)
+{
+    __ASM volatile("csrw pmpaddr0, %0" : : "r"(pmpaddr));
+}
+
+__ALWAYS_STATIC_INLINE void __set_PMPADDR1(uint64_t pmpaddr)
+{
+    __ASM volatile("csrw pmpaddr1, %0" : : "r"(pmpaddr));
+}
+
+__ALWAYS_STATIC_INLINE void __set_PMPADDR2(uint64_t pmpaddr)
+{
+    __ASM volatile("csrw pmpaddr2, %0" : : "r"(pmpaddr));
+}
+
+__ALWAYS_STATIC_INLINE void __set_PMPADDR3(uint64_t pmpaddr)
+{
+    __ASM volatile("csrw pmpaddr3, %0" : : "r"(pmpaddr));
+}
+
+__ALWAYS_STATIC_INLINE void __set_PMPADDR4(uint64_t pmpaddr)
+{
+    __ASM volatile("csrw pmpaddr4, %0" : : "r"(pmpaddr));
+}
+
+__ALWAYS_STATIC_INLINE void __set_PMPADDR5(uint64_t pmpaddr)
+{
+    __ASM volatile("csrw pmpaddr5, %0" : : "r"(pmpaddr));
+}
+
+__ALWAYS_STATIC_INLINE void __set_PMPADDR6(uint64_t pmpaddr)
+{
+    __ASM volatile("csrw pmpaddr6, %0" : : "r"(pmpaddr));
+}
+
+__ALWAYS_STATIC_INLINE void __set_PMPADDR7(uint64_t pmpaddr)
+{
+    __ASM volatile("csrw pmpaddr7, %0" : : "r"(pmpaddr));
+}
+
+__ALWAYS_STATIC_INLINE void __set_PMPADDR8(uint64_t pmpaddr)
+{
+    __ASM volatile("csrw pmpaddr8, %0" : : "r"(pmpaddr));
+}
+
+__ALWAYS_STATIC_INLINE void __set_PMPADDR9(uint64_t pmpaddr)
+{
+    __ASM volatile("csrw pmpaddr9, %0" : : "r"(pmpaddr));
+}
+
+__ALWAYS_STATIC_INLINE void __set_PMPADDR10(uint64_t pmpaddr)
+{
+    __ASM volatile("csrw pmpaddr10, %0" : : "r"(pmpaddr));
+}
+
+__ALWAYS_STATIC_INLINE void __set_PMPADDR11(uint64_t pmpaddr)
+{
+    __ASM volatile("csrw pmpaddr11, %0" : : "r"(pmpaddr));
+}
+
+__ALWAYS_STATIC_INLINE void __set_PMPADDR12(uint64_t pmpaddr)
+{
+    __ASM volatile("csrw pmpaddr12, %0" : : "r"(pmpaddr));
+}
+
+__ALWAYS_STATIC_INLINE void __set_PMPADDR13(uint64_t pmpaddr)
+{
+    __ASM volatile("csrw pmpaddr13, %0" : : "r"(pmpaddr));
+}
+
+__ALWAYS_STATIC_INLINE void __set_PMPADDR14(uint64_t pmpaddr)
+{
+    __ASM volatile("csrw pmpaddr14, %0" : : "r"(pmpaddr));
+}
+
+__ALWAYS_STATIC_INLINE void __set_PMPADDR15(uint64_t pmpaddr)
+{
+    __ASM volatile("csrw pmpaddr15, %0" : : "r"(pmpaddr));
+}
+
+/**
+  \brief   Set PMPADDRx by index
+  \details Writes the given value to the PMPADDRx Register.
+  \param [in]    idx      PMP region index
+  \param [in]    pmpaddr  PMPADDRx Register value to set
+ */
+__STATIC_INLINE void __set_PMPADDRx(uint64_t idx, uint64_t pmpaddr)
+{
+    switch (idx) {
+        case 0:
+            __set_PMPADDR0(pmpaddr);
+            break;
+
+        case 1:
+            __set_PMPADDR1(pmpaddr);
+            break;
+
+        case 2:
+            __set_PMPADDR2(pmpaddr);
+            break;
+
+        case 3:
+            __set_PMPADDR3(pmpaddr);
+            break;
+
+        case 4:
+            __set_PMPADDR4(pmpaddr);
+            break;
+
+        case 5:
+            __set_PMPADDR5(pmpaddr);
+            break;
+
+        case 6:
+            __set_PMPADDR6(pmpaddr);
+            break;
+
+        case 7:
+            __set_PMPADDR7(pmpaddr);
+            break;
+
+        case 8:
+            __set_PMPADDR8(pmpaddr);
+            break;
+
+        case 9:
+            __set_PMPADDR9(pmpaddr);
+            break;
+
+        case 10:
+            __set_PMPADDR10(pmpaddr);
+            break;
+
+        case 11:
+            __set_PMPADDR11(pmpaddr);
+            break;
+
+        case 12:
+            __set_PMPADDR12(pmpaddr);
+            break;
+
+        case 13:
+            __set_PMPADDR13(pmpaddr);
+            break;
+
+        case 14:
+            __set_PMPADDR14(pmpaddr);
+            break;
+
+        case 15:
+            __set_PMPADDR15(pmpaddr);
+            break;
+
+        default:
+            return;
+    }
+}
+
+/**
+  \brief   Get MCOUNTEREN
+  \details Returns the content of the MCOUNTEREN Register.
+  \return               MCOUNTEREN Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MCOUNTEREN(void)
+{
+    uint32_t result;
+
+    __ASM volatile("csrr %0, mcounteren" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Set MCOUNTEREN
+  \details Writes the given value to the MCOUNTEREN Register.
+  \param [in]    mcounteren  MCOUNTEREN Register value to set
+ */
+__ALWAYS_STATIC_INLINE void __set_MCOUNTEREN(uint32_t mcounteren)
+{
+    __ASM volatile("csrw mcounteren, %0" : : "r"(mcounteren));
+}
+
+/**
+  \brief   Get MCOUNTERWEN
+  \details Returns the content of the MCOUNTERWEN Register.
+  \return               MCOUNTERWEN Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MCOUNTERWEN(void)
+{
+    uint32_t result;
+
+    __ASM volatile("csrr %0, mcounterwen" : "=r"(result));
+    return (result);
+}
+
+/**
+  \brief   Set MCOUNTERWEN
+  \details Writes the given value to the MCOUNTERWEN Register.
+  \param [in]    mcounterwen  MCOUNTERWEN Register value to set
+ */
+__ALWAYS_STATIC_INLINE void __set_MCOUNTERWEN(uint32_t mcounterwen)
+{
+    __ASM volatile("csrw mcounterwen, %0" : : "r"(mcounterwen));
+}
+/**
+  \brief   Set MEDELEG Register
+  \details Writes the given value to the MEDELEG Register.
+ */
+__ALWAYS_STATIC_INLINE void __set_MEDELEG(uint64_t x)
+{
+    asm volatile("csrw medeleg, %0"::"r"(x));
+}
+
+/**
+  \brief   Set MEDELEG Register
+  \details Writes the given value to the MEDELEG Register.
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MEDELEG(void)
+{
+    uint64_t x;
+    asm volatile("csrr %0, medeleg":"=r"(x));
+    return x;
+}
+
+/**
+  \brief   Set MIDELEG Register
+  \details Writes the given value to the MIDELEG Register.
+ */
+__ALWAYS_STATIC_INLINE void __set_MIDELEG(uint64_t x)
+{
+    asm volatile("csrw mideleg, %0"::"r"(x));
+}
+
+/**
+  \brief   Get MIDELEG Register
+  \details Returns the content of the MIDELEG Register.
+  \return               MIDELEG Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_MIDELEG(void)
+{
+    uint64_t x;
+    asm volatile("csrr %0, mideleg":"=r"(x));
+    return x;
+}
+
+/**
+  \brief   Set SSTATUS Register
+  \details Writes the given value to the SSTATUS Register.
+ */
+__ALWAYS_STATIC_INLINE void __set_SSTATUS(uint64_t x)
+{
+    asm volatile("csrw sstatus, %0"::"r"(x));
+}
+
+/**
+  \brief   Get SSTATUS Register
+  \details Returns the content of the SSTATUS Register.
+  \return               SSTATUS Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_SSTATUS(void)
+{
+    uint64_t x;
+    asm volatile("csrr %0, sstatus":"=r"(x));
+    return x;
+}
+
+/**
+  \brief   Set SXSTATUS Register
+  \details Writes the given value to the SXSTATUS Register.
+ */
+__ALWAYS_STATIC_INLINE void __set_SXSTATUS(uint64_t x)
+{
+    asm volatile("csrw sxstatus, %0"::"r"(x));
+}
+
+/**
+  \brief   Get SXSTATUS Register
+  \details Returns the content of the SXSTATUS Register.
+  \return               SXSTATUS Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get__SXSTATUS(void)
+{
+    uint64_t x;
+    asm volatile("csrr %0, sxstatus":"=r"(x));
+    return x;
+}
+
+/**
+  \brief   Set SIE Register
+  \details Writes the given value to the SIE Register.
+ */
+__ALWAYS_STATIC_INLINE void __set_SIE(uint64_t x)
+{
+    asm volatile("csrw sie, %0"::"r"(x));
+}
+
+/**
+  \brief   Get SIE Register
+  \details Returns the content of the SIE Register.
+  \return               SIE Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_SIE(void)
+{
+    uint64_t x;
+    asm volatile("csrr %0, sie":"=r"(x));
+    return x;
+}
+
+/**
+  \brief   Set STVAC Register
+  \details Writes the given value to the STVEC Register.
+ */
+__ALWAYS_STATIC_INLINE void __set_STVEC(uint64_t x)
+{
+    asm volatile("csrw stvec, %0"::"r"(x));
+}
+
+/**
+  \brief   Get STVAC Register
+  \details Returns the content of the STVAC Register.
+  \return               STVAC Register value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __get_STVEC(void)
+{
+    uint64_t x;
+    asm volatile("csrr %0, stvec":"=r"(x));
+    return x;
+}
+
+/**
+  \brief   Enable interrupts and exceptions
+  \details Enables interrupts and exceptions by setting the IE-bit and EE-bit in the PSR.
+           Can only be executed in Privileged modes.
+ */
+__ALWAYS_STATIC_INLINE void __enable_excp_irq(void)
+{
+#ifdef CONFIG_MMU
+    __enable_supervisor_irq();
+#else
+    __enable_irq();
+#endif
+}
+
+
+/**
+  \brief   Disable interrupts and exceptions
+  \details Disables interrupts and exceptions by clearing the IE-bit and EE-bit in the PSR.
+           Can only be executed in Privileged modes.
+ */
+__ALWAYS_STATIC_INLINE void __disable_excp_irq(void)
+{
+#ifdef CONFIG_MMU
+    __disable_supervisor_irq();
+#else
+    __disable_irq();
+#endif
+}
+
+#define __CSI_GCC_OUT_REG(r) "=r" (r)
+#define __CSI_GCC_USE_REG(r) "r" (r)
+
+/**
+  \brief   No Operation
+  \details No Operation does nothing. This instruction can be used for code alignment purposes.
+ */
+__ALWAYS_STATIC_INLINE void __NOP(void)
+{
+    __ASM volatile("nop");
+}
+
+
+/**
+  \brief   return from M-MODE
+  \details return from M-MODE.
+ */
+__ALWAYS_STATIC_INLINE void __MRET(void)
+{
+    __ASM volatile("mret");
+}
+
+/**
+  \brief   Wait For Interrupt
+  \details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
+ */
+__ALWAYS_STATIC_INLINE void __WFI(void)
+{
+    __ASM volatile("wfi");
+}
+
+/**
+  \brief   Wait For Interrupt
+  \details Wait For Interrupt is a hint instruction that suspends execution until one interrupt occurs.
+ */
+__ALWAYS_STATIC_INLINE void __WAIT(void)
+{
+    __ASM volatile("wfi");
+}
+
+/**
+  \brief   Doze For Interrupt
+  \details Doze For Interrupt is a hint instruction that suspends execution until one interrupt occurs.
+ */
+__ALWAYS_STATIC_INLINE void __DOZE(void)
+{
+    __ASM volatile("wfi");
+}
+
+/**
+  \brief   Stop For Interrupt
+  \details Stop For Interrupt is a hint instruction that suspends execution until one interrupt occurs.
+ */
+__ALWAYS_STATIC_INLINE void __STOP(void)
+{
+    __ASM volatile("wfi");
+}
+
+/**
+  \brief   Instruction Synchronization Barrier
+  \details Instruction Synchronization Barrier flushes the pipeline in the processor,
+           so that all instructions following the ISB are fetched from cache or memory,
+           after the instruction has been completed.
+ */
+__ALWAYS_STATIC_INLINE void __ISB(void)
+{
+    __ASM volatile("fence.i");
+    __ASM volatile("fence r, r");
+}
+
+
+/**
+  \brief   Data Synchronization Barrier
+  \details Acts as a special kind of Data Memory Barrier.
+           It completes when all explicit memory accesses before this instruction complete.
+ */
+__ALWAYS_STATIC_INLINE void __DSB(void)
+{
+    __ASM volatile("fence iorw, iorw");
+    __ASM volatile("sync");
+}
+
+/**
+  \brief   Data Memory Barrier
+  \details Ensures the apparent order of the explicit memory operations before
+           and after the instruction, without ensuring their completion.
+ */
+__ALWAYS_STATIC_INLINE void __DMB(void)
+{
+    __ASM volatile("fence rw, rw");
+}
+
+/**
+  \brief   Data Synchronization Barrier
+  \details Acts as a special kind of Data Memory Barrier.
+           It completes when all explicit memory accesses before this instruction complete.
+ */
+__ALWAYS_STATIC_INLINE void __SYNC_IS(void)
+{
+    __ASM volatile("sync.is");
+}
+
+/**
+  \brief   Invalid all icache
+  \details invalid all icache.
+ */
+__ALWAYS_STATIC_INLINE void __ICACHE_IALL(void)
+{
+    __ASM volatile("icache.iall");
+}
+
+/**
+  \brief   Invalid all cpu icache
+  \details invalid all cpu icache.
+ */
+__ALWAYS_STATIC_INLINE void __ICACHE_IALLS(void)
+{
+    __ASM volatile("icache.ialls");
+}
+
+/**
+  \brief   Invalid Icache by phy addr
+  \details Invalid Icache by phy addr.
+  \param [in] addr  operate addr
+ */
+__ALWAYS_STATIC_INLINE void __ICACHE_IPA(uint64_t addr)
+{
+    __ASM volatile("icache.ipa %0" : : "r"(addr));
+}
+
+/**
+  \brief   Invalid Icache by virt address
+  \details Invalid Icache by virt address
+  \param [in] addr  operate addr
+ */
+__ALWAYS_STATIC_INLINE void __ICACHE_IVA(uint64_t addr)
+{
+    __ASM volatile("icache.iva %0" : : "r"(addr));
+}
+
+/**
+  \brief   Invalid all dcache
+  \details invalid all dcache.
+ */
+__ALWAYS_STATIC_INLINE void __DCACHE_IALL(void)
+{
+    __ASM volatile("dcache.iall");
+}
+
+/**
+  \brief   Clear all dcache
+  \details clear all dcache.
+ */
+__ALWAYS_STATIC_INLINE void __DCACHE_CALL(void)
+{
+    __ASM volatile("dcache.call");
+}
+
+/**
+  \brief   Clear&invalid all dcache
+  \details clear & invalid all dcache.
+ */
+__ALWAYS_STATIC_INLINE void __DCACHE_CIALL(void)
+{
+    __ASM volatile("dcache.ciall");
+}
+
+#if (__L2CACHE_PRESENT == 1U)
+/**
+  \brief   Invalid L2 cache
+  \details invalid L2 cache.
+ */
+__ALWAYS_STATIC_INLINE void __L2CACHE_IALL(void)
+{
+    __ASM volatile("l2cache.iall");
+}
+
+/**
+  \brief   Clear L2cache
+  \details clear L2cache.
+ */
+__ALWAYS_STATIC_INLINE void __L2CACHE_CALL(void)
+{
+    __ASM volatile("l2cache.call");
+}
+
+/**
+  \brief   Clear&invalid L2cache
+  \details clear & invalid L2cache.
+ */
+__ALWAYS_STATIC_INLINE void __L2CACHE_CIALL(void)
+{
+    __ASM volatile("l2cache.ciall");
+}
+#endif
+
+
+/**
+  \brief   Invalid Dcache by addr
+  \details Invalid Dcache by addr.
+  \param [in] addr  operate addr
+ */
+__ALWAYS_STATIC_INLINE void __DCACHE_IPA(uint64_t addr)
+{
+    __ASM volatile("dcache.ipa %0" : : "r"(addr));
+}
+
+/**
+  \brief   Invalid Dcache by virt addr
+  \details Invalid Dcache by virt addr.
+  \param [in] addr  operate addr
+ */
+__ALWAYS_STATIC_INLINE void __DCACHE_IVA(uint64_t addr)
+{
+    __ASM volatile("dcache.iva %0" : : "r"(addr));
+}
+
+/**
+  \brief   Clear Dcache by addr
+  \details Clear Dcache by addr.
+  \param [in] addr  operate addr
+ */
+__ALWAYS_STATIC_INLINE void __DCACHE_CPA(uint64_t addr)
+{
+    __ASM volatile("dcache.cpa %0" : : "r"(addr));
+}
+
+/**
+  \brief   Clear Dcache by virt addr
+  \details Clear Dcache by virt addr.
+  \param [in] addr  operate addr
+ */
+__ALWAYS_STATIC_INLINE void __DCACHE_CVA(uint64_t addr)
+{
+    __ASM volatile("dcache.cva %0" : : "r"(addr));
+}
+
+/**
+  \brief   Clear & Invalid Dcache by addr
+  \details Clear & Invalid Dcache by addr.
+  \param [in] addr  operate addr
+ */
+__ALWAYS_STATIC_INLINE void __DCACHE_CIPA(uint64_t addr)
+{
+    __ASM volatile("dcache.cipa %0" : : "r"(addr));
+}
+
+/**
+  \brief   Clear & Invalid Dcache by virt addr
+  \details Clear & Invalid Dcache by virt addr.
+  \param [in] addr  operate addr
+ */
+__ALWAYS_STATIC_INLINE void __DCACHE_CIVA(uint64_t addr)
+{
+    __ASM volatile("dcache.civa %0" : : "r"(addr));
+}
+
+/**
+  \brief   Reverse byte order (32 bit)
+  \details Reverses the byte order in integer value.
+  \param [in]    value  Value to reverse
+  \return               Reversed value
+ */
+__ALWAYS_STATIC_INLINE uint64_t __REV(uint64_t value)
+{
+    return __builtin_bswap32(value);
+}
+
+
+/**
+  \brief   Reverse byte order (16 bit)
+  \details Reverses the byte order in two unsigned short values.
+  \param [in]    value  Value to reverse
+  \return               Reversed value
+ */
+__ALWAYS_STATIC_INLINE uint32_t __REV16(uint32_t value)
+{
+    uint32_t result;
+
+    result = ((value & 0xFF000000) >> 8) | ((value & 0x00FF0000) << 8) |
+             ((value & 0x0000FF00) >> 8) | ((value & 0x000000FF) << 8);
+
+    return (result);
+}
+
+
+/**
+  \brief   Reverse byte order in signed short value
+  \details Reverses the byte order in a signed short value with sign extension to integer.
+  \param [in]    value  Value to reverse
+  \return               Reversed value
+ */
+__ALWAYS_STATIC_INLINE int32_t __REVSH(int32_t value)
+{
+    return (short)(((value & 0xFF00) >> 8) | ((value & 0x00FF) << 8));
+}
+
+
+/**
+  \brief   Rotate Right in unsigned value (32 bit)
+  \details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
+  \param [in]    op1  Value to rotate
+  \param [in]    op2  Number of Bits to rotate
+  \return               Rotated value
+ */
+__ALWAYS_STATIC_INLINE uint32_t __ROR(uint32_t op1, uint32_t op2)
+{
+    return (op1 >> op2) | (op1 << (32U - op2));
+}
+
+
+/**
+  \brief   Breakpoint
+  \details Causes the processor to enter Debug state
+           Debug tools can use this to investigate system state when the instruction at a particular address is reached.
+ */
+__ALWAYS_STATIC_INLINE void __BKPT(void)
+{
+    __ASM volatile("ebreak");
+}
+
+/**
+  \brief   Reverse bit order of value
+  \details Reverses the bit order of the given value.
+  \param [in]    value  Value to reverse
+  \return               Reversed value
+ */
+__ALWAYS_STATIC_INLINE uint32_t __RBIT(uint32_t value)
+{
+    uint32_t result;
+
+    int32_t s = 4 /*sizeof(v)*/ * 8 - 1; /* extra shift needed at end */
+
+    result = value;                      /* r will be reversed bits of v; first get LSB of v */
+
+    for (value >>= 1U; value; value >>= 1U) {
+        result <<= 1U;
+        result |= value & 1U;
+        s--;
+    }
+
+    result <<= s;                        /* shift when v's highest bits are zero */
+
+    return (result);
+}
+
+
+/**
+  \brief   Count leading zeros
+  \details Counts the number of leading zeros of a data value.
+  \param [in]  value  Value to count the leading zeros
+  \return             number of leading zeros in value
+ */
+#define __CLZ             __builtin_clz
+/**
+  \details This function saturates a signed value.
+  \param [in]    x   Value to be saturated
+  \param [in]    y   Bit position to saturate to [1..32]
+  \return            Saturated value.
+ */
+__ALWAYS_STATIC_INLINE int32_t __SSAT(int32_t x, uint32_t y)
+{
+    int32_t posMax, negMin;
+    uint32_t i;
+
+    posMax = 1;
+
+    for (i = 0; i < (y - 1); i++) {
+        posMax = posMax * 2;
+    }
+
+    if (x > 0) {
+        posMax = (posMax - 1);
+
+        if (x > posMax) {
+            x = posMax;
+        }
+
+//    x &= (posMax * 2 + 1);
+    } else {
+        negMin = -posMax;
+
+        if (x < negMin) {
+            x = negMin;
+        }
+
+//    x &= (posMax * 2 - 1);
+    }
+
+    return (x);
+}
+
+/**
+  \brief   Unsigned Saturate
+  \details Saturates an unsigned value.
+  \param [in]  value  Value to be saturated
+  \param [in]    sat  Bit position to saturate to (0..31)
+  \return             Saturated value
+ */
+__ALWAYS_STATIC_INLINE uint32_t __USAT(uint32_t value, uint32_t sat)
+{
+    uint32_t result;
+
+    if ((((0xFFFFFFFF >> sat) << sat) & value) != 0) {
+        result = 0xFFFFFFFF >> (32 - sat);
+    } else {
+        result = value;
+    }
+
+    return (result);
+}
+
+/**
+  \brief   Unsigned Saturate for internal use
+  \details Saturates an unsigned value, should not call directly.
+  \param [in]  value  Value to be saturated
+  \param [in]    sat  Bit position to saturate to (0..31)
+  \return             Saturated value
+ */
+__ALWAYS_STATIC_INLINE uint32_t __IUSAT(uint32_t value, uint32_t sat)
+{
+    uint32_t result;
+
+    if (value & 0x80000000) { /* only overflow set bit-31 */
+        result = 0;
+    } else if ((((0xFFFFFFFF >> sat) << sat) & value) != 0) {
+        result = 0xFFFFFFFF >> (32 - sat);
+    } else {
+        result = value;
+    }
+
+    return (result);
+}
+
+/**
+  \brief   Rotate Right with Extend
+  \details This function moves each bit of a bitstring right by one bit.
+           The carry input is shifted in at the left end of the bitstring.
+  \note    carry input will always 0.
+  \param [in]    op1  Value to rotate
+  \return               Rotated value
+ */
+__ALWAYS_STATIC_INLINE uint32_t __RRX(uint32_t op1)
+{
+    return 0;
+}
+
+/**
+  \brief   LDRT Unprivileged (8 bit)
+  \details Executes a Unprivileged LDRT instruction for 8 bit value.
+  \param [in]    addr  Pointer to location
+  \return             value of type uint8_t at (*ptr)
+ */
+__ALWAYS_STATIC_INLINE uint8_t __LDRBT(volatile uint8_t *addr)
+{
+    uint32_t result;
+
+    __ASM volatile("lb %0, 0(%1)" : "=r"(result) : "r"(addr));
+
+    return ((uint8_t) result);    /* Add explicit type cast here */
+}
+
+
+/**
+  \brief   LDRT Unprivileged (16 bit)
+  \details Executes a Unprivileged LDRT instruction for 16 bit values.
+  \param [in]    addr  Pointer to location
+  \return        value of type uint16_t at (*ptr)
+ */
+__ALWAYS_STATIC_INLINE uint16_t __LDRHT(volatile uint16_t *addr)
+{
+    uint32_t result;
+
+    __ASM volatile("lh %0, 0(%1)" : "=r"(result) : "r"(addr));
+
+    return ((uint16_t) result);    /* Add explicit type cast here */
+}
+
+
+/**
+  \brief   LDRT Unprivileged (32 bit)
+  \details Executes a Unprivileged LDRT instruction for 32 bit values.
+  \param [in]    addr  Pointer to location
+  \return        value of type uint32_t at (*ptr)
+ */
+__ALWAYS_STATIC_INLINE uint32_t __LDRT(volatile uint32_t *addr)
+{
+    uint32_t result;
+
+    __ASM volatile("lw %0, 0(%1)" : "=r"(result) : "r"(addr));
+
+    return (result);
+}
+
+
+/**
+  \brief   STRT Unprivileged (8 bit)
+  \details Executes a Unprivileged STRT instruction for 8 bit values.
+  \param [in]  value  Value to store
+  \param [in]    addr  Pointer to location
+ */
+__ALWAYS_STATIC_INLINE void __STRBT(uint8_t value, volatile uint8_t *addr)
+{
+    __ASM volatile("sb %1, 0(%0)" :: "r"(addr), "r"((uint32_t)value) : "memory");
+}
+
+
+/**
+  \brief   STRT Unprivileged (16 bit)
+  \details Executes a Unprivileged STRT instruction for 16 bit values.
+  \param [in]  value  Value to store
+  \param [in]    addr  Pointer to location
+ */
+__ALWAYS_STATIC_INLINE void __STRHT(uint16_t value, volatile uint16_t *addr)
+{
+    __ASM volatile("sh %1, 0(%0)" :: "r"(addr), "r"((uint32_t)value) : "memory");
+}
+
+
+/**
+  \brief   STRT Unprivileged (32 bit)
+  \details Executes a Unprivileged STRT instruction for 32 bit values.
+  \param [in]  value  Value to store
+  \param [in]    addr  Pointer to location
+ */
+__ALWAYS_STATIC_INLINE void __STRT(uint32_t value, volatile uint32_t *addr)
+{
+    __ASM volatile("sw %1, 0(%0)" :: "r"(addr), "r"(value) : "memory");
+}
+
+/*@}*/ /* end of group CSI_Core_InstructionInterface */
+
+/* ###################  Compiler specific Intrinsics  ########################### */
+/** \defgroup CSI_SIMD_intrinsics CSI SIMD Intrinsics
+  Access to dedicated SIMD instructions \n
+  Single Instruction Multiple Data (SIMD) extensions are provided to simplify development of application software. SIMD extensions increase the processing capability without materially increasing the power consumption. The SIMD extensions are completely transparent to the operating system (OS), allowing existing OS ports to be used.
+
+  @{
+*/
+
+/**
+  \brief   Halfword packing instruction. Combines bits[15:0] of val1 with bits[31:16]
+           of val2 levitated with the val3.
+  \details Combine a halfword from one register with a halfword from another register.
+           The second argument can be left-shifted before extraction of the halfword.
+  \param [in]    val1   first 16-bit operands
+  \param [in]    val2   second 16-bit operands
+  \param [in]    val3   value for left-shifting val2. Value range [0..31].
+  \return               the combination of halfwords.
+  \remark
+                 res[15:0]  = val1[15:0]              \n
+                 res[31:16] = val2[31:16] << val3
+ */
+__ALWAYS_STATIC_INLINE uint32_t __PKHBT(uint32_t val1, uint32_t val2, uint32_t val3)
+{
+    return ((((int32_t)(val1) << 0) & (int32_t)0x0000FFFF) | (((int32_t)(val2) << val3) & (int32_t)0xFFFF0000));
+}
+
+/**
+  \brief   Halfword packing instruction. Combines bits[31:16] of val1 with bits[15:0]
+           of val2 right-shifted with the val3.
+  \details Combine a halfword from one register with a halfword from another register.
+           The second argument can be right-shifted before extraction of the halfword.
+  \param [in]    val1   first 16-bit operands
+  \param [in]    val2   second 16-bit operands
+  \param [in]    val3   value for right-shifting val2. Value range [1..32].
+  \return               the combination of halfwords.
+  \remark
+                 res[15:0]  = val2[15:0] >> val3        \n
+                 res[31:16] = val1[31:16]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __PKHTB(uint32_t val1, uint32_t val2, uint32_t val3)
+{
+    return ((((int32_t)(val1) << 0) & (int32_t)0xFFFF0000) | (((int32_t)(val2) >> val3) & (int32_t)0x0000FFFF));
+}
+
+/**
+  \brief   Dual 16-bit signed saturate.
+  \details This function saturates a signed value.
+  \param [in]    x   two signed 16-bit values to be saturated.
+  \param [in]    y   bit position for saturation, an integral constant expression in the range 1 to 16.
+  \return        the sum of the absolute differences of the following bytes, added to the accumulation value:\n
+                 the signed saturation of the low halfword in val1, saturated to the bit position specified in
+                 val2 and returned in the low halfword of the return value.\n
+                 the signed saturation of the high halfword in val1, saturated to the bit position specified in
+                 val2 and returned in the high halfword of the return value.
+ */
+__ALWAYS_STATIC_INLINE uint32_t __SSAT16(int32_t x, const uint32_t y)
+{
+    int32_t r = 0, s = 0;
+
+    r = __SSAT((((int32_t)x << 16) >> 16), y) & (int32_t)0x0000FFFF;
+    s = __SSAT((((int32_t)x) >> 16), y) & (int32_t)0x0000FFFF;
+
+    return ((uint32_t)((s << 16) | (r)));
+}
+
+/**
+  \brief   Dual 16-bit unsigned saturate.
+  \details This function enables you to saturate two signed 16-bit values to a selected unsigned range.
+  \param [in]    x   two signed 16-bit values to be saturated.
+  \param [in]    y   bit position for saturation, an integral constant expression in the range 1 to 16.
+  \return        the saturation of the two signed 16-bit values, as non-negative values:
+                 the saturation of the low halfword in val1, saturated to the bit position specified in
+                 val2 and returned in the low halfword of the return value.\n
+                 the saturation of the high halfword in val1, saturated to the bit position specified in
+                 val2 and returned in the high halfword of the return value.
+ */
+__ALWAYS_STATIC_INLINE uint32_t __USAT16(uint32_t x, const uint32_t y)
+{
+    int32_t r = 0, s = 0;
+
+    r = __IUSAT(((x << 16) >> 16), y) & 0x0000FFFF;
+    s = __IUSAT(((x) >> 16), y) & 0x0000FFFF;
+
+    return ((s << 16) | (r));
+}
+
+/**
+  \brief   Quad 8-bit saturating addition.
+  \details This function enables you to perform four 8-bit integer additions,
+           saturating the results to the 8-bit signed integer range -2^7 <= x <= 2^7 - 1.
+  \param [in]    x   first four 8-bit summands.
+  \param [in]    y   second four 8-bit summands.
+  \return        the saturated addition of the first byte of each operand in the first byte of the return value.\n
+                 the saturated addition of the second byte of each operand in the second byte of the return value.\n
+                 the saturated addition of the third byte of each operand in the third byte of the return value.\n
+                 the saturated addition of the fourth byte of each operand in the fourth byte of the return value.\n
+                 The returned results are saturated to the 8-bit signed integer range -2^7 <= x <= 2^7 - 1.
+  \remark
+                 res[7:0]   = val1[7:0]   + val2[7:0]        \n
+                 res[15:8]  = val1[15:8]  + val2[15:8]       \n
+                 res[23:16] = val1[23:16] + val2[23:16]      \n
+                 res[31:24] = val1[31:24] + val2[31:24]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __QADD8(uint32_t x, uint32_t y)
+{
+    int32_t r, s, t, u;
+
+    r = __SSAT(((((int32_t)x << 24) >> 24) + (((int32_t)y << 24) >> 24)), 8) & (int32_t)0x000000FF;
+    s = __SSAT(((((int32_t)x << 16) >> 24) + (((int32_t)y << 16) >> 24)), 8) & (int32_t)0x000000FF;
+    t = __SSAT(((((int32_t)x <<  8) >> 24) + (((int32_t)y <<  8) >> 24)), 8) & (int32_t)0x000000FF;
+    u = __SSAT(((((int32_t)x) >> 24) + (((int32_t)y) >> 24)), 8) & (int32_t)0x000000FF;
+
+    return ((uint32_t)((u << 24) | (t << 16) | (s <<  8) | (r)));
+}
+
+/**
+  \brief   Quad 8-bit unsigned saturating addition.
+  \details This function enables you to perform four unsigned 8-bit integer additions,
+           saturating the results to the 8-bit unsigned integer range 0 < x < 2^8 - 1.
+  \param [in]    x   first four 8-bit summands.
+  \param [in]    y   second four 8-bit summands.
+  \return        the saturated addition of the first byte of each operand in the first byte of the return value.\n
+                 the saturated addition of the second byte of each operand in the second byte of the return value.\n
+                 the saturated addition of the third byte of each operand in the third byte of the return value.\n
+                 the saturated addition of the fourth byte of each operand in the fourth byte of the return value.\n
+                 The returned results are saturated to the 8-bit signed integer range 0 <= x <= 2^8 - 1.
+  \remark
+                 res[7:0]   = val1[7:0]   + val2[7:0]        \n
+                 res[15:8]  = val1[15:8]  + val2[15:8]       \n
+                 res[23:16] = val1[23:16] + val2[23:16]      \n
+                 res[31:24] = val1[31:24] + val2[31:24]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __UQADD8(uint32_t x, uint32_t y)
+{
+    int32_t r, s, t, u;
+
+    r = __IUSAT((((x << 24) >> 24) + ((y << 24) >> 24)), 8) & 0x000000FF;
+    s = __IUSAT((((x << 16) >> 24) + ((y << 16) >> 24)), 8) & 0x000000FF;
+    t = __IUSAT((((x <<  8) >> 24) + ((y <<  8) >> 24)), 8) & 0x000000FF;
+    u = __IUSAT((((x) >> 24) + ((y) >> 24)), 8) & 0x000000FF;
+
+    return ((u << 24) | (t << 16) | (s <<  8) | (r));
+}
+
+/**
+  \brief   Quad 8-bit signed addition.
+  \details This function performs four 8-bit signed integer additions.
+  \param [in]    x  first four 8-bit summands.
+  \param [in]    y  second four 8-bit summands.
+  \return        the addition of the first bytes from each operand, in the first byte of the return value.\n
+                 the addition of the second bytes of each operand, in the second byte of the return value.\n
+                 the addition of the third bytes of each operand, in the third byte of the return value.\n
+                 the addition of the fourth bytes of each operand, in the fourth byte of the return value.
+  \remark
+                 res[7:0]   = val1[7:0]   + val2[7:0]        \n
+                 res[15:8]  = val1[15:8]  + val2[15:8]       \n
+                 res[23:16] = val1[23:16] + val2[23:16]      \n
+                 res[31:24] = val1[31:24] + val2[31:24]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __SADD8(uint32_t x, uint32_t y)
+{
+    int32_t r, s, t, u;
+
+    r = ((((int32_t)x << 24) >> 24) + (((int32_t)y << 24) >> 24)) & (int32_t)0x000000FF;
+    s = ((((int32_t)x << 16) >> 24) + (((int32_t)y << 16) >> 24)) & (int32_t)0x000000FF;
+    t = ((((int32_t)x <<  8) >> 24) + (((int32_t)y <<  8) >> 24)) & (int32_t)0x000000FF;
+    u = ((((int32_t)x) >> 24) + (((int32_t)y) >> 24)) & (int32_t)0x000000FF;
+
+    return ((uint32_t)((u << 24) | (t << 16) | (s <<  8) | (r)));
+}
+
+/**
+  \brief   Quad 8-bit unsigned addition.
+  \details This function performs four unsigned 8-bit integer additions.
+  \param [in]    x  first four 8-bit summands.
+  \param [in]    y  second four 8-bit summands.
+  \return        the addition of the first bytes from each operand, in the first byte of the return value.\n
+                 the addition of the second bytes of each operand, in the second byte of the return value.\n
+                 the addition of the third bytes of each operand, in the third byte of the return value.\n
+                 the addition of the fourth bytes of each operand, in the fourth byte of the return value.
+  \remark
+                 res[7:0]   = val1[7:0]   + val2[7:0]        \n
+                 res[15:8]  = val1[15:8]  + val2[15:8]       \n
+                 res[23:16] = val1[23:16] + val2[23:16]      \n
+                 res[31:24] = val1[31:24] + val2[31:24]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __UADD8(uint32_t x, uint32_t y)
+{
+    int32_t r, s, t, u;
+
+    r = (((x << 24) >> 24) + ((y << 24) >> 24)) & 0x000000FF;
+    s = (((x << 16) >> 24) + ((y << 16) >> 24)) & 0x000000FF;
+    t = (((x <<  8) >> 24) + ((y <<  8) >> 24)) & 0x000000FF;
+    u = (((x) >> 24) + ((y) >> 24)) & 0x000000FF;
+
+    return ((u << 24) | (t << 16) | (s <<  8) | (r));
+}
+
+/**
+  \brief   Quad 8-bit saturating subtract.
+  \details This function enables you to perform four 8-bit integer subtractions,
+           saturating the results to the 8-bit signed integer range -2^7 <= x <= 2^7 - 1.
+  \param [in]    x   first four 8-bit summands.
+  \param [in]    y   second four 8-bit summands.
+  \return        the subtraction of the first byte of each operand in the first byte of the return value.\n
+                 the subtraction of the second byte of each operand in the second byte of the return value.\n
+                 the subtraction of the third byte of each operand in the third byte of the return value.\n
+                 the subtraction of the fourth byte of each operand in the fourth byte of the return value.\n
+                 The returned results are saturated to the 8-bit signed integer range -2^7 <= x <= 2^7 - 1.
+  \remark
+                 res[7:0]   = val1[7:0]   - val2[7:0]        \n
+                 res[15:8]  = val1[15:8]  - val2[15:8]       \n
+                 res[23:16] = val1[23:16] - val2[23:16]      \n
+                 res[31:24] = val1[31:24] - val2[31:24]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __QSUB8(uint32_t x, uint32_t y)
+{
+    int32_t r, s, t, u;
+
+    r = __SSAT(((((int32_t)x << 24) >> 24) - (((int32_t)y << 24) >> 24)), 8) & (int32_t)0x000000FF;
+    s = __SSAT(((((int32_t)x << 16) >> 24) - (((int32_t)y << 16) >> 24)), 8) & (int32_t)0x000000FF;
+    t = __SSAT(((((int32_t)x <<  8) >> 24) - (((int32_t)y <<  8) >> 24)), 8) & (int32_t)0x000000FF;
+    u = __SSAT(((((int32_t)x) >> 24) - (((int32_t)y) >> 24)), 8) & (int32_t)0x000000FF;
+
+    return ((uint32_t)((u << 24) | (t << 16) | (s <<  8) | (r)));
+}
+
+/**
+  \brief   Quad 8-bit unsigned saturating subtraction.
+  \details This function enables you to perform four unsigned 8-bit integer subtractions,
+           saturating the results to the 8-bit unsigned integer range 0 < x < 2^8 - 1.
+  \param [in]    x   first four 8-bit summands.
+  \param [in]    y   second four 8-bit summands.
+  \return        the subtraction of the first byte of each operand in the first byte of the return value.\n
+                 the subtraction of the second byte of each operand in the second byte of the return value.\n
+                 the subtraction of the third byte of each operand in the third byte of the return value.\n
+                 the subtraction of the fourth byte of each operand in the fourth byte of the return value.\n
+                 The returned results are saturated to the 8-bit unsigned integer range 0 <= x <= 2^8 - 1.
+  \remark
+                 res[7:0]   = val1[7:0]   - val2[7:0]        \n
+                 res[15:8]  = val1[15:8]  - val2[15:8]       \n
+                 res[23:16] = val1[23:16] - val2[23:16]      \n
+                 res[31:24] = val1[31:24] - val2[31:24]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __UQSUB8(uint32_t x, uint32_t y)
+{
+    int32_t r, s, t, u;
+
+    r = __IUSAT((((x << 24) >> 24) - ((y << 24) >> 24)), 8) & 0x000000FF;
+    s = __IUSAT((((x << 16) >> 24) - ((y << 16) >> 24)), 8) & 0x000000FF;
+    t = __IUSAT((((x <<  8) >> 24) - ((y <<  8) >> 24)), 8) & 0x000000FF;
+    u = __IUSAT((((x) >> 24) - ((y) >> 24)), 8) & 0x000000FF;
+
+    return ((u << 24) | (t << 16) | (s <<  8) | (r));
+}
+
+/**
+  \brief   Quad 8-bit signed subtraction.
+  \details This function enables you to perform four 8-bit signed integer subtractions.
+  \param [in]    x  first four 8-bit operands of each subtraction.
+  \param [in]    y  second four 8-bit operands of each subtraction.
+  \return        the subtraction of the first bytes from each operand, in the first byte of the return value.\n
+                 the subtraction of the second bytes of each operand, in the second byte of the return value.\n
+                 the subtraction of the third bytes of each operand, in the third byte of the return value.\n
+                 the subtraction of the fourth bytes of each operand, in the fourth byte of the return value.
+  \remark
+                 res[7:0]   = val1[7:0]   - val2[7:0]        \n
+                 res[15:8]  = val1[15:8]  - val2[15:8]       \n
+                 res[23:16] = val1[23:16] - val2[23:16]      \n
+                 res[31:24] = val1[31:24] - val2[31:24]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __SSUB8(uint32_t x, uint32_t y)
+{
+    int32_t r, s, t, u;
+
+    r = ((((int32_t)x << 24) >> 24) - (((int32_t)y << 24) >> 24)) & (int32_t)0x000000FF;
+    s = ((((int32_t)x << 16) >> 24) - (((int32_t)y << 16) >> 24)) & (int32_t)0x000000FF;
+    t = ((((int32_t)x <<  8) >> 24) - (((int32_t)y <<  8) >> 24)) & (int32_t)0x000000FF;
+    u = ((((int32_t)x) >> 24) - (((int32_t)y) >> 24)) & (int32_t)0x000000FF;
+
+    return ((uint32_t)((u << 24) | (t << 16) | (s <<  8) | (r)));
+}
+
+/**
+  \brief   Quad 8-bit unsigned subtract.
+  \details This function enables you to perform four 8-bit unsigned integer subtractions.
+  \param [in]    x  first four 8-bit operands of each subtraction.
+  \param [in]    y  second four 8-bit operands of each subtraction.
+  \return        the subtraction of the first bytes from each operand, in the first byte of the return value.\n
+                 the subtraction of the second bytes of each operand, in the second byte of the return value.\n
+                 the subtraction of the third bytes of each operand, in the third byte of the return value.\n
+                 the subtraction of the fourth bytes of each operand, in the fourth byte of the return value.
+  \remark
+                 res[7:0]   = val1[7:0]   - val2[7:0]        \n
+                 res[15:8]  = val1[15:8]  - val2[15:8]       \n
+                 res[23:16] = val1[23:16] - val2[23:16]      \n
+                 res[31:24] = val1[31:24] - val2[31:24]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __USUB8(uint32_t x, uint32_t y)
+{
+    int32_t r, s, t, u;
+
+    r = (((x << 24) >> 24) - ((y << 24) >> 24)) & 0x000000FF;
+    s = (((x << 16) >> 24) - ((y << 16) >> 24)) & 0x000000FF;
+    t = (((x <<  8) >> 24) - ((y <<  8) >> 24)) & 0x000000FF;
+    u = (((x) >> 24) - ((y) >> 24)) & 0x000000FF;
+
+    return ((u << 24) | (t << 16) | (s <<  8) | (r));
+}
+
+/**
+  \brief   Unsigned sum of quad 8-bit unsigned absolute difference.
+  \details This function enables you to perform four unsigned 8-bit subtractions, and add the absolute values
+           of the differences together, returning the result as a single unsigned integer.
+  \param [in]    x  first four 8-bit operands of each subtraction.
+  \param [in]    y  second four 8-bit operands of each subtraction.
+  \return        the subtraction of the first bytes from each operand, in the first byte of the return value.\n
+                 the subtraction of the second bytes of each operand, in the second byte of the return value.\n
+                 the subtraction of the third bytes of each operand, in the third byte of the return value.\n
+                 the subtraction of the fourth bytes of each operand, in the fourth byte of the return value.\n
+                 The sum is returned as a single unsigned integer.
+  \remark
+                 absdiff1   = val1[7:0]   - val2[7:0]        \n
+                 absdiff2   = val1[15:8]  - val2[15:8]       \n
+                 absdiff3   = val1[23:16] - val2[23:16]      \n
+                 absdiff4   = val1[31:24] - val2[31:24]      \n
+                 res[31:0]  = absdiff1 + absdiff2 + absdiff3 + absdiff4
+ */
+__ALWAYS_STATIC_INLINE uint32_t __USAD8(uint32_t x, uint32_t y)
+{
+    int32_t r, s, t, u;
+
+    r = (((x << 24) >> 24) - ((y << 24) >> 24)) & 0x000000FF;
+    s = (((x << 16) >> 24) - ((y << 16) >> 24)) & 0x000000FF;
+    t = (((x <<  8) >> 24) - ((y <<  8) >> 24)) & 0x000000FF;
+    u = (((x) >> 24) - ((y) >> 24)) & 0x000000FF;
+
+    return (u + t + s + r);
+}
+
+/**
+  \brief   Unsigned sum of quad 8-bit unsigned absolute difference with 32-bit accumulate.
+  \details This function enables you to perform four unsigned 8-bit subtractions, and add the absolute values
+           of the differences to a 32-bit accumulate operand.
+  \param [in]    x  first four 8-bit operands of each subtraction.
+  \param [in]    y  second four 8-bit operands of each subtraction.
+  \param [in]  sum  accumulation value.
+  \return        the sum of the absolute differences of the following bytes, added to the accumulation value:
+                 the subtraction of the first bytes from each operand, in the first byte of the return value.\n
+                 the subtraction of the second bytes of each operand, in the second byte of the return value.\n
+                 the subtraction of the third bytes of each operand, in the third byte of the return value.\n
+                 the subtraction of the fourth bytes of each operand, in the fourth byte of the return value.
+  \remark
+                 absdiff1 = val1[7:0]   - val2[7:0]        \n
+                 absdiff2 = val1[15:8]  - val2[15:8]       \n
+                 absdiff3 = val1[23:16] - val2[23:16]      \n
+                 absdiff4 = val1[31:24] - val2[31:24]      \n
+                 sum = absdiff1 + absdiff2 + absdiff3 + absdiff4 \n
+                 res[31:0] = sum[31:0] + val3[31:0]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __USADA8(uint32_t x, uint32_t y, uint32_t sum)
+{
+    int32_t r, s, t, u;
+
+#ifdef __cplusplus
+    r = (abs((long long)((x << 24) >> 24) - ((y << 24) >> 24))) & 0x000000FF;
+    s = (abs((long long)((x << 16) >> 24) - ((y << 16) >> 24))) & 0x000000FF;
+    t = (abs((long long)((x <<  8) >> 24) - ((y <<  8) >> 24))) & 0x000000FF;
+    u = (abs((long long)((x) >> 24) - ((y) >> 24))) & 0x000000FF;
+#else
+    r = (abs(((x << 24) >> 24) - ((y << 24) >> 24))) & 0x000000FF;
+    s = (abs(((x << 16) >> 24) - ((y << 16) >> 24))) & 0x000000FF;
+    t = (abs(((x <<  8) >> 24) - ((y <<  8) >> 24))) & 0x000000FF;
+    u = (abs(((x) >> 24) - ((y) >> 24))) & 0x000000FF;
+#endif
+    return (u + t + s + r + sum);
+}
+
+/**
+  \brief   Dual 16-bit saturating addition.
+  \details This function enables you to perform two 16-bit integer arithmetic additions in parallel,
+           saturating the results to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
+  \param [in]    x   first two 16-bit summands.
+  \param [in]    y   second two 16-bit summands.
+  \return        the saturated addition of the low halfwords, in the low halfword of the return value.\n
+                 the saturated addition of the high halfwords, in the high halfword of the return value.\n
+                 The returned results are saturated to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
+  \remark
+                 res[15:0]  = val1[15:0]  + val2[15:0]        \n
+                 res[31:16] = val1[31:16] + val2[31:16]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __QADD16(uint32_t x, uint32_t y)
+{
+    int32_t r = 0, s = 0;
+
+    r = __SSAT(((((int32_t)x << 16) >> 16) + (((int32_t)y << 16) >> 16)), 16) & (int32_t)0x0000FFFF;
+    s = __SSAT(((((int32_t)x) >> 16) + (((int32_t)y) >> 16)), 16) & (int32_t)0x0000FFFF;
+
+    return ((uint32_t)((s << 16) | (r)));
+}
+
+/**
+  \brief   Dual 16-bit unsigned saturating addition.
+  \details This function enables you to perform two unsigned 16-bit integer additions, saturating
+           the results to the 16-bit unsigned integer range 0 < x < 2^16 - 1.
+  \param [in]    x   first two 16-bit summands.
+  \param [in]    y   second two 16-bit summands.
+  \return        the saturated addition of the low halfwords, in the low halfword of the return value.\n
+                 the saturated addition of the high halfwords, in the high halfword of the return value.\n
+                 The results are saturated to the 16-bit unsigned integer range 0 < x < 2^16 - 1.
+  \remark
+                 res[15:0]  = val1[15:0]  + val2[15:0]        \n
+                 res[31:16] = val1[31:16] + val2[31:16]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __UQADD16(uint32_t x, uint32_t y)
+{
+    int32_t r = 0, s = 0;
+
+    r = __IUSAT((((x << 16) >> 16) + ((y << 16) >> 16)), 16) & 0x0000FFFF;
+    s = __IUSAT((((x) >> 16) + ((y) >> 16)), 16) & 0x0000FFFF;
+
+    return ((s << 16) | (r));
+}
+
+/**
+  \brief   Dual 16-bit signed addition.
+  \details This function enables you to perform two 16-bit signed integer additions.
+  \param [in]    x   first two 16-bit summands.
+  \param [in]    y   second two 16-bit summands.
+  \return        the addition of the low halfwords in the low halfword of the return value.\n
+                 the addition of the high halfwords in the high halfword of the return value.
+  \remark
+                 res[15:0]  = val1[15:0]  + val2[15:0]        \n
+                 res[31:16] = val1[31:16] + val2[31:16]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __SADD16(uint32_t x, uint32_t y)
+{
+    int32_t r = 0, s = 0;
+
+    r = ((((int32_t)x << 16) >> 16) + (((int32_t)y << 16) >> 16)) & (int32_t)0x0000FFFF;
+    s = ((((int32_t)x) >> 16) + (((int32_t)y) >> 16)) & (int32_t)0x0000FFFF;
+
+    return ((uint32_t)((s << 16) | (r)));
+}
+
+/**
+  \brief   Dual 16-bit unsigned addition
+  \details This function enables you to perform two 16-bit unsigned integer additions.
+  \param [in]    x   first two 16-bit summands for each addition.
+  \param [in]    y   second two 16-bit summands for each addition.
+  \return        the addition of the low halfwords in the low halfword of the return value.\n
+                 the addition of the high halfwords in the high halfword of the return value.
+  \remark
+                 res[15:0]  = val1[15:0]  + val2[15:0]        \n
+                 res[31:16] = val1[31:16] + val2[31:16]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __UADD16(uint32_t x, uint32_t y)
+{
+    int32_t r = 0, s = 0;
+
+    r = (((x << 16) >> 16) + ((y << 16) >> 16)) & 0x0000FFFF;
+    s = (((x) >> 16) + ((y) >> 16)) & 0x0000FFFF;
+
+    return ((s << 16) | (r));
+}
+
+
+/**
+  \brief   Dual 16-bit signed addition with halved results.
+  \details This function enables you to perform two signed 16-bit integer additions, halving the results.
+  \param [in]    x   first two 16-bit summands.
+  \param [in]    y   second two 16-bit summands.
+  \return        the halved addition of the low halfwords, in the low halfword of the return value.\n
+                 the halved addition of the high halfwords, in the high halfword of the return value.
+  \remark
+                 res[15:0]  = (val1[15:0]  + val2[15:0]) >> 1        \n
+                 res[31:16] = (val1[31:16] + val2[31:16]) >> 1
+ */
+__ALWAYS_STATIC_INLINE uint32_t __SHADD16(uint32_t x, uint32_t y)
+{
+    int32_t r, s;
+
+    r = (((((int32_t)x << 16) >> 16) + (((int32_t)y << 16) >> 16)) >> 1) & (int32_t)0x0000FFFF;
+    s = (((((int32_t)x) >> 16) + (((int32_t)y) >> 16)) >> 1) & (int32_t)0x0000FFFF;
+
+    return ((uint32_t)((s << 16) | (r)));
+}
+
+/**
+  \brief   Dual 16-bit unsigned addition with halved results.
+  \details This function enables you to perform two unsigned 16-bit integer additions, halving the results.
+  \param [in]    x   first two 16-bit summands.
+  \param [in]    y   second two 16-bit summands.
+  \return        the halved addition of the low halfwords, in the low halfword of the return value.\n
+                 the halved addition of the high halfwords, in the high halfword of the return value.
+  \remark
+                 res[15:0]  = (val1[15:0]  + val2[15:0]) >> 1        \n
+                 res[31:16] = (val1[31:16] + val2[31:16]) >> 1
+ */
+__ALWAYS_STATIC_INLINE uint32_t __UHADD16(uint32_t x, uint32_t y)
+{
+    int32_t r, s;
+
+    r = ((((x << 16) >> 16) + ((y << 16) >> 16)) >> 1) & 0x0000FFFF;
+    s = ((((x) >> 16) + ((y) >> 16)) >> 1) & 0x0000FFFF;
+
+    return ((s << 16) | (r));
+}
+
+/**
+  \brief   Quad 8-bit signed addition with halved results.
+  \details This function enables you to perform four signed 8-bit integer additions, halving the results.
+  \param [in]    x   first four 8-bit summands.
+  \param [in]    y   second four 8-bit summands.
+  \return        the halved addition of the first bytes from each operand, in the first byte of the return value.\n
+                 the halved addition of the second bytes from each operand, in the second byte of the return value.\n
+                 the halved addition of the third bytes from each operand, in the third byte of the return value.\n
+                 the halved addition of the fourth bytes from each operand, in the fourth byte of the return value.
+  \remark
+                 res[7:0]   = (val1[7:0]   + val2[7:0]  ) >> 1    \n
+                 res[15:8]  = (val1[15:8]  + val2[15:8] ) >> 1    \n
+                 res[23:16] = (val1[23:16] + val2[23:16]) >> 1    \n
+                 res[31:24] = (val1[31:24] + val2[31:24]) >> 1
+ */
+__ALWAYS_STATIC_INLINE uint32_t __SHADD8(uint32_t x, uint32_t y)
+{
+    int32_t r, s, t, u;
+
+    r = (((((int32_t)x << 24) >> 24) + (((int32_t)y << 24) >> 24)) >> 1) & (int32_t)0x000000FF;
+    s = (((((int32_t)x << 16) >> 24) + (((int32_t)y << 16) >> 24)) >> 1) & (int32_t)0x000000FF;
+    t = (((((int32_t)x <<  8) >> 24) + (((int32_t)y <<  8) >> 24)) >> 1) & (int32_t)0x000000FF;
+    u = (((((int32_t)x) >> 24) + (((int32_t)y) >> 24)) >> 1) & (int32_t)0x000000FF;
+
+    return ((uint32_t)((u << 24) | (t << 16) | (s <<  8) | (r)));
+}
+
+/**
+  \brief   Quad 8-bit unsigned addition with halved results.
+  \details This function enables you to perform four unsigned 8-bit integer additions, halving the results.
+  \param [in]    x   first four 8-bit summands.
+  \param [in]    y   second four 8-bit summands.
+  \return        the halved addition of the first bytes from each operand, in the first byte of the return value.\n
+                 the halved addition of the second bytes from each operand, in the second byte of the return value.\n
+                 the halved addition of the third bytes from each operand, in the third byte of the return value.\n
+                 the halved addition of the fourth bytes from each operand, in the fourth byte of the return value.
+  \remark
+                 res[7:0]   = (val1[7:0]   + val2[7:0]  ) >> 1    \n
+                 res[15:8]  = (val1[15:8]  + val2[15:8] ) >> 1    \n
+                 res[23:16] = (val1[23:16] + val2[23:16]) >> 1    \n
+                 res[31:24] = (val1[31:24] + val2[31:24]) >> 1
+ */
+__ALWAYS_STATIC_INLINE uint32_t __UHADD8(uint32_t x, uint32_t y)
+{
+    int32_t r, s, t, u;
+
+    r = ((((x << 24) >> 24) + ((y << 24) >> 24)) >> 1) & 0x000000FF;
+    s = ((((x << 16) >> 24) + ((y << 16) >> 24)) >> 1) & 0x000000FF;
+    t = ((((x <<  8) >> 24) + ((y <<  8) >> 24)) >> 1) & 0x000000FF;
+    u = ((((x) >> 24) + ((y) >> 24)) >> 1) & 0x000000FF;
+
+    return ((u << 24) | (t << 16) | (s <<  8) | (r));
+}
+
+/**
+  \brief   Dual 16-bit saturating subtract.
+  \details This function enables you to perform two 16-bit integer subtractions in parallel,
+           saturating the results to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
+  \param [in]    x   first two 16-bit summands.
+  \param [in]    y   second two 16-bit summands.
+  \return        the saturated subtraction of the low halfwords, in the low halfword of the return value.\n
+                 the saturated subtraction of the high halfwords, in the high halfword of the return value.\n
+                 The returned results are saturated to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
+  \remark
+                 res[15:0]  = val1[15:0]  - val2[15:0]        \n
+                 res[31:16] = val1[31:16] - val2[31:16]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __QSUB16(uint32_t x, uint32_t y)
+{
+    int32_t r, s;
+
+    r = __SSAT(((((int32_t)x << 16) >> 16) - (((int32_t)y << 16) >> 16)), 16) & (int32_t)0x0000FFFF;
+    s = __SSAT(((((int32_t)x) >> 16) - (((int32_t)y) >> 16)), 16) & (int32_t)0x0000FFFF;
+
+    return ((uint32_t)((s << 16) | (r)));
+}
+
+/**
+  \brief   Dual 16-bit unsigned saturating subtraction.
+  \details This function enables you to perform two unsigned 16-bit integer subtractions,
+           saturating the results to the 16-bit unsigned integer range 0 < x < 2^16 - 1.
+  \param [in]    x   first two 16-bit operands for each subtraction.
+  \param [in]    y   second two 16-bit operands for each subtraction.
+  \return        the saturated subtraction of the low halfwords, in the low halfword of the return value.\n
+                 the saturated subtraction of the high halfwords, in the high halfword of the return value.\n
+                 The returned results are saturated to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
+  \remark
+                 res[15:0]  = val1[15:0]  - val2[15:0]        \n
+                 res[31:16] = val1[31:16] - val2[31:16]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __UQSUB16(uint32_t x, uint32_t y)
+{
+    int32_t r, s;
+
+    r = __IUSAT((((x << 16) >> 16) - ((y << 16) >> 16)), 16) & 0x0000FFFF;
+    s = __IUSAT((((x) >> 16) - ((y) >> 16)), 16) & 0x0000FFFF;
+
+    return ((s << 16) | (r));
+}
+
+/**
+  \brief   Dual 16-bit signed subtraction.
+  \details This function enables you to perform two 16-bit signed integer subtractions.
+  \param [in]    x   first two 16-bit operands of each subtraction.
+  \param [in]    y   second two 16-bit operands of each subtraction.
+  \return        the subtraction of the low halfword in the second operand from the low
+                 halfword in the first operand, in the low halfword of the return value. \n
+                 the subtraction of the high halfword in the second operand from the high
+                 halfword in the first operand, in the high halfword of the return value.
+  \remark
+                 res[15:0]  = val1[15:0]  - val2[15:0]        \n
+                 res[31:16] = val1[31:16] - val2[31:16]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __SSUB16(uint32_t x, uint32_t y)
+{
+    int32_t r, s;
+
+    r = ((((int32_t)x << 16) >> 16) - (((int32_t)y << 16) >> 16)) & (int32_t)0x0000FFFF;
+    s = ((((int32_t)x) >> 16) - (((int32_t)y) >> 16)) & (int32_t)0x0000FFFF;
+
+    return ((uint32_t)((s << 16) | (r)));
+}
+
+/**
+  \brief   Dual 16-bit unsigned subtract.
+  \details This function enables you to perform two 16-bit unsigned integer subtractions.
+  \param [in]    x   first two 16-bit operands of each subtraction.
+  \param [in]    y   second two 16-bit operands of each subtraction.
+  \return        the subtraction of the low halfword in the second operand from the low
+                 halfword in the first operand, in the low halfword of the return value. \n
+                 the subtraction of the high halfword in the second operand from the high
+                 halfword in the first operand, in the high halfword of the return value.
+  \remark
+                 res[15:0]  = val1[15:0]  - val2[15:0]        \n
+                 res[31:16] = val1[31:16] - val2[31:16]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __USUB16(uint32_t x, uint32_t y)
+{
+    int32_t r, s;
+
+    r = (((x << 16) >> 16) - ((y << 16) >> 16)) & 0x0000FFFF;
+    s = (((x) >> 16) - ((y) >> 16)) & 0x0000FFFF;
+
+    return ((s << 16) | (r));
+}
+
+/**
+  \brief   Dual 16-bit signed subtraction with halved results.
+  \details This function enables you to perform two signed 16-bit integer subtractions, halving the results.
+  \param [in]    x   first two 16-bit summands.
+  \param [in]    y   second two 16-bit summands.
+  \return        the halved subtraction of the low halfwords, in the low halfword of the return value.\n
+                 the halved subtraction of the high halfwords, in the high halfword of the return value.
+  \remark
+                 res[15:0]  = (val1[15:0]  - val2[15:0]) >> 1        \n
+                 res[31:16] = (val1[31:16] - val2[31:16]) >> 1
+ */
+__ALWAYS_STATIC_INLINE uint32_t __SHSUB16(uint32_t x, uint32_t y)
+{
+    int32_t r, s;
+
+    r = (((((int32_t)x << 16) >> 16) - (((int32_t)y << 16) >> 16)) >> 1) & (int32_t)0x0000FFFF;
+    s = (((((int32_t)x) >> 16) - (((int32_t)y) >> 16)) >> 1) & (int32_t)0x0000FFFF;
+
+    return ((uint32_t)((s << 16) | (r)));
+}
+
+/**
+  \brief   Dual 16-bit unsigned subtraction with halved results.
+  \details This function enables you to perform two unsigned 16-bit integer subtractions, halving the results.
+  \param [in]    x   first two 16-bit summands.
+  \param [in]    y   second two 16-bit summands.
+  \return        the halved subtraction of the low halfwords, in the low halfword of the return value.\n
+                 the halved subtraction of the high halfwords, in the high halfword of the return value.
+  \remark
+                 res[15:0]  = (val1[15:0]  - val2[15:0]) >> 1        \n
+                 res[31:16] = (val1[31:16] - val2[31:16]) >> 1
+ */
+__ALWAYS_STATIC_INLINE uint32_t __UHSUB16(uint32_t x, uint32_t y)
+{
+    int32_t r, s;
+
+    r = ((((x << 16) >> 16) - ((y << 16) >> 16)) >> 1) & 0x0000FFFF;
+    s = ((((x) >> 16) - ((y) >> 16)) >> 1) & 0x0000FFFF;
+
+    return ((s << 16) | (r));
+}
+
+/**
+  \brief   Quad 8-bit signed addition with halved results.
+  \details This function enables you to perform four signed 8-bit integer subtractions, halving the results.
+  \param [in]    x   first four 8-bit summands.
+  \param [in]    y   second four 8-bit summands.
+  \return        the halved subtraction of the first bytes from each operand, in the first byte of the return value.\n
+                 the halved subtraction of the second bytes from each operand, in the second byte of the return value.\n
+                 the halved subtraction of the third bytes from each operand, in the third byte of the return value.\n
+                 the halved subtraction of the fourth bytes from each operand, in the fourth byte of the return value.
+  \remark
+                 res[7:0]   = (val1[7:0]   - val2[7:0]  ) >> 1    \n
+                 res[15:8]  = (val1[15:8]  - val2[15:8] ) >> 1    \n
+                 res[23:16] = (val1[23:16] - val2[23:16]) >> 1    \n
+                 res[31:24] = (val1[31:24] - val2[31:24]) >> 1
+ */
+__ALWAYS_STATIC_INLINE uint32_t __SHSUB8(uint32_t x, uint32_t y)
+{
+    int32_t r, s, t, u;
+
+    r = (((((int32_t)x << 24) >> 24) - (((int32_t)y << 24) >> 24)) >> 1) & (int32_t)0x000000FF;
+    s = (((((int32_t)x << 16) >> 24) - (((int32_t)y << 16) >> 24)) >> 1) & (int32_t)0x000000FF;
+    t = (((((int32_t)x <<  8) >> 24) - (((int32_t)y <<  8) >> 24)) >> 1) & (int32_t)0x000000FF;
+    u = (((((int32_t)x) >> 24) - (((int32_t)y) >> 24)) >> 1) & (int32_t)0x000000FF;
+
+    return ((uint32_t)((u << 24) | (t << 16) | (s <<  8) | (r)));
+}
+
+/**
+  \brief   Quad 8-bit unsigned subtraction with halved results.
+  \details This function enables you to perform four unsigned 8-bit integer subtractions, halving the results.
+  \param [in]    x   first four 8-bit summands.
+  \param [in]    y   second four 8-bit summands.
+  \return        the halved subtraction of the first bytes from each operand, in the first byte of the return value.\n
+                 the halved subtraction of the second bytes from each operand, in the second byte of the return value.\n
+                 the halved subtraction of the third bytes from each operand, in the third byte of the return value.\n
+                 the halved subtraction of the fourth bytes from each operand, in the fourth byte of the return value.
+  \remark
+                 res[7:0]   = (val1[7:0]   - val2[7:0]  ) >> 1    \n
+                 res[15:8]  = (val1[15:8]  - val2[15:8] ) >> 1    \n
+                 res[23:16] = (val1[23:16] - val2[23:16]) >> 1    \n
+                 res[31:24] = (val1[31:24] - val2[31:24]) >> 1
+ */
+__ALWAYS_STATIC_INLINE uint32_t __UHSUB8(uint32_t x, uint32_t y)
+{
+    int32_t r, s, t, u;
+
+    r = ((((x << 24) >> 24) - ((y << 24) >> 24)) >> 1) & 0x000000FF;
+    s = ((((x << 16) >> 24) - ((y << 16) >> 24)) >> 1) & 0x000000FF;
+    t = ((((x <<  8) >> 24) - ((y <<  8) >> 24)) >> 1) & 0x000000FF;
+    u = ((((x) >> 24) - ((y) >> 24)) >> 1) & 0x000000FF;
+
+    return ((u << 24) | (t << 16) | (s <<  8) | (r));
+}
+
+/**
+  \brief   Dual 16-bit add and subtract with exchange.
+  \details This function enables you to exchange the halfwords of the one operand,
+           then add the high halfwords and subtract the low halfwords,
+           saturating the results to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
+  \param [in]    x   first operand for the subtraction in the low halfword,
+                     and the first operand for the addition in the high halfword.
+  \param [in]    y   second operand for the subtraction in the high halfword,
+                     and the second operand for the addition in the low halfword.
+  \return        the saturated subtraction of the high halfword in the second operand from the
+                 low halfword in the first operand, in the low halfword of the return value.\n
+                 the saturated addition of the high halfword in the first operand and the
+                 low halfword in the second operand, in the high halfword of the return value.\n
+                 The returned results are saturated to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
+  \remark
+                 res[15:0]  = val1[15:0]  - val2[31:16]        \n
+                 res[31:16] = val1[31:16] + val2[15:0]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __QASX(uint32_t x, uint32_t y)
+{
+    int32_t r, s;
+
+    r = __SSAT(((((int32_t)x << 16) >> 16) - (((int32_t)y) >> 16)), 16) & (int32_t)0x0000FFFF;
+    s = __SSAT(((((int32_t)x) >> 16) + (((int32_t)y << 16) >> 16)), 16) & (int32_t)0x0000FFFF;
+
+    return ((uint32_t)((s << 16) | (r)));
+}
+
+/**
+  \brief   Dual 16-bit unsigned saturating addition and subtraction with exchange.
+  \details This function enables you to exchange the halfwords of the second operand and
+           perform one unsigned 16-bit integer addition and one unsigned 16-bit subtraction,
+           saturating the results to the 16-bit unsigned integer range 0 <= x <= 2^16 - 1.
+  \param [in]    x   first operand for the subtraction in the low halfword,
+                     and the first operand for the addition in the high halfword.
+  \param [in]    y   second operand for the subtraction in the high halfword,
+                     and the second operand for the addition in the low halfword.
+  \return        the saturated subtraction of the high halfword in the second operand from the
+                 low halfword in the first operand, in the low halfword of the return value.\n
+                 the saturated addition of the high halfword in the first operand and the
+                 low halfword in the second operand, in the high halfword of the return value.\n
+                 The returned results are saturated to the 16-bit unsigned integer range 0 <= x <= 2^16 - 1.
+  \remark
+                 res[15:0]  = val1[15:0]  - val2[31:16]        \n
+                 res[31:16] = val1[31:16] + val2[15:0]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __UQASX(uint32_t x, uint32_t y)
+{
+    int32_t r, s;
+
+    r = __IUSAT((((x << 16) >> 16) - ((y) >> 16)), 16) & 0x0000FFFF;
+    s = __IUSAT((((x) >> 16) + ((y << 16) >> 16)), 16) & 0x0000FFFF;
+
+    return ((s << 16) | (r));
+}
+
+/**
+  \brief   Dual 16-bit addition and subtraction with exchange.
+  \details It enables you to exchange the halfwords of the second operand, add the high halfwords
+           and subtract the low halfwords.
+  \param [in]    x   first operand for the subtraction in the low halfword,
+                     and the first operand for the addition in the high halfword.
+  \param [in]    y   second operand for the subtraction in the high halfword,
+                     and the second operand for the addition in the low halfword.
+  \return        the subtraction of the high halfword in the second operand from the
+                 low halfword in the first operand, in the low halfword of the return value.\n
+                 the addition of the high halfword in the first operand and the
+                 low halfword in the second operand, in the high halfword of the return value.
+  \remark
+                 res[15:0]  = val1[15:0]  - val2[31:16]        \n
+                 res[31:16] = val1[31:16] + val2[15:0]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __SASX(uint32_t x, uint32_t y)
+{
+    int32_t r, s;
+
+    r = ((((int32_t)x << 16) >> 16) - (((int32_t)y) >> 16)) & (int32_t)0x0000FFFF;
+    s = ((((int32_t)x) >> 16) + (((int32_t)y << 16) >> 16)) & (int32_t)0x0000FFFF;
+
+    return ((uint32_t)((s << 16) | (r)));
+}
+
+/**
+  \brief   Dual 16-bit unsigned addition and subtraction with exchange.
+  \details This function enables you to exchange the two halfwords of the second operand,
+           add the high halfwords and subtract the low halfwords.
+  \param [in]    x   first operand for the subtraction in the low halfword,
+                     and the first operand for the addition in the high halfword.
+  \param [in]    y   second operand for the subtraction in the high halfword,
+                     and the second operand for the addition in the low halfword.
+  \return        the subtraction of the high halfword in the second operand from the
+                 low halfword in the first operand, in the low halfword of the return value.\n
+                 the addition of the high halfword in the first operand and the
+                 low halfword in the second operand, in the high halfword of the return value.
+  \remark
+                 res[15:0]  = val1[15:0]  - val2[31:16]        \n
+                 res[31:16] = val1[31:16] + val2[15:0]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __UASX(uint32_t x, uint32_t y)
+{
+    int32_t r, s;
+
+    r = (((x << 16) >> 16) - ((y) >> 16)) & 0x0000FFFF;
+    s = (((x) >> 16) + ((y << 16) >> 16)) & 0x0000FFFF;
+
+    return ((s << 16) | (r));
+}
+
+/**
+  \brief   Dual 16-bit signed addition and subtraction with halved results.
+  \details This function enables you to exchange the two halfwords of one operand, perform one
+           signed 16-bit integer addition and one signed 16-bit subtraction, and halve the results.
+  \param [in]    x   first 16-bit operands.
+  \param [in]    y   second 16-bit operands.
+  \return        the halved subtraction of the high halfword in the second operand from the
+                 low halfword in the first operand, in the low halfword of the return value.\n
+                 the halved addition of the low halfword in the second operand from the high
+                 halfword in the first operand, in the high halfword of the return value.
+  \remark
+                 res[15:0]  = (val1[15:0]  - val2[31:16]) >> 1        \n
+                 res[31:16] = (val1[31:16] + val2[15:0]) >> 1
+ */
+__ALWAYS_STATIC_INLINE uint32_t __SHASX(uint32_t x, uint32_t y)
+{
+    int32_t r, s;
+
+    r = (((((int32_t)x << 16) >> 16) - (((int32_t)y) >> 16)) >> 1) & (int32_t)0x0000FFFF;
+    s = (((((int32_t)x) >> 16) + (((int32_t)y << 16) >> 16)) >> 1) & (int32_t)0x0000FFFF;
+
+    return ((uint32_t)((s << 16) | (r)));
+}
+
+/**
+  \brief   Dual 16-bit unsigned addition and subtraction with halved results and exchange.
+  \details This function enables you to exchange the halfwords of the second operand,
+           add the high halfwords and subtract the low halfwords, halving the results.
+  \param [in]    x   first operand for the subtraction in the low halfword, and
+                     the first operand for the addition in the high halfword.
+  \param [in]    y   second operand for the subtraction in the high halfword, and
+                     the second operand for the addition in the low halfword.
+  \return        the halved subtraction of the high halfword in the second operand from the
+                 low halfword in the first operand, in the low halfword of the return value.\n
+                 the halved addition of the low halfword in the second operand from the high
+                 halfword in the first operand, in the high halfword of the return value.
+  \remark
+                 res[15:0]  = (val1[15:0]  - val2[31:16]) >> 1        \n
+                 res[31:16] = (val1[31:16] + val2[15:0]) >> 1
+ */
+__ALWAYS_STATIC_INLINE uint32_t __UHASX(uint32_t x, uint32_t y)
+{
+    int32_t r, s;
+
+    r = ((((x << 16) >> 16) - ((y) >> 16)) >> 1) & 0x0000FFFF;
+    s = ((((x) >> 16) + ((y << 16) >> 16)) >> 1) & 0x0000FFFF;
+
+    return ((s << 16) | (r));
+}
+
+/**
+  \brief   Dual 16-bit subtract and add with exchange.
+  \details This function enables you to exchange the halfwords of one operand,
+           then subtract the high halfwords and add the low halfwords,
+           saturating the results to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
+  \param [in]    x   first operand for the addition in the low halfword,
+                     and the first operand for the subtraction in the high halfword.
+  \param [in]    y   second operand for the addition in the high halfword,
+                     and the second operand for the subtraction in the low halfword.
+  \return        the saturated addition of the low halfword of the first operand and the high
+                 halfword of the second operand, in the low halfword of the return value.\n
+                 the saturated subtraction of the low halfword of the second operand from the
+                 high halfword of the first operand, in the high halfword of the return value.\n
+                 The returned results are saturated to the 16-bit signed integer range -2^15 <= x <= 2^15 - 1.
+  \remark
+                 res[15:0]  = val1[15:0]  + val2[31:16]        \n
+                 res[31:16] = val1[31:16] - val2[15:0]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __QSAX(uint32_t x, uint32_t y)
+{
+    int32_t r, s;
+
+    r = __SSAT(((((int32_t)x << 16) >> 16) + (((int32_t)y) >> 16)), 16) & (int32_t)0x0000FFFF;
+    s = __SSAT(((((int32_t)x) >> 16) - (((int32_t)y << 16) >> 16)), 16) & (int32_t)0x0000FFFF;
+
+    return ((uint32_t)((s << 16) | (r)));
+}
+
+/**
+  \brief   Dual 16-bit unsigned saturating subtraction and addition with exchange.
+  \details This function enables you to exchange the halfwords of the second operand and perform
+           one unsigned 16-bit integer subtraction and one unsigned 16-bit addition, saturating
+           the results to the 16-bit unsigned integer range 0 <= x <= 2^16 - 1.
+  \param [in]    x   first operand for the addition in the low halfword,
+                     and the first operand for the subtraction in the high halfword.
+  \param [in]    y   second operand for the addition in the high halfword,
+                     and the second operand for the subtraction in the low halfword.
+  \return        the saturated addition of the low halfword of the first operand and the high
+                 halfword of the second operand, in the low halfword of the return value.\n
+                 the saturated subtraction of the low halfword of the second operand from the
+                 high halfword of the first operand, in the high halfword of the return value.\n
+                 The returned results are saturated to the 16-bit unsigned integer range 0 <= x <= 2^16 - 1.
+  \remark
+                 res[15:0]  = val1[15:0]  + val2[31:16]        \n
+                 res[31:16] = val1[31:16] - val2[15:0]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __UQSAX(uint32_t x, uint32_t y)
+{
+    int32_t r, s;
+
+    r = __IUSAT((((x << 16) >> 16) + ((y) >> 16)), 16) & 0x0000FFFF;
+    s = __IUSAT((((x) >> 16) - ((y << 16) >> 16)), 16) & 0x0000FFFF;
+
+    return ((s << 16) | (r));
+}
+
+/**
+  \brief   Dual 16-bit unsigned subtract and add with exchange.
+  \details This function enables you to exchange the halfwords of the second operand,
+           subtract the high halfwords and add the low halfwords.
+  \param [in]    x   first operand for the addition in the low halfword,
+                     and the first operand for the subtraction in the high halfword.
+  \param [in]    y   second operand for the addition in the high halfword,
+                     and the second operand for the subtraction in the low halfword.
+  \return        the addition of the low halfword of the first operand and the high
+                 halfword of the second operand, in the low halfword of the return value.\n
+                 the subtraction of the low halfword of the second operand from the
+                 high halfword of the first operand, in the high halfword of the return value.\n
+  \remark
+                 res[15:0]  = val1[15:0]  + val2[31:16]        \n
+                 res[31:16] = val1[31:16] - val2[15:0]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __USAX(uint32_t x, uint32_t y)
+{
+    int32_t r, s;
+
+    r = (((x << 16) >> 16) + ((y) >> 16)) & 0x0000FFFF;
+    s = (((x) >> 16) - ((y << 16) >> 16)) & 0x0000FFFF;
+
+    return ((s << 16) | (r));
+}
+
+/**
+  \brief   Dual 16-bit signed subtraction and addition with exchange.
+  \details This function enables you to exchange the two halfwords of one operand and perform one
+           16-bit integer subtraction and one 16-bit addition.
+  \param [in]    x   first operand for the addition in the low halfword, and the first operand
+                     for the subtraction in the high halfword.
+  \param [in]    y   second operand for the addition in the high halfword, and the second
+                     operand for the subtraction in the low halfword.
+  \return        the addition of the low halfword of the first operand and the high
+                 halfword of the second operand, in the low halfword of the return value.\n
+                 the subtraction of the low halfword of the second operand from the
+                 high halfword of the first operand, in the high halfword of the return value.\n
+  \remark
+                 res[15:0]  = val1[15:0]  + val2[31:16]        \n
+                 res[31:16] = val1[31:16] - val2[15:0]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __SSAX(uint32_t x, uint32_t y)
+{
+    int32_t r, s;
+
+    r = ((((int32_t)x << 16) >> 16) + (((int32_t)y) >> 16)) & (int32_t)0x0000FFFF;
+    s = ((((int32_t)x) >> 16) - (((int32_t)y << 16) >> 16)) & (int32_t)0x0000FFFF;
+
+    return ((uint32_t)((s << 16) | (r)));
+}
+
+
+/**
+  \brief   Dual 16-bit signed subtraction and addition with halved results.
+  \details This function enables you to exchange the two halfwords of one operand, perform one signed
+           16-bit integer subtraction and one signed 16-bit addition, and halve the results.
+  \param [in]    x   first 16-bit operands.
+  \param [in]    y   second 16-bit operands.
+  \return        the halved addition of the low halfword in the first operand and the
+                 high halfword in the second operand, in the low halfword of the return value.\n
+                 the halved subtraction of the low halfword in the second operand from the
+                 high halfword in the first operand, in the high halfword of the return value.
+  \remark
+                 res[15:0]  = (val1[15:0]  + val2[31:16]) >> 1        \n
+                 res[31:16] = (val1[31:16] - val2[15:0]) >> 1
+ */
+__ALWAYS_STATIC_INLINE uint32_t __SHSAX(uint32_t x, uint32_t y)
+{
+    int32_t r, s;
+
+    r = (((((int32_t)x << 16) >> 16) + (((int32_t)y) >> 16)) >> 1) & (int32_t)0x0000FFFF;
+    s = (((((int32_t)x) >> 16) - (((int32_t)y << 16) >> 16)) >> 1) & (int32_t)0x0000FFFF;
+
+    return ((uint32_t)((s << 16) | (r)));
+}
+
+/**
+  \brief   Dual 16-bit unsigned subtraction and addition with halved results and exchange.
+  \details This function enables you to exchange the halfwords of the second operand,
+           subtract the high halfwords and add the low halfwords, halving the results.
+  \param [in]    x   first operand for the addition in the low halfword, and
+                     the first operand for the subtraction in the high halfword.
+  \param [in]    y   second operand for the addition in the high halfword, and
+                     the second operand for the subtraction in the low halfword.
+  \return        the halved addition of the low halfword in the first operand and the
+                 high halfword in the second operand, in the low halfword of the return value.\n
+                 the halved subtraction of the low halfword in the second operand from the
+                 high halfword in the first operand, in the high halfword of the return value.
+  \remark
+                 res[15:0]  = (val1[15:0]  + val2[31:16]) >> 1        \n
+                 res[31:16] = (val1[31:16] - val2[15:0]) >> 1
+ */
+__ALWAYS_STATIC_INLINE uint32_t __UHSAX(uint32_t x, uint32_t y)
+{
+    int32_t r, s;
+
+    r = ((((x << 16) >> 16) + ((y) >> 16)) >> 1) & 0x0000FFFF;
+    s = ((((x) >> 16) - ((y << 16) >> 16)) >> 1) & 0x0000FFFF;
+
+    return ((s << 16) | (r));
+}
+
+/**
+  \brief   Dual 16-bit signed multiply with exchange returning difference.
+  \details This function enables you to perform two 16-bit signed multiplications, subtracting
+           one of the products from the other. The halfwords of the second operand are exchanged
+           before performing the arithmetic. This produces top * bottom and bottom * top multiplication.
+  \param [in]    x   first 16-bit operands for each multiplication.
+  \param [in]    y   second 16-bit operands for each multiplication.
+  \return        the difference of the products of the two 16-bit signed multiplications.
+  \remark
+                 p1 = val1[15:0]  * val2[31:16]       \n
+                 p2 = val1[31:16] * val2[15:0]        \n
+                 res[31:0] = p1 - p2
+ */
+__ALWAYS_STATIC_INLINE uint32_t __SMUSDX(uint32_t x, uint32_t y)
+{
+    return ((uint32_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y) >> 16)) -
+                       ((((int32_t)x) >> 16) * (((int32_t)y << 16) >> 16))));
+}
+
+/**
+  \brief   Sum of dual 16-bit signed multiply with exchange.
+  \details This function enables you to perform two 16-bit signed multiplications with exchanged
+           halfwords of the second operand, adding the products together.
+  \param [in]    x   first 16-bit operands for each multiplication.
+  \param [in]    y   second 16-bit operands for each multiplication.
+  \return        the sum of the products of the two 16-bit signed multiplications with exchanged halfwords of the second operand.
+  \remark
+                 p1 = val1[15:0]  * val2[31:16]       \n
+                 p2 = val1[31:16] * val2[15:0]        \n
+                 res[31:0] = p1 + p2
+ */
+__ALWAYS_STATIC_INLINE uint32_t __SMUADX(uint32_t x, uint32_t y)
+{
+    return ((uint32_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y) >> 16)) +
+                       ((((int32_t)x) >> 16) * (((int32_t)y << 16) >> 16))));
+}
+
+
+/**
+  \brief   Saturating add.
+  \details This function enables you to obtain the saturating add of two integers.
+  \param [in]    x   first summand of the saturating add operation.
+  \param [in]    y   second summand of the saturating add operation.
+  \return        the saturating addition of val1 and val2.
+  \remark
+                 res[31:0] = SAT(val1 + SAT(val2))
+ */
+__ALWAYS_STATIC_INLINE int32_t __QADD(int32_t x, int32_t y)
+{
+    int32_t result;
+
+    if (y >= 0) {
+        if ((int32_t)((uint32_t)x + (uint32_t)y) >= x) {
+            result = x + y;
+        } else {
+            result = 0x7FFFFFFF;
+        }
+    } else {
+        if ((int32_t)((uint32_t)x + (uint32_t)y) < x) {
+            result = x + y;
+        } else {
+            result = 0x80000000;
+        }
+    }
+
+    return result;
+}
+
+/**
+  \brief   Saturating subtract.
+  \details This function enables you to obtain the saturating add of two integers.
+  \param [in]    x   first summand of the saturating add operation.
+  \param [in]    y   second summand of the saturating add operation.
+  \return        the saturating addition of val1 and val2.
+  \remark
+                 res[31:0] = SAT(val1 - SAT(val2))
+ */
+__ALWAYS_STATIC_INLINE int32_t __QSUB(int32_t x, int32_t y)
+{
+    int64_t tmp;
+    int32_t result;
+
+    tmp = (int64_t)x - (int64_t)y;
+
+    if (tmp > 0x7fffffff) {
+        tmp = 0x7fffffff;
+    } else if (tmp < (-2147483647 - 1)) {
+        tmp = -2147483647 - 1;
+    }
+
+    result = tmp;
+    return result;
+}
+
+/**
+  \brief   Dual 16-bit signed multiply with single 32-bit accumulator.
+  \details This function enables you to perform two signed 16-bit multiplications,
+           adding both results to a 32-bit accumulate operand.
+  \param [in]    x   first 16-bit operands for each multiplication.
+  \param [in]    y   second 16-bit operands for each multiplication.
+  \param [in]  sum   accumulate value.
+  \return        the product of each multiplication added to the accumulate value, as a 32-bit integer.
+  \remark
+                 p1 = val1[15:0]  * val2[15:0]      \n
+                 p2 = val1[31:16] * val2[31:16]     \n
+                 res[31:0] = p1 + p2 + val3[31:0]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __SMLAD(uint32_t x, uint32_t y, uint32_t sum)
+{
+    return ((uint32_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y << 16) >> 16)) +
+                       ((((int32_t)x) >> 16) * (((int32_t)y) >> 16)) +
+                       (((int32_t)sum))));
+}
+
+/**
+  \brief   Pre-exchanged dual 16-bit signed multiply with single 32-bit accumulator.
+  \details This function enables you to perform two signed 16-bit multiplications with exchanged
+           halfwords of the second operand, adding both results to a 32-bit accumulate operand.
+  \param [in]    x   first 16-bit operands for each multiplication.
+  \param [in]    y   second 16-bit operands for each multiplication.
+  \param [in]  sum   accumulate value.
+  \return        the product of each multiplication with exchanged halfwords of the second
+                 operand added to the accumulate value, as a 32-bit integer.
+  \remark
+                 p1 = val1[15:0]  * val2[31:16]     \n
+                 p2 = val1[31:16] * val2[15:0]      \n
+                 res[31:0] = p1 + p2 + val3[31:0]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __SMLADX(uint32_t x, uint32_t y, uint32_t sum)
+{
+    return ((uint32_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y) >> 16)) +
+                       ((((int32_t)x) >> 16) * (((int32_t)y << 16) >> 16)) +
+                       (((int32_t)sum))));
+}
+
+/**
+  \brief   Dual 16-bit signed multiply with exchange subtract with 32-bit accumulate.
+  \details This function enables you to perform two 16-bit signed multiplications, take the
+           difference of the products, subtracting the high halfword product from the low
+           halfword product, and add the difference to a 32-bit accumulate operand.
+  \param [in]    x   first 16-bit operands for each multiplication.
+  \param [in]    y   second 16-bit operands for each multiplication.
+  \param [in]  sum   accumulate value.
+  \return        the difference of the product of each multiplication, added to the accumulate value.
+  \remark
+                 p1 = val1[15:0]  * val2[15:0]       \n
+                 p2 = val1[31:16] * val2[31:16]      \n
+                 res[31:0] = p1 - p2 + val3[31:0]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __SMLSD(uint32_t x, uint32_t y, uint32_t sum)
+{
+    return ((uint32_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y << 16) >> 16)) -
+                       ((((int32_t)x) >> 16) * (((int32_t)y) >> 16)) +
+                       (((int32_t)sum))));
+}
+
+/**
+  \brief   Dual 16-bit signed multiply with exchange subtract with 32-bit accumulate.
+  \details This function enables you to exchange the halfwords in the second operand, then perform two 16-bit
+           signed multiplications. The difference of the products is added to a 32-bit accumulate operand.
+  \param [in]    x   first 16-bit operands for each multiplication.
+  \param [in]    y   second 16-bit operands for each multiplication.
+  \param [in]  sum   accumulate value.
+  \return        the difference of the product of each multiplication, added to the accumulate value.
+  \remark
+                 p1 = val1[15:0]  * val2[31:16]     \n
+                 p2 = val1[31:16] * val2[15:0]      \n
+                 res[31:0] = p1 - p2 + val3[31:0]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __SMLSDX(uint32_t x, uint32_t y, uint32_t sum)
+{
+    return ((uint32_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y) >> 16)) -
+                       ((((int32_t)x) >> 16) * (((int32_t)y << 16) >> 16)) +
+                       (((int32_t)sum))));
+}
+
+/**
+  \brief   Dual 16-bit signed multiply with single 64-bit accumulator.
+  \details This function enables you to perform two signed 16-bit multiplications, adding both results
+           to a 64-bit accumulate operand. Overflow is only possible as a result of the 64-bit addition.
+           This overflow is not detected if it occurs. Instead, the result wraps around modulo2^64.
+  \param [in]    x   first 16-bit operands for each multiplication.
+  \param [in]    y   second 16-bit operands for each multiplication.
+  \param [in]  sum   accumulate value.
+  \return        the product of each multiplication added to the accumulate value.
+  \remark
+                 p1 = val1[15:0]  * val2[15:0]      \n
+                 p2 = val1[31:16] * val2[31:16]     \n
+                 sum = p1 + p2 + val3[63:32][31:0]  \n
+                 res[63:32] = sum[63:32]            \n
+                 res[31:0]  = sum[31:0]
+ */
+__ALWAYS_STATIC_INLINE uint64_t __SMLALD(uint32_t x, uint32_t y, uint64_t sum)
+{
+    return ((uint64_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y << 16) >> 16)) +
+                       ((((int32_t)x) >> 16) * (((int32_t)y) >> 16)) +
+                       (((uint64_t)sum))));
+}
+
+/**
+  \brief   Dual 16-bit signed multiply with exchange with single 64-bit accumulator.
+  \details This function enables you to exchange the halfwords of the second operand, and perform two
+           signed 16-bit multiplications, adding both results to a 64-bit accumulate operand. Overflow
+           is only possible as a result of the 64-bit addition. This overflow is not detected if it occurs.
+           Instead, the result wraps around modulo2^64.
+  \param [in]    x   first 16-bit operands for each multiplication.
+  \param [in]    y   second 16-bit operands for each multiplication.
+  \param [in]  sum   accumulate value.
+  \return        the product of each multiplication added to the accumulate value.
+  \remark
+                 p1 = val1[15:0]  * val2[31:16]     \n
+                 p2 = val1[31:16] * val2[15:0]      \n
+                 sum = p1 + p2 + val3[63:32][31:0]  \n
+                 res[63:32] = sum[63:32]            \n
+                 res[31:0]  = sum[31:0]
+ */
+__ALWAYS_STATIC_INLINE uint64_t __SMLALDX(uint32_t x, uint32_t y, uint64_t sum)
+{
+    return ((uint64_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y) >> 16)) +
+                       ((((int32_t)x) >> 16) * (((int32_t)y << 16) >> 16)) +
+                       (((uint64_t)sum))));
+}
+
+/**
+  \brief   dual 16-bit signed multiply subtract with 64-bit accumulate.
+  \details This function It enables you to perform two 16-bit signed multiplications, take the difference
+           of the products, subtracting the high halfword product from the low halfword product, and add the
+           difference to a 64-bit accumulate operand. Overflow cannot occur during the multiplications or the
+           subtraction. Overflow can occur as a result of the 64-bit addition, and this overflow is not
+           detected. Instead, the result wraps round to modulo2^64.
+  \param [in]    x   first 16-bit operands for each multiplication.
+  \param [in]    y   second 16-bit operands for each multiplication.
+  \param [in]  sum   accumulate value.
+  \return        the difference of the product of each multiplication, added to the accumulate value.
+  \remark
+                 p1 = val1[15:0]  * val2[15:0]      \n
+                 p2 = val1[31:16] * val2[31:16]     \n
+                 res[63:32][31:0] = p1 - p2 + val3[63:32][31:0]
+ */
+__ALWAYS_STATIC_INLINE uint64_t __SMLSLD(uint32_t x, uint32_t y, uint64_t sum)
+{
+    return ((uint64_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y << 16) >> 16)) -
+                       ((((int32_t)x) >> 16) * (((int32_t)y) >> 16)) +
+                       (((uint64_t)sum))));
+}
+
+/**
+  \brief   Dual 16-bit signed multiply with exchange subtract with 64-bit accumulate.
+  \details This function enables you to exchange the halfwords of the second operand, perform two 16-bit multiplications,
+           adding the difference of the products to a 64-bit accumulate operand. Overflow cannot occur during the
+           multiplications or the subtraction. Overflow can occur as a result of the 64-bit addition, and this overflow
+           is not detected. Instead, the result wraps round to modulo2^64.
+  \param [in]    x   first 16-bit operands for each multiplication.
+  \param [in]    y   second 16-bit operands for each multiplication.
+  \param [in]  sum   accumulate value.
+  \return        the difference of the product of each multiplication, added to the accumulate value.
+  \remark
+                 p1 = val1[15:0]  * val2[31:16]      \n
+                 p2 = val1[31:16] * val2[15:0]       \n
+                 res[63:32][31:0] = p1 - p2 + val3[63:32][31:0]
+ */
+__ALWAYS_STATIC_INLINE uint64_t __SMLSLDX(uint32_t x, uint32_t y, uint64_t sum)
+{
+    return ((uint64_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y) >> 16)) -
+                       ((((int32_t)x) >> 16) * (((int32_t)y << 16) >> 16)) +
+                       (((uint64_t)sum))));
+}
+
+/**
+  \brief   32-bit signed multiply with 32-bit truncated accumulator.
+  \details This function enables you to perform a signed 32-bit multiplications, adding the most
+           significant 32 bits of the 64-bit result to a 32-bit accumulate operand.
+  \param [in]    x   first operand for multiplication.
+  \param [in]    y   second operand for multiplication.
+  \param [in]  sum   accumulate value.
+  \return        the product of multiplication (most significant 32 bits) is added to the accumulate value, as a 32-bit integer.
+  \remark
+                 p = val1 * val2      \n
+                 res[31:0] = p[63:32] + val3[31:0]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __SMMLA(int32_t x, int32_t y, int32_t sum)
+{
+    return (uint32_t)((int32_t)((int64_t)((int64_t)x * (int64_t)y) >> 32) + sum);
+}
+
+/**
+  \brief   Sum of dual 16-bit signed multiply.
+  \details This function enables you to perform two 16-bit signed multiplications, adding the products together.
+  \param [in]    x   first 16-bit operands for each multiplication.
+  \param [in]    y   second 16-bit operands for each multiplication.
+  \return        the sum of the products of the two 16-bit signed multiplications.
+  \remark
+                 p1 = val1[15:0]  * val2[15:0]      \n
+                 p2 = val1[31:16] * val2[31:16]     \n
+                 res[31:0] = p1 + p2
+ */
+__ALWAYS_STATIC_INLINE uint32_t __SMUAD(uint32_t x, uint32_t y)
+{
+    return ((uint32_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y << 16) >> 16)) +
+                       ((((int32_t)x) >> 16) * (((int32_t)y) >> 16))));
+}
+
+/**
+  \brief   Dual 16-bit signed multiply returning difference.
+  \details This function enables you to perform two 16-bit signed multiplications, taking the difference
+           of the products by subtracting the high halfword product from the low halfword product.
+  \param [in]    x   first 16-bit operands for each multiplication.
+  \param [in]    y   second 16-bit operands for each multiplication.
+  \return        the difference of the products of the two 16-bit signed multiplications.
+  \remark
+                 p1 = val1[15:0]  * val2[15:0]      \n
+                 p2 = val1[31:16] * val2[31:16]     \n
+                 res[31:0] = p1 - p2
+ */
+__ALWAYS_STATIC_INLINE uint32_t __SMUSD(uint32_t x, uint32_t y)
+{
+    return ((uint32_t)(((((int32_t)x << 16) >> 16) * (((int32_t)y << 16) >> 16)) -
+                       ((((int32_t)x) >> 16) * (((int32_t)y) >> 16))));
+}
+
+/**
+  \brief   Dual extracted 8-bit to 16-bit signed addition.
+  \details This function enables you to extract two 8-bit values from the second operand (at bit positions
+           [7:0] and [23:16]), sign-extend them to 16-bits each, and add the results to the first operand.
+  \param [in]    x   values added to the sign-extended to 16-bit values.
+  \param [in]    y   two 8-bit values to be extracted and sign-extended.
+  \return        the addition of val1 and val2, where the 8-bit values in val2[7:0] and
+                 val2[23:16] have been extracted and sign-extended prior to the addition.
+  \remark
+                 res[15:0]  = val1[15:0] + SignExtended(val2[7:0])      \n
+                 res[31:16] = val1[31:16] + SignExtended(val2[23:16])
+ */
+__ALWAYS_STATIC_INLINE uint32_t __SXTAB16(uint32_t x, uint32_t y)
+{
+    return ((uint32_t)((((((int32_t)y << 24) >> 24) + (((int32_t)x << 16) >> 16)) & (int32_t)0x0000FFFF) |
+                       (((((int32_t)y <<  8) >>  8)  + (((int32_t)x >> 16) << 16)) & (int32_t)0xFFFF0000)));
+}
+
+/**
+  \brief   Extracted 16-bit to 32-bit unsigned addition.
+  \details This function enables you to extract two 8-bit values from one operand, zero-extend
+           them to 16 bits each, and add the results to two 16-bit values from another operand.
+  \param [in]    x   values added to the zero-extended to 16-bit values.
+  \param [in]    y   two 8-bit values to be extracted and zero-extended.
+  \return        the addition of val1 and val2, where the 8-bit values in val2[7:0] and
+                 val2[23:16] have been extracted and zero-extended prior to the addition.
+  \remark
+                 res[15:0]  = ZeroExt(val2[7:0]   to 16 bits) + val1[15:0]      \n
+                 res[31:16] = ZeroExt(val2[31:16] to 16 bits) + val1[31:16]
+ */
+__ALWAYS_STATIC_INLINE uint32_t __UXTAB16(uint32_t x, uint32_t y)
+{
+    return ((uint32_t)(((((y << 24) >> 24) + ((x << 16) >> 16)) & 0x0000FFFF) |
+                       ((((y <<  8) >>  8) + ((x >> 16) << 16)) & 0xFFFF0000)));
+}
+
+/**
+  \brief   Dual extract 8-bits and sign extend each to 16-bits.
+  \details This function enables you to extract two 8-bit values from an operand and sign-extend them to 16 bits each.
+  \param [in]    x   two 8-bit values in val[7:0] and val[23:16] to be sign-extended.
+  \return        the 8-bit values sign-extended to 16-bit values.\n
+                 sign-extended value of val[7:0] in the low halfword of the return value.\n
+                 sign-extended value of val[23:16] in the high halfword of the return value.
+  \remark
+                 res[15:0]  = SignExtended(val[7:0])       \n
+                 res[31:16] = SignExtended(val[23:16])
+ */
+__ALWAYS_STATIC_INLINE uint32_t __SXTB16(uint32_t x)
+{
+    return ((uint32_t)(((((int32_t)x << 24) >> 24) & (int32_t)0x0000FFFF) |
+                       ((((int32_t)x <<  8) >>  8) & (int32_t)0xFFFF0000)));
+}
+
+/**
+  \brief   Dual extract 8-bits and zero-extend to 16-bits.
+  \details This function enables you to extract two 8-bit values from an operand and zero-extend them to 16 bits each.
+  \param [in]    x   two 8-bit values in val[7:0] and val[23:16] to be zero-extended.
+  \return        the 8-bit values sign-extended to 16-bit values.\n
+                 sign-extended value of val[7:0] in the low halfword of the return value.\n
+                 sign-extended value of val[23:16] in the high halfword of the return value.
+  \remark
+                 res[15:0]  = SignExtended(val[7:0])       \n
+                 res[31:16] = SignExtended(val[23:16])
+ */
+__ALWAYS_STATIC_INLINE uint32_t __UXTB16(uint32_t x)
+{
+    return ((uint32_t)((((x << 24) >> 24) & 0x0000FFFF) |
+                       (((x <<  8) >>  8) & 0xFFFF0000)));
+}
+
+#endif /* _CSI_RV32_GCC_H_ */

+ 3 - 3
bsp/cvitek/drivers/libraries/cv181x/pinctrl.h

@@ -33,8 +33,8 @@ extern rt_ubase_t pinmux_base_ioremap(void);
 #define PINMUX_OFFSET(PIN_NAME) FMUX_GPIO_FUNCSEL_##PIN_NAME##_OFFSET
 #define PINMUX_VALUE(PIN_NAME, FUNC_NAME) PIN_NAME##__##FUNC_NAME
 #define PINMUX_CONFIG(PIN_NAME, FUNC_NAME) \
-		mmio_clrsetbits_32(PINMUX_BASE + FMUX_GPIO_FUNCSEL_##PIN_NAME, \
-		PINMUX_MASK(PIN_NAME) << PINMUX_OFFSET(PIN_NAME), \
-		PINMUX_VALUE(PIN_NAME, FUNC_NAME))
+        mmio_clrsetbits_32(PINMUX_BASE + FMUX_GPIO_FUNCSEL_##PIN_NAME, \
+        PINMUX_MASK(PIN_NAME) << PINMUX_OFFSET(PIN_NAME), \
+        PINMUX_VALUE(PIN_NAME, FUNC_NAME))
 
 #endif /* __PINCTRL_CV181X_H__ */

+ 637 - 0
bsp/cvitek/drivers/libraries/sdif/dw_mmc_reg.h

@@ -0,0 +1,637 @@
+#ifndef _FSL_SDIF_REGS_
+#define _FSL_SDIF_REGS_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#define FSL_FEATURE_SDIF_INTERNAL_DMA_MAX_BUFFER_SIZE 4096
+
+/* ----------------------------------------------------------------------------
+   -- SDIF Register Masks
+   ---------------------------------------------------------------------------- */
+
+/*!
+ * @addtogroup SDIF_Register_Masks SDIF Register Masks
+ * @{
+ */
+
+/*! @name CTRL - Control register */
+/*! @{ */
+#define SDIF_CTRL_CONTROLLER_RESET_MASK          (0x1U)
+#define SDIF_CTRL_CONTROLLER_RESET_SHIFT         (0U)
+#define SDIF_CTRL_CONTROLLER_RESET(x)            (((uint32_t)(((uint32_t)(x)) << SDIF_CTRL_CONTROLLER_RESET_SHIFT)) & SDIF_CTRL_CONTROLLER_RESET_MASK)
+#define SDIF_CTRL_FIFO_RESET_MASK                (0x2U)
+#define SDIF_CTRL_FIFO_RESET_SHIFT               (1U)
+#define SDIF_CTRL_FIFO_RESET(x)                  (((uint32_t)(((uint32_t)(x)) << SDIF_CTRL_FIFO_RESET_SHIFT)) & SDIF_CTRL_FIFO_RESET_MASK)
+#define SDIF_CTRL_DMA_RESET_MASK                 (0x4U)
+#define SDIF_CTRL_DMA_RESET_SHIFT                (2U)
+#define SDIF_CTRL_DMA_RESET(x)                   (((uint32_t)(((uint32_t)(x)) << SDIF_CTRL_DMA_RESET_SHIFT)) & SDIF_CTRL_DMA_RESET_MASK)
+#define SDIF_CTRL_INT_ENABLE_MASK                (0x10U)
+#define SDIF_CTRL_INT_ENABLE_SHIFT               (4U)
+#define SDIF_CTRL_INT_ENABLE(x)                  (((uint32_t)(((uint32_t)(x)) << SDIF_CTRL_INT_ENABLE_SHIFT)) & SDIF_CTRL_INT_ENABLE_MASK)
+#define SDIF_CTRL_READ_WAIT_MASK                 (0x40U)
+#define SDIF_CTRL_READ_WAIT_SHIFT                (6U)
+#define SDIF_CTRL_READ_WAIT(x)                   (((uint32_t)(((uint32_t)(x)) << SDIF_CTRL_READ_WAIT_SHIFT)) & SDIF_CTRL_READ_WAIT_MASK)
+#define SDIF_CTRL_SEND_IRQ_RESPONSE_MASK         (0x80U)
+#define SDIF_CTRL_SEND_IRQ_RESPONSE_SHIFT        (7U)
+#define SDIF_CTRL_SEND_IRQ_RESPONSE(x)           (((uint32_t)(((uint32_t)(x)) << SDIF_CTRL_SEND_IRQ_RESPONSE_SHIFT)) & SDIF_CTRL_SEND_IRQ_RESPONSE_MASK)
+#define SDIF_CTRL_ABORT_READ_DATA_MASK           (0x100U)
+#define SDIF_CTRL_ABORT_READ_DATA_SHIFT          (8U)
+#define SDIF_CTRL_ABORT_READ_DATA(x)             (((uint32_t)(((uint32_t)(x)) << SDIF_CTRL_ABORT_READ_DATA_SHIFT)) & SDIF_CTRL_ABORT_READ_DATA_MASK)
+#define SDIF_CTRL_SEND_CCSD_MASK                 (0x200U)
+#define SDIF_CTRL_SEND_CCSD_SHIFT                (9U)
+#define SDIF_CTRL_SEND_CCSD(x)                   (((uint32_t)(((uint32_t)(x)) << SDIF_CTRL_SEND_CCSD_SHIFT)) & SDIF_CTRL_SEND_CCSD_MASK)
+#define SDIF_CTRL_SEND_AUTO_STOP_CCSD_MASK       (0x400U)
+#define SDIF_CTRL_SEND_AUTO_STOP_CCSD_SHIFT      (10U)
+#define SDIF_CTRL_SEND_AUTO_STOP_CCSD(x)         (((uint32_t)(((uint32_t)(x)) << SDIF_CTRL_SEND_AUTO_STOP_CCSD_SHIFT)) & SDIF_CTRL_SEND_AUTO_STOP_CCSD_MASK)
+#define SDIF_CTRL_CEATA_DEVICE_INTERRUPT_STATUS_MASK (0x800U)
+#define SDIF_CTRL_CEATA_DEVICE_INTERRUPT_STATUS_SHIFT (11U)
+#define SDIF_CTRL_CEATA_DEVICE_INTERRUPT_STATUS(x) (((uint32_t)(((uint32_t)(x)) << SDIF_CTRL_CEATA_DEVICE_INTERRUPT_STATUS_SHIFT)) & SDIF_CTRL_CEATA_DEVICE_INTERRUPT_STATUS_MASK)
+#define SDIF_CTRL_CARD_VOLTAGE_A0_MASK           (0x10000U)
+#define SDIF_CTRL_CARD_VOLTAGE_A0_SHIFT          (16U)
+#define SDIF_CTRL_CARD_VOLTAGE_A0(x)             (((uint32_t)(((uint32_t)(x)) << SDIF_CTRL_CARD_VOLTAGE_A0_SHIFT)) & SDIF_CTRL_CARD_VOLTAGE_A0_MASK)
+#define SDIF_CTRL_CARD_VOLTAGE_A1_MASK           (0x20000U)
+#define SDIF_CTRL_CARD_VOLTAGE_A1_SHIFT          (17U)
+#define SDIF_CTRL_CARD_VOLTAGE_A1(x)             (((uint32_t)(((uint32_t)(x)) << SDIF_CTRL_CARD_VOLTAGE_A1_SHIFT)) & SDIF_CTRL_CARD_VOLTAGE_A1_MASK)
+#define SDIF_CTRL_CARD_VOLTAGE_A2_MASK           (0x40000U)
+#define SDIF_CTRL_CARD_VOLTAGE_A2_SHIFT          (18U)
+#define SDIF_CTRL_CARD_VOLTAGE_A2(x)             (((uint32_t)(((uint32_t)(x)) << SDIF_CTRL_CARD_VOLTAGE_A2_SHIFT)) & SDIF_CTRL_CARD_VOLTAGE_A2_MASK)
+#define SDIF_CTRL_USE_INTERNAL_DMAC_MASK         (0x2000000U)
+#define SDIF_CTRL_USE_INTERNAL_DMAC_SHIFT        (25U)
+#define SDIF_CTRL_USE_INTERNAL_DMAC(x)           (((uint32_t)(((uint32_t)(x)) << SDIF_CTRL_USE_INTERNAL_DMAC_SHIFT)) & SDIF_CTRL_USE_INTERNAL_DMAC_MASK)
+/*! @} */
+
+/*! @name PWREN - Power Enable register */
+/*! @{ */
+#define SDIF_PWREN_POWER_ENABLE_MASK             (0x1U)
+#define SDIF_PWREN_POWER_ENABLE_SHIFT            (0U)
+#define SDIF_PWREN_POWER_ENABLE(x)               (((uint32_t)(((uint32_t)(x)) << SDIF_PWREN_POWER_ENABLE_SHIFT)) & SDIF_PWREN_POWER_ENABLE_MASK)
+/*! @} */
+
+/*! @name CLKDIV - Clock Divider register */
+/*! @{ */
+#define SDIF_CLKDIV_CLK_DIVIDER0_MASK            (0xFFU)
+#define SDIF_CLKDIV_CLK_DIVIDER0_SHIFT           (0U)
+#define SDIF_CLKDIV_CLK_DIVIDER0(x)              (((uint32_t)(((uint32_t)(x)) << SDIF_CLKDIV_CLK_DIVIDER0_SHIFT)) & SDIF_CLKDIV_CLK_DIVIDER0_MASK)
+/*! @} */
+
+/*! @name CLKENA - Clock Enable register */
+/*! @{ */
+#define SDIF_CLKENA_CCLK_ENABLE_MASK             (0x1U)
+#define SDIF_CLKENA_CCLK_ENABLE_SHIFT            (0U)
+#define SDIF_CLKENA_CCLK_ENABLE(x)               (((uint32_t)(((uint32_t)(x)) << SDIF_CLKENA_CCLK_ENABLE_SHIFT)) & SDIF_CLKENA_CCLK_ENABLE_MASK)
+#define SDIF_CLKENA_CCLK_LOW_POWER_MASK          (0x10000U)
+#define SDIF_CLKENA_CCLK_LOW_POWER_SHIFT         (16U)
+#define SDIF_CLKENA_CCLK_LOW_POWER(x)            (((uint32_t)(((uint32_t)(x)) << SDIF_CLKENA_CCLK_LOW_POWER_SHIFT)) & SDIF_CLKENA_CCLK_LOW_POWER_MASK)
+/*! @} */
+
+/*! @name TMOUT - Time-out register */
+/*! @{ */
+#define SDIF_TMOUT_RESPONSE_TIMEOUT_MASK         (0xFFU)
+#define SDIF_TMOUT_RESPONSE_TIMEOUT_SHIFT        (0U)
+#define SDIF_TMOUT_RESPONSE_TIMEOUT(x)           (((uint32_t)(((uint32_t)(x)) << SDIF_TMOUT_RESPONSE_TIMEOUT_SHIFT)) & SDIF_TMOUT_RESPONSE_TIMEOUT_MASK)
+#define SDIF_TMOUT_DATA_TIMEOUT_MASK             (0xFFFFFF00U)
+#define SDIF_TMOUT_DATA_TIMEOUT_SHIFT            (8U)
+#define SDIF_TMOUT_DATA_TIMEOUT(x)               (((uint32_t)(((uint32_t)(x)) << SDIF_TMOUT_DATA_TIMEOUT_SHIFT)) & SDIF_TMOUT_DATA_TIMEOUT_MASK)
+/*! @} */
+
+/*! @name CTYPE - Card Type register */
+/*! @{ */
+#define SDIF_CTYPE_CARD_WIDTH0_MASK              (0x1U)
+#define SDIF_CTYPE_CARD_WIDTH0_SHIFT             (0U)
+#define SDIF_CTYPE_CARD_WIDTH0(x)                (((uint32_t)(((uint32_t)(x)) << SDIF_CTYPE_CARD_WIDTH0_SHIFT)) & SDIF_CTYPE_CARD_WIDTH0_MASK)
+#define SDIF_CTYPE_CARD_WIDTH1_MASK              (0x10000U)
+#define SDIF_CTYPE_CARD_WIDTH1_SHIFT             (16U)
+#define SDIF_CTYPE_CARD_WIDTH1(x)                (((uint32_t)(((uint32_t)(x)) << SDIF_CTYPE_CARD_WIDTH1_SHIFT)) & SDIF_CTYPE_CARD_WIDTH1_MASK)
+/*! @} */
+
+/*! @name BLKSIZ - Block Size register */
+/*! @{ */
+#define SDIF_BLKSIZ_BLOCK_SIZE_MASK              (0xFFFFU)
+#define SDIF_BLKSIZ_BLOCK_SIZE_SHIFT             (0U)
+#define SDIF_BLKSIZ_BLOCK_SIZE(x)                (((uint32_t)(((uint32_t)(x)) << SDIF_BLKSIZ_BLOCK_SIZE_SHIFT)) & SDIF_BLKSIZ_BLOCK_SIZE_MASK)
+/*! @} */
+
+/*! @name BYTCNT - Byte Count register */
+/*! @{ */
+#define SDIF_BYTCNT_BYTE_COUNT_MASK              (0xFFFFFFFFU)
+#define SDIF_BYTCNT_BYTE_COUNT_SHIFT             (0U)
+#define SDIF_BYTCNT_BYTE_COUNT(x)                (((uint32_t)(((uint32_t)(x)) << SDIF_BYTCNT_BYTE_COUNT_SHIFT)) & SDIF_BYTCNT_BYTE_COUNT_MASK)
+/*! @} */
+
+/*! @name INTMASK - Interrupt Mask register */
+/*! @{ */
+#define SDIF_INTMASK_CDET_MASK                   (0x1U)
+#define SDIF_INTMASK_CDET_SHIFT                  (0U)
+#define SDIF_INTMASK_CDET(x)                     (((uint32_t)(((uint32_t)(x)) << SDIF_INTMASK_CDET_SHIFT)) & SDIF_INTMASK_CDET_MASK)
+#define SDIF_INTMASK_RE_MASK                     (0x2U)
+#define SDIF_INTMASK_RE_SHIFT                    (1U)
+#define SDIF_INTMASK_RE(x)                       (((uint32_t)(((uint32_t)(x)) << SDIF_INTMASK_RE_SHIFT)) & SDIF_INTMASK_RE_MASK)
+#define SDIF_INTMASK_CDONE_MASK                  (0x4U)
+#define SDIF_INTMASK_CDONE_SHIFT                 (2U)
+#define SDIF_INTMASK_CDONE(x)                    (((uint32_t)(((uint32_t)(x)) << SDIF_INTMASK_CDONE_SHIFT)) & SDIF_INTMASK_CDONE_MASK)
+#define SDIF_INTMASK_DTO_MASK                    (0x8U)
+#define SDIF_INTMASK_DTO_SHIFT                   (3U)
+#define SDIF_INTMASK_DTO(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_INTMASK_DTO_SHIFT)) & SDIF_INTMASK_DTO_MASK)
+#define SDIF_INTMASK_TXDR_MASK                   (0x10U)
+#define SDIF_INTMASK_TXDR_SHIFT                  (4U)
+#define SDIF_INTMASK_TXDR(x)                     (((uint32_t)(((uint32_t)(x)) << SDIF_INTMASK_TXDR_SHIFT)) & SDIF_INTMASK_TXDR_MASK)
+#define SDIF_INTMASK_RXDR_MASK                   (0x20U)
+#define SDIF_INTMASK_RXDR_SHIFT                  (5U)
+#define SDIF_INTMASK_RXDR(x)                     (((uint32_t)(((uint32_t)(x)) << SDIF_INTMASK_RXDR_SHIFT)) & SDIF_INTMASK_RXDR_MASK)
+#define SDIF_INTMASK_RCRC_MASK                   (0x40U)
+#define SDIF_INTMASK_RCRC_SHIFT                  (6U)
+#define SDIF_INTMASK_RCRC(x)                     (((uint32_t)(((uint32_t)(x)) << SDIF_INTMASK_RCRC_SHIFT)) & SDIF_INTMASK_RCRC_MASK)
+#define SDIF_INTMASK_DCRC_MASK                   (0x80U)
+#define SDIF_INTMASK_DCRC_SHIFT                  (7U)
+#define SDIF_INTMASK_DCRC(x)                     (((uint32_t)(((uint32_t)(x)) << SDIF_INTMASK_DCRC_SHIFT)) & SDIF_INTMASK_DCRC_MASK)
+#define SDIF_INTMASK_RTO_MASK                    (0x100U)
+#define SDIF_INTMASK_RTO_SHIFT                   (8U)
+#define SDIF_INTMASK_RTO(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_INTMASK_RTO_SHIFT)) & SDIF_INTMASK_RTO_MASK)
+#define SDIF_INTMASK_DRTO_MASK                   (0x200U)
+#define SDIF_INTMASK_DRTO_SHIFT                  (9U)
+#define SDIF_INTMASK_DRTO(x)                     (((uint32_t)(((uint32_t)(x)) << SDIF_INTMASK_DRTO_SHIFT)) & SDIF_INTMASK_DRTO_MASK)
+#define SDIF_INTMASK_HTO_MASK                    (0x400U)
+#define SDIF_INTMASK_HTO_SHIFT                   (10U)
+#define SDIF_INTMASK_HTO(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_INTMASK_HTO_SHIFT)) & SDIF_INTMASK_HTO_MASK)
+#define SDIF_INTMASK_FRUN_MASK                   (0x800U)
+#define SDIF_INTMASK_FRUN_SHIFT                  (11U)
+#define SDIF_INTMASK_FRUN(x)                     (((uint32_t)(((uint32_t)(x)) << SDIF_INTMASK_FRUN_SHIFT)) & SDIF_INTMASK_FRUN_MASK)
+#define SDIF_INTMASK_HLE_MASK                    (0x1000U)
+#define SDIF_INTMASK_HLE_SHIFT                   (12U)
+#define SDIF_INTMASK_HLE(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_INTMASK_HLE_SHIFT)) & SDIF_INTMASK_HLE_MASK)
+#define SDIF_INTMASK_SBE_MASK                    (0x2000U)
+#define SDIF_INTMASK_SBE_SHIFT                   (13U)
+#define SDIF_INTMASK_SBE(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_INTMASK_SBE_SHIFT)) & SDIF_INTMASK_SBE_MASK)
+#define SDIF_INTMASK_ACD_MASK                    (0x4000U)
+#define SDIF_INTMASK_ACD_SHIFT                   (14U)
+#define SDIF_INTMASK_ACD(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_INTMASK_ACD_SHIFT)) & SDIF_INTMASK_ACD_MASK)
+#define SDIF_INTMASK_EBE_MASK                    (0x8000U)
+#define SDIF_INTMASK_EBE_SHIFT                   (15U)
+#define SDIF_INTMASK_EBE(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_INTMASK_EBE_SHIFT)) & SDIF_INTMASK_EBE_MASK)
+#define SDIF_INTMASK_SDIO_INT_MASK_MASK          (0x10000U)
+#define SDIF_INTMASK_SDIO_INT_MASK_SHIFT         (16U)
+#define SDIF_INTMASK_SDIO_INT_MASK(x)            (((uint32_t)(((uint32_t)(x)) << SDIF_INTMASK_SDIO_INT_MASK_SHIFT)) & SDIF_INTMASK_SDIO_INT_MASK_MASK)
+/*! @} */
+
+/*! @name CMDARG - Command Argument register */
+/*! @{ */
+#define SDIF_CMDARG_CMD_ARG_MASK                 (0xFFFFFFFFU)
+#define SDIF_CMDARG_CMD_ARG_SHIFT                (0U)
+#define SDIF_CMDARG_CMD_ARG(x)                   (((uint32_t)(((uint32_t)(x)) << SDIF_CMDARG_CMD_ARG_SHIFT)) & SDIF_CMDARG_CMD_ARG_MASK)
+/*! @} */
+
+/*! @name CMD - Command register */
+/*! @{ */
+#define SDIF_CMD_CMD_INDEX_MASK                  (0x3FU)
+#define SDIF_CMD_CMD_INDEX_SHIFT                 (0U)
+#define SDIF_CMD_CMD_INDEX(x)                    (((uint32_t)(((uint32_t)(x)) << SDIF_CMD_CMD_INDEX_SHIFT)) & SDIF_CMD_CMD_INDEX_MASK)
+#define SDIF_CMD_RESPONSE_EXPECT_MASK            (0x40U)
+#define SDIF_CMD_RESPONSE_EXPECT_SHIFT           (6U)
+#define SDIF_CMD_RESPONSE_EXPECT(x)              (((uint32_t)(((uint32_t)(x)) << SDIF_CMD_RESPONSE_EXPECT_SHIFT)) & SDIF_CMD_RESPONSE_EXPECT_MASK)
+#define SDIF_CMD_RESPONSE_LENGTH_MASK            (0x80U)
+#define SDIF_CMD_RESPONSE_LENGTH_SHIFT           (7U)
+#define SDIF_CMD_RESPONSE_LENGTH(x)              (((uint32_t)(((uint32_t)(x)) << SDIF_CMD_RESPONSE_LENGTH_SHIFT)) & SDIF_CMD_RESPONSE_LENGTH_MASK)
+#define SDIF_CMD_CHECK_RESPONSE_CRC_MASK         (0x100U)
+#define SDIF_CMD_CHECK_RESPONSE_CRC_SHIFT        (8U)
+#define SDIF_CMD_CHECK_RESPONSE_CRC(x)           (((uint32_t)(((uint32_t)(x)) << SDIF_CMD_CHECK_RESPONSE_CRC_SHIFT)) & SDIF_CMD_CHECK_RESPONSE_CRC_MASK)
+#define SDIF_CMD_DATA_EXPECTED_MASK              (0x200U)
+#define SDIF_CMD_DATA_EXPECTED_SHIFT             (9U)
+#define SDIF_CMD_DATA_EXPECTED(x)                (((uint32_t)(((uint32_t)(x)) << SDIF_CMD_DATA_EXPECTED_SHIFT)) & SDIF_CMD_DATA_EXPECTED_MASK)
+#define SDIF_CMD_READ_WRITE_MASK                 (0x400U)
+#define SDIF_CMD_READ_WRITE_SHIFT                (10U)
+#define SDIF_CMD_READ_WRITE(x)                   (((uint32_t)(((uint32_t)(x)) << SDIF_CMD_READ_WRITE_SHIFT)) & SDIF_CMD_READ_WRITE_MASK)
+#define SDIF_CMD_TRANSFER_MODE_MASK              (0x800U)
+#define SDIF_CMD_TRANSFER_MODE_SHIFT             (11U)
+#define SDIF_CMD_TRANSFER_MODE(x)                (((uint32_t)(((uint32_t)(x)) << SDIF_CMD_TRANSFER_MODE_SHIFT)) & SDIF_CMD_TRANSFER_MODE_MASK)
+#define SDIF_CMD_SEND_AUTO_STOP_MASK             (0x1000U)
+#define SDIF_CMD_SEND_AUTO_STOP_SHIFT            (12U)
+#define SDIF_CMD_SEND_AUTO_STOP(x)               (((uint32_t)(((uint32_t)(x)) << SDIF_CMD_SEND_AUTO_STOP_SHIFT)) & SDIF_CMD_SEND_AUTO_STOP_MASK)
+#define SDIF_CMD_WAIT_PRVDATA_COMPLETE_MASK      (0x2000U)
+#define SDIF_CMD_WAIT_PRVDATA_COMPLETE_SHIFT     (13U)
+#define SDIF_CMD_WAIT_PRVDATA_COMPLETE(x)        (((uint32_t)(((uint32_t)(x)) << SDIF_CMD_WAIT_PRVDATA_COMPLETE_SHIFT)) & SDIF_CMD_WAIT_PRVDATA_COMPLETE_MASK)
+#define SDIF_CMD_STOP_ABORT_CMD_MASK             (0x4000U)
+#define SDIF_CMD_STOP_ABORT_CMD_SHIFT            (14U)
+#define SDIF_CMD_STOP_ABORT_CMD(x)               (((uint32_t)(((uint32_t)(x)) << SDIF_CMD_STOP_ABORT_CMD_SHIFT)) & SDIF_CMD_STOP_ABORT_CMD_MASK)
+#define SDIF_CMD_SEND_INITIALIZATION_MASK        (0x8000U)
+#define SDIF_CMD_SEND_INITIALIZATION_SHIFT       (15U)
+#define SDIF_CMD_SEND_INITIALIZATION(x)          (((uint32_t)(((uint32_t)(x)) << SDIF_CMD_SEND_INITIALIZATION_SHIFT)) & SDIF_CMD_SEND_INITIALIZATION_MASK)
+#define SDIF_CMD_UPDATE_CLOCK_REGISTERS_ONLY_MASK (0x200000U)
+#define SDIF_CMD_UPDATE_CLOCK_REGISTERS_ONLY_SHIFT (21U)
+#define SDIF_CMD_UPDATE_CLOCK_REGISTERS_ONLY(x)  (((uint32_t)(((uint32_t)(x)) << SDIF_CMD_UPDATE_CLOCK_REGISTERS_ONLY_SHIFT)) & SDIF_CMD_UPDATE_CLOCK_REGISTERS_ONLY_MASK)
+#define SDIF_CMD_READ_CEATA_DEVICE_MASK          (0x400000U)
+#define SDIF_CMD_READ_CEATA_DEVICE_SHIFT         (22U)
+#define SDIF_CMD_READ_CEATA_DEVICE(x)            (((uint32_t)(((uint32_t)(x)) << SDIF_CMD_READ_CEATA_DEVICE_SHIFT)) & SDIF_CMD_READ_CEATA_DEVICE_MASK)
+#define SDIF_CMD_CCS_EXPECTED_MASK               (0x800000U)
+#define SDIF_CMD_CCS_EXPECTED_SHIFT              (23U)
+#define SDIF_CMD_CCS_EXPECTED(x)                 (((uint32_t)(((uint32_t)(x)) << SDIF_CMD_CCS_EXPECTED_SHIFT)) & SDIF_CMD_CCS_EXPECTED_MASK)
+#define SDIF_CMD_ENABLE_BOOT_MASK                (0x1000000U)
+#define SDIF_CMD_ENABLE_BOOT_SHIFT               (24U)
+#define SDIF_CMD_ENABLE_BOOT(x)                  (((uint32_t)(((uint32_t)(x)) << SDIF_CMD_ENABLE_BOOT_SHIFT)) & SDIF_CMD_ENABLE_BOOT_MASK)
+#define SDIF_CMD_EXPECT_BOOT_ACK_MASK            (0x2000000U)
+#define SDIF_CMD_EXPECT_BOOT_ACK_SHIFT           (25U)
+#define SDIF_CMD_EXPECT_BOOT_ACK(x)              (((uint32_t)(((uint32_t)(x)) << SDIF_CMD_EXPECT_BOOT_ACK_SHIFT)) & SDIF_CMD_EXPECT_BOOT_ACK_MASK)
+#define SDIF_CMD_DISABLE_BOOT_MASK               (0x4000000U)
+#define SDIF_CMD_DISABLE_BOOT_SHIFT              (26U)
+#define SDIF_CMD_DISABLE_BOOT(x)                 (((uint32_t)(((uint32_t)(x)) << SDIF_CMD_DISABLE_BOOT_SHIFT)) & SDIF_CMD_DISABLE_BOOT_MASK)
+#define SDIF_CMD_BOOT_MODE_MASK                  (0x8000000U)
+#define SDIF_CMD_BOOT_MODE_SHIFT                 (27U)
+#define SDIF_CMD_BOOT_MODE(x)                    (((uint32_t)(((uint32_t)(x)) << SDIF_CMD_BOOT_MODE_SHIFT)) & SDIF_CMD_BOOT_MODE_MASK)
+#define SDIF_CMD_VOLT_SWITCH_MASK                (0x10000000U)
+#define SDIF_CMD_VOLT_SWITCH_SHIFT               (28U)
+#define SDIF_CMD_VOLT_SWITCH(x)                  (((uint32_t)(((uint32_t)(x)) << SDIF_CMD_VOLT_SWITCH_SHIFT)) & SDIF_CMD_VOLT_SWITCH_MASK)
+#define SDIF_CMD_USE_HOLD_REG_MASK               (0x20000000U)
+#define SDIF_CMD_USE_HOLD_REG_SHIFT              (29U)
+#define SDIF_CMD_USE_HOLD_REG(x)                 (((uint32_t)(((uint32_t)(x)) << SDIF_CMD_USE_HOLD_REG_SHIFT)) & SDIF_CMD_USE_HOLD_REG_MASK)
+#define SDIF_CMD_START_CMD_MASK                  (0x80000000U)
+#define SDIF_CMD_START_CMD_SHIFT                 (31U)
+#define SDIF_CMD_START_CMD(x)                    (((uint32_t)(((uint32_t)(x)) << SDIF_CMD_START_CMD_SHIFT)) & SDIF_CMD_START_CMD_MASK)
+/*! @} */
+
+/*! @name RESP - Response register */
+/*! @{ */
+#define SDIF_RESP_RESPONSE_MASK                  (0xFFFFFFFFU)
+#define SDIF_RESP_RESPONSE_SHIFT                 (0U)
+#define SDIF_RESP_RESPONSE(x)                    (((uint32_t)(((uint32_t)(x)) << SDIF_RESP_RESPONSE_SHIFT)) & SDIF_RESP_RESPONSE_MASK)
+/*! @} */
+
+/* The count of SDIF_RESP */
+#define SDIF_RESP_COUNT                          (4U)
+
+/*! @name MINTSTS - Masked Interrupt Status register */
+/*! @{ */
+#define SDIF_MINTSTS_CDET_MASK                   (0x1U)
+#define SDIF_MINTSTS_CDET_SHIFT                  (0U)
+#define SDIF_MINTSTS_CDET(x)                     (((uint32_t)(((uint32_t)(x)) << SDIF_MINTSTS_CDET_SHIFT)) & SDIF_MINTSTS_CDET_MASK)
+#define SDIF_MINTSTS_RE_MASK                     (0x2U)
+#define SDIF_MINTSTS_RE_SHIFT                    (1U)
+#define SDIF_MINTSTS_RE(x)                       (((uint32_t)(((uint32_t)(x)) << SDIF_MINTSTS_RE_SHIFT)) & SDIF_MINTSTS_RE_MASK)
+#define SDIF_MINTSTS_CDONE_MASK                  (0x4U)
+#define SDIF_MINTSTS_CDONE_SHIFT                 (2U)
+#define SDIF_MINTSTS_CDONE(x)                    (((uint32_t)(((uint32_t)(x)) << SDIF_MINTSTS_CDONE_SHIFT)) & SDIF_MINTSTS_CDONE_MASK)
+#define SDIF_MINTSTS_DTO_MASK                    (0x8U)
+#define SDIF_MINTSTS_DTO_SHIFT                   (3U)
+#define SDIF_MINTSTS_DTO(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_MINTSTS_DTO_SHIFT)) & SDIF_MINTSTS_DTO_MASK)
+#define SDIF_MINTSTS_TXDR_MASK                   (0x10U)
+#define SDIF_MINTSTS_TXDR_SHIFT                  (4U)
+#define SDIF_MINTSTS_TXDR(x)                     (((uint32_t)(((uint32_t)(x)) << SDIF_MINTSTS_TXDR_SHIFT)) & SDIF_MINTSTS_TXDR_MASK)
+#define SDIF_MINTSTS_RXDR_MASK                   (0x20U)
+#define SDIF_MINTSTS_RXDR_SHIFT                  (5U)
+#define SDIF_MINTSTS_RXDR(x)                     (((uint32_t)(((uint32_t)(x)) << SDIF_MINTSTS_RXDR_SHIFT)) & SDIF_MINTSTS_RXDR_MASK)
+#define SDIF_MINTSTS_RCRC_MASK                   (0x40U)
+#define SDIF_MINTSTS_RCRC_SHIFT                  (6U)
+#define SDIF_MINTSTS_RCRC(x)                     (((uint32_t)(((uint32_t)(x)) << SDIF_MINTSTS_RCRC_SHIFT)) & SDIF_MINTSTS_RCRC_MASK)
+#define SDIF_MINTSTS_DCRC_MASK                   (0x80U)
+#define SDIF_MINTSTS_DCRC_SHIFT                  (7U)
+#define SDIF_MINTSTS_DCRC(x)                     (((uint32_t)(((uint32_t)(x)) << SDIF_MINTSTS_DCRC_SHIFT)) & SDIF_MINTSTS_DCRC_MASK)
+#define SDIF_MINTSTS_RTO_MASK                    (0x100U)
+#define SDIF_MINTSTS_RTO_SHIFT                   (8U)
+#define SDIF_MINTSTS_RTO(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_MINTSTS_RTO_SHIFT)) & SDIF_MINTSTS_RTO_MASK)
+#define SDIF_MINTSTS_DRTO_MASK                   (0x200U)
+#define SDIF_MINTSTS_DRTO_SHIFT                  (9U)
+#define SDIF_MINTSTS_DRTO(x)                     (((uint32_t)(((uint32_t)(x)) << SDIF_MINTSTS_DRTO_SHIFT)) & SDIF_MINTSTS_DRTO_MASK)
+#define SDIF_MINTSTS_HTO_MASK                    (0x400U)
+#define SDIF_MINTSTS_HTO_SHIFT                   (10U)
+#define SDIF_MINTSTS_HTO(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_MINTSTS_HTO_SHIFT)) & SDIF_MINTSTS_HTO_MASK)
+#define SDIF_MINTSTS_FRUN_MASK                   (0x800U)
+#define SDIF_MINTSTS_FRUN_SHIFT                  (11U)
+#define SDIF_MINTSTS_FRUN(x)                     (((uint32_t)(((uint32_t)(x)) << SDIF_MINTSTS_FRUN_SHIFT)) & SDIF_MINTSTS_FRUN_MASK)
+#define SDIF_MINTSTS_HLE_MASK                    (0x1000U)
+#define SDIF_MINTSTS_HLE_SHIFT                   (12U)
+#define SDIF_MINTSTS_HLE(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_MINTSTS_HLE_SHIFT)) & SDIF_MINTSTS_HLE_MASK)
+#define SDIF_MINTSTS_SBE_MASK                    (0x2000U)
+#define SDIF_MINTSTS_SBE_SHIFT                   (13U)
+#define SDIF_MINTSTS_SBE(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_MINTSTS_SBE_SHIFT)) & SDIF_MINTSTS_SBE_MASK)
+#define SDIF_MINTSTS_ACD_MASK                    (0x4000U)
+#define SDIF_MINTSTS_ACD_SHIFT                   (14U)
+#define SDIF_MINTSTS_ACD(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_MINTSTS_ACD_SHIFT)) & SDIF_MINTSTS_ACD_MASK)
+#define SDIF_MINTSTS_EBE_MASK                    (0x8000U)
+#define SDIF_MINTSTS_EBE_SHIFT                   (15U)
+#define SDIF_MINTSTS_EBE(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_MINTSTS_EBE_SHIFT)) & SDIF_MINTSTS_EBE_MASK)
+#define SDIF_MINTSTS_SDIO_INTERRUPT_MASK         (0x10000U)
+#define SDIF_MINTSTS_SDIO_INTERRUPT_SHIFT        (16U)
+#define SDIF_MINTSTS_SDIO_INTERRUPT(x)           (((uint32_t)(((uint32_t)(x)) << SDIF_MINTSTS_SDIO_INTERRUPT_SHIFT)) & SDIF_MINTSTS_SDIO_INTERRUPT_MASK)
+/*! @} */
+
+/*! @name RINTSTS - Raw Interrupt Status register */
+/*! @{ */
+#define SDIF_RINTSTS_CDET_MASK                   (0x1U)
+#define SDIF_RINTSTS_CDET_SHIFT                  (0U)
+#define SDIF_RINTSTS_CDET(x)                     (((uint32_t)(((uint32_t)(x)) << SDIF_RINTSTS_CDET_SHIFT)) & SDIF_RINTSTS_CDET_MASK)
+#define SDIF_RINTSTS_RE_MASK                     (0x2U)
+#define SDIF_RINTSTS_RE_SHIFT                    (1U)
+#define SDIF_RINTSTS_RE(x)                       (((uint32_t)(((uint32_t)(x)) << SDIF_RINTSTS_RE_SHIFT)) & SDIF_RINTSTS_RE_MASK)
+#define SDIF_RINTSTS_CDONE_MASK                  (0x4U)
+#define SDIF_RINTSTS_CDONE_SHIFT                 (2U)
+#define SDIF_RINTSTS_CDONE(x)                    (((uint32_t)(((uint32_t)(x)) << SDIF_RINTSTS_CDONE_SHIFT)) & SDIF_RINTSTS_CDONE_MASK)
+#define SDIF_RINTSTS_DTO_MASK                    (0x8U)
+#define SDIF_RINTSTS_DTO_SHIFT                   (3U)
+#define SDIF_RINTSTS_DTO(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_RINTSTS_DTO_SHIFT)) & SDIF_RINTSTS_DTO_MASK)
+#define SDIF_RINTSTS_TXDR_MASK                   (0x10U)
+#define SDIF_RINTSTS_TXDR_SHIFT                  (4U)
+#define SDIF_RINTSTS_TXDR(x)                     (((uint32_t)(((uint32_t)(x)) << SDIF_RINTSTS_TXDR_SHIFT)) & SDIF_RINTSTS_TXDR_MASK)
+#define SDIF_RINTSTS_RXDR_MASK                   (0x20U)
+#define SDIF_RINTSTS_RXDR_SHIFT                  (5U)
+#define SDIF_RINTSTS_RXDR(x)                     (((uint32_t)(((uint32_t)(x)) << SDIF_RINTSTS_RXDR_SHIFT)) & SDIF_RINTSTS_RXDR_MASK)
+#define SDIF_RINTSTS_RCRC_MASK                   (0x40U)
+#define SDIF_RINTSTS_RCRC_SHIFT                  (6U)
+#define SDIF_RINTSTS_RCRC(x)                     (((uint32_t)(((uint32_t)(x)) << SDIF_RINTSTS_RCRC_SHIFT)) & SDIF_RINTSTS_RCRC_MASK)
+#define SDIF_RINTSTS_DCRC_MASK                   (0x80U)
+#define SDIF_RINTSTS_DCRC_SHIFT                  (7U)
+#define SDIF_RINTSTS_DCRC(x)                     (((uint32_t)(((uint32_t)(x)) << SDIF_RINTSTS_DCRC_SHIFT)) & SDIF_RINTSTS_DCRC_MASK)
+#define SDIF_RINTSTS_RTO_BAR_MASK                (0x100U)
+#define SDIF_RINTSTS_RTO_BAR_SHIFT               (8U)
+#define SDIF_RINTSTS_RTO_BAR(x)                  (((uint32_t)(((uint32_t)(x)) << SDIF_RINTSTS_RTO_BAR_SHIFT)) & SDIF_RINTSTS_RTO_BAR_MASK)
+#define SDIF_RINTSTS_DRTO_BDS_MASK               (0x200U)
+#define SDIF_RINTSTS_DRTO_BDS_SHIFT              (9U)
+#define SDIF_RINTSTS_DRTO_BDS(x)                 (((uint32_t)(((uint32_t)(x)) << SDIF_RINTSTS_DRTO_BDS_SHIFT)) & SDIF_RINTSTS_DRTO_BDS_MASK)
+#define SDIF_RINTSTS_HTO_MASK                    (0x400U)
+#define SDIF_RINTSTS_HTO_SHIFT                   (10U)
+#define SDIF_RINTSTS_HTO(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_RINTSTS_HTO_SHIFT)) & SDIF_RINTSTS_HTO_MASK)
+#define SDIF_RINTSTS_FRUN_MASK                   (0x800U)
+#define SDIF_RINTSTS_FRUN_SHIFT                  (11U)
+#define SDIF_RINTSTS_FRUN(x)                     (((uint32_t)(((uint32_t)(x)) << SDIF_RINTSTS_FRUN_SHIFT)) & SDIF_RINTSTS_FRUN_MASK)
+#define SDIF_RINTSTS_HLE_MASK                    (0x1000U)
+#define SDIF_RINTSTS_HLE_SHIFT                   (12U)
+#define SDIF_RINTSTS_HLE(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_RINTSTS_HLE_SHIFT)) & SDIF_RINTSTS_HLE_MASK)
+#define SDIF_RINTSTS_SBE_MASK                    (0x2000U)
+#define SDIF_RINTSTS_SBE_SHIFT                   (13U)
+#define SDIF_RINTSTS_SBE(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_RINTSTS_SBE_SHIFT)) & SDIF_RINTSTS_SBE_MASK)
+#define SDIF_RINTSTS_ACD_MASK                    (0x4000U)
+#define SDIF_RINTSTS_ACD_SHIFT                   (14U)
+#define SDIF_RINTSTS_ACD(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_RINTSTS_ACD_SHIFT)) & SDIF_RINTSTS_ACD_MASK)
+#define SDIF_RINTSTS_EBE_MASK                    (0x8000U)
+#define SDIF_RINTSTS_EBE_SHIFT                   (15U)
+#define SDIF_RINTSTS_EBE(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_RINTSTS_EBE_SHIFT)) & SDIF_RINTSTS_EBE_MASK)
+#define SDIF_RINTSTS_SDIO_INTERRUPT_MASK         (0x10000U)
+#define SDIF_RINTSTS_SDIO_INTERRUPT_SHIFT        (16U)
+#define SDIF_RINTSTS_SDIO_INTERRUPT(x)           (((uint32_t)(((uint32_t)(x)) << SDIF_RINTSTS_SDIO_INTERRUPT_SHIFT)) & SDIF_RINTSTS_SDIO_INTERRUPT_MASK)
+/*! @} */
+
+/*! @name STATUS - Status register */
+/*! @{ */
+#define SDIF_STATUS_FIFO_RX_WATERMARK_MASK       (0x1U)
+#define SDIF_STATUS_FIFO_RX_WATERMARK_SHIFT      (0U)
+#define SDIF_STATUS_FIFO_RX_WATERMARK(x)         (((uint32_t)(((uint32_t)(x)) << SDIF_STATUS_FIFO_RX_WATERMARK_SHIFT)) & SDIF_STATUS_FIFO_RX_WATERMARK_MASK)
+#define SDIF_STATUS_FIFO_TX_WATERMARK_MASK       (0x2U)
+#define SDIF_STATUS_FIFO_TX_WATERMARK_SHIFT      (1U)
+#define SDIF_STATUS_FIFO_TX_WATERMARK(x)         (((uint32_t)(((uint32_t)(x)) << SDIF_STATUS_FIFO_TX_WATERMARK_SHIFT)) & SDIF_STATUS_FIFO_TX_WATERMARK_MASK)
+#define SDIF_STATUS_FIFO_EMPTY_MASK              (0x4U)
+#define SDIF_STATUS_FIFO_EMPTY_SHIFT             (2U)
+#define SDIF_STATUS_FIFO_EMPTY(x)                (((uint32_t)(((uint32_t)(x)) << SDIF_STATUS_FIFO_EMPTY_SHIFT)) & SDIF_STATUS_FIFO_EMPTY_MASK)
+#define SDIF_STATUS_FIFO_FULL_MASK               (0x8U)
+#define SDIF_STATUS_FIFO_FULL_SHIFT              (3U)
+#define SDIF_STATUS_FIFO_FULL(x)                 (((uint32_t)(((uint32_t)(x)) << SDIF_STATUS_FIFO_FULL_SHIFT)) & SDIF_STATUS_FIFO_FULL_MASK)
+#define SDIF_STATUS_CMDFSMSTATES_MASK            (0xF0U)
+#define SDIF_STATUS_CMDFSMSTATES_SHIFT           (4U)
+#define SDIF_STATUS_CMDFSMSTATES(x)              (((uint32_t)(((uint32_t)(x)) << SDIF_STATUS_CMDFSMSTATES_SHIFT)) & SDIF_STATUS_CMDFSMSTATES_MASK)
+#define SDIF_STATUS_DATA_3_STATUS_MASK           (0x100U)
+#define SDIF_STATUS_DATA_3_STATUS_SHIFT          (8U)
+#define SDIF_STATUS_DATA_3_STATUS(x)             (((uint32_t)(((uint32_t)(x)) << SDIF_STATUS_DATA_3_STATUS_SHIFT)) & SDIF_STATUS_DATA_3_STATUS_MASK)
+#define SDIF_STATUS_DATA_BUSY_MASK               (0x200U)
+#define SDIF_STATUS_DATA_BUSY_SHIFT              (9U)
+#define SDIF_STATUS_DATA_BUSY(x)                 (((uint32_t)(((uint32_t)(x)) << SDIF_STATUS_DATA_BUSY_SHIFT)) & SDIF_STATUS_DATA_BUSY_MASK)
+#define SDIF_STATUS_DATA_STATE_MC_BUSY_MASK      (0x400U)
+#define SDIF_STATUS_DATA_STATE_MC_BUSY_SHIFT     (10U)
+#define SDIF_STATUS_DATA_STATE_MC_BUSY(x)        (((uint32_t)(((uint32_t)(x)) << SDIF_STATUS_DATA_STATE_MC_BUSY_SHIFT)) & SDIF_STATUS_DATA_STATE_MC_BUSY_MASK)
+#define SDIF_STATUS_RESPONSE_INDEX_MASK          (0x1F800U)
+#define SDIF_STATUS_RESPONSE_INDEX_SHIFT         (11U)
+#define SDIF_STATUS_RESPONSE_INDEX(x)            (((uint32_t)(((uint32_t)(x)) << SDIF_STATUS_RESPONSE_INDEX_SHIFT)) & SDIF_STATUS_RESPONSE_INDEX_MASK)
+#define SDIF_STATUS_FIFO_COUNT_MASK              (0x3FFE0000U)
+#define SDIF_STATUS_FIFO_COUNT_SHIFT             (17U)
+#define SDIF_STATUS_FIFO_COUNT(x)                (((uint32_t)(((uint32_t)(x)) << SDIF_STATUS_FIFO_COUNT_SHIFT)) & SDIF_STATUS_FIFO_COUNT_MASK)
+#define SDIF_STATUS_DMA_ACK_MASK                 (0x40000000U)
+#define SDIF_STATUS_DMA_ACK_SHIFT                (30U)
+#define SDIF_STATUS_DMA_ACK(x)                   (((uint32_t)(((uint32_t)(x)) << SDIF_STATUS_DMA_ACK_SHIFT)) & SDIF_STATUS_DMA_ACK_MASK)
+#define SDIF_STATUS_DMA_REQ_MASK                 (0x80000000U)
+#define SDIF_STATUS_DMA_REQ_SHIFT                (31U)
+#define SDIF_STATUS_DMA_REQ(x)                   (((uint32_t)(((uint32_t)(x)) << SDIF_STATUS_DMA_REQ_SHIFT)) & SDIF_STATUS_DMA_REQ_MASK)
+/*! @} */
+
+/*! @name FIFOTH - FIFO Threshold Watermark register */
+/*! @{ */
+#define SDIF_FIFOTH_TX_WMARK_MASK                (0xFFFU)
+#define SDIF_FIFOTH_TX_WMARK_SHIFT               (0U)
+#define SDIF_FIFOTH_TX_WMARK(x)                  (((uint32_t)(((uint32_t)(x)) << SDIF_FIFOTH_TX_WMARK_SHIFT)) & SDIF_FIFOTH_TX_WMARK_MASK)
+#define SDIF_FIFOTH_RX_WMARK_MASK                (0xFFF0000U)
+#define SDIF_FIFOTH_RX_WMARK_SHIFT               (16U)
+#define SDIF_FIFOTH_RX_WMARK(x)                  (((uint32_t)(((uint32_t)(x)) << SDIF_FIFOTH_RX_WMARK_SHIFT)) & SDIF_FIFOTH_RX_WMARK_MASK)
+#define SDIF_FIFOTH_DMA_MTS_MASK                 (0x70000000U)
+#define SDIF_FIFOTH_DMA_MTS_SHIFT                (28U)
+#define SDIF_FIFOTH_DMA_MTS(x)                   (((uint32_t)(((uint32_t)(x)) << SDIF_FIFOTH_DMA_MTS_SHIFT)) & SDIF_FIFOTH_DMA_MTS_MASK)
+/*! @} */
+
+/*! @name CDETECT - Card Detect register */
+/*! @{ */
+#define SDIF_CDETECT_CARD_DETECT_MASK            (0x200U)
+#define SDIF_CDETECT_CARD_DETECT_SHIFT           (0U)
+#define SDIF_CDETECT_CARD_DETECT(x)              (((uint32_t)(((uint32_t)(x)) << SDIF_CDETECT_CARD_DETECT_SHIFT)) & SDIF_CDETECT_CARD_DETECT_MASK)
+/*! @} */
+
+/*! @name WRTPRT - Write Protect register */
+/*! @{ */
+#define SDIF_WRTPRT_WRITE_PROTECT_MASK           (0x1U)
+#define SDIF_WRTPRT_WRITE_PROTECT_SHIFT          (0U)
+#define SDIF_WRTPRT_WRITE_PROTECT(x)             (((uint32_t)(((uint32_t)(x)) << SDIF_WRTPRT_WRITE_PROTECT_SHIFT)) & SDIF_WRTPRT_WRITE_PROTECT_MASK)
+/*! @} */
+
+/*! @name TCBCNT - Transferred CIU Card Byte Count register */
+/*! @{ */
+#define SDIF_TCBCNT_TRANS_CARD_BYTE_COUNT_MASK   (0xFFFFFFFFU)
+#define SDIF_TCBCNT_TRANS_CARD_BYTE_COUNT_SHIFT  (0U)
+#define SDIF_TCBCNT_TRANS_CARD_BYTE_COUNT(x)     (((uint32_t)(((uint32_t)(x)) << SDIF_TCBCNT_TRANS_CARD_BYTE_COUNT_SHIFT)) & SDIF_TCBCNT_TRANS_CARD_BYTE_COUNT_MASK)
+/*! @} */
+
+/*! @name TBBCNT - Transferred Host to BIU-FIFO Byte Count register */
+/*! @{ */
+#define SDIF_TBBCNT_TRANS_FIFO_BYTE_COUNT_MASK   (0xFFFFFFFFU)
+#define SDIF_TBBCNT_TRANS_FIFO_BYTE_COUNT_SHIFT  (0U)
+#define SDIF_TBBCNT_TRANS_FIFO_BYTE_COUNT(x)     (((uint32_t)(((uint32_t)(x)) << SDIF_TBBCNT_TRANS_FIFO_BYTE_COUNT_SHIFT)) & SDIF_TBBCNT_TRANS_FIFO_BYTE_COUNT_MASK)
+/*! @} */
+
+/*! @name DEBNCE - Debounce Count register */
+/*! @{ */
+#define SDIF_DEBNCE_DEBOUNCE_COUNT_MASK          (0xFFFFFFU)
+#define SDIF_DEBNCE_DEBOUNCE_COUNT_SHIFT         (0U)
+#define SDIF_DEBNCE_DEBOUNCE_COUNT(x)            (((uint32_t)(((uint32_t)(x)) << SDIF_DEBNCE_DEBOUNCE_COUNT_SHIFT)) & SDIF_DEBNCE_DEBOUNCE_COUNT_MASK)
+/*! @} */
+
+/*! @name RST_N - Hardware Reset */
+/*! @{ */
+#define SDIF_RST_N_CARD_RESET_MASK               (0x1U)
+#define SDIF_RST_N_CARD_RESET_SHIFT              (0U)
+#define SDIF_RST_N_CARD_RESET(x)                 (((uint32_t)(((uint32_t)(x)) << SDIF_RST_N_CARD_RESET_SHIFT)) & SDIF_RST_N_CARD_RESET_MASK)
+/*! @} */
+
+/*! @name BMOD - Bus Mode register */
+/*! @{ */
+#define SDIF_BMOD_SWR_MASK                       (0x1U)
+#define SDIF_BMOD_SWR_SHIFT                      (0U)
+#define SDIF_BMOD_SWR(x)                         (((uint32_t)(((uint32_t)(x)) << SDIF_BMOD_SWR_SHIFT)) & SDIF_BMOD_SWR_MASK)
+#define SDIF_BMOD_FB_MASK                        (0x2U)
+#define SDIF_BMOD_FB_SHIFT                       (1U)
+#define SDIF_BMOD_FB(x)                          (((uint32_t)(((uint32_t)(x)) << SDIF_BMOD_FB_SHIFT)) & SDIF_BMOD_FB_MASK)
+#define SDIF_BMOD_DSL_MASK                       (0x7CU)
+#define SDIF_BMOD_DSL_SHIFT                      (2U)
+#define SDIF_BMOD_DSL(x)                         (((uint32_t)(((uint32_t)(x)) << SDIF_BMOD_DSL_SHIFT)) & SDIF_BMOD_DSL_MASK)
+#define SDIF_BMOD_DE_MASK                        (0x80U)
+#define SDIF_BMOD_DE_SHIFT                       (7U)
+#define SDIF_BMOD_DE(x)                          (((uint32_t)(((uint32_t)(x)) << SDIF_BMOD_DE_SHIFT)) & SDIF_BMOD_DE_MASK)
+#define SDIF_BMOD_PBL_MASK                       (0x700U)
+#define SDIF_BMOD_PBL_SHIFT                      (8U)
+#define SDIF_BMOD_PBL(x)                         (((uint32_t)(((uint32_t)(x)) << SDIF_BMOD_PBL_SHIFT)) & SDIF_BMOD_PBL_MASK)
+/*! @} */
+
+/*! @name PLDMND - Poll Demand register */
+/*! @{ */
+#define SDIF_PLDMND_PD_MASK                      (0xFFFFFFFFU)
+#define SDIF_PLDMND_PD_SHIFT                     (0U)
+#define SDIF_PLDMND_PD(x)                        (((uint32_t)(((uint32_t)(x)) << SDIF_PLDMND_PD_SHIFT)) & SDIF_PLDMND_PD_MASK)
+/*! @} */
+
+/*! @name DBADDR - Descriptor List Base Address register */
+/*! @{ */
+#define SDIF_DBADDR_SDL_MASK                     (0xFFFFFFFFU)
+#define SDIF_DBADDR_SDL_SHIFT                    (0U)
+#define SDIF_DBADDR_SDL(x)                       (((uint32_t)(((uint32_t)(x)) << SDIF_DBADDR_SDL_SHIFT)) & SDIF_DBADDR_SDL_MASK)
+/*! @} */
+
+/*! @name IDSTS - Internal DMAC Status register */
+/*! @{ */
+#define SDIF_IDSTS_TI_MASK                       (0x1U)
+#define SDIF_IDSTS_TI_SHIFT                      (0U)
+#define SDIF_IDSTS_TI(x)                         (((uint32_t)(((uint32_t)(x)) << SDIF_IDSTS_TI_SHIFT)) & SDIF_IDSTS_TI_MASK)
+#define SDIF_IDSTS_RI_MASK                       (0x2U)
+#define SDIF_IDSTS_RI_SHIFT                      (1U)
+#define SDIF_IDSTS_RI(x)                         (((uint32_t)(((uint32_t)(x)) << SDIF_IDSTS_RI_SHIFT)) & SDIF_IDSTS_RI_MASK)
+#define SDIF_IDSTS_FBE_MASK                      (0x4U)
+#define SDIF_IDSTS_FBE_SHIFT                     (2U)
+#define SDIF_IDSTS_FBE(x)                        (((uint32_t)(((uint32_t)(x)) << SDIF_IDSTS_FBE_SHIFT)) & SDIF_IDSTS_FBE_MASK)
+#define SDIF_IDSTS_DU_MASK                       (0x10U)
+#define SDIF_IDSTS_DU_SHIFT                      (4U)
+#define SDIF_IDSTS_DU(x)                         (((uint32_t)(((uint32_t)(x)) << SDIF_IDSTS_DU_SHIFT)) & SDIF_IDSTS_DU_MASK)
+#define SDIF_IDSTS_CES_MASK                      (0x20U)
+#define SDIF_IDSTS_CES_SHIFT                     (5U)
+#define SDIF_IDSTS_CES(x)                        (((uint32_t)(((uint32_t)(x)) << SDIF_IDSTS_CES_SHIFT)) & SDIF_IDSTS_CES_MASK)
+#define SDIF_IDSTS_NIS_MASK                      (0x100U)
+#define SDIF_IDSTS_NIS_SHIFT                     (8U)
+#define SDIF_IDSTS_NIS(x)                        (((uint32_t)(((uint32_t)(x)) << SDIF_IDSTS_NIS_SHIFT)) & SDIF_IDSTS_NIS_MASK)
+#define SDIF_IDSTS_AIS_MASK                      (0x200U)
+#define SDIF_IDSTS_AIS_SHIFT                     (9U)
+#define SDIF_IDSTS_AIS(x)                        (((uint32_t)(((uint32_t)(x)) << SDIF_IDSTS_AIS_SHIFT)) & SDIF_IDSTS_AIS_MASK)
+#define SDIF_IDSTS_EB_MASK                       (0x1C00U)
+#define SDIF_IDSTS_EB_SHIFT                      (10U)
+#define SDIF_IDSTS_EB(x)                         (((uint32_t)(((uint32_t)(x)) << SDIF_IDSTS_EB_SHIFT)) & SDIF_IDSTS_EB_MASK)
+#define SDIF_IDSTS_FSM_MASK                      (0x1E000U)
+#define SDIF_IDSTS_FSM_SHIFT                     (13U)
+#define SDIF_IDSTS_FSM(x)                        (((uint32_t)(((uint32_t)(x)) << SDIF_IDSTS_FSM_SHIFT)) & SDIF_IDSTS_FSM_MASK)
+/*! @} */
+
+/*! @name IDINTEN - Internal DMAC Interrupt Enable register */
+/*! @{ */
+#define SDIF_IDINTEN_TI_MASK                     (0x1U)
+#define SDIF_IDINTEN_TI_SHIFT                    (0U)
+#define SDIF_IDINTEN_TI(x)                       (((uint32_t)(((uint32_t)(x)) << SDIF_IDINTEN_TI_SHIFT)) & SDIF_IDINTEN_TI_MASK)
+#define SDIF_IDINTEN_RI_MASK                     (0x2U)
+#define SDIF_IDINTEN_RI_SHIFT                    (1U)
+#define SDIF_IDINTEN_RI(x)                       (((uint32_t)(((uint32_t)(x)) << SDIF_IDINTEN_RI_SHIFT)) & SDIF_IDINTEN_RI_MASK)
+#define SDIF_IDINTEN_FBE_MASK                    (0x4U)
+#define SDIF_IDINTEN_FBE_SHIFT                   (2U)
+#define SDIF_IDINTEN_FBE(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_IDINTEN_FBE_SHIFT)) & SDIF_IDINTEN_FBE_MASK)
+#define SDIF_IDINTEN_DU_MASK                     (0x10U)
+#define SDIF_IDINTEN_DU_SHIFT                    (4U)
+#define SDIF_IDINTEN_DU(x)                       (((uint32_t)(((uint32_t)(x)) << SDIF_IDINTEN_DU_SHIFT)) & SDIF_IDINTEN_DU_MASK)
+#define SDIF_IDINTEN_CES_MASK                    (0x20U)
+#define SDIF_IDINTEN_CES_SHIFT                   (5U)
+#define SDIF_IDINTEN_CES(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_IDINTEN_CES_SHIFT)) & SDIF_IDINTEN_CES_MASK)
+#define SDIF_IDINTEN_NIS_MASK                    (0x100U)
+#define SDIF_IDINTEN_NIS_SHIFT                   (8U)
+#define SDIF_IDINTEN_NIS(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_IDINTEN_NIS_SHIFT)) & SDIF_IDINTEN_NIS_MASK)
+#define SDIF_IDINTEN_AIS_MASK                    (0x200U)
+#define SDIF_IDINTEN_AIS_SHIFT                   (9U)
+#define SDIF_IDINTEN_AIS(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_IDINTEN_AIS_SHIFT)) & SDIF_IDINTEN_AIS_MASK)
+/*! @} */
+
+/*! @name DSCADDR - Current Host Descriptor Address register */
+/*! @{ */
+#define SDIF_DSCADDR_HDA_MASK                    (0xFFFFFFFFU)
+#define SDIF_DSCADDR_HDA_SHIFT                   (0U)
+#define SDIF_DSCADDR_HDA(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_DSCADDR_HDA_SHIFT)) & SDIF_DSCADDR_HDA_MASK)
+/*! @} */
+
+/*! @name BUFADDR - Current Buffer Descriptor Address register */
+/*! @{ */
+#define SDIF_BUFADDR_HBA_MASK                    (0xFFFFFFFFU)
+#define SDIF_BUFADDR_HBA_SHIFT                   (0U)
+#define SDIF_BUFADDR_HBA(x)                      (((uint32_t)(((uint32_t)(x)) << SDIF_BUFADDR_HBA_SHIFT)) & SDIF_BUFADDR_HBA_MASK)
+/*! @} */
+
+/*! @name UHS_REG_EXT - UHS register */
+/*! @{ */
+#define SDIF_UHS_REG_EXT_MMC_VOLT_MASK           (0xFFFFU)
+#define SDIF_UHS_REG_EXT_MMC_VOLT_SHIFT          (0U)
+#define SDIF_UHS_REG_EXT_MMC_VOLT(x)             (((uint32_t)(((uint32_t)(x)) << SDIF_UHS_REG_EXT_MMC_VOLT_SHIFT)) & SDIF_UHS_REG_EXT_MMC_VOLT_MASK)
+#define SDIF_UHS_REG_EXT_CLK_SMPL_PHASE_MASK     (0x30000U)
+#define SDIF_UHS_REG_EXT_CLK_SMPL_PHASE_SHIFT    (16U)
+#define SDIF_UHS_REG_EXT_CLK_SMPL_PHASE(x)       (((uint32_t)(((uint32_t)(x)) << SDIF_UHS_REG_EXT_CLK_SMPL_PHASE_SHIFT)) & SDIF_UHS_REG_EXT_CLK_SMPL_PHASE_MASK)
+#define SDIF_UHS_REG_EXT_CLK_SMPL_DLY_MASK       (0x700000U)
+#define SDIF_UHS_REG_EXT_CLK_SMPL_DLY_SHIFT      (20U)
+#define SDIF_UHS_REG_EXT_CLK_SMPL_DLY(x)         (((uint32_t)(((uint32_t)(x)) << SDIF_UHS_REG_EXT_CLK_SMPL_DLY_SHIFT)) & SDIF_UHS_REG_EXT_CLK_SMPL_DLY_MASK)
+#define SDIF_UHS_REG_EXT_CLK_DRV_PHASE_MASK      (0x1800000U)
+#define SDIF_UHS_REG_EXT_CLK_DRV_PHASE_SHIFT     (23U)
+#define SDIF_UHS_REG_EXT_CLK_DRV_PHASE(x)        (((uint32_t)(((uint32_t)(x)) << SDIF_UHS_REG_EXT_CLK_DRV_PHASE_SHIFT)) & SDIF_UHS_REG_EXT_CLK_DRV_PHASE_MASK)
+#define SDIF_UHS_REG_EXT_CLK_DRV_DLY_MASK        (0x38000000U)
+#define SDIF_UHS_REG_EXT_CLK_DRV_DLY_SHIFT       (27U)
+#define SDIF_UHS_REG_EXT_CLK_DRV_DLY(x)          (((uint32_t)(((uint32_t)(x)) << SDIF_UHS_REG_EXT_CLK_DRV_DLY_SHIFT)) & SDIF_UHS_REG_EXT_CLK_DRV_DLY_MASK)
+#define SDIF_UHS_REG_EXT_EXT_CLK_MUX_MASK        (0xC0000000U)
+#define SDIF_UHS_REG_EXT_EXT_CLK_MUX_SHIFT       (30U)
+#define SDIF_UHS_REG_EXT_EXT_CLK_MUX(x)          (((uint32_t)(((uint32_t)(x)) << SDIF_UHS_REG_EXT_EXT_CLK_MUX_SHIFT)) & SDIF_UHS_REG_EXT_EXT_CLK_MUX_MASK)
+/*! @} */
+
+/*! @name CARDTHRCTL - Card Threshold Control */
+/*! @{ */
+#define SDIF_CARDTHRCTL_CARDRDTHREN_MASK         (0x1U)
+#define SDIF_CARDTHRCTL_CARDRDTHREN_SHIFT        (0U)
+#define SDIF_CARDTHRCTL_CARDRDTHREN(x)           (((uint32_t)(((uint32_t)(x)) << SDIF_CARDTHRCTL_CARDRDTHREN_SHIFT)) & SDIF_CARDTHRCTL_CARDRDTHREN_MASK)
+#define SDIF_CARDTHRCTL_BSYCLRINTEN_MASK         (0x2U)
+#define SDIF_CARDTHRCTL_BSYCLRINTEN_SHIFT        (1U)
+#define SDIF_CARDTHRCTL_BSYCLRINTEN(x)           (((uint32_t)(((uint32_t)(x)) << SDIF_CARDTHRCTL_BSYCLRINTEN_SHIFT)) & SDIF_CARDTHRCTL_BSYCLRINTEN_MASK)
+#define SDIF_CARDTHRCTL_CARDTHRESHOLD_MASK       (0xFF0000U)
+#define SDIF_CARDTHRCTL_CARDTHRESHOLD_SHIFT      (16U)
+#define SDIF_CARDTHRCTL_CARDTHRESHOLD(x)         (((uint32_t)(((uint32_t)(x)) << SDIF_CARDTHRCTL_CARDTHRESHOLD_SHIFT)) & SDIF_CARDTHRCTL_CARDTHRESHOLD_MASK)
+/*! @} */
+
+/*! @name BACKENDPWR - Power control */
+/*! @{ */
+#define SDIF_BACKENDPWR_BACKENDPWR_MASK          (0x1U)
+#define SDIF_BACKENDPWR_BACKENDPWR_SHIFT         (0U)
+#define SDIF_BACKENDPWR_BACKENDPWR(x)            (((uint32_t)(((uint32_t)(x)) << SDIF_BACKENDPWR_BACKENDPWR_SHIFT)) & SDIF_BACKENDPWR_BACKENDPWR_MASK)
+/*! @} */
+
+/*! @name FIFO - SDIF FIFO */
+/*! @{ */
+#define SDIF_FIFO_DATA_MASK                      (0xFFFFFFFFU)
+#define SDIF_FIFO_DATA_SHIFT                     (0U)
+#define SDIF_FIFO_DATA(x)                        (((uint32_t)(((uint32_t)(x)) << SDIF_FIFO_DATA_SHIFT)) & SDIF_FIFO_DATA_MASK)
+/*! @} */
+
+/* The count of SDIF_FIFO */
+#define SDIF_FIFO_COUNT                          (32U)
+
+
+/*!
+ * @}
+ */ /* end of group SDIF_Register_Masks */
+
+
+/*!
+ * @}
+ */ /* end of group SDIF_Peripheral_Access_Layer */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

+ 375 - 0
bsp/cvitek/drivers/libraries/sdif/dw_sdmmc.h

@@ -0,0 +1,375 @@
+/*
+* Copyright (C) Cvitek Co., Ltd. 2019-2029. All rights reserved.
+*/
+#ifndef __MMC_H__
+#define __MMC_H__
+
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+
+#define TOP_BASE        0x03000000
+#define DW_SDIO0_BASE               0x04320000
+#define DW_SDIO1_BASE               0x04310000
+#define DW_SDIO2_BASE               0x04300000
+
+#define CONFIG_SDIO_NUM   3
+
+#define MMC_CMD0            0
+#define MMC_CMD1            1
+#define MMC_CMD2            2
+#define MMC_CMD3            3
+#define MMC_CMD5            5
+#define MMC_CMD6            6
+#define MMC_CMD7            7
+#define MMC_CMD8            8
+#define MMC_CMD9            9
+#define MMC_CMD11           11
+#define MMC_CMD12           12
+#define MMC_CMD13           13
+#define MMC_CMD16           16
+#define MMC_CMD17           17
+#define MMC_CMD18           18
+#define MMC_CMD19           19
+#define MMC_CMD21           21
+#define MMC_CMD23           23
+#define MMC_CMD24           24
+#define MMC_CMD25           25
+#define MMC_CMD32           32
+#define MMC_CMD33           33
+#define MMC_CMD35           35
+#define MMC_CMD36           36
+#define MMC_CMD38           38
+#define MMC_CMD52           52
+#define MMC_CMD53           53
+#define MMC_CMD55           55
+#define SD_ACMD6            6
+#define SD_ACMD13           13
+#define SD_ACMD41           41
+#define SD_ACMD42           42
+#define SD_ACMD51           51
+
+static inline int mmc_op_multi(uint32_t opcode)
+{
+    return opcode == MMC_CMD25 || opcode == MMC_CMD18;
+}
+
+#define SDIO0_IRQ           36
+#define SDIO1_IRQ           38
+#define SDIO2_IRQ           34
+#define SDIO0_BASE          DW_SDIO1_BASE
+#define SDIO1_BASE          DW_SDIO0_BASE
+#define SDIO2_BASE          DW_SDIO2_BASE
+
+#define SDIF_DMA_ADDRESS               0x00
+#define SDIF_BLOCK_SIZE                0x04
+#define SDIF_MAKE_BLKSZ(dma, blksz)    ((((dma) & 0x7) << 12) | ((blksz) & 0xFFF))
+#define SDIF_BLOCK_COUNT               0x06
+#define SDIF_ARGUMENT                  0x08
+#define SDIF_TRANSFER_MODE             0x0C
+#define SDIF_TRNS_DMA                  BIT(0)
+#define SDIF_TRNS_BLK_CNT_EN           BIT(1)
+#define SDIF_TRNS_ACMD12               BIT(2)
+#define SDIF_TRNS_READ                 BIT(4)
+#define SDIF_TRNS_MULTI                BIT(5)
+#define SDIF_TRNS_RESP_INT             BIT(8)
+#define SDIF_COMMAND                   0x0E
+#define SDIF_CMD_RESP_MASK             0x03
+#define SDIF_CMD_CRC                   0x08
+#define SDIF_CMD_INDEX                 0x10
+#define SDIF_CMD_DATA                  0x20
+#define SDIF_CMD_ABORTCMD              0xC0
+#define SDIF_CMD_RESP_NONE             0x00
+#define SDIF_CMD_RESP_LONG             0x01
+#define SDIF_CMD_RESP_SHORT            0x02
+#define SDIF_CMD_RESP_SHORT_BUSY       0x03
+#define SDIF_MAKE_CMD(c, f)            ((((c) & 0xff) << 8) | ((f) & 0xff))
+#define SDIF_RESPONSE_01               0x10
+#define SDIF_RESPONSE_23               0x14
+#define SDIF_RESPONSE_45               0x18
+#define SDIF_RESPONSE_67               0x1C
+
+#define SDIF_RESPONSE           0x10
+
+#define SDIF_BUFFER         0x20
+
+#define SDIF_PRESENT_STATE      0x24
+#define SDIF_DATA_INHIBIT       0x00000002
+#define SDIF_DOING_WRITE        0x00000100
+#define SDIF_DOING_READ     0x00000200
+#define SDIF_SPACE_AVAILABLE    0x00000400
+#define SDIF_DATA_AVAILABLE 0x00000800
+#define SDIF_CARD_PRESENT       0x00010000
+#define SDIF_WRITE_PROTECT      0x00080000
+#define SDIF_DATA_LVL_MASK      0x00F00000
+#define SDIF_DATA_LVL_SHIFT 20
+#define SDIF_DATA_0_LVL_MASK    0x00100000
+#define SDIF_CMD_LVL            0x01000000
+
+#define SDIF_CMD_INHIBIT               BIT(0)
+#define SDIF_CMD_INHIBIT_DAT           BIT(1)
+#define SDIF_CARD_INSERTED             BIT(16)
+#define SDIF_CARD_STABLE               BIT(17)
+#define SDIF_WR_PROTECT_SW_LVL         BIT(19)
+#define SDIF_DAT_XFER_WIDTH            BIT(1)
+#define SDIF_CTRL_SDMA                 0x00
+#define SDIF_CTRL_HISPD                0x04
+#define SDIF_BUS_VOL_VDD1_1_8V         0xC
+#define SDIF_BUS_VOL_VDD1_3_0V         0xE
+#define SDIF_CTRL_DMA_MASK             0x18
+#define SDIF_BUF_DATA_R                0x20
+#define SDIF_HOST_CONTROL              0x28
+#define SDIF_PWR_CONTROL               0x29
+#define SDIF_BLOCK_GAP_CONTROL         0x2A
+#define SDIF_WAKE_UP_CONTROL           0x2B
+#define SDIF_CLK_CTRL                  0x2C
+#define SDIF_TOUT_CTRL                 0x2E
+#define SDIF_SOFTWARE_RESET            0x2F
+#define SDIF_RESET_CMD                 0x02
+#define SDIF_RESET_DATA                0x04
+#define SDIF_INT_STATUS                0x30
+#define SDIF_ERR_INT_STATUS            0x32
+#define SDIF_INT_ENABLE                0x34
+#define SDIF_INT_XFER_COMPLETE         BIT(1)
+#define SDIF_INT_BUF_RD_READY          BIT(5)
+#define SDIF_INT_STATUS_EN             0x34
+#define SDIF_ERR_INT_STATUS_EN         0x36
+#define SDIF_SIGNAL_ENABLE             0x38
+#define SDIF_ERROR_SIGNAL_ENABLE       0x3A
+#define SDIF_AUTO_CMD_STATUS           0x3C
+#define SDIF_HOST_CONTROL2             0x3E
+#define SDIF_CAPABILITIES              0x40
+#define SDIF_CAPABILITIES_1            0x44
+#define SDIF_MAX_CURRENT               0x48
+#define SDIF_ADMA_ERROR                0x54
+#define SDIF_ADMA_ADDRESS              0x58
+#define SDIF_ADMA_ADDRESS_HI           0x5C
+#define SDIF_SLOT_INT_STATUS          0xFC
+#define SDIF_HOST_VERSION              0xFE
+#define SDIF_INT_XFER_COMPLETE_EN      BIT(1)
+#define SDIF_INT_DMA_END_EN            BIT(3)
+#define SDIF_INT_ERROR_EN              BIT(15)
+#define SDIF_HOST_ADMA2_LEN_MODE       BIT(10)
+#define SDIF_CTRL_UHS_MASK          0x0007
+#define SDIF_CTRL_UHS_SDR12         0x0000
+#define SDIF_CTRL_UHS_SDR25         0x0001
+#define SDIF_CTRL_UHS_SDR50         0x0002
+#define SDIF_CTRL_UHS_SDR104        0x0003
+#define SDIF_CTRL_UHS_DDR50         0x0004
+#define SDIF_CTRL_HS400         0x0005 /* Non-standard */
+#define SDIF_CTRL_DRV_TYPE_MASK     0x0030
+#define SDIF_CTRL_DRV_TYPE_B        0x0000
+#define SDIF_CTRL_DRV_TYPE_A        0x0010
+#define SDIF_CTRL_DRV_TYPE_C        0x0020
+#define SDIF_CTRL_DRV_TYPE_D        0x0030
+#define SDIF_CTRL_EXEC_TUNING       0x0040
+#define SDIF_CTRL_TUNED_CLK         0x0080
+#define SDIF_CTRL_PRESET_VAL_ENABLE   0x8000
+
+#define SDIF_GET_CMD(c) ((c>>8) & 0x3f)
+
+#define SDIF_INT_RESPONSE       0x00000001
+#define SDIF_INT_DATA_END       0x00000002
+#define SDIF_INT_BLK_GAP        0x00000004
+#define SDIF_INT_DMA_END        0x00000008
+#define SDIF_INT_SPACE_AVAIL    0x00000010
+#define SDIF_INT_DATA_AVAIL 0x00000020
+#define SDIF_INT_CARD_INSERT    0x00000040
+#define SDIF_INT_CARD_REMOVE    0x00000080
+#define SDIF_INT_CARD_INT       0x00000100
+#define SDIF_INT_RETUNE     0x00001000
+#define SDIF_INT_ERROR          0x00008000
+#define SDIF_INT_TIMEOUT        0x00010000
+#define SDIF_INT_CRC            0x00020000
+#define SDIF_INT_END_BIT        0x00040000
+#define SDIF_INT_INDEX          0x00080000
+#define SDIF_INT_DATA_TIMEOUT   0x00100000
+#define SDIF_INT_DATA_CRC       0x00200000
+#define SDIF_INT_DATA_END_BIT   0x00400000
+#define SDIF_INT_BUS_POWER      0x00800000
+#define SDIF_INT_ACMD12ERR      0x01000000
+#define SDIF_INT_ADMA_ERROR 0x02000000
+
+#define SDIF_INT_CMD_MASK   (SDIF_INT_RESPONSE | SDIF_INT_TIMEOUT | \
+        SDIF_INT_CRC | SDIF_INT_END_BIT | SDIF_INT_INDEX)
+#define SDIF_INT_DATA_MASK  (SDIF_INT_DATA_END | SDIF_INT_DMA_END | \
+        SDIF_INT_DATA_AVAIL | SDIF_INT_SPACE_AVAIL | \
+        SDIF_INT_DATA_TIMEOUT | SDIF_INT_DATA_CRC | \
+        SDIF_INT_DATA_END_BIT | SDIF_INT_ADMA_ERROR | \
+        SDIF_INT_BLK_GAP)
+
+#define SDIF_HOST_VER4_ENABLE          BIT(12)
+#define SDIF_CAPABILITIES1             0x40
+#define SDIF_CAPABILITIES2             0x44
+#define SDIF_ADMA_SA_LOW               0x58
+#define SDIF_ADMA_SA_HIGH              0x5C
+#define SDIF_HOST_CNTRL_VERS            0xFE
+#define SDIF_UHS_2_TIMER_CNTRL          0xC2
+
+#define P_VENDOR_SPECIFIC_AREA          0xE8
+#define P_VENDOR2_SPECIFIC_AREA         0xEA
+#define VENDOR_SD_CTRL                  0x2C
+
+
+#define DEFAULT_DIV_SD_INIT_CLOCK 0x2
+
+/*execute tuning register and bit flag*/
+#define SDIF_PHY_TX_RX_DLY  0x40
+#define SDIF_PHY_CONFIG     0x4c
+
+/*SDIO 0 register and bit flag*/
+#define REG_SDIO0_PAD_MASK      (0xFFFFFFF3)
+#define REG_SDIO0_PAD_SHIFT     (2)
+
+#define REG_SDIO0_CD_PAD_REG        (PINMUX_BASE + 0x900)
+#define REG_SDIO0_CD_PAD_VALUE      (1)
+
+#define REG_SDIO0_PWR_EN_PAD_REG    (PINMUX_BASE + 0x904)
+#define REG_SDIO0_PWR_EN_PAD_VALUE  (2)
+
+#define REG_SDIO0_CLK_PAD_REG       (PINMUX_BASE + 0xA00)
+#define REG_SDIO0_CLK_PAD_VALUE     (2)
+
+#define REG_SDIO0_CMD_PAD_REG       (PINMUX_BASE + 0xA04)
+#define REG_SDIO0_CMD_PAD_VALUE     (1)
+
+#define REG_SDIO0_DAT0_PAD_REG      (PINMUX_BASE + 0xA08)
+#define REG_SDIO0_DAT0_PAD_VALUE    (1)
+
+#define REG_SDIO0_DAT1_PAD_REG      (PINMUX_BASE + 0xA0C)
+#define REG_SDIO0_DAT1_PAD_VALUE    (1)
+
+#define REG_SDIO0_DAT2_PAD_REG      (PINMUX_BASE + 0xA10)
+#define REG_SDIO0_DAT2_PAD_VALUE    (1)
+
+#define REG_SDIO0_DAT3_PAD_REG      (PINMUX_BASE + 0xA14)
+#define REG_SDIO0_DAT3_PAD_VALUE    (1)
+
+#define REG_SDIO0_CD_PIO_REG        (PINMUX_BASE + 0x34)
+#define REG_SDIO0_CD_PIO_VALUE      (0x3)
+
+#define REG_SDIO0_PWR_EN_PIO_REG    (PINMUX_BASE + 0x38)
+#define REG_SDIO0_PWR_EN_PIO_VALUE  (0x0)
+
+#define REG_SDIO0_CLK_PIO_REG       (PINMUX_BASE + 0x1C)
+#define REG_SDIO0_CLK_PIO_VALUE     (0x0)
+
+#define REG_SDIO0_CMD_PIO_REG       (PINMUX_BASE + 0x20)
+#define REG_SDIO0_CMD_PIO_VALUE     (0x0)
+
+#define REG_SDIO0_DAT0_PIO_REG      (PINMUX_BASE + 0x24)
+#define REG_SDIO0_DAT0_PIO_VALUE    (0x0)
+
+#define REG_SDIO0_DAT1_PIO_REG      (PINMUX_BASE + 0x28)
+#define REG_SDIO0_DAT1_PIO_VALUE    (0x0)
+
+#define REG_SDIO0_DAT2_PIO_REG      (PINMUX_BASE + 0x2C)
+#define REG_SDIO0_DAT2_PIO_VALUE    (0x0)
+
+#define REG_SDIO0_DAT3_PIO_REG      (PINMUX_BASE + 0x30)
+#define REG_SDIO0_DAT3_PIO_VALUE    (0x0)
+
+/*SDIO 1 register and bit flag*/
+#define RTCIO_BASE (0x5027000)
+#define REG_SDIO1_PAD_MASK      (0xFFFFFFF3)
+#define REG_SDIO1_PAD_SHIFT     (2)
+
+#define REG_SDIO1_CLK_PAD_REG       (RTCIO_BASE + 0x6C)
+#define REG_SDIO1_CLK_PAD_VALUE     (2)
+
+#define REG_SDIO1_CMD_PAD_REG       (RTCIO_BASE + 0x68)
+#define REG_SDIO1_CMD_PAD_VALUE     (1)
+
+#define REG_SDIO1_DAT0_PAD_REG      (RTCIO_BASE + 0x64)
+#define REG_SDIO1_DAT0_PAD_VALUE    (1)
+
+#define REG_SDIO1_DAT1_PAD_REG      (RTCIO_BASE + 0x60)
+#define REG_SDIO1_DAT1_PAD_VALUE    (1)
+
+#define REG_SDIO1_DAT2_PAD_REG      (RTCIO_BASE + 0x5C)
+#define REG_SDIO1_DAT2_PAD_VALUE    (1)
+
+#define REG_SDIO1_DAT3_PAD_REG      (RTCIO_BASE + 0x58)
+#define REG_SDIO1_DAT3_PAD_VALUE    (1)
+
+#define REG_SDIO1_CLK_PIO_REG       (PINMUX_BASE + 0xE4)
+#define REG_SDIO1_CLK_PIO_VALUE     (0x0)
+
+#define REG_SDIO1_CMD_PIO_REG       (PINMUX_BASE + 0xE0)
+#define REG_SDIO1_CMD_PIO_VALUE     (0x0)
+
+#define REG_SDIO1_DAT0_PIO_REG      (PINMUX_BASE + 0xDC)
+#define REG_SDIO1_DAT0_PIO_VALUE    (0x0)
+
+#define REG_SDIO1_DAT1_PIO_REG      (PINMUX_BASE + 0xD8)
+#define REG_SDIO1_DAT1_PIO_VALUE    (0x0)
+
+#define REG_SDIO1_DAT2_PIO_REG      (PINMUX_BASE + 0xD4)
+#define REG_SDIO1_DAT2_PIO_VALUE    (0x0)
+
+#define REG_SDIO1_DAT3_PIO_REG      (PINMUX_BASE + 0xD0)
+#define REG_SDIO1_DAT3_PIO_VALUE    (0x0)
+
+#define RTC_CTRL_BASE       0x5025000
+#define RTCSYS_CLKMUX       (RTC_CTRL_BASE + 0x1C)
+#define RTCSYS_CLKBYP       (RTC_CTRL_BASE + 0x30)
+#define RTCSYS_MCU51_ICTRL1 (RTC_CTRL_BASE + 0x7C)
+
+#define RTCSYS_CTRL_BASE    0x03000000
+#define RTCSYS_CTRL     (RTCSYS_CTRL_BASE + 0x248)
+
+/*SDIO 2 register and bit flag*/
+#define REG_SDIO2_PAD_MASK (0xFFFFFFF3)
+#define REG_SDIO2_PAD_SHIFT (2)
+
+#define REG_SDIO2_RSTN_PAD_REG (PINMUX_BASE + 0x914)
+#define REG_SDIO2_RSTN_PAD_VALUE (1)
+
+#define REG_SDIO2_CLK_PAD_REG (PINMUX_BASE + 0x91C)
+#define REG_SDIO2_CLK_PAD_VALUE (2)
+
+#define REG_SDIO2_CMD_PAD_REG (PINMUX_BASE + 0x928)
+#define REG_SDIO2_CMD_PAD_VALUE (1)
+
+#define REG_SDIO2_DAT0_PAD_REG (PINMUX_BASE + 0x920)
+#define REG_SDIO2_DAT0_PAD_VALUE (1)
+
+#define REG_SDIO2_DAT1_PAD_REG (PINMUX_BASE + 0x92C)
+#define REG_SDIO2_DAT1_PAD_VALUE (1)
+
+#define REG_SDIO2_DAT2_PAD_REG (PINMUX_BASE + 0x918)
+#define REG_SDIO2_DAT2_PAD_VALUE (1)
+
+#define REG_SDIO2_DAT3_PAD_REG (PINMUX_BASE + 0x924)
+#define REG_SDIO2_DAT3_PAD_VALUE (1)
+
+#define REG_SDIO2_RSTN_PIO_REG (PINMUX_BASE + 0x48)
+#define REG_SDIO2_RSTN_PIO_VALUE (0x0)
+
+#define REG_SDIO2_CLK_PIO_REG (PINMUX_BASE + 0x50)
+#define REG_SDIO2_CLK_PIO_VALUE (0x0)
+
+#define REG_SDIO2_CMD_PIO_REG (PINMUX_BASE + 0x5C)
+#define REG_SDIO2_CMD_PIO_VALUE (0x0)
+
+#define REG_SDIO2_DAT0_PIO_REG (PINMUX_BASE + 0x54)
+#define REG_SDIO2_DAT0_PIO_VALUE (0x0)
+
+#define REG_SDIO2_DAT1_PIO_REG (PINMUX_BASE + 0x60)
+#define REG_SDIO2_DAT1_PIO_VALUE (0x0)
+
+#define REG_SDIO2_DAT2_PIO_REG (PINMUX_BASE + 0x4C)
+#define REG_SDIO2_DAT2_PIO_VALUE (0x0)
+
+#define REG_SDIO2_DAT3_PIO_REG (PINMUX_BASE + 0x58)
+#define REG_SDIO2_DAT3_PIO_VALUE (0x0)
+
+
+#define MMC_SDIO0_PLL_REGISTER 0x3002070
+#define MMC_SDIO1_PLL_REGISTER 0x300207C
+#define MMC_SDIO2_PLL_REGISTER 0x3002064
+#define MMC_MAX_CLOCK_DIV_VALUE (0x40009)
+#define CLOCK_BYPASS_SELECT_REGISTER (0x3002030)
+
+#endif /* __HAL_DW_SDIO_H_ */

+ 108 - 0
bsp/cvitek/drivers/port/mnt.c

@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2006-2023, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2022/12/25     flyingcys    first version
+ */
+#include <rtthread.h>
+
+#ifdef RT_USING_DFS
+#include <dfs_fs.h>
+#include "dfs_romfs.h"
+
+#define DBG_TAG "app.filesystem"
+#define DBG_LVL DBG_LOG
+#include <rtdbg.h>
+
+static const struct romfs_dirent _romfs_root[] =
+{
+#ifdef BSP_USING_ON_CHIP_FLASH
+    {ROMFS_DIRENT_DIR, "flash", RT_NULL, 0},
+#endif
+    {ROMFS_DIRENT_DIR, "sdcard", RT_NULL, 0}
+};
+
+const struct romfs_dirent romfs_root =
+{
+    ROMFS_DIRENT_DIR, "/", (rt_uint8_t *)_romfs_root, sizeof(_romfs_root)  / sizeof(_romfs_root[0])
+};
+
+static void sd_mount(void *parameter)
+{
+    while (1)
+    {
+        rt_thread_mdelay(500);
+
+        if (rt_device_find("sd0") != RT_NULL)
+        {
+            if (dfs_mount("sd0", "/sdcard", "elm", 0, 0) == RT_EOK)
+            {
+                LOG_I("sd card mount to '/sdcard'");
+                break;
+            }
+            else
+            {
+                LOG_W("sd card mount to '/sdcard' failed! %d\n", rt_get_errno());
+            }
+        }
+    }
+}
+
+int mount_init(void)
+{
+    if(dfs_mount(RT_NULL, "/", "rom", 0, &romfs_root) != 0)
+    {
+        LOG_E("rom mount to '/' failed!");
+    }
+
+#ifdef BSP_USING_ON_CHIP_FLASH_FS
+    struct rt_device *flash_dev = RT_NULL;
+
+    /* 使用 filesystem 分区创建块设备,块设备名称为 filesystem */
+    flash_dev = fal_blk_device_create("filesystem");
+    if(flash_dev == RT_NULL)
+    {
+        LOG_E("Failed to create device.\n");
+        return -RT_ERROR;
+    }
+
+    if (dfs_mount("filesystem", "/flash", "lfs", 0, 0) != 0)
+    {
+        LOG_I("file system initialization failed!\n");
+        if(dfs_mkfs("lfs", "filesystem") == 0)
+        {
+            if (dfs_mount("filesystem", "/flash", "lfs", 0, 0) == 0)
+            {
+                LOG_I("mount to '/flash' success!");
+            }
+        }
+    }
+    else
+    {
+        LOG_I("mount to '/flash' success!");
+    }
+#endif
+
+#ifdef BSP_USING_SDH
+    rt_thread_t tid;
+
+    tid = rt_thread_create("sd_mount", sd_mount, RT_NULL,
+                            4096, RT_THREAD_PRIORITY_MAX - 2, 20);
+    if (tid != RT_NULL)
+    {
+        rt_thread_startup(tid);
+    }
+    else
+    {
+        LOG_E("create sd_mount thread err!");
+    }
+#endif
+
+    return RT_EOK;
+}
+INIT_APP_EXPORT(mount_init);
+
+#endif /* RT_USING_DFS */

+ 19 - 0
libcpu/risc-v/t-head/c906/tick.c

@@ -49,3 +49,22 @@ int rt_hw_tick_init(void)
 
     return 0;
 }
+
+/**
+ * This function will delay for some us.
+ *
+ * @param us the delay time of us
+ */
+void rt_hw_us_delay(rt_uint32_t us)
+{
+    unsigned long start_time;
+    unsigned long end_time;
+    unsigned long run_time;
+
+    start_time = get_ticks();
+    end_time = start_time + us * (TIMER_CLK_FREQ / 1000000);
+    do
+    {
+        run_time = get_ticks();
+    } while(run_time < end_time);
+}