summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/action.yml8
-rw-r--r--.github/workflows/action_utest.yml10
-rw-r--r--bsp/ft2004/.config725
-rw-r--r--bsp/ft2004/Kconfig31
-rw-r--r--bsp/ft2004/README.md236
-rw-r--r--bsp/ft2004/SConscript14
-rw-r--r--bsp/ft2004/SConstruct32
-rw-r--r--bsp/ft2004/applications/SConscript11
-rw-r--r--bsp/ft2004/applications/main.c77
-rw-r--r--bsp/ft2004/drivers/SConscript14
-rw-r--r--bsp/ft2004/drivers/board.c155
-rw-r--r--bsp/ft2004/drivers/board.h29
-rw-r--r--bsp/ft2004/drivers/drv_can.c270
-rw-r--r--bsp/ft2004/drivers/drv_can.h38
-rw-r--r--bsp/ft2004/drivers/drv_eth.c691
-rw-r--r--bsp/ft2004/drivers/drv_eth.h25
-rw-r--r--bsp/ft2004/drivers/drv_log.h27
-rw-r--r--bsp/ft2004/drivers/drv_qspi.c424
-rw-r--r--bsp/ft2004/drivers/drv_qspi.h29
-rw-r--r--bsp/ft2004/drivers/drv_qspi_flash.c39
-rw-r--r--bsp/ft2004/drivers/drv_sdcard.c154
-rw-r--r--bsp/ft2004/drivers/drv_sdctrl.c659
-rw-r--r--bsp/ft2004/drivers/drv_sdctrl.h47
-rw-r--r--bsp/ft2004/drivers/drv_spi.c449
-rw-r--r--bsp/ft2004/drivers/drv_spi.h29
-rw-r--r--bsp/ft2004/drivers/drv_spi_flash.c43
-rw-r--r--bsp/ft2004/drivers/drv_usart.c192
-rw-r--r--bsp/ft2004/drivers/drv_usart.h25
-rw-r--r--bsp/ft2004/drivers/ft2004.c88
-rw-r--r--bsp/ft2004/drivers/ft2004.h25
-rw-r--r--bsp/ft2004/drivers/ft2004_cpu.S44
-rw-r--r--bsp/ft2004/drivers/secondary_cpu.c86
-rw-r--r--bsp/ft2004/drivers/serial.h20
-rw-r--r--bsp/ft2004/figures/onchipPeripheral.pngbin0 -> 22293 bytes
-rw-r--r--bsp/ft2004/figures/rttPing通过界面.pngbin0 -> 10980 bytes
-rw-r--r--bsp/ft2004/figures/rttsd调试.pngbin0 -> 22374 bytes
-rw-r--r--bsp/ft2004/figures/启动演示图.pngbin0 -> 24488 bytes
-rw-r--r--bsp/ft2004/ft_aarch32.lds110
-rw-r--r--bsp/ft2004/libraries/.gitignore4
-rw-r--r--bsp/ft2004/libraries/Kconfig146
-rw-r--r--bsp/ft2004/libraries/LICENSE202
-rw-r--r--bsp/ft2004/libraries/SConscript129
-rw-r--r--bsp/ft2004/libraries/bsp/ft_can/ft_can.c299
-rw-r--r--bsp/ft2004/libraries/bsp/ft_can/ft_can.h142
-rw-r--r--bsp/ft2004/libraries/bsp/ft_can/ft_can_calc.c269
-rw-r--r--bsp/ft2004/libraries/bsp/ft_can/ft_can_g.c39
-rw-r--r--bsp/ft2004/libraries/bsp/ft_can/ft_can_hw.c55
-rw-r--r--bsp/ft2004/libraries/bsp/ft_can/ft_can_hw.h161
-rw-r--r--bsp/ft2004/libraries/bsp/ft_can/ft_can_intr.c118
-rw-r--r--bsp/ft2004/libraries/bsp/ft_can/ft_can_sinit.c40
-rw-r--r--bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac.c109
-rw-r--r--bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac.h319
-rw-r--r--bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_desc.c357
-rw-r--r--bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_desc.h20
-rw-r--r--bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_g.c47
-rw-r--r--bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_hw.c566
-rw-r--r--bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_hw.h577
-rw-r--r--bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_intr.c174
-rw-r--r--bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_sinit.c34
-rw-r--r--bsp/ft2004/libraries/bsp/ft_gpio/ft_gpio.c107
-rw-r--r--bsp/ft2004/libraries/bsp/ft_gpio/ft_gpio.h73
-rw-r--r--bsp/ft2004/libraries/bsp/ft_gpio/ft_gpio_hw.h92
-rw-r--r--bsp/ft2004/libraries/bsp/ft_i2c/ft_i2c.c510
-rw-r--r--bsp/ft2004/libraries/bsp/ft_i2c/ft_i2c.h197
-rw-r--r--bsp/ft2004/libraries/bsp/ft_i2c/ft_i2c_g.c13
-rw-r--r--bsp/ft2004/libraries/bsp/ft_i2c/ft_i2c_hw.h321
-rw-r--r--bsp/ft2004/libraries/bsp/ft_i2c/ft_i2c_irq.c182
-rw-r--r--bsp/ft2004/libraries/bsp/ft_i2c/ft_i2c_selftest.c20
-rw-r--r--bsp/ft2004/libraries/bsp/ft_qspi/ft_qspi.c585
-rw-r--r--bsp/ft2004/libraries/bsp/ft_qspi/ft_qspi.h184
-rw-r--r--bsp/ft2004/libraries/bsp/ft_qspi/qspi_g.c26
-rw-r--r--bsp/ft2004/libraries/bsp/ft_qspi/qspi_hw.c25
-rw-r--r--bsp/ft2004/libraries/bsp/ft_qspi/qspi_hw.h199
-rw-r--r--bsp/ft2004/libraries/bsp/ft_qspi/qspi_sinit.c34
-rw-r--r--bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl.c552
-rw-r--r--bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl.h235
-rw-r--r--bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl_g.c31
-rw-r--r--bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl_hw.c41
-rw-r--r--bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl_hw.h210
-rw-r--r--bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl_intr.c110
-rw-r--r--bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl_option.c61
-rw-r--r--bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl_sinit.c33
-rw-r--r--bsp/ft2004/libraries/bsp/ft_spi/ft_spi.c192
-rw-r--r--bsp/ft2004/libraries/bsp/ft_spi/ft_spi.h95
-rw-r--r--bsp/ft2004/libraries/bsp/ft_spi/ft_spi_hw.h330
-rw-r--r--bsp/ft2004/libraries/bsp/ft_spi/ft_spi_irq.c13
-rw-r--r--bsp/ft2004/libraries/bsp/ft_uart/ft_uart.c329
-rw-r--r--bsp/ft2004/libraries/bsp/ft_uart/ft_uart.h120
-rw-r--r--bsp/ft2004/libraries/bsp/ft_uart/ft_uart_g.c34
-rw-r--r--bsp/ft2004/libraries/bsp/ft_uart/ft_uart_hw.c46
-rw-r--r--bsp/ft2004/libraries/bsp/ft_uart/ft_uart_hw.h221
-rw-r--r--bsp/ft2004/libraries/bsp/ft_uart/ft_uart_intr.c196
-rw-r--r--bsp/ft2004/libraries/bsp/ft_uart/ft_uart_options.c102
-rw-r--r--bsp/ft2004/libraries/bsp/ft_uart/ft_uart_selftest.c13
-rw-r--r--bsp/ft2004/libraries/bsp/ft_uart/ft_uart_sinit.c41
-rw-r--r--bsp/ft2004/libraries/bsp/include/ft_parameters.h180
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_assert.c43
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_assert.h154
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_cache.c86
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_cache.h32
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_cpu.c145
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_cpu.h26
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_debug.c67
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_debug.h78
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_error_code.h72
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_generic_timer.c327
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_generic_timer.h57
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_io.h164
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_list.h23
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_math.c19
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_math.h24
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_mux.c90
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_mux.h75
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_printf.c96
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_printf.h29
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_psci.c78
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_psci.h31
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_smc.S36
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_smc.h43
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_status.h82
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_trace.c57
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_trace.h52
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/ft_types.h75
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/inbyte.c21
-rw-r--r--bsp/ft2004/libraries/bsp/standlone/outbyte.c21
-rw-r--r--bsp/ft2004/libraries/cpu/ft_aarch32_asm.h319
-rw-r--r--bsp/ft2004/libraries/doc/ChangeLog.md90
-rw-r--r--bsp/ft2004/libraries/doc/figures/v0.3.0_add.pngbin0 -> 297513 bytes
-rw-r--r--bsp/ft2004/libraries/include/asmArm.h37
-rw-r--r--bsp/ft2004/libraries/readme.md69
-rw-r--r--bsp/ft2004/make.sh16
-rw-r--r--bsp/ft2004/rtconfig.h287
-rw-r--r--bsp/ft2004/rtconfig.py59
-rw-r--r--bsp/gd32303e-eval/cconfig.h18
-rw-r--r--bsp/gd32450z-eval/Libraries/CMSIS/GD/GD32F4xx/Include/gd32f4xx.h293
-rw-r--r--bsp/gd32450z-eval/Libraries/CMSIS/GD/GD32F4xx/Source/system_gd32f4xx.c289
-rw-r--r--bsp/gd32450z-eval/Libraries/CMSIS/core_cm4.h6
-rw-r--r--bsp/gd32450z-eval/Libraries/CMSIS/core_cmFunc.h2
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_adc.h424
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_can.h297
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_crc.h45
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_ctc.h110
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_dac.h268
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_dbg.h92
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_dci.h142
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_dma.h144
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_enet.h472
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_exmc.h984
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_exti.h59
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_fmc.h154
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_fwdgt.h39
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_gpio.h595
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_i2c.h307
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_ipa.h170
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_iref.h41
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_misc.h33
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_pmu.h50
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_rcu.h125
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_rtc.h67
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_sdio.h69
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_spi.h226
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_syscfg.h61
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_timer.h388
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_tli.h274
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_trng.h56
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_usart.h214
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_wwdgt.h33
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_adc.c1294
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_can.c648
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_crc.c63
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_ctc.c249
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_dac.c405
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_dbg.c112
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_dci.c202
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_dma.c747
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_enet.c1150
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_exmc.c967
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_exti.c106
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_fmc.c562
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_fwdgt.c73
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_gpio.c218
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_i2c.c681
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_ipa.c480
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_iref.c35
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_misc.c46
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_pmu.c127
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_rcu.c264
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_rtc.c326
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_sdio.c128
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_spi.c681
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_syscfg.c50
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_timer.c991
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_tli.c607
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_trng.c87
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_usart.c361
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_wwdgt.c70
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usb_core.h287
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usb_defines.h100
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usb_regs.h676
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usb_std.h188
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbd_core.h54
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbd_int.h31
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbd_std.h70
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbh_core.h283
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbh_ctrl.h45
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbh_hcs.h46
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbh_int.h30
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbh_std.h74
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usb_core.c1132
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbd_core.c520
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbd_int.c758
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbd_std.c699
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbh_core.c710
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbh_ctrl.c620
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbh_hcs.c162
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbh_int.c591
-rw-r--r--bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbh_std.c808
-rw-r--r--bsp/gd32450z-eval/Libraries/SConscript4
-rw-r--r--bsp/gd32450z-eval/drivers/drv_usart.c6
-rw-r--r--bsp/gd32450z-eval/rtconfig.py2
-rw-r--r--bsp/imx6ul/.config113
-rw-r--r--bsp/imx6ul/Kconfig1
-rw-r--r--bsp/imx6ul/SConstruct2
-rw-r--r--bsp/imx6ul/drivers/Kconfig3
-rw-r--r--bsp/imx6ul/drivers/iomux/uart_iomux_config.c21
-rw-r--r--bsp/imx6ul/drivers/serial.c24
-rw-r--r--bsp/imx6ul/link.lds (renamed from bsp/imx6ul/imx6.lds)0
-rw-r--r--bsp/imx6ul/platform/include/mx6ul/imx6ul-pinfunc.h915
-rw-r--r--bsp/imx6ul/platform/include/mx6ul/iomux_register.h3
-rw-r--r--bsp/imx6ul/rtconfig.h19
-rw-r--r--bsp/imx6ul/rtconfig.py14
-rw-r--r--bsp/k210/driver/board.c19
-rw-r--r--bsp/qemu-riscv-virt64/.config7
-rw-r--r--bsp/qemu-riscv-virt64/README.md142
-rw-r--r--bsp/qemu-riscv-virt64/README_ZH.md138
-rw-r--r--bsp/qemu-riscv-virt64/SConstruct6
-rw-r--r--bsp/qemu-riscv-virt64/applications/main.c7
-rw-r--r--bsp/qemu-riscv-virt64/driver/Kconfig7
-rw-r--r--bsp/qemu-riscv-virt64/driver/board.c149
-rw-r--r--bsp/qemu-riscv-virt64/driver/board.h2
-rw-r--r--bsp/qemu-riscv-virt64/driver/drv_uart.c112
-rw-r--r--bsp/qemu-riscv-virt64/driver/drv_uart.h34
-rw-r--r--bsp/qemu-riscv-virt64/driver/io.h2
-rw-r--r--bsp/qemu-riscv-virt64/driver/plic.c98
-rw-r--r--bsp/qemu-riscv-virt64/driver/plic.h59
-rw-r--r--bsp/qemu-riscv-virt64/link.lds4
-rw-r--r--bsp/qemu-riscv-virt64/link_stacksize.lds3
-rwxr-xr-xbsp/qemu-riscv-virt64/qemu-nographic-smode.sh1
-rwxr-xr-x[-rw-r--r--]bsp/qemu-riscv-virt64/qemu-nographic.sh2
-rw-r--r--bsp/qemu-riscv-virt64/rtconfig.h2
-rw-r--r--bsp/qemu-vexpress-a9/.config3
-rw-r--r--bsp/qemu-vexpress-a9/Kconfig1
-rw-r--r--bsp/qemu-vexpress-a9/rtconfig.h1
-rw-r--r--bsp/stm32/libraries/HAL_Drivers/drv_usbd.c5
-rw-r--r--bsp/stm32/stm32l475-atk-pandora/board/Kconfig35
-rw-r--r--bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.c21
-rw-r--r--bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/sleep.h9
-rw-r--r--bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/xil_assert.h9
-rw-r--r--bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/xil_cache.h11
-rw-r--r--bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/xil_printf.h13
-rw-r--r--bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/xil_types.h34
-rw-r--r--bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/xplatform_info.h10
-rw-r--r--bsp/zynqmp-r5-axu4ev/drivers/drv_eth.c2
-rw-r--r--bsp/zynqmp-r5-axu4ev/drivers/zynqmp-r5.h9
-rw-r--r--components/dfs/include/dfs_fs.h2
-rw-r--r--components/drivers/cputime/cputime.c5
-rw-r--r--components/drivers/src/pipe.c11
-rw-r--r--components/finsh/msh.c2
-rw-r--r--components/finsh/msh_file.c152
-rw-r--r--components/finsh/shell.c2
-rw-r--r--components/libc/compilers/common/SConscript13
-rw-r--r--components/libc/compilers/common/none-gcc/SConscript6
-rw-r--r--components/libc/compilers/common/none-gcc/sys/errno.h (renamed from include/libc/libc_errno.h)21
-rw-r--r--components/libc/compilers/common/time.c1
-rw-r--r--components/libc/compilers/newlib/minilib.c14
-rw-r--r--components/libc/getline/posix_getline.c6
-rw-r--r--components/libc/pthreads/posix_types.h2
-rw-r--r--components/libc/signal/posix_signal.c3
-rw-r--r--components/net/lwip-1.4.1/src/arch/include/arch/cc.h14
-rw-r--r--components/net/lwip-1.4.1/src/lwipopts.h2
-rw-r--r--components/net/lwip-2.0.2/src/arch/include/arch/cc.h16
-rw-r--r--components/net/lwip-2.0.2/src/lwipopts.h2
-rw-r--r--components/net/lwip-2.1.2/src/arch/include/arch/cc.h13
-rw-r--r--components/net/lwip-2.1.2/src/include/lwip/errno.h2
-rw-r--r--components/net/lwip-2.1.2/src/lwipopts.h3
-rw-r--r--components/net/sal_socket/socket/net_sockets.c2
-rw-r--r--examples/file/listdir.c9
-rw-r--r--examples/libc/ex3.c2
-rw-r--r--examples/libc/ex6.c2
-rw-r--r--examples/libc/ex7.c2
-rw-r--r--examples/libc/file.c2
-rw-r--r--examples/libc/memory.c2
-rw-r--r--examples/utest/configs/kernel/config.h304
-rw-r--r--examples/utest/configs/utest_self/config.h1
-rw-r--r--examples/utest/testcases/Kconfig1
-rw-r--r--examples/utest/testcases/kernel/Kconfig8
-rw-r--r--examples/utest/testcases/kernel/SConscript15
-rw-r--r--examples/utest/testcases/kernel/memheap_tc.c100
-rw-r--r--examples/utest/testcases/utest/pass_tc.c2
-rw-r--r--include/libc/libc_limits.h25
-rw-r--r--include/rtlibc.h2
-rw-r--r--include/rtthread.h1
-rw-r--r--libcpu/Kconfig21
-rw-r--r--libcpu/arm/cortex-a/cpu.c17
-rw-r--r--libcpu/risc-v/virt64/context_gcc.S297
-rw-r--r--libcpu/risc-v/virt64/cpuport.c13
-rw-r--r--libcpu/risc-v/virt64/cpuport.h33
-rw-r--r--libcpu/risc-v/virt64/interrupt.c274
-rw-r--r--libcpu/risc-v/virt64/interrupt.h27
-rw-r--r--libcpu/risc-v/virt64/interrupt_gcc.S178
-rw-r--r--libcpu/risc-v/virt64/riscv.h2
-rw-r--r--libcpu/risc-v/virt64/riscv_io.h178
-rw-r--r--libcpu/risc-v/virt64/stack.h2
-rw-r--r--libcpu/risc-v/virt64/stackframe.h24
-rw-r--r--libcpu/risc-v/virt64/startup_gcc.S77
-rw-r--r--libcpu/risc-v/virt64/tick.c28
-rw-r--r--libcpu/risc-v/virt64/tick.h7
-rw-r--r--src/clock.c20
-rw-r--r--src/components.c26
-rw-r--r--src/cpu.c2
-rw-r--r--src/device.c14
-rw-r--r--src/idle.c38
-rwxr-xr-xsrc/ipc.c91
-rw-r--r--src/irq.c6
-rw-r--r--src/kservice.c64
-rw-r--r--src/mem.c48
-rw-r--r--src/memheap.c102
-rw-r--r--src/mempool.c7
-rw-r--r--src/object.c14
-rw-r--r--src/scheduler.c78
-rw-r--r--src/signal.c12
-rw-r--r--src/slab.c26
-rw-r--r--src/thread.c56
-rw-r--r--src/timer.c28
-rw-r--r--tools/building.py11
-rw-r--r--tools/formatting.py135
-rw-r--r--tools/makefile.py8
-rw-r--r--tools/mkdist.py3
-rw-r--r--tools/rtthread.mk4
339 files changed, 30888 insertions, 17496 deletions
diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml
index ecbc19cca9..bc9e7fe2a4 100644
--- a/.github/workflows/action.yml
+++ b/.github/workflows/action.yml
@@ -149,10 +149,10 @@ jobs:
if: ${{ matrix.legs.RTT_TOOL_CHAIN == 'sourcery-arm' && success() }}
shell: bash
run: |
- wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/arm-2017q2-v6/gcc-arm-none-eabi-6-2017-q2-update-linux.tar.bz2
- sudo tar xjf gcc-arm-none-eabi-6-2017-q2-update-linux.tar.bz2 -C /opt
- /opt/gcc-arm-none-eabi-6-2017-q2-update/bin/arm-none-eabi-gcc --version
- echo "RTT_EXEC_PATH=/opt/gcc-arm-none-eabi-6-2017-q2-update/bin" >> $GITHUB_ENV
+ wget -q https://developer.arm.com/-/media/Files/downloads/gnu-rm/10-2020q4/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
+ sudo tar xjf gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2 -C /opt
+ /opt/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-gcc --version
+ echo "RTT_EXEC_PATH=/opt/gcc-arm-none-eabi-10-2020-q4-major/bin" >> $GITHUB_ENV
- name: Install Mips ToolChains
if: ${{ matrix.legs.RTT_TOOL_CHAIN == 'sourcery-mips' && success() }}
diff --git a/.github/workflows/action_utest.yml b/.github/workflows/action_utest.yml
index b8fea056e1..22e4505177 100644
--- a/.github/workflows/action_utest.yml
+++ b/.github/workflows/action_utest.yml
@@ -11,7 +11,7 @@ jobs:
fail-fast: false
matrix:
legs:
- - {UTEST: "kernel/ipc", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "vexpress-a9", CONFIG_FILE: "examples/utest/configs/utest_self/config.h"}
+ - {UTEST: "kernel/mem", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "vexpress-a9", CONFIG_FILE: "examples/utest/configs/kernel/config.h"}
- {UTEST: "components/utest", RTT_BSP: "bsp/qemu-vexpress-a9", QEMU_ARCH: "vexpress-a9", CONFIG_FILE: "examples/utest/configs/utest_self/config.h"}
env:
@@ -23,12 +23,12 @@ jobs:
run: |
sudo apt-get update > /dev/null
sudo apt-get -yqq install scons qemu-system-arm git
- wget -q https://github.com/RT-Thread/toolchains-ci/releases/download/arm-2017q2-v6/gcc-arm-none-eabi-6-2017-q2-update-linux.tar.bz2
- sudo tar xjf gcc-arm-none-eabi-6-2017-q2-update-linux.tar.bz2 -C /opt
+ wget -q https://developer.arm.com/-/media/Files/downloads/gnu-rm/10-2020q4/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2
+ sudo tar xjf gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2 -C /opt
- name: Build bsp
run: |
- export RTT_EXEC_PATH=/opt/gcc-arm-none-eabi-6-2017-q2-update/bin
- /opt/gcc-arm-none-eabi-6-2017-q2-update/bin/arm-none-eabi-gcc --version
+ export RTT_EXEC_PATH=/opt/gcc-arm-none-eabi-10-2020-q4-major/bin
+ /opt/gcc-arm-none-eabi-10-2020-q4-major/bin/arm-none-eabi-gcc --version
cp $TEST_CONFIG_FILE $TEST_BSP_ROOT/rtconfig.h
scons -j$(nproc) -C $TEST_BSP_ROOT
- name: Start test
diff --git a/bsp/ft2004/.config b/bsp/ft2004/.config
new file mode 100644
index 0000000000..1bd8c76ede
--- /dev/null
+++ b/bsp/ft2004/.config
@@ -0,0 +1,725 @@
+#
+# Automatically generated file; DO NOT EDIT.
+# RT-Thread Project Configuration
+#
+
+#
+# RT-Thread Kernel
+#
+CONFIG_RT_NAME_MAX=32
+# CONFIG_RT_USING_ARCH_DATA_TYPE is not set
+CONFIG_RT_USING_SMP=y
+CONFIG_RT_CPUS_NR=4
+CONFIG_RT_ALIGN_SIZE=128
+# CONFIG_RT_THREAD_PRIORITY_8 is not set
+CONFIG_RT_THREAD_PRIORITY_32=y
+# CONFIG_RT_THREAD_PRIORITY_256 is not set
+CONFIG_RT_THREAD_PRIORITY_MAX=32
+CONFIG_RT_TICK_PER_SECOND=100
+CONFIG_RT_USING_OVERFLOW_CHECK=y
+CONFIG_RT_USING_HOOK=y
+CONFIG_RT_USING_IDLE_HOOK=y
+CONFIG_RT_IDLE_HOOK_LIST_SIZE=4
+CONFIG_IDLE_THREAD_STACK_SIZE=4096
+CONFIG_RT_USING_TIMER_SOFT=y
+CONFIG_RT_TIMER_THREAD_PRIO=4
+CONFIG_RT_TIMER_THREAD_STACK_SIZE=512
+
+#
+# kservice optimization
+#
+# CONFIG_RT_KSERVICE_USING_STDLIB is not set
+# CONFIG_RT_KSERVICE_USING_TINY_SIZE is not set
+CONFIG_RT_DEBUG=y
+CONFIG_RT_DEBUG_COLOR=y
+# CONFIG_RT_DEBUG_INIT_CONFIG is not set
+# CONFIG_RT_DEBUG_THREAD_CONFIG is not set
+# CONFIG_RT_DEBUG_SCHEDULER_CONFIG is not set
+# CONFIG_RT_DEBUG_IPC_CONFIG is not set
+# CONFIG_RT_DEBUG_TIMER_CONFIG is not set
+# CONFIG_RT_DEBUG_IRQ_CONFIG is not set
+# CONFIG_RT_DEBUG_MEM_CONFIG is not set
+# CONFIG_RT_DEBUG_SLAB_CONFIG is not set
+# CONFIG_RT_DEBUG_MEMHEAP_CONFIG is not set
+# CONFIG_RT_DEBUG_MODULE_CONFIG is not set
+
+#
+# Inter-Thread communication
+#
+CONFIG_RT_USING_SEMAPHORE=y
+CONFIG_RT_USING_MUTEX=y
+CONFIG_RT_USING_EVENT=y
+CONFIG_RT_USING_MAILBOX=y
+CONFIG_RT_USING_MESSAGEQUEUE=y
+# CONFIG_RT_USING_SIGNALS is not set
+
+#
+# Memory Management
+#
+# CONFIG_RT_USING_MEMPOOL is not set
+CONFIG_RT_USING_MEMHEAP=y
+# CONFIG_RT_USING_NOHEAP is not set
+# CONFIG_RT_USING_SMALL_MEM is not set
+CONFIG_RT_USING_SLAB=y
+# CONFIG_RT_USING_MEMHEAP_AS_HEAP is not set
+# CONFIG_RT_USING_USERHEAP is not set
+# CONFIG_RT_USING_MEMTRACE is not set
+CONFIG_RT_USING_HEAP=y
+
+#
+# Kernel Device Object
+#
+CONFIG_RT_USING_DEVICE=y
+# CONFIG_RT_USING_DEVICE_OPS is not set
+CONFIG_RT_USING_INTERRUPT_INFO=y
+CONFIG_RT_USING_CONSOLE=y
+CONFIG_RT_CONSOLEBUF_SIZE=4096
+CONFIG_RT_CONSOLE_DEVICE_NAME="uart1"
+CONFIG_RT_VER_NUM=0x40004
+CONFIG_ARCH_ARM=y
+CONFIG_RT_USING_CPU_FFS=y
+CONFIG_ARCH_ARM_CORTEX_A=y
+# CONFIG_RT_SMP_AUTO_BOOT is not set
+# CONFIG_RT_USING_GIC_V2 is not set
+CONFIG_RT_USING_GIC_V3=y
+# CONFIG_ARCH_CPU_STACK_GROWS_UPWARD is not set
+
+#
+# RT-Thread Components
+#
+CONFIG_RT_USING_COMPONENTS_INIT=y
+CONFIG_RT_USING_USER_MAIN=y
+CONFIG_RT_MAIN_THREAD_STACK_SIZE=2048
+CONFIG_RT_MAIN_THREAD_PRIORITY=10
+
+#
+# C++ features
+#
+# CONFIG_RT_USING_CPLUSPLUS is not set
+
+#
+# Command shell
+#
+CONFIG_RT_USING_FINSH=y
+CONFIG_FINSH_THREAD_NAME="tshell"
+CONFIG_FINSH_USING_HISTORY=y
+CONFIG_FINSH_HISTORY_LINES=5
+CONFIG_FINSH_USING_SYMTAB=y
+CONFIG_FINSH_USING_DESCRIPTION=y
+# CONFIG_FINSH_ECHO_DISABLE_DEFAULT is not set
+CONFIG_FINSH_THREAD_PRIORITY=20
+CONFIG_FINSH_THREAD_STACK_SIZE=4096
+CONFIG_FINSH_CMD_SIZE=128
+# CONFIG_FINSH_USING_AUTH is not set
+CONFIG_FINSH_USING_MSH=y
+CONFIG_FINSH_USING_MSH_DEFAULT=y
+# CONFIG_FINSH_USING_MSH_ONLY is not set
+CONFIG_FINSH_ARG_MAX=10
+
+#
+# Device virtual file system
+#
+CONFIG_RT_USING_DFS=y
+CONFIG_DFS_USING_WORKDIR=y
+CONFIG_DFS_FILESYSTEMS_MAX=2
+CONFIG_DFS_FILESYSTEM_TYPES_MAX=2
+CONFIG_DFS_FD_MAX=16
+# CONFIG_RT_USING_DFS_MNTTABLE 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_USING_DFS_DEVFS=y
+# CONFIG_RT_USING_DFS_ROMFS is not set
+# CONFIG_RT_USING_DFS_RAMFS is not set
+# CONFIG_RT_USING_DFS_NFS is not set
+
+#
+# Device Drivers
+#
+CONFIG_RT_USING_DEVICE_IPC=y
+CONFIG_RT_PIPE_BUFSZ=512
+# CONFIG_RT_USING_SYSTEM_WORKQUEUE is not set
+CONFIG_RT_USING_SERIAL=y
+CONFIG_RT_SERIAL_USING_DMA=y
+CONFIG_RT_SERIAL_RB_BUFSZ=256
+CONFIG_RT_USING_CAN=y
+# CONFIG_RT_CAN_USING_HDR is not set
+# CONFIG_RT_USING_HWTIMER is not set
+# CONFIG_RT_USING_CPUTIME is not set
+# CONFIG_RT_USING_I2C is not set
+# CONFIG_RT_USING_PHY is not set
+# CONFIG_RT_USING_PIN is not set
+# CONFIG_RT_USING_ADC is not set
+# CONFIG_RT_USING_DAC is not set
+# CONFIG_RT_USING_PWM is not set
+# CONFIG_RT_USING_MTD_NOR is not set
+# CONFIG_RT_USING_MTD_NAND is not set
+# CONFIG_RT_USING_PM is not set
+# CONFIG_RT_USING_RTC is not set
+CONFIG_RT_USING_SDIO=y
+CONFIG_RT_SDIO_STACK_SIZE=512
+CONFIG_RT_SDIO_THREAD_PRIORITY=15
+CONFIG_RT_MMCSD_STACK_SIZE=1024
+CONFIG_RT_MMCSD_THREAD_PREORITY=22
+CONFIG_RT_MMCSD_MAX_PARTITION=16
+# CONFIG_RT_SDIO_DEBUG is not set
+CONFIG_RT_USING_SPI=y
+CONFIG_RT_USING_QSPI=y
+# CONFIG_RT_USING_SPI_MSD is not set
+CONFIG_RT_USING_SFUD=y
+CONFIG_RT_SFUD_USING_SFDP=y
+CONFIG_RT_SFUD_USING_FLASH_INFO_TABLE=y
+CONFIG_RT_SFUD_USING_QSPI=y
+CONFIG_RT_SFUD_SPI_MAX_HZ=50000000
+# CONFIG_RT_DEBUG_SFUD is not set
+# CONFIG_RT_USING_ENC28J60 is not set
+# CONFIG_RT_USING_SPI_WIFI is not set
+# CONFIG_RT_USING_WDT is not set
+# CONFIG_RT_USING_AUDIO is not set
+# CONFIG_RT_USING_SENSOR is not set
+# CONFIG_RT_USING_TOUCH is not set
+# CONFIG_RT_USING_HWCRYPTO is not set
+# CONFIG_RT_USING_PULSE_ENCODER is not set
+# CONFIG_RT_USING_INPUT_CAPTURE is not set
+# CONFIG_RT_USING_WIFI is not set
+
+#
+# Using USB
+#
+# CONFIG_RT_USING_USB_HOST is not set
+# CONFIG_RT_USING_USB_DEVICE is not set
+
+#
+# POSIX layer and C standard library
+#
+CONFIG_RT_USING_LIBC=y
+# CONFIG_RT_USING_PTHREADS is not set
+CONFIG_RT_USING_POSIX=y
+# CONFIG_RT_USING_POSIX_MMAP is not set
+# CONFIG_RT_USING_POSIX_TERMIOS is not set
+# CONFIG_RT_USING_POSIX_GETLINE is not set
+# CONFIG_RT_USING_POSIX_AIO is not set
+# CONFIG_RT_USING_MODULE is not set
+CONFIG_RT_LIBC_FIXED_TIMEZONE=8
+
+#
+# Network
+#
+
+#
+# Socket abstraction layer
+#
+# CONFIG_RT_USING_SAL is not set
+
+#
+# Network interface device
+#
+CONFIG_RT_USING_NETDEV=y
+CONFIG_NETDEV_USING_IFCONFIG=y
+CONFIG_NETDEV_USING_PING=y
+CONFIG_NETDEV_USING_NETSTAT=y
+CONFIG_NETDEV_USING_AUTO_DEFAULT=y
+# CONFIG_NETDEV_USING_IPV6 is not set
+CONFIG_NETDEV_IPV4=1
+CONFIG_NETDEV_IPV6=0
+# CONFIG_NETDEV_IPV6_SCOPES is not set
+
+#
+# light weight TCP/IP stack
+#
+CONFIG_RT_USING_LWIP=y
+# CONFIG_RT_USING_LWIP141 is not set
+# CONFIG_RT_USING_LWIP202 is not set
+CONFIG_RT_USING_LWIP212=y
+# CONFIG_RT_USING_LWIP_IPV6 is not set
+CONFIG_RT_LWIP_MEM_ALIGNMENT=4
+CONFIG_RT_LWIP_IGMP=y
+CONFIG_RT_LWIP_ICMP=y
+# CONFIG_RT_LWIP_SNMP is not set
+CONFIG_RT_LWIP_DNS=y
+# CONFIG_RT_LWIP_DHCP is not set
+
+#
+# Static IPv4 Address
+#
+CONFIG_RT_LWIP_IPADDR="192.168.3.20"
+CONFIG_RT_LWIP_GWADDR="192.168.3.1"
+CONFIG_RT_LWIP_MSKADDR="255.255.255.0"
+CONFIG_RT_LWIP_UDP=y
+CONFIG_RT_LWIP_TCP=y
+CONFIG_RT_LWIP_RAW=y
+# CONFIG_RT_LWIP_PPP is not set
+CONFIG_RT_MEMP_NUM_NETCONN=8
+CONFIG_RT_LWIP_PBUF_NUM=16
+CONFIG_RT_LWIP_RAW_PCB_NUM=4
+CONFIG_RT_LWIP_UDP_PCB_NUM=4
+CONFIG_RT_LWIP_TCP_PCB_NUM=4
+CONFIG_RT_LWIP_TCP_SEG_NUM=40
+CONFIG_RT_LWIP_TCP_SND_BUF=8196
+CONFIG_RT_LWIP_TCP_WND=8196
+CONFIG_RT_LWIP_TCPTHREAD_PRIORITY=10
+CONFIG_RT_LWIP_TCPTHREAD_MBOX_SIZE=8
+CONFIG_RT_LWIP_TCPTHREAD_STACKSIZE=1024
+# CONFIG_LWIP_NO_RX_THREAD is not set
+# CONFIG_LWIP_NO_TX_THREAD is not set
+CONFIG_RT_LWIP_ETHTHREAD_PRIORITY=12
+CONFIG_RT_LWIP_ETHTHREAD_STACKSIZE=1024
+CONFIG_RT_LWIP_ETHTHREAD_MBOX_SIZE=8
+# CONFIG_RT_LWIP_REASSEMBLY_FRAG is not set
+CONFIG_LWIP_NETIF_STATUS_CALLBACK=1
+CONFIG_LWIP_NETIF_LINK_CALLBACK=1
+CONFIG_SO_REUSE=1
+CONFIG_LWIP_SO_RCVTIMEO=1
+CONFIG_LWIP_SO_SNDTIMEO=1
+CONFIG_LWIP_SO_RCVBUF=1
+CONFIG_LWIP_SO_LINGER=0
+# CONFIG_RT_LWIP_NETIF_LOOPBACK is not set
+CONFIG_LWIP_NETIF_LOOPBACK=0
+# CONFIG_RT_LWIP_STATS is not set
+# CONFIG_RT_LWIP_USING_HW_CHECKSUM is not set
+CONFIG_RT_LWIP_USING_PING=y
+# CONFIG_RT_LWIP_DEBUG is not set
+
+#
+# AT commands
+#
+# CONFIG_RT_USING_AT is not set
+# CONFIG_LWIP_USING_DHCPD is not set
+
+#
+# VBUS(Virtual Software BUS)
+#
+# CONFIG_RT_USING_VBUS is not set
+
+#
+# Utilities
+#
+# CONFIG_RT_USING_RYM is not set
+CONFIG_RT_USING_ULOG=y
+# CONFIG_ULOG_OUTPUT_LVL_A is not set
+# CONFIG_ULOG_OUTPUT_LVL_E is not set
+CONFIG_ULOG_OUTPUT_LVL_W=y
+# CONFIG_ULOG_OUTPUT_LVL_I is not set
+# CONFIG_ULOG_OUTPUT_LVL_D is not set
+CONFIG_ULOG_OUTPUT_LVL=4
+# CONFIG_ULOG_USING_ISR_LOG is not set
+CONFIG_ULOG_ASSERT_ENABLE=y
+CONFIG_ULOG_LINE_BUF_SIZE=128
+# CONFIG_ULOG_USING_ASYNC_OUTPUT is not set
+
+#
+# log format
+#
+# CONFIG_ULOG_OUTPUT_FLOAT is not set
+CONFIG_ULOG_USING_COLOR=y
+CONFIG_ULOG_OUTPUT_TIME=y
+# CONFIG_ULOG_TIME_USING_TIMESTAMP is not set
+CONFIG_ULOG_OUTPUT_LEVEL=y
+CONFIG_ULOG_OUTPUT_TAG=y
+# CONFIG_ULOG_OUTPUT_THREAD_NAME is not set
+CONFIG_ULOG_BACKEND_USING_CONSOLE=y
+# CONFIG_ULOG_USING_FILTER is not set
+# CONFIG_ULOG_USING_SYSLOG is not set
+# CONFIG_RT_USING_UTEST is not set
+# CONFIG_RT_USING_RT_LINK is not set
+# CONFIG_RT_USING_LWP is not set
+
+#
+# RT-Thread Utestcases
+#
+# CONFIG_RT_USING_UTESTCASES is not set
+
+#
+# RT-Thread online packages
+#
+
+#
+# IoT - internet of things
+#
+# CONFIG_PKG_USING_LORAWAN_DRIVER is not set
+# CONFIG_PKG_USING_PAHOMQTT is not set
+# CONFIG_PKG_USING_UMQTT is not set
+# CONFIG_PKG_USING_WEBCLIENT is not set
+# CONFIG_PKG_USING_WEBNET is not set
+# CONFIG_PKG_USING_MONGOOSE is not set
+# CONFIG_PKG_USING_MYMQTT is not set
+# CONFIG_PKG_USING_KAWAII_MQTT is not set
+# CONFIG_PKG_USING_BC28_MQTT is not set
+# CONFIG_PKG_USING_WEBTERMINAL is not set
+# CONFIG_PKG_USING_CJSON is not set
+# CONFIG_PKG_USING_JSMN is not set
+# CONFIG_PKG_USING_LIBMODBUS is not set
+# CONFIG_PKG_USING_FREEMODBUS is not set
+# CONFIG_PKG_USING_LJSON is not set
+# CONFIG_PKG_USING_EZXML is not set
+# CONFIG_PKG_USING_NANOPB is not set
+
+#
+# Wi-Fi
+#
+
+#
+# Marvell WiFi
+#
+# CONFIG_PKG_USING_WLANMARVELL is not set
+
+#
+# Wiced WiFi
+#
+# CONFIG_PKG_USING_WLAN_WICED is not set
+# CONFIG_PKG_USING_RW007 is not set
+# CONFIG_PKG_USING_COAP is not set
+# CONFIG_PKG_USING_NOPOLL is not set
+# CONFIG_PKG_USING_NETUTILS is not set
+# CONFIG_PKG_USING_CMUX is not set
+# CONFIG_PKG_USING_PPP_DEVICE is not set
+# CONFIG_PKG_USING_AT_DEVICE is not set
+# CONFIG_PKG_USING_ATSRV_SOCKET is not set
+# CONFIG_PKG_USING_WIZNET is not set
+
+#
+# IoT Cloud
+#
+# CONFIG_PKG_USING_ONENET is not set
+# CONFIG_PKG_USING_GAGENT_CLOUD is not set
+# CONFIG_PKG_USING_ALI_IOTKIT is not set
+# CONFIG_PKG_USING_AZURE is not set
+# CONFIG_PKG_USING_TENCENT_IOT_EXPLORER is not set
+# CONFIG_PKG_USING_JIOT-C-SDK is not set
+# CONFIG_PKG_USING_UCLOUD_IOT_SDK is not set
+# CONFIG_PKG_USING_JOYLINK is not set
+# CONFIG_PKG_USING_NIMBLE is not set
+# CONFIG_PKG_USING_OTA_DOWNLOADER is not set
+# CONFIG_PKG_USING_IPMSG is not set
+# CONFIG_PKG_USING_LSSDP is not set
+# CONFIG_PKG_USING_AIRKISS_OPEN is not set
+# CONFIG_PKG_USING_LIBRWS is not set
+# CONFIG_PKG_USING_TCPSERVER is not set
+# CONFIG_PKG_USING_PROTOBUF_C is not set
+# CONFIG_PKG_USING_DLT645 is not set
+# CONFIG_PKG_USING_QXWZ is not set
+# CONFIG_PKG_USING_SMTP_CLIENT is not set
+# CONFIG_PKG_USING_ABUP_FOTA is not set
+# CONFIG_PKG_USING_LIBCURL2RTT is not set
+# CONFIG_PKG_USING_CAPNP is not set
+# CONFIG_PKG_USING_RT_CJSON_TOOLS is not set
+# CONFIG_PKG_USING_AGILE_TELNET is not set
+# CONFIG_PKG_USING_NMEALIB is not set
+# CONFIG_PKG_USING_AGILE_JSMN is not set
+# CONFIG_PKG_USING_PDULIB is not set
+# CONFIG_PKG_USING_BTSTACK is not set
+# CONFIG_PKG_USING_LORAWAN_ED_STACK is not set
+# CONFIG_PKG_USING_WAYZ_IOTKIT is not set
+# CONFIG_PKG_USING_MAVLINK is not set
+# CONFIG_PKG_USING_RAPIDJSON is not set
+# CONFIG_PKG_USING_BSAL is not set
+# CONFIG_PKG_USING_AGILE_MODBUS is not set
+# CONFIG_PKG_USING_AGILE_FTP is not set
+# CONFIG_PKG_USING_EMBEDDEDPROTO is not set
+
+#
+# security packages
+#
+# CONFIG_PKG_USING_MBEDTLS is not set
+# CONFIG_PKG_USING_libsodium is not set
+# CONFIG_PKG_USING_TINYCRYPT is not set
+# CONFIG_PKG_USING_TFM is not set
+# CONFIG_PKG_USING_YD_CRYPTO is not set
+
+#
+# language packages
+#
+# CONFIG_PKG_USING_LUA is not set
+# CONFIG_PKG_USING_JERRYSCRIPT is not set
+# CONFIG_PKG_USING_MICROPYTHON is not set
+
+#
+# multimedia packages
+#
+# CONFIG_PKG_USING_OPENMV is not set
+# CONFIG_PKG_USING_MUPDF is not set
+# CONFIG_PKG_USING_STEMWIN is not set
+# CONFIG_PKG_USING_WAVPLAYER is not set
+# CONFIG_PKG_USING_TJPGD is not set
+# CONFIG_PKG_USING_PDFGEN is not set
+# CONFIG_PKG_USING_HELIX is not set
+# CONFIG_PKG_USING_AZUREGUIX is not set
+# CONFIG_PKG_USING_TOUCHGFX2RTT is not set
+# CONFIG_PKG_USING_NUEMWIN is not set
+
+#
+# tools packages
+#
+# CONFIG_PKG_USING_CMBACKTRACE is not set
+# CONFIG_PKG_USING_EASYFLASH is not set
+# CONFIG_PKG_USING_EASYLOGGER is not set
+# CONFIG_PKG_USING_SYSTEMVIEW is not set
+# CONFIG_PKG_USING_SEGGER_RTT is not set
+# CONFIG_PKG_USING_RDB is not set
+# CONFIG_PKG_USING_QRCODE is not set
+# CONFIG_PKG_USING_ULOG_EASYFLASH is not set
+# CONFIG_PKG_USING_ULOG_FILE is not set
+# CONFIG_PKG_USING_LOGMGR is not set
+# CONFIG_PKG_USING_ADBD is not set
+# CONFIG_PKG_USING_COREMARK is not set
+# CONFIG_PKG_USING_DHRYSTONE is not set
+# CONFIG_PKG_USING_MEMORYPERF is not set
+# CONFIG_PKG_USING_NR_MICRO_SHELL is not set
+# CONFIG_PKG_USING_CHINESE_FONT_LIBRARY is not set
+# CONFIG_PKG_USING_LUNAR_CALENDAR is not set
+# CONFIG_PKG_USING_BS8116A is not set
+# CONFIG_PKG_USING_GPS_RMC is not set
+# CONFIG_PKG_USING_URLENCODE is not set
+# CONFIG_PKG_USING_UMCN is not set
+# CONFIG_PKG_USING_LWRB2RTT is not set
+# CONFIG_PKG_USING_CPU_USAGE is not set
+# CONFIG_PKG_USING_GBK2UTF8 is not set
+# CONFIG_PKG_USING_VCONSOLE is not set
+# CONFIG_PKG_USING_KDB is not set
+# CONFIG_PKG_USING_WAMR is not set
+# CONFIG_PKG_USING_MICRO_XRCE_DDS_CLIENT is not set
+# CONFIG_PKG_USING_LWLOG is not set
+# CONFIG_PKG_USING_ANV_TRACE is not set
+# CONFIG_PKG_USING_ANV_MEMLEAK is not set
+# CONFIG_PKG_USING_ANV_TESTSUIT is not set
+# CONFIG_PKG_USING_ANV_BENCH is not set
+# CONFIG_PKG_USING_DEVMEM is not set
+# CONFIG_PKG_USING_REGEX is not set
+# CONFIG_PKG_USING_MEM_SANDBOX is not set
+# CONFIG_PKG_USING_SOLAR_TERMS is not set
+# CONFIG_PKG_USING_GAN_ZHI is not set
+
+#
+# system packages
+#
+
+#
+# acceleration: Assembly language or algorithmic acceleration packages
+#
+# CONFIG_PKG_USING_RT_MEMCPY_CM is not set
+# CONFIG_PKG_USING_QFPLIB_M0_FULL is not set
+# CONFIG_PKG_USING_QFPLIB_M0_TINY is not set
+# CONFIG_PKG_USING_QFPLIB_M3 is not set
+
+#
+# Micrium: Micrium software products porting for RT-Thread
+#
+# CONFIG_PKG_USING_UCOSIII_WRAPPER is not set
+# CONFIG_PKG_USING_UCOSII_WRAPPER is not set
+# CONFIG_PKG_USING_UC_CRC is not set
+# CONFIG_PKG_USING_UC_CLK is not set
+# CONFIG_PKG_USING_UC_COMMON is not set
+# CONFIG_PKG_USING_UC_MODBUS is not set
+# CONFIG_PKG_USING_GUIENGINE is not set
+# CONFIG_PKG_USING_PERSIMMON is not set
+# CONFIG_PKG_USING_CAIRO is not set
+# CONFIG_PKG_USING_PIXMAN is not set
+# CONFIG_PKG_USING_PARTITION is not set
+# CONFIG_PKG_USING_FAL is not set
+# CONFIG_PKG_USING_FLASHDB is not set
+# CONFIG_PKG_USING_SQLITE is not set
+# CONFIG_PKG_USING_RTI is not set
+# CONFIG_PKG_USING_LITTLEVGL2RTT is not set
+# CONFIG_PKG_USING_CMSIS is not set
+# CONFIG_PKG_USING_DFS_YAFFS is not set
+# CONFIG_PKG_USING_LITTLEFS is not set
+# CONFIG_PKG_USING_DFS_JFFS2 is not set
+# CONFIG_PKG_USING_DFS_UFFS is not set
+# CONFIG_PKG_USING_LWEXT4 is not set
+# CONFIG_PKG_USING_THREAD_POOL is not set
+# CONFIG_PKG_USING_ROBOTS is not set
+# CONFIG_PKG_USING_EV is not set
+# CONFIG_PKG_USING_SYSWATCH is not set
+# CONFIG_PKG_USING_SYS_LOAD_MONITOR is not set
+# CONFIG_PKG_USING_PLCCORE is not set
+# CONFIG_PKG_USING_RAMDISK is not set
+# CONFIG_PKG_USING_MININI is not set
+# CONFIG_PKG_USING_QBOOT is not set
+# CONFIG_PKG_USING_PPOOL is not set
+# CONFIG_PKG_USING_OPENAMP is not set
+# CONFIG_PKG_USING_RT_KPRINTF_THREADSAFE is not set
+# CONFIG_PKG_USING_LPM is not set
+# CONFIG_PKG_USING_TLSF is not set
+# CONFIG_PKG_USING_EVENT_RECORDER is not set
+
+#
+# peripheral libraries and drivers
+#
+# CONFIG_PKG_USING_SENSORS_DRIVERS is not set
+# CONFIG_PKG_USING_REALTEK_AMEBA is not set
+# CONFIG_PKG_USING_SHT2X is not set
+# CONFIG_PKG_USING_SHT3X is not set
+# CONFIG_PKG_USING_AS7341 is not set
+# CONFIG_PKG_USING_STM32_SDIO is not set
+# CONFIG_PKG_USING_ICM20608 is not set
+# CONFIG_PKG_USING_U8G2 is not set
+# CONFIG_PKG_USING_BUTTON is not set
+# CONFIG_PKG_USING_PCF8574 is not set
+# CONFIG_PKG_USING_SX12XX is not set
+# CONFIG_PKG_USING_SIGNAL_LED is not set
+# 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
+# CONFIG_PKG_USING_WM_LIBRARIES is not set
+# CONFIG_PKG_USING_KENDRYTE_SDK is not set
+# CONFIG_PKG_USING_INFRARED is not set
+# CONFIG_PKG_USING_ROSSERIAL is not set
+# CONFIG_PKG_USING_AGILE_BUTTON is not set
+# CONFIG_PKG_USING_AGILE_LED is not set
+# CONFIG_PKG_USING_AT24CXX is not set
+# CONFIG_PKG_USING_MOTIONDRIVER2RTT is not set
+# CONFIG_PKG_USING_AD7746 is not set
+# CONFIG_PKG_USING_PCA9685 is not set
+# CONFIG_PKG_USING_I2C_TOOLS is not set
+# CONFIG_PKG_USING_NRF24L01 is not set
+# CONFIG_PKG_USING_TOUCH_DRIVERS is not set
+# CONFIG_PKG_USING_MAX17048 is not set
+# CONFIG_PKG_USING_RPLIDAR is not set
+# 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_CAN_YMODEM is not set
+# CONFIG_PKG_USING_LORA_RADIO_DRIVER is not set
+# CONFIG_PKG_USING_QLED is not set
+# CONFIG_PKG_USING_PAJ7620 is not set
+# CONFIG_PKG_USING_AGILE_CONSOLE is not set
+# CONFIG_PKG_USING_LD3320 is not set
+# CONFIG_PKG_USING_WK2124 is not set
+# CONFIG_PKG_USING_LY68L6400 is not set
+# CONFIG_PKG_USING_DM9051 is not set
+# CONFIG_PKG_USING_SSD1306 is not set
+# CONFIG_PKG_USING_QKEY is not set
+# CONFIG_PKG_USING_RS485 is not set
+# CONFIG_PKG_USING_NES is not set
+# CONFIG_PKG_USING_VIRTUAL_SENSOR is not set
+# CONFIG_PKG_USING_VDEVICE is not set
+# CONFIG_PKG_USING_SGM706 is not set
+# CONFIG_PKG_USING_STM32WB55_SDK is not set
+# CONFIG_PKG_USING_RDA58XX is not set
+# CONFIG_PKG_USING_LIBNFC is not set
+# CONFIG_PKG_USING_MFOC is not set
+# CONFIG_PKG_USING_TMC51XX is not set
+# CONFIG_PKG_USING_TCA9534 is not set
+
+#
+# AI packages
+#
+# CONFIG_PKG_USING_LIBANN is not set
+# CONFIG_PKG_USING_NNOM is not set
+# CONFIG_PKG_USING_ONNX_BACKEND is not set
+# CONFIG_PKG_USING_ONNX_PARSER is not set
+# CONFIG_PKG_USING_TENSORFLOWLITEMICRO is not set
+# CONFIG_PKG_USING_ELAPACK is not set
+# CONFIG_PKG_USING_ULAPACK is not set
+# CONFIG_PKG_USING_QUEST is not set
+# CONFIG_PKG_USING_NAXOS is not set
+
+#
+# miscellaneous packages
+#
+# CONFIG_PKG_USING_LIBCSV is not set
+# CONFIG_PKG_USING_OPTPARSE is not set
+# CONFIG_PKG_USING_FASTLZ is not set
+# CONFIG_PKG_USING_MINILZO is not set
+# CONFIG_PKG_USING_QUICKLZ is not set
+# CONFIG_PKG_USING_LZMA is not set
+# CONFIG_PKG_USING_MULTIBUTTON is not set
+# CONFIG_PKG_USING_FLEXIBLE_BUTTON is not set
+# CONFIG_PKG_USING_CANFESTIVAL is not set
+# CONFIG_PKG_USING_ZLIB is not set
+# CONFIG_PKG_USING_MINIZIP is not set
+# CONFIG_PKG_USING_DSTR is not set
+# CONFIG_PKG_USING_TINYFRAME is not set
+# CONFIG_PKG_USING_KENDRYTE_DEMO is not set
+# CONFIG_PKG_USING_DIGITALCTRL is not set
+# CONFIG_PKG_USING_UPACKER is not set
+# CONFIG_PKG_USING_UPARAM is not set
+
+#
+# samples: kernel and components samples
+#
+# CONFIG_PKG_USING_KERNEL_SAMPLES is not set
+# CONFIG_PKG_USING_FILESYSTEM_SAMPLES is not set
+# CONFIG_PKG_USING_NETWORK_SAMPLES is not set
+# CONFIG_PKG_USING_PERIPHERAL_SAMPLES is not set
+# CONFIG_PKG_USING_HELLO is not set
+# CONFIG_PKG_USING_VI is not set
+# CONFIG_PKG_USING_KI is not set
+# CONFIG_PKG_USING_ARMv7M_DWT is not set
+# CONFIG_PKG_USING_VT100 is not set
+# CONFIG_PKG_USING_UKAL is not set
+# CONFIG_PKG_USING_CRCLIB is not set
+
+#
+# entertainment: terminal games and other interesting software packages
+#
+# CONFIG_PKG_USING_THREES is not set
+# CONFIG_PKG_USING_2048 is not set
+# CONFIG_PKG_USING_SNAKE is not set
+# CONFIG_PKG_USING_TETRIS is not set
+# CONFIG_PKG_USING_DONUT is not set
+# CONFIG_PKG_USING_ACLOCK is not set
+# CONFIG_PKG_USING_LWGPS is not set
+# CONFIG_PKG_USING_STATE_MACHINE is not set
+# CONFIG_PKG_USING_MCURSES is not set
+# CONFIG_PKG_USING_COWSAY is not set
+CONFIG_FT2004=y
+
+#
+# Hardware Drivers Config
+#
+
+#
+# On-chip Peripheral Drivers
+#
+CONFIG_BSP_USING_UART=y
+CONFIG_RT_USING_UART1=y
+# CONFIG_RT_USING_UART0 is not set
+CONFIG_BSP_USING_SDC=y
+# CONFIG_BSP_SDC_DEBUG_PRINT is not set
+# CONFIG_BSP_SDC_USE_IRQ is not set
+CONFIG_BSP_USING_GMAC=y
+# CONFIG_BSP_USING_GMAC0 is not set
+CONFIG_BSP_USING_GMAC1=y
+CONFIG_RT_LWIP_ETH_PAD_SIZE=2
+# CONFIG_RAW_DATA_PRINT is not set
+CONFIG_BSP_USE_SPI=y
+# CONFIG_BSP_SPI_DEBUG is not set
+CONFIG_BSP_USE_GPIO=y
+# CONFIG_BSP_GPIO_DEBUG is not set
+CONFIG_BSP_USE_CAN=y
+CONFIG_BSP_USING_CAN0=y
+# CONFIG_BSP_USING_CAN1 is not set
+# CONFIG_BSP_USING_CAN0_DEBUG is not set
+
+#
+# Board extended module Drivers
+#
diff --git a/bsp/ft2004/Kconfig b/bsp/ft2004/Kconfig
new file mode 100644
index 0000000000..6470d41804
--- /dev/null
+++ b/bsp/ft2004/Kconfig
@@ -0,0 +1,31 @@
+mainmenu "RT-Thread Project Configuration"
+
+config BSP_DIR
+ string
+ option env="BSP_ROOT"
+ default "."
+
+config RTT_DIR
+ string
+ option env="RTT_ROOT"
+ default "../.."
+
+config PKGS_DIR
+ string
+ option env="PKGS_ROOT"
+ default "packages"
+
+source "$RTT_DIR/Kconfig"
+source "$PKGS_DIR/Kconfig"
+
+
+config FT2004
+ bool
+ select ARCH_ARM_CORTEX_A
+ select RT_USING_COMPONENTS_INIT
+ select RT_USING_USER_MAIN
+ select RT_USING_GIC_V3
+ default y
+
+
+source "./libraries/Kconfig"
diff --git a/bsp/ft2004/README.md b/bsp/ft2004/README.md
new file mode 100644
index 0000000000..e39a505b5d
--- /dev/null
+++ b/bsp/ft2004/README.md
@@ -0,0 +1,236 @@
+# ft2004 四核开发板 BSP 说明
+
+## 简介
+
+本文档为 飞腾技术公司 ft2000/4 开发板的 BSP (板级支持包) 说明。
+
+主要内容如下:
+
+- 开发板资源介绍
+- BSP 外设支持
+- 使用方法
+- 相关实验
+
+### 1. 开发板资源介绍
+
+FT-2000/4 是一款面向桌面应用的高性能通用 4 核处理器。每 2 个核构成 1
+个处理器核簇(Cluster),并共享 L2 Cache。主要技术特征如下:
+
+- 兼容 ARM v8 64 位指令系统,兼容 32 位指令
+- 支持单精度、双精度浮点运算指令
+- 支持 ASIMD 处理指令
+- 集成 2 个 DDR4 通道,可对 DDR 存储数据进行实时加密
+- 集成 34 Lane PCIE3.0 接口:2 个 X16(每个可拆分成 2 个 X8),2 个 X1
+- 集成 2 个 GMAC,RGMII 接口,支持 10/100/1000 自适应
+- 集成 1 个 SD 卡控制器,兼容 SD 2.0 规范
+- 集成 1 个 HDAudio,支持音频输出,可同时支持最多 4 个 Codec
+- 集成 SM2、SM3、SM4 模块
+- 集成 4 个 UART,1 个 LPC,32 个 GPIO,4 个 I2C,1 个 QSPI,2 个通
+ 用 SPI,2 个 WDT,16 个外部中断(和 GPIO 共用 IO)
+- 集成温度传感器
+
+### 2. BSP 外设支持
+
+| 外设名 | 支持情况 | 备注 |
+| -------- | -------- | ---------------------- |
+| ft_gicv3 | 支持 | gicv3 中断控制器 |
+| ft_gmac | 支持 | ft gmac 千兆网卡控制器 |
+| ft_i2c | 支持 | FT I2C |
+| ft_qspi | 支持 | FT qspi 控制器 |
+| ft_sd | 支持 | FT mmcsd 控制器 |
+| ft_uart | 支持 | PrimeCell PL011 |
+| ft_spi | 支持 | FT spi 控制器 |
+| ft_gpio | 支持 | FT gpio 控制器 |
+| ft_can | 支持 | FT can 控制器 |
+
+### 3. 使用方法
+
+#### ubuntu 上环境搭建
+
+1. 在 ubuntu 环境下通过指令,下载并安装交叉编译链
+
+```
+sudo apt-get install gcc-arm-none-eabi
+```
+
+2. 安装之后,通过指令,确定交叉编译链安装完毕
+
+```
+arm-none-eabi-gcc -v
+```
+
+3. 搭建 tftp 环境
+
+ - 在主机安装 tftp 服务
+ > 使用 ubuntu 完成下列操作
+
+ ```
+ sudo apt-get install tftp-hpa tftpd-hpa
+ sudo apt-get install xinetd
+ ```
+
+ - 新建 tftboot 目录,如:
+ `/mnt/d/tftboot`
+
+ > 需要给 tftboot 目录执行权限`chmod 777 /**/tftboot`
+
+ - 配置主机 tftpboot 服务
+
+ 新建并配置文件/etc/xinetd.d/tftp
+
+ ```
+ # /etc/xinetd.d/tftp
+
+ server tftp
+ {
+ socket_type = dgram
+ protocol = udp
+ wait = yes
+ user = root
+ server = /usr/sbin/in.tftpd
+ server_args = -s /mnt/d/tftboot
+ disable = no
+ per_source = 11
+ cps = 100 2
+ flags = IPv4
+ }
+ ```
+
+ - 启动主机 tftp 服务
+
+ ```
+ sudo service tftpd-hpa start
+ ```
+
+ - 修改主机 tftp 配置
+ 修改/etc/default/tftpd-hpa
+
+ ```
+ sudo nano /etc/default/tftpd-hpa
+ # /etc/default/tftpd-hpa
+
+ TFTP_USERNAME="tftp"
+ TFTP_DIRECTORY="/mnt/d/tftboot"
+ TFTP_ADDRESS=":69"
+ TFTP_OPTIONS="-l -c -s"
+ ```
+
+ - 重启主机 tftp 服务
+ > 每次开机要重启一次
+
+ ```
+ sudo service tftpd-hpa restart
+ ```
+
+ - 测试主机 tftp 服务的可用性
+ > 登录 tftp 服务,获取一个文件
+
+ ```
+ $ tftp 192.168.4.50
+ tftp> get test1234
+ tftp> q
+ ```
+
+#### 执行
+
+1. 将本 bsp 包拷贝至 RT-THREAD bsp/目录下
+
+1. 在 Ubuntu 终端下,切换至 bsp 目录
+
+```
+cd rt-thread/bsp/ft2004
+```
+
+3. 使用 scons -c 清空工程缓存
+
+4. 使用 scons --menuconfig 配置需要的外设
+
+![](./figures/onchipPeripheral.png)
+
+5. 使用 scons 编译代码,得到 rtthread.bin,并将 rtthread.bin 放入之前配置的 tftp 路径下。
+
+6. 连接开发板对应串口到 PC, 在终端工具里打开相应的串口(115200-8-1-N)。
+
+7. 将开发板网线接入局域网中
+
+8. 本开发板自带 uboot,使用 uboot 自带 指令进行将 bin 文件下载至 ram 中
+
+```
+setenv ipaddr 192.168.x.x # 设置开发板ip
+setenv serverip 192.168.x.x # 设置tftp服务器ip
+setenv gatewayip 192.168.x.x # 设置网关ip
+tftpboot 80100000 rtthread.bin # 在主机 /tftpboot目录中的rtthread.bin文件下载到开发板内存的80100000地址中。
+```
+
+7. 执行跳转指令,便可以正常执行
+
+```
+bootvx32 80100000
+或
+boot32 80100000
+```
+
+![](./figures/启动演示图.png)
+
+### 5. 相关实验
+
+#### 网卡
+
+- 主机 ping 本机 指令 sudo ping 192.168.3.20 (默认)
+
+- rtt ping 主机 指令 ping 192.168.x.x (根据实际情况)
+
+- 通过界面
+
+![](./figures/rttPing通过界面.png)
+
+#### sd 卡调试
+
+- 通过基本命令进行,mv ,echo ,ls ,cd ,rm ....
+
+![](./figures/rttsd调试.png)
+
+#### spi flash 卡调试
+
+- 找一块有 spi flash 插槽的 ft-2004 开发板,插入 sf25s 或 gd25q 系列 spi flash
+- 配置 rt-thread 的编译选项,打开 BSP_USE_SPI 和 BSP_USE_GPIO 配置,关闭 BSP_USE_QSPI 配置,打开 rt-thread 的 SFUD 调试开关
+- 编译 rt-thread,加载版本启动,启动后显示 spi flash probe 成功
+- 执行 sf 基本操作,read, write, erase
+
+#### 推荐指令
+
+1. sf probe S25FS256
+
+2. sf read 0x1FFF000 16
+
+3. sf write 0x1FFF000 16 25 68 78 95 15 75 20
+
+4. sf read 0x1FFF000 16
+
+5. sf erase 0x1FFF000 16
+
+#### can 测试
+
+1. 使用 scons menuconfig 选中 Enable Can
+
+2. 然后选中 Enable can0 ,Enable can0 work in loop back
+
+3. 烧录程序并且烧录
+
+4. 打开 can 盒,将波特率设为 1000000
+
+5. 然后通过 can 盒发送对应的数据(标准帧,扩展帧),就可以看见回复同样的内容
+
+## 6. 参考资源
+
+- ARM Architecture Reference Manual
+
+- FT-2000/4 软件编程手册-V1.4
+
+## 7. 联系人信息
+
+请联系飞腾嵌入式软件部
+
+
diff --git a/bsp/ft2004/SConscript b/bsp/ft2004/SConscript
new file mode 100644
index 0000000000..fe0ae941ae
--- /dev/null
+++ b/bsp/ft2004/SConscript
@@ -0,0 +1,14 @@
+# for module compiling
+import os
+Import('RTT_ROOT')
+
+cwd = str(Dir('#'))
+objs = []
+list = os.listdir(cwd)
+
+for d in list:
+ path = os.path.join(cwd, d)
+ if os.path.isfile(os.path.join(path, 'SConscript')):
+ objs = objs + SConscript(os.path.join(d, 'SConscript'))
+
+Return('objs')
diff --git a/bsp/ft2004/SConstruct b/bsp/ft2004/SConstruct
new file mode 100644
index 0000000000..e3c1df26fa
--- /dev/null
+++ b/bsp/ft2004/SConstruct
@@ -0,0 +1,32 @@
+import os
+import sys
+import rtconfig
+
+if os.getenv('RTT_ROOT'):
+ RTT_ROOT = os.getenv('RTT_ROOT')
+else:
+ RTT_ROOT = os.path.join(os.getcwd(), '..', '..')
+
+sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
+from building import *
+
+TARGET = 'ft2004.' + rtconfig.TARGET_EXT
+
+DefaultEnvironment(tools=[])
+env = Environment(tools = ['mingw'],
+ AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS,
+ CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS,
+ CXX= rtconfig.CXX, CXXFLAGS = rtconfig.CFLAGS,
+ AR = rtconfig.AR, ARFLAGS = '-rc',
+ LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS)
+env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
+env['ASCOM'] = env['ASPPCOM']
+
+Export('RTT_ROOT')
+Export('rtconfig')
+
+# prepare building environment
+objs = PrepareBuilding(env, RTT_ROOT)
+
+# make a building
+DoBuilding(TARGET, objs)
diff --git a/bsp/ft2004/applications/SConscript b/bsp/ft2004/applications/SConscript
new file mode 100644
index 0000000000..a526af2c75
--- /dev/null
+++ b/bsp/ft2004/applications/SConscript
@@ -0,0 +1,11 @@
+Import('RTT_ROOT')
+Import('rtconfig')
+from building import *
+
+cwd = GetCurrentDir()
+src = Glob('*.c')
+CPPPATH = [cwd]
+
+group = DefineGroup('Applications', src, depend = [''], CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/bsp/ft2004/applications/main.c b/bsp/ft2004/applications/main.c
new file mode 100644
index 0000000000..95fad98370
--- /dev/null
+++ b/bsp/ft2004/applications/main.c
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2012-12-05 Bernard the first version
+ */
+
+#include <rthw.h>
+#include <rtthread.h>
+#include "ft_cpu.h"
+#include "ft_generic_timer.h"
+
+#include <board.h>
+
+#ifdef RT_USING_SMP
+
+struct rt_thread test_core[RT_CPUS_NR];
+static char *core_thread_name[RT_CPUS_NR] = {
+ "core0_test",
+ "core1_test",
+ "core2_test",
+ "core3_test"};
+static rt_uint8_t core_stack[RT_CPUS_NR][1024];
+
+static void demo_core_thread(void *parameter)
+{
+ rt_base_t level;
+ while (1)
+ {
+ /* code */
+ level = rt_cpus_lock();
+ rt_kprintf("Hi, core%d \r\n", FCpu_IdGet());
+ rt_cpus_unlock(level);
+ rt_thread_mdelay(20000);
+ }
+}
+
+void demo_core(void)
+{
+ rt_ubase_t i;
+ rt_uint8_t cpu_id = 0;
+ for (i = 0; i < RT_CPUS_NR; i++)
+ {
+ cpu_id = i;
+ rt_thread_init(&test_core[i],
+ core_thread_name[i],
+ demo_core_thread,
+ RT_NULL,
+ &core_stack[i],
+ 1024,
+ 20,
+ 32);
+
+ rt_thread_control(&test_core[i], RT_THREAD_CTRL_BIND_CPU, (void *)cpu_id);
+ rt_thread_startup(&test_core[i]);
+ }
+}
+#endif
+
+int main(void)
+{
+ int count = 1;
+
+#ifdef RT_USING_SMP
+ demo_core();
+#endif
+
+ while (count++)
+ {
+ rt_thread_mdelay(2000);
+ }
+
+ return RT_EOK;
+}
diff --git a/bsp/ft2004/drivers/SConscript b/bsp/ft2004/drivers/SConscript
new file mode 100644
index 0000000000..b18c98833e
--- /dev/null
+++ b/bsp/ft2004/drivers/SConscript
@@ -0,0 +1,14 @@
+
+from building import *
+
+cwd = GetCurrentDir()
+src = Glob('*.S')
+src += Glob('*.c')
+
+
+
+CPPPATH = [cwd]
+
+group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/bsp/ft2004/drivers/board.c b/bsp/ft2004/drivers/board.c
new file mode 100644
index 0000000000..408a58d344
--- /dev/null
+++ b/bsp/ft2004/drivers/board.c
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-03-04 Carl the first version
+ *
+ */
+
+#include <rtthread.h>
+#include "ft_printf.h"
+#include "ft_assert.h"
+#include "ft_cpu.h"
+#include "ft_psci.h"
+#include "ft_parameters.h"
+#include "board.h"
+#include "gtimer.h"
+#include "ft_generic_timer.h"
+#include <gicv3.h>
+
+#include "interrupt.h"
+#include <mmu.h>
+#include "cp15.h"
+#include "ft2004.h"
+
+#define DDR_MEM (SHARED | AP_RW | DOMAIN0 | MEMWT | DESC_SEC)
+
+struct mem_desc platform_mem_desc[] = {
+ {0x80000000,
+ 0x80000000 + 0x7f000000,
+ 0x80000000,
+ DDR_MEM},
+ {0, //< QSPI
+ 0x1FFFFFFF,
+ 0,
+ DEVICE_MEM},
+ {0x20000000, //<! LPC
+ 0x27FFFFFF,
+ 0x20000000,
+ DEVICE_MEM},
+ {FT_DEV_BASE_ADDR, //<! Device register
+ FT_DEV_END_ADDR,
+ FT_DEV_BASE_ADDR,
+ DEVICE_MEM},
+ {0x30000000, //<! debug
+ 0x39FFFFFF,
+ 0x30000000,
+ DEVICE_MEM},
+ {0x3A000000, //<! Internal register space in the on-chip network
+ 0x3AFFFFFF,
+ 0x3A000000,
+ DEVICE_MEM},
+ {FT_PCI_CONFIG_BASEADDR,
+ FT_PCI_CONFIG_BASEADDR + FT_PCI_CONFIG_REG_LENGTH,
+ FT_PCI_CONFIG_BASEADDR,
+ DEVICE_MEM},
+ {FT_PCI_IO_CONFIG_BASEADDR,
+ FT_PCI_IO_CONFIG_BASEADDR + FT_PCI_IO_CONFIG_REG_LENGTH,
+ FT_PCI_IO_CONFIG_BASEADDR,
+ DEVICE_MEM},
+ {FT_PCI_MEM32_BASEADDR,
+ FT_PCI_MEM32_BASEADDR + FT_PCI_MEM32_REG_LENGTH,
+ FT_PCI_MEM32_BASEADDR,
+ DEVICE_MEM},
+};
+
+const rt_uint32_t platform_mem_desc_size = sizeof(platform_mem_desc) / sizeof(platform_mem_desc[0]);
+
+rt_uint32_t platform_get_gic_dist_base(void)
+{
+ return FT_GICV3_DISTRIBUTOR_BASEADDRESS;
+}
+
+static rt_uint32_t timerStep;
+
+void rt_hw_timer_isr(int vector, void *parameter)
+{
+ gtimer_set_load_value(timerStep);
+ rt_tick_increase();
+}
+
+int rt_hw_timer_init(void)
+{
+ rt_hw_interrupt_install(30, rt_hw_timer_isr, RT_NULL, "tick");
+ rt_hw_interrupt_umask(30);
+ timerStep = gtimer_get_counter_frequency();
+ timerStep /= RT_TICK_PER_SECOND;
+ gtimer_set_load_value(timerStep);
+ gtimer_set_control(1);
+ return 0;
+}
+INIT_BOARD_EXPORT(rt_hw_timer_init);
+
+static void AssertCallback(const char *File, s32 Line)
+{
+ Ft_printf("Assert Error is %s : %d \r\n", File, Line);
+}
+
+#ifdef RT_USING_SMP
+void rt_hw_ipi_handler_install(int ipi_vector, rt_isr_handler_t ipi_isr_handler);
+#endif
+
+/**
+ * This function will initialize hardware board
+ */
+void rt_hw_board_init(void)
+{
+ /* bsp debug */
+ FCpu_SpinLockInit();
+ Ft_GenericTimer_Init(0, RT_NULL);
+ Ft_vsprintfRegister((vsprintf_p)rt_vsprintf);
+ Ft_assertSetCallBack((Ft_assertCallback)AssertCallback);
+
+ /* interrupt init */
+ arm_gic_redist_address_set(0, FT_GICV3_RD_BASEADDRESS + 0, 0);
+
+#if RT_CPUS_NR == 2
+ Ft_printf("arm_gic_redist_address_set is 2 \r\n");
+ arm_gic_redist_address_set(0, FT_GICV3_RD_BASEADDRESS + (2U << 16), 1);
+#elif RT_CPUS_NR == 3
+ arm_gic_redist_address_set(0, FT_GICV3_RD_BASEADDRESS + (2U << 16), 1);
+ arm_gic_redist_address_set(0, FT_GICV3_RD_BASEADDRESS + 2 * (2U << 16), 2);
+#elif RT_CPUS_NR == 4
+ arm_gic_redist_address_set(0, FT_GICV3_RD_BASEADDRESS + (2U << 16), 1);
+ arm_gic_redist_address_set(0, FT_GICV3_RD_BASEADDRESS + 2 * (2U << 16), 2);
+ arm_gic_redist_address_set(0, FT_GICV3_RD_BASEADDRESS + 3 * (2U << 16), 3);
+#endif
+
+ rt_hw_interrupt_init();
+
+ rt_components_board_init();
+ rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
+
+/* 初始化内存池 */
+#ifdef RT_USING_HEAP
+ rt_system_heap_init(HEAP_BEGIN, HEAP_END);
+#endif
+
+#ifdef RT_USING_SMP
+ /* install IPI handle */
+ rt_hw_interrupt_set_priority(RT_SCHEDULE_IPI, 16);
+ rt_hw_ipi_handler_install(RT_SCHEDULE_IPI, rt_scheduler_ipi_handler);
+ rt_hw_interrupt_umask(RT_SCHEDULE_IPI);
+#endif
+}
+
+static void ft_reset(void)
+{
+ FPsci_Reset();
+}
+MSH_CMD_EXPORT_ALIAS(ft_reset, ft_reset, ft_reset);
+
+/*@}*/
diff --git a/bsp/ft2004/drivers/board.h b/bsp/ft2004/drivers/board.h
new file mode 100644
index 0000000000..4900ed2e79
--- /dev/null
+++ b/bsp/ft2004/drivers/board.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2013-07-06 Bernard the first version
+ */
+
+#ifndef __BOARD_H__
+#define __BOARD_H__
+
+#include "ft_parameters.h"
+#include "ft2004.h"
+
+#if defined(__CC_ARM)
+extern int Image$$RW_IRAM1$$ZI$$Limit;
+#define HEAP_BEGIN ((void *)&Image$$RW_IRAM1$$ZI$$Limit)
+#elif defined(__GNUC__)
+extern int __bss_end;
+#define HEAP_BEGIN ((void *)&__bss_end)
+#endif
+
+#define HEAP_END (void *)(0x80000000 + 1024 * 1024 * 1024)
+
+void rt_hw_board_init(void);
+
+#endif
diff --git a/bsp/ft2004/drivers/drv_can.c b/bsp/ft2004/drivers/drv_can.c
new file mode 100644
index 0000000000..ff03755761
--- /dev/null
+++ b/bsp/ft2004/drivers/drv_can.c
@@ -0,0 +1,270 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-05-11 Carl the first version
+ */
+
+#include "drv_can.h"
+#include "interrupt.h"
+#include <string.h>
+
+#ifdef BSP_USE_CAN
+
+#define LOG_TAG "drv_can"
+#include <drv_log.h>
+
+#define _CAN0_NAME "can0"
+#define _CAN1_NAME "can1"
+
+#define RTHW_CAN_WAIT(_can) rt_sem_take(&_can->recv_semaphore, RT_WAITING_FOREVER);
+#define RTHW_CAN_SEND(_can) rt_sem_release(&_can->recv_semaphore);
+
+#ifdef BSP_USING_CAN0
+struct ft2004_can drv_can0 =
+ {
+ .name = _CAN0_NAME,
+ .can_handle.Config.InstanceId = 0};
+#endif
+
+#ifdef BSP_USING_CAN1
+struct ft2004_can drv_can1 =
+ {
+ .name = _CAN1_NAME,
+ .can_handle.Config.InstanceId = 1};
+#endif
+
+static void _can_recv_irq(void *args)
+{
+ struct ft2004_can *drv_can = (struct ft2004_can *)args;
+ RTHW_CAN_SEND(drv_can);
+}
+
+static void rt_hw_inner_can_isr(int irqno, void *param)
+{
+ FCan_IntrHandler(param);
+}
+
+static rt_err_t _can_config(struct rt_can_device *can, struct can_configure *cfg)
+{
+ struct FCan_Bittiming bit_timing = {0};
+ struct ft2004_can *drv_can;
+ RT_ASSERT(can);
+ RT_ASSERT(cfg);
+ drv_can = (struct ft2004_can *)can->parent.user_data;
+ RT_ASSERT(drv_can);
+
+ FCan_CfgInitialize(&drv_can->can_handle, FCan_LookupConfig(drv_can->can_handle.Config.InstanceId));
+
+ FCan_SetHandler(&drv_can->can_handle, FCAN_HANDLER_RECV, _can_recv_irq, drv_can);
+
+ bit_timing.bitrate = cfg->baud_rate;
+
+ if (FCan_CalcBittiming(&bit_timing) != FCAN_SUCCESS)
+ {
+ LOG_E("Setting baud rate %x is not valid \r\n", bit_timing.bitrate);
+ return -RT_ERROR;
+ }
+
+ FCan_SetTiming(&drv_can->can_handle, &bit_timing);
+
+ rt_hw_interrupt_set_priority(drv_can->can_handle.Config.IrqNum, 16);
+ rt_hw_interrupt_install(drv_can->can_handle.Config.IrqNum, rt_hw_inner_can_isr, &drv_can->can_handle, drv_can->name);
+ rt_hw_interrupt_umask(drv_can->can_handle.Config.IrqNum);
+
+ FCan_Enable(&drv_can->can_handle);
+
+ return RT_EOK;
+}
+
+static rt_err_t _can_control(struct rt_can_device *can, int cmd, void *arg)
+{
+ return RT_EOK;
+}
+
+static int _can_sendmsg(struct rt_can_device *can, const void *buf, rt_uint32_t box_num)
+{
+ struct ft2004_can *drv_can;
+ struct rt_can_msg *pmsg = (struct rt_can_msg *)buf;
+ struct FCan_Frame can_frame = {0};
+ RT_ASSERT(can);
+ drv_can = (struct ft2004_can *)can->parent.user_data;
+ RT_ASSERT(drv_can);
+
+ /* Check the parameters */
+ RT_ASSERT(pmsg->len <= 8U);
+
+ if (RT_CAN_STDID == pmsg->ide)
+ {
+ can_frame.CanId = pmsg->id;
+ }
+ else
+ {
+ can_frame.CanId = pmsg->id;
+ can_frame.CanId |= CAN_EFF_FLAG;
+ }
+
+ if (RT_CAN_DTR == pmsg->rtr)
+ {
+ }
+ else
+ {
+ can_frame.CanId |= CAN_RTR_FLAG;
+ }
+
+ can_frame.CanDlc = pmsg->len & 0x0FU;
+ memcpy(can_frame.data, pmsg->data, 8);
+
+ return (FCan_SendByIrq(&drv_can->can_handle, &can_frame, 1, RT_NULL) == 1) ? RT_EOK : -RT_ERROR;
+}
+
+static int _can_recvmsg(struct rt_can_device *can, void *buf, rt_uint32_t fifo)
+{
+ struct ft2004_can *drv_can;
+ struct rt_can_msg *pmsg = (struct rt_can_msg *)buf;
+ RT_ASSERT(can);
+ struct FCan_Frame recv_frame = {0};
+ drv_can = (struct ft2004_can *)can->parent.user_data;
+ RT_ASSERT(drv_can);
+
+ RTHW_CAN_WAIT(drv_can);
+
+ if (FCan_RecvByIrq(&drv_can->can_handle, &recv_frame, 1) == 0)
+ {
+ LOG_E("rx msg is error");
+ return -RT_ERROR;
+ }
+
+ if (CAN_EFF_FLAG & recv_frame.CanId)
+ {
+ pmsg->ide = RT_CAN_EXTID;
+ pmsg->id = (recv_frame.CanId & ~(RT_CAN_EXTID));
+ }
+ else
+ {
+ pmsg->ide = RT_CAN_STDID;
+ pmsg->id = recv_frame.CanId;
+ }
+
+ if (CAN_RTR_FLAG & recv_frame.CanId)
+ {
+ pmsg->id &= ~CAN_RTR_FLAG;
+ pmsg->rtr = RT_CAN_RTR;
+ }
+ else
+ {
+ pmsg->rtr = RT_CAN_DTR;
+ }
+
+ /* get len */
+ pmsg->len = recv_frame.CanDlc;
+ return RT_EOK;
+}
+
+static const struct rt_can_ops _can_ops =
+ {
+ _can_config,
+ _can_control,
+ _can_sendmsg,
+ _can_recvmsg,
+};
+
+int rt_hw_can_init(void)
+{
+#ifdef BSP_USING_CAN0
+ drv_can0.can_handle.Config.InstanceId = 0;
+ rt_sem_init(&drv_can0.recv_semaphore, "can0_recv", 0, RT_IPC_FLAG_FIFO);
+ drv_can0.device.config.ticks = 20000;
+ drv_can0.device.config.baud_rate = 1000000;
+ rt_hw_can_register(&drv_can0.device,
+ drv_can0.name,
+ &_can_ops,
+ &drv_can0);
+
+#endif
+
+#ifdef BSP_USING_CAN1
+ drv_can1.can_handle.Config.InstanceId = 1;
+ drv_can0.device.config.baud_rate = 1000000;
+ rt_sem_init(&drv_can1.recv_semaphore, "can1_recv", 0, RT_IPC_FLAG_FIFO);
+ rt_hw_can_register(&drv_can1.device,
+ drv_can1.name,
+ &_can_ops,
+ &drv_can1);
+
+#endif
+ return 0;
+}
+
+INIT_BOARD_EXPORT(rt_hw_can_init);
+
+#ifdef BSP_USING_CAN0_DEBUG
+
+struct can_test_struct
+{
+ const char *name;
+ struct rt_can_filter_config *filter;
+ rt_device_t candev;
+ struct rt_semaphore _sem;
+};
+
+static struct can_test_struct can0_test_obj = {
+ .name = _CAN0_NAME};
+
+void can_recv_irq(void *param)
+{
+ struct can_test_struct *_can_obj = (struct can_test_struct *)param;
+ rt_kprintf("can_recv_iqr \r\n");
+ rt_sem_release(&_can_obj->_sem);
+}
+
+static void rt_can_test_loopback_thread_entry(void *param)
+{
+ struct can_test_struct *_can_obj = (struct can_test_struct *)param;
+ struct FCan_Frame recv_frame;
+ struct ft2004_can *drv_can;
+ rt_uint32_t i;
+ _can_obj->candev = rt_device_find(_can_obj->name);
+ RT_ASSERT(_can_obj->candev);
+ drv_can = (struct ft2004_can *)_can_obj->candev->user_data;
+ rt_sem_init(&_can_obj->_sem, "canrx_wait", 0, RT_IPC_FLAG_FIFO);
+ rt_device_open(_can_obj->candev, RT_DEVICE_OFLAG_RDWR);
+
+ while (1)
+ {
+ rt_kprintf(" start to wait loopback \r\n");
+ RTHW_CAN_WAIT(drv_can);
+ while (0 != FCan_RecvByIrq(&drv_can->can_handle, &recv_frame, 1))
+ {
+ rt_kprintf("CanId %x \r\n", recv_frame.CanId);
+ rt_kprintf("CanDlc %x \r\n", recv_frame.CanDlc);
+ for (i = 0; i < recv_frame.CanDlc; i++)
+ {
+ rt_kprintf("data [%d] %x \r\n", i, recv_frame.data[i]);
+ }
+ FCan_SendByIrq(&drv_can->can_handle, &recv_frame, 1, RT_NULL);
+ }
+ }
+}
+
+int rt_can0_test(void)
+{
+ rt_thread_t tid;
+
+ tid = rt_thread_create("can0_loopback",
+ rt_can_test_loopback_thread_entry, &can0_test_obj,
+ 1024, 16, 20);
+ if (tid != RT_NULL)
+ rt_thread_startup(tid);
+
+ return 0;
+}
+
+INIT_APP_EXPORT(rt_can0_test);
+
+#endif
+
+#endif
diff --git a/bsp/ft2004/drivers/drv_can.h b/bsp/ft2004/drivers/drv_can.h
new file mode 100644
index 0000000000..92e809eb1e
--- /dev/null
+++ b/bsp/ft2004/drivers/drv_can.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-05-11 Carl the first version
+ */
+
+#ifndef __DRV_CAN_H__
+#define __DRV_CAN_H__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <board.h>
+#include <rtdevice.h>
+#include <rtthread.h>
+#include "ft_can.h"
+
+ struct ft2004_can
+ {
+ const char *name;
+ FCan_t can_handle;
+ struct rt_semaphore recv_semaphore;
+ struct rt_can_device device; /* inherit from can device */
+ };
+
+ int rt_hw_can_init(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // !
diff --git a/bsp/ft2004/drivers/drv_eth.c b/bsp/ft2004/drivers/drv_eth.c
new file mode 100644
index 0000000000..e7148631e4
--- /dev/null
+++ b/bsp/ft2004/drivers/drv_eth.c
@@ -0,0 +1,691 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-03-09 Carl the first version
+ */
+
+#include "board.h"
+#include <netif/ethernetif.h>
+#include "lwipopts.h"
+#include "ft_parameters.h"
+#include "ft_gmac.h"
+#include "ft_cache.h"
+#include "ft_gmac_hw.h"
+#include "ft_status.h"
+#include "ft_io.h"
+#include "drv_eth.h"
+
+#ifdef BSP_USING_GMAC
+
+#define LOG_TAG "drv.gmac"
+#include <drv_log.h>
+
+#define MAX_ADDR_LEN 6
+
+#define LINK_THREAD_STACK_LENGTH 0x400
+
+struct drv_gmac
+{
+ struct eth_device parent; /* inherit from ethernet device */
+ Ft_Gmac_t Gmac; /* Gmac driver */
+#ifndef PHY_USING_INTERRUPT_MODE
+ rt_timer_t poll_link_timer;
+#endif
+ rt_uint8_t *rx_buffer; /* Buffer for RxDesc */
+ rt_uint8_t *tx_buffer; /* Buffer for TxDesc */
+ uint32_t eth_speed; /* eth_speed */
+ uint32_t eth_mode; /* ETH_Duplex_Mode */
+ rt_uint8_t dev_addr[MAX_ADDR_LEN]; /* MAC address */
+ struct rt_event link_event;
+
+ struct rt_thread _link_thread;
+ rt_uint8_t _link_thread_stack[LINK_THREAD_STACK_LENGTH];
+
+ rt_thread_t _debug_tid;
+};
+
+static void rt_ft2004_status_check(void *Args, u32 MacPhyStatus);
+
+//
+#if defined(RAW_DATA_PRINT)
+#if defined(ETH_RX_DUMP) || defined(ETH_TX_DUMP)
+#define __is_print(ch) ((unsigned int)((ch) - ' ') < 127u - ' ')
+static void dump_hex(const rt_uint8_t *ptr, rt_size_t buflen)
+{
+ unsigned char *buf = (unsigned char *)ptr;
+ int i, j;
+
+ for (i = 0; i < buflen; i += 16)
+ {
+ rt_kprintf("%08X: ", i);
+
+ for (j = 0; j < 16; j++)
+ if (i + j < buflen)
+ rt_kprintf("%02X ", buf[i + j]);
+ else
+ rt_kprintf(" ");
+ rt_kprintf(" ");
+
+ for (j = 0; j < 16; j++)
+ if (i + j < buflen)
+ rt_kprintf("%c", __is_print(buf[i + j]) ? buf[i + j] : '.');
+ rt_kprintf("\n");
+ }
+}
+#endif
+#endif
+
+/**
+ * @name: rt_gmacmem_create
+ * @msg: Initialize the Gmac TX/Rx Describe Memory 。
+ * @param {*}
+ * @return {*}
+ */
+static void rt_gmacmem_create(struct drv_gmac *pOsGmac)
+{
+ pOsGmac->rx_buffer = rt_calloc(1, RX_DESCNUM * GMAC_MAX_PACKET_SIZE);
+ if (pOsGmac->rx_buffer == NULL)
+ {
+ LOG_E("rx_buffer Malloc is error ");
+ RT_ASSERT(0)
+ }
+
+ pOsGmac->tx_buffer = rt_calloc(1, TX_DESCNUM * GMAC_MAX_PACKET_SIZE);
+ if (pOsGmac->tx_buffer == NULL)
+ {
+ LOG_E("tx_buffer Malloc is error ");
+ RT_ASSERT(0)
+ }
+
+ pOsGmac->Gmac.TxDesc = rt_calloc(1, TX_DESCNUM * sizeof(FGmac_DmaDesc_t));
+ if (pOsGmac->Gmac.TxDesc == NULL)
+ {
+ LOG_E("TxDesc Malloc is error ");
+ RT_ASSERT(0)
+ }
+
+ pOsGmac->Gmac.RxDesc = rt_calloc(1, RX_DESCNUM * sizeof(FGmac_DmaDesc_t) + 128);
+ if (pOsGmac->Gmac.RxDesc == NULL)
+ {
+ LOG_E("RxDesc Malloc is error ");
+ RT_ASSERT(0)
+ }
+
+#define ROUND_UP(x, align) (((long)(x) + ((long)align - 1)) & \
+ ~((long)align - 1))
+
+ pOsGmac->Gmac.RxDesc = (FGmac_DmaDesc_t *)ROUND_UP(pOsGmac->Gmac.RxDesc, 128);
+ LOG_D("RxDesc fit after addr %x ", pOsGmac->Gmac.RxDesc);
+}
+
+static void rt_gmacmem_free(struct drv_gmac *pOsGmac)
+{
+ if (pOsGmac->rx_buffer)
+ {
+ rt_free(pOsGmac->rx_buffer);
+ }
+
+ if (pOsGmac->tx_buffer)
+ {
+ rt_free(pOsGmac->tx_buffer);
+ }
+
+ if (pOsGmac->Gmac.RxDesc)
+ {
+ rt_free(pOsGmac->Gmac.RxDesc);
+ }
+
+ if (pOsGmac->Gmac.TxDesc)
+ {
+ rt_free(pOsGmac->Gmac.TxDesc);
+ }
+}
+
+static void rt_hw_gmac_isr(int irqno, void *param)
+{
+ FGmac_IntrHandler(param);
+}
+
+static void rt_hw_gmac_recv_isr(void *Args)
+{
+ struct drv_gmac *pOsMac;
+ rt_err_t result = 0;
+
+ if (RT_NULL == Args)
+ {
+ LOG_E("Args is NULL");
+ return;
+ }
+
+ pOsMac = (struct drv_gmac *)Args;
+ result = eth_device_ready(&(pOsMac->parent));
+ if (result != RT_EOK)
+ {
+ LOG_I("RxCpltCallback err = %d", result);
+ }
+}
+
+static rt_err_t
+rt_ft2004_gmac_start(struct drv_gmac *pOsMac)
+{
+ Ft_Gmac_t *pGmac;
+ pGmac = &pOsMac->Gmac;
+
+ if (FST_SUCCESS != Ft_Gmac_HwInitialize(pGmac))
+ {
+ return -RT_ERROR;
+ }
+
+ FGmac_SetHandler(pGmac, FT_GMAC_RX_COMPLETE_CB_ID, rt_hw_gmac_recv_isr, pOsMac);
+ FGmac_SetHandler(pGmac, FT_GMAC_MAC_PHY_STATUS_CB_ID, rt_ft2004_status_check, pOsMac);
+
+ /* Initialize Rx Description list : ring Mode */
+ FGmac_DmaRxDescRingInit(pGmac, pGmac->RxDesc, pOsMac->rx_buffer, GMAC_MAX_PACKET_SIZE, RX_DESCNUM);
+
+ /* Initialize Tx Description list : ring Mode */
+ FGmac_DmaTxDescRingInit(pGmac, pGmac->TxDesc, pOsMac->tx_buffer, GMAC_MAX_PACKET_SIZE, TX_DESCNUM);
+
+ Ft_Gmac_Start(pGmac);
+ /* Gmac interrupt init */
+ rt_hw_interrupt_install(pGmac->Config.IRQ_NUM, rt_hw_gmac_isr, pGmac, "Gmac");
+ rt_hw_interrupt_umask(pGmac->Config.IRQ_NUM);
+ return RT_EOK;
+}
+
+void rt_ft2004_gmac_stop(struct drv_gmac *pOsMac)
+{
+ Ft_Gmac_t *pGmac;
+ pGmac = &pOsMac->Gmac;
+ Ft_Gmac_Stop(pGmac);
+}
+
+/* GMAC initialization function */
+static rt_err_t rt_ft2004_gmac_init(rt_device_t dev)
+{
+ struct drv_gmac *pOsMac;
+ struct eth_device *pGmacParent;
+ FGmac_Config_t *pConfig;
+
+ pGmacParent = rt_container_of(dev, struct eth_device, parent);
+ if (NULL == pGmacParent)
+ {
+ return -RT_ENOMEM;
+ }
+
+ pOsMac = rt_container_of(pGmacParent, struct drv_gmac, parent);
+ if (NULL == pOsMac)
+ {
+ return -RT_ENOMEM;
+ }
+
+ pConfig = Ft_Gmac_LookupConfig(pOsMac->Gmac.Config.InstanceId);
+ if (NULL == pConfig)
+ {
+ return -RT_ENOMEM;
+ }
+
+ Ft_Gmac_UseDefaultMacAddr(&pOsMac->Gmac, pOsMac->Gmac.Config.MacAddr);
+
+ if (FST_SUCCESS != Ft_GmacCfgInitialize(&pOsMac->Gmac, pConfig))
+ {
+ return -RT_ERROR;
+ }
+
+ return rt_ft2004_gmac_start(pOsMac);
+}
+
+static rt_err_t rt_ft2004_gmac_open(rt_device_t dev, rt_uint16_t oflag)
+{
+ LOG_D("gmac open");
+ return RT_EOK;
+}
+
+static rt_err_t rt_ft2004_gmac_close(rt_device_t dev)
+{
+ LOG_D("gmac close");
+ return RT_EOK;
+}
+
+static rt_size_t rt_ft2004_gmac_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
+{
+ LOG_D("gmac read");
+ rt_set_errno(-RT_ENOSYS);
+ return 0;
+}
+
+static rt_size_t rt_ft2004_gmac_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
+{
+ LOG_D("gmac write");
+ rt_set_errno(-RT_ENOSYS);
+ return 0;
+}
+
+static rt_err_t rt_ft2004_gmac_control(rt_device_t dev, int cmd, void *args)
+{
+
+ struct drv_gmac *pOsMac;
+ struct eth_device *pGmacParent;
+
+ pGmacParent = rt_container_of(dev, struct eth_device, parent);
+ if (NULL == pGmacParent)
+ {
+ return -RT_ENOMEM;
+ }
+
+ pOsMac = rt_container_of(pGmacParent, struct drv_gmac, parent);
+ if (NULL == pOsMac)
+ {
+ return -RT_ENOMEM;
+ }
+
+ switch (cmd)
+ {
+ case NIOCTL_GADDR:
+ /* get mac address */
+ if (args)
+ rt_memcpy(args, pOsMac->dev_addr, 6);
+ else
+ return -RT_ERROR;
+ break;
+
+ default:
+ break;
+ }
+
+ return RT_EOK;
+}
+
+rt_err_t rt_ft2004_gmac_tx(rt_device_t dev, struct pbuf *p)
+{
+ struct drv_gmac *pOsMac;
+ Ft_Gmac_t *pGmac;
+ struct eth_device *pGmacParent;
+
+ err_t errval;
+ struct pbuf *q;
+ u8 *Buffer = NULL;
+ volatile FGmac_DmaDesc_t *DmaTxDesc;
+
+ u32 FrameLength = 0;
+ u32 BufferOffset = 0;
+ u32 BytesLeftToCopy = 0;
+ u32 PayLoadOffset = 0;
+
+ pGmacParent = rt_container_of(dev, struct eth_device, parent);
+ if (NULL == pGmacParent)
+ {
+ return -RT_ENOMEM;
+ }
+
+ pOsMac = rt_container_of(pGmacParent, struct drv_gmac, parent);
+ if (NULL == pOsMac)
+ {
+ return -RT_ENOMEM;
+ }
+
+ pGmac = &pOsMac->Gmac;
+ DmaTxDesc = &pGmac->TxDesc[pGmac->TxDescRingData.DescBufIndex];
+ Buffer = (u8 *)DmaTxDesc->Buffer1Addr;
+
+ if (Buffer == NULL)
+ {
+ LOG_E("Buffer is NULL \r\n");
+ RT_ASSERT(0)
+ }
+
+#if RT_LWIP_ETH_PAD_SIZE
+ pbuf_header(p, -RT_LWIP_ETH_PAD_SIZE); /* reclaim the padding word */
+#endif
+
+ for (q = p; q != NULL; q = q->next)
+ {
+ /* Is this buffer available? If not, goto error */
+ if ((DmaTxDesc->Status & DMA_TDES0_OWN) != 0)
+ {
+ errval = ERR_USE;
+ LOG_E("error errval = ERR_USE; \r\n");
+ goto error;
+ }
+
+ /* Get bytes in current lwIP buffer */
+ BytesLeftToCopy = q->len;
+ PayLoadOffset = 0;
+ /* Check if the length of data to copy is bigger than Tx buffer size*/
+ while ((BytesLeftToCopy + BufferOffset) > GMAC_MAX_PACKET_SIZE)
+ {
+ /* Copy data to Tx buffer*/
+ memcpy((u8 *)((u8 *)Buffer + BufferOffset), (u8 *)((u8 *)q->payload + PayLoadOffset), (GMAC_MAX_PACKET_SIZE - BufferOffset));
+ FCache_cpuDcacheClean((rt_uint32_t *)DmaTxDesc->Buffer1Addr, GMAC_MAX_PACKET_SIZE);
+ GMAC_INC_DESC(pGmac->TxDescRingData.DescBufIndex, pGmac->TxDescRingData.DescMaxNumber);
+ /* Point to next descriptor */
+ DmaTxDesc = &pGmac->TxDesc[pGmac->TxDescRingData.DescBufIndex];
+
+ /* Check if the Bufferis available */
+ if ((DmaTxDesc->Status & DMA_TDES0_OWN) != (u32)0)
+ {
+ errval = ERR_USE;
+ LOG_E("Check if the Bufferis available \r\n");
+ goto error;
+ }
+
+ Buffer = (u8 *)(DmaTxDesc->Buffer1Addr);
+ BytesLeftToCopy = BytesLeftToCopy - (GMAC_MAX_PACKET_SIZE - BufferOffset);
+ PayLoadOffset = PayLoadOffset + (GMAC_MAX_PACKET_SIZE - BufferOffset);
+ FrameLength = FrameLength + (GMAC_MAX_PACKET_SIZE - BufferOffset);
+ BufferOffset = 0;
+
+ if (Buffer == NULL)
+ {
+ LOG_E(" error Buffer is 0 \r\n");
+ RT_ASSERT(0)
+ }
+ }
+
+ /* Copy the remaining bytes */
+ memcpy((u8 *)((u8 *)Buffer + BufferOffset), (u8 *)((u8 *)q->payload + PayLoadOffset), BytesLeftToCopy);
+ BufferOffset = BufferOffset + BytesLeftToCopy;
+ FrameLength = FrameLength + BytesLeftToCopy;
+ }
+ /* 指向下一个位置 */
+ FCache_cpuDcacheClean((rt_uint32_t *)DmaTxDesc->Buffer1Addr, GMAC_MAX_PACKET_SIZE);
+ GMAC_INC_DESC(pGmac->TxDescRingData.DescBufIndex, pGmac->TxDescRingData.DescMaxNumber);
+#if RT_LWIP_ETH_PAD_SIZE
+ pbuf_header(p, RT_LWIP_ETH_PAD_SIZE); /* reclaim the padding word */
+#endif
+
+#ifdef ETH_TX_DUMP
+ dump_hex(Buffer, p->tot_len);
+#endif
+
+ FGmac_TransmitframeRingPoll(pGmac, FrameLength);
+error:
+ FGmac_SetTransmitUnderflow(pGmac);
+ return errval;
+}
+
+struct pbuf *rt_ft2004_gmac_rx(rt_device_t dev)
+{
+ struct drv_gmac *pOsMac;
+ Ft_Gmac_t *pGmac;
+ struct eth_device *pGmacParent;
+
+ struct pbuf *p = NULL;
+ struct pbuf *q = NULL;
+ u16 Length = 0;
+ u8 *Buffer;
+ volatile FGmac_DmaDesc_t *DmaRxDesc;
+ u32 BufferOffset = 0;
+ u32 PayLoadOffset = 0;
+ u32 BytesLeftToCopy = 0;
+ u32 DescBufIndex; /* For Current Desc buffer buf position */
+
+ pGmacParent = rt_container_of(dev, struct eth_device, parent);
+ if (NULL == pGmacParent)
+ {
+ return RT_NULL;
+ }
+
+ pOsMac = rt_container_of(pGmacParent, struct drv_gmac, parent);
+ if (NULL == pOsMac)
+ {
+ return RT_NULL;
+ }
+
+ pGmac = &pOsMac->Gmac;
+
+ /* get received frame */
+ if (FST_SUCCESS != FGmac_RingGetReceivedFrame_IT(pGmac))
+ {
+ return NULL;
+ }
+
+ DescBufIndex = pGmac->RxDescRingData.DescBufIndex;
+ Length = (pGmac->RxDesc[DescBufIndex].Status & DMA_RDES0_FRAME_LEN_MASK) >> DMA_RDES0_FRAME_LEN_SHIFT;
+ Buffer = (u8 *)pGmac->RxDesc[DescBufIndex].Buffer1Addr;
+
+#if RT_LWIP_ETH_PAD_SIZE
+ Length += RT_LWIP_ETH_PAD_SIZE; /* allow room for Ethernet padding */
+#endif
+
+ if (Length > 0)
+ {
+ /* We allocate a pbuf chain of pbufs from the Lwip buffer pool */
+ p = pbuf_alloc(PBUF_RAW, Length, PBUF_POOL);
+ }
+
+#ifdef ETH_RX_DUMP
+ dump_hex(Buffer, (u32)Length);
+#endif
+
+ if (p != NULL)
+ {
+#if RT_LWIP_ETH_PAD_SIZE
+ pbuf_header(p, -RT_LWIP_ETH_PAD_SIZE); /* drop the padding word */
+#endif
+ DmaRxDesc = &pGmac->RxDesc[DescBufIndex];
+ BufferOffset = 0;
+ for (q = p; q != NULL; q = q->next)
+ {
+ BytesLeftToCopy = q->len;
+ PayLoadOffset = 0;
+ /* Check if the length of bytes to copy in current pbuf is bigger than Rx buffer size*/
+ while ((BytesLeftToCopy + BufferOffset) > GMAC_MAX_PACKET_SIZE)
+ {
+ /* Copy data to pbuf */
+ memcpy((u8 *)((u8 *)q->payload + PayLoadOffset), (u8 *)((u8 *)Buffer + BufferOffset), (GMAC_MAX_PACKET_SIZE - BufferOffset));
+
+ /* Point to next descriptor */
+ GMAC_INC_DESC(DescBufIndex, pGmac->RxDescRingData.DescMaxNumber);
+ if (DescBufIndex == pGmac->RxDescRingData.DescIndex)
+ {
+ break;
+ }
+
+ DmaRxDesc = &pGmac->RxDesc[DescBufIndex];
+ Buffer = (u8 *)(DmaRxDesc->Buffer1Addr);
+
+ BytesLeftToCopy = BytesLeftToCopy - (GMAC_MAX_PACKET_SIZE - BufferOffset);
+ PayLoadOffset = PayLoadOffset + (GMAC_MAX_PACKET_SIZE - BufferOffset);
+ BufferOffset = 0;
+ }
+ /* Copy remaining data in pbuf */
+ memcpy((u8 *)((u8 *)q->payload + PayLoadOffset), (u8 *)((u8 *)Buffer + BufferOffset), BytesLeftToCopy);
+ BufferOffset = BufferOffset + BytesLeftToCopy;
+ }
+
+#if RT_LWIP_ETH_PAD_SIZE
+ pbuf_header(p, RT_LWIP_ETH_PAD_SIZE); /* reclaim the padding word */
+#endif
+ }
+
+ /* Release descriptors to DMA */
+ /* Point to first descriptor */
+ DmaRxDesc = &pGmac->RxDesc[DescBufIndex];
+ /* Set Own bit in Rx descriptors: gives the buffers back to DMA */
+ for (DescBufIndex = pGmac->RxDescRingData.DescBufIndex; DescBufIndex != pGmac->RxDescRingData.DescIndex; GMAC_INC_DESC(DescBufIndex, pGmac->RxDescRingData.DescMaxNumber))
+ {
+ FCache_cpuDcacheInvalidate((rt_uint32_t *)pGmac->RxDesc[DescBufIndex].Buffer1Addr, GMAC_MAX_PACKET_SIZE);
+ DmaRxDesc->Status |= DMA_RDES0_OWN;
+ DmaRxDesc = &pGmac->RxDesc[DescBufIndex];
+ }
+
+ /* Sync index */
+ pGmac->RxDescRingData.DescBufIndex = pGmac->RxDescRingData.DescIndex;
+ FGmac_ResumeTransmissionReception(pGmac);
+
+ return p;
+}
+
+static void rt_ft2004_status_check(void *Args, u32 MacPhyStatus)
+{
+ struct drv_gmac *pOsMac;
+ pOsMac = (struct drv_gmac *)Args;
+
+ if (MacPhyStatus & 0x8)
+ {
+ rt_event_send(&pOsMac->link_event, FT_NETIF_LINKUP);
+ }
+ else
+ {
+ rt_event_send(&pOsMac->link_event, FT_NETIF_DOWN);
+ }
+}
+
+static void ethernet_link_thread(void *Args)
+{
+ struct drv_gmac *pOsMac;
+ rt_uint32_t status;
+ u32 LastStatus = FT_NETIF_DOWN;
+ u32 Flg;
+ if (RT_NULL == Args)
+ {
+ return;
+ }
+
+ pOsMac = (struct drv_gmac *)Args;
+
+ while (1)
+ {
+ status = 0;
+ if (rt_event_recv(&pOsMac->link_event, FT_NETIF_LINKUP | FT_NETIF_DOWN, RT_EVENT_FLAG_CLEAR | RT_EVENT_FLAG_OR,
+ RT_WAITING_FOREVER, &status) != RT_EOK)
+ {
+ LOG_E("wait completed timeout");
+ continue;
+ }
+
+ if (status & FT_NETIF_DOWN)
+ {
+ eth_device_linkchange(&pOsMac->parent, RT_FALSE);
+ LastStatus = FT_NETIF_DOWN;
+ }
+ else if (status & FT_NETIF_LINKUP)
+ {
+ Flg = (LastStatus == FT_NETIF_LINKUP) ? 0 : 1;
+ LastStatus = FT_NETIF_LINKUP;
+ }
+ else
+ {
+ LOG_I(" EventGroup is error \r\n");
+ RT_ASSERT(0)
+ }
+
+ if (Flg)
+ {
+ Flg = 0;
+ // eth_device_linkchange(&pOsMac->parent, RT_FALSE);
+ LOG_I(" Start Linkup \r\n");
+ rt_ft2004_gmac_stop(pOsMac);
+ rt_ft2004_gmac_start(pOsMac);
+ LOG_I(" HardWare is ok \r\n");
+ if (LastStatus == FT_NETIF_LINKUP)
+ {
+ rt_thread_mdelay(5000);
+ eth_device_linkchange(&pOsMac->parent, RT_TRUE);
+ }
+ }
+ }
+}
+
+#ifdef BSP_USING_GMAC0
+struct drv_gmac os_drv_gmac0;
+static char *os_drv_gmac0_name = "gmac0";
+#endif
+
+#ifdef BSP_USING_GMAC1
+struct drv_gmac os_drv_gmac1;
+static char *os_drv_gmac1_name = "gmac1";
+
+#endif
+
+static int rt_hw_gmac_init(struct drv_gmac *pOsMac, const char *name)
+{
+ rt_err_t state = RT_EOK;
+ // rt_thread_t tid;
+ rt_gmacmem_free(pOsMac);
+ rt_gmacmem_create(pOsMac);
+
+ pOsMac->eth_speed = GMAC_SPEED_1000M;
+ pOsMac->eth_mode = GMAC_MODE_FULLDUPLEX;
+
+ pOsMac->parent.parent.init = rt_ft2004_gmac_init;
+ pOsMac->parent.parent.open = rt_ft2004_gmac_open;
+ pOsMac->parent.parent.close = rt_ft2004_gmac_close;
+ pOsMac->parent.parent.read = rt_ft2004_gmac_read;
+ pOsMac->parent.parent.write = rt_ft2004_gmac_write;
+ pOsMac->parent.parent.control = rt_ft2004_gmac_control;
+ pOsMac->parent.parent.user_data = RT_NULL;
+
+ pOsMac->parent.eth_rx = rt_ft2004_gmac_rx;
+ pOsMac->parent.eth_tx = rt_ft2004_gmac_tx;
+ Ft_Gmac_UseDefaultMacAddr(&pOsMac->Gmac, pOsMac->dev_addr);
+ state = rt_event_init(&pOsMac->link_event, name, RT_IPC_FLAG_FIFO);
+ LOG_I("rt_event_init is ok \r\n");
+ if (RT_EOK != state)
+ {
+ rt_kprintf("init gmac0 event failed.\n");
+ return -RT_ERROR;
+ }
+
+ /* register eth device */
+ state = eth_device_init(&(pOsMac->parent), name);
+ if (RT_EOK != state)
+ {
+ LOG_E("gmac device init faild: %d", state);
+ return -RT_ERROR;
+ }
+
+ state = rt_thread_init(&pOsMac->_link_thread,
+ name,
+ ethernet_link_thread,
+ pOsMac,
+ &pOsMac->_link_thread_stack[0],
+ sizeof(pOsMac->_link_thread_stack),
+ 10, 2);
+
+ if (RT_EOK == state)
+ {
+ rt_thread_startup(&pOsMac->_link_thread);
+ }
+ else
+ {
+ LOG_E("rt_thread_init is error");
+ return -RT_ERROR;
+ }
+
+ return RT_EOK;
+}
+
+static int rt_hw_ft2004_eth_init(void)
+{
+ rt_err_t state = RT_EOK;
+
+#ifdef BSP_USING_GMAC0
+ os_drv_gmac0.Gmac.Config.InstanceId = 0;
+ state = rt_hw_gmac_init(&os_drv_gmac0, os_drv_gmac0_name);
+ if (RT_EOK != state)
+ {
+ goto __exit;
+ }
+#endif
+
+#ifdef BSP_USING_GMAC1
+ os_drv_gmac1.Gmac.Config.InstanceId = 1;
+ state = rt_hw_gmac_init(&os_drv_gmac1, os_drv_gmac1_name);
+ if (RT_EOK != state)
+ {
+ goto __exit;
+ }
+#endif
+
+__exit:
+ return state;
+}
+
+INIT_DEVICE_EXPORT(rt_hw_ft2004_eth_init);
+
+#endif
diff --git a/bsp/ft2004/drivers/drv_eth.h b/bsp/ft2004/drivers/drv_eth.h
new file mode 100644
index 0000000000..ed68b71728
--- /dev/null
+++ b/bsp/ft2004/drivers/drv_eth.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-03-09 Carl the first version
+ */
+#ifndef __DRV_ETH_H__
+#define __DRV_ETH_H__
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define FT_NETIF_LINKUP 0x1U
+#define FT_NETIF_DOWN 0x2U
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // !
diff --git a/bsp/ft2004/drivers/drv_log.h b/bsp/ft2004/drivers/drv_log.h
new file mode 100644
index 0000000000..3fe511789b
--- /dev/null
+++ b/bsp/ft2004/drivers/drv_log.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2018-11-15 SummerGift first version
+ */
+
+/*
+ * NOTE: DO NOT include this file on the header file.
+ */
+
+#ifndef LOG_TAG
+#define DBG_TAG "drv"
+#else
+#define DBG_TAG LOG_TAG
+#endif /* LOG_TAG */
+
+#ifdef DRV_DEBUG
+#define DBG_LVL DBG_LOG
+#else
+#define DBG_LVL DBG_INFO
+#endif /* DRV_DEBUG */
+
+#include <rtdbg.h>
diff --git a/bsp/ft2004/drivers/drv_qspi.c b/bsp/ft2004/drivers/drv_qspi.c
new file mode 100644
index 0000000000..9c5cbf4a9f
--- /dev/null
+++ b/bsp/ft2004/drivers/drv_qspi.c
@@ -0,0 +1,424 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-04-11 Carl the first version
+ */
+
+#include "drv_qspi.h"
+#include <rtthread.h>
+#include "rtdevice.h"
+#include "ft_qspi.h"
+#include "ft_parameters.h"
+
+#ifdef BSP_USE_QSPI
+
+#define DRV_DEBUG
+#define LOG_TAG "drv.qspi"
+#include <drv_log.h>
+
+struct ft2004_qspi_bus
+{
+ FQSpi_t fqspi;
+ char *name;
+ rt_uint32_t init; /* 1 is init already */
+};
+
+static struct rt_spi_bus _qspi_bus;
+static struct ft2004_qspi_bus _ft2004_qspi_bus;
+
+static int ft2004_qspi_init(struct rt_qspi_device *device, struct rt_qspi_configuration *qspi_cfg)
+{
+
+ RT_ASSERT(device != RT_NULL);
+ RT_ASSERT(qspi_cfg != RT_NULL);
+
+ // struct rt_spi_configuration *cfg = &qspi_cfg->parent;
+ struct ft2004_qspi_bus *qspi_bus_p = device->parent.bus->parent.user_data;
+
+ if (qspi_bus_p->init == 0)
+ {
+ qspi_bus_p->init = 1;
+ FQSpi_CfgInitialize(&qspi_bus_p->fqspi, FQSpi_LookupConfig(0));
+ }
+
+ return RT_EOK;
+}
+
+static rt_err_t ft2004_cmdOperation(struct ft2004_qspi_bus *qspi_bus_p, struct rt_spi_message *message)
+{
+ struct rt_qspi_message *qspi_message = (struct rt_qspi_message *)message;
+ const rt_uint8_t *sndb = message->send_buf;
+ rt_uint8_t *rcvb = message->recv_buf;
+ ft_error_t ret;
+ RT_ASSERT(qspi_bus_p != RT_NULL);
+ RT_ASSERT(message != RT_NULL);
+
+ struct FQSpi_CmdPack cmd_pack = {0};
+
+ if (qspi_message->instruction.qspi_lines == 0)
+ {
+ LOG_E("instruction is not valid");
+ return RT_ERROR;
+ }
+
+ cmd_pack.cmd = qspi_message->instruction.content;
+
+ if (qspi_message->address.qspi_lines != 0)
+ {
+ cmd_pack.flags |= FQSPI_CMD_NEED_ADDR_MASK;
+ cmd_pack.addr = qspi_message->address.content;
+ }
+
+ if (qspi_message->address.size == 24)
+ {
+ cmd_pack.flags |= FQSPI_CMD_ADDRESS_3BYTE_MASK;
+ }
+ else if (qspi_message->address.size == 32)
+ {
+ cmd_pack.flags |= FQSPI_CMD_ADDRESS_4BYTE_MASK;
+ }
+
+ if (qspi_message->qspi_data_lines != 0)
+ {
+ if (sndb && (message->length > 0))
+ {
+ cmd_pack.flags |= FQSPI_CMD_NEED_SET_MASK;
+ cmd_pack.txBuf = sndb;
+ cmd_pack.length = message->length;
+ }
+ else if (rcvb && (message->length > 0))
+ {
+ cmd_pack.flags |= FQSPI_CMD_NEED_GET_MASK;
+ cmd_pack.rxBuf = rcvb;
+ cmd_pack.length = message->length;
+ }
+ else
+ {
+ cmd_pack.flags &= ~(FQSPI_CMD_NEED_GET_MASK | FQSPI_CMD_NEED_SET_MASK);
+ }
+ }
+
+ if (qspi_message->dummy_cycles)
+ {
+ cmd_pack.flags |= FQSPI_CMD_NEED_DUMMY_MASK;
+ cmd_pack.dummyCycle = qspi_message->dummy_cycles;
+ }
+
+ if (cmd_pack.cmd == 0x20)
+ {
+ if (qspi_message->address.size == 32)
+ {
+ cmd_pack.cmd = 0xdc;
+ }
+ }
+
+#ifdef BSP_QSPI_DEBUG
+ LOG_I("flags %x", cmd_pack.flags);
+#endif
+
+ ret = FQSpi_CmdOperation(&qspi_bus_p->fqspi, &cmd_pack);
+
+#ifdef BSP_QSPI_DEBUG
+ if (ret == FQSPI_SUCCESS)
+ if (cmd_pack.cmd == 5)
+ {
+ LOG_I("cmd05 0x%x", cmd_pack.rxBuf[0]);
+ }
+#endif
+
+ return (ret == FQSPI_SUCCESS) ? RT_EOK : RT_ERROR;
+}
+
+static rt_uint32_t ft2004_qspi_xfer(struct ft2004_qspi_bus *qspi_bus_p, struct rt_spi_message *message)
+{
+ struct rt_qspi_message *qspi_message = (struct rt_qspi_message *)message;
+ rt_uint32_t ret_length = 0;
+ const rt_uint8_t *sndb = message->send_buf;
+ rt_uint8_t *rcvb = message->recv_buf;
+ rt_int32_t length = message->length;
+ rt_uint32_t cmd;
+ rt_uint32_t addr;
+ FQSpi_t *qspi_p;
+ FQSpi_Config_t *qspi_config_p;
+ struct FQSpi_DataPack data_pack = {0};
+ qspi_p = &qspi_bus_p->fqspi;
+ qspi_config_p = &qspi_bus_p->fqspi.config;
+
+ cmd = qspi_message->instruction.content;
+ addr = qspi_message->address.content;
+
+#ifdef BSP_QSPI_DEBUG
+ LOG_I("cmd is %x ", cmd);
+ LOG_I("length %d , rcvb %x sndb %x addr %x dummy_cycles %x ", length, rcvb, sndb, addr, qspi_message->dummy_cycles);
+#endif
+
+ if (qspi_config_p->channel >= FT_QSPI_MAX_CS_NUM)
+ {
+ LOG_E("invalid channel[%x] ", qspi_config_p->channel);
+ return RT_ERROR;
+ }
+ switch (cmd)
+ {
+ case FQSPI_FLASH_CMD_PP:
+ {
+ if (RT_NULL != sndb)
+ {
+ data_pack.cmd = cmd;
+ data_pack.addr = addr;
+ if (qspi_message->address.size == 24)
+ {
+ data_pack.flags |= FQSPI_DATA_ADDRESS_3BYTE_MASK;
+ }
+ else
+ {
+ data_pack.flags |= FQSPI_DATA_ADDRESS_4BYTE_MASK;
+ }
+
+ LOG_E("write flags %x ", data_pack.flags);
+ data_pack.txBuf = sndb;
+ data_pack.length = length;
+ ret_length = ((FQSpi_Write(qspi_p, &data_pack) == FQSPI_SUCCESS) ? length : 0);
+ }
+ else
+ {
+ LOG_E("pp cmd %x sndb is null", cmd);
+ ret_length = 0;
+ }
+ }
+ break;
+ case FQSPI_FLASH_CMD_WRDI: /* for sufd qspi fast read */
+ FQSpi_FlashRegSet(qspi_p, cmd, RT_NULL, 0);
+ case FQSPI_FLASH_CMD_READ:
+ {
+ if (RT_NULL != rcvb)
+ {
+ data_pack.cmd = FQSPI_FLASH_CMD_READ;
+ data_pack.addr = addr;
+ if (qspi_message->address.size == 24)
+ {
+ data_pack.flags |= FQSPI_DATA_ADDRESS_3BYTE_MASK;
+ }
+ else
+ {
+ data_pack.flags |= FQSPI_DATA_ADDRESS_4BYTE_MASK;
+ }
+
+ if (qspi_message->dummy_cycles)
+ {
+ data_pack.flags |= FQSPI_DATA_NEED_DUMMY_MASK;
+ data_pack.dummyCycle = qspi_message->dummy_cycles;
+ }
+ data_pack.rxBuf = rcvb;
+ data_pack.length = length;
+
+ ret_length = ((FQSpi_Read(qspi_p, &data_pack) == FQSPI_SUCCESS) ? length : 0);
+ }
+ else
+ {
+ // LOG_E("read cmd %x rcvb is null", cmd);
+ ret_length = 0;
+ }
+ }
+ break;
+
+ default:
+ {
+ if (ft2004_cmdOperation(qspi_bus_p, message) == RT_EOK)
+ {
+ ret_length = 1;
+ }
+ else
+ {
+ LOG_E("ft2004_cmdOperation error");
+ ret_length = 0;
+ }
+ }
+ }
+
+ return ret_length;
+}
+
+static rt_uint32_t qspixfer(struct rt_spi_device *device, struct rt_spi_message *message)
+{
+ RT_ASSERT(device != RT_NULL);
+ RT_ASSERT(device->bus != RT_NULL);
+ struct ft2004_qspi_bus *qspi_bus_p = device->bus->parent.user_data;
+
+ return ft2004_qspi_xfer(qspi_bus_p, message);
+}
+
+static rt_err_t qspi_configure(struct rt_spi_device *device, struct rt_spi_configuration *configuration)
+{
+ RT_ASSERT(device != RT_NULL);
+ RT_ASSERT(configuration != RT_NULL);
+
+ struct rt_qspi_device *qspi_device = (struct rt_qspi_device *)device;
+ return ft2004_qspi_init(qspi_device, &qspi_device->config);
+}
+
+static const struct rt_spi_ops ft2004_qspi_ops =
+ {
+ .configure = qspi_configure,
+ .xfer = qspixfer,
+};
+
+static int ft2004_qspi_register_bus(struct ft2004_qspi_bus *qspi_bus, const char *name)
+{
+ RT_ASSERT(qspi_bus != RT_NULL);
+ RT_ASSERT(name != RT_NULL);
+
+ _qspi_bus.parent.user_data = qspi_bus;
+ return rt_qspi_bus_register(&_qspi_bus, name, &ft2004_qspi_ops);
+}
+
+rt_err_t ft2004_qspi_bus_attach_device(const char *bus_name, const char *device_name, rt_uint8_t data_line_width, void (*enter_qspi_mode)(), void (*exit_qspi_mode)())
+{
+ struct rt_qspi_device *qspi_device = RT_NULL;
+ rt_err_t result = RT_EOK;
+
+ RT_ASSERT(bus_name != RT_NULL);
+ RT_ASSERT(device_name != RT_NULL);
+ RT_ASSERT(data_line_width == 1 || data_line_width == 2 || data_line_width == 4);
+
+ qspi_device = (struct rt_qspi_device *)rt_malloc(sizeof(struct rt_qspi_device));
+ if (qspi_device == RT_NULL)
+ {
+ LOG_E("no memory, qspi bus attach device failed!");
+ result = RT_ENOMEM;
+ goto __exit;
+ }
+
+ qspi_device->enter_qspi_mode = enter_qspi_mode;
+ qspi_device->exit_qspi_mode = exit_qspi_mode;
+ qspi_device->config.qspi_dl_width = data_line_width;
+
+ result = rt_spi_bus_attach_device(&qspi_device->parent, device_name, bus_name, RT_NULL);
+
+__exit:
+ if (result != RT_EOK)
+ {
+ if (qspi_device)
+ {
+ rt_free(qspi_device);
+ }
+ }
+
+ return result;
+}
+
+static int rt_hw_qspi_bus_init(void)
+{
+ return ft2004_qspi_register_bus(&_ft2004_qspi_bus, FT2004_QSPI_NAME);
+}
+INIT_BOARD_EXPORT(rt_hw_qspi_bus_init);
+#ifdef BSP_QSPI_DEBUG
+static void cmd05_check(void)
+{
+ struct FQSpi_CmdPack cmd_pack = {0};
+ u8 rx_buffer[1];
+
+ cmd_pack.cmd = 0x6;
+ FQSpi_CmdOperation(&_ft2004_qspi_bus.fqspi, &cmd_pack);
+
+ rt_memset(&cmd_pack, 0, sizeof(&cmd_pack));
+ cmd_pack.cmd = 0x5;
+ cmd_pack.flags = FQSPI_CMD_NEED_GET_MASK;
+ cmd_pack.rxBuf = rx_buffer;
+ cmd_pack.length = sizeof(rx_buffer);
+
+ FQSpi_CmdOperation(&_ft2004_qspi_bus.fqspi, &cmd_pack);
+
+ for (u32 i = 0; i < cmd_pack.length; i++)
+ {
+ LOG_I("cnt %d, 0x%x ", i, rx_buffer[i]);
+ }
+
+ rt_memset(&cmd_pack, 0, sizeof(&cmd_pack));
+ cmd_pack.cmd = 0x4;
+ FQSpi_CmdOperation(&_ft2004_qspi_bus.fqspi, &cmd_pack);
+
+ rt_memset(&cmd_pack, 0, sizeof(&cmd_pack));
+ cmd_pack.cmd = 0x5;
+ cmd_pack.flags = FQSPI_CMD_NEED_GET_MASK;
+ cmd_pack.rxBuf = rx_buffer;
+ cmd_pack.length = sizeof(rx_buffer);
+
+ FQSpi_CmdOperation(&_ft2004_qspi_bus.fqspi, &cmd_pack);
+
+ for (u32 i = 0; i < cmd_pack.length; i++)
+ {
+ LOG_I("cnt %d, 0x%x ", i, rx_buffer[i]);
+ }
+}
+MSH_CMD_EXPORT_ALIAS(cmd05_check, cmd05_check, cmd05_check);
+#endif
+
+#ifdef BSP_QSPI_DEBUG
+static void cmd35_check(void)
+{
+ struct FQSpi_CmdPack cmd_pack = {0};
+ u8 rx_buffer[1];
+
+ cmd_pack.cmd = 0x6;
+ FQSpi_CmdOperation(&_ft2004_qspi_bus.fqspi, &cmd_pack);
+
+ rt_memset(&cmd_pack, 0, sizeof(&cmd_pack));
+ cmd_pack.cmd = 0x5;
+ cmd_pack.flags = FQSPI_CMD_NEED_GET_MASK;
+ cmd_pack.rxBuf = rx_buffer;
+ cmd_pack.length = sizeof(rx_buffer);
+
+ FQSpi_CmdOperation(&_ft2004_qspi_bus.fqspi, &cmd_pack);
+
+ for (u32 i = 0; i < cmd_pack.length; i++)
+ {
+ LOG_I("cnt %d, 0x%x ", i, rx_buffer[i]);
+ }
+
+ cmd_pack.cmd = 0xB7;
+ FQSpi_CmdOperation(&_ft2004_qspi_bus.fqspi, &cmd_pack);
+
+ rt_memset(&cmd_pack, 0, sizeof(&cmd_pack));
+ cmd_pack.cmd = 0x35;
+ cmd_pack.flags = FQSPI_CMD_NEED_GET_MASK;
+ cmd_pack.rxBuf = rx_buffer;
+ cmd_pack.length = sizeof(rx_buffer);
+
+ FQSpi_CmdOperation(&_ft2004_qspi_bus.fqspi, &cmd_pack);
+
+ for (u32 i = 0; i < cmd_pack.length; i++)
+ {
+ LOG_I("cnt %d, 0x%x ", i, rx_buffer[i]);
+ }
+}
+MSH_CMD_EXPORT_ALIAS(cmd35_check, cmd35_check, cmd35_check);
+#endif
+#ifdef BSP_QSPI_DEBUG
+static void cmd15_check(void)
+{
+ struct FQSpi_CmdPack cmd_pack = {0};
+ u8 rx_buffer[1];
+
+ // cmd_pack.cmd = 0xB7;
+ // FQSpi_CmdOperation(&_ft2004_qspi_bus.fqspi, &cmd_pack);
+
+ rt_memset(&cmd_pack, 0, sizeof(&cmd_pack));
+ cmd_pack.cmd = 0x15;
+ cmd_pack.flags = FQSPI_CMD_NEED_GET_MASK;
+ cmd_pack.rxBuf = rx_buffer;
+ cmd_pack.length = sizeof(rx_buffer);
+
+ FQSpi_CmdOperation(&_ft2004_qspi_bus.fqspi, &cmd_pack);
+
+ for (u32 i = 0; i < cmd_pack.length; i++)
+ {
+ LOG_I("cnt %d, 0x%x ", i, rx_buffer[i]);
+ }
+}
+MSH_CMD_EXPORT_ALIAS(cmd15_check, cmd15_check, cmd15_check);
+#endif
+#endif
diff --git a/bsp/ft2004/drivers/drv_qspi.h b/bsp/ft2004/drivers/drv_qspi.h
new file mode 100644
index 0000000000..29566f9af6
--- /dev/null
+++ b/bsp/ft2004/drivers/drv_qspi.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-04-11 Carl the first version
+ */
+
+#ifndef __DRT_QSPI_H__
+#define __DRT_QSPI_H__
+
+#include <rtthread.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define FT2004_QSPI_NAME "qspi"
+
+ rt_err_t ft2004_qspi_bus_attach_device(const char *bus_name, const char *device_name, rt_uint8_t data_line_width, void (*enter_qspi_mode)(), void (*exit_qspi_mode)());
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // !DRT_QSPI_H
diff --git a/bsp/ft2004/drivers/drv_qspi_flash.c b/bsp/ft2004/drivers/drv_qspi_flash.c
new file mode 100644
index 0000000000..102cd5fc5b
--- /dev/null
+++ b/bsp/ft2004/drivers/drv_qspi_flash.c
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-04-08 Carl the first version
+ */
+
+#include <board.h>
+#include <drv_qspi.h>
+#include <rtdevice.h>
+#include <rthw.h>
+#include <finsh.h>
+
+#ifdef BSP_USE_QSPI
+
+#include "spi_flash.h"
+#include "spi_flash_sfud.h"
+#define _QSPI_DEVICE_NAME "qspiflash"
+
+static int
+rt_hw_qspi_flash_with_sfud_init(void)
+{
+ ft2004_qspi_bus_attach_device(FT2004_QSPI_NAME, _QSPI_DEVICE_NAME, 1, RT_NULL, RT_NULL);
+
+ /* init gd */
+ rt_kprintf("start rt_sfud_flash_probe \r\n");
+ if (RT_NULL == rt_sfud_flash_probe("GD25LQ256D", _QSPI_DEVICE_NAME))
+ {
+ return -RT_ERROR;
+ }
+
+ return RT_EOK;
+}
+INIT_COMPONENT_EXPORT(rt_hw_qspi_flash_with_sfud_init);
+
+#endif /* BSP_USING_QSPI_FLASH */
diff --git a/bsp/ft2004/drivers/drv_sdcard.c b/bsp/ft2004/drivers/drv_sdcard.c
new file mode 100644
index 0000000000..a6494089f6
--- /dev/null
+++ b/bsp/ft2004/drivers/drv_sdcard.c
@@ -0,0 +1,154 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-03-18 Carl the first version
+ */
+
+#include <rtthread.h>
+
+#ifdef BSP_USING_SDC
+
+#include <dfs_elm.h>
+#include <dfs_fs.h>
+#include <dfs_posix.h>
+#include "drv_sdctrl.h"
+
+#define DBG_TAG "app.card"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
+
+static rt_err_t _sdcard_mount(void)
+{
+ rt_device_t device;
+
+ device = rt_device_find("sd0");
+ rt_kprintf("rt_device_find %x \r\n", device);
+ if (device == NULL)
+ {
+ mmcsd_wait_cd_changed(0);
+ ft2004_mmcsd_change();
+ if (mmcsd_wait_cd_changed(rt_tick_from_millisecond(5000)) == -RT_ETIMEOUT)
+ {
+ rt_kprintf("timeout \r\n");
+ return RT_ERROR;
+ }
+ device = rt_device_find("sd0");
+ }
+
+ rt_thread_mdelay(1000);
+ LOG_I("dfs_mount \r\n");
+ if (device != RT_NULL)
+ {
+ if (dfs_mount("sd0", "/", "elm", 0, 0) == RT_EOK)
+ {
+ LOG_I("sd card mount to '/'");
+ }
+ else
+ {
+ LOG_W("sd card mount to '/' failed!");
+ return RT_ERROR;
+ }
+ }
+
+ return RT_EOK;
+}
+
+static void _sdcard_unmount(void)
+{
+ rt_thread_mdelay(200);
+ dfs_unmount("/");
+ LOG_I("Unmount \"/\"");
+
+ mmcsd_wait_cd_changed(0);
+ ft2004_mmcsd_change();
+ mmcsd_wait_cd_changed(rt_tick_from_millisecond(5000));
+ LOG_I("Unmount is over \r\n");
+}
+
+static void sd_mount(void *parameter)
+{
+ rt_uint8_t state = 0; /* 1. is valid card ,0 is removal */
+#ifdef BSP_SDC_IRQ_CARD_REMOVE
+ rt_uint32_t status;
+#endif
+ while (1)
+ {
+ switch (state)
+ {
+ case 0:
+ if (ft2004_card_status() == 1)
+ {
+#ifdef BSP_SDC_IRQ_CARD_REMOVE
+ ft2004_card_remove_check(0, RT_NULL); /* Clear removal flag bit */
+#endif
+ if (_sdcard_mount() == RT_EOK)
+ {
+ state = 1;
+ }
+ else
+ {
+ /* For the critical case of frequent plug */
+ rt_kprintf("dfs_unmount \r\n");
+ _sdcard_unmount();
+ ft2004_sdctrl_reset();
+ }
+ }
+ else
+ {
+ rt_thread_mdelay(100);
+ }
+ break;
+ case 1:
+
+#ifdef BSP_SDC_IRQ_CARD_REMOVE
+ if (ft2004_card_remove_check(RT_WAITING_FOREVER, &status) == RT_EOK)
+ {
+ if (status & SDCTR_CARD_REMOVE_FLG)
+ {
+ state = 0;
+ _sdcard_unmount();
+ }
+ }
+#else
+ if (ft2004_card_status() == 0)
+ {
+ state = 0;
+ _sdcard_unmount();
+ }
+#endif
+ else
+ {
+ rt_thread_mdelay(100);
+ }
+ break;
+ default:
+ state = 0;
+ break;
+ }
+ }
+}
+
+int ft2004_sdcard_mount(void)
+{
+ rt_thread_t tid;
+
+ tid = rt_thread_create("sd_mount", sd_mount, RT_NULL,
+ 8192, 2, 20);
+
+ if (tid != RT_NULL)
+ {
+ rt_thread_startup(tid);
+ }
+ else
+ {
+ LOG_E("create sd_mount thread err!");
+ }
+ return RT_EOK;
+}
+INIT_APP_EXPORT(ft2004_sdcard_mount);
+
+#endif /* BSP_USING_SDCARD */
diff --git a/bsp/ft2004/drivers/drv_sdctrl.c b/bsp/ft2004/drivers/drv_sdctrl.c
new file mode 100644
index 0000000000..1f6a4df7e5
--- /dev/null
+++ b/bsp/ft2004/drivers/drv_sdctrl.c
@@ -0,0 +1,659 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-03-18 Carl the first version
+ */
+
+#include "drv_sdctrl.h"
+#include "ft_sdctrl_hw.h"
+#include "ft_sdctrl.h"
+#include "ft_debug.h"
+#include "ft_types.h"
+#include "ft_generic_timer.h"
+#include <drivers/mmcsd_core.h>
+#include "interrupt.h"
+#include "rtconfig.h"
+#include "ft_cache.h"
+
+#ifdef BSP_USING_SDC
+
+#define LOG_TAG "drv.sdmmc"
+#include <drv_log.h>
+
+#define RTHW_SDCTRL_LOCK(_sdctrl) rt_mutex_take(&_sdctrl->mutex, RT_WAITING_FOREVER)
+#define RTHW_SDCTRL_UNLOCK(_sdctrl) rt_mutex_release(&_sdctrl->mutex);
+
+struct mmcsd_pkg
+{
+ struct rt_mmcsd_cmd *cmd;
+ void *buff;
+ rt_uint32_t flag;
+};
+
+typedef struct
+{
+ FtsdCtrl_t ft_sdctrl;
+ struct rt_mmcsd_host *host;
+ struct rt_event event;
+ struct rt_mutex mutex;
+ struct mmcsd_pkg *pkg;
+} ft_sdctrl_class_t;
+
+ft_sdctrl_class_t sdctrl_class;
+
+ALIGN(SDCTR_ALIGN_LEN)
+static rt_uint8_t cache_buf[SDCTR_BUFF_SIZE];
+
+static void rthw_sdctrl_send_command(ft_sdctrl_class_t *class_p, struct mmcsd_pkg *pkg);
+
+static void demo_dump_sdc(void)
+{
+ Ft_DumpHexWord((const rt_uint32_t *)(0x28207C00), 256);
+}
+MSH_CMD_EXPORT_ALIAS(demo_dump_sdc, dump_sdc, output all dump_sdc);
+
+static void rthw_sdctrl_delay(u32 delayCnt)
+{
+ Ft_GenericTimer_UsDelay(delayCnt);
+}
+
+static u32 rthw_sdctrl_rasp2type(u32 rasp)
+{
+
+ switch (rasp)
+ {
+ case RESP_NONE:
+ return FTSDCTRL_CMD_RES_NONE;
+ case RESP_R2:
+ return FTSDCTRL_CMD_RES_LONG;
+ default:
+ return FTSDCTRL_CMD_RES_SHORT;
+ }
+
+ return FTSDCTRL_CMD_RES_SHORT;
+}
+
+static void rthw_sdctrl_transfer_by_dma(ft_sdctrl_class_t *class_p, struct mmcsd_pkg *pkg)
+{
+ struct rt_mmcsd_data *data;
+ struct rt_mmcsd_cmd *cmd;
+ u32 rasp;
+ u32 *buff;
+ FtsdCtrl_t *ft_sdctrl_p;
+
+ if ((RT_NULL == class_p))
+ {
+ LOG_E("rthw_sdctrl_transfer_by_dma invalid class_p");
+ return;
+ }
+ ft_sdctrl_p = &class_p->ft_sdctrl;
+
+ if ((RT_NULL == pkg))
+ {
+ LOG_E("rthw_sdctrl_transfer_by_dma invalid args");
+ return;
+ }
+
+ data = pkg->cmd->data;
+ if (RT_NULL == data)
+ {
+ LOG_E("rthw_sdctrl_transfer_by_dma invalid args");
+ return;
+ }
+
+ buff = pkg->buff;
+ if (RT_NULL == buff)
+ {
+ LOG_E("rthw_sdctrl_transfer_by_dma invalid args");
+ return;
+ }
+
+ cmd = pkg->cmd;
+ rasp = resp_type(pkg->cmd);
+ rasp = rthw_sdctrl_rasp2type(rasp);
+
+ if (data->flags & DATA_DIR_WRITE)
+ {
+#ifdef BSP_SDC_DEBUG_PRINT
+ rt_kprintf("DATA_DIR_WRITE %x \r\n", cmd->arg);
+#endif
+ FCache_cpuDcacheClean(buff, data->blks * data->blksize);
+
+ /* data, card, blk: card : data + blk */
+ FSdCtrl_WriteData(ft_sdctrl_p, (UINTPTR)buff, cmd->arg, data->blks);
+ cmd->err = FSdCtrl_WaitCmdEnd(ft_sdctrl_p, (pFtsdCtrl_delayTimer_t)rthw_sdctrl_delay, rasp, cmd->resp);
+
+#ifdef BSP_SDC_DEBUG_PRINT
+ for (int i = 0; i < 4; i++)
+ {
+ rt_kprintf("cmdRsp[%d] %x \r\n", i, cmd->resp[i]);
+ }
+ Ft_DumpHexWord(buff, 256);
+#endif
+ FSdCtrl_WaitWriteDataEnd(ft_sdctrl_p, (pFtsdCtrl_delayTimer_t)rthw_sdctrl_delay, data->blks);
+ FCache_cpuDcacheInvalidate(buff, data->blks * data->blksize);
+ }
+ else if (data->flags & DATA_DIR_READ)
+ {
+#ifdef BSP_SDC_DEBUG_PRINT
+ rt_kprintf("DATA_DIR_READ %x \r\n", cmd->arg);
+#endif
+ if ((cmd->flags & CMD_ADTC) && (data->blksize < 512))
+ {
+#ifdef BSP_SDC_DEBUG_PRINT
+ LOG_E("CMD_ADTC \r\n");
+#endif
+ FSdCtrl_DoACmd(ft_sdctrl_p, cmd->cmd_code, rasp, cmd->arg);
+ rt_thread_mdelay(10);
+ }
+
+ FCache_cpuDcacheInvalidate(buff, data->blks * data->blksize);
+ FSdCtrl_ReadData(ft_sdctrl_p, (UINTPTR)buff, cmd->arg, data->blks);
+ cmd->err = FSdCtrl_WaitCmdEnd(ft_sdctrl_p, (pFtsdCtrl_delayTimer_t)rthw_sdctrl_delay, rasp, cmd->resp);
+#ifdef BSP_SDC_DEBUG_PRINT
+ for (int i = 0; i < 4; i++)
+ {
+ rt_kprintf("cmdRsp[%d] %x \r\n", i, cmd->resp[i]);
+ }
+#endif
+ FSdCtrl_WaitReadDataEnd(ft_sdctrl_p, (pFtsdCtrl_delayTimer_t)rthw_sdctrl_delay, data->blks);
+ FCache_cpuDcacheClean(buff, data->blks * data->blksize);
+#ifdef BSP_SDC_DEBUG_PRINT
+ Ft_DumpHexWord(buff, data->blks * data->blksize);
+#endif
+ }
+}
+
+static void rthw_sdctrl_docmd(ft_sdctrl_class_t *class_p, struct mmcsd_pkg *pkg)
+{
+ struct rt_mmcsd_cmd *cmd;
+ u32 rasp;
+ FtsdCtrl_t *ft_sdctrl_p;
+
+ if ((RT_NULL == class_p))
+ {
+ LOG_E("rthw_sdctrl_docmd invalid class_p");
+ return;
+ }
+
+ ft_sdctrl_p = &class_p->ft_sdctrl;
+
+ if ((RT_NULL == pkg))
+ {
+ LOG_E("rthw_sdctrl_docmd invalid args");
+ return;
+ }
+
+ cmd = pkg->cmd;
+ rasp = resp_type(pkg->cmd);
+ rasp = rthw_sdctrl_rasp2type(rasp);
+ FSdCtrl_DoCmd(ft_sdctrl_p, pkg->cmd->cmd_code, rasp, cmd->arg);
+ cmd->err = FSdCtrl_WaitCmdEnd(ft_sdctrl_p, (pFtsdCtrl_delayTimer_t)rthw_sdctrl_delay, rasp, cmd->resp);
+
+#ifdef BSP_SDC_DEBUG_PRINT
+ for (int i = 0; i < 4; i++)
+ {
+ rt_kprintf("cmdRsp[%d] %x \r\n", i, cmd->resp[i]);
+ }
+#endif
+}
+
+static void rthw_sdctrl_send_command(ft_sdctrl_class_t *class_p, struct mmcsd_pkg *pkg)
+{
+ struct rt_mmcsd_cmd *cmd = pkg->cmd;
+ struct rt_mmcsd_data *data = cmd->data;
+ /* save pkg */
+ class_p->pkg = pkg;
+
+ /* config data reg */
+ if (data != RT_NULL && data->blks)
+ {
+ /* transfer config */
+ rthw_sdctrl_transfer_by_dma(class_p, pkg);
+ }
+ else
+ {
+ rthw_sdctrl_docmd(class_p, pkg);
+ }
+}
+
+/**
+ * @brief This function send sdio request.
+ * @param host rt_mmcsd_host
+ * @param req request
+ * @retval None
+ */
+static void rthw_sdctrl_request(struct rt_mmcsd_host *host, struct rt_mmcsd_req *req)
+{
+ struct mmcsd_pkg pkg;
+ ft_sdctrl_class_t *class_p = host->private_data;
+ struct rt_mmcsd_data *data;
+
+ RTHW_SDCTRL_LOCK(class_p);
+ if (req->cmd != RT_NULL)
+ {
+ rt_memset(&pkg, 0, sizeof(pkg));
+ data = req->cmd->data;
+ pkg.cmd = req->cmd;
+
+ if (pkg.cmd->cmd_code == 5 || pkg.cmd->cmd_code == 1)
+ {
+ rt_kprintf("cmd_code is not vaild %x \r\n", pkg.cmd->cmd_code);
+ pkg.cmd->err = RT_EINVAL;
+ goto _exit;
+ }
+
+#ifdef BSP_SDC_DEBUG_PRINT
+ struct rt_mmcsd_cmd *cmd;
+ cmd = req->cmd;
+ LOG_E("CMD:%d ARG:0x%08x RES:%s%s%s%s%s%s%s%s%s rw:%c len:%d blksize:%d",
+ 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->blks * data->blksize : 0,
+ data ? data->blksize : 0);
+#endif
+
+ if (data != RT_NULL)
+ {
+ rt_uint32_t size = data->blks * data->blksize;
+
+ RT_ASSERT(size <= SDCTR_BUFF_SIZE);
+ pkg.buff = data->buf;
+ if ((rt_uint32_t)data->buf & (SDCTR_ALIGN_LEN - 1))
+ {
+ pkg.buff = cache_buf;
+ if (data->flags & DATA_DIR_WRITE)
+ {
+ rt_memcpy(cache_buf, data->buf, size);
+ }
+ }
+ }
+
+ rthw_sdctrl_send_command(class_p, &pkg);
+
+ if ((data != RT_NULL) && (data->flags & DATA_DIR_READ) && ((rt_uint32_t)data->buf & (SDCTR_ALIGN_LEN - 1)))
+ {
+ rt_memcpy(data->buf, cache_buf, data->blksize * data->blks);
+ }
+ }
+
+ if (req->stop != RT_NULL)
+ {
+ rt_memset(&pkg, 0, sizeof(pkg));
+ pkg.cmd = req->stop;
+ rthw_sdctrl_send_command(class_p, &pkg);
+ }
+
+_exit:
+
+ RTHW_SDCTRL_UNLOCK(class_p);
+ mmcsd_req_complete(class_p->host);
+}
+
+static void rthw_sdctrl_clk_divider(struct rt_mmcsd_host *host, struct rt_mmcsd_io_cfg *io_cfg)
+{
+ ft_sdctrl_class_t *class_p = host->private_data;
+ FtsdCtrl_t *sd_ctrl = &(class_p->ft_sdctrl);
+
+ /* bus mode is pull push */
+ FSdCtrl_ClkFreqSetup(sd_ctrl, io_cfg->clock);
+ return;
+}
+
+static void rthw_sdctrl_iocfg(struct rt_mmcsd_host *host, struct rt_mmcsd_io_cfg *io_cfg)
+{
+ ft_sdctrl_class_t *class_p = host->private_data;
+ RTHW_SDCTRL_LOCK(class_p);
+
+ /* calculate and set clk divider */
+ rthw_sdctrl_clk_divider(host, io_cfg);
+
+ RTHW_SDCTRL_UNLOCK(class_p);
+}
+
+rt_int32_t rthw_sdctrl_detect(struct rt_mmcsd_host *host)
+{
+ ft_sdctrl_class_t *class_p = host->private_data;
+
+ return FSdCtrl_CardDetect(&class_p->ft_sdctrl);
+}
+
+static const struct rt_mmcsd_host_ops ops =
+ {
+ rthw_sdctrl_request,
+ rthw_sdctrl_iocfg,
+ rthw_sdctrl_detect,
+ RT_NULL,
+};
+
+void rthw_sdctrl_nomarl_callback(void *args)
+{
+ FtsdCtrl_t *pFtsdCtrl = (FtsdCtrl_t *)args;
+ rt_uint32_t status;
+ ft_sdctrl_class_t *class_p;
+ if (RT_NULL == pFtsdCtrl)
+ {
+ return;
+ }
+
+ class_p = rt_container_of(pFtsdCtrl, ft_sdctrl_class_t, ft_sdctrl);
+
+ status = FSdCtrl_GetNormalIrqStatus(pFtsdCtrl);
+
+ if (status & NORMAL_INT_STATUS_CR)
+ {
+ rt_event_send(&class_p->event, SDCTR_CARD_REMOVE_FLG);
+ }
+ else if (status & NORMAL_INT_STATUS_CC)
+ {
+ rt_event_send(&class_p->event, SDCTR_CMD_IS_COMPLETE_FLG);
+ }
+ else if (status & NORMAL_INT_STATUS_EI)
+ {
+ rt_event_send(&class_p->event, SDCTR_CMD_IS_ERROR_FLG);
+ }
+
+ return;
+}
+
+void rthw_sdctrl_dma_callback(void *args)
+{
+ FtsdCtrl_t *pFtsdCtrl = (FtsdCtrl_t *)args;
+ rt_uint32_t status;
+ ft_sdctrl_class_t *class_p;
+
+ if (RT_NULL == pFtsdCtrl)
+ {
+ return;
+ }
+
+ class_p = rt_container_of(pFtsdCtrl, ft_sdctrl_class_t, ft_sdctrl);
+
+ status = FSdCtrl_GetDataIrqStatus(pFtsdCtrl);
+
+ if (status & BD_ISR_REG_TRS)
+ {
+ /* send write complete event */
+ rt_event_send(&class_p->event, SDCTR_WRITE_IS_COMPLETE_FLG);
+ }
+
+ if (status & BD_ISR_REG_RESPE)
+ {
+ /* send read complete event */
+ rt_event_send(&class_p->event, SDCTR_READ_IS_COMPLETE_FLG);
+ }
+
+ if (status & BD_ISR_REG_DAIS)
+ {
+ /* send dma errror event */
+ rt_event_send(&class_p->event, SDCTR_DMA_IS_ERROR_FLG);
+ }
+}
+
+void rthw_sdctrl_error_callback(void *args)
+{
+ FtsdCtrl_t *pFtsdCtrl = (FtsdCtrl_t *)args;
+ rt_uint32_t status;
+ ft_sdctrl_class_t *class_p;
+
+ if (RT_NULL == pFtsdCtrl)
+ {
+ return;
+ }
+
+ class_p = rt_container_of(pFtsdCtrl, ft_sdctrl_class_t, ft_sdctrl);
+
+ status = FSdCtrl_GetErrorIrqStatus(pFtsdCtrl);
+
+ if (status & SDCTR_CMD_TIMEOUT_FLG)
+ {
+ rt_event_send(&class_p->event, SDCTR_CMD_TIMEOUT_FLG);
+ }
+
+ if (status & ERROR_INT_EN_CNR)
+ {
+ rt_event_send(&class_p->event, SDCTR_CMD_RECEIVE_IS_ERROR_FLG);
+ }
+
+ if (status & ERROR_INT_EN_CCRCE)
+ {
+ rt_event_send(&class_p->event, SDCTR_CMD_CRC_IS_ERROR_FLG);
+ }
+}
+
+void rthw_sdctrl_normal_irq(int vector, void *param)
+{
+ FtsdCtrl_t *pFtsdCtrl = (FtsdCtrl_t *)param;
+ FSdCtrl_NormalIrq(pFtsdCtrl);
+}
+
+void rthw_sdctrl_dma_irq(int vector, void *param)
+{
+ FtsdCtrl_t *pFtsdCtrl = (FtsdCtrl_t *)param;
+ FSdCtrl_DmaIrq(pFtsdCtrl);
+}
+
+void rthw_sdctrl_err_irq(int vector, void *param)
+{
+ FtsdCtrl_t *pFtsdCtrl = (FtsdCtrl_t *)param;
+ FSdCtrl_ErrIrq(pFtsdCtrl);
+}
+
+ft_error_t rthw_sdctrl_cmd_wait(FtsdCtrl_t *pFtsdCtrl)
+{
+ rt_uint32_t status;
+ ft_sdctrl_class_t *class_p;
+
+ if (RT_NULL == pFtsdCtrl)
+ {
+ return FTSDC_INVALID_PARAM;
+ }
+
+ class_p = rt_container_of(pFtsdCtrl, ft_sdctrl_class_t, ft_sdctrl);
+
+ if (rt_event_recv(&class_p->event, SDCTR_CMD_IS_COMPLETE_FLG | SDCTR_CMD_IS_ERROR_FLG | SDCTR_CMD_CRC_IS_ERROR_FLG, RT_EVENT_FLAG_CLEAR | RT_EVENT_FLAG_OR,
+ rt_tick_from_millisecond(50000), &status) != RT_EOK)
+ {
+ /* wait cmd completed timeout */
+ LOG_E("wait cmd completed timeout");
+ return FTSDC_TIMEOUT;
+ }
+
+ if (SDCTR_CMD_IS_COMPLETE_FLG == (status & SDCTR_CMD_IS_COMPLETE_FLG))
+ {
+ return FTSDC_SUCCESS;
+ }
+ else
+ {
+ LOG_E("wait cmd is error %x ", status);
+ return FTSDC_FAILURE;
+ }
+}
+
+ft_error_t rthw_sdctrl_read_wait(FtsdCtrl_t *pFtsdCtrl)
+{
+ rt_uint32_t status;
+ ft_sdctrl_class_t *class_p;
+
+ if (RT_NULL == pFtsdCtrl)
+ {
+ return FTSDC_INVALID_PARAM;
+ }
+
+ class_p = rt_container_of(pFtsdCtrl, ft_sdctrl_class_t, ft_sdctrl);
+
+ if (rt_event_recv(&class_p->event, SDCTR_READ_IS_COMPLETE_FLG | SDCTR_CMD_RECEIVE_IS_ERROR_FLG,
+ RT_EVENT_FLAG_CLEAR | RT_EVENT_FLAG_OR,
+ rt_tick_from_millisecond(50000), &status) != RT_EOK)
+ {
+ /* wait read completed timeout */
+ LOG_E("wait read completed timeout");
+ return FTSDC_TIMEOUT;
+ }
+
+ if (SDCTR_READ_IS_COMPLETE_FLG == (status & SDCTR_READ_IS_COMPLETE_FLG))
+ {
+ return FTSDC_SUCCESS;
+ }
+ else
+ {
+ LOG_E("wait read is error %x ", status);
+ return FTSDC_FAILURE;
+ }
+}
+
+ft_error_t rthw_sdctrl_write_wait(FtsdCtrl_t *pFtsdCtrl)
+{
+ rt_uint32_t status;
+ ft_sdctrl_class_t *class_p;
+
+ if (RT_NULL == pFtsdCtrl)
+ {
+ return FTSDC_INVALID_PARAM;
+ }
+
+ class_p = rt_container_of(pFtsdCtrl, ft_sdctrl_class_t, ft_sdctrl);
+
+ if (rt_event_recv(&class_p->event, SDCTR_WRITE_IS_COMPLETE_FLG, RT_EVENT_FLAG_CLEAR | RT_EVENT_FLAG_OR,
+ rt_tick_from_millisecond(50000), &status) != RT_EOK)
+ {
+ /* wait write completed timeout */
+ LOG_E("wait write completed timeout");
+ return FTSDC_TIMEOUT;
+ }
+
+ if (SDCTR_WRITE_IS_COMPLETE_FLG == (status & SDCTR_WRITE_IS_COMPLETE_FLG))
+ {
+ return FTSDC_SUCCESS;
+ }
+ else
+ {
+ LOG_E("wait write is error %x ", status);
+ return FTSDC_FAILURE;
+ }
+}
+
+static rt_err_t rthw_sdctrl_create(ft_sdctrl_class_t *class_p)
+{
+ struct rt_mmcsd_host *host;
+
+ host = mmcsd_alloc_host();
+ if (host == RT_NULL)
+ {
+ LOG_E("L:%d F:%s mmcsd alloc host fail");
+ return RT_ENOMEM;
+ }
+
+ class_p->ft_sdctrl.config = *(FSdCtrl_Config_t *)FSdCtrl_LookupConfig(0);
+ rt_event_init(&class_p->event, "sdctrl", RT_IPC_FLAG_FIFO);
+ rt_mutex_init(&class_p->mutex, "sdctrl", RT_IPC_FLAG_FIFO);
+
+ class_p->host = host;
+ host->ops = &ops;
+ /* range of sd work speed */
+ host->freq_min = 400 * 1000;
+ host->freq_max = 48 * 1000000;
+ host->valid_ocr = 0X00FFFF80; /* The voltage range supported is 1.65v-3.6v */
+ host->flags = MMCSD_BUSWIDTH_4;
+ host->private_data = class_p;
+ /* ready to change */
+
+ return RT_EOK;
+}
+
+int rthw_sdctrl_init(void)
+{
+
+ FtsdCtrl_t *ft_sdctrl_p;
+#ifdef BSP_SDC_USE_IRQ
+ FSdCtrl_Config_t *config_p;
+ FSdCtrl_NormalIrqSelect_t normalIrqFlgs = 0;
+#endif
+
+ rt_kprintf("rthw_sdctrl_init \r\n");
+ RT_ASSERT(rthw_sdctrl_create(&sdctrl_class) == RT_EOK);
+ ft_sdctrl_p = &sdctrl_class.ft_sdctrl;
+
+ FSdCtrl_Reset(ft_sdctrl_p, (pFtsdCtrl_delayTimer_t)rthw_sdctrl_delay);
+ FsdCtrl_Init(ft_sdctrl_p);
+
+#ifdef BSP_SDC_USE_IRQ
+ config_p = &ft_sdctrl_p->config;
+#ifdef BSP_SDC_IRQ_CARD_REMOVE
+ normalIrqFlgs |= NORMAL_IRQ_CR;
+
+#endif
+ normalIrqFlgs |= NORMAL_IRQ_CC;
+ /* register handler、irq enable bit and wait callback */
+ FSdCtrl_SetHandler(ft_sdctrl_p, FTSDCTRL_CMDIRQID, rthw_sdctrl_nomarl_callback, ft_sdctrl_p);
+ FSdCtrl_NormalIrqSet(ft_sdctrl_p, normalIrqFlgs);
+ FSdCtrl_CmdWaitRegister(ft_sdctrl_p, rthw_sdctrl_cmd_wait);
+
+ FSdCtrl_SetHandler(ft_sdctrl_p, FTSDCTRL_DMADATAIRQID, rthw_sdctrl_dma_callback, ft_sdctrl_p);
+ FSdCtrl_BdIrqSet(ft_sdctrl_p, BD_IRQ_TRS | BD_IRQ_RESPE);
+ FSdCtrl_WriteWaitRegister(ft_sdctrl_p, rthw_sdctrl_write_wait);
+ FSdCtrl_ReadWaitRegister(ft_sdctrl_p, rthw_sdctrl_read_wait);
+
+ config_p->workMode = FTSDCTRL_CMD_IRQ_MASK | FTSDCTRL_DATA_WRITE_IRQ_MASK | FTSDCTRL_DATA_READ_IRQ_MASK;
+
+#else
+
+#endif
+
+ /* install normal irq */
+
+ rt_hw_interrupt_install(ft_sdctrl_p->config.normalIrqNum, rthw_sdctrl_normal_irq,
+ &sdctrl_class.ft_sdctrl, "normalIrq");
+ rt_hw_interrupt_umask(ft_sdctrl_p->config.normalIrqNum);
+
+ rt_hw_interrupt_install(ft_sdctrl_p->config.dmaIrqNum, rthw_sdctrl_dma_irq,
+ &sdctrl_class.ft_sdctrl, "dmaIrq");
+ rt_hw_interrupt_umask(ft_sdctrl_p->config.dmaIrqNum);
+
+ return 0;
+}
+
+INIT_DEVICE_EXPORT(rthw_sdctrl_init);
+
+void ft2004_mmcsd_change(void)
+{
+ mmcsd_change(sdctrl_class.host);
+}
+
+rt_bool_t ft2004_card_status(void)
+{
+ return FSdCtrl_CardDetect(&sdctrl_class.ft_sdctrl);
+}
+
+rt_err_t ft2004_card_remove_check(rt_int32_t timeout, rt_uint32_t *status)
+{
+ return rt_event_recv(&sdctrl_class.event, SDCTR_CARD_REMOVE_FLG, RT_EVENT_FLAG_CLEAR | RT_EVENT_FLAG_OR,
+ timeout, status);
+}
+
+void ft2004_sdctrl_reset(void)
+{
+ FSdCtrl_Reset(&sdctrl_class.ft_sdctrl, (pFtsdCtrl_delayTimer_t)rthw_sdctrl_delay);
+ FsdCtrl_Init(&sdctrl_class.ft_sdctrl);
+
+#ifdef BSP_SDC_USE_IRQ
+ FSdCtrl_NormalIrqSet(&sdctrl_class.ft_sdctrl, NORMAL_IRQ_CC | NORMAL_IRQ_CR | NORMAL_IRQ_EI);
+ FSdCtrl_BdIrqSet(&sdctrl_class.ft_sdctrl, BD_IRQ_TRS | BD_IRQ_RESPE);
+#endif
+}
+
+#endif
diff --git a/bsp/ft2004/drivers/drv_sdctrl.h b/bsp/ft2004/drivers/drv_sdctrl.h
new file mode 100644
index 0000000000..dba34f2525
--- /dev/null
+++ b/bsp/ft2004/drivers/drv_sdctrl.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-03-18 Carl the first version
+ */
+
+#ifndef __DRV_SDCTRL_H__
+#define __DRV_SDCTRL_H__
+
+#include <rtthread.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define SDCTR_CMD_IS_COMPLETE_FLG 0x1UL /* Command is complete */
+#define SDCTR_WRITE_IS_COMPLETE_FLG 0x2UL
+#define SDCTR_READ_IS_COMPLETE_FLG 0x4UL
+#define SDCTR_CMD_IS_ERROR_FLG 0x8UL
+#define SDCTR_CMD_CRC_IS_ERROR_FLG 0x10UL /* Command CRC error */
+#define SDCTR_DMA_IS_ERROR_FLG 0x20UL /* */
+#define SDCTR_CARD_REMOVE_FLG 0x40UL /* Card remove */
+#define SDCTR_CMD_TIMEOUT_FLG 0x70UL /* command timeout */
+#define SDCTR_CMD_RECEIVE_IS_ERROR_FLG 0x80UL /* CMD receive is error */
+
+#ifndef SDCTR_BUFF_SIZE
+#define SDCTR_BUFF_SIZE (512 * 128)
+#endif
+
+#ifndef SDCTR_ALIGN_LEN
+#define SDCTR_ALIGN_LEN (32)
+#endif
+
+ void ft2004_mmcsd_change(void);
+ rt_bool_t ft2004_card_status(void);
+ rt_err_t ft2004_card_remove_check(rt_int32_t timeout, rt_uint32_t *status);
+ void ft2004_sdctrl_reset(void);
+#ifdef __cplusplus
+}
+#endif
+
+#endif // !
diff --git a/bsp/ft2004/drivers/drv_spi.c b/bsp/ft2004/drivers/drv_spi.c
new file mode 100644
index 0000000000..0ac38709e4
--- /dev/null
+++ b/bsp/ft2004/drivers/drv_spi.c
@@ -0,0 +1,449 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-25 14:01:29
+ * @LastEditTime: 2021-05-26 15:42:52
+ * @Description:  This files is for
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "drv_spi.h"
+#include <rtthread.h>
+#include <rtdevice.h>
+#include <string.h>
+#include "ft_spi.h"
+#include "ft_mux.h"
+#include "ft_trace.h"
+#include "ft_generic_timer.h"
+
+#ifdef BSP_USE_SPI
+
+#define DRV_DEBUG
+#define LOG_TAG "drv.spi"
+#include <drv_log.h>
+
+typedef void (*spi_cs_handler_t)(const rt_bool_t select);
+typedef struct
+{
+ FSpi_Ctrl_t spi_ctrl;
+ struct rt_spi_bus spi_bus;
+ uint16_t spi_cs_pin;
+ spi_cs_handler_t spi_cs_handler;
+} ft2004_spi_class;
+
+void ft2004_spi_cs(const rt_bool_t select);
+static ft2004_spi_class spi_obj = {
+ .spi_cs_handler = ft2004_spi_cs,
+ .spi_ctrl = {
+ .CtrlId = SPI_CTRL_ID_0,
+ .DevId = SPI_DEV_ID_0,
+ .IsReady = FALSE,
+ .CsPin = 5, /* use pin 5 in gpio group a as cs signal pin */
+ },
+};
+static const FSpi_Conf_t spi_conf[NUM_OF_SPI_CTRL] =
+ {
+ {
+ .DevAddr = {0x00, 0x00, 0x00, 0x00},
+ .DevAddrLen = SPI_4_BYTE_ADDR,
+ .WorkMode = SPI_CTRL_MASTER_MODE,
+ /* mode 2 CPOL = 1, CPHA = 0 */
+ .Cpol = SPI_CTRL_CPOL_HIGH,
+ .Cpha = SPI_CTRL_CPHA_1EDGE,
+ .BaudRDiv = SPI_SCKDV_4,
+ },
+ {
+ .DevAddr = {0x00, 0x00, 0x00, 0x00},
+ .DevAddrLen = SPI_4_BYTE_ADDR,
+ .WorkMode = SPI_CTRL_MASTER_MODE,
+ .Cpol = SPI_CTRL_CPOL_HIGH,
+ .Cpha = SPI_CTRL_CPHA_1EDGE,
+ .BaudRDiv = SPI_SCKDV_MAX,
+ }};
+
+inline static ft2004_spi_class *ft2004_spi_get_class()
+{
+ return &spi_obj;
+}
+
+inline static FSpi_Ctrl_t *ft2004_spi_get_ctrl()
+{
+ return &(ft2004_spi_get_class()->spi_ctrl);
+}
+
+static const FSpi_Conf_t *ft2004_lookup_conf(FT_IN FSpi_CtrlId_t CtrlId)
+{
+ return &spi_conf[CtrlId];
+}
+
+void ft2004_spi_cs(const rt_bool_t select)
+{
+ FSpi_Ctrl_t *ctrl_p = ft2004_spi_get_ctrl();
+ FSpi_SelectSlave(ctrl_p, ctrl_p->DevId, (bool_t)select);
+}
+
+/**spi flash operations***/
+u32 ft2004_spi_transcation(const u8 tx_data, u8 *rx_data_p)
+{
+ FSpi_Ctrl_t *ctrl_p = ft2004_spi_get_ctrl();
+ u32 ret = ERR_SPI_OK;
+
+ ret = FSpi_ReadWriteByte(ctrl_p, tx_data, rx_data_p);
+ return ret;
+}
+/**spi flash operations***/
+
+static rt_err_t ft2004_spi_init(struct rt_spi_configuration *cfg)
+{
+ FSpi_Ctrl_t *ctrl_p = ft2004_spi_get_ctrl();
+ FSpi_DevId_t dev_id;
+ u32 ret = ERR_SPI_OK;
+
+ //RT_ASSERT(cfg != RT_NULL);
+ RT_ASSERT(ctrl_p != RT_NULL);
+ dev_id = ctrl_p->DevId;
+
+ /* get spi flash default config */
+ ctrl_p->Config = *(ft2004_lookup_conf(dev_id));
+
+ /* change config according to inputs, cfg could be RT_NULL */
+
+ /* reset ctrl block */
+ ctrl_p->IsReady = FALSE;
+
+ /* set spi pin mux */
+ Ft_setSpiMux(ctrl_p->CtrlId);
+
+ /* init spi ctrl */
+ ret = FSpi_Init(ctrl_p);
+
+ if (ERR_SPI_OK == ret)
+ {
+ return RT_EOK;
+ }
+ else
+ {
+ return -RT_ERROR;
+ }
+}
+
+static rt_uint32_t spi_xfer(struct rt_spi_device *device, struct rt_spi_message *message)
+{
+ rt_size_t message_length, loop;
+ rt_uint8_t *recv_buf;
+ const rt_uint8_t *send_buf;
+ u32 tx_rx_result = ERR_SPI_OK;
+ spi_cs_handler_t cs_handler = ft2004_spi_get_class()->spi_cs_handler;
+
+ RT_ASSERT(device != RT_NULL);
+ RT_ASSERT(device->bus != RT_NULL);
+ RT_ASSERT(device->bus->parent.user_data != RT_NULL);
+ RT_ASSERT(message != RT_NULL);
+
+ if (message->cs_take && cs_handler)
+ {
+ cs_handler(TRUE);
+ }
+
+ message_length = message->length;
+ recv_buf = message->recv_buf;
+ send_buf = message->send_buf;
+
+ /* handle msg */
+ for (loop = 0; loop < message_length; loop++)
+ {
+ /* start data exchange */
+ if ((message->recv_buf) && (message->send_buf))
+ {
+ /* need tx and rx */
+ tx_rx_result |= ft2004_spi_transcation(*send_buf, recv_buf);
+ send_buf++;
+ recv_buf++;
+ }
+ else if (message->send_buf)
+ {
+ /* tx only */
+ tx_rx_result |= ft2004_spi_transcation(*send_buf, RT_NULL);
+ send_buf++;
+ }
+ else
+ {
+ /* rx only */
+ tx_rx_result |= ft2004_spi_transcation(SPI_DUMMY_TX_DATA, recv_buf);
+ recv_buf++;
+ }
+ }
+
+ if (ERR_SPI_OK != tx_rx_result)
+ {
+ LOG_E("spi transfer error : 0x%x", tx_rx_result);
+ message->length = 0;
+ }
+ else
+ {
+ }
+
+ if (message->cs_release && cs_handler)
+ {
+ cs_handler(FALSE);
+ }
+
+ return message->length;
+}
+
+static rt_err_t spi_configure(struct rt_spi_device *device,
+ struct rt_spi_configuration *configuration)
+{
+ RT_ASSERT(device != RT_NULL);
+ RT_ASSERT(configuration != RT_NULL);
+
+ return ft2004_spi_init(configuration);
+}
+
+static const struct rt_spi_ops ft2004_spi_ops =
+ {
+ .configure = spi_configure,
+ .xfer = spi_xfer,
+};
+
+/**
+ * Attach the spi device to SPI bus, this function must be used after initialization.
+ */
+rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, uint16_t cs_gpio_pin)
+{
+ rt_err_t result;
+ struct rt_spi_device *spi_device;
+ ft2004_spi_class *spi_class = ft2004_spi_get_class();
+
+ RT_ASSERT(spi_class != RT_NULL);
+
+ spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device));
+ RT_ASSERT(spi_device != RT_NULL);
+
+ result = rt_spi_bus_attach_device(spi_device, device_name, bus_name, RT_NULL);
+
+ LOG_I("attach result 0x%x", result);
+
+ if (result != RT_EOK)
+ {
+ if (spi_device)
+ {
+ rt_free(spi_device);
+ }
+ }
+ return result;
+}
+
+static int rt_hw_spi_bus_init(void)
+{
+ rt_err_t result;
+ ft2004_spi_class *spi_class = ft2004_spi_get_class();
+
+ LOG_I("init spi ctrl");
+ spi_class->spi_bus.parent.user_data = &spi_class->spi_bus;
+ result = rt_spi_bus_register(&spi_class->spi_bus, SPI_BUS_NAME, &ft2004_spi_ops);
+ return result;
+}
+
+int rt_hw_spi_init(void)
+{
+ return rt_hw_spi_bus_init();
+}
+INIT_BOARD_EXPORT(rt_hw_spi_init);
+
+static void rthw_spi_delay(u32 delayCnt)
+{
+ Ft_GenericTimer_UsDelay(delayCnt);
+}
+
+/************spi flash operatiosn implemented for sample test****************/
+/* definition of s25fs maunfactor id */
+typedef struct
+{
+ u8 Mid;
+ u8 MemoryType;
+ u8 Density;
+ u8 RemainBytes;
+ u8 PhySectArch;
+ u8 FamilyID;
+} ft2004_manuid_t;
+
+/* definition of cmd for s25fs */
+#define S25FS_ENABLE_WR 0x06
+#define S25FS_DISABLE_WR 0x04
+#define S25FS_READ_ID 0x9F
+#define S25FS_READ_4BYTE_ADD 0x13
+#define S25FS_ERASE_4BYTE_ADD 0x21
+#define S25FS_READ_STATUS_1 0x05
+#define S25FS_READ_FLASH_PARAM 0x5A
+
+static void ft2004_dump_manuid(const ft2004_manuid_t *pId)
+{
+ rt_kprintf("0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\r\n",
+ pId->Mid, pId->MemoryType, pId->Density, pId->RemainBytes,
+ pId->PhySectArch, pId->FamilyID);
+}
+
+static u32 ft2004_read_in_4byte_addr(const u32 ReadAddr, const u32 BytesToRead, u8 *pBuf)
+{
+ u32 ret = ERR_SPI_OK;
+ u32 loop;
+
+ RT_ASSERT(RT_NULL != pBuf);
+
+ ft2004_spi_cs(TRUE);
+ ret |= ft2004_spi_transcation(S25FS_READ_4BYTE_ADD, RT_NULL);
+ /* only 4-bytes address, MSB first */
+ ret |= ft2004_spi_transcation((u8)(ReadAddr >> 24), RT_NULL);
+ ret |= ft2004_spi_transcation((u8)(ReadAddr >> 16), RT_NULL);
+ ret |= ft2004_spi_transcation((u8)(ReadAddr >> 8), RT_NULL);
+ ret |= ft2004_spi_transcation((u8)ReadAddr, RT_NULL);
+ /* read out data */
+ for (loop = 0; loop < BytesToRead; loop++)
+ {
+ ret |= ft2004_spi_transcation(SPI_DUMMY_TX_DATA, pBuf + loop);
+ if (ERR_SPI_OK != ret)
+ {
+ break;
+ }
+ }
+ ft2004_spi_cs(FALSE);
+ return ret;
+}
+
+u32 ft2004_spi_enable_wr(const bool_t enable)
+{
+ u32 ret = ERR_SPI_OK;
+ ft2004_spi_cs(TRUE);
+ if (enable)
+ {
+ ret |= ft2004_spi_transcation(S25FS_ENABLE_WR, RT_NULL);
+ }
+ else
+ {
+ ret |= ft2004_spi_transcation(S25FS_DISABLE_WR, RT_NULL);
+ }
+ ft2004_spi_cs(FALSE);
+ return ret;
+}
+
+u32 ft2004_erase_sector_in_4byte_addr(const u32 sector_addr)
+{
+ u32 Ret = ERR_SPI_OK;
+
+ ft2004_spi_enable_wr(TRUE);
+ LOG_I("erase sector 0x%x", Ret);
+ if (ERR_SPI_OK != Ret)
+ {
+ return Ret;
+ }
+
+ ft2004_spi_cs(TRUE);
+ Ret |= ft2004_spi_transcation(S25FS_ERASE_4BYTE_ADD, RT_NULL);
+ Ret |= ft2004_spi_transcation((u8)(sector_addr >> 24), RT_NULL);
+ Ret |= ft2004_spi_transcation((u8)(sector_addr >> 16), RT_NULL);
+ Ret |= ft2004_spi_transcation((u8)(sector_addr >> 8), RT_NULL);
+ Ret |= ft2004_spi_transcation((u8)(sector_addr), RT_NULL);
+ ft2004_spi_cs(FALSE);
+
+ return Ret;
+}
+
+u32 ft2004_spi_read_params(const u32 Addr)
+{
+ u32 Ret = ERR_SPI_OK;
+ u8 dat[8] = {0};
+ u32 loop;
+
+ ft2004_spi_cs(TRUE);
+ Ret |= ft2004_spi_transcation(S25FS_READ_FLASH_PARAM, RT_NULL);
+ Ret |= ft2004_spi_transcation((u8)(Addr >> 16), RT_NULL);
+ Ret |= ft2004_spi_transcation((u8)(Addr >> 8), RT_NULL);
+ Ret |= ft2004_spi_transcation((u8)(Addr), RT_NULL);
+ for (loop = 0; loop < 8; loop++)
+ {
+ Ret |= ft2004_spi_transcation(SPI_DUMMY_TX_DATA, dat + loop);
+ rt_kprintf("%d: 0x%x", loop, *(dat + loop));
+ }
+
+ ft2004_spi_cs(FALSE);
+ return Ret;
+}
+
+static u32 ft2004_spi_readid_for_test(ft2004_manuid_t *pId)
+{
+ FSpi_Ctrl_t *ctrl_p = ft2004_spi_get_ctrl();
+ u32 ret = ERR_SPI_OK;
+
+ if (!ctrl_p->IsReady)
+ {
+ return ERR_SPI_NOT_READY;
+ }
+
+ RT_ASSERT(RT_NULL != pId);
+
+ ft2004_spi_cs(TRUE);
+
+ /* shifting the command code “90H” followed by a 24-bit address */
+ ret |= ft2004_spi_transcation(S25FS_READ_ID, RT_NULL);
+
+ /* Manufacturer ID and the Device ID are shifted out */
+ ret |= ft2004_spi_transcation(SPI_DUMMY_TX_DATA, &pId->Mid);
+ ret |= ft2004_spi_transcation(SPI_DUMMY_TX_DATA, &pId->MemoryType);
+ ret |= ft2004_spi_transcation(SPI_DUMMY_TX_DATA, &pId->Density);
+ ret |= ft2004_spi_transcation(SPI_DUMMY_TX_DATA, &pId->RemainBytes);
+ ret |= ft2004_spi_transcation(SPI_DUMMY_TX_DATA, &pId->PhySectArch);
+ ret |= ft2004_spi_transcation(SPI_DUMMY_TX_DATA, &pId->FamilyID);
+ ft2004_spi_cs(FALSE);
+
+ if (ERR_SPI_OK == ret)
+ {
+ ft2004_dump_manuid(pId);
+ }
+
+ return ret;
+}
+
+static void spi_9f_s25fs_sample(int argc, char *argv[])
+{
+ ft2004_manuid_t dev_id;
+ u32 ret = ERR_SPI_OK;
+ u32 delay = SPI_TIMEOUT * 10;
+
+ rt_kprintf("test s25fs spi flash\r\n");
+ ret |= ft2004_spi_init(RT_NULL);
+ ret |= ft2004_spi_readid_for_test(&dev_id);
+
+ rt_kprintf("result is: 0x%x \r\n", ret);
+ while (--delay)
+ {
+ rthw_spi_delay(10);
+ }
+}
+MSH_CMD_EXPORT(spi_9f_s25fs_sample, "spi s25fs cmd 9fH sample");
+
+static u8 read_buf[256];
+static void spi_5a_s25fs_sample(int argc, char *argv[])
+{
+ u32 ret = ERR_SPI_OK;
+ u32 delay = SPI_TIMEOUT * 10;
+ u32 read_addr = 0x0000;
+
+ rt_kprintf("test s25fs spi flash\r\n");
+ ret |= ft2004_spi_init(RT_NULL);
+ ret |= ft2004_spi_read_params(read_addr);
+ ret |= ft2004_read_in_4byte_addr(read_addr, 256, read_buf);
+ rt_kprintf("result is: 0x%x \r\n", ret);
+ while (--delay)
+ {
+ rthw_spi_delay(10);
+ }
+}
+MSH_CMD_EXPORT(spi_5a_s25fs_sample, "spi s25fs cmd 5aH sample");
+
+#endif
diff --git a/bsp/ft2004/drivers/drv_spi.h b/bsp/ft2004/drivers/drv_spi.h
new file mode 100644
index 0000000000..5b31ab678c
--- /dev/null
+++ b/bsp/ft2004/drivers/drv_spi.h
@@ -0,0 +1,29 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-25 14:01:39
+ * @LastEditTime: 2021-04-29 09:40:13
+ * @Description:  This files is for
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+#ifndef FT_DRIVERS_RTT_SPI_H
+#define FT_DRIVERS_RTT_SPI_H
+
+#include <rtthread.h>
+
+#define SPI_BUS_NAME "spi0"
+#define SPI_DEV_NAME "S25FS256"
+
+rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, uint16_t cs_gpio_pin);
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#endif
diff --git a/bsp/ft2004/drivers/drv_spi_flash.c b/bsp/ft2004/drivers/drv_spi_flash.c
new file mode 100644
index 0000000000..26d8b44712
--- /dev/null
+++ b/bsp/ft2004/drivers/drv_spi_flash.c
@@ -0,0 +1,43 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-25 14:01:16
+ * @LastEditTime: 2021-04-30 14:43:12
+ * @Description:  This files is for
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include <board.h>
+#include <drv_spi.h>
+#include <rtdevice.h>
+#include <rthw.h>
+#include <finsh.h>
+#include "ft_spi.h"
+
+#ifdef BSP_USE_SPI
+
+#include "spi_flash.h"
+#include "spi_flash_sfud.h"
+
+static int rt_hw_spi_flash_init(void)
+{
+ uint16_t cs_pin = 5;
+ rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_DEV_NAME, cs_pin);
+
+ rt_kprintf("attach spi flash\r\n");
+ /* lookup flah */
+ if (RT_NULL == rt_sfud_flash_probe("S25FS256S", SPI_DEV_NAME))
+ {
+ rt_kprintf("attach spi flash failed\r\n");
+ return -RT_ERROR;
+ }
+
+ return RT_EOK;
+}
+INIT_COMPONENT_EXPORT(rt_hw_spi_flash_init);
+#endif
diff --git a/bsp/ft2004/drivers/drv_usart.c b/bsp/ft2004/drivers/drv_usart.c
new file mode 100644
index 0000000000..96ac3c97eb
--- /dev/null
+++ b/bsp/ft2004/drivers/drv_usart.c
@@ -0,0 +1,192 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-03-04 Carl the first version
+ */
+
+#include "board.h"
+#include "drv_usart.h"
+#include "interrupt.h"
+#include "serial.h"
+#include "rtconfig.h"
+
+#ifdef RT_USING_SERIAL
+
+extern u32 FUart_GetInterruptMask(Ft_Uart *uart_ptr);
+
+static void Ft_Os_Uart_Callback(void *Args, u32 Event, u32 EventData);
+
+static void rt_hw_uart_isr(int irqno, void *param)
+{
+ Ft_Uart *uart_ptr = (Ft_Uart *)param;
+ FUart_InterruptHandler(uart_ptr);
+}
+
+static rt_err_t uart_configure(struct rt_serial_device *serial, struct serial_configure *cfg)
+{
+ struct drv_usart *uart = RT_NULL;
+ Ft_Uart *uart_ptr = RT_NULL;
+ u32 RegTemp;
+ u32 ret;
+ RT_ASSERT(serial != RT_NULL);
+ RT_ASSERT(cfg != RT_NULL);
+ uart = rt_container_of(serial, struct drv_usart, serial);
+ uart_ptr = uart->handle;
+
+ RT_ASSERT(FUart_CfgInitialize(uart_ptr, FUart_LookupConfig(uart_ptr->Config.InstanceId)) == FST_SUCCESS);
+ FUart_SetHandler(uart_ptr, Ft_Os_Uart_Callback, serial);
+ rt_hw_interrupt_install(uart_ptr->Config.IsrNum, rt_hw_uart_isr, uart_ptr, "uart");
+ rt_hw_interrupt_umask(uart_ptr->Config.IsrNum);
+
+ //<! 设置波特率
+ ret = FUart_SetBaudRate(uart_ptr, cfg->baud_rate);
+ RT_ASSERT(ret == FST_SUCCESS);
+
+ //<! 打开接收中断
+ RegTemp = FUart_GetInterruptMask(uart_ptr);
+ RegTemp |= UARTMIS_RTMIS;
+ FUart_SetInterruptMask(uart_ptr, RegTemp);
+ FUart_SetOptions(uart_ptr, FUART_OPTION_UARTEN | FUART_OPTION_RXEN | FUART_OPTION_TXEN | FUART_OPTION_FIFOEN);
+ return RT_EOK;
+}
+
+static rt_err_t uart_control(struct rt_serial_device *serial, int cmd, void *arg)
+{
+ struct drv_usart *uart = RT_NULL;
+ Ft_Uart *uart_ptr = RT_NULL;
+ RT_ASSERT(serial != RT_NULL);
+
+ uart = rt_container_of(serial, struct drv_usart, serial);
+ uart_ptr = uart->handle;
+
+ switch (cmd)
+ {
+ case RT_DEVICE_CTRL_CLR_INT:
+ /* disable rx irq */
+ rt_hw_interrupt_mask(uart_ptr->Config.IsrNum);
+ break;
+
+ case RT_DEVICE_CTRL_SET_INT:
+ /* enable rx irq */
+ rt_hw_interrupt_umask(uart_ptr->Config.IsrNum);
+ break;
+ }
+
+ return RT_EOK;
+}
+
+static void Ft_Os_Uart_Callback(void *Args, u32 Event, u32 EventData)
+{
+ struct rt_serial_device *serial = (struct rt_serial_device *)Args;
+
+ if (FUART_EVENT_RECV_DATA == Event || FUART_EVENT_RECV_TOUT == Event)
+ {
+ rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_IND);
+ }
+ else if (FUART_EVENT_RECV_ERROR == Event)
+ {
+ }
+ else if (FUART_EVENT_SENT_DATA == Event)
+ {
+ }
+ else if (FUART_EVENT_PARE_FRAME_BRKE == Event)
+ {
+ }
+ else if (FUART_EVENT_RECV_ORERR == Event)
+ {
+ }
+
+ if (FUART_EVENT_SENT_DATA == Event)
+ {
+ }
+ else
+ {
+ }
+}
+
+static int uart_putc(struct rt_serial_device *serial, char c)
+{
+ struct drv_usart *uart = RT_NULL;
+ Ft_Uart *uart_ptr = RT_NULL;
+ RT_ASSERT(serial != RT_NULL);
+
+ uart = rt_container_of(serial, struct drv_usart, serial);
+ uart_ptr = uart->handle;
+
+ FUart_SendByte(uart_ptr->Config.BaseAddress, c);
+
+ return 1;
+}
+
+static int uart_getc(struct rt_serial_device *serial)
+{
+ int ch;
+ struct drv_usart *uart = RT_NULL;
+ Ft_Uart *uart_ptr = RT_NULL;
+ RT_ASSERT(serial != RT_NULL);
+
+ uart = rt_container_of(serial, struct drv_usart, serial);
+ uart_ptr = uart->handle;
+
+ ch = FUart_GetChar(uart_ptr->Config.BaseAddress);
+ if (ch == 0xff)
+ ch = -1;
+
+ return ch;
+}
+
+static const struct rt_uart_ops _uart_ops =
+ {
+ uart_configure,
+ uart_control,
+ uart_putc,
+ uart_getc,
+};
+
+#ifdef RT_USING_UART0
+static Ft_Uart Ft_Uart0;
+static struct drv_usart _RtUart0;
+#endif
+
+#ifdef RT_USING_UART1
+static Ft_Uart Ft_Uart1;
+static struct drv_usart _RtUart1;
+#endif
+
+int rt_hw_uart_init(void)
+{
+
+ struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
+
+#ifdef RT_USING_UART0
+ config.bufsz = RT_SERIAL_RB_BUFSZ;
+ _RtUart0.serial.ops = &_uart_ops;
+ _RtUart0.serial.config = config;
+ Ft_Uart0.Config.InstanceId = FT_UART0_ID;
+ _RtUart0.Handle = &Ft_Uart0;
+
+ rt_hw_serial_register(&_RtUart0.serial, "uart0",
+ RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
+ &_RtUart0);
+#endif
+
+#ifdef RT_USING_UART1
+ config.bufsz = RT_SERIAL_RB_BUFSZ;
+ _RtUart1.serial.ops = &_uart_ops;
+ _RtUart1.serial.config = config;
+ Ft_Uart1.Config.InstanceId = FT_UART1_ID;
+ _RtUart1.handle = &Ft_Uart1;
+ rt_hw_serial_register(&_RtUart1.serial, "uart1",
+ RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
+ &_RtUart1);
+#endif
+
+ return 0;
+}
+INIT_BOARD_EXPORT(rt_hw_uart_init);
+
+#endif /* RT_USING_SERIAL */
diff --git a/bsp/ft2004/drivers/drv_usart.h b/bsp/ft2004/drivers/drv_usart.h
new file mode 100644
index 0000000000..aff47caa29
--- /dev/null
+++ b/bsp/ft2004/drivers/drv_usart.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-03-04 Carl the first version
+ */
+
+#ifndef __DRV_USART_H__
+#define __DRV_USART_H__
+
+#include <rtthread.h>
+#include "rtdevice.h"
+#include "ft_uart.h"
+
+struct drv_usart
+{
+ Ft_Uart *handle;
+
+ struct rt_serial_device serial;
+};
+
+#endif // !
diff --git a/bsp/ft2004/drivers/ft2004.c b/bsp/ft2004/drivers/ft2004.c
new file mode 100644
index 0000000000..da04993276
--- /dev/null
+++ b/bsp/ft2004/drivers/ft2004.c
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-04-29 Carl the first version
+ *
+ */
+
+#include <rtthread.h>
+#include "ft2004.h"
+#include "gicv3.h"
+
+rt_uint64_t get_main_cpu_affval(void)
+{
+ return 0;
+}
+
+rt_uint32_t arm_gic_cpumask_to_affval(rt_uint32_t *cpu_mask, rt_uint32_t *cluster_id, rt_uint32_t *target_list)
+{
+
+ if (*cpu_mask == 0)
+ {
+ return 0;
+ }
+
+ *target_list = 0;
+ *cluster_id = 0;
+
+ if (*cpu_mask & 0x3)
+ {
+ if ((*cpu_mask & 0x3) == 0x3)
+ {
+ *target_list = 3;
+ }
+ else if ((*cpu_mask & 0x1))
+ {
+ *target_list = 1;
+ }
+ else
+ {
+ *target_list = 2;
+ }
+ *cpu_mask &= ~0x3;
+ }
+ else if (*cpu_mask & 0xc)
+ {
+ *cluster_id = 0x100;
+ if ((*cpu_mask & 0xc) == 0xc)
+ {
+ *target_list = 3;
+ }
+ else if ((*cpu_mask & 0x4))
+ {
+ *target_list = 1;
+ }
+ else
+ {
+ *target_list = 2;
+ }
+ *cpu_mask &= ~0xc;
+ }
+ else
+ {
+ *cpu_mask = 0;
+ return 0;
+ }
+
+ return 1;
+}
+
+#ifdef RT_USING_SMP
+
+void send_core_isg(void)
+{
+ for (size_t i = 0; i <= 0xf; i++)
+ {
+ /* code */
+ rt_kprintf("i %x \r\n", i);
+ arm_gic_send_affinity_sgi(0, 0, i, 0);
+ rt_thread_mdelay(100);
+ }
+}
+MSH_CMD_EXPORT(send_core_isg, send_core_isg);
+
+#endif
diff --git a/bsp/ft2004/drivers/ft2004.h b/bsp/ft2004/drivers/ft2004.h
new file mode 100644
index 0000000000..fe3293ab94
--- /dev/null
+++ b/bsp/ft2004/drivers/ft2004.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-04-29 Carl the first version
+ *
+ */
+
+#ifndef __FT2004_H__
+#define __FT2004_H__
+
+#include <rthw.h>
+#include <rtthread.h>
+
+#define ARM_GIC_NR_IRQS 160
+#define ARM_GIC_MAX_NR 1
+#define MAX_HANDLERS 160
+#define GIC_IRQ_START 0
+
+rt_uint64_t get_main_cpu_affval(void);
+
+#endif // !
diff --git a/bsp/ft2004/drivers/ft2004_cpu.S b/bsp/ft2004/drivers/ft2004_cpu.S
new file mode 100644
index 0000000000..2e713a5b20
--- /dev/null
+++ b/bsp/ft2004/drivers/ft2004_cpu.S
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-04-29 Carl the first version
+ *
+ */
+
+#include "rtconfig.h"
+
+.globl rt_hw_cpu_id
+rt_hw_cpu_id:
+ mrc p15, 0, r0, c0, c0, 5
+ ubfx r0, r0, #0, #12
+ cmp r0, #0
+ beq core0
+ cmp r0, #1
+ beq core1
+ cmp r0, #256
+ beq core2
+ mov r1 ,#257
+ cmp r0, r1
+ beq core3
+ b default
+core0:
+ mov r0, #0
+ b return
+core1:
+ mov r0, #1
+ b return
+core2:
+ mov r0, #2
+ b return
+core3:
+ mov r0, #3
+ b return
+default:
+ and r0, r0, #15
+return:
+ bx lr
+
diff --git a/bsp/ft2004/drivers/secondary_cpu.c b/bsp/ft2004/drivers/secondary_cpu.c
new file mode 100644
index 0000000000..5ffcadbefe
--- /dev/null
+++ b/bsp/ft2004/drivers/secondary_cpu.c
@@ -0,0 +1,86 @@
+/*
+ * @ : Copyright (c) 2020 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-05-26 10:09:45
+ * @LastEditTime: 2021-05-26 10:31:44
+ * @Description:  This files is for
+ *
+ * @Modify History:
+ *  Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include <rtthread.h>
+#include "board.h"
+#include <gicv3.h>
+
+#ifdef RT_USING_SMP
+#include <interrupt.h>
+#include "ft_psci.h"
+#include "ft_generic_timer.h"
+
+extern int rt_hw_timer_init(void);
+extern void secondary_cpu_start(void);
+
+void rt_hw_secondary_cpu_up(void)
+{
+
+ rt_uint32_t i;
+ rt_uint32_t cpu_mask = 0;
+
+ rt_kprintf("rt_hw_secondary_cpu_up is processing \r\n");
+ for (i = 1; i < RT_CPUS_NR; i++)
+ {
+ if (i == 1)
+ {
+ /* code */
+ FPsci_CpuOn(1 << i, (rt_uint32_t)secondary_cpu_start);
+ cpu_mask = 2;
+ }
+ else if (i == 2)
+ {
+ FPsci_CpuOn(1 << i, (rt_uint32_t)secondary_cpu_start);
+ cpu_mask = 4;
+ }
+ else if (i == 3)
+ {
+ FPsci_CpuOn(1 << i, (rt_uint32_t)secondary_cpu_start);
+ cpu_mask = 8;
+ }
+ else
+ {
+ continue;
+ }
+
+ __asm__ volatile("dsb" ::
+ : "memory");
+ rt_hw_ipi_send(RT_SCHEDULE_IPI, cpu_mask);
+ Ft_GenericTimer_UsDelay(1000000);
+ }
+}
+
+void secondary_cpu_c_start(void)
+{
+ rt_hw_vector_init();
+ rt_hw_spin_lock(&_cpus_lock);
+
+ arm_gic_cpu_init(0);
+ arm_gic_redist_init(0);
+
+ rt_hw_timer_init();
+
+ rt_hw_interrupt_set_priority(RT_SCHEDULE_IPI, 16);
+ rt_hw_interrupt_umask(RT_SCHEDULE_IPI);
+
+ rt_system_scheduler_start();
+}
+
+void rt_hw_secondary_cpu_idle_exec(void)
+{
+ asm volatile("wfe" ::
+ : "memory", "cc");
+}
+
+#endif
diff --git a/bsp/ft2004/drivers/serial.h b/bsp/ft2004/drivers/serial.h
new file mode 100644
index 0000000000..cf4e337a1f
--- /dev/null
+++ b/bsp/ft2004/drivers/serial.h
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-04-29 Carl the first version
+ *
+ */
+
+#ifndef __UART_H__
+#define __UART_H__
+
+#include <board.h>
+
+int rt_hw_uart_init(void);
+
+#endif
+
diff --git a/bsp/ft2004/figures/onchipPeripheral.png b/bsp/ft2004/figures/onchipPeripheral.png
new file mode 100644
index 0000000000..3b5833bcca
--- /dev/null
+++ b/bsp/ft2004/figures/onchipPeripheral.png
Binary files differ
diff --git a/bsp/ft2004/figures/rttPing通过界面.png b/bsp/ft2004/figures/rttPing通过界面.png
new file mode 100644
index 0000000000..0c287ea571
--- /dev/null
+++ b/bsp/ft2004/figures/rttPing通过界面.png
Binary files differ
diff --git a/bsp/ft2004/figures/rttsd调试.png b/bsp/ft2004/figures/rttsd调试.png
new file mode 100644
index 0000000000..98d1b5fa2b
--- /dev/null
+++ b/bsp/ft2004/figures/rttsd调试.png
Binary files differ
diff --git a/bsp/ft2004/figures/启动演示图.png b/bsp/ft2004/figures/启动演示图.png
new file mode 100644
index 0000000000..46a117c96f
--- /dev/null
+++ b/bsp/ft2004/figures/启动演示图.png
Binary files differ
diff --git a/bsp/ft2004/ft_aarch32.lds b/bsp/ft2004/ft_aarch32.lds
new file mode 100644
index 0000000000..d37332d97f
--- /dev/null
+++ b/bsp/ft2004/ft_aarch32.lds
@@ -0,0 +1,110 @@
+OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
+OUTPUT_ARCH(arm)
+
+SECTIONS
+{
+ . = 0x80100000;
+
+ __text_start = .;
+ .text :
+ {
+ *(.vectors)
+ *(.text)
+ *(.text.*)
+
+ /* section information for finsh shell */
+ . = ALIGN(4);
+ __fsymtab_start = .;
+ KEEP(*(FSymTab))
+ __fsymtab_end = .;
+ . = ALIGN(4);
+ __vsymtab_start = .;
+ KEEP(*(VSymTab))
+ __vsymtab_end = .;
+ . = ALIGN(4);
+
+ /* section information for modules */
+ . = ALIGN(4);
+ __rtmsymtab_start = .;
+ KEEP(*(RTMSymTab))
+ __rtmsymtab_end = .;
+
+ /* section information for initialization */
+ . = ALIGN(4);
+ __rt_init_start = .;
+ KEEP(*(SORT(.rti_fn*)))
+ __rt_init_end = .;
+ } =0
+ __text_end = .;
+
+ __rodata_start = .;
+ .rodata : { *(.rodata) *(.rodata.*) }
+ __rodata_end = .;
+
+ . = ALIGN(4);
+ .ctors :
+ {
+ PROVIDE(__ctors_start__ = .);
+ KEEP(*(SORT(.ctors.*)))
+ KEEP(*(.ctors))
+ PROVIDE(__ctors_end__ = .);
+ }
+
+ .dtors :
+ {
+ PROVIDE(__dtors_start__ = .);
+ KEEP(*(SORT(.dtors.*)))
+ KEEP(*(.dtors))
+ PROVIDE(__dtors_end__ = .);
+ }
+
+ . = ALIGN(16 * 1024);
+ .l1_page_table :
+ {
+ __l1_page_table_start = .;
+ . += 16K;
+ }
+
+ . = ALIGN(8);
+ __data_start = .;
+ .data :
+ {
+ *(.data)
+ *(.data.*)
+ }
+ __data_end = .;
+
+ . = ALIGN(8);
+ __bss_start = .;
+ .bss :
+ {
+ *(.bss)
+ *(.bss.*)
+ *(COMMON)
+ . = ALIGN(4);
+ }
+ . = ALIGN(4);
+ __bss_end = .;
+
+ .heap :
+ {
+ . = ALIGN(8);
+ __end__ = .;
+ PROVIDE(end = .);
+ __HeapBase = .;
+ . += 0x400;
+ __HeapLimit = .;
+ __heap_limit = .; /* Add for _sbrk */
+ }
+
+ /* Stabs debugging sections. */
+ .stab 0 : { *(.stab) }
+ .stabstr 0 : { *(.stabstr) }
+ .stab.excl 0 : { *(.stab.excl) }
+ .stab.exclstr 0 : { *(.stab.exclstr) }
+ .stab.index 0 : { *(.stab.index) }
+ .stab.indexstr 0 : { *(.stab.indexstr) }
+ .comment 0 : { *(.comment) }
+
+ _end = .;
+}
diff --git a/bsp/ft2004/libraries/.gitignore b/bsp/ft2004/libraries/.gitignore
new file mode 100644
index 0000000000..fcfda9fc84
--- /dev/null
+++ b/bsp/ft2004/libraries/.gitignore
@@ -0,0 +1,4 @@
+*.o
+*.elf
+*.bin
+*.map
diff --git a/bsp/ft2004/libraries/Kconfig b/bsp/ft2004/libraries/Kconfig
new file mode 100644
index 0000000000..c544395596
--- /dev/null
+++ b/bsp/ft2004/libraries/Kconfig
@@ -0,0 +1,146 @@
+menu "Hardware Drivers Config"
+
+menu "On-chip Peripheral Drivers"
+ menuconfig BSP_USING_UART
+ bool "Enable UART"
+ default y
+ select RT_USING_SERIAL
+ if BSP_USING_UART
+ config RT_USING_UART1
+ bool "Enable UART1"
+ default y
+
+ config RT_USING_UART0
+ bool "Enable UART0"
+ default n
+
+ endif
+
+ menuconfig BSP_USING_SDC
+ bool "Enable sd controller"
+ select RT_USING_SDIO
+ select RT_USING_DFS
+ select RT_USING_DFS_ELMFAT
+ default n
+
+ if BSP_USING_SDC
+
+ config BSP_SDC_DEBUG_PRINT
+ bool "Enable sd controller debug print"
+ default n
+
+
+ config BSP_SDC_USE_IRQ
+ bool "Use interrupt to handle when cmd complete, dma complete"
+ default n
+
+ if BSP_SDC_USE_IRQ
+ config BSP_SDC_IRQ_CARD_REMOVE
+ bool "Use interrupt to determine if the card is pulled out"
+ default n
+
+ endif
+
+ endif
+
+ menuconfig BSP_USING_GMAC
+ bool "Enable gmac"
+ default n
+ select RT_USING_NETDEV
+
+
+ if BSP_USING_GMAC
+ config BSP_USING_GMAC0
+ bool "Enable GMAC0"
+ default y
+
+ config BSP_USING_GMAC1
+ bool "Enable GMAC1"
+ default n
+
+ config RT_LWIP_ETH_PAD_SIZE
+ int "set lwip ETH_PAD_SIZE"
+ range 2 256
+ default 2
+
+ config RAW_DATA_PRINT
+ bool "Enable mac raw data print"
+ default n
+
+ if RAW_DATA_PRINT
+ config ETH_RX_DUMP
+ bool "Enable gmac receive raw data print "
+ default n
+
+ config ETH_TX_DUMP
+ bool "Enable gmac send raw data print "
+ default n
+ endif
+
+ endif
+
+
+ # menuconfig BSP_USE_QSPI
+ # bool "Enable Qspi"
+ # select RT_USING_SFUD
+ # select RT_SFUD_USING_QSPI
+ # default n
+
+ # if BSP_USE_QSPI
+ # config BSP_QSPI_DEBUG
+ # bool "Enable qspi debug print"
+ # default n
+ # endif
+
+ menuconfig BSP_USE_SPI
+ bool "Enable Spi"
+ select RT_USING_SFUD
+ select RT_SFUD_USING_SPI
+ select RT_SFUD_USING_SFDP
+ select RT_SFUD_USING_FLASH_INFO_TABLE
+ select BSP_USE_GPIO
+ default n
+ if BSP_USE_SPI
+ config BSP_SPI_DEBUG
+ bool "Enable spi debug print"
+ default n
+ endif
+
+ menuconfig BSP_USE_GPIO
+ bool "Enable Gpio"
+ default n
+ if BSP_USE_GPIO
+ config BSP_GPIO_DEBUG
+ bool "Enable gpio debug print"
+ default n
+ endif
+
+ menuconfig BSP_USE_CAN
+ bool "Enable Can"
+ select RT_USING_CAN
+ default n
+
+ if BSP_USE_CAN
+ config BSP_USING_CAN0
+ bool "Enable can0"
+ default n
+ config BSP_USING_CAN1
+ bool "Enable can1"
+ default n
+
+ if BSP_USING_CAN0
+ config BSP_USING_CAN0_DEBUG
+ bool "Enable can0 work in loop back"
+ default n
+ endif
+
+ endif
+
+
+endmenu
+
+menu "Board extended module Drivers"
+
+endmenu
+
+endmenu
diff --git a/bsp/ft2004/libraries/LICENSE b/bsp/ft2004/libraries/LICENSE
new file mode 100644
index 0000000000..7a4a3ea242
--- /dev/null
+++ b/bsp/ft2004/libraries/LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License. \ No newline at end of file
diff --git a/bsp/ft2004/libraries/SConscript b/bsp/ft2004/libraries/SConscript
new file mode 100644
index 0000000000..e279d05ea1
--- /dev/null
+++ b/bsp/ft2004/libraries/SConscript
@@ -0,0 +1,129 @@
+'''
+ : Copyright (c) 2020 Phytium Information Technology, Inc. 
+ 
+SPDX-License-Identifier: Apache-2.0.
+
+Date: 2021-05-24 14:30:13
+LastEditTime: 2021-05-26 14:58:34
+Description:  This files is for 
+
+Modify History:
+ Ver   Who        Date         Changes
+----- ------     --------    --------------------------------------
+'''
+from building import *
+import rtconfig
+Import('RTT_ROOT')
+
+# get current directory
+cwd = GetCurrentDir()
+
+# The set of source files associated with this SConscript file.
+src = Split("""
+bsp/standlone/ft_assert.c
+bsp/standlone/ft_generic_timer.c
+bsp/standlone/ft_printf.c
+bsp/standlone/ft_trace.c
+bsp/standlone/ft_mux.c
+bsp/standlone/inbyte.c
+bsp/standlone/outbyte.c
+bsp/standlone/ft_cache.c
+bsp/standlone/ft_cpu.c
+bsp/standlone/ft_smc.S
+bsp/standlone/ft_psci.c
+bsp/standlone/ft_debug.c
+""")
+
+
+
+if GetDepend(['RT_USING_SERIAL']):
+ src += ['bsp/ft_uart/ft_uart_g.c']
+ src += ['bsp/ft_uart/ft_uart_hw.c']
+ src += ['bsp/ft_uart/ft_uart_intr.c']
+ src += ['bsp/ft_uart/ft_uart_options.c']
+ src += ['bsp/ft_uart/ft_uart_selftest.c']
+ src += ['bsp/ft_uart/ft_uart_sinit.c']
+ src += ['bsp/ft_uart/ft_uart.c']
+
+if GetDepend(['RT_USING_I2C']):
+ None
+
+if GetDepend(['RT_USING_USB_HOST']) or GetDepend(['RT_USING_USB_DEVICE']):
+ None
+
+if GetDepend(['BSP_USE_CAN']):
+ src += ['bsp/ft_can/ft_can_g.c']
+ src += ['bsp/ft_can/ft_can_hw.c']
+ src += ['bsp/ft_can/ft_can_intr.c']
+ src += ['bsp/ft_can/ft_can_sinit.c']
+ src += ['bsp/ft_can/ft_can.c']
+ src += ['bsp/ft_can/ft_can_calc.c']
+ None
+
+
+if GetDepend(['RT_USING_HWTIMER']) or GetDepend(['RT_USING_PWM']):
+ None
+
+if GetDepend(['RT_USING_ADC']):
+ None
+
+if GetDepend(['RT_USING_RTC']):
+ None
+
+if GetDepend(['RT_USING_WDT']):
+ None
+
+if GetDepend(['RT_USING_AUDIO']):
+ None
+
+if GetDepend(['BSP_USING_ON_CHIP_FLASH']):
+ None
+
+if GetDepend(['BSP_USING_GMAC']):
+ src += ['bsp/ft_gmac/ft_gmac_desc.c']
+ src += ['bsp/ft_gmac/ft_gmac_g.c']
+ src += ['bsp/ft_gmac/ft_gmac_hw.c']
+ src += ['bsp/ft_gmac/ft_gmac_intr.c']
+ src += ['bsp/ft_gmac/ft_gmac_sinit.c']
+ src += ['bsp/ft_gmac/ft_gmac.c']
+
+if GetDepend(['BSP_USING_SDC']):
+ src += ['bsp/ft_sd/ft_sdctrl_option.c']
+ src += ['bsp/ft_sd/ft_sdctrl_sinit.c']
+ src += ['bsp/ft_sd/ft_sdctrl_intr.c']
+ src += ['bsp/ft_sd/ft_sdctrl_g.c']
+ src += ['bsp/ft_sd/ft_sdctrl_hw.c']
+ src += ['bsp/ft_sd/ft_sdctrl.c']
+
+if GetDepend(['BSP_USE_QSPI']):
+ src += ['bsp/ft_qspi/qspi_g.c']
+ src += ['bsp/ft_qspi/qspi_hw.c']
+ src += ['bsp/ft_qspi/ft_qspi.c']
+ src += ['bsp/ft_qspi/qspi_sinit.c']
+
+if GetDepend(['BSP_USE_SPI']):
+ src += ['bsp/ft_spi/ft_spi.c']
+ src += ['bsp/ft_spi/ft_spi_irq.c']
+
+if GetDepend(['BSP_USE_GPIO']):
+ src += ['bsp/ft_gpio/ft_gpio.c']
+
+path = [cwd + '/bsp/standlone/',
+ cwd + '/bsp/ft_gicv3',
+ cwd + '/bsp/ft_gmac',
+ cwd + '/bsp/ft_uart',
+ cwd + '/bsp/ft_sd',
+ cwd + '/bsp/ft_qspi',
+ cwd + '/bsp/ft_can',
+ cwd + '/bsp/ft_spi',
+ cwd + '/bsp/ft_gpio',
+ cwd + '/bsp/include',
+ cwd + '/include',
+ cwd + '/cpu', ]
+
+
+CPPDEFINES = ['USE_FT_DRIVER']
+group = DefineGroup('FT_DRIVER', src, depend=[
+ ''], CPPPATH=path, CPPDEFINES=CPPDEFINES)
+
+Return('group')
diff --git a/bsp/ft2004/libraries/bsp/ft_can/ft_can.c b/bsp/ft2004/libraries/bsp/ft_can/ft_can.c
new file mode 100644
index 0000000000..9546670715
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_can/ft_can.c
@@ -0,0 +1,299 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-29 10:21:53
+ * @LastEditTime: 2021-05-25 16:41:38
+ * @Description:  Description of file
+ * @Modify History:
+ * * * Ver   Who        Date         Changes
+ * * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_can.h"
+#include "ft_can_hw.h"
+#include "ft_assert.h"
+#include "ft_debug.h"
+#include "string.h"
+
+#define FT_CAN_DEBUG_TAG "FT_CAN"
+
+#define FT_CAN_DEBUG_I(format, ...) FT_DEBUG_PRINT_I(FT_CAN_DEBUG_TAG, format, ##__VA_ARGS__)
+#define FT_CAN_DEBUG_E(format, ...) FT_DEBUG_PRINT_E(FT_CAN_DEBUG_TAG, format, ##__VA_ARGS__)
+#define FT_CAN_DEBUG_W(format, ...) FT_DEBUG_PRINT_W(FT_CAN_DEBUG_TAG, format, ##__VA_ARGS__)
+
+ft_error_t
+FCan_CfgInitialize(FCan_t *Can_p, FCan_Config_t *Config_p)
+{
+ Ft_assertNonvoid(Can_p != NULL);
+ Ft_assertNonvoid(Config_p != NULL);
+ Can_p->Config = *Config_p;
+ Can_p->IsReady = FT_COMPONENT_IS_READLY;
+ FCan_Reset(Can_p);
+ return FCAN_SUCCESS;
+}
+
+void FCan_GetErrorCnt(FCan_t *Can_p, u32 *TxErr, u32 *RxErr)
+{
+ FCan_Config_t *Config_p;
+ Ft_assertVoid(Can_p != NULL);
+ Ft_assertVoid(Can_p->IsReady == FT_COMPONENT_IS_READLY);
+ Config_p = &Can_p->Config;
+
+ *RxErr = FCan_ReadReg(Config_p->CanBaseAddress, FCAN_ERR_CNT_OFFSET) & FCAN_ERR_CNT_RFN_MASK;
+ *TxErr = (FCan_ReadReg(Config_p->CanBaseAddress, FCAN_ERR_CNT_OFFSET) & FCAN_ERR_CNT_TFN_MASK) >> FCAN_ERR_CNT_TFN_SHIFT;
+}
+
+u32 FCan_RecvByIrq(FCan_t *Can_p, struct FCan_Frame *Frame_p, u32 FrameNumber)
+{
+ u32 FifoCnt = 0;
+ FCan_Config_t *Config_p;
+ u32 CanId;
+ u32 Dlc;
+ u32 CanFrameIndex = 0;
+ u32 RxValue;
+ Ft_assertZeroNum(Can_p != NULL);
+ Ft_assertZeroNum(Can_p->IsReady == FT_COMPONENT_IS_READLY);
+ Config_p = &Can_p->Config;
+
+ FifoCnt = FCan_ReadReg(Config_p->CanBaseAddress, FCAN_FIFO_CNT_OFFSET) & 0x3f;
+
+ if (0 == FifoCnt)
+ {
+ return 0;
+ }
+
+ FrameNumber = (FrameNumber > FifoCnt) ? FifoCnt : FrameNumber;
+
+ while (FrameNumber)
+ {
+ /* Read a frame from Phytium CAN */
+ CanId = FCan_ReadReg(Config_p->CanBaseAddress, FCAN_RX_FIFO_OFFSET);
+ /* if CanId is big-endian ,use swap change to little-endian */
+ CanId = FT_SWAP32(CanId);
+ /* Identifier extension */
+ if (CanId & FCAN_IDR_IDE_MASK)
+ {
+ Dlc = FCan_ReadReg(Config_p->CanBaseAddress, FCAN_RX_FIFO_OFFSET);
+ Dlc = FT_SWAP32(Dlc);
+ Dlc = ((Dlc & FCAN_IDR_EDLC_MASK) >> FCAN_IDR_EDLC_SHIFT);
+
+ Frame_p[CanFrameIndex].CanId = (CanId & FCAN_IDR_ID1_MASK) >> 3;
+ Frame_p[CanFrameIndex].CanId |= (CanId & FCAN_IDR_ID2_MASK) >> FCAN_IDR_ID2_SHIFT;
+ Frame_p[CanFrameIndex].CanId |= CAN_EFF_FLAG;
+
+ if (CanId & FCAN_IDR_RTR_MASK)
+ {
+ Frame_p[CanFrameIndex].CanId |= CAN_RTR_FLAG;
+ }
+ }
+ else
+ {
+ Dlc = ((CanId & FCAN_IDR_DLC_MASK) >> FCAN_IDR_SDLC_SHIFT);
+
+ /* The received frame is a standard format frame */
+ Frame_p[CanFrameIndex].CanId = (CanId & FCAN_IDR_ID1_MASK) >> FCAN_IDR_ID1_SHIFT;
+ if (CanId & FCAN_IDR_SRR_MASK)
+ {
+ Frame_p[CanFrameIndex].CanId |= CAN_RTR_FLAG;
+ }
+ }
+
+ Frame_p[CanFrameIndex].CanDlc = (Dlc > sizeof(Frame_p[CanFrameIndex].data)) ? sizeof(Frame_p[CanFrameIndex].data) : Dlc;
+
+ if (!(Frame_p[CanFrameIndex].CanId & CAN_RTR_FLAG))
+ {
+ if (Frame_p[CanFrameIndex].CanDlc > 0)
+ {
+ RxValue = FCan_ReadReg(Config_p->CanBaseAddress, FCAN_RX_FIFO_OFFSET);
+ memcpy(Frame_p[CanFrameIndex].data, &RxValue, sizeof(RxValue));
+ }
+
+ if (Frame_p[CanFrameIndex].CanDlc > 4)
+ {
+ RxValue = FCan_ReadReg(Config_p->CanBaseAddress, FCAN_RX_FIFO_OFFSET);
+ memcpy(&Frame_p[CanFrameIndex].data[4], &RxValue, sizeof(RxValue));
+ }
+ }
+ FrameNumber--;
+ CanFrameIndex++;
+ }
+
+ return (CanFrameIndex + 1);
+}
+
+static void FCan_SendFifo(FCan_t *Can_p, struct FCan_Frame *Frame_p)
+{
+ u32 Id, Dlc;
+ FCan_Config_t *Config_p;
+ u32 SendBuffer = 0;
+ Ft_assertVoid(Can_p != NULL);
+ Ft_assertVoid(Can_p->IsReady == FT_COMPONENT_IS_READLY);
+ Config_p = &Can_p->Config;
+ if (Frame_p->CanId & CAN_EFF_FLAG)
+ {
+ /* Extended CAN ID format */
+ Id = ((Frame_p->CanId & CAN_EFF_MASK) << FCAN_IDR_ID2_SHIFT) &
+ FCAN_IDR_ID2_MASK;
+ Id |= (((Frame_p->CanId & CAN_EFF_MASK) >>
+ (CAN_EFF_ID_BITS - CAN_SFF_ID_BITS))
+ << FCAN_IDR_ID1_SHIFT) &
+ FCAN_IDR_ID1_MASK;
+
+ Id |= FCAN_IDR_IDE_MASK | FCAN_IDR_SRR_MASK;
+ if (Frame_p->CanId & CAN_RTR_FLAG)
+ {
+ Id |= FCAN_IDR_RTR_MASK;
+ }
+
+ Dlc = Frame_p->CanDlc << FCAN_IDR_EDLC_SHIFT;
+
+ FCan_WriteReg(Config_p->CanBaseAddress, FCAN_TX_FIFO_OFFSET, FT_SWAP32(Id));
+ FCan_WriteReg(Config_p->CanBaseAddress, FCAN_TX_FIFO_OFFSET, FT_SWAP32(Dlc));
+ }
+ else
+ {
+ /* Standard CAN ID format */
+ Id = ((Frame_p->CanId & CAN_SFF_MASK) << FCAN_IDR_ID1_SHIFT) &
+ FCAN_IDR_ID1_MASK;
+ if (Frame_p->CanId & CAN_RTR_FLAG)
+ Id |= FCAN_IDR_SRR_MASK;
+
+ Dlc = ((Frame_p->CanDlc << FCAN_IDR_SDLC_SHIFT) | FCAN_IDR_PAD_MASK);
+ Id |= Dlc;
+ FCan_WriteReg(Config_p->CanBaseAddress, FCAN_TX_FIFO_OFFSET, FT_SWAP32(Id));
+ }
+
+ if (!(Frame_p->CanId & CAN_RTR_FLAG))
+ {
+ if (Frame_p->CanDlc > 0)
+ {
+ memcpy(&SendBuffer, Frame_p->data, 4);
+ FCan_WriteReg(Config_p->CanBaseAddress, FCAN_TX_FIFO_OFFSET, SendBuffer);
+ }
+
+ if (Frame_p->CanDlc > 4)
+ {
+ memcpy(&SendBuffer, &Frame_p->data[4], 4);
+ FCan_WriteReg(Config_p->CanBaseAddress, FCAN_TX_FIFO_OFFSET, SendBuffer);
+ }
+ }
+}
+
+u32 FCan_SendByIrq(FCan_t *Can_p,
+ struct FCan_Frame *Frame_p,
+ u32 FrameNumber, void (*UserIrqWait)(void))
+{
+ FCan_Config_t *Config_p;
+ u32 FrameIndex = 0;
+ u32 NeedSendOnce;
+ u32 cnt = 0;
+ Ft_assertZeroNum(Can_p != NULL);
+ Ft_assertZeroNum(Can_p->IsReady == FT_COMPONENT_IS_READLY);
+ Config_p = &Can_p->Config;
+
+ if (NULL == Frame_p)
+ {
+ FT_CAN_DEBUG_E("Frame_p is NULL , %s: %d", __FILE__, __LINE__);
+ return 0;
+ }
+
+ if (0 == FrameNumber)
+ {
+ FT_CAN_DEBUG_E("FrameNumber is 0 , %s: %d", __FILE__, __LINE__);
+ return 0;
+ }
+
+ for (; 0 < FrameNumber;)
+ {
+ if (FrameNumber > Config_p->TxFifoDeepth)
+ {
+ NeedSendOnce = Config_p->TxFifoDeepth;
+ FrameNumber -= Config_p->TxFifoDeepth;
+ }
+ else
+ {
+ NeedSendOnce = FrameNumber;
+ FrameNumber = 0;
+ }
+ Ft_printf("shut down tranmission \r\n");
+ /*shut down tranmission*/
+ FCan_ClearBit(Config_p->CanBaseAddress, FCAN_CTRL_OFFSET, FCAN_CTRL_XFER_MASK);
+ FCan_ClearBit(Config_p->CanBaseAddress, FCAN_CTRL_OFFSET, FCAN_CTRL_TXREQ_MASK);
+ FCan_SetBit(Config_p->CanBaseAddress, FCAN_CTRL_OFFSET, FCAN_CTRL_XFER_MASK);
+ Ft_printf("NeedSendOnce %d \r\n", NeedSendOnce);
+ for (cnt = 0; cnt < NeedSendOnce; cnt++)
+ {
+ FCan_SendFifo(Can_p, &Frame_p[FrameIndex]);
+ FrameIndex++;
+ }
+ Can_p->TxFifoCnt = NeedSendOnce;
+
+ /* triggers tranmission */
+ FCan_ClearBit(Config_p->CanBaseAddress, FCAN_CTRL_OFFSET, FCAN_CTRL_XFER_MASK);
+ FCan_SetBit(Config_p->CanBaseAddress, FCAN_CTRL_OFFSET, FCAN_CTRL_TXREQ_MASK);
+ FCan_SetBit(Config_p->CanBaseAddress, FCAN_CTRL_OFFSET, FCAN_CTRL_TXREQ_MASK | FCAN_CTRL_XFER_MASK);
+
+ if (UserIrqWait)
+ {
+ UserIrqWait();
+ }
+ else
+ {
+ while (0 != Can_p->TxFifoCnt)
+ {
+ };
+ }
+ }
+
+ return FrameIndex + 1;
+}
+
+ft_error_t FCan_SetTiming(FCan_t *Can_p,
+ struct FCan_Bittiming *Bittiming_p)
+{
+ u32 Btr = 0;
+ FCan_Config_t *Config_p;
+ u32 IsConfigMode;
+ Ft_assertNonvoid(Can_p != NULL);
+ Ft_assertNonvoid(Can_p->IsReady == FT_COMPONENT_IS_READLY);
+ Config_p = &Can_p->Config;
+
+ Ft_assertNonvoid(Bittiming_p->brp != 0);
+ Ft_assertNonvoid(Bittiming_p->prop_seg != 0);
+ Ft_assertNonvoid(Bittiming_p->phase_seg1 != 0);
+ Ft_assertNonvoid(Bittiming_p->phase_seg2 != 0);
+
+ /* Setting Baud Rate prescalar value in BRPR Register */
+ Btr = (Bittiming_p->brp - 1) << 16;
+ Btr |= (Bittiming_p->prop_seg - 1) << 2;
+ Btr |= (Bittiming_p->phase_seg1 - 1) << 5;
+ Btr |= (Bittiming_p->phase_seg2 - 1) << 8;
+ Btr |= (Bittiming_p->sjw - 1);
+
+ IsConfigMode = (FCan_ReadReg(Config_p->CanBaseAddress, FCAN_CTRL_OFFSET) & FCAN_CTRL_XFER_MASK);
+
+ if (IsConfigMode)
+ {
+ FCan_WriteReg(Config_p->CanBaseAddress, FCAN_CTRL_OFFSET, FCAN_CTRL_XFER_MASK);
+ }
+
+ FCan_WriteReg(Config_p->CanBaseAddress, FCAN_DAT_RATE_CTRL_OFFSET, Btr);
+ FCan_WriteReg(Config_p->CanBaseAddress, FCAN_ARB_RATE_CTRL_OFFSET, Btr);
+
+ /*Enable Transfer*/
+ FCan_SetBit(Config_p->CanBaseAddress, FCAN_CTRL_OFFSET, FCAN_CTRL_XFER_MASK);
+
+ return FCAN_SUCCESS;
+}
+
+void FCan_Enable(FCan_t *Can_p)
+{
+ FCan_Config_t *Config_p;
+ Ft_assertVoid(Can_p != NULL);
+ Ft_assertVoid(Can_p->IsReady == FT_COMPONENT_IS_READLY);
+ Config_p = &Can_p->Config;
+
+ FCan_WriteReg(Config_p->CanBaseAddress, FCAN_CTRL_OFFSET, FCAN_CTRL_XFER_MASK);
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_can/ft_can.h b/bsp/ft2004/libraries/bsp/ft_can/ft_can.h
new file mode 100644
index 0000000000..35998daf05
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_can/ft_can.h
@@ -0,0 +1,142 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-27 15:08:44
+ * @LastEditTime: 2021-04-27 15:08:44
+ * @Description:  Description of file
+ * @Modify History:
+ * * * Ver   Who        Date         Changes
+ * * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef FT_CAN_H
+#define FT_CAN_H
+
+#include "ft_types.h"
+#include "ft_error_code.h"
+
+#define FCAN_SUCCESS FST_SUCCESS /* SUCCESS */
+#define FCAN_FAILURE FT_MAKE_ERRCODE(errCan, errBspGeneral, FST_FAILURE) /* Normal */
+#define FCAN_TIMEOUT FT_MAKE_ERRCODE(errCan, errBspGeneral, FST_TIMEOUT) /* Timeout */
+#define FCAN_EILSEQ FT_MAKE_ERRCODE(errCan, errBspGeneral, FST_EILSEQ) /* Illegal byte sequence. */
+#define FCAN_INVALID_PARAM FT_MAKE_ERRCODE(errCan, errBspGeneral, FST_INVALID_PARAM) /* Invalid param. */
+
+#define FCAN_HANDLER_SEND 1U /**< Handler type for frame sending interrupt */
+#define FCAN_HANDLER_RECV 2U /**< Handler type for frame reception interrupt*/
+#define FCAN_HANDLER_ERROR 3U /**< Handler type for error interrupt */
+#define FCAN_DATA_LENGTH 8U
+
+/* CAN payload length and DLC definitions according to ISO 11898-1 */
+#define CAN_MAX_DLC 8
+#define CAN_MAX_DLEN 8
+#define CAN_MAX_CTL 3
+#define CAN_SFF_ID_BITS 11
+#define CAN_EFF_ID_BITS 29
+
+/* special address description flags for the CAN_ID */
+#define CAN_EFF_FLAG 0x80000000U /* EFF/SFF is set in the MSB */
+#define CAN_RTR_FLAG 0x40000000U /* remote transmission request */
+#define CAN_ERR_FLAG 0x20000000U /* error message frame */
+
+/* valid bits in CAN ID for frame formats */
+#define CAN_SFF_MASK 0x000007FFU /* standard frame format (SFF) */
+#define CAN_EFF_MASK 0x1FFFFFFFU /* extended frame format (EFF) */
+#define CAN_ERR_MASK 0x1FFFFFFFU /* omit EFF, RTR, ERR flags */
+
+/* Frame type */
+#define STANDARD_FRAME 0 /* standard frame */
+#define EXTEND_FRAME 1 /* extended frame */
+
+typedef void (*FCan_irqHandler_t)(void *Args);
+
+struct FCan_Frame
+{
+ u32 CanId;
+ u8 CanDlc;
+ u8 data[FCAN_DATA_LENGTH];
+};
+
+struct FCan_Bittiming
+{
+ u32 bitrate; /* Bit-rate in bits/second */
+ u32 sample_point; /* Sample point in one-tenth of a percent */
+ u32 tq; /* Time quanta (TQ) in nanoseconds */
+ u32 prop_seg; /* Propagation segment in TQs */
+ u32 phase_seg1; /* Phase buffer segment 1 in TQs */
+ u32 phase_seg2; /* Phase buffer segment 2 in TQs */
+ u32 sjw; /* Synchronisation jump width in TQs */
+ u32 brp; /* Bit-rate prescaler */
+};
+
+typedef struct
+{
+ u32 InstanceId; /* Id of device */
+ u32 CanBaseAddress; /* Can base Address */
+ u32 IrqNum;
+ u32 BaudRate;
+ u32 TxFifoDeepth; /* The depth of the full frame , */
+} FCan_Config_t;
+
+typedef struct
+{
+ FCan_Config_t Config;
+ u32 IsReady; /* Device is initialized and ready */
+
+ volatile u32 TxFifoCnt;
+
+ FCan_irqHandler_t SendHandler;
+ void *SendRef;
+
+ FCan_irqHandler_t RecvHandler;
+ void *RecvRef;
+
+ FCan_irqHandler_t ErrorHandler;
+ void *ErrorRef;
+
+} FCan_t;
+
+FCan_Config_t *FCan_LookupConfig(u32 InstanceId);
+
+/**
+ * @name: FCan_CfgInitialize
+ * @msg: This function initializes a Can instance/driver.
+ * @in param Can_p: Can_p is a pointer to the FCan_t instance.
+ * @in param Config_p: Config_p points to the FCan_t device configuration structure.
+ * @return {*}
+ */
+ft_error_t FCan_CfgInitialize(FCan_t *Can_p, FCan_Config_t *Config_p);
+
+/**
+ * @name: FCan_SetHandler
+ * @msg: This routine installs an asynchronous callback function for the given
+ * @inout param Can_p: Can_p is a pointer to the FCan_t instance.
+ * @in param HandlerType: specifies which handler is to be attached.
+ * @in param IrqCallBackFunc: IrqCallBackFunc is the address of the callback function.
+ * @in param IrqCallBackRef: IrqCallBackRef is a user data item that will be passed to the
+ * callback function when it is invoked.
+ * @return {*}
+ * @param {FCan_t} *Can_p
+ * @param {u32} HandlerType
+ * @param {FCan_irqHandler_t} *IrqCallBackFunc
+ * @param {void} *IrqCallBackRef
+ */
+ft_error_t FCan_SetHandler(FCan_t *Can_p, u32 HandlerType, FCan_irqHandler_t IrqCallBackFunc, void *IrqCallBackRef);
+
+ft_error_t FCan_SetTiming(FCan_t *Can_p,
+ struct FCan_Bittiming *Bittiming_p);
+
+void FCan_IntrHandler(void *InstancePtr);
+
+ft_error_t FCan_CalcBittiming(struct FCan_Bittiming *Bt_p);
+
+u32 FCan_SendByIrq(FCan_t *Can_p,
+ struct FCan_Frame *Frame_p,
+ u32 FrameNumber, void (*UserIrqWait)(void));
+
+u32 FCan_RecvByIrq(FCan_t *Can_p, struct FCan_Frame *Frame_p, u32 FrameNumber);
+
+void FCan_Enable(FCan_t *Can_p);
+
+#endif // !FT_CAN_H
diff --git a/bsp/ft2004/libraries/bsp/ft_can/ft_can_calc.c b/bsp/ft2004/libraries/bsp/ft_can/ft_can_calc.c
new file mode 100644
index 0000000000..c897b2e303
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_can/ft_can_calc.c
@@ -0,0 +1,269 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-05-06 09:30:51
+ * @LastEditTime: 2021-05-25 16:41:10
+ * @Description:  Description of file
+ * @Modify History:
+ * * * Ver   Who        Date         Changes
+ * * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_can.h"
+
+#include "ft_debug.h"
+#include "string.h"
+
+#ifndef max
+#define max(x, y) (((x) < (y)) ? (y) : (x))
+#endif
+
+#ifndef min
+#define min(x, y) (((x) < (y)) ? (x) : (y))
+#endif
+
+#define FT_CAN_DEBUG_TAG "FT_CAN"
+
+#define FT_CAN_DEBUG_I(format, ...) FT_DEBUG_PRINT_I(FT_CAN_DEBUG_TAG, format, ##__VA_ARGS__)
+#define FT_CAN_DEBUG_E(format, ...) FT_DEBUG_PRINT_E(FT_CAN_DEBUG_TAG, format, ##__VA_ARGS__)
+#define FT_CAN_DEBUG_W(format, ...) FT_DEBUG_PRINT_W(FT_CAN_DEBUG_TAG, format, ##__VA_ARGS__)
+
+#define CAN_CLK_FREQ 600000000
+#define CAN_CALC_SYNC_SEG 1
+#define FCAN_TSEG1_MIN 1
+#define FCAN_TSEG1_MAX 8
+#define FCAN_TSEG2_MIN 1
+#define FCAN_TSEG2_MAX 8
+#define FCAN_SJW_MAX 4
+#define FCAN_BRP_MIN 1
+#define FCAN_BRP_MAX 512
+#define FCAN_BRP_INC 1
+#define FCAN_CALC_SYNC_SEG 1
+#define CAN_CALC_MAX_ERROR 50 /* in one-tenth of a percent */
+#define BEST_BITRATE_ERROR (2147483647 * 2U + 1)
+
+#define clamp(x, low, high) (min(max(low, x), high))
+
+typedef struct can_bittiming_const
+{
+ char name[16]; /* Name of the CAN controller hardware */
+ u32 tseg1_min; /* Time segement 1 = prop_seg + phase_seg1 */
+ u32 tseg1_max;
+ u32 tseg2_min; /* Time segement 2 = phase_seg2 */
+ u32 tseg2_max;
+ u32 sjw_max; /* Synchronisation jump width */
+ u32 brp_min; /* Bit-rate prescaler */
+ u32 brp_max;
+ u32 brp_inc;
+} FTCAN_BITTIMING_CONST;
+
+static const struct can_bittiming_const ftcan_bittiming_const = {
+ .name = "vxbftCan",
+ .tseg1_min = 1,
+ .tseg1_max = 8,
+ .tseg2_min = 1,
+ .tseg2_max = 8,
+ .sjw_max = 4,
+ .brp_min = 1,
+ .brp_max = 512,
+ .brp_inc = 1,
+};
+
+static int abs(
+ int i /* integer for which to return absolute value */
+)
+{
+ return (i >= 0 ? i : -i);
+}
+
+static u32 div64_32(u64 *n, u32 base)
+{
+ u64 rem = *n;
+ u64 b = base;
+ u64 res, d = 1;
+ u32 high = rem >> 32;
+
+ /* Reduce the thing a bit first */
+ res = 0;
+ if (high >= base)
+ {
+ high /= base;
+ res = (u64)high << 32;
+ rem -= (u64)(high * base) << 32;
+ }
+
+ while ((u64)b > 0 && b < rem)
+ {
+ b = b + b;
+ d = d + d;
+ }
+
+ do
+ {
+ if (rem >= b)
+ {
+ rem -= b;
+ res += d;
+ }
+ b >>= 1;
+ d >>= 1;
+ } while (d);
+
+ *n = res;
+ return rem;
+}
+
+s32 can_update_sample_point(const struct can_bittiming_const *btc,
+ u32 sample_point_nominal, u32 tseg,
+ u32 *tseg1_ptr, u32 *tseg2_ptr,
+ u32 *sample_point_error_ptr)
+{
+ u32 sample_point_error, best_sample_point_error = BEST_BITRATE_ERROR;
+ u32 sample_point, best_sample_point = 0;
+ u32 tseg1, tseg2;
+ s32 i;
+
+ for (i = 0; i <= 1; i++)
+ {
+ tseg2 = tseg + CAN_CALC_SYNC_SEG - (sample_point_nominal * (tseg + CAN_CALC_SYNC_SEG)) / 1000 - i;
+ tseg2 = clamp(tseg2, btc->tseg2_min, btc->tseg2_max);
+ tseg1 = tseg - tseg2;
+ if (tseg1 > btc->tseg1_max)
+ {
+ tseg1 = btc->tseg1_max;
+ tseg2 = tseg - tseg1;
+ }
+
+ sample_point = 1000 * (tseg + CAN_CALC_SYNC_SEG - tseg2) / (tseg + CAN_CALC_SYNC_SEG);
+ sample_point_error = abs(sample_point_nominal - sample_point);
+
+ if ((sample_point <= sample_point_nominal) && (sample_point_error < best_sample_point_error))
+ {
+ best_sample_point = sample_point;
+ best_sample_point_error = sample_point_error;
+ *tseg1_ptr = tseg1;
+ *tseg2_ptr = tseg2;
+ }
+ }
+
+ if (sample_point_error_ptr)
+ *sample_point_error_ptr = best_sample_point_error;
+
+ return best_sample_point;
+}
+
+ft_error_t FCan_CalcBittiming(struct FCan_Bittiming *Bt_p)
+{
+ u32 bitrate; /* current bitrate */
+ u32 bitrate_error; /* difference between current and nominal value */
+ u32 best_bitrate_error = BEST_BITRATE_ERROR;
+ u32 sample_point_error; /* difference between current and nominal value */
+ u32 best_sample_point_error = BEST_BITRATE_ERROR;
+ u32 sample_point_nominal; /* nominal sample point */
+ u32 best_tseg = 0; /* current best value for tseg */
+ u32 best_brp = 0; /* current best value for brp */
+ u32 brp, tsegall, tseg, tseg1 = 0, tseg2 = 0;
+ u64 v64;
+ const struct can_bittiming_const *btc = &ftcan_bittiming_const;
+ struct FCan_Bittiming *bt = Bt_p;
+
+ if (bt->sample_point)
+ {
+ sample_point_nominal = bt->sample_point;
+ }
+ else
+ {
+ if (bt->bitrate > 800000)
+ sample_point_nominal = 750;
+ else if (bt->bitrate > 500000)
+ sample_point_nominal = 800;
+ else
+ sample_point_nominal = 875;
+ }
+
+ for (tseg = (btc->tseg1_max + btc->tseg2_max) * 2 + 1;
+ tseg >= (btc->tseg1_min + btc->tseg2_min) * 2; tseg--)
+ {
+ tsegall = CAN_CALC_SYNC_SEG + tseg / 2;
+
+ /* Compute all possible tseg choices (tseg=tseg1+tseg2) */
+ brp = CAN_CLK_FREQ / (tsegall * bt->bitrate) + tseg % 2;
+
+ /* choose brp step which is possible in system */
+ brp = (brp / btc->brp_inc) * btc->brp_inc;
+
+ if ((brp < btc->brp_min) || (brp > btc->brp_max))
+ continue;
+
+ bitrate = CAN_CLK_FREQ / (brp * tsegall);
+
+ bitrate_error = abs(bt->bitrate - bitrate);
+ /* tseg brp biterror */
+ if (bitrate_error > best_bitrate_error)
+ continue;
+
+ /* reset sample point error if we have a better bitrate */
+ if (bitrate_error < best_bitrate_error)
+ best_sample_point_error = BEST_BITRATE_ERROR;
+
+ can_update_sample_point(btc, sample_point_nominal, tseg / 2, &tseg1, &tseg2, &sample_point_error);
+ if (sample_point_error > best_sample_point_error)
+ continue;
+
+ best_sample_point_error = sample_point_error;
+ best_bitrate_error = bitrate_error;
+ best_tseg = tseg / 2;
+ best_brp = brp;
+
+ if (bitrate_error == 0 && sample_point_error == 0)
+ break;
+ }
+
+ if (best_bitrate_error)
+ {
+ /* Error in one-tenth of a percent */
+ v64 = (u64)best_bitrate_error * 1000;
+ div64_32(&v64, bt->bitrate);
+ bitrate_error = (u32)v64;
+ if (bitrate_error > CAN_CALC_MAX_ERROR)
+ {
+ FT_CAN_DEBUG_E("bitrate error");
+ }
+ return FCAN_FAILURE;
+ FT_CAN_DEBUG_E("bitrate error 2");
+ }
+
+ /* real sample point */
+ bt->sample_point = can_update_sample_point(btc, sample_point_nominal, best_tseg,
+ &tseg1, &tseg2, NULL);
+
+ v64 = (u64)best_brp * 1000 * 1000 * 1000;
+ div64_32(&v64, CAN_CLK_FREQ);
+ bt->tq = (u64)v64;
+ bt->prop_seg = tseg1 / 2;
+ bt->phase_seg1 = tseg1 - bt->prop_seg;
+ bt->phase_seg2 = tseg2;
+
+ /* check for sjw user settings */
+ if (!bt->sjw || !btc->sjw_max)
+ {
+ bt->sjw = 1;
+ }
+ else
+ {
+ /* bt->sjw is at least 1 -> sanitize upper bound to sjw_max */
+ if (bt->sjw > btc->sjw_max)
+ bt->sjw = btc->sjw_max;
+ /* bt->sjw must not be higher than tseg2 */
+ if (tseg2 < bt->sjw)
+ bt->sjw = tseg2;
+ }
+
+ bt->brp = best_brp;
+
+ /* real bitrate */
+ bt->bitrate = CAN_CLK_FREQ / (bt->brp * (CAN_CALC_SYNC_SEG + tseg1 + tseg2));
+ return FCAN_SUCCESS;
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_can/ft_can_g.c b/bsp/ft2004/libraries/bsp/ft_can/ft_can_g.c
new file mode 100644
index 0000000000..77edbc84fc
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_can/ft_can_g.c
@@ -0,0 +1,39 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-27 15:31:44
+ * @LastEditTime: 2021-04-27 15:31:44
+ * @Description:  Description of file
+ * @Modify History:
+ * * * Ver   Who        Date         Changes
+ * * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_can.h"
+#include "ft_parameters.h"
+
+FCan_Config_t FCan_Config[FT_CAN_NUM] =
+ {
+ {
+ .InstanceId = 0, /* Id of device */
+ .CanBaseAddress = FT_CAN0_BASEADDR, /* Can base Address */
+ .IrqNum = FT_CAN0_IRQNUM,
+ .BaudRate = 250000,
+ .TxFifoDeepth = 16,
+ },
+ {
+ .InstanceId = 1, /* Id of device */
+ .CanBaseAddress = FT_CAN1_BASEADDR, /* Can base Address */
+ .IrqNum = FT_CAN1_IRQNUM,
+ .BaudRate = 250000,
+ .TxFifoDeepth = 16,
+ },
+ {
+ .InstanceId = 2, /* Id of device */
+ .CanBaseAddress = FT_CAN2_BASEADDR, /* Can base Address */
+ .IrqNum = FT_CAN2_IRQNUM,
+ .BaudRate = 250000,
+ .TxFifoDeepth = 16,
+ }};
diff --git a/bsp/ft2004/libraries/bsp/ft_can/ft_can_hw.c b/bsp/ft2004/libraries/bsp/ft_can/ft_can_hw.c
new file mode 100644
index 0000000000..1af32abf46
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_can/ft_can_hw.c
@@ -0,0 +1,55 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-27 13:52:41
+ * @LastEditTime: 2021-04-27 13:52:41
+ * @Description:  Description of file
+ * @Modify History:
+ * * * Ver   Who        Date         Changes
+ * * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_can_hw.h"
+#include "ft_can.h"
+#include "ft_mux.h"
+#include "ft_parameters.h"
+#include "ft_math.h"
+#include "ft_assert.h"
+#include "ft_debug.h"
+
+#define CAN_HW_DEBUG_TAG "CAN_HW"
+
+#define CAN_HW_DEBUG_I(format, ...) FT_DEBUG_PRINT_I(CAN_HW_DEBUG_TAG, format, ##__VA_ARGS__)
+#define CAN_HW_DEBUG_E(format, ...) FT_DEBUG_PRINT_E(CAN_HW_DEBUG_TAG, format, ##__VA_ARGS__)
+#define CAN_HW_DEBUG_W(format, ...) FT_DEBUG_PRINT_W(CAN_HW_DEBUG_TAG, format, ##__VA_ARGS__)
+
+void FCan_Reset(FCan_t *Can_p)
+{
+ u32 RegValue;
+ FCan_Config_t *Config_p;
+ Ft_assertVoid(Can_p != NULL);
+ Ft_assertVoid(Can_p->IsReady == FT_COMPONENT_IS_READLY);
+ Config_p = &Can_p->Config;
+
+ RegValue = FCan_ReadReg(Config_p->CanBaseAddress, FCAN_CTRL_OFFSET);
+
+ if (RegValue & FCAN_CTRL_XFER_MASK)
+ {
+ CAN_HW_DEBUG_E("FT can is not in configration mode\n");
+ Ft_assertVoid(0);
+ return;
+ }
+
+ FCan_WriteReg(FT_PIN_DEMUX_BASE, FT_PIN_DEMUX_REG204_OFFSET, 0x89999990); // Reuse can IO
+
+ FCan_WriteReg(Config_p->CanBaseAddress, FCAN_CTRL_OFFSET, FCAN_CTRL_RESET_MASK);
+ FCan_SetBit(Config_p->CanBaseAddress, FCAN_CTRL_OFFSET, FCAN_CTRL_AIME_MASK);
+ FCan_WriteReg(Config_p->CanBaseAddress, FCAN_ACC_ID0_MASK_OFFSET, FCAN_ACC_IDN_MASK);
+ FCan_WriteReg(Config_p->CanBaseAddress, FCAN_ACC_ID1_MASK_OFFSET, FCAN_ACC_IDN_MASK);
+ FCan_WriteReg(Config_p->CanBaseAddress, FCAN_ACC_ID2_MASK_OFFSET, FCAN_ACC_IDN_MASK);
+ FCan_WriteReg(Config_p->CanBaseAddress, FCAN_ACC_ID3_MASK_OFFSET, FCAN_ACC_IDN_MASK);
+ FCan_ClearBit(Config_p->CanBaseAddress, FCAN_CTRL_OFFSET, FCAN_CTRL_RESET_MASK);
+ FCan_WriteReg(Config_p->CanBaseAddress, FCAN_INTR_OFFSET, FCAN_INTR_TEIE_MASK | FCAN_INTR_REIE_MASK);
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_can/ft_can_hw.h b/bsp/ft2004/libraries/bsp/ft_can/ft_can_hw.h
new file mode 100644
index 0000000000..634a765774
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_can/ft_can_hw.h
@@ -0,0 +1,161 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-27 13:52:47
+ * @LastEditTime: 2021-04-27 13:52:47
+ * @Description:  Description of file
+ * @Modify History:
+ * * * Ver   Who        Date         Changes
+ * * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef FT_CAN_HW_H
+#define FT_CAN_HW_H
+
+#include "ft_types.h"
+#include "ft_io.h"
+#include "ft_can.h"
+
+/***ft CAN REGISTER offset*/
+#define FCAN_CTRL_OFFSET 0x00 /* Global control register */
+#define FCAN_INTR_OFFSET 0x04 /* Interrupt register */
+#define FCAN_ARB_RATE_CTRL_OFFSET 0x08 /* Arbitration rate control register */
+#define FCAN_DAT_RATE_CTRL_OFFSET 0x0C /* Data rate control register */
+#define FCAN_ACC_ID0_OFFSET 0x10 /* Acceptance identifier0 register */
+#define FCAN_ACC_ID1_OFFSET 0x14 /* Acceptance identifier1 register */
+#define FCAN_ACC_ID2_OFFSET 0x18 /* Acceptance identifier2 register */
+#define FCAN_ACC_ID3_OFFSET 0x1C /* Acceptance identifier3 register */
+#define FCAN_ACC_ID0_MASK_OFFSET 0x20 /* Acceptance identifier0 mask register */
+#define FCAN_ACC_ID1_MASK_OFFSET 0x24 /* Acceptance identifier1 mask register */
+#define FCAN_ACC_ID2_MASK_OFFSET 0x28 /* Acceptance identifier2 mask register */
+#define FCAN_ACC_ID3_MASK_OFFSET 0x2C /* Acceptance identifier3 mask register */
+#define FCAN_XFER_STS_OFFSET 0x30 /* Transfer status register */
+#define FCAN_ERR_CNT_OFFSET 0x34 /* Error counter register */
+#define FCAN_FIFO_CNT_OFFSET 0x38 /* FIFO counter register */
+#define FCAN_DMA_CTRL_OFFSET 0x3C /* DMA request control register */
+#define FCAN_TX_FIFO_OFFSET 0x100 /* TX FIFO shadow register */
+#define FCAN_RX_FIFO_OFFSET 0x200 /* RX FIFO shadow register */
+
+/*----------------------------------------------------------------------------*/
+/* CAN register bit masks - FCAN_<REG>_<BIT>_MASK */
+/*----------------------------------------------------------------------------*/
+
+/* FCAN_CTRL mask */
+#define FCAN_CTRL_XFER_MASK (0x1 << 0) /* RW */ /*Transfer enable*/
+#define FCAN_CTRL_TXREQ_MASK (0x1 << 1) /* RW */ /*Transmit request*/
+#define FCAN_CTRL_AIME_MASK (0x1 << 2) /* RW */ /*Acceptance identifier mask enable*/
+#define FCAN_CTRL_RESET_MASK (0x1 << 6)
+
+/* FCAN_INTR mask */
+#define FCAN_INTR_STATUS_MASK (0xFF << 0) /* RO */ /*the interrupt status*/
+#define FCAN_INTR_BOIS_MASK (0x1 << 0) /* RO */ /*Bus off interrupt status*/
+#define FCAN_INTR_PWIS_MASK (0x1 << 1) /* RO */ /*Passive warning interrupt status*/
+#define FCAN_INTR_PEIS_MASK (0x1 << 2) /* RO */ /*Passive error interrupt status*/
+#define FCAN_INTR_RFIS_MASK (0x1 << 3) /* RO */ /*RX FIFO full interrupt status*/
+#define FCAN_INTR_TFIS_MASK (0x1 << 4) /* RO */ /*TX FIFO empty interrupt status*/
+#define FCAN_INTR_REIS_MASK (0x1 << 5) /* RO */ /*RX frame end interrupt status*/
+#define FCAN_INTR_TEIS_MASK (0x1 << 6) /* RO */ /*TX frame end interrupt status*/
+#define FCAN_INTR_EIS_MASK (0x1 << 7) /* RO */ /*Error interrupt status*/
+
+#define FCAN_INTR_EN_MASK (0xFF << 8) /* RO */ /*the interrupt enable*/
+#define FCAN_INTR_BOIE_MASK (0x1 << 8) /* RW */ /*Bus off interrupt enable*/
+#define FCAN_INTR_PWIE_MASK (0x1 << 9) /* RW */ /*Passive warning interrupt enable*/
+#define FCAN_INTR_PEIE_MASK (0x1 << 10) /* RW */ /*Passive error interrupt enable*/
+#define FCAN_INTR_RFIE_MASK (0x1 << 11) /* RW */ /*RX FIFO full interrupt enable*/
+#define FCAN_INTR_TFIE_MASK (0x1 << 12) /* RW */ /*TX FIFO empty interrupt enable*/
+#define FCAN_INTR_REIE_MASK (0x1 << 13) /* RW */ /*RX frame end interrupt enable*/
+#define FCAN_INTR_TEIE_MASK (0x1 << 14) /* RW */ /*TX frame end interrupt enable*/
+#define FCAN_INTR_EIE_MASK (0x1 << 15) /* RW */ /*Error interrupt enable*/
+
+#define FCAN_INTR_BOIC_MASK (0x1 << 16) /* WO */ /*Bus off interrupt clear*/
+#define FCAN_INTR_PWIC_MASK (0x1 << 17) /* WO */ /*Passive warning interrupt clear*/
+#define FCAN_INTR_PEIC_MASK (0x1 << 18) /* WO */ /*Passive error interrupt clear*/
+#define FCAN_INTR_RFIC_MASK (0x1 << 19) /* WO */ /*RX FIFO full interrupt clear*/
+#define FCAN_INTR_TFIC_MASK (0x1 << 20) /* WO */ /*TX FIFO empty interrupt clear*/
+#define FCAN_INTR_REIC_MASK (0x1 << 21) /* WO */ /*RX frame end interrupt clear*/
+#define FCAN_INTR_TEIC_MASK (0x1 << 22) /* WO */ /*TX frame end interrupt clear*/
+#define FCAN_INTR_EIC_MASK (0x1 << 23) /* WO */ /*Error interrupt clear*/
+
+/* FCAN_ACC_ID(0-3)_MASK mask */
+#define FCAN_ACC_IDN_MASK 0x1FFFFFFF /* WO */ /*don’t care the matching */
+/* FCAN_DAT_RATE_CTRL mask */
+
+/* FCAN_ERR_CNT_OFFSET mask */
+#define FCAN_ERR_CNT_RFN_MASK (0xFF << 0) /* RO */ /*Receive error counter*/
+#define FCAN_ERR_CNT_TFN_MASK (0xFF << 16) /* RO */ /*Transmit error counter*/
+
+/* FCAN_FIFO_CNT_OFFSET mask */
+#define FCAN_FIFO_CNT_RFN_MASK (0xFF << 0) /* RO */ /*Receive FIFO valid data number*/
+#define FCAN_FIFO_CNT_TFN_MASK (0xFF << 16) /* RO */ /*Transmit FIFO valid data number*/
+
+#define FCAN_ERR_CNT_TFN_SHIFT 16 /* Tx Error Count shift */
+#define FCAN_FIFO_CNT_TFN_SHIFT 16 /* Tx FIFO Count shift*/
+#define FCAN_IDR_ID1_SHIFT 21 /* Standard Messg Identifier */
+#define FCAN_IDR_ID2_SHIFT 1 /* Extended Message Identifier */
+#define FCAN_IDR_SDLC_SHIFT 14
+#define FCAN_IDR_EDLC_SHIFT 26
+#define FCAN_ACC_IDN_SHIFT 18 /*Standard ACC ID shift*/
+
+#define FCAN_IDR_ID2_MASK 0x0007FFFE /* Extended message ident */
+#define FCAN_IDR_ID1_MASK 0xFFE00000 /* Standard msg identifier */
+#define FCAN_IDR_IDE_MASK 0x00080000 /* Identifier extension */
+#define FCAN_IDR_SRR_MASK 0x00100000 /* Substitute remote TXreq */
+#define FCAN_IDR_RTR_MASK 0x00000001 /* Extended frames remote TX request */
+#define FCAN_IDR_DLC_MASK 0x0003C000 /* Standard msg dlc */
+#define FCAN_IDR_PAD_MASK 0x00003FFF /* Standard msg padding 1 */
+#define FCAN_IDR_EDLC_MASK 0x3C000000 /* Extended msg dlc */
+
+/* Can timming */
+#define FCAN_TSEG1_MIN 1
+#define FCAN_TSEG1_MAX 8
+#define FCAN_TSEG2_MIN 1
+#define FCAN_TSEG2_MAX 8
+#define FCAN_SJW_MAX 4
+#define FCAN_BRP_MIN 1
+#define FCAN_BRP_MAX 512
+#define FCAN_BRP_INC 1
+#define FCAN_CALC_SYNC_SEG 1
+
+/**
+*
+* This macro reads the given register.
+*
+* @param BaseAddr is the base address of the device.
+* @param RegOffset is the register offset to be read.
+*
+* @return The 32-bit value of the register
+*
+* @note None.
+*
+*****************************************************************************/
+#define FCan_ReadReg(BaseAddr, RegOffset) \
+ Ft_in32((BaseAddr) + (u32)(RegOffset))
+
+/****************************************************************************/
+/**
+*
+* This macro writes the given register.
+*
+* @param BaseAddr is the base address of the device.
+* @param RegOffset is the register offset to be written.
+* @param Data is the 32-bit value to write to the register.
+*
+* @return None.
+*
+* @note None.
+*
+*****************************************************************************/
+#define FCan_WriteReg(BaseAddr, RegOffset, Data) \
+ Ft_out32((BaseAddr) + (u32)(RegOffset), (u32)(Data))
+
+#define FCan_SetBit(BaseAddr, RegOffset, Data) \
+ Ft_setBit32((BaseAddr) + (u32)(RegOffset), (u32)(Data))
+
+#define FCan_ClearBit(BaseAddr, RegOffset, Data) \
+ Ft_clearBit32((BaseAddr) + (u32)(RegOffset), (u32)(Data))
+
+void FCan_Reset(FCan_t *Can_p);
+
+#endif // !
diff --git a/bsp/ft2004/libraries/bsp/ft_can/ft_can_intr.c b/bsp/ft2004/libraries/bsp/ft_can/ft_can_intr.c
new file mode 100644
index 0000000000..6fb4cdd074
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_can/ft_can_intr.c
@@ -0,0 +1,118 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-29 10:40:47
+ * @LastEditTime: 2021-04-29 10:40:47
+ * @Description:  Description of file
+ * @Modify History:
+ * * * Ver   Who        Date         Changes
+ * * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_can.h"
+#include "ft_can_hw.h"
+#include "ft_assert.h"
+#include "ft_types.h"
+
+ft_error_t FCan_SetHandler(FCan_t *Can_p, u32 HandlerType, FCan_irqHandler_t IrqCallBackFunc, void *IrqCallBackRef)
+{
+ ft_error_t status = FCAN_SUCCESS;
+ Ft_assertNonvoid(Can_p != NULL);
+ Ft_assertNonvoid(Can_p->IsReady == FT_COMPONENT_IS_READLY);
+ switch (HandlerType)
+ {
+ case FCAN_HANDLER_SEND:
+ Can_p->SendHandler = IrqCallBackFunc;
+ Can_p->SendRef = IrqCallBackRef;
+ break;
+ case FCAN_HANDLER_RECV:
+ Can_p->RecvHandler = IrqCallBackFunc;
+ Can_p->RecvRef = IrqCallBackRef;
+ break;
+ case FCAN_HANDLER_ERROR:
+ Can_p->ErrorHandler = IrqCallBackFunc;
+ Can_p->ErrorRef = IrqCallBackRef;
+ break;
+ default:
+ status = FCAN_FAILURE;
+ }
+
+ return status;
+}
+
+static void FCan_TxInterrupt(FCan_t *Can_p)
+{
+ FCan_Config_t *Config_p = &Can_p->Config;
+ FCan_SetBit(Config_p->CanBaseAddress, FCAN_INTR_OFFSET, FCAN_INTR_TEIC_MASK | FCAN_INTR_REIC_MASK);
+
+ if (0 != Can_p->TxFifoCnt)
+ {
+ Can_p->TxFifoCnt--;
+ FCan_ClearBit(Config_p->CanBaseAddress, FCAN_CTRL_OFFSET, FCAN_CTRL_XFER_MASK);
+ FCan_SetBit(Config_p->CanBaseAddress, FCAN_CTRL_OFFSET, FCAN_CTRL_TXREQ_MASK);
+ FCan_SetBit(Config_p->CanBaseAddress, FCAN_CTRL_OFFSET, FCAN_CTRL_XFER_MASK);
+ }
+ else
+ {
+ if (Can_p->SendHandler)
+ {
+ Can_p->SendHandler(Can_p->SendRef);
+ }
+ }
+}
+
+static void FCan_ErrorInterrupt(FCan_t *Can_p)
+{
+ if (Can_p->ErrorHandler)
+ {
+ Can_p->ErrorHandler(Can_p->ErrorRef);
+ }
+}
+
+static void FCan_RxInterrupt(FCan_t *Can_p)
+{
+ if (Can_p->RecvHandler)
+ {
+ Can_p->RecvHandler(Can_p->RecvRef);
+ }
+}
+
+void FCan_IntrHandler(void *InstancePtr)
+{
+ u32 Irq;
+ FCan_t *Can_p = (FCan_t *)InstancePtr;
+ FCan_Config_t *Config_p;
+ Ft_assertVoid(Can_p != NULL);
+ Ft_assertVoid(Can_p->IsReady == FT_COMPONENT_IS_READLY);
+ Config_p = &Can_p->Config;
+ Irq = FCan_ReadReg(Config_p->CanBaseAddress, FCAN_INTR_OFFSET);
+
+ if (0 == Irq)
+ {
+ return;
+ }
+
+ /* Check for the type of error interrupt and Processing it */
+ if (Irq & FCAN_INTR_TEIS_MASK)
+ {
+ Irq &= ~FCAN_INTR_REIS_MASK;
+ FCan_TxInterrupt(Can_p);
+ }
+
+ if (Irq & (FCAN_INTR_EIS_MASK | FCAN_INTR_RFIS_MASK |
+ FCAN_INTR_BOIS_MASK | FCAN_INTR_PEIS_MASK | FCAN_INTR_PWIS_MASK))
+ {
+ FCan_SetBit(Config_p->CanBaseAddress, FCAN_INTR_OFFSET, (FCAN_INTR_EIC_MASK | FCAN_INTR_RFIC_MASK | FCAN_INTR_BOIC_MASK | FCAN_INTR_PEIC_MASK | FCAN_INTR_PWIC_MASK));
+ FCan_ErrorInterrupt(Can_p);
+ }
+
+ if (Irq & FCAN_INTR_REIS_MASK)
+ {
+ FCan_SetBit(Config_p->CanBaseAddress, FCAN_INTR_OFFSET, FCAN_INTR_REIE_MASK);
+ FCan_RxInterrupt(Can_p);
+ FCan_SetBit(Config_p->CanBaseAddress, FCAN_INTR_OFFSET, FCAN_INTR_REIC_MASK);
+ FCan_SetBit(Config_p->CanBaseAddress, FCAN_INTR_OFFSET, FCAN_INTR_REIE_MASK);
+ }
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_can/ft_can_sinit.c b/bsp/ft2004/libraries/bsp/ft_can/ft_can_sinit.c
new file mode 100644
index 0000000000..d9b3c816a8
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_can/ft_can_sinit.c
@@ -0,0 +1,40 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-27 15:31:57
+ * @LastEditTime: 2021-04-27 15:31:57
+ * @Description:  Description of file
+ * @Modify History:
+ * * * Ver   Who        Date         Changes
+ * * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_can.h"
+#include "ft_parameters.h"
+
+extern FCan_Config_t FCan_Config[FT_CAN_NUM];
+
+/**
+ * @name:
+ * @msg:
+ * @in param:
+ * @return {*}
+ * @param {u32} InstanceId
+ */
+FCan_Config_t *FCan_LookupConfig(u32 InstanceId)
+{
+ FCan_Config_t *CfgPtr = NULL;
+ u32 Index;
+
+ for (Index = 0; Index < (u32)FT_CAN_NUM; Index++)
+ {
+ if (FCan_Config[Index].InstanceId == InstanceId)
+ {
+ CfgPtr = &FCan_Config[Index];
+ break;
+ }
+ }
+ return (FCan_Config_t *)CfgPtr;
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac.c b/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac.c
new file mode 100644
index 0000000000..c4ed19b408
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac.c
@@ -0,0 +1,109 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-05-25 16:43:14
+ * @Description:  This files is for gmac ctrl
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_gmac.h"
+#include "ft_gmac_hw.h"
+#include "ft_assert.h"
+#include "ft_io.h"
+#include "ft_status.h"
+#include "ft_printf.h"
+#include "ft_parameters.h"
+
+static void Ft_Gmac_StubHandler(void *args)
+{
+ Ft_assertVoidAlways();
+}
+
+static void Ft_Gmac_StubErrorHandler(void *CallBackRef, u32 ErrorWord)
+{
+ // Ft_assertVoidAlways();
+}
+
+s32 Ft_Gmac_HwInitialize(Ft_Gmac_t *Gmac)
+{
+ Ft_assertNonvoid(Gmac != NULL);
+ Ft_assertNonvoid(Gmac->IsReady == FT_COMPONENT_IS_READLY);
+ return FGmac_InitializeHw(&Gmac->Config);
+}
+
+s32 Ft_GmacCfgInitialize(Ft_Gmac_t *Gmac, FGmac_Config_t *Config)
+{
+ Ft_assertNonvoid(Gmac != NULL);
+ Ft_assertNonvoid(Config != NULL);
+
+ Gmac->Config = *Config;
+ Gmac->IsReady = FT_COMPONENT_IS_READLY;
+
+ FGmac_SetHandler(Gmac, FT_GMAC_TX_COMPLETE_CB_ID, Ft_Gmac_StubHandler, Gmac);
+ FGmac_SetHandler(Gmac, FT_GMAC_RX_COMPLETE_CB_ID, Ft_Gmac_StubHandler, Gmac);
+ FGmac_SetHandler(Gmac, FT_GMAC_DMA_ERROR_CB_ID, Ft_Gmac_StubErrorHandler, Gmac);
+
+ return FST_SUCCESS;
+}
+
+s32 Ft_Gmac_Start(Ft_Gmac_t *Gmac)
+{
+ FGmac_Config_t *Config = NULL;
+ Ft_assertNonvoid(Gmac != NULL);
+ Ft_assertNonvoid(Gmac->IsReady == FT_COMPONENT_IS_READLY);
+ Config = &Gmac->Config;
+
+ FGmac_DMAReceptionTransmissionEnable(Config);
+ FGmac_ReceptionTransmissionEnable(Config);
+
+ /* Clear Tx and Rx process stopped flags */
+ Ft_out32(Gmac->Config.BaseAddress + DMA_INTR_ENA_OFFSET, DMA_INTR_ENA_RIE | DMA_INTR_ENA_AIE | DMA_INTR_ENA_NIE);
+
+ return FST_SUCCESS;
+}
+
+s32 Ft_Gmac_Stop(Ft_Gmac_t *Gmac)
+{
+ FGmac_Config_t *Config = NULL;
+ Ft_assertNonvoid(Gmac != NULL);
+ Ft_assertNonvoid(Gmac->IsReady == FT_COMPONENT_IS_READLY);
+ Config = &Gmac->Config;
+
+ FGmac_TransmissionDisable(Config);
+ FGmac_ReceptionDisable(Config);
+ FGmac_DMATransmissionDisable(Config);
+ FGmac_DMAReceptionDisable(Config);
+ return FST_SUCCESS;
+}
+
+void Ft_Gmac_Phy_Debug(Ft_Gmac_t *Gmac)
+{
+
+ Ft_printf("\r\n ****************************** \r\n");
+}
+
+
+void Ft_Gmac_UseDefaultMacAddr(Ft_Gmac_t *Gmac, u8 *MacAddr)
+{
+ u32 MacAddrLo;
+ u32 MacAddrHi;
+ FGmac_Config_t *pConfig;
+ Ft_assertNoneReturn(Gmac != NULL);
+ pConfig = &Gmac->Config;
+
+ MacAddrLo = Ft_in32(pConfig->BaseAddress + GMAC_MAC_ADDR0_LOWER16BIT_OFFSET);
+ MacAddrHi = Ft_in32(pConfig->BaseAddress + GMAC_MAC_ADDR0_UPPER16BIT_OFFSET);
+
+ MacAddr[0] = MacAddrLo & 0xFF;
+ MacAddr[1] = (MacAddrLo >> 8) & 0xFF;
+ MacAddr[2] = (MacAddrLo >> 16) & 0xFF;
+ MacAddr[3] = (MacAddrLo >> 24) & 0xFF;
+ MacAddr[4] = MacAddrHi & 0xFF;
+ MacAddr[5] = (MacAddrHi >> 8) & 0xFF;
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac.h b/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac.h
new file mode 100644
index 0000000000..332c431456
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac.h
@@ -0,0 +1,319 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-05-24 14:32:56
+ * @Description:  This files is for
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ * 1.00a hh 2021-02-05 First release
+ */
+
+#ifndef FT_GMAC_H
+#define FT_GMAC_H
+
+#include "ft_types.h"
+#define GMAC_INC_DESC(x, y) (x) = (((x) + 1) % y)
+/**
+ * @name: Callback invoked when frame(s) have been sent or received in interrupt
+ * driven DMA mode .to set the send callback ,invoke FGmac_SetHandler()
+ * @msg:
+ * @param {void} *CallBackRef
+ * @return {*}
+ */
+typedef void (*FGmac_IntrCallback_t)(void *CallBackRef);
+
+/**
+ * @name: FGmac_ErrIntrCallback_t
+ * @msg: Callback whem asynchronous error occurs. To set this callback, invoke
+ * FGmac_ErrIntrCallback_t .
+ * @param {void} *CallBackRef
+ * @param {u32} ErrorWord definition varies with Error
+ * @return {*}
+ */
+typedef void (*FGmac_ErrIntrCallback_t)(void *CallBackRef, u32 ErrorWord);
+
+/**
+ *
+ *
+ */
+typedef void (*Ft_Gmac_MacPhyStatus_Callback)(void *CallBackRef, u32 MacPhyStatus);
+
+/** GMAC_SPEED */
+#define GMAC_SPEED_10M 0x00000001U
+#define GMAC_SPEED_100M 0x00000002U
+#define GMAC_SPEED_1000M 0x00000004U
+
+#define IS_RIGHT_SPEED()
+
+/* GMAC_AutoNegotiation */
+#define GMAC_AUTONEGOTIATION_ENABLE 0x00000001U
+#define GMAC_AUTONEGOTIATION_DISABLE 0x00000000U
+
+/* GMAC_Duplex_Mode */
+#define GMAC_MODE_FULLDUPLEX 0x00000001U
+#define GMAC_MODE_HALFDUPLEX 0x00000000U
+
+/* GMAC_Rx_Mode */
+#define GMAC_RXPOLLING_MODE 0x00000000U
+#define GMAC_RXINTERRUPT_MODE 0x00000001U
+
+/* GMAC_Checksum_Mode */
+#define GMAC_CHECKSUM_BY_SOFTWARE 0x00000000U
+#define GMAC_CHECKSUM_BY_HARDWARE 0x00000001U
+
+/* GMAC_Media_Interface */
+#define GMAC_MEDIA_INTERFACE_RGMII 0x00000000U
+#define GMAC_MEDIA_INTERFACE_MII 0x00000001U
+
+/* Gmac Error value */
+
+#define GMAC_ERROR_TRANSMIT_PROCESS_STOPPED 0x00000001U
+#define GMAC_ERROR_TRANSMIT_UNAVAILABLE_STATUS 0x00000002U
+#define GMAC_ERROR_TRANSMIT_JABBER_TIMEOUT 0x00000004U
+#define GMAC_ERROR_RECEIVE_FIFO_OVERFLOW 0x00000008U
+#define GMAC_ERROR_TRANSMIT_UNDERFLOW 0x00000010U
+#define GMAC_ERROR_RECEIVE_BUFFER_UNAVAILABLE 0x00000020U
+#define GMAC_ERROR_RECEIVE_PROCESS_STOPPED 0x00000040U
+#define GMAC_ERROR_RECEIVE_WATCHDOG_TIMEOUT 0x00000080U
+#define GMAC_ERROR_EARLY_TRANSMIT_INTERRUPT 0x000000100U
+#define GMAC_ERROR_FATAL_BUS_ERROR 0x000000200U
+#define GMAC_ERROR_UNDEFINED 0x000000400U
+
+typedef enum
+{
+ FT_GMAC_TX_COMPLETE_CB_ID = 0x01U, /*!< Gmac Tx Complete Callback ID */
+ FT_GMAC_RX_COMPLETE_CB_ID = 0x02U, /*!< Gmac Rx Complete Callback ID */
+ FT_GMAC_DMA_ERROR_CB_ID = 0x03U, /*!< Gmac DMA Error Callback ID */
+ FT_GMAC_MAC_PHY_STATUS_CB_ID = 0x04U, /*!< */
+} FGmac_IsrCallbackSelect_t;
+
+/* Gmac DMA Descriptors data structure definition */
+
+typedef struct
+{
+ volatile u32 Status; /*!< Status */
+ u32 Control; /*!< Control and Buffer1, Buffer2 lengths */
+ u32 Buffer1Addr; /*!< Buffer1 address pointer */
+ u32 Buffer2NextDescAddr; /*!< Buffer2 or next descriptor address pointer */
+} FGmac_DmaDesc_t;
+
+/* Received Frame Informations structure definition */
+typedef struct
+{
+ FGmac_DmaDesc_t *FSRxDesc; /*!< First Segment Rx Desc */
+ FGmac_DmaDesc_t *LSRxDesc; /*!< Last Segment Rx Desc */
+ u32 SegCount; /*!< Segment count */
+ u32 length; /*!< Frame length */
+ u32 buffer; /*!< Frame buffer */
+} FGmac_DmaRxFrameInfos;
+
+typedef struct
+{
+ u32 InstanceId; /* Id of device */
+ uintptr_t CommonAddress; /* Gmac Common Register */
+ uintptr_t BaseAddress; /* Physical base address of Mac Private Address */
+ u32 IRQ_NUM;
+ u32 IRQPriority;
+ s32 PhyAddr; /* Phy Ic Addre1 ,-1 is need to auto check*/
+ u32 clkMDC; /* MDC clock access PHY. [1.0MHz ~2.5MHz] */
+ u32 AutoNegotiation; /* Selects or not the AutoNegotiation mode for the external PHY
+ The AutoNegotiation allows an automatic setting of the Speed (10/100/1000Mbps)
+ and the mode (half/full-duplex).
+ This parameter can be a value of @ref GMAC_AutoNegotiation */
+ u32 Speed; /* Sets the Ethernet speed: 10/100/1000 Mbps.
+ This parameter can be a value of @ref GMAC_SPEED */
+ u32 DuplexMode; /* Selects the MAC duplex mode: Half-Duplex or Full-Duplex mode
+ This parameter can be a value of @ref GMAC_Duplex_Mode */
+ u32 RxMode; /* Selects the Ethernet Rx mode: Polling mode, Interrupt mode.
+ This parameter can be a value of @ref GMAC_Rx_Mode */
+ u32 ChecksumMode; /* Selects if the checksum is check by hardware or by software.
+ This parameter can be a value of @ref GMAC_Checksum_Mode */
+ u32 MediaInterface; /* Selects the media-independent interface or the reduced media-independent interface.
+ This parameter can be a value of @ref GMAC_Media_Interface */
+ u8 MacAddr[6]; /* 6 bytes Mac address */
+
+} FGmac_Config_t;
+
+/* Only for Dma ring structure */
+struct DescRingData
+{
+ u32 DescIndex; /* For Current Desc position */
+ u32 DescBufIndex; /* For Current Desc buffer buf position */
+ u32 DescMaxNumber; /* Max Number for Desc and Desc buffer */
+ u8 *DescBufBase; /* Desc buffer Base */
+};
+
+typedef struct
+{
+ FGmac_Config_t Config; /* Hardware configuration */
+ u32 IsReady; /* Device is initialised and ready */
+ u32 Options; /* Current options word */
+
+ FGmac_DmaDesc_t *RxDesc; /*!< Rx descriptor to Get */
+ struct DescRingData RxDescRingData;
+ FGmac_DmaDesc_t *TxDesc; /*!< Tx descriptor to Set */
+ struct DescRingData TxDescRingData;
+
+ FGmac_IntrCallback_t SendHandler;
+ FGmac_IntrCallback_t RecvHandler;
+ Ft_Gmac_MacPhyStatus_Callback StatusHandler;
+ void *SendArgs;
+ void *RecvArgs;
+ void *StatusArgs;
+ FGmac_ErrIntrCallback_t ErrorHandler;
+ void *ErrorArgs;
+
+ FGmac_DmaRxFrameInfos DMARxFrameInfos; /* Only for chain structure */
+
+} Ft_Gmac_t;
+
+/**
+ * @name: FGmac_DmaRxDescRingInit
+ * @msg: 化标准 DMA 接收描述符 在ring结构下的初始化。
+ * @param {Ft_Gmac_t} *Gmac Gmac对象
+ * @param {FGmac_DmaDesc_t} *DMARxDescTab 用户定义的静态 DMA 接收描述符表格
+ * @param {u8} *RxBuff 用户定义的用于匹配 DMA 接收描述符表格的缓冲区
+ * @param {u32} DescBufPerLength 每个缓冲区的大小
+ * @param {u32} RxBuffCount 缓冲区的总数量
+ * @return {s32} Common_status 参数。
+ */
+s32 FGmac_DmaRxDescRingInit(Ft_Gmac_t *Gmac,
+ FGmac_DmaDesc_t *DMATxDescTab,
+ u8 *TxBuff,
+ u32 DescBufPerLength,
+ u32 TxBuffCount);
+
+/**
+ * @name: FGmac_DmaTxDescRingInit
+ * @msg: 标准 DMA 发送描述符 在ring结构下的初始化。
+ * @param {Ft_Gmac_t} *Gmac Gmac对象
+ * @param {FGmac_DmaDesc_t} *DMATxDescTab 用户定义的静态 DMA 发送描述符表格
+ * @param {u8} *TxBuff 用户定义的用于匹配 DMA 发送描述符表格的缓冲区
+ * @param {u32} DescBufPerLength 每个缓冲区的大小
+ * @param {u32} TxBuffCount 缓冲区的总数量
+ * @return {s32} Common_status 参数
+ */
+s32 FGmac_DmaTxDescRingInit(Ft_Gmac_t *Gmac,
+ FGmac_DmaDesc_t *DMATxDescTab,
+ u8 *TxBuff,
+ u32 DescBufPerLength,
+ u32 TxBuffCount);
+
+/**
+ * @name: FGmac_TransmitframeRingPoll
+ * @msg: 轮询的方式发送DMA发送表述符
+ * @param {Ft_Gmac_t} *Gmac Gmac对象
+ * @param {uint32_t} FrameLength 需要发送数据的有效长度
+ * @return {s32} Common_status 参数
+ */
+s32 FGmac_TransmitframeRingPoll(Ft_Gmac_t *Gmac, uint32_t FrameLength);
+
+/**
+ * @name: FGmac_RingGetReceivedFrame_IT
+ * @msg: 检查标准ring结构的DMA接收符中是否有完整的数据包。
+ * @param {Ft_Gmac_t} *Gmac Gmac对象
+ * @return {s32} Common_status 参数
+ */
+s32 FGmac_RingGetReceivedFrame_IT(Ft_Gmac_t *Gmac);
+
+/**
+ * @name: FGmac_ResumeTransmission
+ * @msg: 检查 DMA_STATUS_TU 符号是否存在,如果存在将其置位,恢复DMA 描述符的发送 。
+ * @param {Ft_Gmac_t} *Gmac Gmac对象
+ * @return {void}
+ */
+void FGmac_ResumeTransmission(Ft_Gmac_t *Gmac);
+
+/**
+ * @name: FGmac_SetTransmitUnderflow
+ * @msg: 检查 DMA_STATUS_UNF 符号是否存在,如果存在将其置位,恢复DMA 描述符的发送 。
+ * @param {Ft_Gmac_t} *Gmac Gmac对象
+ * @return {void}
+ */
+void FGmac_SetTransmitUnderflow(Ft_Gmac_t *Gmac);
+
+/**
+ * @name: FGmac_ResumeTransmissionReception
+ * @msg: 检查 DMA_STATUS_RU 符号是否存在,如果存在将其置位,恢复DMA 描述符的接收 。
+ * @param {Ft_Gmac_t} *Gmac
+ * @return {void}
+ */
+void FGmac_ResumeTransmissionReception(Ft_Gmac_t *Gmac);
+
+/**
+ * @name: Ft_Gmac_LookupConfig
+ * @msg: 获取 Gmac 静态预设配置参数 。
+ * @param {u32} InstanceId Gmac 实例编号。
+ * @return {FGmac_Config_t *} 返回Gmac的静态配置
+ */
+FGmac_Config_t *Ft_Gmac_LookupConfig(u32 InstanceId);
+
+/**
+ * @name: Ft_Gmac_HwInitialize
+ * @msg: 对于Gmac Mac 层 与Phy 层的硬件部分进行预设初始化配置
+ * @param {Ft_Gmac_t} *Gmac Gmac对象。
+ * @return {s32} Common_status 参数
+ */
+s32 Ft_Gmac_HwInitialize(Ft_Gmac_t *Gmac);
+
+/**
+ * @name: Ft_GmacCfgInitialize
+ * @msg: 初始化,硬件配置相关参数。
+ * @param {Ft_Gmac_t} *Gmac Gmac对象。
+ * @param {FGmac_Config_t} *Config
+ * @return {s32} Common_status 参数
+ */
+s32 Ft_GmacCfgInitialize(Ft_Gmac_t *Gmac, FGmac_Config_t *Config);
+
+/**
+ * @name: Ft_Gmac_Start
+ * @msg: 开启Gmac 的 发送接收功能,并且开启中断功能。
+ * @param {Ft_Gmac_t} *Gmac Gmac对象。
+ * @return {s32} Common_status 参数
+ */
+s32 Ft_Gmac_Start(Ft_Gmac_t *Gmac);
+
+/**
+ * @name: Ft_Gmac_Stop
+ * @msg: 关闭Gmac 的 发送接收功能。
+ * @param {Ft_Gmac_t} *Gmac Gmac对象。
+ * @return {s32} Common_status 参数
+ */
+s32 Ft_Gmac_Stop(Ft_Gmac_t *Gmac);
+
+/**
+ * @name: FGmac_IntrHandler
+ * @msg: Gmac 中断函数,用于响应Gmac 相关所以函数
+ * @param {void} *Args Ft_Gmac_t *Gmac 参数传入
+ * @return {void}
+ */
+void FGmac_IntrHandler(void *Args);
+
+/**
+ * @name: FGmac_SetHandler
+ * @msg: 根据SelectIndex 配置 中断过程中响应函数
+ * @param {Ft_Gmac_t} *Gmac Gmac对象。
+ * @param {FGmac_IsrCallbackSelect_t} SelectIndex
+ * @param {void} *FuncPtr
+ * @param {void} *Args
+ * @return {s32} Common_status 参数
+ */
+s32 FGmac_SetHandler(Ft_Gmac_t *Gmac, FGmac_IsrCallbackSelect_t SelectIndex, void *FuncPtr, void *Args);
+
+void Ft_Gmac_Phy_Debug(Ft_Gmac_t *Gmac);
+
+/**
+ * @name: Ft_Gmac_UseDefaultMacAddr
+ * @msg: 在有uboot的模式之下,使用默认的Mac0配置参数。
+ * @in param{Ft_Gmac_t *}: Gmac对象
+ * @out param{u8 *}: 输出的Mac参数
+ * @return {None}:
+ */
+void Ft_Gmac_UseDefaultMacAddr(Ft_Gmac_t *Gmac, u8 *MacAddr);
+
+#endif // !GMAC_H
diff --git a/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_desc.c b/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_desc.c
new file mode 100644
index 0000000000..6071e08df9
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_desc.c
@@ -0,0 +1,357 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-05-25 16:42:13
+ * @Description:  This files is for gmac description
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_gmac_desc.h"
+#include "ft_gmac_hw.h"
+#include "ft_parameters.h"
+
+#include "ft_io.h"
+#include "ft_status.h"
+#include "ft_assert.h"
+#include "ft_cache.h"
+#include "ft_debug.h"
+#include <string.h>
+
+#define GMAC_DESC_DEBUG_TAG "GMAC_DESC"
+
+#define GMAC_DESC_DEBUG_I(format, ...) FT_DEBUG_PRINT_I(GMAC_DESC_DEBUG_TAG, format, ##__VA_ARGS__)
+#define GMAC_DESC_DEBUG_E(format, ...) FT_DEBUG_PRINT_E(GMAC_DESC_DEBUG_TAG, format, ##__VA_ARGS__)
+#define GMAC_DESC_DEBUG_W(format, ...) FT_DEBUG_PRINT_W(GMAC_DESC_DEBUG_TAG, format, ##__VA_ARGS__)
+
+void FGmac_ResumeTransmission(Ft_Gmac_t *Gmac)
+{
+ /* When Tx Buffer unavailable flag is set: clear it and resume transmission */
+ if ((Ft_in32(Gmac->Config.BaseAddress + DMA_STATUS_OFFSET) & DMA_STATUS_TU) == DMA_STATUS_TU)
+ {
+ /* Clear TBUS GMAC DMA flag */
+ Ft_out32(Gmac->Config.BaseAddress + DMA_STATUS_OFFSET, DMA_STATUS_TU);
+
+ /* Resume DMA transmission*/
+ Ft_out32(Gmac->Config.BaseAddress + DMA_XMT_POLL_DEMAND_OFFSET, 0xff);
+ }
+}
+
+void FGmac_SetTransmitUnderflow(Ft_Gmac_t *Gmac)
+{
+ /* When Tx Buffer unavailable flag is set: clear it and resume transmission */
+ if ((Ft_in32(Gmac->Config.BaseAddress + DMA_STATUS_OFFSET) & DMA_STATUS_UNF) == DMA_STATUS_UNF)
+ {
+ /* Clear TBUS GMAC DMA flag */
+ Ft_out32(Gmac->Config.BaseAddress + DMA_STATUS_OFFSET, DMA_STATUS_UNF);
+
+ /* Resume DMA transmission*/
+ Ft_out32(Gmac->Config.BaseAddress + DMA_XMT_POLL_DEMAND_OFFSET, 0xff);
+ }
+}
+
+s32 FGmac_DMATxDescChainInit(Ft_Gmac_t *Gmac, FGmac_DmaDesc_t *DMATxDescTab, u8 *TxBuff, u32 TxBuffCount)
+{
+ u32 i;
+ FGmac_DmaDesc_t *TxDesc;
+ Ft_assertNonvoid(Gmac != NULL);
+ Ft_assertNonvoid(Gmac->IsReady == FT_COMPONENT_IS_READLY);
+
+ /* Make Each DmaTx descriptor with initialized value*/
+ for (i = 0; i < TxBuffCount; i++)
+ {
+ TxDesc = DMATxDescTab + i;
+ TxDesc->Control = DMA_TDES1_SECOND_ADDRESS_CHAINED;
+ TxDesc->Buffer1Addr = (u32)(&TxBuff[i * GMAC_MAX_PACKET_SIZE]);
+
+ /* Initialize the next descriptor with the Next Descriptor Polling Enable */
+ if (i < (TxBuffCount - 1))
+ {
+ /* Set next descriptor address register with next descriptor base address */
+ TxDesc->Buffer2NextDescAddr = (u32)(DMATxDescTab + i + 1);
+ Ft_printf(" Buffer2NextDescAddr %x \r\n", TxDesc->Buffer2NextDescAddr);
+ }
+ else
+ {
+ /* For last descriptor, set next descriptor address register equal to the first descriptor base address */
+ TxDesc->Buffer2NextDescAddr = (u32)DMATxDescTab;
+ Ft_printf(" Buffer2NextDescAddr %x \r\n", TxDesc->Buffer2NextDescAddr);
+ }
+ }
+ Ft_printf("DMATxDescTab addr is %x", DMATxDescTab);
+
+ return FST_SUCCESS;
+}
+
+s32 FGmac_DmaTxDescRingInit(Ft_Gmac_t *Gmac, FGmac_DmaDesc_t *DMATxDescTab, u8 *TxBuff, u32 DescBufPerLength, u32 TxBuffCount)
+{
+ u32 i;
+ FGmac_DmaDesc_t *TxDesc;
+ Ft_assertNonvoid(Gmac != NULL);
+ Ft_assertNonvoid(Gmac->IsReady == FT_COMPONENT_IS_READLY);
+
+ memset(&Gmac->TxDescRingData, 0, sizeof(Gmac->TxDescRingData));
+ Gmac->TxDescRingData.DescMaxNumber = TxBuffCount;
+ memset(DMATxDescTab, 0, sizeof(FGmac_DmaDesc_t) * TxBuffCount);
+ DMATxDescTab[TxBuffCount - 1].Control |= DMA_TDES1_END_RING;
+ for (i = 0; i < TxBuffCount; i++)
+ {
+ TxDesc = DMATxDescTab + i;
+ FCache_cpuDcacheInvalidate(&TxBuff[i * DescBufPerLength], DescBufPerLength);
+ TxDesc->Buffer1Addr = (u32)(&TxBuff[i * DescBufPerLength]);
+ }
+ Ft_out32(Gmac->Config.BaseAddress + DMA_TX_BASE_ADDR_OFFSET, (u32)DMATxDescTab);
+ return FST_SUCCESS;
+}
+
+s32 FGmac_TransmitframeRingPoll(Ft_Gmac_t *Gmac, uint32_t FrameLength)
+{
+ u32 Size = 0U;
+ u32 i = 0U;
+ u32 BufCount = 0U;
+ FGmac_DmaDesc_t *TxDesc;
+
+ if (0U == FrameLength)
+ {
+ return FST_SUCCESS;
+ }
+
+ if (FrameLength > GMAC_MAX_PACKET_SIZE)
+ {
+ BufCount = FrameLength / GMAC_MAX_PACKET_SIZE;
+ if (FrameLength % GMAC_MAX_PACKET_SIZE)
+ {
+ BufCount++;
+ }
+ }
+ else
+ {
+ BufCount = 1U;
+ }
+
+ if (BufCount == 1U)
+ {
+
+ TxDesc = &Gmac->TxDesc[Gmac->TxDescRingData.DescIndex];
+ /* Set LAST and FIRST segment */
+ TxDesc->Control |= (DMA_TDES1_FIRST_SEGMENT | DMA_TDES1_LAST_SEGMENT);
+
+ /* Set frame size */
+ TxDesc->Control &= ~(DMA_TDES1_BUFFER1_SIZE_MASK);
+ TxDesc->Control |= (FrameLength & DMA_TDES1_BUFFER1_SIZE_MASK);
+ /* Set Own bit of the Tx descriptor Status: gives the buffer back to ETHERNET DMA */
+ TxDesc->Status |= (DMA_TDES0_OWN);
+ GMAC_INC_DESC(Gmac->TxDescRingData.DescIndex, Gmac->TxDescRingData.DescMaxNumber);
+ }
+ else
+ {
+ for (i = 0U; i < BufCount; i++)
+ {
+ TxDesc = &Gmac->TxDesc[Gmac->TxDescRingData.DescIndex];
+ /* Clear FIRST and LAST segment bits */
+ TxDesc->Control &= ~(DMA_TDES1_FIRST_SEGMENT | DMA_TDES1_LAST_SEGMENT);
+
+ if (i == 0U)
+ {
+ /* Setting the first segment bit */
+ TxDesc->Control |= DMA_TDES1_FIRST_SEGMENT;
+ }
+
+ /* Program size */
+ TxDesc->Control &= ~(DMA_TDES1_BUFFER1_SIZE_MASK);
+ TxDesc->Control |= (GMAC_MAX_PACKET_SIZE & DMA_TDES1_BUFFER1_SIZE_MASK);
+
+ if (i == (BufCount - 1U))
+ {
+ /* Setting the last segment bit */
+ TxDesc->Control |= (DMA_TDES1_LAST_SEGMENT);
+ Size = FrameLength - (BufCount - 1U) * GMAC_MAX_PACKET_SIZE;
+ TxDesc->Control &= ~(DMA_TDES1_BUFFER1_SIZE_MASK);
+ TxDesc->Control |= (Size & DMA_TDES1_BUFFER1_SIZE_MASK);
+ }
+
+ /* Set Own bit of the Tx descriptor Status: gives the buffer back to ETHERNET DMA */
+ TxDesc->Status |= (DMA_TDES0_OWN);
+
+ GMAC_INC_DESC(Gmac->TxDescRingData.DescIndex, Gmac->TxDescRingData.DescMaxNumber);
+ }
+ }
+
+ FGmac_ResumeTransmission(Gmac);
+
+ return FST_SUCCESS;
+}
+
+s32 FGmac_DMARxDescChainInit(Ft_Gmac_t *Gmac, FGmac_DmaDesc_t *DMARxDescTab, u8 *RxBuff, u32 RxBuffCount)
+{
+ u32 i;
+ FGmac_DmaDesc_t *RxDesc;
+ Ft_assertNonvoid(Gmac != NULL);
+ Ft_assertNonvoid(Gmac->IsReady == FT_COMPONENT_IS_READLY);
+
+ for (i = 0; i < RxBuffCount; i++)
+ {
+ RxDesc = DMARxDescTab + i;
+ /* Set Own bit of the Rx descriptor Status */
+ RxDesc->Status = DMA_RDES0_OWN;
+
+ /* Set Buffer1 size and Second Address Chained bit */
+ RxDesc->Control = DMA_RDES1_BUFFER1_SIZE_MASK & (u32)(GMAC_MAX_PACKET_SIZE);
+ RxDesc->Control |= DMA_RDES1_SECOND_ADDRESS_CHAINED;
+ /* Set Buffer1 address pointer */
+ RxDesc->Buffer1Addr = (u32)(&RxBuff[i * GMAC_MAX_PACKET_SIZE]);
+
+ /* Initialize the next descriptor with the Next Descriptor Polling Enable */
+ if (i < (RxBuffCount - 1))
+ {
+ /* Set next descriptor address register with next descriptor base address */
+ RxDesc->Buffer2NextDescAddr = (u32)(DMARxDescTab + i + 1);
+ }
+ else
+ {
+ /* For last descriptor, set next descriptor address register equal to the first descriptor base address */
+ RxDesc->Buffer2NextDescAddr = (u32)(DMARxDescTab);
+ }
+
+ // Ft_printf("rx Buffer2NextDescAddr %x \r\n", RxDesc->Buffer2NextDescAddr);
+ }
+ Ft_out32(Gmac->Config.BaseAddress + DMA_RCV_BASE_ADDR_OFFSET, (u32)DMARxDescTab);
+ return FST_SUCCESS;
+}
+
+s32 FGmac_DmaRxDescRingInit(Ft_Gmac_t *Gmac, FGmac_DmaDesc_t *DMARxDescTab, u8 *RxBuff, u32 DescBufPerLength, u32 RxBuffCount)
+{
+ u32 i;
+ FGmac_DmaDesc_t *RxDesc;
+ Ft_assertNonvoid(Gmac != NULL);
+ Ft_assertNonvoid(Gmac->IsReady == FT_COMPONENT_IS_READLY);
+
+ memset(&Gmac->RxDescRingData, 0, sizeof(Gmac->RxDescRingData));
+ Gmac->RxDescRingData.DescMaxNumber = RxBuffCount;
+ memset(DMARxDescTab, 0, sizeof(FGmac_DmaDesc_t) * RxBuffCount);
+
+ for (i = 0; i < RxBuffCount; i++)
+ {
+ RxDesc = DMARxDescTab + i;
+ /* Set Own bit of the Rx descriptor Status */
+ RxDesc->Status = DMA_RDES0_OWN;
+ /* Set Buffer1 size and Second Address Chained bit */
+ RxDesc->Control = DMA_RDES1_BUFFER1_SIZE_MASK & (u32)(DescBufPerLength);
+ /* Set Buffer1 address pointer */
+ FCache_cpuDcacheInvalidate(&RxBuff[i * DescBufPerLength], DescBufPerLength);
+ RxDesc->Buffer1Addr = (u32)(&RxBuff[i * DescBufPerLength]);
+
+ if (i == (RxBuffCount - 1))
+ {
+ RxDesc->Control |= DMA_RDES1_END_RING;
+ }
+ }
+
+ Ft_out32(Gmac->Config.BaseAddress + DMA_RCV_BASE_ADDR_OFFSET, (u32)DMARxDescTab);
+
+ return FST_SUCCESS;
+}
+
+void FGmac_ResumeTransmissionReception(Ft_Gmac_t *Gmac)
+{
+ /* When Rx Buffer unavailable flag is set: clear it and resume transmission */
+ if ((Ft_in32(Gmac->Config.BaseAddress + DMA_STATUS_OFFSET) & DMA_STATUS_RU) == DMA_STATUS_RU)
+ {
+ /* Clear RBUS GMAC DMA flag */
+ Ft_out32(Gmac->Config.BaseAddress + DMA_STATUS_OFFSET, DMA_STATUS_RU);
+
+ /* Resume DMA transmission*/
+ Ft_out32(Gmac->Config.BaseAddress + DMA_RCV_POLL_DEMAND_OFFSET, 0xff);
+ }
+}
+
+s32 FGmac_RingGetReceivedFrame_IT(Ft_Gmac_t *Gmac)
+{
+ u32 DescriptorsCounter = 0U;
+ FGmac_DmaDesc_t *RxDesc;
+ RxDesc = &Gmac->RxDesc[Gmac->RxDescRingData.DescIndex];
+
+ while (((RxDesc->Status & DMA_RDES0_OWN) == 0) && DescriptorsCounter < Gmac->RxDescRingData.DescMaxNumber)
+ {
+ DescriptorsCounter++;
+
+ /* Check if first segment in frame */
+ if ((RxDesc->Status & (DMA_RDES0_FIRST_DESCRIPTOR | DMA_RDES0_LAST_DESCRIPTOR)) == (u32)DMA_RDES0_FIRST_DESCRIPTOR)
+ {
+ // GMAC_DESC_DEBUG_I("find first frame");
+ Gmac->RxDescRingData.DescBufIndex = Gmac->RxDescRingData.DescIndex;
+ /* Point to next descriptor */
+ GMAC_INC_DESC(Gmac->RxDescRingData.DescIndex, Gmac->RxDescRingData.DescMaxNumber);
+ RxDesc = &Gmac->RxDesc[Gmac->RxDescRingData.DescIndex];
+ } /* Check if intermediate segment */
+ else if ((RxDesc->Status & (DMA_RDES0_FIRST_DESCRIPTOR | DMA_RDES0_LAST_DESCRIPTOR)) == 0)
+ {
+ // GMAC_DESC_DEBUG_I("find invaild frame");
+ /* Point to next descriptor */
+ GMAC_INC_DESC(Gmac->RxDescRingData.DescIndex, Gmac->RxDescRingData.DescMaxNumber);
+ RxDesc = &Gmac->RxDesc[Gmac->RxDescRingData.DescIndex];
+ } /* Should be last segment */
+ else
+ {
+ Gmac->RxDescRingData.DescBufIndex = Gmac->RxDescRingData.DescIndex;
+ GMAC_INC_DESC(Gmac->RxDescRingData.DescIndex, Gmac->RxDescRingData.DescMaxNumber);
+ return FST_SUCCESS;
+ }
+ }
+ return FST_FAILURE;
+}
+
+s32 FGmac_GetReceivedFrame(Ft_Gmac_t *Gmac)
+{
+ u32 FrameLength = 0U;
+ /* Check if segment is not owned by DMA */
+ if ((Gmac->RxDesc->Status & DMA_RDES0_OWN) == 0)
+ {
+ if ((Gmac->RxDesc->Status & DMA_RDES0_LAST_DESCRIPTOR) != 0)
+ {
+ /* increment segment count */
+ Gmac->DMARxFrameInfos.SegCount++;
+
+ /* Check if last segment is first segment: one segment contains the frame */
+ if (1U == Gmac->DMARxFrameInfos.SegCount)
+ {
+ (Gmac->DMARxFrameInfos).FSRxDesc = Gmac->RxDesc;
+ }
+
+ Gmac->DMARxFrameInfos.LSRxDesc = Gmac->RxDesc;
+
+ /* Get the Frame Length of the received packet: substruct 4 bytes of the CRC */
+ FrameLength = (((Gmac->RxDesc)->Status & DMA_RDES0_FRAME_LEN_MASK) >> 16U) - 4U;
+ Gmac->DMARxFrameInfos.length = FrameLength;
+
+ /* Get the address of the buffer start address */
+ Gmac->DMARxFrameInfos.buffer = ((Gmac->DMARxFrameInfos).FSRxDesc)->Buffer1Addr;
+ /* point to next descriptor */
+ Gmac->RxDesc = (FGmac_DmaDesc_t *)((Gmac->RxDesc)->Buffer2NextDescAddr);
+
+ return FST_SUCCESS;
+ }
+ /* Check if first segment */
+ else if ((Gmac->RxDesc->Status & DMA_RDES0_FIRST_DESCRIPTOR) == (u32)DMA_RDES0_FIRST_DESCRIPTOR)
+ {
+ (Gmac->DMARxFrameInfos).FSRxDesc = Gmac->RxDesc;
+ (Gmac->DMARxFrameInfos).LSRxDesc = NULL;
+ (Gmac->DMARxFrameInfos).SegCount = 1U;
+ /* Point to next descriptor */
+ Gmac->RxDesc = (FGmac_DmaDesc_t *)(Gmac->RxDesc->Buffer2NextDescAddr);
+ } /* Check if intermediate segment */
+ else
+ {
+ (Gmac->DMARxFrameInfos).SegCount++;
+ /* Point to next descriptor */
+ Gmac->RxDesc = (FGmac_DmaDesc_t *)(Gmac->RxDesc->Buffer2NextDescAddr);
+ }
+ }
+
+ return FST_FAILURE;
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_desc.h b/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_desc.h
new file mode 100644
index 0000000000..91dd19bba2
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_desc.h
@@ -0,0 +1,20 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-04-07 13:24:16
+ * @Description:  This files is for gmac descrption
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef GMAC_DESC_H
+#define GMAC_DESC_H
+
+#include "ft_gmac.h"
+
+#endif // !
diff --git a/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_g.c b/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_g.c
new file mode 100644
index 0000000000..48ca3ddbeb
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_g.c
@@ -0,0 +1,47 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-04-07 13:24:30
+ * @Description:  This files is for gmac config
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_gmac.h"
+#include "ft_parameters.h"
+
+FGmac_Config_t Gmac_ConfigTable[FT_GMAC_INSTANCES_NUM] = {
+ {FT_GMAC0_ID,
+ FT_GMAC_COMMON_ADDR,
+ FT_GMAC0_BASEADDR,
+ GMAC0_ISRNUM,
+ GMAC0_ISRPRIORITY,
+ 0,
+ 5,
+ GMAC_AUTONEGOTIATION_ENABLE,
+ GMAC_SPEED_1000M,
+ GMAC_MODE_FULLDUPLEX,
+ GMAC_RXINTERRUPT_MODE,
+ GMAC_CHECKSUM_BY_SOFTWARE,
+ GMAC_MEDIA_INTERFACE_RGMII,
+ FT_GMAC0_DEFAULT_ADDR},
+ {FT_GMAC1_ID,
+ FT_GMAC_COMMON_ADDR,
+ FT_GMAC1_BASEADDR,
+ GMAC1_ISRNUM,
+ GMAC1_ISRPRIORITY,
+ 0,
+ 5,
+ GMAC_AUTONEGOTIATION_ENABLE,
+ GMAC_SPEED_1000M,
+ GMAC_MODE_FULLDUPLEX,
+ GMAC_RXINTERRUPT_MODE,
+ GMAC_CHECKSUM_BY_SOFTWARE,
+ GMAC_MEDIA_INTERFACE_RGMII,
+ {0}},
+};
diff --git a/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_hw.c b/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_hw.c
new file mode 100644
index 0000000000..a46bad28b3
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_hw.c
@@ -0,0 +1,566 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-05-25 16:42:23
+ * @Description:  This files is for gmac register
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_gmac_hw.h"
+#include "ft_types.h"
+#include "ft_generic_timer.h"
+#include "ft_assert.h"
+#include "ft_status.h"
+#include "ft_io.h"
+#include "ft_debug.h"
+#define PHY_CONFIG_DELAY_US 100
+
+#define GMAC_HW_DEBUG_TAG "GMAC_HW"
+
+#define GMAC_HW_DEBUG_I(format, ...) FT_DEBUG_PRINT_I(GMAC_HW_DEBUG_TAG, format, ##__VA_ARGS__)
+#define GMAC_HW_DEBUG_E(format, ...) FT_DEBUG_PRINT_E(GMAC_HW_DEBUG_TAG, format, ##__VA_ARGS__)
+#define GMAC_HW_DEBUG_W(format, ...) FT_DEBUG_PRINT_W(GMAC_HW_DEBUG_TAG, format, ##__VA_ARGS__)
+
+s32 Gmac_WritePHYRegister(FGmac_Config_t *Config, u16 PHYReg, u32 RegValue)
+{
+ u32 TmpReg;
+ u32 Wait_Counter = 0;
+
+ TmpReg = Ft_in32(Config->BaseAddress + GMAC_MII_ADDR_OFFSET);
+
+ TmpReg |= GMAC_MII_ADDR_CR(Config->clkMDC);
+ TmpReg |= GMAC_MII_ADDR_PA(Config->PhyAddr); /* Set the PHY device address */
+ TmpReg |= GMAC_MII_ADDR_GR(PHYReg); /* Set the PHY register address */
+ TmpReg |= GMAC_MII_ADDR_GW; /* Set the write mode */
+ TmpReg |= GMAC_MII_ADDR_GB; /* Set the MII Busy bit */
+
+ Ft_out32(Config->BaseAddress + GMAC_MII_DATA_OFFSET, RegValue);
+ Ft_out32(Config->BaseAddress + GMAC_MII_ADDR_OFFSET, TmpReg);
+
+ /* Check for the Busy flag */
+ while ((Ft_in32(Config->BaseAddress + GMAC_MII_ADDR_OFFSET) & GMAC_MII_ADDR_GB) == GMAC_MII_ADDR_GB)
+ {
+ if (10000000 <= ++Wait_Counter)
+ {
+ GMAC_HW_DEBUG_E("Gmac_WritePHYRegister FST_ERROR_COUNT_MAX \r\n");
+ return FST_ERROR_COUNT_MAX;
+ }
+ }
+ return FST_SUCCESS;
+}
+
+s32 FGmac_ReadPHYRegister(FGmac_Config_t *Config, u16 PHYReg, u32 *RegValue)
+{
+ u32 TmpReg;
+ u32 Wait_Counter = 0;
+
+ TmpReg = 0;
+ TmpReg |= GMAC_MII_ADDR_CR(Config->clkMDC);
+ TmpReg |= GMAC_MII_ADDR_PA(Config->PhyAddr); /* Set the PHY device address */
+ TmpReg |= GMAC_MII_ADDR_GR(PHYReg); /* Set the PHY register address */
+ TmpReg &= ~GMAC_MII_ADDR_GW; /* Set the read mode */
+ TmpReg |= GMAC_MII_ADDR_GB; /* Set the MII Busy bit */
+
+ while ((Ft_in32(Config->BaseAddress + GMAC_MII_ADDR_OFFSET) & GMAC_MII_ADDR_GB) == GMAC_MII_ADDR_GB)
+ {
+ if (10000000 <= ++Wait_Counter)
+ {
+ GMAC_HW_DEBUG_E("wait GMAC_MII_ADDR_GB is error \r\n");
+ *RegValue = 0xffff;
+ return FST_ERROR_COUNT_MAX;
+ }
+ }
+
+ Ft_out32(Config->BaseAddress + GMAC_MII_ADDR_OFFSET, TmpReg);
+
+ while ((Ft_in32(Config->BaseAddress + GMAC_MII_ADDR_OFFSET) & GMAC_MII_ADDR_GB) == GMAC_MII_ADDR_GB)
+ {
+ if (10000000 <= ++Wait_Counter)
+ {
+ GMAC_HW_DEBUG_E("wait GMAC_MII_ADDR_GB 2 is error \r\n");
+ *RegValue = 0xffff;
+ return FST_ERROR_COUNT_MAX;
+ }
+ }
+ *RegValue = Ft_in32(Config->BaseAddress + GMAC_MII_DATA_OFFSET);
+ return FST_SUCCESS;
+}
+
+static s32 FGmac_PhyAddrGet(FGmac_Config_t *Config)
+{
+ u32 i = 0;
+ u32 phyId1;
+ u32 phyId2;
+ u8 flag = 0;
+
+ for (i = 0; i < 32; i++)
+ {
+ Config->PhyAddr = i;
+ FGmac_ReadPHYRegister(Config, PHY_ID1_REG_OFFSET, &phyId1);
+ FGmac_ReadPHYRegister(Config, PHY_ID2_REG_OFFSET, &phyId2);
+
+ if ((phyId2 & 0xffff) != 0xffff)
+ {
+ if ((0 == i) && (0x1c == phyId1) && ((phyId2 >> 10) == 0x32))
+ {
+ continue;
+ }
+ flag = 1;
+ break;
+ }
+ }
+ return (flag == 1) ? FST_SUCCESS : FST_FAILURE;
+}
+
+
+static void FGmac_MACAddressConfig(FGmac_Config_t *Config, u32 MacAddr, u8 *Addr)
+{
+ u32 tmpreg;
+ /* Calculate the selected MAC address high register */
+ tmpreg = ((u32)Addr[5] << 8) | (u32)Addr[4];
+ /* Load the selected MAC address high register */
+ Ft_out32(Config->BaseAddress + GMAC_MAC_ADDR0_UPPER16BIT_OFFSET + MacAddr, tmpreg);
+ /* Calculate the selected MAC address low register */
+ tmpreg = ((u32)Addr[3] << 24) | ((u32)Addr[2] << 16) | ((u32)Addr[1] << 8) | Addr[0];
+ /* Load the selected MAC address low register */
+ Ft_out32(Config->BaseAddress + GMAC_MAC_ADDR0_LOWER16BIT_OFFSET + MacAddr, tmpreg);
+}
+
+
+static void FGmac_MACDMAInit(FGmac_Config_t *Config)
+{
+ u32 RegValue = 0;
+ Ft_assertVoid(FGmac_PhyAddrGet(Config) == FST_SUCCESS);
+ RegValue = Ft_in32(Config->BaseAddress + GMAC_CONTROL_OFFSET);
+ /* MACCR Configuration **************************************/
+ /* Set the WD bit according to ETH Watchdog value */
+ /* Set the JD: bit according to ETH Jabber value */
+ /* Set the IFG bit according to ETH InterFrameGap value */
+ /* Set the DCRS bit according to ETH CarrierSense value */
+ /* Set the FES bit according to ETH Speed value */
+ /* Set the DO bit according to ETH ReceiveOwn value */
+ /* Set the LM bit according to ETH LoopbackMode value */
+ /* Set the DM bit according to ETH Mode value */
+ /* Set the IPCO bit according to ETH ChecksumOffload value */
+ /* Set the DR bit according to ETH RetryTransmission value */
+ /* Set the ACS bit according to ETH AutomaticPadCRCStrip value */
+ /* Set the BL bit according to ETH BackOffLimit value */
+ /* Set the DC bit according to ETH DeferralCheck value */
+ RegValue &= ~GMAC_CONTROL_WD;
+ RegValue &= ~GMAC_CONTROL_JD;
+ RegValue |= GMAC_CONTROL_IFG(0);
+ RegValue &= ~GMAC_CONTROL_DCRS;
+ RegValue &= ~GMAC_CONTROL_DO;
+ RegValue &= ~GMAC_CONTROL_LM;
+ if (Config->ChecksumMode)
+ {
+ RegValue |= GMAC_CONTROL_IPC;
+ }
+ else
+ {
+ RegValue &= ~GMAC_CONTROL_IPC;
+ }
+
+ RegValue |= GMAC_CONTROL_DR;
+ RegValue &= ~GMAC_CONTROL_ACS;
+ RegValue |= GMAC_CONTROL_BL(0);
+ RegValue &= ~GMAC_CONTROL_DC;
+ if (Config->DuplexMode == GMAC_MODE_FULLDUPLEX)
+ {
+ RegValue |= GMAC_CONTROL_DM;
+ }
+ else
+ {
+ RegValue &= ~GMAC_CONTROL_DM;
+ }
+
+ RegValue &= ~GMAC_CONTROL_FES;
+ Ft_out32(Config->BaseAddress + GMAC_CONTROL_OFFSET, RegValue);
+ Ft_GenericTimer_UsDelay(PHY_CONFIG_DELAY_US);
+
+ /*----------------------- GMAC MACFFR Configuration --------------------*/
+ /* Set the RA bit according to ETH ReceiveAll value */
+ /* Set the SAF and SAIF bits according to ETH SourceAddrFilter value */
+ /* Set the PCF bit according to ETH PassControlFrames value */
+ /* Set the DBF bit according to ETH BroadcastFramesReception value */
+ /* Set the DAIF bit according to ETH DestinationAddrFilter value */
+ /* Set the PR bit according to ETH PromiscuousMode value */
+ /* Set the PM, HMC and HPF bits according to ETH MulticastFramesFilter value */
+ /* Set the HUC and HPF bits according to ETH UnicastFramesFilter value */
+ /* Write to MACFFR */
+ RegValue = Ft_in32(Config->BaseAddress + GMAC_FRAME_FILTER_OFFSET);
+ RegValue |= GMAC_FRAME_FILTER_RA;
+ RegValue |= GMAC_FRAME_FILTER_PCF(2);
+ RegValue &= ~GMAC_FRAME_FILTER_PM;
+ RegValue &= ~GMAC_FRAME_FILTER_DBF;
+ RegValue &= ~GMAC_FRAME_FILTER_DAIF;
+ RegValue &= ~GMAC_FRAME_FILTER_PR;
+ Ft_out32(Config->BaseAddress + GMAC_FRAME_FILTER_OFFSET, RegValue);
+ Ft_GenericTimer_UsDelay(PHY_CONFIG_DELAY_US);
+
+ /*--------------- MACHTHR and MACHTLR Configuration --------------*/
+ Ft_out32(Config->BaseAddress + GMAC_HASH_HIGH_OFFSET, 0);
+ Ft_GenericTimer_UsDelay(PHY_CONFIG_DELAY_US);
+ Ft_out32(Config->BaseAddress + GMAC_HASH_LOW_OFFSET, 0);
+ Ft_GenericTimer_UsDelay(PHY_CONFIG_DELAY_US);
+
+ /*----------------------- MACFCR Configuration -------------------*/
+ /* Set the PT bit according to ETH PauseTime value */
+ /* Set the DZPQ bit according to ETH ZeroQuantaPause value */
+ /* Set the PLT bit according to ETH PauseLowThreshold value */
+ /* Set the UP bit according to ETH UnicastPauseFrameDetect value */
+ /* Set the RFE bit according to ETH ReceiveFlowControl value */
+ /* Set the TFE bit according to ETH TransmitFlowControl value */
+ RegValue = Ft_in32(Config->BaseAddress + GMAC_FLOW_CTRL_OFFSET);
+ RegValue |= GMAC_FLOW_DZPQ;
+ RegValue |= GMAC_FLOW_PLT(0);
+ RegValue &= ~GMAC_FLOW_RFE;
+ RegValue &= ~GMAC_FLOW_TFE;
+ Ft_out32(Config->BaseAddress + GMAC_FLOW_CTRL_OFFSET, RegValue);
+ Ft_GenericTimer_UsDelay(PHY_CONFIG_DELAY_US);
+
+ /*----------------------- MACVLANTR Configuration ----------------*/
+ /* Set the ETV bit according to ETH VLANTagComparison value */
+ /* Set the VL bit according to ETH VLANTagIdentifier value */
+ RegValue = GMAC_VLAN_TAG_VL(0);
+ RegValue &= ~GMAC_VLAN_TAG_ETV;
+ Ft_out32(Config->BaseAddress + GMAC_VLAN_TAG_OFFSET, RegValue);
+ Ft_GenericTimer_UsDelay(PHY_CONFIG_DELAY_US);
+
+ /* DMA default initialization ************************************/
+ /* Set the DT bit according to ETH DropTCPIPChecksumErrorFrame value */
+ /* Set the RSF bit according to ETH ReceiveStoreForward value */
+ /* Set the DFF bit according to ETH FlushReceivedFrame value */
+ /* Set the TSF bit according to ETH TransmitStoreForward value */
+ /* Set the TTC bit according to ETH TransmitThresholdControl value */
+ /* Set the FEF bit according to ETH ForwardErrorFrames value */
+ /* Set the FUF bit according to ETH ForwardUndersizedGoodFrames value */
+ /* Set the RTC bit according to ETH ReceiveThresholdControl value */
+ /* Set the OSF bit according to ETH SecondFrameOperate value */
+ RegValue = Ft_in32(Config->BaseAddress + DMA_OP_OFFSET);
+ RegValue &= DMA_OP_CLEAR_MASK;
+ RegValue &= ~DMA_OP_DT;
+ RegValue |= DMA_OP_RSF;
+ RegValue &= ~DMA_OP_DFF;
+ RegValue |= DMA_OP_TSF;
+ RegValue |= DMA_OP_TTC(7);
+ RegValue |= DMA_OP_OSF;
+ Ft_out32(Config->BaseAddress + DMA_OP_OFFSET, RegValue);
+ Ft_GenericTimer_UsDelay(PHY_CONFIG_DELAY_US);
+
+ /* DMABMR Configuration ------------------*/
+ /* Set the AAL bit according to ETH AddressAlignedBeats value */
+ /* Set the FB bit according to ETH FixedBurst value */
+ /* Set the RPBL and 4*PBL bits according to ETH RxDMABurstLength value */
+ /* Set the PBL and 4*PBL bits according to ETH TxDMABurstLength value */
+ /* Set the Enhanced DMA descriptors bit according to ETH EnhancedDescriptorFormat value*/
+ /* Set the DSL bit according to ETH DesciptorSkipLength value */
+ /* Set the PR and DA bits according to ETH DMAArbitration value */
+ RegValue = Ft_in32(Config->BaseAddress + DMA_BUS_MODE_OFFSET);
+ RegValue |= DMA_BUS_AAL;
+ RegValue |= DMA_BUS_FB;
+ RegValue |= DMA_BUS_RPBL(32);
+ RegValue |= DMA_BUS_PBL(32);
+ RegValue |= DMA_BUS_ATDS;
+ RegValue |= DMA_BUS_PR(0);
+ RegValue |= DMA_BUS_USP;
+ Ft_out32(Config->BaseAddress + DMA_BUS_MODE_OFFSET, RegValue);
+ Ft_GenericTimer_UsDelay(PHY_CONFIG_DELAY_US);
+ Ft_out32(Config->BaseAddress + DMA_AXI_BUS_MOD_OFFSET, 0x0000000e);
+ FGmac_MACAddressConfig(Config, 0, Config->MacAddr);
+}
+
+s32 FGmac_InitializeHw(FGmac_Config_t *Config)
+{
+ u32 Wait_Counter = 0;
+ u32 RegValue;
+ s32 ret = FST_SUCCESS;
+
+ /*Gmac Software reset */
+ Ft_out32(Config->BaseAddress + DMA_BUS_MODE_OFFSET, DMA_BUS_SWR);
+
+ while ((Ft_in32(Config->BaseAddress + DMA_BUS_MODE_OFFSET) & DMA_BUS_SWR) == DMA_BUS_SWR)
+ {
+ if (++Wait_Counter > 30)
+ {
+ GMAC_HW_DEBUG_E("DMA_BUS_MODE_OFFSET wait is too long ,Addr %x \r\n", Config->BaseAddress);
+ return FST_ERROR_COUNT_MAX;
+ }
+ Ft_GenericTimer_UsDelay(PHY_CONFIG_DELAY_US);
+ }
+ Wait_Counter = 0;
+ Ft_out32(Config->BaseAddress + DMA_BUS_MODE_OFFSET, DMA_BUS_INIT);
+
+ Ft_out32(Config->BaseAddress + DMA_OP_OFFSET, Ft_in32(Config->BaseAddress + DMA_OP_OFFSET) | DMA_OP_FTF);
+
+ while ((Ft_in32(Config->BaseAddress + DMA_OP_OFFSET) & DMA_OP_FTF) == DMA_OP_FTF)
+ {
+ if (++Wait_Counter > 30)
+ {
+ GMAC_HW_DEBUG_E("DMA_OP_OFFSET wait is too long \r\n");
+ return FST_ERROR_COUNT_MAX;
+ }
+ Ft_GenericTimer_UsDelay(PHY_CONFIG_DELAY_US);
+ }
+
+ Wait_Counter = 0;
+
+ /* GMAC Init */
+ Ft_out32(Config->BaseAddress + GMAC_CONTROL_OFFSET, GMAC_CONTROL_INIT);
+ /* disable flow control */
+ Ft_out32(Config->BaseAddress + GMAC_FLOW_CTRL_OFFSET, 0);
+
+ Ft_out32(Config->BaseAddress + DMA_STATUS_OFFSET, DMA_STATUS_INIT);
+
+ Ft_out32(Config->BaseAddress + DMA_INTR_ENA_OFFSET, 0);
+
+ /* get Phy addr */
+ Ft_assertNonvoid(FGmac_PhyAddrGet(Config) == FST_SUCCESS);
+
+ /*-------------------------------- MAC Initialization ----------------------*/
+ /*-------------------- PHY initialization and configuration ----------------*/
+ /* Put the PHY in reset mode */
+ if (Gmac_WritePHYRegister(Config, PHY_BCR_OFFSET, PHY_RESET) != FST_SUCCESS)
+ {
+ GMAC_HW_DEBUG_E("PHY_BCR_OFFSET is error \r\n");
+ return FST_FAILURE;
+ }
+
+ do
+ {
+ FGmac_ReadPHYRegister(Config, PHY_BCR_OFFSET, &RegValue);
+ Ft_GenericTimer_UsDelay(PHY_CONFIG_DELAY_US);
+
+ if (++Wait_Counter > 30)
+ {
+ GMAC_HW_DEBUG_E("PHY_BCR_OFFSET wait is too long \r\n");
+ ret = FST_ERROR_COUNT_MAX;
+ goto gmac_init;
+ }
+ } while ((RegValue & PHY_RESET) == PHY_RESET);
+
+ Wait_Counter = 0;
+ if (Config->AutoNegotiation == GMAC_AUTONEGOTIATION_ENABLE)
+ {
+ do
+ {
+ FGmac_ReadPHYRegister(Config, PHY_BSR_OFFSET, &RegValue);
+
+ if (++Wait_Counter > 30)
+ {
+ GMAC_HW_DEBUG_E("PHY_BSR_OFFSET 1 wait is too long \r\n");
+ ret = FST_ERROR_COUNT_MAX;
+ goto gmac_init;
+ }
+ Ft_GenericTimer_UsDelay(PHY_CONFIG_DELAY_US);
+
+ } while ((RegValue & PHY_LINKED_STATUS) != PHY_LINKED_STATUS);
+
+ Wait_Counter = 0;
+ if (Gmac_WritePHYRegister(Config, PHY_BCR_OFFSET, PHY_AUTONEGOTIATION | PHY_RESTART_AUTONEGOTIATION) != FST_SUCCESS)
+ {
+ GMAC_HW_DEBUG_E("PHY_BCR_OFFSET 2 is error \r\n");
+ ret = FST_FAILURE;
+ goto gmac_init;
+ }
+
+ do
+ {
+ FGmac_ReadPHYRegister(Config, PHY_BSR_OFFSET, &RegValue);
+ if (++Wait_Counter > 30)
+ {
+ GMAC_HW_DEBUG_E("PHY_BSR_OFFSET 2 wait is too long \r\n");
+ ret = FST_ERROR_COUNT_MAX;
+ goto gmac_init;
+ }
+ } while ((RegValue & PHY_AUTONEGO_COMPLETE) != PHY_AUTONEGO_COMPLETE);
+
+ if (FGmac_ReadPHYRegister(Config, PHY_SPECIFIC_STATUS_OFFSET, &RegValue) != FST_SUCCESS)
+ {
+ GMAC_HW_DEBUG_E("PHY_SPECIFIC_STATUS_OFFSET is error \r\n");
+ ret = FST_FAILURE;
+ goto gmac_init;
+ }
+ /* Configure the MAC with the Duplex Mode fixed by the auto-negotiation process */
+ if ((RegValue & PHY_SPECIFIC_STATUS_DUPLEX) != PHY_SPECIFIC_STATUS_DUPLEX)
+ {
+ /* Set Ethernet duplex mode to Full-duplex following the auto-negotiation */
+ Config->DuplexMode = GMAC_MODE_HALFDUPLEX;
+ }
+ else
+ {
+ /* Set Ethernet duplex mode to Half-duplex following the auto-negotiation */
+ Config->DuplexMode = GMAC_MODE_FULLDUPLEX;
+ }
+ }
+ else
+ {
+ RegValue = 0;
+ if (Config->DuplexMode == GMAC_MODE_FULLDUPLEX)
+ {
+ if (Config->Speed == GMAC_SPEED_1000M)
+ {
+ RegValue = PHY_FULLDUPLEX_1000M;
+ }
+ else if (Config->Speed == GMAC_SPEED_100M)
+ {
+ RegValue = PHY_FULLDUPLEX_100M;
+ }
+ else if (Config->Speed == GMAC_SPEED_10M)
+ {
+ RegValue = PHY_FULLDUPLEX_10M;
+ }
+ }
+ else
+ {
+ if (Config->Speed == GMAC_SPEED_1000M)
+ {
+ RegValue = PHY_HALFDUPLEX_1000M;
+ }
+ else if (Config->Speed == GMAC_SPEED_100M)
+ {
+ RegValue = PHY_HALFDUPLEX_100M;
+ }
+ else if (Config->Speed == GMAC_SPEED_10M)
+ {
+ RegValue = PHY_HALFDUPLEX_10M;
+ }
+ }
+
+ /* AutoNegotiation Disable */
+ if (Gmac_WritePHYRegister(Config, PHY_BCR_OFFSET, RegValue) != FST_SUCCESS)
+ {
+ GMAC_HW_DEBUG_E("PHY_BCR_OFFSET 3 is error \r\n");
+ ret = FST_FAILURE;
+ goto gmac_init;
+ }
+ }
+ Ft_GenericTimer_UsDelay(PHY_CONFIG_DELAY_US);
+
+gmac_init:
+
+ FGmac_MACDMAInit(Config);
+ return ret;
+}
+
+void FGmac_TransmissionEnable(FGmac_Config_t *Config)
+{
+ u32 RegValue;
+ RegValue = Ft_in32(Config->BaseAddress + GMAC_CONTROL_OFFSET);
+ RegValue |= GMAC_CONTROL_TE;
+ Ft_out32(Config->BaseAddress + GMAC_CONTROL_OFFSET, RegValue);
+}
+
+void FGmac_TransmissionDisable(FGmac_Config_t *Config)
+{
+ u32 RegValue;
+ RegValue = Ft_in32(Config->BaseAddress + GMAC_CONTROL_OFFSET);
+ RegValue &= ~GMAC_CONTROL_TE;
+ Ft_out32(Config->BaseAddress + GMAC_CONTROL_OFFSET, RegValue);
+}
+
+void FGmac_ReceptionEnable(FGmac_Config_t *Config)
+{
+ u32 RegValue;
+ RegValue = Ft_in32(Config->BaseAddress + GMAC_CONTROL_OFFSET);
+ RegValue |= GMAC_CONTROL_RE;
+ Ft_out32(Config->BaseAddress + GMAC_CONTROL_OFFSET, RegValue);
+}
+
+void FGmac_ReceptionDisable(FGmac_Config_t *Config)
+{
+ u32 RegValue;
+ RegValue = Ft_in32(Config->BaseAddress + GMAC_CONTROL_OFFSET);
+ RegValue &= ~GMAC_CONTROL_RE;
+ Ft_out32(Config->BaseAddress + GMAC_CONTROL_OFFSET, RegValue);
+}
+
+void FGmac_FlushTransmitFIFO(FGmac_Config_t *Config)
+{
+ u32 RegValue;
+ RegValue = Ft_in32(Config->BaseAddress + DMA_OP_OFFSET);
+ RegValue |= DMA_OP_FTF;
+ Ft_out32(Config->BaseAddress + DMA_OP_OFFSET, RegValue);
+}
+
+void FGmac_DMATransmissionEnable(FGmac_Config_t *Config)
+{
+ u32 RegValue;
+ RegValue = Ft_in32(Config->BaseAddress + DMA_OP_OFFSET);
+ RegValue |= DMA_OP_ST;
+ Ft_out32(Config->BaseAddress + DMA_OP_OFFSET, RegValue);
+}
+
+/**
+ * @name: FGmac_DMATransmissionDisable
+ * @msg: Disable the DMA transmission
+ * @param {FGmac_Config_t} *Config
+ * @return {*}
+ */
+void FGmac_DMATransmissionDisable(FGmac_Config_t *Config)
+{
+ u32 RegValue;
+ RegValue = Ft_in32(Config->BaseAddress + DMA_OP_OFFSET);
+ RegValue &= ~DMA_OP_ST;
+ Ft_out32(Config->BaseAddress + DMA_OP_OFFSET, RegValue);
+}
+
+/**
+ * @name: FGmac_DMAReceptionEnable
+ * @msg: Enable the DMA reception
+ * @param {FGmac_Config_t} *Config
+ * @return {*}
+ */
+void FGmac_DMAReceptionEnable(FGmac_Config_t *Config)
+{
+ u32 RegValue;
+ RegValue = Ft_in32(Config->BaseAddress + DMA_OP_OFFSET);
+ RegValue |= DMA_OP_SR;
+ Ft_out32(Config->BaseAddress + DMA_OP_OFFSET, RegValue);
+}
+
+void FGmac_DMAReceptionDisable(FGmac_Config_t *Config)
+{
+ u32 RegValue;
+ RegValue = Ft_in32(Config->BaseAddress + DMA_OP_OFFSET);
+ RegValue &= ~DMA_OP_SR;
+ Ft_out32(Config->BaseAddress + DMA_OP_OFFSET, RegValue);
+}
+
+void FGmac_DMAReceptionTransmissionEnable(FGmac_Config_t *Config)
+{
+ u32 RegValue;
+ RegValue = Ft_in32(Config->BaseAddress + DMA_OP_OFFSET);
+ RegValue |= (DMA_OP_SR | DMA_OP_ST);
+ Ft_out32(Config->BaseAddress + DMA_OP_OFFSET, RegValue);
+}
+
+void FGmac_DMAReceptionTransmissionDisable(FGmac_Config_t *Config)
+{
+ u32 RegValue;
+ RegValue = Ft_in32(Config->BaseAddress + DMA_OP_OFFSET);
+ RegValue &= ~(DMA_OP_SR | DMA_OP_ST);
+ Ft_out32(Config->BaseAddress + DMA_OP_OFFSET, RegValue);
+}
+
+void FGmac_ReceptionTransmissionEnable(FGmac_Config_t *Config)
+{
+ u32 RegValue;
+ RegValue = Ft_in32(Config->BaseAddress + GMAC_CONTROL_OFFSET);
+ RegValue |= (GMAC_CONTROL_RE | GMAC_CONTROL_TE);
+ Ft_out32(Config->BaseAddress + GMAC_CONTROL_OFFSET, RegValue);
+}
+
+void FGmac_ReceptionTransmissionDisable(FGmac_Config_t *Config)
+{
+ u32 RegValue;
+ RegValue = Ft_in32(Config->BaseAddress + GMAC_CONTROL_OFFSET);
+ RegValue &= ~(GMAC_CONTROL_RE | GMAC_CONTROL_TE);
+ Ft_out32(Config->BaseAddress + GMAC_CONTROL_OFFSET, RegValue);
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_hw.h b/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_hw.h
new file mode 100644
index 0000000000..6556880863
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_hw.h
@@ -0,0 +1,577 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-04-07 13:25:10
+ * @Description:  This files is for gmac register
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef GMAC_HW_H
+#define GMAC_HW_H
+#include "ft_types.h"
+#include "ft_gmac.h"
+/* Register Offset */
+
+#define GMAC_CONTROL_OFFSET 0x00000000U /* Configuration */
+#define GMAC_FRAME_FILTER_OFFSET 0x00000004U /* Frame Filter */
+#define GMAC_HASH_HIGH_OFFSET 0x00000008U /* Multicast Hash Table High */
+#define GMAC_HASH_LOW_OFFSET 0x0000000cU /* Multicast Hash Table Low */
+#define GMAC_MII_ADDR_OFFSET 0x00000010U /* MII Address */
+#define GMAC_MII_DATA_OFFSET 0x00000014U /* MII Data */
+#define GMAC_FLOW_CTRL_OFFSET 0x00000018U /* Flow Control */
+#define GMAC_VLAN_TAG_OFFSET 0x0000001cU /* VLAN Tag */
+#define GMAC_VERSION_OFFSET 0x00000020U /* GMAC CORE Version */
+#define GMAC_INTERNAL_MODULE_STATUS_OFFSET 0x00000024U /* 给出各种内部块的状态以进行调试。 */
+#define GMAC_LPI_CONTROL_STATUS_OFFSET 0x00000030U /* 控制低功耗空闲(LPI)操作并提供内核的 LPI 状态。 */
+#define GMAC_LPI_TIMER_CONTROL_OFFSET 0x00000034U /* 控制 LPI 状态中的超时值。 */
+#define GMAC_ISR_STATUS_OFFSET 0x00000038U /* 中断状态。 */
+#define GMAC_ISR_MASK_OFFSET 0x0000003CU /* 生成中断的掩码 */
+#define GMAC_MAC_ADDR0_UPPER16BIT_OFFSET 0x00000040U /* 第一个 MAC 地址的高 16 位。 */
+#define GMAC_MAC_ADDR0_LOWER16BIT_OFFSET 0x00000044U /* 第一个 MAC 地址的低 32 位。。 */
+#define GMAC_MAC_ADDR1_UPPER16BIT_OFFSET 0x00000048U /* 第二个 MAC 地址的高 16 位。 */
+#define GMAC_MAC_ADDR1_LOWER16BIT_OFFSET 0x0000004CU /* 第二个 MAC 地址的低 32 位。。 */
+#define GMAC_MAC_MAC_PHY_STATUS 0x000000D8U /* MAC PHY 状态 */
+
+#define DMA_BUS_MODE_OFFSET 0x00001000U /* Bus Mode */
+#define DMA_XMT_POLL_DEMAND_OFFSET 0x00001004U /* Transmit Poll Demand */
+#define DMA_RCV_POLL_DEMAND_OFFSET 0x00001008U /* Received Poll Demand */
+#define DMA_RCV_BASE_ADDR_OFFSET 0x0000100cU /* Receive List Base */
+#define DMA_TX_BASE_ADDR_OFFSET 0x00001010U /* Transmit List Base */
+#define DMA_STATUS_OFFSET 0x00001014U /* Status Register */
+#define DMA_OP_OFFSET 0x00001018U /* Ctrl (Operational Mode) */
+#define DMA_INTR_ENA_OFFSET 0x0000101cU /* Interrupt Enable */
+#define DMA_MISSED_FRAME_CTR_OFFSET 0x00001020U /* Missed Frame Counter */
+#define DMA_RX_WATCHDOG_OFFSET 0x1024U /* Receive Interrupt Watchdog */
+#define DMA_AXI_BUS_MOD_OFFSET 0x1028U /* 控制 AXI 主行为 */
+#define DMA_AXI_BUS_STATUS_OFFSET 0x102CU /* 控制 AXI 状态 */
+
+/* MMC control */
+#define MMC_CNTRL 0x0100U /* MMC Control */
+#define MMC_RX_INTR 0x0104U /* MMC RX Interrupt */
+#define MMC_TX_INTR 0x0108U /* MMC TX Interrupt */
+#define MMC_RX_INTR_MASK 0x010cU /* MMC Interrupt Mask */
+#define MMC_TX_INTR_MASK 0x0110U /* MMC Interrupt Mask */
+#define MMC_RX_IPC_INTR_MASK 0x0200U
+#define MMC_RX_IPC_INTR 0x0208U
+
+/** MAC 配置寄存器 **/
+#define GMAC_CONTROL_2K 0x08000000U /* IEEE 802.3as 2K packets */
+#define GMAC_CONTROL_CST 0x2000000U
+#define GMAC_CONTROL_TC 0x01000000U /* Transmit Conf. in RGMII/SGMII */
+#define GMAC_CONTROL_WD 0x00800000U /* Disable Watchdog on receive */
+#define GMAC_CONTROL_JD 0x00400000U /* Jabber disable */
+#define GMAC_CONTROL_BE 0x00200000U /* Frame Burst Enable */
+#define GMAC_CONTROL_JE 0x00100000U /* Jumbo frame */
+#define GMAC_CONTROL_IFG(x) ((x & 7) << 17) /* 帧内间隔 ,000 96bit times 001 88bit times 010 80bit times … 111 40bit times*/
+#define GMAC_CONTROL_DCRS 0x00010000U /* Disable carrier sense */
+#define GMAC_CONTROL_PS 0x00008000U /* Port Select 0:GMII 1:MII */
+#define GMAC_CONTROL_FES 0x00004000U /* Speed 0:10 1:100 */
+#define GMAC_CONTROL_DO 0x00002000U /* Disable Rx Own */
+#define GMAC_CONTROL_LM 0x00001000U /* Loop-back mode */
+#define GMAC_CONTROL_DM 0x00000800U /* Duplex Mode . 1 is Duplex */
+#define GMAC_CONTROL_IPC 0x00000400U /* Checksum Offload */
+#define GMAC_CONTROL_DR 0x00000200U /* Disable Retry */
+#define GMAC_CONTROL_LUD 0x00000100U /* Link up/down */
+#define GMAC_CONTROL_ACS 0x00000080U /* Auto Pad/FCS Stripping */
+#define GMAC_CONTROL_BL(x) ((x & 3) << 5)
+#define GMAC_CONTROL_DC 0x00000010U /* Deferral Check */
+#define GMAC_CONTROL_TE 0x00000008U /* Transmitter Enable */
+#define GMAC_CONTROL_RE 0x00000004U /* Receiver Enable */
+#define GMAC_CONTROL_INIT (GMAC_CONTROL_DO | GMAC_CONTROL_JD | GMAC_CONTROL_ACS | GMAC_CONTROL_IPC | GMAC_CONTROL_BE | GMAC_CONTROL_DM | GMAC_CONTROL_WD | GMAC_CONTROL_CST)
+
+/** Frame Filter **/
+#define GMAC_FRAME_FILTER_PR 0x00000001U
+#define GMAC_FRAME_FILTER_HUC 0x00000002U
+#define GMAC_FRAME_FILTER_HMC 0x00000004U
+#define GMAC_FRAME_FILTER_DAIF 0x00000008U
+#define GMAC_FRAME_FILTER_PM 0x00000010U
+#define GMAC_FRAME_FILTER_DBF 0x00000020U
+#define GMAC_FRAME_FILTER_PCF(x) ((x & 3) << 6)
+#define GMAC_FRAME_FILTER_SAIF 0x00000100U
+#define GMAC_FRAME_FILTER_SAF 0x00000200U
+#define GMAC_FRAME_FILTER_HPF 0x00000400U
+#define GMAC_FRAME_FILTER_RA 0x80000000U
+
+/** 哈希表高位寄存器 **/
+#define GMAC_HASH_HIGH_HTH 0xffffffffUL /* 该字段包含 Hash 表的高 32 位。 */
+
+/** 哈希表低位寄存器 **/
+#define GMAC_HASH_LOW_HTH 0xffffffffUL /* 该字段包含 Hash 表的低 32 位。 */
+
+/** GMII 地址寄存器 **/
+#define GMAC_MII_ADDR_GB 0x00000001
+#define GMAC_MII_ADDR_GW 0x00000002
+#define GMAC_MII_ADDR_CR(x) ((x & 0xf) << 2)
+#define GMAC_MII_ADDR_GR(x) ((x & 0x1f) << 6)
+#define GMAC_MII_ADDR_PA(x) ((x & 0x1f) << 11)
+
+/** GMII 数据寄存器 **/
+#define GMAC_MII_DATA_GD 0x0000ffffU
+
+/** 流控寄存器 **/
+#define GMAC_FLOW_FCB 0x00000001U
+#define GMAC_FLOW_BPA GMAC_FLOW_FCB
+#define GMAC_FLOW_TFE 0x00000002U
+#define GMAC_FLOW_RFE 0x00000004U
+#define GMAC_FLOW_UP 0x00000008U
+#define GMAC_FLOW_PLT(x) ((x & 3) << 3)
+#define GMAC_FLOW_DZPQ 0x00000080U
+#define GMAC_FLOW_PT 0xffff0000U
+
+/** VLAN 标记寄存器 **/
+// #define GMAC_VLAN_TAG_VL 0x0000ffffU
+#define GMAC_VLAN_TAG_VL(x) (x & 0xffffU)
+#define GMAC_VLAN_TAG_ETV 0x00010000U
+
+/** 版本寄存器 **/
+#define GMAC_VERSION_UDV 0x00FF0000U /* 用户定义版本号 */
+#define GMAC_VERSION_SDV 0x000000ffU /* 硬件定议版本号 */
+
+/** LPI 控制和状态寄存器 **/
+#define GMAC_LPI_CONTROL_STATUS_TLPIEN 0x00000001U
+#define GMAC_LPI_CONTROL_STATUS_TLPIEX 0x00000002U
+#define GMAC_LPI_CONTROL_STATUS_RLPIEN 0x00000004U
+#define GMAC_LPI_CONTROL_STATUS_RLPIEX 0x00000008U
+#define GMAC_LPI_CONTROL_STATUS_TLPIST 0x00000100U
+#define GMAC_LPI_CONTROL_STATUS_RLPIST 0x00000200U
+#define GMAC_LPI_CONTROL_STATUS_LPIEN 0x00010000U
+#define GMAC_LPI_CONTROL_STATUS_PLS 0x00020000U
+#define GMAC_LPI_CONTROL_STATUS_PLSEN 0x00040000U
+#define GMAC_LPI_CONTROL_STATUS_LPITXA 0x00080000U
+
+/** LPI 定时器控制寄存器 **/
+#define GMAC_LPI_TIMER_TWT 0x0000ffffU
+#define GMAC_LPI_TIMER_LIT 0x3FF0000U
+
+/** 中断状态寄存器 **/
+#define GMAC_ISR_STATUS_RSIS 0x00000001U
+#define GMAC_ISR_STATUS_PCSLSC 0x00000002U
+#define GMAC_ISR_STATUS_PCSANC 0x00000004U
+#define GMAC_ISR_STATUS_PMTIS 0x00000008U
+#define GMAC_ISR_STATUS_MMCIS 0x00000010U
+#define GMAC_ISR_STATUS_MMCRIS 0x00000020U
+#define GMAC_ISR_STATUS_MMCTIS 0x00000040U
+#define GMAC_ISR_STATUS_MMCRCOIS 0x00000080U
+#define GMAC_ISR_STATUS_TIS 0x00000200U
+#define GMAC_ISR_STATUS_LPIIS 0x00000400U
+
+/** 中断屏蔽寄存器 **/
+#define GMAC_ISR_MASK_RSIM 0x00000001U /* RGMII/SMII 中断屏蔽 */
+#define GMAC_ISR_MASK_PCSLSIM 0x00000002U
+#define GMAC_ISR_MASK_PCSANCIM 0x00000004U
+#define GMAC_ISR_MASK_PMTIM 0x00000008U
+#define GMAC_ISR_MASK_TIM 0x00000020U
+#define GMAC_ISR_MASK_LPIIM 0x00000040U
+
+/** MAC 地址 0 高寄存器 **/
+#define GMAC_MAC_ADDR0_UPPER16BIT_A 0x0000ffffU
+
+/** MAC 地址 0 低寄存器 **/
+#define GMAC_MAC_ADDR0_LOWERER16BIT_A 0xffffffffU
+
+/** MAC 地址 1 高寄存器 **/
+#define GMAC_MAC_ADDR1_UPPER16BIT_A 0x0000ffffU
+#define GMAC_MAC_ADDR1_UPPER16BIT_MBC 0x3f000000U
+#define GMAC_MAC_ADDR1_UPPER16BIT_SA 0x40000000U
+#define GMAC_MAC_ADDR1_UPPER16BIT_AE 0x80000000U
+
+/** MAC 地址 1 低寄存器 **/
+#define GMAC_MAC_ADDR1_LOWER16BIT_A 0xffffffffU
+
+/* GMAC DMA 寄存器 */
+/** 总线模式寄存器 **/
+#define DMA_BUS_PRWG 0x030000000U
+#define DMA_BUS_TXPR 0x08000000U
+#define DMA_BUS_MB 0x04000000U
+#define DMA_BUS_AAL 0x02000000U
+#define DMA_BUS_8xPBL 0x01000000U
+#define DMA_BUS_USP 0x00800000U
+#define DMA_BUS_RPBL(x) ((x & 0x3f) << 17)
+#define DMA_BUS_FB 0x00010000U /* Fixed Burst */
+#define DMA_BUS_PR(x) ((x & 0x3) << 14) /* 00: 1:1 ,01: 2:1 ,10: 3:1 ,11: 4:1 */
+#define DMA_BUS_PBL(x) ((x & 0x3f) << 8)
+#define DMA_BUS_ATDS 0x00000080U
+#define DMA_BUS_DSL 0x0000007CU /* Descriptor Skip Length */
+#define DMA_BUS_DA 0x00000002U /* DMA Arbitration Scheme,Rx High Pro */
+#define DMA_BUS_SWR 0x00000001U /* Software Reset */
+
+#define DMA_BUS_INIT (DMA_BUS_FB | DMA_BUS_PBL(16) | DMA_BUS_RPBL(16))
+
+/** 发送轮询请求寄存器 **/
+#define DMA_XMT_POLL_DEMAND_TPD 0xffffffffU
+
+/** 发送轮询请求寄存器 **/
+#define DMA_RCV_POLL_DEMAND_RPD 0xffffffffU
+
+/** 接收描述符列表地址寄存器 **/
+#define DMA_RCV_BASE_ADDR_START_REC_LIST 0xfffffff0U
+
+/** 发送描述符列表地址寄存器 **/
+#define DMA_TX_BASE_ADDR_START_TRA_LIST 0xfffffff0U
+
+/**
+ * @brief Bit definition of TDES0 register: DMA Tx descriptor status register
+ */
+#define BIT(bitnum) (1 << (bitnum % 32))
+#define GENMASK(h, l) \
+ (((~0UL) - (1UL << (l)) + 1) & (~0UL >> (32 - 1 - (h))))
+
+#define DMA_TDES0_DEFERRED BIT(0)
+#define DMA_TDES0_UNDERFLOW_ERROR BIT(1)
+#define DMA_TDES0_EXCESSIVE_DEFERRAL BIT(2)
+#define DMA_TDES0_COLLISION_COUNT_MASK GENMASK(6, 3)
+#define DMA_TDES0_VLAN_FRAME BIT(7)
+#define DMA_TDES0_EXCESSIVE_COLLISIONS BIT(8)
+#define DMA_TDES0_LATE_COLLISION BIT(9)
+#define DMA_TDES0_NO_CARRIER BIT(10)
+#define DMA_TDES0_LOSS_CARRIER BIT(11)
+#define DMA_TDES0_PAYLOAD_ERROR BIT(12)
+#define DMA_TDES0_FRAME_FLUSHED BIT(13)
+#define DMA_TDES0_JABBER_TIMEOUT BIT(14)
+#define DMA_TDES0_ERROR_SUMMARY BIT(15)
+#define DMA_TDES0_IP_HEADER_ERROR BIT(16)
+#define DMA_TDES0_TIME_STAMP_STATUS BIT(17)
+#define DMA_TDES0_OWN ((u32)BIT(31)) /* silence sparse */
+/* TDES1 */
+#define DMA_TDES1_BUFFER1_SIZE_MASK GENMASK(10, 0)
+#define DMA_TDES1_BUFFER2_SIZE_MASK GENMASK(21, 11)
+#define DMA_TDES1_BUFFER2_SIZE_SHIFT 11
+#define DMA_TDES1_TIME_STAMP_ENABLE BIT(22)
+#define DMA_TDES1_DISABLE_PADDING BIT(23)
+#define DMA_TDES1_SECOND_ADDRESS_CHAINED BIT(24)
+#define DMA_TDES1_END_RING BIT(25)
+#define DMA_TDES1_CRC_DISABLE BIT(26)
+#define DMA_TDES1_CHECKSUM_INSERTION_MASK GENMASK(28, 27)
+#define DMA_TDES1_CHECKSUM_INSERTION_SHIFT 27
+#define DMA_TDES1_FIRST_SEGMENT BIT(29)
+#define DMA_TDES1_LAST_SEGMENT BIT(30)
+#define DMA_TDES1_INTERRUPT BIT(31)
+
+/* Bit definition of RDES0 register: DMA Rx descriptor status register */
+/* RDES0 */
+#define DMA_RDES0_PAYLOAD_CSUM_ERR BIT(0)
+#define DMA_RDES0_CRC_ERROR BIT(1)
+#define DMA_RDES0_DRIBBLING BIT(2)
+#define DMA_RDES0_MII_ERROR BIT(3)
+#define DMA_RDES0_RECEIVE_WATCHDOG BIT(4)
+#define DMA_RDES0_FRAME_TYPE BIT(5)
+#define DMA_RDES0_COLLISION BIT(6)
+#define DMA_RDES0_IPC_CSUM_ERROR BIT(7)
+#define DMA_RDES0_LAST_DESCRIPTOR BIT(8)
+#define DMA_RDES0_FIRST_DESCRIPTOR BIT(9)
+#define DMA_RDES0_VLAN_TAG BIT(10)
+#define DMA_RDES0_OVERFLOW_ERROR BIT(11)
+#define DMA_RDES0_LENGTH_ERROR BIT(12)
+#define DMA_RDES0_SA_FILTER_FAIL BIT(13)
+#define DMA_RDES0_DESCRIPTOR_ERROR BIT(14)
+#define DMA_RDES0_ERROR_SUMMARY BIT(15)
+#define DMA_RDES0_FRAME_LEN_MASK (0x3FFF << 16) /*GENMASK(29, 16)*/
+#define DMA_RDES0_FRAME_LEN_SHIFT 16
+#define DMA_RDES0_DA_FILTER_FAIL BIT(30)
+#define DMA_RDES0_OWN BIT(31)
+/* RDES1 */
+#define DMA_RDES1_BUFFER1_SIZE_MASK GENMASK(10, 0)
+#define DMA_RDES1_BUFFER2_SIZE_MASK GENMASK(21, 11)
+#define DMA_RDES1_BUFFER2_SIZE_SHIFT 11
+#define DMA_RDES1_SECOND_ADDRESS_CHAINED BIT(24)
+#define DMA_RDES1_END_RING BIT(25)
+#define DMA_RDES1_DISABLE_IC BIT(31)
+
+/** DMA Status register defines **/
+#define DMA_STATUS_GLPII 0x40000000 /* GMAC LPI interrupt */
+#define DMA_STATUS_GPI 0x10000000 /* PMT interrupt */
+#define DMA_STATUS_GMI 0x08000000 /* MMC interrupt */
+#define DMA_STATUS_GLI 0x04000000 /* GMAC Line interface int */
+#define DMA_STATUS_EB_MASK 0x00380000 /* Error Bits Mask */
+#define DMA_STATUS_EB_TX_ABORT 0x00080000 /* Error Bits - TX Abort */
+#define DMA_STATUS_EB_RX_ABORT 0x00100000 /* Error Bits - RX Abort */
+#define DMA_STATUS_TS_MASK 0x00700000 /* Transmit Process State */
+#define DMA_STATUS_RS_MASK 0x000e0000 /* Receive Process State */
+#define DMA_STATUS_NIS 0x00010000 /* Normal Interrupt Summary */
+#define DMA_STATUS_AIS 0x00008000 /* Abnormal Interrupt Summary */
+#define DMA_STATUS_ERI 0x00004000 /* Early Receive Interrupt */
+#define DMA_STATUS_FBI 0x00002000 /* Fatal Bus Error Interrupt */
+#define DMA_STATUS_ETI 0x00000400 /* Early Transmit Interrupt */
+#define DMA_STATUS_RWT 0x00000200 /* Receive Watchdog Timeout */
+#define DMA_STATUS_RPS 0x00000100 /* Receive Process Stopped */
+#define DMA_STATUS_RU 0x00000080 /* Receive Buffer Unavailable */
+#define DMA_STATUS_RI 0x00000040 /* Receive Interrupt */
+#define DMA_STATUS_UNF 0x00000020 /* Transmit Underflow */
+#define DMA_STATUS_OVF 0x00000010 /* Receive Overflow */
+#define DMA_STATUS_TJT 0x00000008 /* Transmit Jabber Timeout */
+#define DMA_STATUS_TU 0x00000004 /* Transmit Buffer Unavailable */
+#define DMA_STATUS_TPS 0x00000002 /* Transmit Process Stopped */
+#define DMA_STATUS_TI 0x00000001 /* Transmit Interrupt */
+#define DMA_STATUS_INIT 0xFFFFFFFF
+
+/** DMA 操作模式寄存器 **/
+#define DMA_OP_DT 0x04000000U /* No Dropping of TCP/IP csum Err Frame */
+#define DMA_OP_RSF 0x02000000U /* Rx Store and Forward */
+#define DMA_OP_DFF 0x01000000U /* */
+#define DMA_OP_TSF 0x000200000U /* Tx Store and Forward */
+#define DMA_OP_FTF 0x000100000U /* Flush Tx FIFO */
+#define DMA_OP_TTC(x) ((x & 7) << 14) /* Tx Threshold Control ,• 000 64 , 001 128 , 010 192 ,011 256 ,100 40 , 101 32 , 110 24 , 111 16*/
+#define DMA_OP_ST 0x000002000U /* Start/Stop Tx */
+#define DMA_OP_RFD(x) ((x & 0x3) << 11) /* Threshold for DeActive Flow Control */
+#define DMA_OP_RFA 0x000000600U /* Threshold for Active Flow Control */
+#define DMA_OP_EFC 0x000000100U /* Enable HW Flow control */
+#define DMA_OP_FEF 0x000000080U /* Forward Error Frame */
+#define DMA_OP_FUF 0x000000040U /* Forward Undersize Good Frame */
+#define DMA_OP_RTC 0x000000018U /* Rx Threshold Control */
+#define DMA_OP_OSF 0x000000004U /* Operate On Second Mode */
+#define DMA_OP_SR 0x00000002U /* Start/Stop Rx */
+#define DMA_OP_CLEAR_MASK ((u32)0xF8DE3F23U)
+#define DMA_OP_INIT (DMA_OP_SR | DMA_OP_RSF)
+
+/** 中断使能寄存器 **/
+#define DMA_INTR_ENA_TIE 0x00000001U /* Transmit Interrupt */
+#define DMA_INTR_ENA_TSE 0x00000002U /* 传输停止启用 */
+#define DMA_INTR_ENA_TUE 0x00000004U /* Transmit Buffer Unavailable */
+#define DMA_INTR_ENA_THE 0x00000008U /* 发送 Jabber 超时启用 */
+#define DMA_INTR_ENA_OVE 0x00000010U /* 溢出中断使能 */
+#define DMA_INTR_ENA_UNE 0x00000020U /* 下溢中断使能 */
+#define DMA_INTR_ENA_RIE 0x00000040U /* Receive Interrupt */
+#define DMA_INTR_ENA_RUE 0x00000080U /* 接收缓冲区不可用启用 */
+#define DMA_INTR_ENA_RSE 0x00000100U /* 接收已停止启用 */
+#define DMA_INTR_ENA_RWE 0x00000200U /* 接收看门狗超时使能 */
+#define DMA_INTR_ENA_ETE 0x00000400U /* 早期发送中断使能 */
+#define DMA_INTR_ENA_FBE 0x00002000U /* Fatal Bus Error */
+#define DMA_INTR_ENA_ERE 0x00004000U /* Early Receive */
+#define DMA_INTR_ENA_AIE 0x00008000 /* Abnormal Summary */
+#define DMA_INTR_ENA_NIE 0x00010000 /* Normal Summary */
+
+#define DMA_INTR_DEFAULT (DMA_INTR_ENA_TIE | DMA_INTR_ENA_TSE | DMA_INTR_ENA_TUE | DMA_INTR_ENA_THE | DMA_INTR_ENA_OVE | DMA_INTR_ENA_UNE | DMA_INTR_ENA_RIE | DMA_INTR_ENA_RUE | DMA_INTR_ENA_RSE | DMA_INTR_ENA_RWE | DMA_INTR_ENA_ETE | DMA_INTR_ENA_FBE | DMA_INTR_ENA_ERE | DMA_INTR_ENA_AIE | DMA_INTR_ENA_NIE)
+
+/** 丢帧和缓冲区溢出计数器寄存器 **/
+#define DMA_MISSED_FRAME_CTR_CMIS 0x0000FFFFUDMA_MISSED_FRAME
+#define DMA_MISSED_FRAME_CTR_OVMIS 0x00010000U
+#define DMA_MISSED_FRAME_CTR_CFIFO 0x0ffe0000U
+#define DMA_MISSED_FRAME_CTR_OVFIFO 0x10000000U
+
+/** 接收中断看门狗定时器寄存器 **/
+#define DMA_RX_WATCHDOG_RIWT 0x0000000fU
+
+/** AXI_BUS_MOD **/
+#define DMA_AXI_BUS_MOD_UNDEF 0x00000001U /* AXI 未定义的突发长度 */
+#define DMA_AXI_BUS_MOD_BLEN4 0x00000002U /* AXI 突发长度 4 */
+#define DMA_AXI_BUS_MOD_BLEN8 0x00000004U /* AXI 突发长度 8 */
+#define DMA_AXI_BUS_MOD_BLEN16 0x00000008U /* AXI 突发长度 16 */
+#define DMA_AXI_BUS_MOD_BLEN32 0x00000010U /* AXI 突发长度 32 */
+#define DMA_AXI_BUS_MOD_BLEN64 0x00000020U /* AXI 突发长度 64 */
+#define DMA_AXI_BUS_MOD_BLEN128 0x00000040U /* AXI 突发长度 128 */
+#define DMA_AXI_BUS_MOD_BLEN256 0x00000080U /* AXI 突发长度 256 */
+#define DMA_AXI_BUS_MOD_AXI_AAL 0x00001000U /* 地址对齐的节拍 */
+#define DMA_AXI_BUS_MOD_RD_OSR_LMT(x) ((x & 0xf) << 16) /* XI 最大读取未决请求限制此值限 制 AXI 读取接口上的最大未完成请求。 */
+#define DMA_AXI_BUS_MOD_WR_OSR_LMT(x) ((x & 0xf) << 20) /* AXI 最大写入未决请求限制此值 限制 AXI 写入接口上的最大未完成请求。 */
+#define DMA_AXI_BUS_MOD_UNLCK_ON_MGK_RWK 0x40000000U
+#define DMA_AXI_BUS_MOD_EN_LPI 0x80000000U
+
+/** MMC Control **/
+#define MMC_DEFAULT_MASK 0xffffffff
+
+/* Common PHY Registers (AR8035) */
+
+#define PHY_BCR_OFFSET ((u16)0x00) /* Transceiver Basic Control Register */
+#define PHY_BSR_OFFSET ((u16)0x01) /* Transceiver Basic Status Register */
+#define PHY_ID1_REG_OFFSET ((u16)0x02) /* PHY ID1 Identifier */
+#define PHY_ID2_REG_OFFSET ((u16)0x03) /* PHY ID2 Identifier */
+#define PHY_AUTO_NEGOTIATION_ADVERTISEMENT_OFFSET ((u16)0x04)
+#define PHY_EXTENDED_CONTROL_REGISTER_OFFSET ((u16)0x9)
+#define PHY_SPECIFIC_STATUS_OFFSET ((u16)0x11)
+#define PHY_INTERRUPT_ENABLE_OFFSET ((u16)0x12)
+#define PHY_INTERRUPT_STATUS_OFFSET ((u16)0x13)
+#define PHY_DEBUG_ADDR_OFFSET ((u16)0x1D)
+#define PHY_DEBUG_DATA_OFFSET ((u16)0x1E)
+
+/* MII control register bit */
+
+#define PHY_BCR_1000 0x0040 /* 1 = 1000mb when \
+ PHY_BCR_100 is also 1 */
+#define PHY_BCR_COLL_TEST 0x0080 /* collision test */
+#define PHY_BCR_FDX 0x0100 /* FDX =1, half duplex =0 */
+#define PHY_BCR_RESTART 0x0200 /* restart auto negotiation */
+#define PHY_BCR_ISOLATE 0x0400 /* isolate PHY from MII */
+#define PHY_BCR_POWER_DOWN 0x0800 /* power down */
+#define PHY_BCR_AUTO_EN 0x1000 /* auto-negotiation enable */
+#define PHY_BCR_100 0x2000 /* 0 = 10mb, 1 = 100mb */
+#define PHY_BCR_LOOPBACK 0x4000 /* 0 = normal, 1 = loopback */
+#define PHY_BCR_RESET 0x8000 /* 0 = normal, 1 = PHY reset */
+#define PHY_BCR_NORM_EN 0x0000 /* just enable the PHY */
+#define PHY_BCR_DEF_0_MASK 0xca7f /* they must return zero */
+#define PHY_BCR_RES_MASK 0x003f /* reserved bits,return zero */
+
+#define PHY_ANAR_10TX_HD ((u16)0x0020)
+#define PHY_ANAR_10TX_FD ((u16)0x0040)
+#define PHY_ANAR_100TX_HD ((u16)0x0080)
+#define PHY_ANAR_100TX_FD ((u16)0x0100)
+#define PHY_ANAR_100T_4 ((u16)0x0200)
+#define PHY_ANAR_PAUSE ((u16)0x0400)
+#define PHY_ANAR_ASM_PAUSE ((u16)0x0800)
+#define PHY_ANAR_REMORT_FAULT ((u16)0x2000)
+#define PHY_ANAR_NEXT_PAGE ((u16)0x8000)
+#define PHY_ANAR_PAUSE_MASK ((u16)0x0c00)
+
+#define PHY_BSR_EXTENDED_STATUS ((u16)0x100)
+
+#define PHY_EXTENDED_CONTROL_1000T_FD ((u16)0x200)
+#define PHY_EXTENDED_CONTROL_1000T_HD ((u16)0x100)
+
+#define PHY_RESET ((u16)0x8000U) /* PHY Reset */
+#define PHY_LOOPBACK ((u16)0x4000U) /* Select loop-back mode */
+#define PHY_FULLDUPLEX_1000M ((u16)0x2140U) /* Set the full-duplex mode at 1000 Mb/s */
+#define PHY_HALFDUPLEX_1000M ((u16)0x2040U) /* Set the half-duplex mode at 1000 Mb/s */
+#define PHY_FULLDUPLEX_100M ((u16)0x2100U) /* Set the full-duplex mode at 100 Mb/s */
+#define PHY_HALFDUPLEX_100M ((u16)0x2000U) /* Set the half-duplex mode at 100 Mb/s */
+#define PHY_FULLDUPLEX_10M ((u16)0x0100U) /* Set the full-duplex mode at 10 Mb/s */
+#define PHY_HALFDUPLEX_10M ((u16)0x0000U) /* Set the half-duplex mode at 10 Mb/s */
+#define PHY_AUTONEGOTIATION ((u16)0x1000U) /* Enable auto-negotiation function */
+#define PHY_RESTART_AUTONEGOTIATION ((u16)0x0200U) /* Restart auto-negotiation function */
+#define PHY_POWERDOWN ((u16)0x0800U) /* Select the power down mode */
+#define PHY_ISOLATE ((u16)0x0400U) /* Isolate PHY from MII */
+
+#define PHY_AUTONEGO_COMPLETE ((u16)0x0020U) /* Auto-Negotiation process completed */
+#define PHY_LINKED_STATUS ((u16)0x0004U) /* Valid link established */
+#define PHY_JABBER_DETECTION ((u16)0x0002U) /* Jabber condition detected */
+
+#define PHY_SPECIFIC_STATUS_DUPLEX ((u16)0x2000) /* 0 is Half-duplex ,1 is Full-duplex */
+#define PHY_SPECIFIC_STATUS_SPEED ((u16)0xc000) /* 0 is 10Mbps ,1 is 100Mbps , 2 is 1000Mbps */
+
+#define PHY_INTERRUPT_ENABLE_WAKE_ON_LAN 0x00000001U /* Wake on LAN interrupt enable,0 Interrupt disable , 1 Interrupt enable */
+#define PHY_INTERRUPT_ENABLE_POLARITY_CHANGED 0x00000002U /* Polarity Changed interrupt enable,0 Interrupt disable , 1 Interrupt enable */
+#define PHY_INTERRUPT_ENABLE_WIRESPEED_DOWNGRADE 0x00000020U /* Wirespeed downgrade Interrupt ,0 Interrupt disable , 1 Interrupt enable*/
+#define PHY_INTERRUPT_ENABLE_LINK_SUCCESS 0x00000400U /* Link success interrupt ,0 Interrupt disable , 1 Interrupt enable*/
+#define PHY_INTERRUPT_ENABLE_LINK_FAIL 0x00000800U /* Link fail interrupt, 0 Interrupt disable , 1 Interrupt enable */
+#define PHY_INTERRUPT_ENABLE_PAGE_RECEIVED 0x00001000U /* Page Received, 0 Interrupt disable , 1 Interrupt enable */
+#define PHY_INTERRUPT_ENABLE_DUPLEX_CHANGED 0x00002000U /* Duplex Changed, 0 Interrupt disable , 1 Interrupt enable*/
+#define PHY_INTERRUPT_ENABLE_SPEED_CHANGED 0x00004000U /* Speed Changed , 0 Interrupt disable , 1 Interrupt enable */
+#define PHY_INTERRUPT_ENABLE_AUTO_NEGOTIATION_ERROR 0x00008000U /* Auto-Negotiation Error , 0 Interrupt disable , 1 Interrupt enable */
+
+#define PHY_INTERRUPT_STATUS_WAKE_ON_LAN 0x00000001U /* Wake on LAN ,0 No Wake-on-LAN packet is received , 1 Wake-on-LAN packet is received */
+#define PHY_INTERRUPT_STATUS_POLARITY_CHANGED 0x00000002U /* Polarity Changed ,0 Polarity changed , 1 Polarity not changed */
+#define PHY_INTERRUPT_STATUS_WIRESPEED_DOWNGRADE 0x00000020U /* Wirespeed downgrade Interrupt ,0 No Smartspeed interrupt detected , 1 Smartspeed interrupt detected */
+#define PHY_INTERRUPT_STATUS_LINK_SUCCESS 0x00000400U /* Link success interrupt ,0 Link up not happened , 1 Link up happened.*/
+#define PHY_INTERRUPT_STATUS_LINK_FAIL 0x00000800U /* Link fail interrupt, 0 Link down not happened , 1 Link down happened. */
+#define PHY_INTERRUPT_STATUS_PAGE_RECEIVED 0x00001000U /* Page Received, 0 Page not received , 1 Page received */
+#define PHY_INTERRUPT_STATUS_DUPLEX_CHANGED 0x00002000U /* Duplex Changed, 0 Duplex not changed , 1 Duplex changed*/
+#define PHY_INTERRUPT_STATUS_SPEED_CHANGED 0x00004000U /* Speed Changed , 0 Speed not changed , 1 Speed changed */
+#define PHY_INTERRUPT_STATUS_AUTO_NEGOTIATION_ERROR 0x00008000U /* Auto-Negotiation Error , 0 No Auto-Negotiation Error , 1 Auto-Negotiation Error */
+
+/**
+ * @name: FGmac_InitializeHw
+ * @msg: 初始化Mac层与Phy层参数 。
+ * @param {FGmac_Config_t} *Config 包含Mac层 与Phy层,配置参数。
+ * @return {s32} Common_status 参数。
+ */
+s32 FGmac_InitializeHw(FGmac_Config_t *Config);
+
+/**
+ * @name: FGmac_ReadPHYRegister
+ * @msg: 读取Phy 中的寄存器
+ * @param {FGmac_Config_t} *Config 提供读取的基地址,与Phy读取过程中需要的相关参数。
+ * @param {u16} PHYReg 需要读取Phy 芯片的寄存器地址。
+ * @param {u32} *RegValue 读取出来的寄存器参数
+ * @return {s32} Common_status 参数。
+ */
+s32 FGmac_ReadPHYRegister(FGmac_Config_t *Config, u16 PHYReg, u32 *RegValue);
+
+/**
+ * @name: Gmac_WritePHYRegister
+ * @msg: 向Phy 中的特定寄存器写入参数。
+ * @param {FGmac_Config_t} *Config 提供读取的基地址,与Phy读取过程中需要的相关参数。
+ * @param {u16} PHYReg 需要读取Phy 芯片的寄存器地址。
+ * @param {u32} RegValue 需要写入的寄存器参数
+ * @return {s32} Common_status 参数。
+ */
+s32 Gmac_WritePHYRegister(FGmac_Config_t *Config, u16 PHYReg, u32 RegValue);
+
+/**
+ * @name: FGmac_TransmissionEnable
+ * @msg: 使能 Gmac 开始发送功能
+ * @param {FGmac_Config_t} *Config 提供Mac的基地址。
+ * @return {None}
+ */
+void FGmac_TransmissionEnable(FGmac_Config_t *Config);
+
+/**
+ * @name: FGmac_TransmissionDisable
+ * @msg: 禁止 Gmac 开始发送功能
+ * @param {FGmac_Config_t} *Config 提供Mac的基地址。
+ * @return {None}
+ */
+void FGmac_TransmissionDisable(FGmac_Config_t *Config);
+
+/**
+ * @name: FGmac_ReceptionEnable
+ * @msg: 使能 Gmac 开始接收功能
+ * @param {FGmac_Config_t} *Config 提供Mac的基地址。
+ * @return {None}
+ */
+void FGmac_ReceptionEnable(FGmac_Config_t *Config);
+
+/**
+ * @name: FGmac_ReceptionDisable
+ * @msg: 禁止 Gmac 开始接收功能
+ * @param {FGmac_Config_t} *Config 提供Mac的基地址。
+ * @return {None}
+ */
+void FGmac_ReceptionDisable(FGmac_Config_t *Config);
+
+/**
+ * @name: FGmac_DMAReceptionTransmissionEnable
+ * @msg: 使能 Gmac 开始DMA描述符接收与写入功能
+ * @param {FGmac_Config_t} *Config 提供Mac的基地址。
+ * @return {*}
+ */
+void FGmac_DMAReceptionTransmissionEnable(FGmac_Config_t *Config);
+
+/**
+ * @name: FGmac_ReceptionTransmissionEnable
+ * @msg: 使能 Gmac 开始接收与发送功能
+ * @param {FGmac_Config_t} *Config 提供Mac的基地址。
+ * @return {*}
+ */
+void FGmac_ReceptionTransmissionEnable(FGmac_Config_t *Config);
+
+/**
+ * @name: FGmac_FlushTransmitFIFO
+ * @msg: 刷新 Gmac 发送 FIFO
+ * @param {FGmac_Config_t} *Config 提供Mac的基地址。
+ * @return {*}
+ */
+void FGmac_FlushTransmitFIFO(FGmac_Config_t *Config);
+
+/**
+ * @name: FGmac_DMATransmissionEnable
+ * @msg: 使能 DMA描述符发送功能
+ * @param {FGmac_Config_t} *Config 提供Mac的基地址。
+ * @return {*}
+ */
+void FGmac_DMATransmissionEnable(FGmac_Config_t *Config);
+/**
+ * @name: FGmac_DMATransmissionDisable
+ * @msg: 关闭 DMA描述符发送功能
+ * @param {FGmac_Config_t} *Config 提供Mac的基地址。
+ * @return {*}
+ */
+void FGmac_DMATransmissionDisable(FGmac_Config_t *Config);
+/**
+ * @name: FGmac_DMAReceptionEnable
+ * @msg: 使能 DMA描述符接收功能
+ * @param {FGmac_Config_t} *Config 提供Mac的基地址。
+ * @return {*}
+ */
+void FGmac_DMAReceptionEnable(FGmac_Config_t *Config);
+/**
+ * @name: FGmac_DMAReceptionEnable
+ * @msg: 使能 DMA描述符接收功能
+ * @param {FGmac_Config_t} *Config 提供Mac的基地址。
+ * @return {*}
+ */
+void FGmac_DMAReceptionDisable(FGmac_Config_t *Config);
+#endif // !
diff --git a/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_intr.c b/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_intr.c
new file mode 100644
index 0000000000..0c57a118ee
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_intr.c
@@ -0,0 +1,174 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-05-25 16:42:56
+ * @Description:  This files is for gmac irq
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_gmac_hw.h"
+#include "ft_gmac.h"
+#include "ft_status.h"
+#include "ft_assert.h"
+#include "ft_io.h"
+
+#include "ft_debug.h"
+#define GMAC_INTR_DEBUG_TAG "GMAC_INTR"
+
+#define GMAC_INTR_DEBUG_I(format, ...) FT_DEBUG_PRINT_I(GMAC_INTR_DEBUG_TAG, format, ##__VA_ARGS__)
+#define GMAC_INTR_DEBUG_E(format, ...) FT_DEBUG_PRINT_E(GMAC_INTR_DEBUG_TAG, format, ##__VA_ARGS__)
+#define GMAC_INTR_DEBUG_W(format, ...) FT_DEBUG_PRINT_W(GMAC_INTR_DEBUG_TAG, format, ##__VA_ARGS__)
+
+s32 FGmac_SetHandler(Ft_Gmac_t *Gmac, FGmac_IsrCallbackSelect_t SelectIndex, void *FuncPtr,
+ void *Args)
+{
+ Ft_assertNonvoid(Gmac != NULL);
+ Ft_assertNonvoid(FuncPtr != NULL);
+ Ft_assertNonvoid(Gmac->IsReady == FT_COMPONENT_IS_READLY);
+
+ switch (SelectIndex)
+ {
+ case FT_GMAC_TX_COMPLETE_CB_ID:
+ /* code */
+ Gmac->SendHandler = FuncPtr;
+ Gmac->SendArgs = Args;
+ break;
+ case FT_GMAC_RX_COMPLETE_CB_ID:
+ Gmac->RecvHandler = FuncPtr;
+ Gmac->RecvArgs = Args;
+ break;
+ case FT_GMAC_DMA_ERROR_CB_ID:
+ Gmac->ErrorHandler = FuncPtr;
+ Gmac->ErrorArgs = Args;
+ break;
+ case FT_GMAC_MAC_PHY_STATUS_CB_ID:
+ Gmac->StatusHandler = FuncPtr;
+ Gmac->StatusArgs = Args;
+ break;
+ default:
+ return FST_FAILURE;
+ }
+
+ return FST_SUCCESS;
+}
+
+
+__STATIC_INLINE u32 FGmac_ErrorCheck(Ft_Gmac_t *Gmac)
+{
+ u32 RegValue = 0;
+ u32 ErrIsr_RegValue = 0;
+ u32 RetValue = 0;
+ RegValue = Ft_in32(Gmac->Config.BaseAddress + DMA_STATUS_OFFSET);
+ ErrIsr_RegValue = Ft_in32(Gmac->Config.BaseAddress + DMA_INTR_ENA_OFFSET);
+
+ if (((RegValue & DMA_STATUS_TPS) == DMA_STATUS_TPS) && ((ErrIsr_RegValue & DMA_INTR_ENA_TSE) == DMA_INTR_ENA_TSE))
+ {
+ RetValue |= GMAC_ERROR_TRANSMIT_PROCESS_STOPPED;
+ }
+
+ if (((RegValue & DMA_STATUS_TU) == DMA_STATUS_TU) && ((ErrIsr_RegValue & DMA_INTR_ENA_TUE) == DMA_INTR_ENA_TUE))
+ {
+ RetValue |= GMAC_ERROR_TRANSMIT_UNAVAILABLE_STATUS;
+ }
+
+ if (((RegValue & DMA_STATUS_TJT) == DMA_STATUS_TJT) && ((ErrIsr_RegValue & DMA_INTR_ENA_THE) == DMA_INTR_ENA_THE))
+ {
+ RetValue |= GMAC_ERROR_TRANSMIT_JABBER_TIMEOUT;
+ }
+
+ if (((RegValue & DMA_STATUS_OVF) == DMA_STATUS_OVF) && ((ErrIsr_RegValue & DMA_INTR_ENA_OVE) == DMA_INTR_ENA_OVE))
+ {
+ RetValue |= GMAC_ERROR_RECEIVE_FIFO_OVERFLOW;
+ }
+
+ if (((RegValue & DMA_STATUS_UNF) == DMA_STATUS_UNF) && ((ErrIsr_RegValue & DMA_INTR_ENA_UNE) == DMA_INTR_ENA_UNE))
+ {
+ RetValue |= GMAC_ERROR_TRANSMIT_UNDERFLOW;
+ }
+
+ if (((RegValue & DMA_STATUS_RU) == DMA_STATUS_RU) && ((ErrIsr_RegValue & DMA_INTR_ENA_RUE) == DMA_INTR_ENA_RUE))
+ {
+ RetValue |= GMAC_ERROR_RECEIVE_BUFFER_UNAVAILABLE;
+ }
+
+ if (((RegValue & DMA_STATUS_RPS) == DMA_STATUS_RPS) && ((ErrIsr_RegValue & DMA_INTR_ENA_RSE) == DMA_INTR_ENA_RSE))
+ {
+ RetValue |= GMAC_ERROR_RECEIVE_PROCESS_STOPPED;
+ }
+
+ if (((RegValue & DMA_STATUS_RWT) == DMA_STATUS_RWT) && ((ErrIsr_RegValue & DMA_INTR_ENA_RWE) == DMA_INTR_ENA_RWE))
+ {
+ RetValue |= GMAC_ERROR_RECEIVE_WATCHDOG_TIMEOUT;
+ }
+
+ if (((RegValue & DMA_STATUS_ETI) == DMA_STATUS_ETI) && ((ErrIsr_RegValue & DMA_INTR_ENA_ETE) == DMA_INTR_ENA_ETE))
+ {
+ RetValue |= GMAC_ERROR_EARLY_TRANSMIT_INTERRUPT;
+ }
+
+ if (((RegValue & DMA_STATUS_FBI) == DMA_STATUS_FBI) && ((ErrIsr_RegValue & DMA_INTR_ENA_FBE) == DMA_INTR_ENA_FBE))
+ {
+ RetValue |= GMAC_ERROR_FATAL_BUS_ERROR;
+ }
+
+ if (0U == RetValue)
+ {
+ RetValue |= GMAC_ERROR_UNDEFINED;
+ }
+ Ft_printf("error RetValue %x \r\n", RetValue);
+ return RetValue;
+}
+
+
+void FGmac_IntrHandler(void *Args)
+{
+ Ft_Gmac_t *Gmac;
+ u32 RegValue;
+ u32 MACRegValue;
+ Ft_assertVoid(Args != NULL);
+ Gmac = (Ft_Gmac_t *)Args;
+
+ RegValue = Ft_in32(Gmac->Config.BaseAddress + DMA_STATUS_OFFSET);
+ if ((RegValue)&DMA_STATUS_GLI)
+ {
+ MACRegValue = Ft_in32(Gmac->Config.BaseAddress + GMAC_MAC_MAC_PHY_STATUS);
+ if (Gmac->StatusHandler)
+ {
+ Gmac->StatusHandler(Gmac->StatusArgs, MACRegValue);
+ }
+ }
+
+ /* Frame received */
+ if ((RegValue & (DMA_STATUS_RI)) != 0)
+ {
+ if (Gmac->RecvHandler)
+ {
+ Gmac->RecvHandler(Gmac->RecvArgs);
+ }
+
+ Ft_out32(Gmac->Config.BaseAddress + DMA_STATUS_OFFSET, DMA_STATUS_RI);
+ }
+ else if ((RegValue & DMA_STATUS_TI) == DMA_STATUS_TI)
+ {
+ Ft_printf("DMA_STATUS_TI %x \r\n", RegValue);
+ Ft_printf("ti debug %x \r\n", Ft_in32(Gmac->Config.BaseAddress + GMAC_INTERNAL_MODULE_STATUS_OFFSET));
+
+ Ft_out32(Gmac->Config.BaseAddress + DMA_STATUS_OFFSET, DMA_STATUS_TI);
+ }
+
+ Ft_out32(Gmac->Config.BaseAddress + DMA_STATUS_OFFSET, DMA_STATUS_NIS);
+
+ /* DMA Error */
+ if ((Ft_in32(Gmac->Config.BaseAddress + DMA_STATUS_OFFSET) & DMA_STATUS_AIS) == DMA_STATUS_AIS)
+ {
+ if (Gmac->ErrorHandler)
+ Gmac->ErrorHandler(Gmac->ErrorArgs, FGmac_ErrorCheck(Gmac));
+ Ft_out32(Gmac->Config.BaseAddress + DMA_STATUS_OFFSET, Ft_in32(Gmac->Config.BaseAddress + DMA_STATUS_OFFSET));
+ }
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_sinit.c b/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_sinit.c
new file mode 100644
index 0000000000..909e05dc22
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_gmac/ft_gmac_sinit.c
@@ -0,0 +1,34 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-05-25 16:43:06
+ * @Description:  This files is for gmac static init
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_gmac.h"
+#include "ft_parameters.h"
+
+extern FGmac_Config_t Gmac_ConfigTable[FT_GMAC_INSTANCES_NUM];
+
+FGmac_Config_t *Ft_Gmac_LookupConfig(u32 InstanceId)
+{
+ FGmac_Config_t *CfgPtr = NULL;
+ u32 Index;
+ for (Index = 0; Index < (u32)FT_GMAC_INSTANCES_NUM; Index++)
+ {
+ if (Gmac_ConfigTable[Index].InstanceId == InstanceId)
+ {
+ CfgPtr = &Gmac_ConfigTable[Index];
+ break;
+ }
+ }
+
+ return (FGmac_Config_t *)CfgPtr;
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_gpio/ft_gpio.c b/bsp/ft2004/libraries/bsp/ft_gpio/ft_gpio.c
new file mode 100644
index 0000000000..37c442f39e
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_gpio/ft_gpio.c
@@ -0,0 +1,107 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-27 17:55:31
+ * @LastEditTime: 2021-05-25 16:43:31
+ * @Description:  This files is for
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_gpio.h"
+#include "ft_gpio_hw.h"
+#include "ft_assert.h"
+#include "ft_debug.h"
+
+#define GPIO_MAX_PIN 7
+#define GPIO_MAX_CTRL_ID 1
+
+void FGpio_SetGroupModeA(FT_IN u32 ctrlId, FT_IN u8 pin, FT_IN u32 mode)
+{
+ u32 RegVal;
+ Ft_assertNoneReturn(ctrlId <= GPIO_MAX_CTRL_ID);
+ Ft_assertNoneReturn(pin <= GPIO_MAX_PIN);
+
+ RegVal = FGpioA_ReadReg(ctrlId, GPIO_INTEN);
+ switch (mode)
+ {
+ case GPIO_MODE_GPIO:
+ RegVal &= ~(1 << pin);
+ break;
+ case GPIO_MODE_INT:
+ RegVal |= (1 << pin);
+ break;
+ default:
+ Ft_assertNoneReturn(0);
+ break;
+ }
+
+ FGpioA_WriteReg(ctrlId, GPIO_INTEN, RegVal);
+ return;
+}
+
+static void FGpio_SetPinInOutA(FT_IN u32 ctrlId, FT_IN u8 pin, FT_IN u8 inOut)
+{
+ u32 RegVal;
+ Ft_assertNoneReturn(ctrlId <= GPIO_MAX_CTRL_ID);
+ Ft_assertNoneReturn(pin <= GPIO_MAX_PIN);
+
+ RegVal = FGpioA_ReadReg(ctrlId, GPIO_SWPORTA_DDR);
+ if (inOut != (RegVal & (0x1 << pin)))
+ {
+ if (GPIO_INPUT == inOut)
+ {
+ RegVal &= ~(0x1 << pin);
+ }
+ else if (GPIO_OUTPUT == inOut)
+ {
+ RegVal |= (0x1 << pin);
+ }
+ else
+ {
+ Ft_assertNoneReturn(0);
+ }
+
+ FGpioA_WriteReg(ctrlId, GPIO_SWPORTA_DDR, RegVal);
+ }
+
+ return;
+}
+
+u32 FGpio_ReadPinA(FT_IN u32 ctrlId, FT_IN u8 pin)
+{
+ u32 RegVal;
+ u32 OnOff;
+ Ft_assertNoneReturn(ctrlId <= GPIO_MAX_CTRL_ID);
+ Ft_assertNoneReturn(pin <= GPIO_MAX_PIN);
+
+ FGpio_SetPinInOutA(ctrlId, pin, GPIO_INPUT);
+ RegVal = FGpioA_ReadReg(ctrlId, GPIO_EXT_PORTA);
+ OnOff = (RegVal & (0x1 << pin)) ? GPIO_ON : GPIO_OFF;
+ return OnOff;
+}
+
+void FGpio_WritePinA(FT_IN u32 ctrlId, FT_IN u8 pin, FT_IN u8 onOff)
+{
+ u32 RegVal;
+ Ft_assertNoneReturn(ctrlId <= GPIO_MAX_CTRL_ID);
+ Ft_assertNoneReturn(pin <= GPIO_MAX_PIN);
+ Ft_assertNoneReturn((onOff == GPIO_OFF) || (onOff == GPIO_ON));
+
+ FGpio_SetPinInOutA(ctrlId, pin, GPIO_OUTPUT);
+ RegVal = FGpioA_ReadReg(ctrlId, GPIO_SWPORTA_DR);
+ if (GPIO_OFF == onOff)
+ {
+ RegVal &= ~(1 << pin);
+ }
+ else
+ {
+ RegVal |= (1 << pin);
+ }
+ FGpioA_WriteReg(ctrlId, GPIO_SWPORTA_DR, RegVal);
+ return;
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_gpio/ft_gpio.h b/bsp/ft2004/libraries/bsp/ft_gpio/ft_gpio.h
new file mode 100644
index 0000000000..b875470e53
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_gpio/ft_gpio.h
@@ -0,0 +1,73 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-27 17:55:12
+ * @LastEditTime: 2021-04-30 14:38:45
+ * @Description:  This files is for
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef FT_BSP_GPIO_H
+#define FT_BSP_GPIO_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "ft_types.h"
+#include "ft_gpio_hw.h"
+
+/* gpio mode: gpio/int */
+#define GPIO_MODE_GPIO 0
+#define GPIO_MODE_INT 1
+
+/* define debug utilities */
+#define FT_GPIO_DEBUG_TAG "FT_GPIO"
+#define FT_GPIO_ENABLE_DEBUG
+#define FT_GPIO_ERROR(format, ...) FT_DEBUG_PRINT_E(FT_GPIO_DEBUG_TAG, format, ##__VA_ARGS__)
+#ifdef FT_GPIO_ENABLE_DEBUG
+#define FT_GPIO_DEBUG_I(format, ...) FT_DEBUG_PRINT_I(FT_GPIO_DEBUG_TAG, format, ##__VA_ARGS__)
+#define FT_GPIO_DEBUG_W(format, ...) FT_DEBUG_PRINT_W(FT_GPIO_DEBUG_TAG, format, ##__VA_ARGS__)
+#else
+#define FT_GPIO_DEBUG_I(format, ...)
+#define FT_GPIO_DEBUG_W(format, ...)
+#endif
+
+ /**
+ * @name: FGpio_SetGroupModeA
+ * @msg: set gpio mode, polling or intr
+ * @return {*}
+ * @param {FT_IN u32} ctrlId
+ * @param {FT_IN u8} pin
+ * @param {FT_IN u32} mode
+ */
+ void FGpio_SetGroupModeA(FT_IN u32 CtrlId, FT_IN u8 Pin, FT_IN u32 Mode);
+ /**
+ * @name: FGpio_ReadPinA
+ * @msg: get gpio pin status
+ * @return {*}
+ * @param {FT_IN u32} ctrlId
+ * @param {FT_IN u8} pin
+ */
+ u32 FGpio_ReadPinA(FT_IN u32 CtrlId, FT_IN u8 Pin);
+ /**
+ * @name: FGpio_WritePinA
+ * @msg: set gpio pin status
+ * @return {*}
+ * @param {FT_IN u32} ctrlId
+ * @param {FT_IN u8} pin
+ * @param {FT_IN u8} onOff
+ */
+ void FGpio_WritePinA(FT_IN u32 CtrlId, FT_IN u8 Pin, FT_IN u8 OnOff);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/bsp/ft2004/libraries/bsp/ft_gpio/ft_gpio_hw.h b/bsp/ft2004/libraries/bsp/ft_gpio/ft_gpio_hw.h
new file mode 100644
index 0000000000..77d9071fd4
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_gpio/ft_gpio_hw.h
@@ -0,0 +1,92 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-27 17:55:22
+ * @LastEditTime: 2021-04-28 08:39:20
+ * @Description:  This files is for
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef FT_BSP_GPIO_HW_H
+#define FT_BSP_GPIO_HW_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "ft_types.h"
+#include "ft_io.h"
+
+#define GPIO_CTRL_ID_0 0
+#define GPIO_CTRL_ID_1 1
+
+/* base address of gpio register */
+#define GPIO_CTRL0_PA_BASE 0x28004000
+#define GPIO_CTRL1_PA_BASE 0x28005000
+#define GPIO_GROUPA_OFFSET 0x0
+#define GPIO_GROUPB_OFFSET 0xc
+
+/* offset of register map */
+#define GPIO_SWPORTA_DR 0x00 //A 组端口输出寄存器
+#define GPIO_SWPORTA_DDR 0x04 //A 组端口方向控制寄存器
+#define GPIO_EXT_PORTA 0x08 //A 组端口输入寄存器
+
+#define GPIO_SWPORTB_DR 0x0c //B 组端口输出寄存器
+#define GPIO_SWPORTB_DDR 0x10 //B 组端口方向控制寄存器
+#define GPIO_EXT_PORTB 0x14 //B 组端口输入寄存器
+
+#define GPIO_INTEN 0x18 //A 组端口中断使能寄存器
+#define GPIO_INTMASK 0x1c //A 组端口中断屏蔽寄存器
+#define GPIO_INTTYPE_LEVEL 0x20 //A 组端口中断等级寄存器
+#define GPIO_INT_POLARITY 0x24 //A 组端口中断极性寄存器
+#define GPIO_INTSTATUS 0x28 //A 组端口中断状态寄存器
+#define GPIO_RAW_INTSTATUS 0x2c //A 组端口原始中断状态寄存器
+
+#define GPIO_LS_SYNC 0x30 //配置中断同步寄存器
+#define GPIO_DEBOUNCE 0x34 //防反跳配置寄存器
+#define GPIO_PORTA_EOI 0x38 //A 组端口中断清除寄存器
+
+/* misc marco */
+#define GPIO_GROUP_A 0
+#define GPIO_OFF 0
+#define GPIO_ON 1
+#define GPIO_INPUT 0
+#define GPIO_OUTPUT 1
+
+ inline static u32 FGpio_GetBaseAddr(FT_IN u32 ctrlId, FT_IN u32 groupId)
+ {
+ static const u32 CtrlAddr[2] = {GPIO_CTRL0_PA_BASE, GPIO_CTRL1_PA_BASE};
+ static const u32 GroupOff[2] = {GPIO_GROUPA_OFFSET, GPIO_GROUPB_OFFSET};
+ return CtrlAddr[ctrlId] + GroupOff[groupId];
+ }
+
+/**
+ * @name: FGpio_WriteReg
+ * @msg: write gpio register
+ * @param {u32} BaseAddress base addr of i2c
+ * @param {u32} RegOffset addr offset of i2c register
+ * @param {u32} RegisterValue val to be write into register
+ * @return {void}
+ */
+#define FGpioA_WriteReg(ctrlId, RegOffset, RegisterValue) Ft_out32(FGpio_GetBaseAddr(ctrlId, GPIO_GROUP_A) + (u32)RegOffset, (u32)RegisterValue)
+
+/**
+ * @name: FGpio_ReadReg
+ * @msg: read gpio register
+ * @param {u32} BaseAddress base addr of i2c
+ * @param {u32} RegOffset addr offset of i2c register
+ * @return {u32} val read from register
+ */
+#define FGpioA_ReadReg(ctrlId, RegOffset) Ft_in32(FGpio_GetBaseAddr(ctrlId, GPIO_GROUP_A) + (u32)RegOffset)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/bsp/ft2004/libraries/bsp/ft_i2c/ft_i2c.c b/bsp/ft2004/libraries/bsp/ft_i2c/ft_i2c.c
new file mode 100644
index 0000000000..57985f906f
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_i2c/ft_i2c.c
@@ -0,0 +1,510 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-05-25 16:45:00
+ * @Description:  This files is for i2c user interface
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include <string.h>
+#include <stdio.h>
+#include "ft_mux.h"
+#include "ft_i2c_hw.h"
+#include "ft_i2c.h"
+#include "ft_generic_timer.h"
+
+/* reset val of register */
+#define I2C_CON_DEFAULT 0x7F
+#define I2C_TAR_DEFAULT 0x1055
+#define I2C_SAR_DEFAULT 0x55
+#define I2C_DATA_CMD_DEFAULT 0x0
+#define I2C_SS_SCL_LCNT_DEFAULT 0x1D6
+#define I2C_SS_SCL_HCNT_DEFAULT 0x190
+#define I2C_FS_SCL_LCNT_DEFAULT 0x82
+#define I2C_FS_SCL_HCNT_DEFAULT 0x3C
+#define I2C_HS_SCL_LCNT_DEFAULT 0x10
+#define I2C_HS_SCL_HCNT_DEFAULT 0x6
+#define I2C_INTR_MASK_DEFAULT 0x8FF
+//#define I2C_RX_TL_DEFAULT 0x0
+//#define I2C_TX_TL_DEFAULT 0x0
+#define I2C_SCL_HCNT_DEFAULT 0x2f
+#define I2C_SCL_LCNT_DEFAULT 0x2f
+//#define I2C_RX_TL_SET 0xff
+//#define I2C_TX_TL_SET 0xff
+
+#define I2C_RX_TL_BY_BYTE 0x0
+#define I2C_TX_TL_BY_BYTE 0x0
+#define I2C_RX_TL_BY_FIFO 0x01
+#define I2C_TX_TL_BY_FIFO 0x01
+
+LOCAL const u32 g_I2cSpeedMask[MAX_I2C_SPEED] = {I2C_STANDARD_SPEED_MASK,
+ I2C_FAST_SPEED_MASK,
+ I2C_HIGH_SPEED_MASK};
+LOCAL const u32 g_I2cSclLcntReg[MAX_I2C_SPEED] = {I2C_SS_SCL_LCNT,
+ I2C_FS_SCL_LCNT, I2C_HS_SCL_LCNT};
+LOCAL const u32 g_I2cSclHcntReg[MAX_I2C_SPEED] = {I2C_SS_SCL_HCNT,
+ I2C_FS_SCL_LCNT, I2C_HS_SCL_LCNT};
+
+void FI2C_resetReg(u32 BaseAddr)
+{
+ /* set default value for register */
+ FI2C_WriteReg(BaseAddr, I2C_CON, I2C_CON_DEFAULT);
+ FI2C_WriteReg(BaseAddr, I2C_TAR, I2C_TAR_DEFAULT);
+ FI2C_WriteReg(BaseAddr, I2C_SAR, I2C_SAR_DEFAULT);
+ FI2C_WriteReg(BaseAddr, I2C_DATA_CMD, I2C_DATA_CMD_DEFAULT);
+ FI2C_WriteReg(BaseAddr, I2C_SS_SCL_LCNT, I2C_SS_SCL_LCNT_DEFAULT);
+ FI2C_WriteReg(BaseAddr, I2C_SS_SCL_HCNT, I2C_SS_SCL_HCNT_DEFAULT);
+ FI2C_WriteReg(BaseAddr, I2C_FS_SCL_LCNT, I2C_FS_SCL_LCNT_DEFAULT);
+ FI2C_WriteReg(BaseAddr, I2C_FS_SCL_HCNT, I2C_FS_SCL_HCNT_DEFAULT);
+ FI2C_WriteReg(BaseAddr, I2C_HS_SCL_LCNT, I2C_HS_SCL_LCNT_DEFAULT);
+ FI2C_WriteReg(BaseAddr, I2C_HS_SCL_HCNT, I2C_HS_SCL_HCNT_DEFAULT);
+ FI2C_WriteReg(BaseAddr, I2C_INTR_MASK, I2C_INTR_MASK_DEFAULT);
+ FI2C_WriteReg(BaseAddr, I2C_RX_TL, I2C_RX_TL_DEFAULT);
+ FI2C_WriteReg(BaseAddr, I2C_TX_TL, I2C_TX_TL_DEFAULT);
+}
+
+inline LOCAL void FI2C_setSclClk(FT_IN u32 BaseAddr, FT_IN FI2C_SpeedType_t SpeedType,
+ FT_IN u32 SclLcnt, FT_IN u32 SclHcnt)
+{
+ u32 SclLcntAddr = g_I2cSclLcntReg[SpeedType];
+ u32 SclHcntAddr = g_I2cSclHcntReg[SpeedType];
+
+ FI2C_WriteReg(BaseAddr, SclLcntAddr, SclLcnt);
+ FI2C_WriteReg(BaseAddr, SclHcntAddr, SclHcnt);
+
+ return;
+}
+
+inline LOCAL void FI2C_setCtrlParam(FT_IN u32 BaseAddr, FT_IN FI2C_SpeedType_t SpeedType, FT_IN bool_t Is7BitAddr)
+{
+ u32 RegVal;
+
+ RegVal = I2C_CON_ME | g_I2cSpeedMask[SpeedType];
+ RegVal |= ((TRUE == Is7BitAddr) ? I2C_CON_MASTER_ADR_7BIT : I2C_CON_MASTER_ADR_10BIT);
+ RegVal |= I2C_CON_RESTART_EN | I2C_CON_SLAVE_DISABLE;
+
+ FI2C_WriteReg(BaseAddr, I2C_CON, RegVal);
+ return;
+}
+
+void FI2C_initMasterCfg(FT_IN FI2C_Instance_t id,
+ FT_IN FI2C_WorkMode_t mode,
+ FT_IN bool_t UseWRFifo,
+ FT_IN u32 PageSize,
+ FT_INOUT FI2C_Config_t *pCfg)
+{
+ Ft_assertNoneReturn(NULL != pCfg);
+
+ pCfg->InstanceId = id;
+ pCfg->BaseAddress = g_FI2cRegBaseAddr[id];
+ pCfg->IrqNum = g_FI2cIrqNum[id];
+ pCfg->IrqPriority = I2C_DEFAULT_IRQ_PRIORITY;
+ pCfg->BusSpeed = I2C_STANDARD_SPEED;
+ pCfg->SclLcnt = I2C_SCL_LCNT_DEFAULT;
+ pCfg->SclHcnt = I2C_SCL_HCNT_DEFAULT;
+ pCfg->WRByFifo = UseWRFifo;
+ if (TRUE == pCfg->WRByFifo)
+ {
+ pCfg->RxThres = I2C_RX_TL_BY_FIFO;
+ pCfg->TxThres = I2C_TX_TL_BY_FIFO;
+ }
+ else
+ {
+ pCfg->RxThres = I2C_RX_TL_BY_BYTE;
+ pCfg->TxThres = I2C_TX_TL_BY_BYTE;
+ }
+ pCfg->Is7BitAddr = TRUE;
+ pCfg->BlockSize = PageSize;
+
+ if (I2C_POLLING_MODE == mode)
+ {
+ pCfg->IsPolling = TRUE;
+ }
+ else if (I2C_IRQ_MODE == mode)
+ {
+ pCfg->IsPolling = FALSE;
+ }
+ else
+ {
+ Ft_assertNoneReturn(0);
+ }
+
+ return;
+}
+
+void FI2C_initMaster(FT_IN FI2C_Instance_t id,
+ FT_IN FI2C_WorkMode_t mode,
+ FT_IN u32 SlaveAddr,
+ FT_IN bool_t UseWRFifo,
+ FT_IN u32 PageSize,
+ FT_INOUT FI2C_t *pDev)
+{
+ u32 RxDepth;
+ u32 TxDepth;
+
+ Ft_assertNoneReturn(NULL != pDev);
+
+ memset(pDev, 0, sizeof(FI2C_t));
+
+ /* setup i2c bus mux */
+ Ft_setI2cMux(id);
+
+ /* setup i2c config as master */
+ FI2C_initMasterCfg(id, mode, UseWRFifo, PageSize, &pDev->Config);
+ pDev->SlaveAddr = SlaveAddr;
+ pDev->DelayHandle = Ft_GenericTimer_UsDelay;
+
+ /* init irq handler */
+ pDev->pRxEvent = NULL;
+ pDev->pTxEvent = NULL;
+
+ pDev->pIrqCallBack = NULL;
+ pDev->pWaitCallBack = NULL;
+
+ FI2C_DISABLE_I2C_BUS(pDev);
+ FI2C_CLR_ALL_IRQ_STATUS(pDev);
+
+ /* reset reg val */
+ FI2C_resetReg(pDev->Config.BaseAddress);
+
+ /* set scl high && low level */
+ FI2C_setSclClk(pDev->Config.BaseAddress,
+ pDev->Config.BusSpeed,
+ pDev->Config.SclLcnt,
+ pDev->Config.SclHcnt);
+
+ /* set ctrl parameters */
+ FI2C_setCtrlParam(pDev->Config.BaseAddress,
+ pDev->Config.BusSpeed,
+ pDev->Config.Is7BitAddr);
+
+ /* set rx & tx trigger level */
+ RxDepth = FI2C_GET_RX_BUFFER_DEPTH(pDev);
+ TxDepth = FI2C_GET_TX_BUFFER_DEPTH(pDev);
+
+ /* threshold shall not greater than depth */
+
+ FI2C_SET_TX_TL(pDev, FT_MIN(pDev->Config.TxThres, TxDepth));
+ FI2C_SET_RX_TL(pDev, FT_MIN(pDev->Config.RxThres, RxDepth));
+ pDev->IsReady = TRUE;
+ return;
+}
+
+void FI2C_deInitMaster(FT_INOUT FI2C_t *pDev)
+{
+ /* assert no memory need to release */
+ pDev->IsReady = FALSE;
+}
+
+inline LOCAL void FI2C_sendRestartCmd(FT_IN u32 BaseAddr)
+{
+ u32 RegVal = FI2C_ReadReg(BaseAddr, I2C_CON);
+ RegVal |= I2C_CON_RESTART_EN;
+ FI2C_WriteReg(BaseAddr, I2C_CON, RegVal);
+}
+
+inline LOCAL void FI2C_setTarAddr(FT_IN u32 BaseAddr, FT_IN u32 SlaveAddr)
+{
+ u32 RegVal = (SlaveAddr & I2C_TAR_ADR_MASK);
+ FI2C_WriteReg(BaseAddr, I2C_TAR, RegVal);
+}
+
+inline LOCAL void FI2C_sendWriteCmd(FT_IN u32 BaseAddr, FT_IN u32 PageAddr)
+{
+ u32 RegVal = I2C_DATA_CMD_RESTART | (PageAddr & I2C_DATA_CMD_DAT_MASK);
+ FI2C_WriteReg(BaseAddr, I2C_DATA_CMD, RegVal);
+}
+
+inline LOCAL void FI2C_sendStartReadCmd(FT_IN u32 BaseAddr, FT_IN u32 PageAddr)
+{
+ /* send read cmd */
+ u32 RegVal = I2C_DATA_CMD_STOP | I2C_DATA_CMD_RESTART | (PageAddr & 0xff);
+ FI2C_WriteReg(BaseAddr, I2C_DATA_CMD, RegVal);
+}
+
+void FI2C_sendStopCmd(FT_IN u32 BaseAddr)
+{
+ /* send stop signal */
+ u32 RegVal = I2C_DATA_CMD_STOP;
+ FI2C_WriteReg(BaseAddr, I2C_DATA_CMD, RegVal);
+}
+
+LOCAL bool_t FI2C_blockWaitForStatus(FT_IN u32 stMask, FT_INOUT FI2C_t *pDev)
+{
+ u32 timeout = 0;
+ bool_t IsFree = FALSE;
+
+ Ft_assertNoneReturn(NULL != pDev);
+
+ /* Wait until Specific Status Bit in I2C_STATUS is 1 */
+ while ((!FI2C_CHECK_STATUS(pDev, stMask)) && (timeout < I2C_TIMEOUT))
+ {
+ pDev->DelayHandle(5000);
+ timeout++;
+ }
+
+ /* check if status wait successful or timeout */
+ if (I2C_TIMEOUT != timeout)
+ {
+ IsFree = TRUE;
+ }
+ else
+ {
+ FT_I2C_ERROR("wait status 0x%x failed!!! reg val is 0x%x",
+ stMask, FI2C_GET_STATUS(pDev));
+ }
+
+ return IsFree;
+}
+
+u32 FI2C_writeByByte(FT_IN u32 len, FT_IN u8 *pI2cBuf, FT_IN u8 PageAddr, FT_INOUT FI2C_t *pDev)
+{
+ u32 loop;
+ bool_t isNotTimeout;
+ u32 ret = ERR_I2C_OK;
+ Ft_assertNoneReturn((NULL != pDev) && (NULL != pI2cBuf));
+
+ if (!pDev->IsReady)
+ {
+ return ERR_I2C_NOT_READY;
+ }
+
+ if (pDev->Config.BlockSize <= len)
+ {
+ return ERR_I2C_SIZE_TOO_LARGE;
+ }
+
+ FI2C_DISABLE_I2C_BUS(pDev);
+ FI2C_sendRestartCmd(pDev->Config.BaseAddress);
+ FI2C_setTarAddr(pDev->Config.BaseAddress, pDev->SlaveAddr);
+ FI2C_ENABLE_I2C_BUS(pDev);
+
+ FI2C_sendWriteCmd(pDev->Config.BaseAddress, PageAddr);
+
+ for (loop = 0; loop < len; loop++)
+ {
+ if (!pDev->Config.IsPolling)
+ {
+ FI2C_setIrq(pDev, I2C_IRQ_TX_EMPTY, TRUE);
+ }
+ pDev->DelayHandle(2);
+ FI2C_SET_TX_DATA(pDev, pI2cBuf[loop]);
+
+ /* wait until TX fifo is empty */
+ if (pDev->Config.IsPolling)
+ {
+ isNotTimeout = FI2C_blockWaitForStatus(I2C_STATUS_TFE, pDev);
+ if (!isNotTimeout)
+ {
+ ret = ERR_I2C_WRITE_TIMEOUT;
+ goto EXIT;
+ }
+ }
+ else
+ {
+ pDev->LastIrqErr = ERR_I2C_OK;
+ if (pDev->pWaitCallBack)
+ {
+ pDev->pWaitCallBack(I2C_IRQ_TYPE_TX_COMPLETE, pDev);
+ }
+ else
+ {
+ ret = ERR_I2C_INVALID_HANDLER;
+ goto EXIT;
+ }
+
+ if (ERR_I2C_OK != pDev->LastIrqErr)
+ {
+ ret = pDev->LastIrqErr;
+ goto EXIT;
+ }
+ }
+
+ pDev->DelayHandle(2);
+ }
+
+EXIT:
+ FI2C_SEND_TX_STOP_CMD(pDev);
+ pDev->DelayHandle(2);
+
+ return ret;
+}
+
+u32 FI2C_readByByte(FT_IN u32 len, FT_OUT u8 *pI2cBuf, FT_IN u8 PageAddr, FT_INOUT FI2C_t *pDev)
+{
+ u32 loop;
+ bool_t isNotTimeout;
+ u32 ret = ERR_I2C_OK;
+ Ft_assertNoneReturn((NULL != pDev) && (NULL != pI2cBuf));
+
+ if (!pDev->IsReady)
+ {
+ return ERR_I2C_NOT_READY;
+ }
+
+ FI2C_DISABLE_I2C_BUS(pDev);
+ FI2C_sendRestartCmd(pDev->Config.BaseAddress);
+ FI2C_CLR_ALL_IRQ_STATUS(pDev);
+ FI2C_setTarAddr(pDev->Config.BaseAddress, pDev->SlaveAddr);
+ FI2C_ENABLE_I2C_BUS(pDev);
+
+ /* assign page addr when start read */
+ FI2C_sendStartReadCmd(pDev->Config.BaseAddress, PageAddr);
+
+ /* read contents */
+ for (loop = 0; loop < len; loop++)
+ {
+ if (!pDev->Config.IsPolling)
+ {
+ FI2C_setIrq(pDev, I2C_IRQ_RX_FULL, TRUE);
+ }
+
+ FI2C_SEND_RX_NEXT_CMD(pDev);
+ pDev->DelayHandle(2);
+
+ /* wait until data reach and start fetch data */
+ if (pDev->Config.IsPolling)
+ {
+ isNotTimeout = FI2C_blockWaitForStatus(I2C_STATUS_RFNE, pDev);
+ if (!isNotTimeout)
+ {
+ ret = ERR_I2C_READ_TIMEOUT;
+ goto EXIT;
+ }
+ }
+ else
+ {
+ pDev->LastIrqErr = ERR_I2C_OK;
+ if (pDev->pWaitCallBack)
+ {
+ pDev->pWaitCallBack(I2C_IRQ_TYPE_RX_COMPLETE, pDev);
+ }
+ else
+ {
+ ret = ERR_I2C_INVALID_HANDLER;
+ goto EXIT;
+ }
+
+ if (ERR_I2C_OK != pDev->LastIrqErr)
+ {
+ ret = pDev->LastIrqErr;
+ goto EXIT;
+ }
+ }
+
+ pI2cBuf[loop] = FI2C_GET_RX_DATA(pDev);
+ pDev->DelayHandle(2);
+ }
+
+EXIT:
+ FI2C_SEND_RX_STOP_CMD(pDev);
+ pDev->DelayHandle(2);
+ return ret;
+}
+
+u32 FI2C_writeByFifo(FT_IN u8 PageAddr, FT_INOUT FI2C_t *pDev)
+{
+ u32 loop;
+ u32 ret = ERR_I2C_OK;
+ u32 timeout = I2C_TIMEOUT / 10;
+ Ft_assertNoneReturn(NULL != pDev);
+
+ if (!pDev->IsReady)
+ {
+ return ERR_I2C_NOT_READY;
+ }
+
+ if (pDev->Config.IsPolling)
+ {
+ return ERR_I2C_NOT_SUPPORT;
+ }
+
+ FI2C_DISABLE_I2C_BUS(pDev);
+ FI2C_sendRestartCmd(pDev->Config.BaseAddress);
+ FI2C_setTarAddr(pDev->Config.BaseAddress, pDev->SlaveAddr);
+ FI2C_ENABLE_I2C_BUS(pDev);
+
+ FI2C_sendWriteCmd(pDev->Config.BaseAddress, PageAddr);
+
+ /* enable TX Empty, disable Rx Full */
+ FI2C_setIrq(pDev, I2C_IRQ_TX_EMPTY, TRUE);
+ FI2C_setIrq(pDev, I2C_IRQ_RX_FULL, FALSE);
+
+ pDev->LastIrqErr = ERR_I2C_OK;
+ if (pDev->pWaitCallBack)
+ {
+ pDev->pWaitCallBack(I2C_IRQ_TYPE_TX_COMPLETE, pDev);
+ }
+ else
+ {
+ ret = ERR_I2C_INVALID_HANDLER;
+ }
+
+ if (ERR_I2C_OK != pDev->LastIrqErr)
+ {
+ ret = pDev->LastIrqErr;
+ }
+
+ return ret;
+}
+
+u32 FI2C_readByFifo(FT_IN u8 PageAddr, FT_INOUT FI2C_t *pDev)
+{
+ u32 loop;
+ u32 ret = ERR_I2C_OK;
+ u32 timeout = I2C_TIMEOUT / 10;
+ Ft_assertNoneReturn((NULL != pDev));
+
+ if (!pDev->IsReady)
+ {
+ return ERR_I2C_NOT_READY;
+ }
+
+ if (pDev->Config.IsPolling)
+ {
+ return ERR_I2C_NOT_SUPPORT;
+ }
+
+ FI2C_DISABLE_I2C_BUS(pDev);
+ FI2C_sendRestartCmd(pDev->Config.BaseAddress);
+ FI2C_setTarAddr(pDev->Config.BaseAddress, pDev->SlaveAddr);
+ FI2C_ENABLE_I2C_BUS(pDev);
+
+ /* assign page addr when start read */
+ FI2C_sendStartReadCmd(pDev->Config.BaseAddress, PageAddr);
+
+ FI2C_setIrq(pDev, I2C_IRQ_RX_FULL, TRUE);
+ FI2C_setIrq(pDev, I2C_IRQ_TX_EMPTY, FALSE);
+ FI2C_SET_RX_TL(pDev, 1);
+
+ pDev->DelayHandle(2);
+ FT_I2C_DEBUG_I("rx tl is 0x%x irq mask 0x%x",
+ FI2C_GET_RX_TL(pDev),
+ FI2C_getIrqMask(pDev));
+
+ FI2C_SEND_RX_NEXT_CMD(pDev);
+ pDev->DelayHandle(2);
+
+ pDev->LastIrqErr = ERR_I2C_OK;
+ if (pDev->pWaitCallBack)
+ {
+ pDev->pWaitCallBack(I2C_IRQ_TYPE_RX_COMPLETE, pDev);
+ }
+ else
+ {
+ ret = ERR_I2C_INVALID_HANDLER;
+ }
+
+ if (ERR_I2C_OK != pDev->LastIrqErr)
+ {
+ ret = pDev->LastIrqErr;
+ }
+ FI2C_SET_RX_TL(pDev, 0);
+ return ret;
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_i2c/ft_i2c.h b/bsp/ft2004/libraries/bsp/ft_i2c/ft_i2c.h
new file mode 100644
index 0000000000..20bab542b7
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_i2c/ft_i2c.h
@@ -0,0 +1,197 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-04-07 13:32:20
+ * @Description:  This files is for i2c user interface
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef FT_BSP_I2C_H
+#define FT_BSP_I2C_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "ft_types.h"
+#include "ft_debug.h"
+#include "ft_assert.h"
+#include "ft_error_code.h"
+#include "ft_i2c_hw.h"
+
+ /* I2C Ctrl instance */
+ typedef enum
+ {
+ I2C_CTRL_ID_0 = 0,
+ I2C_CTRL_ID_1,
+ I2C_CTRL_ID_2,
+ I2C_CTRL_ID_3,
+
+ MAX_I2C_CTRL_ID,
+ } FI2C_Instance_t;
+
+ static const u32 g_FI2cIrqNum[MAX_I2C_CTRL_ID] = {
+ 44, 45, 46, 47};
+
+ static const u32 g_FI2cRegBaseAddr[MAX_I2C_CTRL_ID] = {
+ I2C0_BASE_ADDRESS, I2C1_BASE_ADDRESS,
+ I2C2_BASE_ADDRESS, I2C3_BASE_ADDRESS};
+
+#define I2C_DEFAULT_IRQ_PRIORITY 0
+
+ /* Type of I2C device */
+ typedef enum
+ {
+ I2C_MASTER_DEV = 0,
+ I2C_SLAVE_DEV,
+
+ MAX_I2C_DEV
+ } FI2C_DevType_t;
+
+ /* I2C work mode type */
+ typedef enum
+ {
+ I2C_POLLING_MODE = 0,
+ I2C_IRQ_MODE,
+
+ MAX_I2C_WORKMODE
+ } FI2C_WorkMode_t;
+
+ /* Type of I2C bus speed */
+ typedef enum
+ {
+ I2C_STANDARD_SPEED = 0,
+ I2C_FAST_SPEED,
+ I2C_HIGH_SPEED,
+
+ MAX_I2C_SPEED,
+ } FI2C_SpeedType_t;
+
+ /* I2C error code Submodule */
+ typedef enum
+ {
+ I2C_ERR_MODE_DEF = 0,
+
+ MAX_I2C_ERR_MODE,
+ } FI2C_Submodule_t;
+
+ /* I2C irq type */
+ typedef enum
+ {
+ I2C_IRQ_TYPE_NONE = 0,
+ I2C_IRQ_TYPE_TX_COMPLETE,
+ I2C_IRQ_TYPE_RX_COMPLETE,
+
+ MAX_I2C_IRQ_TYPE
+ } FI2C_IrqType_t;
+
+ /* I2C config info */
+ typedef struct
+ {
+ FI2C_Instance_t InstanceId; /* Id of I2C ctrl instance */
+ u32 BaseAddress; /* base address of I2C register */
+ FI2C_DevType_t WorkMode; /* work as master or slave */
+ FI2C_SpeedType_t BusSpeed; /* bus speed setting */
+ u32 SclLcnt;
+ u32 SclHcnt;
+ u32 RxThres;
+ u32 TxThres;
+ bool_t Is7BitAddr; /* TRUE: use 7 bit addr, FALSE: use 10 bit addr */
+ bool_t IsPolling; /* is polling */
+ u32 IrqNum; /* irq num of I2C in system */
+ u32 IrqPriority; /* irq priority */
+ u32 BlockSize; /* block size, for eeprom */
+ bool_t WRByFifo;
+ } FI2C_Config_t;
+
+ /* I2C RX/TX buffer */
+ typedef struct
+ {
+ u8 *BytePtr;
+ u32 TotalBytes;
+ u32 DataLength;
+ u32 CurIndex;
+ } FI2C_Buffer_t;
+
+ typedef void (*FI2C_IrqCallBackHandler_t)(FT_IN u32 IrqType,
+ FT_INOUT void *pDev,
+ FT_INOUT void *pArg);
+ typedef void (*FI2C_IrqWaitHandler_t)(FT_IN u32 IrqType,
+ FT_INOUT void *pDev);
+ typedef int32_t (*FI2C_DelayHandler_t)(FT_IN u32);
+
+ /* I2C device info */
+ typedef struct
+ {
+ FI2C_Config_t Config; /* Configuration data structure */
+
+ void *pRxEvent;
+ void *pTxEvent;
+ FI2C_IrqCallBackHandler_t pIrqCallBack;
+ FI2C_IrqWaitHandler_t pWaitCallBack;
+ u32 LastIrqErr;
+ FI2C_Buffer_t RxBuf;
+ FI2C_Buffer_t TxBuf;
+
+ FI2C_DelayHandler_t DelayHandle;
+ bool_t IsReady; /* Device is ininitialized and ready*/
+ u16 SlaveAddr; /* address of I2C slave device for master */
+ } FI2C_t;
+
+ void FI2C_initMaster(FT_IN FI2C_Instance_t id,
+ FT_IN FI2C_WorkMode_t mode,
+ FT_IN u32 SlaveAddr,
+ FT_IN bool_t UseWRFifo,
+ FT_IN u32 PageSize,
+ FT_INOUT FI2C_t *pDev);
+ u32 FI2C_writeByByte(FT_IN u32 len, FT_IN u8 *pI2cBuf, FT_IN u8 PageAddr,
+ FT_INOUT FI2C_t *pDev);
+ u32 FI2C_readByByte(FT_IN u32 len, FT_OUT u8 *pI2cBuf, FT_IN u8 PageAddr,
+ FT_INOUT FI2C_t *pDev);
+ u32 FI2C_setIrqHandler(FT_IN FI2C_IrqType_t IrqType, FT_IN FI2C_DelayHandler_t pHandler, FT_IN void *pArgs,
+ FT_INOUT FI2C_t *pDev);
+ void FI2C_irqHandler(void *pArgs);
+ void FI2C_irqHandler4Fifo(void *pArgs);
+ u32 FI2C_getIrqMask(FT_IN FI2C_t *pDev);
+ void FI2C_setIrqMask(FT_IN FI2C_t *pDev, FT_IN u32 mask);
+ void FI2C_setIrq(FT_IN FI2C_t *pDev, FT_IN u32 maskBit, FT_IN bool_t enable);
+ bool_t FI2C_checkIfIntr(FT_IN FI2C_t *pDev);
+ u32 FI2C_writeByFifo(FT_IN u8 PageAddr, FT_INOUT FI2C_t *pDev);
+ u32 FI2C_readByFifo(FT_IN u8 PageAddr, FT_INOUT FI2C_t *pDev);
+ void FI2C_deInitMaster(FT_INOUT FI2C_t *pDev);
+
+#define FT_I2C_DEBUG_TAG "FT_I2C"
+//#define FT_I2C_ENABLE_DEBUG
+#define FT_I2C_ERROR(format, ...) FT_DEBUG_PRINT_E(FT_I2C_DEBUG_TAG, format, ##__VA_ARGS__)
+#ifdef FT_I2C_ENABLE_DEBUG
+#define FT_I2C_DEBUG_I(format, ...) FT_DEBUG_PRINT_I(FT_I2C_DEBUG_TAG, format, ##__VA_ARGS__)
+#define FT_I2C_DEBUG_W(format, ...) FT_DEBUG_PRINT_W(FT_I2C_DEBUG_TAG, format, ##__VA_ARGS__)
+#else
+#define FT_I2C_DEBUG_I(format, ...)
+#define FT_I2C_DEBUG_W(format, ...)
+#endif
+
+#define ERR_I2C_OK ERR_SUCCESS
+#define ERR_I2C_NOT_READY FT_CODE_ERR(errModeI2c, I2C_ERR_MODE_DEF, 1)
+#define ERR_I2C_WRITE_TIMEOUT FT_CODE_ERR(errModeI2c, I2C_ERR_MODE_DEF, 2)
+#define ERR_I2C_READ_TIMEOUT FT_CODE_ERR(errModeI2c, I2C_ERR_MODE_DEF, 3)
+#define ERR_I2C_SIZE_TOO_LARGE FT_CODE_ERR(errModeI2c, I2C_ERR_MODE_DEF, 4)
+#define ERR_I2C_NOT_SUPPORT FT_CODE_ERR(errModeI2c, I2C_ERR_MODE_DEF, 5)
+#define ERR_I2C_INVALID_PARAM FT_CODE_ERR(errModeI2c, I2C_ERR_MODE_DEF, 6)
+#define ERR_I2C_INVALID_HANDLER FT_CODE_ERR(errModeI2c, I2C_ERR_MODE_DEF, 7)
+#define ERR_I2C_INVALID_NO_MEM FT_CODE_ERR(errModeI2c, I2C_ERR_MODE_DEF, 8)
+#define ERR_I2C_BUS_NOT_ENABLED FT_CODE_ERR(errModeI2c, I2C_ERR_MODE_DEF, 9)
+#define ERR_I2C_EVT_TIMEOUT FT_CODE_ERR(errModeI2c, I2C_ERR_MODE_DEF, 0xA)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/bsp/ft2004/libraries/bsp/ft_i2c/ft_i2c_g.c b/bsp/ft2004/libraries/bsp/ft_i2c/ft_i2c_g.c
new file mode 100644
index 0000000000..3d9bd40994
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_i2c/ft_i2c_g.c
@@ -0,0 +1,13 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-20 15:35:23
+ * @LastEditTime: 2021-04-20 15:35:24
+ * @Description:  This files is for
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
diff --git a/bsp/ft2004/libraries/bsp/ft_i2c/ft_i2c_hw.h b/bsp/ft2004/libraries/bsp/ft_i2c/ft_i2c_hw.h
new file mode 100644
index 0000000000..53f7de7bfe
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_i2c/ft_i2c_hw.h
@@ -0,0 +1,321 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-04-07 13:26:58
+ * @Description:  This files is for i2c register definition
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef FT_BSP_I2C_HW_H
+#define FT_BSP_I2C_HW_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "ft_types.h"
+#include "ft_io.h"
+
+/* i2c 1~4 reg base address */
+#define I2C0_BASE_ADDRESS 0x28006000U
+#define I2C1_BASE_ADDRESS 0x28007000U
+#define I2C2_BASE_ADDRESS 0x28008000U
+#define I2C3_BASE_ADDRESS 0x28009000U
+
+/* defines */
+#define I2C_TIMEOUT 5000
+
+#define I2C_MAX_READ_SIZE 1
+#define SEM_TIMEOUT 2
+
+ /* Register Definition */
+
+#define I2C_CON 0x00
+#define I2C_TAR 0x04
+#define I2C_SAR 0x08
+#define I2C_HS_MADDR 0x0C
+#define I2C_DATA_CMD 0x10
+#define I2C_SS_SCL_HCNT 0x14
+#define I2C_SS_SCL_LCNT 0x18
+#define I2C_FS_SCL_HCNT 0x1C
+#define I2C_FS_SCL_LCNT 0x20
+#define I2C_HS_SCL_HCNT 0x24
+#define I2C_HS_SCL_LCNT 0x28
+#define I2C_INTR_STAT 0x2C
+#define I2C_INTR_MASK 0x30
+#define I2C_RAW_INTR_STAT 0x34
+#define I2C_RX_TL 0x38
+#define I2C_TX_TL 0x3C
+#define I2C_CLR_INTR 0x40
+#define I2C_CLR_RX_UNDER 0x44
+#define I2C_CLR_RX_OVER 0x48
+#define I2C_CLR_TX_OVER 0x4C
+#define I2C_CLR_RD_REQ 0x50
+#define I2C_CLR_TX_ABRT 0x54
+#define I2C_CLR_RX_DONE 0x58
+#define I2C_CLR_ACTIVITY 0x5c
+#define I2C_CLR_STOP_DET 0x60
+#define I2C_CLR_START_DET 0x64
+#define I2C_CLR_GEN_CALL 0x68
+#define I2C_ENABLE 0x6C
+#define I2C_STATUS 0x70
+#define I2C_TXFLR 0x74
+#define I2C_RXFLR 0x78
+#define I2C_TX_ABRT_SOURCE 0x80
+#define I2C_SLV_DATA_NACK_ONLY 0x84
+#define I2C_DMA_CR 0x88
+#define I2C_DMA_TDLR 0x8c
+#define I2C_DMA_RDLR 0x90
+#define I2C_SDA_SETUP 0x94
+#define I2C_ACK_GENERAL_CALL 0x98
+#define I2C_ENABLE_STATUS 0x9C
+#define I2C_COMP_PARAM_1 0xf4
+#define I2C_COMP_VERSION 0xf8
+#define I2C_COMP_TYPE 0xfc
+
+#define I2C_RAW_INTR_STAT_RX_UNDER 0x1
+#define I2C_RAW_INTR_STAT_RX_OVER 0x2
+#define I2C_RAW_INTR_STAT_RX_FULL 0x4
+#define I2C_RAW_INTR_STAT_TX_OVER 0x8
+#define I2C_RAW_INTR_STAT_TX_EMPTY 0x10
+
+ /* Default parameters */
+
+#define I2C_CON_ME (0x1 << 0)
+#define I2C_CON_MS_SS (0x1 << 1)
+#define I2C_CON_MS_FS (0x2 << 1)
+#define I2C_CON_MS_HS (0x3 << 1)
+#define I2C_CON_SLAVE_ADR_7BIT (0x0 << 3)
+#define I2C_CON_SLAVE_ADR_10BIT (0x1 << 3)
+#define I2C_CON_MASTER_ADR_7BIT (0x0 << 4)
+#define I2C_CON_MASTER_ADR_10BIT (0x1 << 4)
+#define I2C_CON_RESTART_EN (0x1 << 5)
+#define I2C_CON_SLAVE_DISABLE (0x1 << 6)
+
+/* 0110 0011 0x63 */
+#define I2C_CON_DEFAULT_MASTER (I2C_CON_ME | I2C_CON_MS_FS /*I2C_CON_MS_SS*/ /* | I2C_CON_RESTART_EN*/ | \
+ I2C_CON_SLAVE_ADR_7BIT | I2C_CON_SLAVE_DISABLE)
+#define I2C_CTR_DEFAULT (I2C_CON_ME | I2C_CON_MASTER_ADR_7BIT | \
+ I2C_CON_SLAVE_DISABLE)
+
+#define I2C_IRQ_NONE_MASK 0x0
+#define I2C_IRQ_ALL_MASK 0x8ff
+
+#define I2C_TAR_STARTBYTE (0x1 << 10)
+#define I2C_TAR_SPECIAL_STARTBYTE (0x1 << 11)
+#define I2C_TAR_ADR_7BIT (0x0 << 12)
+#define I2C_TAR_ADR_10BIT (0x1 << 12)
+#define I2C_TAR_ADR_MASK 0x3ff /* bit [9: 0] */
+
+#define I2C_SLAVE_DISABLE_DEFAULT 0
+#define I2C_RESTART_EN_DEFAULT 1
+#define I2C_10BITADDR_MASTER_DEFAULT 0
+#define I2C_10BITADDR_SLAVE_DEFAULT 1
+#define I2C_MAX_SPEED_MODE_DEFAULT 3
+#define I2C_MASTER_MODE_DEFAULT 1
+
+#define I2C_STANDARD_SPEED_MASK (0x01 << 1)
+#define I2C_FAST_SPEED_MASK (0x02 << 1)
+#define I2C_HIGH_SPEED_MASK (0x03 << 1)
+
+#define I2C_DEFAULT_TAR_ADDR_DEFAULT 0x055
+#define I2C_DEFAULT_SLAVE_ADDR_DEFAULT 0x055
+#define I2C_COMP_VERSION_DEFAULT 0x3131352A
+
+#define I2C_HS_MASTER_CODE_DEFAULT 1
+#define I2C_SS_SCL_HIGH_COUNT_DEFAULT 0x0190
+#define I2C_SS_SCL_LOW_COUNT_DEFAULT 0x01d6
+#define I2C_FS_SCL_HIGH_COUNT_DEFAULT 0x003c
+#define I2C_FS_SCL_LOW_COUNT_DEFAULT 0x0082
+#define I2C_HS_SCL_HIGH_COUNT_DEFAULT 0x006
+#define I2C_HS_SCL_LOW_COUNT_DEFAULT 0x0010
+#define I2C_RX_TL_DEFAULT 0
+#define I2C_TX_TL_DEFAULT 0
+#define I2C_DEFAULT_SDA_SETUP_DEFAULT 0x64
+#define I2C_DEFAULT_ACK_GENERAL_CALL_DEFAULT 1
+#define I2C_DYNAMI2C_TAR_UPDATE_DEFAULT 1
+#define I2C_RX_BUFFER_DEPTH_DEFAULT 8
+#define I2C_TX_BUFFER_DEPTH_DEFAULT 8
+#define I2C_ADD_ENCODED_PARAMS_DEFAULT 1
+#define I2C_HAS_DMA_DEFAULT 0
+#define I2C_INTR_IO_DEFAULT 0
+#define I2C_HC_COUNT_VALUES_DEFAULT 0
+#define APB_DATA_WIDTH_DEFAULT 0
+#define I2C_SLV_DATA_NACK_ONLY_DEFAULT 0
+#define I2C_USE_COUNTS_DEFAULT 0
+#define I2C_CLK_TYPE_DEFAULT 1
+#define I2C_CLOCK_PERIOD_DEFAULT 10
+
+ /* Raw Interrupt Status */
+
+#define I2C_IRQ_NONE (0x0)
+#define I2C_IRQ_RX_UNDER (0x01 << 0)
+#define I2C_IRQ_RX_OVER (0x01 << 1)
+#define I2C_IRQ_RX_FULL (0x01 << 2)
+#define I2C_IRQ_TX_OVER (0x01 << 3)
+#define I2C_IRQ_TX_EMPTY (0x01 << 4)
+#define I2C_IRQ_RD_REQ (0x01 << 5)
+#define I2C_IRQ_TX_ABRT (0x01 << 6)
+#define I2C_IRQ_RX_DONE (0x01 << 7)
+#define I2C_IRQ_ACTIVITY (0x01 << 8)
+#define I2C_IRQ_STOP_DET (0x01 << 9)
+#define I2C_IRQ_START_DET (0x01 << 10)
+#define I2C_IRQ_GEN_CALL (0x01 << 11)
+#define I2C_IRQ_ALL 0xFFF
+
+ /* Default IRQ Mask Bit Setting */
+
+#define I2C_IRQ_DEFAULT_MASK (I2C_IRQ_RX_FULL | I2C_IRQ_TX_EMPTY | \
+ I2C_IRQ_TX_ABRT | I2C_IRQ_STOP_DET | \
+ I2C_IRQ_START_DET)
+
+ /* Data command stop bit */
+
+#define I2C_DATA_CMD_WR_STOP_BIT (0x02 << 8) /* bit 8=0:W, bit 9=1: stop */
+#define I2C_DATA_CMD_RD_STOP_BIT (0x03 << 8) /* bit 8=1:R, bit 9=1: stop */
+#define I2C_DATA_CMD_DAT_MASK 0xff /* bit [7:0] , TX and RX data */
+#define I2C_DATA_CMD_WR (0x00 << 8)
+#define I2C_DATA_CMD_RD (0x01 << 8)
+#define I2C_DATA_CMD_STOP (0x01 << 9)
+#define I2C_DATA_CMD_RESTART (0X01 << 10)
+
+ /* I2C TX Abort Source*/
+
+#define I2C_ABRT_7B_ADDR_NOACK 0x001
+#define I2C_ABRT_10_ADDR1_NOACK 0x002
+#define I2C_ABRT_10_ADDR2_NOACK 0x004
+#define I2C_ABRT_TXDATA_NOACK 0x008
+#define I2C_ABRT_GCALL_NOACK 0x010
+#define I2C_ABRT_GCALL_READ 0x020
+#define I2C_ABRT_HS_ACKDET 0x040
+#define I2C_ABRT_SBYTE_ACKDET 0x080
+#define I2C_ABRT_HS_NORSTRT 0x100
+#define I2C_ABRT_SBYTE_NORSTRT 0x200
+#define I2C_ABRT_10B_RD_NORSTRT 0x400
+#define I2C_ABRT_MASTER_DIS 0x800
+#define I2C_ABRT_ARB_LOST 0x1000
+#define I2C_ABRT_SLVFLUSH_TXFIFO 0x2000
+#define I2C_ABRT_SLV_ARBLOST 0x5000
+#define I2C_ABRT_SLVRD_INTX 0x8000
+
+ /* Minimum High and Low period in nanosecends */
+
+#define SS_MIN_SCL_HIGH 4000
+#define SS_MIN_SCL_LOW 4700
+#define FS_MIN_SCL_HIGH 600
+#define FS_MIN_SCL_LOW 1300
+#define HS_MIN_SCL_HIGH_100PF 60
+#define HS_MIN_SCL_LOW_100PF 120
+
+ /* I2C_STATUS (RO) */
+
+#define I2C_STATUS_ACTIVITY (0x1 << 0) /* I2C ctrl is enabled */
+#define I2C_STATUS_TFNF (0x1 << 1) /* TX FIFO is not full */
+#define I2C_STATUS_TFE (0x1 << 2) /* TX FIFO is empty */
+#define I2C_STATUS_RFNE (0x1 << 3) /* RX FIFO is not empty */
+#define I2C_STATUS_RFF (0x1 << 4) /* RX FIFO is full */
+#define I2C_STATUS_MST_ACTIVITY (0x1 << 5) /* Master is not idle */
+#define I2C_STATUS_SLV_ACTIVITY (0x1 << 6) /* Slave is not idle */
+
+ /* Interrupts status */
+
+#define I2C_INTR_RX_UNDER (0x1 << 0)
+#define I2C_INTR_RX_OVER (0x1 << 1)
+#define I2C_INTR_RX_FULL (0x1 << 2)
+#define I2C_INTR_TX_OVER (0x1 << 3)
+#define I2C_INTR_TX_EMPTY (0x1 << 4)
+#define I2C_INTR_RD_REQ (0x1 << 5)
+#define I2C_INTR_TX_ABRT (0x1 << 6)
+#define I2C_INTR_RX_DONE (0x1 << 7)
+#define I2C_INTR_ACTIVITY (0x1 << 8)
+#define I2C_INTR_STOP_DET (0x1 << 9)
+#define I2C_INTR_START_DET (0x1 << 10)
+#define I2C_INTR_GEN_CALL (0x1 << 11)
+
+#define I2C_TX_BUFFER_DEPTH_MASK 0xFF0000 /* bit [23: 16] */
+#define I2C_RX_BUFFER_DEPTH_MASK 0x00FF00 /* bit [15: 8] */
+
+#define I2C_INTR_MAX_BITS 12
+
+#define I2C_ENABLE_CONTROLLER 0x01
+#define I2C_DISABLE_CONTROLLER 0x00
+
+#define I2C_DATA_CMD_READ (0x01 << 8)
+#define I2C_DATA_CMD_WRITE (0x00 << 8)
+
+#define I2C_TAR_DEFAULT_ADDR 0x55
+#define FT2000_I2C_CLK (48000000) /* I2C clock */
+/**
+ * @name: FI2c_WriteReg
+ * @msg: write i2c register
+ * @param {u32} BaseAddress base addr of i2c
+ * @param {u32} RegOffset addr offset of i2c register
+ * @param {u32} RegisterValue val to be write into register
+ * @return {void}
+ */
+#define FI2C_WriteReg(BaseAddress, RegOffset, RegisterValue) Ft_out32(BaseAddress + (u32)RegOffset, (u32)RegisterValue)
+
+/**
+ * @name: FI2c_ReadReg
+ * @msg: read i2c register
+ * @param {u32} BaseAddress base addr of i2c
+ * @param {u32} RegOffset addr offset of i2c register
+ * @return {u32} val read from register
+ */
+#define FI2C_ReadReg(BaseAddress, RegOffset) Ft_in32(BaseAddress + (u32)RegOffset)
+
+ /*
+* the following macros convert from BCD to binary and back.
+* Be careful that the arguments are chars, only char width returned.
+*/
+
+#define BCD_TO_BIN(bcd) ((((((bcd)&0xf0) >> 4) * 10) + ((bcd)&0xf)) & 0xff)
+#define BIN_TO_BCD(bin) (((((bin) / 10) << 4) + ((bin) % 10)) & 0xff)
+
+#define FI2C_GET_BASE_ADDR(pDev) ((pDev)->Config.BaseAddress)
+#define FI2C_ENABLE_I2C_BUS(pDev) (FI2C_WriteReg(FI2C_GET_BASE_ADDR(pDev), I2C_ENABLE, I2C_ENABLE_CONTROLLER))
+#define FI2C_DISABLE_I2C_BUS(pDev) (FI2C_WriteReg(FI2C_GET_BASE_ADDR(pDev), I2C_ENABLE, I2C_DISABLE_CONTROLLER))
+#define FI2C_IS_I2C_BUS_ENABLED(pDev) (FI2C_ReadReg(FI2C_GET_BASE_ADDR(pDev), I2C_ENABLE))
+
+#define FI2C_GET_STATUS(pDev) (FI2C_ReadReg(FI2C_GET_BASE_ADDR(pDev), I2C_STATUS))
+#define FI2C_CHECK_STATUS(pDev, stMask) (FI2C_GET_STATUS(pDev) & (stMask))
+#define FI2C_CLR_ALL_IRQ_STATUS(pDev) (FI2C_ReadReg(FI2C_GET_BASE_ADDR(pDev), I2C_CLR_INTR))
+#define FI2C_GET_IRQ_STATUS(pDev) (FI2C_ReadReg(FI2C_GET_BASE_ADDR(pDev), I2C_INTR_STAT))
+#define FI2C_GET_IRQ_MASK(pDev) (FI2C_ReadReg(FI2C_GET_BASE_ADDR(pDev), I2C_INTR_MASK))
+#define FI2C_SET_IRQ_MASK(pDev, mask) (FI2C_WriteReg(FI2C_GET_BASE_ADDR(pDev), I2C_INTR_MASK, (mask)))
+
+#define FI2C_GET_TX_TL(pDev) (FI2C_ReadReg(FI2C_GET_BASE_ADDR(pDev), I2C_TX_TL))
+#define FI2C_GET_RX_TL(pDev) (FI2C_ReadReg(FI2C_GET_BASE_ADDR(pDev), I2C_RX_TL))
+#define FI2C_SET_TX_TL(pDev, TxThres) (FI2C_WriteReg(FI2C_GET_BASE_ADDR(pDev), I2C_TX_TL, (TxThres)))
+#define FI2C_SET_RX_TL(pDev, RxThres) (FI2C_WriteReg(FI2C_GET_BASE_ADDR(pDev), I2C_RX_TL, (RxThres)))
+
+#define FI2C_GET_TXFLR(pDev) (FI2C_ReadReg(FI2C_GET_BASE_ADDR(pDev), I2C_TXFLR))
+#define FI2C_GET_RXFLR(pDev) (FI2C_ReadReg(FI2C_GET_BASE_ADDR(pDev), I2C_RXFLR))
+
+#define FI2C_CLR_IRQ_RX_OVER(pDev) (FI2C_ReadReg(FI2C_GET_BASE_ADDR(pDev), I2C_CLR_RX_OVER))
+#define FI2C_CLR_IRQ_TX_OVER(pDev) (FI2C_ReadReg(FI2C_GET_BASE_ADDR(pDev), I2C_CLR_TX_OVER))
+
+#define FI2C_GET_COMP_PARAM_1(pDev) (FI2C_ReadReg(FI2C_GET_BASE_ADDR(pDev), I2C_COMP_PARAM_1))
+#define FI2C_GET_TX_BUFFER_DEPTH(pDev) ((I2C_TX_BUFFER_DEPTH_MASK & FI2C_GET_COMP_PARAM_1(pDev)) >> 16)
+#define FI2C_GET_RX_BUFFER_DEPTH(pDev) ((I2C_RX_BUFFER_DEPTH_MASK & FI2C_GET_COMP_PARAM_1(pDev)) >> 8)
+
+#define FI2C_SEND_TX_STOP_CMD(pDev) (FI2C_WriteReg(FI2C_GET_BASE_ADDR(pDev), I2C_DATA_CMD, I2C_DATA_CMD_STOP))
+#define FI2C_SET_TX_DATA(pDev, data) (FI2C_WriteReg(FI2C_GET_BASE_ADDR(pDev), I2C_DATA_CMD, ((u32)(data)&I2C_DATA_CMD_DAT_MASK)))
+#define FI2C_GET_RX_DATA(pDev) (u8)(I2C_DATA_CMD_DAT_MASK & (FI2C_ReadReg(FI2C_GET_BASE_ADDR(pDev), I2C_DATA_CMD)))
+#define FI2C_SEND_RX_NEXT_CMD(pDev) (FI2C_WriteReg(FI2C_GET_BASE_ADDR(pDev), I2C_DATA_CMD, I2C_DATA_CMD_STOP | I2C_DATA_CMD_RESTART | I2C_DATA_CMD_RD))
+#define FI2C_SEND_RX_STOP_CMD(pDev) (FI2C_WriteReg(FI2C_GET_BASE_ADDR(pDev), I2C_DATA_CMD, I2C_DATA_CMD_STOP | I2C_DATA_CMD_RD))
+
+ void FI2C_resetReg(u32 BaseAddr);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/bsp/ft2004/libraries/bsp/ft_i2c/ft_i2c_irq.c b/bsp/ft2004/libraries/bsp/ft_i2c/ft_i2c_irq.c
new file mode 100644
index 0000000000..85b39edf1b
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_i2c/ft_i2c_irq.c
@@ -0,0 +1,182 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-20 15:35:44
+ * @LastEditTime: 2021-05-25 16:44:45
+ * @Description:  This files is for
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_i2c.h"
+
+void FI2C_irqHandler(void *pArgs)
+{
+ FI2C_t *pDev;
+ u32 RegVal;
+ FI2C_IrqType_t IrqType = I2C_IRQ_TYPE_NONE;
+
+ Ft_assertNoneReturn(NULL != pArgs);
+ pDev = (FI2C_t *)pArgs;
+
+ RegVal = FI2C_GET_IRQ_STATUS(pDev);
+ if (I2C_IRQ_RX_FULL & RegVal)
+ {
+ IrqType = I2C_IRQ_TYPE_RX_COMPLETE;
+ }
+ else if (I2C_IRQ_TX_EMPTY & RegVal)
+ {
+ IrqType = I2C_IRQ_TYPE_TX_COMPLETE;
+ }
+
+ if ((NULL != pDev->pIrqCallBack) && (I2C_IRQ_TYPE_NONE != IrqType))
+ {
+ pDev->pIrqCallBack(IrqType, pDev, NULL);
+ }
+
+ if (I2C_IRQ_TYPE_RX_COMPLETE == IrqType)
+ {
+ FI2C_setIrq(pDev, I2C_IRQ_RX_FULL, FALSE);
+ }
+ else if (I2C_IRQ_TYPE_TX_COMPLETE == IrqType)
+ {
+ FI2C_setIrq(pDev, I2C_IRQ_TX_EMPTY, FALSE);
+ }
+
+ FI2C_CLR_ALL_IRQ_STATUS(pDev);
+ return;
+}
+
+void FI2C_irqHandler4Fifo(void *pArgs)
+{
+ FI2C_t *pDev;
+ u32 RegVal;
+ u32 BytesToRx;
+ FI2C_IrqType_t IrqType = I2C_IRQ_TYPE_NONE;
+
+ Ft_assertNoneReturn(NULL != pArgs);
+ pDev = (FI2C_t *)pArgs;
+
+ /* check if i2c controller is enabled */
+ if (!FI2C_IS_I2C_BUS_ENABLED(pDev))
+ {
+ pDev->LastIrqErr = ERR_I2C_BUS_NOT_ENABLED;
+ return;
+ }
+
+ /* check there is no interrupt */
+ if (!FI2C_checkIfIntr(pDev))
+ {
+ pDev->LastIrqErr = ERR_I2C_INVALID_PARAM;
+ return;
+ }
+
+ /* read interrupt status */
+ RegVal = FI2C_GET_IRQ_STATUS(pDev);
+ if (I2C_IRQ_RX_FULL & RegVal)
+ {
+ IrqType = I2C_IRQ_TYPE_RX_COMPLETE;
+ BytesToRx = FI2C_GET_RXFLR(pDev);
+
+ while ((pDev->RxBuf.CurIndex < pDev->RxBuf.DataLength) &&
+ (0 < BytesToRx))
+ {
+ /* read one byte */
+ pDev->RxBuf.BytePtr[pDev->RxBuf.CurIndex] = FI2C_GET_RX_DATA(pDev);
+
+ pDev->RxBuf.CurIndex++;
+ BytesToRx--;
+ pDev->DelayHandle(10);
+
+ /* read next byte */
+ if (pDev->RxBuf.CurIndex != pDev->RxBuf.DataLength)
+ {
+ FI2C_SEND_RX_NEXT_CMD(pDev);
+ }
+ else
+ {
+ FI2C_SEND_RX_STOP_CMD(pDev);
+ pDev->DelayHandle(10);
+ FI2C_setIrq(pDev, I2C_IRQ_RX_FULL, FALSE);
+ }
+ }
+ }
+ else if (I2C_IRQ_TX_EMPTY & RegVal)
+ {
+ IrqType = I2C_IRQ_TYPE_TX_COMPLETE;
+
+ if (pDev->TxBuf.CurIndex == pDev->TxBuf.DataLength)
+ {
+ FI2C_SEND_TX_STOP_CMD(pDev);
+ pDev->DelayHandle(10);
+ FI2C_setIrq(pDev, I2C_IRQ_TX_EMPTY, FALSE);
+ }
+ else
+ {
+ FI2C_SET_TX_DATA(pDev, pDev->TxBuf.BytePtr[pDev->TxBuf.CurIndex]);
+ pDev->TxBuf.CurIndex++;
+ }
+ }
+
+ if ((NULL != pDev->pIrqCallBack) && (I2C_IRQ_TYPE_NONE != IrqType))
+ {
+ pDev->pIrqCallBack(IrqType, pDev, NULL);
+ }
+
+ pDev->LastIrqErr = ERR_I2C_OK;
+ return;
+}
+
+u32 FI2C_getIrqMask(FT_IN FI2C_t *pDev)
+{
+ u32 RegVal;
+ Ft_assertNoneReturn(NULL != pDev);
+
+ RegVal = FI2C_GET_IRQ_MASK(pDev);
+ return RegVal;
+}
+
+void FI2C_setIrqMask(FT_IN FI2C_t *pDev, FT_IN u32 mask)
+{
+ u32 RegVal;
+ Ft_assertNoneReturn(NULL != pDev);
+
+ RegVal = mask & I2C_IRQ_ALL_MASK;
+ FI2C_SET_IRQ_MASK(pDev, RegVal);
+ return;
+}
+
+void FI2C_setIrq(FT_IN FI2C_t *pDev, FT_IN u32 maskBit, FT_IN bool_t enable)
+{
+ Ft_assertNoneReturn(0x0 != maskBit);
+
+ if (TRUE == enable)
+ {
+ FI2C_setIrqMask(pDev, FI2C_getIrqMask(pDev) | maskBit);
+ }
+ else
+ {
+ FI2C_setIrqMask(pDev, FI2C_getIrqMask(pDev) & (~maskBit));
+ }
+ return;
+}
+
+bool_t FI2C_checkIfIntr(FT_IN FI2C_t *pDev)
+{
+ u32 RegVal;
+ Ft_assertNoneReturn(NULL != pDev);
+
+ RegVal = FI2C_ReadReg(FI2C_GET_BASE_ADDR(pDev), I2C_RAW_INTR_STAT);
+ if (0 == (RegVal & (~I2C_IRQ_ACTIVITY)))
+ {
+ return FALSE;
+ }
+ else
+ {
+ return TRUE;
+ }
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_i2c/ft_i2c_selftest.c b/bsp/ft2004/libraries/bsp/ft_i2c/ft_i2c_selftest.c
new file mode 100644
index 0000000000..4a43df0ce4
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_i2c/ft_i2c_selftest.c
@@ -0,0 +1,20 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-04-07 13:27:24
+ * @Description:  This files is for i2c test cases
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include <time.h>
+#include <string.h>
+#include "ft_i2c_hw.h"
+#include "ft_i2c.h"
+#include "ft_status.h"
+#include "ft_printf.h"
diff --git a/bsp/ft2004/libraries/bsp/ft_qspi/ft_qspi.c b/bsp/ft2004/libraries/bsp/ft_qspi/ft_qspi.c
new file mode 100644
index 0000000000..3476e20333
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_qspi/ft_qspi.c
@@ -0,0 +1,585 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-05 22:15:53
+ * @LastEditTime: 2021-05-25 16:45:36
+ * @Description:  Description of file
+ * @Modify History:
+ * * * Ver   Who        Date         Changes
+ * * ----- ------     --------    --------------------------------------
+ * * 1.00 hh 2021.04-06 init
+ */
+
+#include "ft_qspi.h"
+#include "qspi_hw.h"
+#include "ft_io.h"
+#include "ft_assert.h"
+#include "ft_types.h"
+#include "string.h"
+
+#include "ft_debug.h"
+
+#define FTQSPI_DEBUG_TAG "FTQSPI"
+
+#define FTQSPI_DEBUG_I(format, ...) FT_DEBUG_PRINT_I(FTQSPI_DEBUG_TAG, format, ##__VA_ARGS__)
+#define FTQSPI_DEBUG_E(format, ...) FT_DEBUG_PRINT_E(FTQSPI_DEBUG_TAG, format, ##__VA_ARGS__)
+#define FTQSPI_DEBUG_W(format, ...) FT_DEBUG_PRINT_W(FTQSPI_DEBUG_TAG, format, ##__VA_ARGS__)
+
+ft_error_t FQSpi_CfgInitialize(FQSpi_t *pQspi, FQSpi_Config_t *pConfig)
+{
+ Ft_assertNonvoid(pQspi != NULL);
+ Ft_assertNonvoid(pConfig != NULL);
+
+ pQspi->config = *pConfig;
+ pQspi->isReady = FT_COMPONENT_IS_READLY;
+
+ FQSpi_Reset(pQspi);
+
+ return FQSPI_SUCCESS;
+}
+
+/**
+ * @name: FQSpi_MemcpyToReg
+ * @msg: Memory copy To Register
+ * @in param {FQSpi_t} *pQspi
+ * @in param {u8} *buf
+ * @in param {u32} length
+ * @return {ft_error_t}
+ */
+static ft_error_t FQSpi_MemcpyToReg(FQSpi_t *pQspi, FT_IN u8 *buf, u32 length)
+{
+ u32 val = 0;
+ FQSpi_Config_t *pConfig = NULL;
+ Ft_assertNonvoid(pQspi != NULL);
+ Ft_assertNonvoid(pQspi->isReady == FT_COMPONENT_IS_READLY);
+ pConfig = &pQspi->config;
+ if (!buf || (length > 4))
+ {
+ return FQSPI_FAILURE;
+ }
+
+ if (1 == length)
+ {
+ val = buf[0];
+ }
+ else if (2 == length)
+ {
+ val = buf[1];
+ val = (val << 8) + buf[0];
+ }
+ else if (3 == length)
+ {
+ val = buf[2];
+ val = (val << 8) + buf[1];
+ val = (val << 8) + buf[0];
+ }
+ else if (4 == length)
+ {
+ val = buf[3];
+ val = (val << 8) + buf[2];
+ val = (val << 8) + buf[1];
+ val = (val << 8) + buf[0];
+ }
+
+ Ft_out32(pConfig->baseAddress + FT_REG_QSPI_LD_PORT_OFFSET, val);
+ return FQSPI_SUCCESS;
+}
+
+/**
+ * @name: FQSpi_MemcpyFromReg
+ * @msg: Memory copy from Register
+ * @in param {FT_INFQSpi_t} *pQspi
+ * @out param {u8} *buf
+ * @in param {u32} length
+ * @return {*}
+ */
+static ft_error_t FQSpi_MemcpyFromReg(FQSpi_t *pQspi, u8 *buf, u32 length)
+{
+ s32 i;
+ u32 val = 0;
+ FQSpi_Config_t *pConfig = NULL;
+ Ft_assertNonvoid(pQspi != NULL);
+ Ft_assertNonvoid(pQspi->isReady == FT_COMPONENT_IS_READLY);
+ pConfig = &pQspi->config;
+
+ for (i = 0; i < length; i++)
+ {
+ /* code */
+ if (0 == i % 4)
+ {
+ val = Ft_in32(pConfig->baseAddress + FT_REG_QSPI_LD_PORT_OFFSET);
+ }
+ buf[i] = (u8)(val >> (i % 4) * 8) & 0xff;
+ }
+
+ return FQSPI_SUCCESS;
+}
+
+/**
+ * @name: FQSpi_FlashRead
+ * @msg: Reads bytes data from flash addr to buf
+ * @in param pQspi:
+ * @in param cmd: Read the instruction byte of the command
+ * @in param addr: Read the data start character
+ * @out param rxBuf: Read buffer
+ * @in param length: need read length
+ * @return {*}
+ */
+ft_error_t FQSpi_FlashRead(FQSpi_t *pQspi,
+ FT_IN u8 cmd,
+ FT_IN u32 addr,
+ FT_OUT u8 *rxBuf,
+ u32 length)
+{
+ FQSpi_Config_t *pConfig = NULL;
+ FQSpi_RdCfgReg_t rdCfgReg;
+ Ft_assertNonvoid(pQspi != NULL);
+ Ft_assertNonvoid(pQspi->isReady == FT_COMPONENT_IS_READLY);
+ pConfig = &pQspi->config;
+
+ if ((NULL == rxBuf) || (0 == length))
+ {
+ return FQSPI_FAILURE;
+ }
+
+ rdCfgReg.data = 0;
+
+ rdCfgReg.val.rdCmd = cmd;
+ rdCfgReg.val.dBuffer = 1;
+ rdCfgReg.val.rdAddrSel = pConfig->addrMode;
+ rdCfgReg.val.rdSckSel = pConfig->clkDiv;
+ rdCfgReg.val.rdTransfer = pConfig->transMode;
+ Ft_out32(pConfig->baseAddress + FT_REG_QSPI_RD_CFG_OFFSET, rdCfgReg.data);
+
+ memcpy(rxBuf, (char *)(addr), length);
+
+ return FQSPI_SUCCESS;
+}
+
+/**
+ * @name: FQSpi_FlashWrite
+ * @msg: Writes one page into flash,changing bits from 1 to 0
+ * @in param pQspi:
+ * @in param cmd: write the instruction byte of the command
+ * @in param addr: write the data start character
+ * @in param txBuf: write buffer
+ * @in param length: need write length
+ * @return {*}
+ */
+ft_error_t FQSpi_FlashWrite(FQSpi_t *pQspi,
+ FT_IN u8 cmd,
+ FT_IN u32 addr,
+ FT_IN u8 *txBuf,
+ u32 length)
+{
+
+ FQSpi_Config_t *pConfig = NULL;
+ FQSpi_WrCfgReg_t wrCfgReg;
+ u32 index = 0;
+ u32 val = 0;
+ u32 *pu32Buf = NULL;
+ Ft_assertNonvoid(pQspi != NULL);
+ Ft_assertNonvoid(pQspi->isReady == FT_COMPONENT_IS_READLY);
+ pConfig = &pQspi->config;
+
+ if ((NULL == txBuf) || (0 == length))
+ {
+ return FQSPI_FAILURE;
+ }
+
+ pu32Buf = (u32 *)txBuf;
+
+ wrCfgReg.data = 0;
+ wrCfgReg.val.wrCmd = cmd;
+ wrCfgReg.val.wrWait = 1;
+ wrCfgReg.val.wrSckSel = pConfig->clkDiv;
+ wrCfgReg.val.wrAddrsel = pConfig->addrMode;
+ wrCfgReg.val.wrTransfer = pConfig->transMode;
+ wrCfgReg.val.wrMode = 1;
+
+ Ft_out32(pConfig->baseAddress + FT_REG_QSPI_WR_CFG_OFFSET, wrCfgReg.data);
+
+ while (length)
+ {
+ if (length >= 4)
+ {
+ Ft_out32(addr + index, pu32Buf[index / 4]);
+ length -= 4;
+ index += 4;
+ }
+ else
+ {
+ if (1 == length)
+ {
+ val = txBuf[index] | 0xFFFFFF00;
+ }
+ else if (2 == length)
+ {
+ val = txBuf[index] | (txBuf[index + 1] << 8) | 0xFFFF0000;
+ }
+ else
+ {
+ val = txBuf[index] | (txBuf[index + 1] << 8) | (txBuf[index + 2] << 8) | 0xFF000000;
+ }
+
+ Ft_out32(addr + index, val);
+ length = 0;
+ }
+ }
+
+ Ft_out32(pConfig->baseAddress + FT_REG_QSPI_FLUSH_OFFSET, 1);
+ return FQSPI_SUCCESS;
+}
+
+/**
+ * @name: FQSpi_FlashRegSet
+ * @msg: Set registers of flash
+ * @in param cmd: Command byte
+ * @in param writebuf: write buffer
+ * @in param length: need write length
+ * @return {*}
+ */
+ft_error_t FQSpi_FlashRegSet(FQSpi_t *pQspi,
+ FT_IN u8 cmd,
+ FT_IN u8 *writebuf,
+ u32 length)
+{
+ FQSpi_Config_t *pConfig = NULL;
+ FQSpi_CmdPortReg_t cmdPortReg;
+ Ft_assertNonvoid(pQspi != NULL);
+ Ft_assertNonvoid(pQspi->isReady == FT_COMPONENT_IS_READLY);
+ pConfig = &pQspi->config;
+
+ cmdPortReg.data = 0;
+ cmdPortReg.val.cmd = cmd;
+ cmdPortReg.val.wait = 1;
+ cmdPortReg.val.sckSel = pConfig->clkDiv;
+ cmdPortReg.val.transfer = pConfig->transMode;
+ cmdPortReg.val.cs = pConfig->channel;
+
+ if (length == 0)
+ {
+ Ft_out32(pConfig->baseAddress + FT_REG_QSPI_CMD_PORT_OFFSET, cmdPortReg.data);
+ Ft_out32(pConfig->baseAddress + FT_REG_QSPI_LD_PORT_OFFSET, 1);
+ }
+ else
+ {
+ cmdPortReg.val.dataTransfer = 1;
+ cmdPortReg.val.rwMum = length;
+ Ft_out32(pConfig->baseAddress + FT_REG_QSPI_CMD_PORT_OFFSET, cmdPortReg.data);
+ FQSpi_MemcpyToReg(pQspi, writebuf, length);
+ }
+
+ return FQSPI_SUCCESS;
+}
+
+ft_error_t FQSpi_FlashRegSetWithaddr(FQSpi_t *pQspi,
+ FT_IN u8 cmd,
+ FT_IN u32 addr,
+ FT_IN u8 *writebuf,
+ u32 length)
+{
+ FQSpi_Config_t *pConfig = NULL;
+ FQSpi_CmdPortReg_t cmdPortReg;
+ Ft_assertNonvoid(pQspi != NULL);
+ Ft_assertNonvoid(pQspi->isReady == FT_COMPONENT_IS_READLY);
+ pConfig = &pQspi->config;
+
+ cmdPortReg.data = 0;
+ cmdPortReg.val.cmd = cmd;
+ cmdPortReg.val.wait = 1;
+ cmdPortReg.val.sckSel = pConfig->clkDiv;
+ cmdPortReg.val.transfer = pConfig->transMode;
+ cmdPortReg.val.cs = pConfig->channel;
+ cmdPortReg.val.cmdAddr = 1;
+ cmdPortReg.val.addrSel = pConfig->addrMode;
+
+ Ft_out32(pConfig->baseAddress + FT_REG_QSPI_ADDR_PORT_OFFSET, addr);
+
+ if (length == 0)
+ {
+ Ft_out32(pConfig->baseAddress + FT_REG_QSPI_CMD_PORT_OFFSET, cmdPortReg.data);
+ Ft_out32(pConfig->baseAddress + FT_REG_QSPI_LD_PORT_OFFSET, 0);
+ }
+ else
+ {
+ cmdPortReg.val.dataTransfer = 1;
+ cmdPortReg.val.rwMum = length;
+ Ft_out32(pConfig->baseAddress + FT_REG_QSPI_CMD_PORT_OFFSET, cmdPortReg.data);
+ FQSpi_MemcpyToReg(pQspi, writebuf, length);
+ }
+
+ return FQSPI_SUCCESS;
+}
+
+ft_error_t FQSpi_FlashRegGet(FQSpi_t *pQspi,
+ FT_IN u8 cmd,
+ u8 *readbuf,
+ u32 length)
+{
+ FQSpi_Config_t *pConfig = NULL;
+ FQSpi_CmdPortReg_t cmdPortReg;
+ Ft_assertNonvoid(pQspi != NULL);
+ Ft_assertNonvoid(pQspi->isReady == FT_COMPONENT_IS_READLY);
+ pConfig = &pQspi->config;
+
+ cmdPortReg.data = 0;
+ cmdPortReg.val.cmd = cmd;
+ cmdPortReg.val.wait = 1;
+ cmdPortReg.val.sckSel = pConfig->clkDiv;
+ cmdPortReg.val.transfer = pConfig->transMode;
+ cmdPortReg.val.cs = pConfig->channel;
+ cmdPortReg.val.dataTransfer = 1;
+ cmdPortReg.val.pBuffer = 1;
+
+ Ft_out32(pConfig->baseAddress + FT_REG_QSPI_CMD_PORT_OFFSET, cmdPortReg.data);
+ FQSpi_MemcpyFromReg(pQspi, readbuf, length);
+ return FQSPI_SUCCESS;
+}
+
+ft_error_t FQSpi_FlashRegGetWithAddr(FQSpi_t *pQspi,
+ FT_IN u8 cmd,
+ FT_IN u32 addr,
+ FT_IN u32 dummyCycle,
+ u8 *readbuf,
+ u32 length)
+{
+ FQSpi_Config_t *pConfig = NULL;
+ FQSpi_CmdPortReg_t cmdPortReg;
+ Ft_assertNonvoid(pQspi != NULL);
+ Ft_assertNonvoid(pQspi->isReady == FT_COMPONENT_IS_READLY);
+ pConfig = &pQspi->config;
+
+ cmdPortReg.data = 0;
+ cmdPortReg.val.cmd = cmd;
+ cmdPortReg.val.wait = 1;
+ cmdPortReg.val.sckSel = pConfig->clkDiv;
+ cmdPortReg.val.transfer = pConfig->transMode;
+ cmdPortReg.val.cs = pConfig->channel;
+ cmdPortReg.val.dataTransfer = 1;
+ cmdPortReg.val.pBuffer = 1;
+ cmdPortReg.val.cmdAddr = 1;
+
+ cmdPortReg.val.addrSel = pConfig->addrMode;
+ cmdPortReg.val.latency = 1;
+ cmdPortReg.val.dummy = dummyCycle - 1;
+
+ Ft_out32(pConfig->baseAddress + FT_REG_QSPI_ADDR_PORT_OFFSET, addr);
+ Ft_out32(pConfig->baseAddress + FT_REG_QSPI_CMD_PORT_OFFSET, cmdPortReg.data);
+ FQSpi_MemcpyFromReg(pQspi, readbuf, length);
+ return FQSPI_SUCCESS;
+}
+
+ft_error_t FQSpi_Write(FQSpi_t *pQspi, struct FQSpi_DataPack *pDataPack)
+{
+ FQSpi_Config_t *pConfig = NULL;
+ FQSpi_WrCfgReg_t wrCfgReg;
+ u32 length;
+ u32 index = 0;
+ u32 val = 0;
+ const u32 *pu32Buf = NULL;
+ Ft_assertNonvoid(pQspi != NULL);
+ Ft_assertNonvoid(pQspi->isReady == FT_COMPONENT_IS_READLY);
+ pConfig = &pQspi->config;
+
+ if ((FQSPI_DATA_ADDRESS_3BYTE_MASK | FQSPI_DATA_ADDRESS_4BYTE_MASK) == (pDataPack->flags & (FQSPI_DATA_ADDRESS_3BYTE_MASK | FQSPI_DATA_ADDRESS_4BYTE_MASK)))
+ {
+ FTQSPI_DEBUG_E(" Two addresses are not allowed at the same time ");
+ return FQSPI_FAILURE;
+ }
+
+ if (0 == (pDataPack->flags & (FQSPI_DATA_ADDRESS_3BYTE_MASK | FQSPI_DATA_ADDRESS_4BYTE_MASK)))
+ {
+ FTQSPI_DEBUG_E(" There is no address configuration ");
+ return FQSPI_FAILURE;
+ }
+
+ if (NULL == pDataPack->txBuf)
+ {
+ FTQSPI_DEBUG_E("pDataPack->txBuf is null");
+ return FQSPI_FAILURE;
+ }
+
+ pu32Buf = (const u32 *)pDataPack->txBuf;
+ wrCfgReg.data = 0;
+
+ if (FQSPI_DATA_ADDRESS_3BYTE_MASK == (pDataPack->flags & FQSPI_DATA_ADDRESS_3BYTE_MASK))
+ {
+ wrCfgReg.val.wrAddrsel = FT_QSPI_ADDR_SEL_3;
+ }
+ else if (FQSPI_DATA_ADDRESS_4BYTE_MASK == (pDataPack->flags & FQSPI_DATA_ADDRESS_4BYTE_MASK))
+ {
+ wrCfgReg.val.wrAddrsel = FT_QSPI_ADDR_SEL_4;
+ }
+
+ wrCfgReg.val.wrCmd = pDataPack->cmd;
+ wrCfgReg.val.wrWait = 1;
+ wrCfgReg.val.wrSckSel = pConfig->clkDiv;
+ wrCfgReg.val.wrTransfer = pConfig->transMode;
+ wrCfgReg.val.wrMode = 1;
+ length = pDataPack->length;
+
+ Ft_out32(pConfig->baseAddress + FT_REG_QSPI_WR_CFG_OFFSET, wrCfgReg.data);
+
+ while (length)
+ {
+ if (length >= 4)
+ {
+ Ft_out32(pDataPack->addr + index, pu32Buf[index / 4]);
+ length -= 4;
+ index += 4;
+ }
+ else
+ {
+ if (1 == length)
+ {
+ val = pDataPack->txBuf[index] | 0xFFFFFF00;
+ }
+ else if (2 == length)
+ {
+ val = pDataPack->txBuf[index] | (pDataPack->txBuf[index + 1] << 8) | 0xFFFF0000;
+ }
+ else
+ {
+ val = pDataPack->txBuf[index] | (pDataPack->txBuf[index + 1] << 8) | (pDataPack->txBuf[index + 2] << 8) | 0xFF000000;
+ }
+ FTQSPI_DEBUG_I("val is 0x%x", val);
+ Ft_out32(pDataPack->addr + index, val);
+ length = 0;
+ }
+ }
+
+ Ft_out32(pConfig->baseAddress + FT_REG_QSPI_FLUSH_OFFSET, 1);
+ return FQSPI_SUCCESS;
+}
+
+ft_error_t FQSpi_Read(FQSpi_t *pQspi, struct FQSpi_DataPack *pDataPack)
+{
+ FQSpi_Config_t *pConfig = NULL;
+ FQSpi_RdCfgReg_t rdCfgReg;
+ Ft_assertNonvoid(pQspi != NULL);
+ Ft_assertNonvoid(pQspi->isReady == FT_COMPONENT_IS_READLY);
+ pConfig = &pQspi->config;
+
+ if ((FQSPI_DATA_ADDRESS_3BYTE_MASK | FQSPI_DATA_ADDRESS_4BYTE_MASK) == (pDataPack->flags & (FQSPI_DATA_ADDRESS_3BYTE_MASK | FQSPI_DATA_ADDRESS_4BYTE_MASK)))
+ {
+ FTQSPI_DEBUG_E(" Two addresses are not allowed at the same time ");
+ return FQSPI_FAILURE;
+ }
+
+ if (0 == (pDataPack->flags & (FQSPI_DATA_ADDRESS_3BYTE_MASK | FQSPI_DATA_ADDRESS_4BYTE_MASK)))
+ {
+ FTQSPI_DEBUG_E(" There is no address configuration ");
+ return FQSPI_FAILURE;
+ }
+
+ if (NULL == pDataPack->rxBuf)
+ {
+ FTQSPI_DEBUG_E("pDataPack->rxBuf is null");
+ return FQSPI_FAILURE;
+ }
+
+ rdCfgReg.data = 0;
+
+ if (FQSPI_DATA_NEED_DUMMY_MASK == (pDataPack->flags & FQSPI_DATA_NEED_DUMMY_MASK))
+ {
+ rdCfgReg.val.rdLatency = 1;
+ rdCfgReg.val.dummy = pDataPack->dummyCycle - 1;
+ }
+
+ if (FQSPI_DATA_ADDRESS_3BYTE_MASK == (pDataPack->flags & FQSPI_DATA_ADDRESS_3BYTE_MASK))
+ {
+ rdCfgReg.val.rdAddrSel = FT_QSPI_ADDR_SEL_3;
+ }
+ else if (FQSPI_DATA_ADDRESS_4BYTE_MASK == (pDataPack->flags & FQSPI_DATA_ADDRESS_4BYTE_MASK))
+ {
+ rdCfgReg.val.rdAddrSel = FT_QSPI_ADDR_SEL_4;
+ }
+
+ rdCfgReg.val.rdCmd = pDataPack->cmd;
+ rdCfgReg.val.dBuffer = 1;
+ rdCfgReg.val.rdSckSel = pConfig->clkDiv;
+ rdCfgReg.val.rdTransfer = pConfig->transMode;
+
+ Ft_out32(pConfig->baseAddress + FT_REG_QSPI_RD_CFG_OFFSET, rdCfgReg.data);
+
+ memcpy(pDataPack->rxBuf, (char *)(pDataPack->addr), pDataPack->length);
+
+ return FQSPI_SUCCESS;
+}
+
+ft_error_t
+FQSpi_CmdOperation(FQSpi_t *pQspi, struct FQSpi_CmdPack *pCmdPack)
+{
+ FQSpi_Config_t *pConfig = NULL;
+ FQSpi_CmdPortReg_t cmdPortReg;
+ Ft_assertNonvoid(pQspi != NULL);
+ Ft_assertNonvoid(pQspi->isReady == FT_COMPONENT_IS_READLY);
+ pConfig = &pQspi->config;
+ if ((FQSPI_CMD_ADDRESS_3BYTE_MASK | FQSPI_CMD_ADDRESS_4BYTE_MASK) == (pCmdPack->flags & (FQSPI_CMD_ADDRESS_3BYTE_MASK | FQSPI_CMD_ADDRESS_4BYTE_MASK)))
+ {
+ FTQSPI_DEBUG_E(" Two addresses are not allowed at the same time ");
+ return FQSPI_FAILURE;
+ }
+
+ cmdPortReg.data = 0;
+ cmdPortReg.val.cmd = pCmdPack->cmd;
+ cmdPortReg.val.wait = 1;
+ cmdPortReg.val.sckSel = pConfig->clkDiv;
+ cmdPortReg.val.transfer = pConfig->transMode;
+ cmdPortReg.val.cs = pConfig->channel;
+
+ if (FQSPI_CMD_NEED_ADDR_MASK == (pCmdPack->flags & FQSPI_CMD_NEED_ADDR_MASK))
+ {
+ // FTQSPI_DEBUG_I(" send addr is 0x%x ", pCmdPack->addr);
+ cmdPortReg.val.cmdAddr = 1;
+ Ft_out32(pConfig->baseAddress + FT_REG_QSPI_ADDR_PORT_OFFSET, pCmdPack->addr);
+ }
+
+ if (FQSPI_CMD_NEED_DUMMY_MASK == (pCmdPack->flags & FQSPI_CMD_NEED_DUMMY_MASK))
+ {
+ cmdPortReg.val.latency = 1;
+ cmdPortReg.val.dummy = pCmdPack->dummyCycle - 1;
+ }
+
+ if (FQSPI_CMD_ADDRESS_3BYTE_MASK == (pCmdPack->flags & FQSPI_CMD_ADDRESS_3BYTE_MASK))
+ {
+ cmdPortReg.val.addrSel = FT_QSPI_ADDR_SEL_3;
+ }
+ else if (FQSPI_CMD_ADDRESS_4BYTE_MASK == (pCmdPack->flags & FQSPI_CMD_ADDRESS_4BYTE_MASK))
+ {
+ cmdPortReg.val.addrSel = FT_QSPI_ADDR_SEL_4;
+ }
+
+ if (FQSPI_CMD_NEED_SET_MASK == (pCmdPack->flags & (FQSPI_CMD_NEED_SET_MASK)))
+ {
+ cmdPortReg.val.dataTransfer = 1;
+ cmdPortReg.val.rwMum = pCmdPack->length;
+ Ft_out32(pConfig->baseAddress + FT_REG_QSPI_CMD_PORT_OFFSET, cmdPortReg.data);
+ FQSpi_MemcpyToReg(pQspi, pCmdPack->txBuf, pCmdPack->length);
+ }
+ else if (FQSPI_CMD_NEED_GET_MASK == (pCmdPack->flags & (FQSPI_CMD_NEED_GET_MASK)))
+ {
+ cmdPortReg.val.dataTransfer = 1;
+ cmdPortReg.val.pBuffer = 1;
+ Ft_out32(pConfig->baseAddress + FT_REG_QSPI_CMD_PORT_OFFSET, cmdPortReg.data);
+ FQSpi_MemcpyFromReg(pQspi, pCmdPack->rxBuf, pCmdPack->length);
+ }
+ else
+ {
+ Ft_out32(pConfig->baseAddress + FT_REG_QSPI_CMD_PORT_OFFSET, cmdPortReg.data);
+
+ if (FQSPI_CMD_NEED_ADDR_MASK == (pCmdPack->flags & FQSPI_CMD_NEED_ADDR_MASK))
+ {
+ Ft_out32(pConfig->baseAddress + FT_REG_QSPI_LD_PORT_OFFSET, 0);
+ }
+ else
+ {
+ Ft_out32(pConfig->baseAddress + FT_REG_QSPI_LD_PORT_OFFSET, 1);
+ }
+ }
+
+ return FQSPI_SUCCESS;
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_qspi/ft_qspi.h b/bsp/ft2004/libraries/bsp/ft_qspi/ft_qspi.h
new file mode 100644
index 0000000000..61aa626f63
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_qspi/ft_qspi.h
@@ -0,0 +1,184 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-05 21:31:10
+ * @LastEditTime: 2021-04-05 21:31:10
+ * @Description:  Description of file
+ * @Modify History:
+ * * * Ver   Who        Date         Changes
+ * * ----- ------     --------    --------------------------------------
+ * * v1.0 hh 2021-04-05 init
+ */
+
+#ifndef FT_QSPI_H
+#define FT_QSPI_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "ft_types.h"
+#include "ft_error_code.h"
+
+#define FQSPI_SUCCESS FST_SUCCESS /* SUCCESS */
+#define FQSPI_FAILURE FT_MAKE_ERRCODE(errQspi, errBspGeneral, FST_FAILURE) /* Normal */
+#define FQSPI_TIMEOUT FT_MAKE_ERRCODE(errQspi, errBspGeneral, FST_TIMEOUT) /* Timeout */
+#define FQSPI_EILSEQ FT_MAKE_ERRCODE(errQspi, errBspGeneral, FST_EILSEQ) /* Illegal byte sequence. */
+#define FQSPI_INVALID_PARAM FT_MAKE_ERRCODE(errQspi, errBspGeneral, FST_INVALID_PARAM) /* Invalid param. */
+
+/* qspi bsp command instruction operation */
+#define FQSPI_CMD_NEED_ADDR_MASK 0x1U
+#define FQSPI_CMD_NEED_DUMMY_MASK 0x2U
+#define FQSPI_CMD_NEED_GET_MASK 0x4U
+#define FQSPI_CMD_NEED_SET_MASK 0x08U
+#define FQSPI_CMD_ADDRESS_3BYTE_MASK 0x10U
+#define FQSPI_CMD_ADDRESS_4BYTE_MASK 0x20U
+
+/* qspi cmd of transfer operation */
+#define FQSPI_DATA_NEED_DUMMY_MASK 0x1U
+#define FQSPI_DATA_ADDRESS_3BYTE_MASK 0x2U
+#define FQSPI_DATA_ADDRESS_4BYTE_MASK 0x4U
+
+#define FQSPI_FLASH_CMD_WRR 0x01 /* Write status register */
+#define FQSPI_FLASH_CMD_PP 0x02 /* Page program */
+#define FQSPI_FLASH_CMD_READ 0x03 /* Normal read data bytes */
+#define FQSPI_FLASH_CMD_WRDI 0x04 /* Write disable */
+#define FQSPI_FLASH_CMD_RDSR1 0x05 /* Read status register */
+#define FQSPI_FLASH_CMD_WREN 0x06 /* Write enable */
+#define FQSPI_FLASH_CMD_RDSR2 0x07 /* Read status register */
+#define FQSPI_FLASH_CMD_FAST_READ 0x0B /* Fast read data bytes */
+#define FQSPI_FLASH_CMD_4FAST_READ 0x0C /* Fast read data bytes */
+#define FQSPI_FLASH_CMD_4PP 0x12 /* Page program */
+#define FQSPI_FLASH_CMD_4READ 0x13 /* Normal read data bytes */
+#define FQSPI_FLASH_CMD_P4E 0x20 /* Erase 4kb sector */
+#define FQSPI_FLASH_CMD_4P4E 0x21 /* Erase 4kb sector */
+#define FQSPI_FLASH_CMD_QPP 0x32 /* Quad Page program */
+#define FQSPI_FLASH_CMD_4QPP 0x34 /* Quad Page program */
+#define FQSPI_FLASH_CMD_RDCR 0x35 /* Read config register */
+#define FQSPI_FLASH_CMD_BE 0x60 /* Bulk erase */
+#define FQSPI_FLASH_CMD_RDAR 0x65 /* Read Any Register */
+#define FQSPI_FLASH_CMD_QOR 0x6B /* Quad read data bytes */
+#define FQSPI_FLASH_CMD_4QOR 0x6C /* Quad read data bytes */
+#define FQSPI_FLASH_CMD_WRAR 0x71 /* Write Any Register */
+#define FQSPI_FLASH_CMD_RDID 0x9F /* Read JEDEC ID */
+#define FQSPI_FLASH_CMD_4BAM 0xB7 /* Enter 4 Bytes Mode */
+#define FQSPI_FLASH_CMD_4BE 0xC7 /* Bulk erase */
+#define FQSPI_FLASH_CMD_SE 0xD8 /* Sector erase */
+#define FQSPI_FLASH_CMD_4SE 0xDC /* Sector erase */
+#define FQSPI_FLASH_CMD_4BEX 0xE9 /* Exit 4 Bytes Mode */
+#define FQSPI_FLASH_CMD_QIOR 0xEB /* Quad read data bytes */
+#define FQSPI_FLASH_CMD_4QIOR 0xEC /* Quad read data bytes */
+#define FQSPI_FLASH_DISCOVERABLE_PARAMETER 0x5a
+#define FQSPI_CMD_ENABLE_RESET 0x66
+#define FQSPI_CMD_RESET 0x99
+
+ struct FQSpi_DataPack
+ {
+ u32 flags; /* Follow qspi cmd of transfer operation */
+ u32 cmd; /* Command instruction */
+ u32 addr; /* Flash address */
+ u32 dummyCycle; /* dummy Cycle */
+ const u8 *txBuf;
+ u8 *rxBuf; /* Need send or read buffer */
+ u32 length; /* Buffer length */
+ };
+
+ struct FQSpi_CmdPack
+ {
+ u32 flags; /* Follow qspi bsp command instruction operation */
+ u32 cmd; /* Command instruction */
+ u32 addr; /* Command address */
+ u32 dummyCycle; /* dummy Cycle */
+ const u8 *txBuf;
+ u8 *rxBuf; /* Need send or read buffer */
+ u32 length; /* Buffer length */
+ };
+
+ typedef struct
+ {
+ u32 instanceId; /* Id of device */
+ uintptr_t baseAddress; /* Base address of qspi */
+ u32 transMode; /* Transfer mode */
+ u32 capacity; /* Flash capacity */
+ u32 addrMode; /**/
+ u32 clkDiv;
+ u32 qspiDevNum; /*Qspi device number */
+ u32 channel; /* Cs number */
+ u32 bitWidth; /* Transfer unit width */
+ } FQSpi_Config_t;
+
+ typedef struct
+ {
+ FQSpi_Config_t config;
+ u32 isReady; /**< Device is initialized and ready */
+
+ } FQSpi_t;
+
+ /**
+ * @name: FQSpi_LookupConfig
+ * @msg: FQSpi_LookupConfig returns a reference FQSpi_Config_t structure based on the
+ * unique device id.
+ * @in param {u32} instanceId : unique device
+ * @return {FQSpi_Config_t} FQSpi_Config_t is a reference to a config record in the configuration
+ * table (in qspi_g.c) corresponding to <i>instanceId</i>, or NULL if no match is found.
+ */
+ FQSpi_Config_t *FQSpi_LookupConfig(u32 instanceId);
+
+ /**
+ * @name: FQSpi_CfgInitialize
+ * @msg: This function intializes the configuration for the qspi instance
+ * @in param {FQSpi_t *} pQspi: A pointer to the qspi instance
+ * @in param {FQSpi_Config_t *} pConfig: A pointer to the qspi instance config record
+ * @return {ft_error_t}
+ */
+ ft_error_t FQSpi_CfgInitialize(FQSpi_t *pQspi, FQSpi_Config_t *pConfig);
+
+ /**
+ * @name: FQSpi_CmdOperation
+ * @msg: This function send command instruction by the struct FQSpi_CmdPack
+ * @in param {FQSpi_t *} pQspi: A pointer to the qspi instance
+ * @in param {struct FQSpi_CmdPack *} pCmdPack: Need to send command instruction package
+ * @return {ft_error_t}
+ */
+ ft_error_t FQSpi_CmdOperation(FQSpi_t *pQspi, struct FQSpi_CmdPack *pCmdPack);
+
+ /**
+ * @name: FQSpi_Read
+ * @msg: This function reads flash data from a specific address by {struct FQSpi_DataPack}
+ * @in param {FQSpi_t *} pQspi: A pointer to the qspi instance
+ * @in param {struct FQSpi_DataPack *} pDataPack: Need to read data package
+ * @return {ft_error_t}
+ */
+ ft_error_t FQSpi_Read(FQSpi_t *pQspi, struct FQSpi_DataPack *pDataPack);
+
+ /**
+ * @name: FQSpi_Write
+ * @msg: This function writes data from a specific address by {struct FQSpi_DataPack}
+ * @in param {FQSpi_t *} pQspi: A pointer to the qspi instance
+ * @in param {struct FQSpi_DataPack *} pDataPack: Need to read data package
+ * @return {ft_error_t}
+ */
+ ft_error_t FQSpi_Write(FQSpi_t *pQspi, struct FQSpi_DataPack *pDataPack);
+
+ /**
+ * @name: FQSpi_FlashRegSet
+ * @msg: This function sends command instruction with specific parameters
+ * @in param {FQSpi_t *} pQspi: A pointer to the qspi instance
+ * @in param {FT_IN u8} cmd: Command instruction
+ * @in param {FT_IN u8 *} writebuf: Data that needs to be sent through command instruction registers
+ * @in param {u32} length: Data length
+ * @return {ft_error_t}
+ */
+ ft_error_t FQSpi_FlashRegSet(FQSpi_t *pQspi,
+ FT_IN u8 cmd,
+ FT_IN u8 *writebuf,
+ u32 length);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/bsp/ft2004/libraries/bsp/ft_qspi/qspi_g.c b/bsp/ft2004/libraries/bsp/ft_qspi/qspi_g.c
new file mode 100644
index 0000000000..18833f60d0
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_qspi/qspi_g.c
@@ -0,0 +1,26 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 11:31:12
+ * @LastEditTime: 2021-04-07 11:31:13
+ * @Description:  Description of file
+ * @Modify History:
+ * * * Ver   Who        Date         Changes
+ * * ----- ------     --------    --------------------------------------
+ * * v1.0 hh 2021-04-07 init
+ */
+#include "ft_qspi.h"
+#include "ft_parameters.h"
+
+FQSpi_Config_t FqSpi_ConfigTable[FT_QSPI_NUM] = {
+ {.instanceId = FT_QSPI_INSTANCE, /* Id of device */
+ .baseAddress = FT_QSPI_BASEADDR, /* Base address of qspi */
+ .transMode = FT_QSPI_TRANSFER_1_1_1, /* Transfer mode */
+ .capacity = FT_QSPI_FLASH_CAP_32MB, /* Flash capacity */
+ .addrMode = FT_QSPI_ADDR_SEL_3, /**/
+ .clkDiv = FT_QSPI_SCK_DIV_128,
+ .qspiDevNum = 1,
+ .channel = 0,
+ .bitWidth = 8}};
diff --git a/bsp/ft2004/libraries/bsp/ft_qspi/qspi_hw.c b/bsp/ft2004/libraries/bsp/ft_qspi/qspi_hw.c
new file mode 100644
index 0000000000..1fb8e05c0d
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_qspi/qspi_hw.c
@@ -0,0 +1,25 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-02 18:32:42
+ * @LastEditTime: 2021-04-02 18:32:43
+ * @Description:  Description of file
+ * @Modify History:
+ * * * Ver   Who        Date         Changes
+ * * ----- ------     --------    --------------------------------------
+ */
+#include "qspi_hw.h"
+#include "ft_qspi.h"
+#include "ft_assert.h"
+#include "ft_io.h"
+
+void FQSpi_Reset(FQSpi_t *pQspi)
+{
+ FQSpi_Config_t *pConfig = NULL;
+ Ft_assertVoid(pQspi != NULL);
+ pConfig = &pQspi->config;
+ Ft_out32(pConfig->baseAddress + FT_REG_QSPI_CAP_OFFSET,
+ FT_REG_QSPI_CAP_FLASH_NUM(pConfig->qspiDevNum) | FT_REG_QSPI_CAP_FLASH_CAP(pConfig->capacity));
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_qspi/qspi_hw.h b/bsp/ft2004/libraries/bsp/ft_qspi/qspi_hw.h
new file mode 100644
index 0000000000..c7b9cb9651
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_qspi/qspi_hw.h
@@ -0,0 +1,199 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-02 18:32:54
+ * @LastEditTime: 2021-05-24 14:33:45
+ * @Description:  Description of file
+ *
+ * @Modify History:
+ * * * Ver   Who        Date         Changes
+ * * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef QSPI_HW_H
+#define QSPI_HW_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "ft_qspi.h"
+#include "ft_types.h"
+
+/* register definition */
+#define FT_REG_QSPI_CAP_OFFSET (0x00) /* Flash capacity setting register */
+#define FT_REG_QSPI_RD_CFG_OFFSET (0x04) /* Address access reads configuration registers */
+#define FT_REG_QSPI_WR_CFG_OFFSET (0x08) /* Write buffer flush register */
+#define FT_REG_QSPI_FLUSH_OFFSET (0x0C) /* Write buffer flush register */
+#define FT_REG_QSPI_CMD_PORT_OFFSET (0x10) /* Command port register */
+#define FT_REG_QSPI_ADDR_PORT_OFFSET (0x14) /* Address port register */
+#define FT_REG_QSPI_HD_PORT_OFFSET (0x18) /* Upper bit port register */
+#define FT_REG_QSPI_LD_PORT_OFFSET (0x1C) /* low bit port register */
+#define FT_REG_QSPI_FUN_SET_OFFSET (0x20) /* CS setting register */
+#define FT_REG_QSPI_WIP_RD_OFFSET (0x24) /* WIP reads the Settings register */
+#define FT_REG_QSPI_WP_OFFSET (0x28) /* WP register */
+#define FT_REG_QSPI_MODE_OFFSET (0x2C) /* Mode setting register */
+
+/*QSPI_CAP*/
+#define FT_REG_QSPI_CAP_FLASH_NUM(data) ((data) << 3) /* Flash number */
+#define FT_REG_QSPI_CAP_FLASH_CAP(data) ((data) << 0) /* The flash capacity */
+
+/* RD_CFG */
+#define FT_RD_CFG_CMD(data) ((data) << 24) /* Read Command */
+#define FT_RD_CFG_THROUGH(data) ((data) << 23) /* The programming flag in the status register */
+#define FT_RD_CFG_TRANSFER(data) ((data) << 20) /* */
+#define FT_RD_CFG_ADDR_SEL(data) ((data) << 19) /* */
+#define FT_RD_CFG_LATENCY(data) ((data) << 18) /* */
+#define FT_RD_CFG_MODE_BYTE(data) ((data) << 17) /* */
+#define FT_RD_CFG_CMD_SIGN(data) ((data) << 9) /* */
+#define FT_RD_CFG_DUMMY(data) ((data) << 4) /* */
+#define FT_RD_CFG_D_BUFFER(data) ((data) << 3) /* */
+#define FT_RD_CFG_SCK_SEL(data) ((data) << 0) /* */
+
+/*QSPI_WR_CFG*/
+#define FT_WR_CFG_CMD(data) ((data) << 24)
+#define FT_WR_CFG_WAIT(data) ((data) << 9)
+#define FT_WR_CFG_THROUGH(data) ((data) << 8)
+#define FT_WR_CFG_TRANSFER(data) ((data) << 5)
+#define FT_WR_CFG_ADDRSEL(data) ((data) << 4)
+#define FT_WR_CFG_MODE(data) ((data) << 3)
+#define FT_WR_CFG_SCK_SEL(data) ((data) << 0)
+
+/*QSPI_CMD_PORT*/
+#define FT_CMD_PORT_CMD(data) ((data) << 24)
+#define FT_CMD_PORT_WAIT(data) ((data) << 22)
+#define FT_CMD_PORT_THROUGH(data) ((data) << 21)
+#define FT_CMD_PORT_CS(data) ((data) << 19)
+#define FT_CMD_PORT_TRANSFER(data) ((data) << 16)
+#define FT_CMD_PORT_ADDR(data) ((data) << 15)
+#define FT_CMD_PORT_LATENCY(data) ((data) << 14)
+#define FT_CMD_PORT_DATA_TRANS(data) ((data) << 13)
+#define FT_CMD_PORT_ADDR_SEL(data) ((data) << 12)
+#define FT_CMD_PORT_DUMMY(data) ((data) << 7)
+#define FT_CMD_PORT_P_BUFFER(data) ((data) << 6)
+#define FT_CMD_PORT_RW_NUM(data) ((data) << 3)
+#define FT_CMD_PORT_CLK_SEL(data) ((data) << 0)
+
+/*QSPI_FUN_SET*/
+#define FT_FUN_SET_CS_HOLD(data) ((data) << 24)
+#define FT_FUN_SET_CS_SETUP(data) ((data) << 16)
+#define FT_FUN_SET_CS_DELAY(data) ((data) << 0)
+
+/*QSPI_WIP_RD*/
+#define FT_WIP_RD_CMD(data) ((data) << 24)
+#define FT_WIP_RD_TRANSFER(data) ((data) << 3)
+#define FT_WIP_RD_SCK_SEL(data) ((data) << 0)
+
+/*QSPI_WP*/
+#define FT_WP_EN(data) ((data) << 17)
+#define FT_WP_WP(data) ((data) << 16)
+#define FT_WP_HOLD(data) ((data) << 8)
+#define FT_WP_SETUP(data) ((data) << 0)
+
+/*QSPI_MODE*/
+#define FT_MODE_VALID(data) ((data) << 8)
+#define FT_MODE_MODE(data) ((data) << 0)
+
+#define FT_QSPI_FLASH_CAP_4MB 0
+#define FT_QSPI_FLASH_CAP_8MB 1
+#define FT_QSPI_FLASH_CAP_16MB 2
+#define FT_QSPI_FLASH_CAP_32MB 3
+#define FT_QSPI_FLASH_CAP_64MB 4
+#define FT_QSPI_FLASH_CAP_128MB 5
+#define FT_QSPI_FLASH_CAP_256MB 6
+
+#define FT_QSPI_ADDR_SEL_3 0
+#define FT_QSPI_ADDR_SEL_4 1
+
+#define FT_QSPI_SCK_DIV_128 0
+#define FT_QSPI_SCK_DIV_2 1
+#define FT_QSPI_SCK_DIV_4 2
+#define FT_QSPI_SCK_DIV_8 3
+#define FT_QSPI_SCK_DIV_16 4
+#define FT_QSPI_SCK_DIV_32 5
+#define FT_QSPI_SCK_DIV_64 6
+
+#define FT_QSPI_TRANSFER_1_1_1 0
+#define FT_QSPI_TRANSFER_1_1_2 1
+#define FT_QSPI_TRANSFER_1_1_4 2
+#define FT_QSPI_TRANSFER_1_2_2 3
+#define FT_QSPI_TRANSFER_1_4_4 4
+#define FT_QSPI_TRANSFER_2_2_2 5
+#define FT_QSPI_TRANSFER_4_4_4 6
+
+ /* typedefs */
+ /*QSPI_RD_CFG*/
+ typedef union
+ {
+ u32 data;
+ struct
+ {
+ u32 rdSckSel : 3; /* 2:0 */
+ u32 dBuffer : 1; /* 3 */
+ u32 dummy : 5; /* 8:4 */
+ u32 cmdSign : 8; /* 16:9 */
+ u32 modeByte : 1; /* 17 */
+ u32 rdLatency : 1; /* 18 */
+ u32 rdAddrSel : 1; /* 19 */
+ u32 rdTransfer : 3; /* 22:20 */
+ u32 rdThrough : 1; /* 23 */
+ u32 rdCmd : 8; /* 31:24 */
+ } val;
+ } FQSpi_RdCfgReg_t;
+
+ /*QSPI_WR_CFG*/
+ typedef union
+ {
+ u32 data;
+ struct
+ {
+ u32 wrSckSel : 3; /* 2:0 */
+ u32 wrMode : 1; /* 3 */
+ u32 wrAddrsel : 1; /* 4 */
+ u32 wrTransfer : 3; /* 7:5 */
+ u32 wrThrough : 1; /* 8 */
+ u32 wrWait : 1; /* 9 */
+ u32 wrRes : 14; /* 23:10 */
+ u32 wrCmd : 8; /* 31:24 */
+ } val;
+ } FQSpi_WrCfgReg_t;
+
+ /*QSPI_CMD_PORT*/
+ typedef union
+ {
+ u32 data;
+ struct
+ {
+ u32 sckSel : 3; /* 2:0 */
+ u32 rwMum : 3; /* 5:3 */
+ u32 pBuffer : 1; /* 6 */
+ u32 dummy : 5; /* 11:7 */
+ u32 addrSel : 1; /* 12 */
+ u32 dataTransfer : 1; /* 13 */
+ u32 latency : 1; /* 14 */
+ u32 cmdAddr : 1; /* 15 */
+ u32 transfer : 3; /* 18:16 */
+ u32 cs : 2; /* 20:19 */
+ u32 through : 1; /* 21 */
+ u32 wait : 1; /* 22 */
+ u32 res : 1; /* 23 */
+ u32 cmd : 8; /* 31:24 */
+ } val;
+ } FQSpi_CmdPortReg_t;
+
+ /**
+ * @name: FQSpi_Reset
+ * @msg: This routine performs the QSPI controller initialization.
+ * @in param: pQspi
+ * @return {*}
+ */
+ void FQSpi_Reset(FQSpi_t *pQspi);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // !
diff --git a/bsp/ft2004/libraries/bsp/ft_qspi/qspi_sinit.c b/bsp/ft2004/libraries/bsp/ft_qspi/qspi_sinit.c
new file mode 100644
index 0000000000..36c1e313a2
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_qspi/qspi_sinit.c
@@ -0,0 +1,34 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 13:22:01
+ * @LastEditTime: 2021-04-07 13:22:01
+ * @Description:  Description of file
+ * @Modify History:
+ * * * Ver   Who        Date         Changes
+ * * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_qspi.h"
+#include "ft_parameters.h"
+
+extern FQSpi_Config_t FqSpi_ConfigTable[FT_QSPI_NUM];
+
+FQSpi_Config_t *FQSpi_LookupConfig(u32 instanceId)
+{
+ FQSpi_Config_t *pFQSpi_Config_t = NULL;
+
+ u32 Index;
+ for (Index = 0; Index < (u32)FT_GMAC_INSTANCES_NUM; Index++)
+ {
+ if (FqSpi_ConfigTable[Index].instanceId == instanceId)
+ {
+ pFQSpi_Config_t = &FqSpi_ConfigTable[Index];
+ break;
+ }
+ }
+
+ return pFQSpi_Config_t;
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl.c b/bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl.c
new file mode 100644
index 0000000000..cf2eb5c7b0
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl.c
@@ -0,0 +1,552 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-03-31 14:59:20
+ * @LastEditTime: 2021-05-25 16:49:01
+ * @Description:  This files is for implemenation of sd ctrl
+ *
+ * @Modify History: * * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_parameters.h"
+#include "ft_assert.h"
+#include "ft_io.h"
+#include "ft_sdctrl.h"
+#include "ft_sdctrl_hw.h"
+#include "ft_debug.h"
+#include "ft_printf.h"
+#include "ft_trace.h"
+#include "ft_cache.h"
+#define FT_SD_CTRL_DEBUG_I(format, ...) FT_DEBUG_PRINT_I(FT_SD_CTRL_DEBUG_TAG, format, ##__VA_ARGS__)
+#define FT_SD_CTRL_DEBUG_E(format, ...) FT_DEBUG_PRINT_E(FT_SD_CTRL_DEBUG_TAG, format, ##__VA_ARGS__)
+#define FT_SD_CTRL_DEBUG_W(format, ...) FT_DEBUG_PRINT_W(FT_SD_CTRL_DEBUG_TAG, format, ##__VA_ARGS__)
+
+void FSdCtrl_ClkFreqSetup(FT_INOUT FtsdCtrl_t *pFtsdCtrl, FT_IN u32 sdClk)
+{
+ FSdCtrl_Config_t *pConfig;
+ u32 clkDiv;
+ u32 inputClk;
+ u32 tmpSdFreq;
+ u32 workSpeed;
+
+ Ft_assertVoid(FT_NULL != pFtsdCtrl);
+ pConfig = &pFtsdCtrl->config;
+ inputClk = pConfig->inputClockHz;
+
+ /* sd work speed is limit to 25MHz */
+ workSpeed = (sdClk < SD_CLK_FREQ_25MHZ) ? sdClk : SD_CLK_FREQ_25MHZ;
+
+ /* if sd clk freq is valid and is two times greater than io input clk */
+ if ((SD_CLK_FREQ_400KHZ < workSpeed) && (inputClk > (2 * workSpeed)))
+ {
+ clkDiv = (u32)(inputClk / (2 * workSpeed)) - 1;
+
+ /* calculte sd freq one more time base on divsor */
+ tmpSdFreq = (u32)inputClk / (2 * (clkDiv + 1));
+
+ /* if calculated sd freq is greater than the real val */
+ if (tmpSdFreq > workSpeed)
+ {
+ clkDiv += 1;
+ }
+ }
+ else
+ {
+ clkDiv = SD_FRRQ_DIV_DEFAULT;
+ }
+
+ Ft_out32(pConfig->baseAddress + CLOCK_DIV_REG_OFFSET, clkDiv);
+
+ return;
+}
+
+ft_error_t FsdCtrl_Init(FT_INOUT FtsdCtrl_t *pFtsdCtrl)
+{
+ FSdCtrl_Config_t *pConfig;
+ Ft_assertNonvoid(FT_NULL != pFtsdCtrl);
+ pConfig = &pFtsdCtrl->config;
+
+ /* Disable card detection */
+ Ft_out32(pConfig->baseAddress + SD_SEN_REG_OFFSET, 0);
+
+ /* Disable all interrupts */
+ Ft_out32(pConfig->baseAddress + NORMAL_INT_EN_REG_OFFSET, 0);
+ Ft_out32(pConfig->baseAddress + ERROR_INT_EN_REG_OFFSET, 0);
+ Ft_out32(pConfig->baseAddress + BD_ISR_EN_REG_OFFSET, 0);
+ // Ft_out32(pConfig->baseAddress + NORMAL_INT_EN_REG_OFFSET, NORMAL_INT_EN_ECCRCE);
+
+ /* Clear status register */
+ Ft_out32(pConfig->baseAddress + NORMAL_INT_STATUS_REG, 0);
+ Ft_out32(pConfig->baseAddress + ERROR_INT_STATUS_REG, 0);
+ Ft_out32(pConfig->baseAddress + BD_ISR_REG, 0);
+
+ /* Set default ctrl register */
+ Ft_out32(pConfig->baseAddress + CONTROLL_SETTING_REG_OFFSET, 0x0f00);
+
+ /* Set default drive and sampling register */
+ Ft_out32(pConfig->baseAddress + SD_DRV_REG_OFFSET, 0);
+ Ft_out32(pConfig->baseAddress + SD_SAMP_REG_OFFSET, 0);
+
+ /* Configure to default cmd data timeout */
+ Ft_out32(pConfig->baseAddress + TIMEOUT_CMD_REG_OFFSET, 0xFFFFFFFF);
+ //FSdCtrl_ClkFreqSetup(pFtsdCtrl, 1);
+
+ Ft_out32(pConfig->baseAddress + CLOCK_DIV_REG_OFFSET, SD_FRRQ_DIV_DEFAULT);
+ Ft_out32(pConfig->baseAddress + SD_SAMP_REG_OFFSET, SD_SAMP_DEFAULT);
+
+ pFtsdCtrl->isReady = FT_COMPONENT_IS_READLY;
+
+ return FTSDC_SUCCESS;
+}
+
+bool_t FSdCtrl_CardDetect(FT_INOUT FtsdCtrl_t *pFtsdCtrl)
+{
+ FSdCtrl_Config_t *pConfig;
+ u32 status;
+
+ Ft_assertBool(FT_NULL != pFtsdCtrl);
+ pConfig = &pFtsdCtrl->config;
+ status = Ft_in32(pConfig->baseAddress + STATUS_REG);
+
+ /* check card-detection signal */
+ if (((status)&STATUS_REG_CDSL) == STATUS_REG_CDSL)
+ {
+ pConfig->cardDetect = 0;
+ }
+ else
+ {
+ pConfig->cardDetect = 1;
+ }
+
+ return pConfig->cardDetect;
+}
+
+void FSdCtrl_ResetDma(FT_INOUT FtsdCtrl_t *pFtsdCtrl)
+{
+ FSdCtrl_Config_t *pConfig;
+ Ft_assertVoid(FT_NULL != pFtsdCtrl);
+ pConfig = &pFtsdCtrl->config;
+
+ Ft_setBit32((UINTPTR)(pConfig->baseAddress + SOFTWARE_RESET_REG_OFFSET), SOFTWARE_RESET_BDRST);
+ Ft_clearBit32((UINTPTR)(pConfig->baseAddress + SOFTWARE_RESET_REG_OFFSET), SOFTWARE_RESET_BDRST);
+}
+
+u32 FSdCtrl_PrepareCmdRaw(FT_IN u32 cmdIndex, FT_IN u32 rspType)
+{
+ u32 rawCmd = 0;
+
+ rawCmd |= CMD_SETTING_CMDI(cmdIndex);
+
+ switch (rspType)
+ {
+ case FTSDCTRL_CMD_RES_NONE:
+ rawCmd |= CMD_SETTING_RTS(0);
+ break;
+ case FTSDCTRL_CMD_RES_LONG:
+ rawCmd |= CMD_SETTING_RTS(1);
+ break;
+ case FTSDCTRL_CMD_RES_SHORT:
+ rawCmd |= CMD_SETTING_RTS(2);
+ break;
+ default:
+ rawCmd |= CMD_SETTING_RTS(0);
+ break;
+ }
+
+ return rawCmd;
+}
+
+void FSdCtrl_WriteData(FT_INOUT FtsdCtrl_t *pFtsdCtrl, FT_IN UINTPTR dataAddr,
+ FT_IN UINTPTR cardAddr, FT_IN u32 blkNum)
+{
+
+ FSdCtrl_Config_t *pConfig;
+ Ft_assertVoid(FT_NULL != pFtsdCtrl);
+ pConfig = &pFtsdCtrl->config;
+
+ /* write 1 to clear data status register and command status register */
+ Ft_out32(pConfig->baseAddress + BD_ISR_REG, BD_ISR_REG_TRS);
+ Ft_out32(pConfig->baseAddress + NORMAL_INT_STATUS_REG, NORMAL_INT_STATUS_CC);
+
+ /* set DMA BD */
+ Ft_setBit32((UINTPTR)(pConfig->baseAddress + SOFTWARE_RESET_REG_OFFSET), SOFTWARE_RESET_BDRST);
+ Ft_clearBit32((UINTPTR)(pConfig->baseAddress + SOFTWARE_RESET_REG_OFFSET), SOFTWARE_RESET_BDRST);
+
+ /* set transfer lenth */
+ Ft_out32(pConfig->baseAddress + BLK_CNT_REG, blkNum);
+
+ /* set DMA discriptor data low address,data high address,card low address,card high address*/
+ Ft_out32(pConfig->baseAddress + DAT_IN_M_TX_BD, dataAddr);
+ Ft_out32(pConfig->baseAddress + DAT_IN_M_TX_BD, 0);
+ Ft_out32(pConfig->baseAddress + DAT_IN_M_TX_BD, cardAddr);
+ Ft_out32(pConfig->baseAddress + DAT_IN_M_TX_BD, 0);
+}
+
+void FSdCtrl_ReadData(FT_INOUT FtsdCtrl_t *pFtsdCtrl,
+ FT_IN UINTPTR dataAddr,
+ FT_IN UINTPTR cardAddr,
+ FT_IN u32 blkNum)
+{
+ FSdCtrl_Config_t *pConfig;
+ Ft_assertVoid(FT_NULL != pFtsdCtrl);
+ pConfig = &pFtsdCtrl->config;
+
+ /* clear data status register and command status register */
+ Ft_out32(pConfig->baseAddress + BD_ISR_REG, BD_ISR_EN_ETRS);
+ Ft_out32(pConfig->baseAddress + NORMAL_INT_STATUS_REG, NORMAL_INT_EN_ECC);
+
+ /* set DMA BD */
+ Ft_setBit32((UINTPTR)(pConfig->baseAddress + SOFTWARE_RESET_REG_OFFSET), SOFTWARE_RESET_BDRST);
+ Ft_clearBit32((UINTPTR)(pConfig->baseAddress + SOFTWARE_RESET_REG_OFFSET), SOFTWARE_RESET_BDRST);
+
+ /* set transfer lenth */
+ Ft_out32(pConfig->baseAddress + BLK_CNT_REG, blkNum);
+
+ /* set DMA discriptor data low address,data high address,card low address,card high address*/
+
+ Ft_out32(pConfig->baseAddress + DAT_IN_M_RX_BD, dataAddr);
+ Ft_out32(pConfig->baseAddress + DAT_IN_M_RX_BD, 0);
+ Ft_out32(pConfig->baseAddress + DAT_IN_M_RX_BD, cardAddr);
+ Ft_out32(pConfig->baseAddress + DAT_IN_M_RX_BD, 0);
+}
+
+static ft_error_t FsdCtrl_privateSendCmd(FT_INOUT FtsdCtrl_t *pFtsdCtrl, FT_IN pFtsdCtrl_delayTimer_t pDelayTimer_fun, FT_IN u32 cmd, FT_IN u32 respType, FT_IN u32 arg)
+{
+ u32 temp;
+ u32 sd_cmd;
+ u32 sd_arg;
+ FSdCtrl_Config_t *pConfig;
+ Ft_assertNonvoid(FT_NULL != pFtsdCtrl);
+ pConfig = &pFtsdCtrl->config;
+
+ /* enable cmd finished irq */
+ Ft_out32(pConfig->baseAddress + NORMAL_INT_STATUS_REG, NORMAL_INT_EN_ECC);
+ Ft_out32(pConfig->baseAddress + NORMAL_INT_STATUS_REG, 0);
+
+ Ft_out32(pConfig->baseAddress + ERROR_INT_STATUS_REG, BD_ISR_EN_ETRS);
+ Ft_out32(pConfig->baseAddress + ERROR_INT_STATUS_REG, 0);
+
+ /* prepare cmd msg, along with arg */
+ sd_cmd = FSdCtrl_PrepareCmdRaw(cmd, respType);
+ sd_arg = arg;
+
+ /* send cmd and arg */
+ Ft_out32(pConfig->baseAddress + CMD_SETTING_REG_OFFSET, sd_cmd);
+ Ft_out32(pConfig->baseAddress + ARGUMENT_REG_OFFSET, sd_arg);
+
+ if (pConfig->workMode & FTSDCTRL_CMD_IRQ_MASK)
+ {
+ if (pFtsdCtrl->cmdWaitCallback)
+ {
+ /* if irq is enabled and call back registered, enter call back procedure */
+ return pFtsdCtrl->cmdWaitCallback(pFtsdCtrl);
+ }
+ else
+ {
+ return FTSDC_INVALID_PARAM;
+ }
+ }
+ else
+ {
+ temp = Ft_in32(pConfig->baseAddress + NORMAL_INT_STATUS_REG);
+ /* polling wait for cmd-finished response */
+ while (NORMAL_INT_STATUS_CC != (temp & NORMAL_INT_STATUS_CC))
+ {
+ temp = Ft_in32(pConfig->baseAddress + NORMAL_INT_STATUS_REG);
+ pDelayTimer_fun(1);
+ }
+ }
+
+ return FTSDC_SUCCESS;
+}
+
+ft_error_t FSdCtrl_WaitWriteDataEnd(FT_INOUT FtsdCtrl_t *pFtsdCtrl,
+ FT_IN pFtsdCtrl_delayTimer_t pDelayTimer_fun,
+ FT_IN u32 blkNum)
+{
+ u32 status;
+ u32 statusMask;
+ ft_error_t ret;
+ s32 timeout = 1000;
+ FSdCtrl_Config_t *pConfig;
+
+ Ft_assertNonvoid(FT_NULL != pFtsdCtrl);
+ pConfig = &pFtsdCtrl->config;
+
+ if (pConfig->workMode & FTSDCTRL_DATA_WRITE_IRQ_MASK)
+ {
+ /* enter irq mode */
+ if (NULL == pFtsdCtrl->writeWaitCallback)
+ {
+ return FTSDC_INVALID_PARAM;
+ }
+
+ ret = pFtsdCtrl->writeWaitCallback(pFtsdCtrl);
+ if (FTSDC_SUCCESS != ret)
+ {
+ return FTSDC_EILSEQ;
+ }
+ }
+ else
+ {
+ /* wait for DMA-error or DMA-finished status */
+ statusMask = BD_ISR_REG_DAIS | BD_ISR_REG_TRS;
+ do
+ {
+ status = (Ft_in32(pConfig->baseAddress + BD_ISR_REG) & statusMask);
+ pDelayTimer_fun(1);
+ timeout--;
+ } while ((!status) && timeout);
+
+ if (status & BD_ISR_REG_DAIS)
+ {
+ if (status & (BD_ISR_REG_TRE | BD_ISR_REG_NRCRC | BD_ISR_REG_CMDE))
+ {
+ return FTSDC_EILSEQ;
+ }
+ else if (!timeout)
+ {
+ return FTSDC_TIMEOUT;
+ }
+ }
+ }
+
+ /* multi block needs MMC_STOP_TRANSMISSION to stop process*/
+ if (blkNum > 1)
+ {
+ return FsdCtrl_privateSendCmd(pFtsdCtrl, pDelayTimer_fun, 12, CMD_SETTING_RTS(2), 0);
+ }
+
+ return FTSDC_SUCCESS;
+}
+
+ft_error_t FSdCtrl_WaitReadDataEnd(FT_INOUT FtsdCtrl_t *pFtsdCtrl,
+ FT_IN pFtsdCtrl_delayTimer_t pDelayTimer_fun,
+ FT_IN u32 blkNum)
+{
+ u32 status;
+ u32 statusMask;
+ ft_error_t ret;
+ s32 timeout = 1000;
+ FSdCtrl_Config_t *pConfig;
+
+ Ft_assertNonvoid(FT_NULL != pFtsdCtrl);
+ pConfig = &pFtsdCtrl->config;
+
+ if (pConfig->workMode & FTSDCTRL_DATA_READ_IRQ_MASK)
+ {
+ if (pFtsdCtrl->readWaitCallback)
+ {
+ ret = pFtsdCtrl->readWaitCallback(pFtsdCtrl);
+ if (FTSDC_SUCCESS != ret)
+ {
+ return FTSDC_EILSEQ;
+ }
+ }
+ else
+ {
+ return FTSDC_INVALID_PARAM;
+ }
+ }
+ else
+ {
+ /* wait for DMA-error or Read-finish status */
+ statusMask = BD_ISR_REG_DAIS | BD_ISR_REG_RESPE;
+ do
+ {
+ status = (Ft_in32(pConfig->baseAddress + BD_ISR_REG) & statusMask);
+ pDelayTimer_fun(1);
+ timeout--;
+ } while ((!status) && timeout);
+
+ if (status & BD_ISR_REG_DAIS)
+ {
+ /* error handle */
+ if (status & (BD_ISR_REG_TRE | BD_ISR_REG_NRCRC | BD_ISR_REG_CMDE))
+ {
+ return FTSDC_EILSEQ;
+ }
+ else if (!timeout)
+ {
+ return FTSDC_TIMEOUT;
+ }
+ }
+ }
+
+ // /* multi block needs MMC_STOP_TRANSMISSION to stop process*/
+ if (blkNum > 1)
+ {
+ return FsdCtrl_privateSendCmd(pFtsdCtrl, pDelayTimer_fun, 12, CMD_SETTING_RTS(2), 0);
+ }
+
+ return FTSDC_SUCCESS;
+}
+
+ft_error_t FSdCtrl_WaitCmdEnd(FT_OUT FtsdCtrl_t *pFtsdCtrl,
+ FT_IN pFtsdCtrl_delayTimer_t pDelayTimer_fun,
+ FT_IN u32 rspType,
+ FT_OUT u32 *cmdRsp)
+{
+ u32 status;
+ u32 statusMask;
+ s32 timeout = 1000;
+ const FSdCtrl_Config_t *pConfig;
+ ft_error_t result = FST_SUCCESS;
+
+ Ft_assertNonvoid(FT_NULL != pFtsdCtrl);
+ pConfig = &pFtsdCtrl->config;
+
+ if (pConfig->workMode & FTSDCTRL_CMD_IRQ_MASK)
+ {
+ if (pFtsdCtrl->cmdWaitCallback)
+ {
+ result = pFtsdCtrl->cmdWaitCallback(pFtsdCtrl);
+ }
+ else
+ {
+ return FTSDC_INVALID_PARAM;
+ }
+ status = Ft_in32(pConfig->baseAddress + NORMAL_INT_STATUS_REG);
+ }
+ else
+ {
+ /* wait for cmd-error or cmd-finish respones */
+ statusMask = NORMAL_INT_STATUS_EI | NORMAL_INT_STATUS_CC;
+
+ do
+ {
+ status = (Ft_in32(pConfig->baseAddress + NORMAL_INT_STATUS_REG) & statusMask);
+ pDelayTimer_fun(1);
+ timeout--;
+
+ } while ((!status) && timeout);
+ }
+
+ if (status & NORMAL_INT_STATUS_EI)
+ {
+ /* error handle */
+ status = Ft_in32(pConfig->baseAddress + ERROR_INT_STATUS_REG);
+
+ if (!timeout)
+ {
+ return FTSDC_TIMEOUT;
+ }
+ else if ((status & NORMAL_INT_EN_ECCRCE))
+ {
+ return FTSDC_EILSEQ;
+ }
+ }
+
+ if (rspType != FTSDCTRL_CMD_RES_NONE)
+ {
+ /* get cmd respones */
+ if (rspType == FTSDCTRL_CMD_RES_LONG)
+ {
+ cmdRsp[0] = Ft_in32(pConfig->baseAddress + CMD_RESP_1);
+ cmdRsp[1] = Ft_in32(pConfig->baseAddress + CMD_RESP_2);
+ cmdRsp[2] = Ft_in32(pConfig->baseAddress + CMD_RESP_3);
+ cmdRsp[3] = Ft_in32(pConfig->baseAddress + CMD_RESP_4);
+ }
+ else
+ {
+ cmdRsp[0] = Ft_in32(pConfig->baseAddress + CMD_RESP_1);
+ cmdRsp[1] = 0;
+ cmdRsp[2] = 0;
+ cmdRsp[3] = 0;
+ }
+ }
+
+ return result;
+}
+
+void FSdCtrl_DoCmd(FT_INOUT FtsdCtrl_t *pFtsdCtrl,
+ FT_IN u32 cmdIndex,
+ FT_IN u32 rspType,
+ u32 arg)
+{
+ u32 cmd;
+
+ FSdCtrl_Config_t *pConfig;
+ Ft_assertVoid(FT_NULL != pFtsdCtrl);
+ pConfig = &pFtsdCtrl->config;
+
+ /* clear normal interrupt status */
+ Ft_out32(pConfig->baseAddress + NORMAL_INT_STATUS_REG, NORMAL_INT_STATUS_EI);
+
+ /* set command*/
+ cmd = FSdCtrl_PrepareCmdRaw(cmdIndex, rspType);
+ Ft_out32(pConfig->baseAddress + CMD_SETTING_REG_OFFSET, cmd);
+
+ if (cmdIndex == 41)
+ {
+ arg = 0x40ff8000;
+ }
+
+ Ft_out32(pConfig->baseAddress + ARGUMENT_REG_OFFSET, arg);
+}
+
+void FSdCtrl_DoACmd(FT_INOUT FtsdCtrl_t *pFtsdCtrl,
+ FT_IN u32 cmdIndex,
+ FT_IN u32 rspType,
+ u32 arg)
+{
+ u32 cmd;
+
+ FSdCtrl_Config_t *pConfig;
+ Ft_assertVoid(FT_NULL != pFtsdCtrl);
+ pConfig = &pFtsdCtrl->config;
+
+ /* clear normal interrupt status */
+ Ft_out32(pConfig->baseAddress + NORMAL_INT_STATUS_REG, NORMAL_INT_EN_ECC);
+ /* set command*/
+ cmd = FSdCtrl_PrepareCmdRaw(cmdIndex, rspType);
+ cmd |= CMD_SETTING_TRTY(2);
+ Ft_out32(pConfig->baseAddress + CMD_SETTING_REG_OFFSET, cmd);
+}
+
+void FSdCtrl_WriteWaitRegister(FT_INOUT FtsdCtrl_t *pFtsdCtrl, FT_IN pFtsdCtrl_irqWaitCallback_t callBack)
+{
+ Ft_assertVoid(FT_NULL != pFtsdCtrl);
+ pFtsdCtrl->writeWaitCallback = callBack;
+}
+
+void FSdCtrl_ReadWaitRegister(FT_INOUT FtsdCtrl_t *pFtsdCtrl, FT_IN pFtsdCtrl_irqWaitCallback_t callBack)
+{
+ Ft_assertVoid(FT_NULL != pFtsdCtrl);
+ pFtsdCtrl->readWaitCallback = callBack;
+}
+
+void FSdCtrl_CmdWaitRegister(FT_INOUT FtsdCtrl_t *pFtsdCtrl, FT_IN pFtsdCtrl_irqWaitCallback_t callBack)
+{
+ Ft_assertVoid(FT_NULL != pFtsdCtrl);
+ pFtsdCtrl->cmdWaitCallback = callBack;
+}
+
+u32 FSdCtrl_GetNormalIrqStatus(FT_INOUT FtsdCtrl_t *pFtsdCtrl)
+{
+ Ft_assertNonvoid(FT_NULL != pFtsdCtrl);
+ FSdCtrl_Config_t *pConfig;
+ pConfig = &pFtsdCtrl->config;
+ return Ft_in32(pConfig->baseAddress + NORMAL_INT_STATUS_REG);
+}
+
+u32 FSdCtrl_GetDataIrqStatus(FT_INOUT FtsdCtrl_t *pFtsdCtrl)
+{
+ Ft_assertNonvoid(FT_NULL != pFtsdCtrl);
+ FSdCtrl_Config_t *pConfig;
+ pConfig = &pFtsdCtrl->config;
+
+ return Ft_in32(pConfig->baseAddress + BD_ISR_REG);
+}
+
+u32 FSdCtrl_GetErrorIrqStatus(FT_INOUT FtsdCtrl_t *pFtsdCtrl)
+{
+ Ft_assertNonvoid(FT_NULL != pFtsdCtrl);
+ FSdCtrl_Config_t *pConfig;
+ pConfig = &pFtsdCtrl->config;
+
+ return Ft_in32(pConfig->baseAddress + ERROR_INT_STATUS_REG);
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl.h b/bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl.h
new file mode 100644
index 0000000000..88a0e9ee2b
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl.h
@@ -0,0 +1,235 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-03-31 14:59:20
+ * @LastEditTime: 2021-04-19 17:04:44
+ * @Description:  This files is for implementation of sd ctrl
+ *
+ * @Modify History: * * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef FTSDCTRL_H
+#define FTSDCTRL_H
+#include "ft_types.h"
+#include "ft_error_code.h"
+
+/* sd ctrl module debug tag */
+#define FT_SD_CTRL_DEBUG_TAG "FT_SD_CTRL"
+
+/* definition of errcode for sd module */
+#define FTSDC_SUCCESS FST_SUCCESS /* 成功 */
+#define FTSDC_FAILURE FT_MAKE_ERRCODE(errModeSdCtrl, errBspGeneral, FST_FAILURE) /* Normal */
+#define FTSDC_TIMEOUT FT_MAKE_ERRCODE(errModeSdCtrl, errBspGeneral, FST_TIMEOUT) /* Timeout */
+#define FTSDC_EILSEQ FT_MAKE_ERRCODE(errModeSdCtrl, errBspGeneral, FST_EILSEQ) /* Illegal byte sequence. */
+#define FTSDC_INVALID_PARAM FT_MAKE_ERRCODE(errModeSdCtrl, errBspGeneral, FST_INVALID_PARAM) /* Illegal byte sequence. */
+
+/* type of response to sd cmds */
+#define FTSDCTRL_CMD_RES_NONE 0 /* No response */
+#define FTSDCTRL_CMD_RES_LONG 1 /* The response length is long, code length is 128 */
+#define FTSDCTRL_CMD_RES_SHORT 2 /* The response length is short, code length is 32 */
+
+/* irq enable bits */
+#define FTSDCTRL_DATA_WRITE_IRQ_MASK 0x1
+#define FTSDCTRL_DATA_READ_IRQ_MASK 0x2
+#define FTSDCTRL_CMD_IRQ_MASK 0x4
+
+/* type of irq callback */
+typedef enum
+{
+ FTSDCTRL_DMADATAIRQID = 0x1U, /* Select dma interrupt */
+ FTSDCTRL_CMDIRQID = 0x2U, /* Select cmd interrupt */
+ FTSDCTRL_ERRORIRQID = 0x3U, /* Select error interrupt */
+} FSdCtrl_IrqCallbackSelect_t;
+
+/* normal irq enable bits for NORMAL_INT_EN_REG_OFFSET */
+typedef enum
+{
+ NORMAL_IRQ_CC = 1, /* Command completion interrupt */
+ NORMAL_IRQ_CR = 2, /* Card removal interrupt */
+ NORMAL_IRQ_EI = 4 /* Command error interrupt */
+} FSdCtrl_NormalIrqSelect_t;
+
+/* error irq enable bits for ERROR_INT_EN_REG_OFFSET */
+typedef enum
+{
+ ERROR_IRQ_CTE = 1, /* Command timeout error interrupted */
+ ERROR_IRQ_CCRCE = 2, /* Command CRC error interrupt */
+ ERROR_IRQ_CIR = 4, /* Command index error interrupt */
+ ERROR_IRQ_CNR = 8 /* Command response error interrupted */
+} FSdCtrl_ErrorIrqSelect_t;
+
+/* data trans irq bits for BD_ISR_EN_REG_OFFSET */
+typedef enum
+{
+ BD_IRQ_TRS = 1, /* DMA transmission has been interrupted */
+ BD_IRQ_DTE = 2, /* Timeout interrupt */
+ BD_IRQ_CMDE = 4, /* Command response error interrupted */
+ BD_IRQ_TRE = 8, /* Command response error interrupt CRC response error interrupt */
+ BD_IRQ_NRCRC = 0x10, /* No CRC response interruption */
+ BD_IRQ_DATFRAX = 0x20, /* AXI bus forces to release interrupts */
+ BD_IRQ_RESPE = 0x40, /* Read SD card operation, AXI BR channel complete interrupt */
+ BD_IRQ_DAIS = 0x80, /* DMA error interrupt */
+} FSdCtrl_BdIrqSelect;
+
+/* types of irq */
+typedef enum
+{
+ FTSDC_NORMAL_ISR = 0U,
+ FTSDC_BD_ISR,
+ FTSDC_ERROR_ISR
+} FSdCtrl_IsrCallbackSelect_t;
+
+/* voltage supply range type of SD Card follow POWER_CONTROLL_REG
+*/
+typedef enum
+{
+ FSDC_HIGH_V = 0, /* SD card operate within the voltage range of 2.7-3.6 V */
+ FSDC_DUAL_V, /* SD card operate within the Low Voltage Range (T.B.D) and 2.7-3.6 V */
+
+ MAX_FSDC_VOLTAGE_TYPE
+} FSdCtrl_VRangeType_t;
+
+/* read-write property of SD Card */
+typedef enum
+{
+ FSDC_RW_CARD = 0,
+ FSDC_RO_CARD,
+
+ MAX_FSDC_WR_CARD_TYPE
+} FSdCtrl_WRType_t;
+
+/* capacity type of SD Card */
+typedef enum
+{
+ FSDC_SD_CARD = 0,
+ FSDC_SDHC_CARD,
+ FSDC_SDXC_CARD,
+
+ MAX_FSDC_CARD_CAPACITY_TYPE
+} FSdCtrl_CapacityType_t;
+
+/* speed class of SD Card */
+typedef enum
+{
+ FSDC_CLASS0 = 0,
+ FSDC_CLASS2,
+ FSDC_CLASS4,
+ FSDC_CLASS6,
+
+ MAX_FSDC_CLASS_TYPE
+} FSdCtrl_ClassType_t;
+
+/**
+ * This typedef contains configuration information for the sd device.
+ */
+typedef struct
+{
+ u32 instanceId; /* Unique ID of device */
+ u32 baseAddress; /* Base address of the device */
+ u32 inputClockHz; /* Input clock frequency */
+ u32 cardDetect; /* Card Detect */
+ u32 writeProtect; /* Write Protect */
+ u32 busWidth; /* Bus Width */
+ u32 dmaIrqNum; /* dma irq number */
+ u32 normalIrqNum; /* normal irq number */
+ u32 errIrqNum; /* error irq number */
+ u8 workMode; /* Work mode for data transfers ,
+ If the mask bit is 0, polling is used ,
+ follow irq enable bits*/
+} FSdCtrl_Config_t;
+
+typedef void (*FtsdCtrl_irqCallback_t)(void *args);
+
+/* irq callback and iput args */
+typedef struct
+{
+ FtsdCtrl_irqCallback_t pDmaDataCallback; /* DMA data interrupt function pointer */
+ void *pDmaDataArgs;
+
+ FtsdCtrl_irqCallback_t pCmdCallback; /* Commond interrupt function pointer */
+ void *pCmdArgs;
+
+ FtsdCtrl_irqCallback_t pErrorCallback; /* Error interrupt function pointer */
+ void *pErrorArgs;
+} FSdCtrl_IrqConfig_t;
+
+typedef struct FtsdCtrl FtsdCtrl_t;
+typedef void (*pFtsdCtrl_delayTimer_t)(ft_base_t delayUs);
+typedef ft_error_t (*pFtsdCtrl_irqWaitCallback_t)(FtsdCtrl_t *FtsdCtrl);
+
+/* ctrl instance of sd */
+struct FtsdCtrl
+{
+ FSdCtrl_Config_t config;
+ u32 isReady; /* Device is initialized and ready */
+ /*************reserved**************/
+ FSdCtrl_VRangeType_t voltageType;
+ FSdCtrl_WRType_t writeReadType;
+ FSdCtrl_CapacityType_t capacityType;
+ FSdCtrl_ClassType_t speedClassType;
+ /*************reserved**************/
+ FSdCtrl_IrqConfig_t irqConfig;
+ pFtsdCtrl_irqWaitCallback_t writeWaitCallback; /* function pointer .Used to determine whether the data transmission is complete*/
+ pFtsdCtrl_irqWaitCallback_t readWaitCallback; /* function pointer .Used to determine whether the data received is complete*/
+ pFtsdCtrl_irqWaitCallback_t cmdWaitCallback; /* function pointer . Used to determine whether the command is complete */
+};
+
+u32 FSdCtrl_PrepareCmdRaw(FT_IN u32 cmdIndex, FT_IN u32 rspType);
+void FSdCtrl_WriteData(FT_INOUT FtsdCtrl_t *pFtsdCtrl, FT_IN UINTPTR dataAddr, FT_IN UINTPTR cmdArg, FT_IN u32 blkNum);
+void FSdCtrl_ReadData(FT_INOUT FtsdCtrl_t *pFtsdCtrl,
+ FT_IN UINTPTR dataAddr,
+ FT_IN UINTPTR cardAddr,
+ FT_IN u32 blkNum);
+ft_error_t FSdCtrl_WaitCmdEnd(FT_OUT FtsdCtrl_t *pFtsdCtrl,
+ FT_IN pFtsdCtrl_delayTimer_t pDelayTimer_fun,
+ FT_IN u32 rspType,
+ FT_OUT u32 *cmdRsp);
+ft_error_t FSdCtrl_WaitReadDataEnd(FT_INOUT FtsdCtrl_t *pFtsdCtrl,
+ FT_IN pFtsdCtrl_delayTimer_t pDelayTimer_fun,
+ FT_IN u32 blkNum);
+ft_error_t FSdCtrl_WaitWriteDataEnd(FT_INOUT FtsdCtrl_t *pFtsdCtrl,
+ FT_IN pFtsdCtrl_delayTimer_t pDelayTimer_fun,
+ FT_IN u32 blkNum);
+
+void FSdCtrl_DoCmd(FT_INOUT FtsdCtrl_t *pFtsdCtrl, FT_IN u32 cmdIndex, FT_IN u32 rspType, u32 arg);
+void FSdCtrl_DoACmd(FT_INOUT FtsdCtrl_t *pFtsdCtrl,
+ FT_IN u32 cmdIndex,
+ FT_IN u32 rspType,
+ u32 arg);
+void FSdCtrl_NormalIrq(FT_INOUT FtsdCtrl_t *pFtsdCtrl);
+void FSdCtrl_DmaIrq(FT_INOUT FtsdCtrl_t *pFtsdCtrl);
+void FSdCtrl_ErrIrq(FT_INOUT FtsdCtrl_t *pFtsdCtrl);
+bool_t FSdCtrl_CardDetect(FT_INOUT FtsdCtrl_t *pFtsdCtrl);
+
+FSdCtrl_Config_t *FSdCtrl_LookupConfig(u32 instanceId);
+/* This routine performs per device specific initialization of Phytium SDHC.*/
+ft_error_t FsdCtrl_Init(FT_INOUT FtsdCtrl_t *pFtsdCtrl);
+void FSdCtrl_ClkFreqSetup(FT_INOUT FtsdCtrl_t *pFtsdCtrl, FT_IN u32 sdClk);
+void FSdCtrl_ResetDma(FT_INOUT FtsdCtrl_t *pFtsdCtrl);
+/* reset sd ctrl during init */
+void FSdCtrl_Reset(FT_INOUT FtsdCtrl_t *pFtsdCtrl, pFtsdCtrl_delayTimer_t fDelayTimer);
+
+/* set irq call backs */
+ft_error_t FSdCtrl_SetHandler(FT_INOUT FtsdCtrl_t *pFtsdCtrl, FT_IN FSdCtrl_IrqCallbackSelect_t selectIndex,
+ void *FuncPtr,
+ void *Args);
+
+/* register call-backs to determinate wheather write、read and cmd is complete */
+void FSdCtrl_WriteWaitRegister(FT_INOUT FtsdCtrl_t *pFtsdCtrl, FT_IN pFtsdCtrl_irqWaitCallback_t callBack);
+void FSdCtrl_ReadWaitRegister(FT_INOUT FtsdCtrl_t *pFtsdCtrl, FT_IN pFtsdCtrl_irqWaitCallback_t callBack);
+void FSdCtrl_CmdWaitRegister(FT_INOUT FtsdCtrl_t *pFtsdCtrl, FT_IN pFtsdCtrl_irqWaitCallback_t callBack);
+void FSdCtrl_ErrWaitRegister(FT_INOUT FtsdCtrl_t *pFtsdCtrl, FT_IN pFtsdCtrl_irqWaitCallback_t callBack);
+
+/* get irq status */
+u32 FSdCtrl_GetNormalIrqStatus(FT_INOUT FtsdCtrl_t *pFtsdCtrl);
+u32 FSdCtrl_GetDataIrqStatus(FT_INOUT FtsdCtrl_t *pFtsdCtrl);
+u32 FSdCtrl_GetErrorIrqStatus(FT_INOUT FtsdCtrl_t *pFtsdCtrl);
+
+/* enable selected normal irq */
+void FSdCtrl_NormalIrqSet(FtsdCtrl_t *pFtsdCtrl, FT_IN FSdCtrl_NormalIrqSelect_t flgs);
+void FSdCtrl_BdIrqSet(FtsdCtrl_t *pFtsdCtrl, FT_IN FSdCtrl_BdIrqSelect flgs);
+
+#endif //
diff --git a/bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl_g.c b/bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl_g.c
new file mode 100644
index 0000000000..3492f89049
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl_g.c
@@ -0,0 +1,31 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-03-31 14:59:20
+ * @LastEditTime: 2021-05-24 14:34:13
+ * @Description:  This files is for sd ctrl config definition
+ *
+ * @Modify History: * * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_sdctrl.h"
+#include "ft_parameters.h"
+
+/* configs of sd ctrl */
+FSdCtrl_Config_t FSdCtrl_Config[FT_SDC_NUM] =
+ {
+ {
+ .instanceId = FT_SDC_INSTANCE,
+ .baseAddress = FT_SDC_BASEADDR,
+ .inputClockHz = FT_SDC_FREQ,
+ .cardDetect = 1,
+ .writeProtect = 0,
+ .busWidth = 1,
+ .dmaIrqNum = 52,
+ .normalIrqNum = 53,
+ .errIrqNum = 54,
+ .workMode = 0 /*FTSDCTRL_CMD_IRQ_MASK | FTSDCTRL_DATA_WRITE_IRQ_MASK | FTSDCTRL_DATA_READ_IRQ_MASK*/
+ }};
diff --git a/bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl_hw.c b/bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl_hw.c
new file mode 100644
index 0000000000..83a9c05dde
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl_hw.c
@@ -0,0 +1,41 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-03-31 14:59:20
+ * @LastEditTime: 2021-05-25 16:46:46
+ * @Description:  This files is for sd ctrl register-related implementations
+ *
+ * @Modify History: * * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_sdctrl_hw.h"
+#include "ft_sdctrl.h"
+
+#include "ft_io.h"
+#include "ft_types.h"
+#include "ft_assert.h"
+#include "ft_generic_timer.h"
+
+void FSdCtrl_Reset(FT_INOUT FtsdCtrl_t *pFtsdCtrl, pFtsdCtrl_delayTimer_t fDelayTimer)
+{
+ FSdCtrl_Config_t *pConfig;
+ Ft_assertVoid(FT_NULL != pFtsdCtrl);
+
+ pConfig = &pFtsdCtrl->config;
+ /* trigger software reset for 1us */
+ Ft_setBit32(pConfig->baseAddress + SOFTWARE_RESET_REG_OFFSET, SOFTWARE_RESET_SRST);
+ /* Wait for reset is ok */
+ Ft_GenericTimer_UsDelay(1);
+ Ft_clearBit32(pConfig->baseAddress + SOFTWARE_RESET_REG_OFFSET, SOFTWARE_RESET_SRST);
+
+ /* wait dat[0] to be high-lev */
+ while ((!(Ft_in32(pConfig->baseAddress + STATUS_REG) & STATUS_REG_DLSL(1))))
+ {
+ fDelayTimer(1);
+ }
+
+ return;
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl_hw.h b/bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl_hw.h
new file mode 100644
index 0000000000..931c3ad7db
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl_hw.h
@@ -0,0 +1,210 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-03-31 14:59:20
+ * @LastEditTime: 2021-04-19 16:17:39
+ * @Description:  This files is for sd ctrl register
+ *
+ * @Modify History: * * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef _SDCTRL_HW_H
+#define _SDCTRL_HW_H
+
+#include "ft_sdctrl.h"
+
+/* Register Offset */
+
+#define CONTROLL_SETTING_REG_OFFSET 0x00 /* Controller configuration register */
+#define ARGUMENT_REG_OFFSET 0x04 /* Parameter register */
+#define CMD_SETTING_REG_OFFSET 0x08 /* Command register */
+#define CLOCK_DIV_REG_OFFSET 0x0C /* Clock division register */
+#define SOFTWARE_RESET_REG_OFFSET 0x10 /* Reset control register */
+#define POWER_CONTROLL_REG_OFFSET 0x14 /* Power control register */
+#define TIMEOUT_CMD_REG_OFFSET 0x18 /* cmd Timeout setting register */
+#define TIMEOUT_DATA_REG_OFFSET 0x1C /* Data timeout setting register */
+#define NORMAL_INT_EN_REG_OFFSET 0x20 /* Interrupt Enable Register */
+#define ERROR_INT_EN_REG_OFFSET 0x24 /* error Interrupt Enable Register */
+#define BD_ISR_EN_REG_OFFSET 0x28 /* Data Transfer Interrupt Enable Register */
+#define CAPABILIES_REG_OFFSET 0x2c /* capabilies register */
+#define SD_DRV_REG_OFFSET 0x30 /* SD card driver phase register */
+#define SD_SAMP_REG_OFFSET 0x34 /* SD card sampling phase register */
+#define SD_SEN_REG_OFFSET 0x38 /* Card detection controller */
+#define HDS_AXI_REG_CONF1_OFFSET 0x3c /* AXI boundary configuration register 1 */
+#define DAT_IN_M_RX_BD 0x40 /* SD BD RX address register */
+#define DAT_IN_M_TX_BD 0x60 /* SD BD TX address register */
+#define BLK_CNT_REG 0x80 /* Block reads and writes configuration registers */
+#define HDS_AXI_REG_CONF2 0xa8 /* AXI boundary configuration register 2 */
+#define NORMAL_INT_STATUS_REG 0xc0 /* Interrupt status register */
+#define ERROR_INT_STATUS_REG 0xc4 /* ERROR interrupt register */
+#define BD_ISR_REG 0xc8 /* Data Transfer Interrupt Status Register */
+#define BD_STATUS 0xcc /* BD descriptor register */
+#define STATUS_REG 0xd0 /* state register */
+#define BLOCK 0xd4 /* Block length register */
+#define CMD_RESP_1 0xe0 /* Command response register 1 */
+#define CMD_RESP_2 0xe4 /* Command response register 2 */
+#define CMD_RESP_3 0xe8 /* Command response register 3 */
+#define CMD_RESP_4 0xec /* Command response register 4 */
+
+/* Controller configuration register */
+#define CONTROLL_SETTING_PERMDR(x) ((x & 3) << 8) /* Read operation corresponding to the size of the end selection: 00: small end alignment,01: large end alignment,10: SD protocol mode */
+#define CONTROLL_SETTING_PERMDW(x) ((x & 3) << 10) /* Write operation corresponding to the size of the endian selection: 00: small endian alignment 01: large endian alignment 10: SD protocol mode*/
+
+/* Parameter register */
+#define ARGUMENT_REG(x) (x & 0xffffffff)
+
+/* Command register */
+#define CMD_SETTING_RTS(x) ((x & 3) << 0) /* 0: No response 01: Response byte length 136 10: Response byte length 48 11: Response byte length 48 */
+#define CMD_SETTING_CRCE (1U << 3) /* 0: CRC check is not performed on CMD response 1: CRC check is performed on CMD response */
+#define CMD_SETTING_CICE (1U << 4) /* 0:CMD 响应时,不执行索引检查 1:CMD 响应时,执行索引检查 */
+#define CMD_SETTING_CMDW(x) ((x & 3) << 6)
+#define CMD_SETTING_CMDI(x) ((x & 0x3f) << 8) /* 命令索引 */
+#define CMD_SETTING_TRTY(x) ((x & 3) << 14) /* 10: adtc 指令 ,其它: 读写操作 */
+
+/* 时钟分频寄存器 */
+#define CLOCK_DIV_RE(x) (x & 0xffffffff) /* CLKD-时钟分频系数 SD_frequency= 600M/ (2*(clock_d+1)) */
+
+/* 复位控制寄存器 */
+#define SOFTWARE_RESET_SRST (1U) /* 控制器软复位 */
+#define SOFTWARE_RESET_BDRST (4U) /* DMA BD 清 0 */
+#define SOFTWARE_RESET_CFCLF (8U) /* 卡插入拔出状态触发标志清 0 */
+
+/* cmd 超时设置寄存器 */
+#define TIMEOUT_CMD_REG(x) (x & 0xffffffff) /* command 超时参数 */
+
+/* 数据超时设置寄存器 */
+#define TIMEOUT_DATA_REG(x) (x & 0xffffffff) /* data 超时参数 */
+
+/* 中断使能寄存器 */
+#define NORMAL_INT_EN_ECC 1U /* 命令完成中断使能 */
+#define NORMAL_INT_EN_ECCRCE 2U /* 卡拔出中断使能 */
+#define NORMAL_INT_EN_ECIE (1U << 15) /* 错误中断使能 */
+
+/* error 中断使能寄存器 */
+#define ERROR_INT_EN_CNR (1U << 4) /* Command response error interrupted */
+#define ERROR_INT_EN_CIR (1U << 3) /* 命令索引错误中断使能 */
+#define ERROR_INT_EN_CCRCE (1U << 1) /* 命令 CRC 错误中断使能 */
+#define ERROR_INT_EN_CTE (1U << 0) /* 命令超时中断使能 */
+
+/* 数据传输中断使能寄存器 */
+#define BD_ISR_EN_ETRS (1U << 0) /* DMA 传输完成中断使能 */
+#define BD_ISR_EN_EDTE (1U << 3) /* 数据超时中断使能 */
+#define BD_ISR_EN_ECMDE (1U << 4) /* 命令响应错误中断使能 */
+#define BD_ISR_EN_ETRE (1U << 5) /* 传输错误中断使能 */
+#define BD_ISR_EN_ENRCRCE (1U << 6) /* CRC 校验错误中断使能 */
+#define BD_ISR_EN_EDATFRAXE (1U << 7) /* AXI 总线错误中断使能 */
+#define BD_ISR_EN_RESPE (1U << 8) /* 读 SD 卡操作,AXI BR 通道完成中断 */
+#define BD_ISR_EN_EDAISE (1U << 15) /* DMA 错误中断使能 */
+#define BD_ISR_ALL_MASK (BD_ISR_EN_ETRS | BD_ISR_EN_EDTE | \
+ BD_ISR_EN_ECMDE | BD_ISR_EN_ETRE | \
+ BD_ISR_EN_ENRCRCE | BD_ISR_EN_EDATFRAXE | \
+ BD_ISR_EN_RESPE | BD_ISR_EN_EDAISE)
+
+/* 状态寄存器 */
+#define CAPABILIES_REG(x) (x & 0xffffffff)
+
+/* SD 卡驱动相位寄存器 */
+#define SD_DRV_REG(x) (x & 0xffffffff) /* 卡驱动相位配置参数 */
+
+/* SD 卡采样相位寄存器 */
+#define SD_SAMP_REG(x) (x & 0xffffffff) /* 卡采样相位配置参数 */
+#define SD_SAMP_DEFAULT 11 /* when SD card work in high-speed mode, \
+ the best sampling pharse is needed to \
+ get the correct data */
+#define SD_FRRQ_DIV_DEFAULT 5 /* default freq div */
+#define SD_CLK_FREQ_400KHZ 400000
+#define SD_CLK_FREQ_25MHZ 25000000
+
+/* 卡检测控制器 */
+#define SD_SEN_REG_CREFR (1U << 1) /* 卡拔出时自动释放 AXI 总线选择 */
+#define SD_SEN_REG_CRES (1U << 2) /* CARD 在位状态标志选择 0: 卡在位-0,不在位-1 1: 卡在位-1,不在位-0 */
+#define SD_SEN_REG_DEBNCE(x) ((x & 0xffffff) << 8) /* 去抖时钟分频参数 */
+
+/* AXI 边界配置寄存器 1 */
+#define HDS_AXI_REG_CONF1_AWDOMAIN_HDS_M(x) ((x & 0x3) << 0)
+#define HDS_AXI_REG_CONF1_AWBAR_HDS_M(x) ((x & 0x3) << 2)
+#define HDS_AXI_REG_CONF1_ARSNOOP_HDS_M(x) ((x & 0xf) << 4)
+#define HDS_AXI_REG_CONF1_ARREGION_HDS_M(x) ((x & 0xf) << 8)
+#define HDS_AXI_REG_CONF1_ARDOMAIN_HDS_M(x) ((x & 0x3) << 12)
+#define HDS_AXI_REG_CONF1_ARBAR_HDS_M(x) ((x & 0x3) << 14)
+#define HDS_AXI_REG_CONF1_AWSNOOP_HDS_M(x) ((x & 0x7) << 16)
+#define HDS_AXI_REG_CONF1_AWREGION_HDS_M(x) ((x & 0xF) << 19)
+
+/* SD BD RX 地址寄存器 */
+#define DAT_IN_M_RX_BD_MASK(x) (x & 0xffffffff) /* dma 读卡地址配置:4 个 cycle ,系统低 4B-系统高 4B-SD 低 4B- SD 高 4B */
+
+/* SD BD TX 地址寄存器 */
+#define DAT_IN_M_TX_BD_MASK(x) (x & 0xffffffff) /* dma 写卡地址配置:4 个 cycle ,系统低 4B-系统高 4B-SD 低 4B- SD 高 4B */
+
+/* 块读写配置寄存器 */
+#define BLK_CNT(x) (x & 0xffffffff) /* dma block num setting */
+
+/* AXI 边界配置寄存器 2 */
+#define HDS_AXI_REG_CONF2_D_ARPROT(x) ((x & 0x7) << 27)
+#define HDS_AXI_REG_CONF2_SD_AWPROT(x) ((x & 0x7) << 24)
+#define HDS_AXI_REG_CONF2_SD_ARCACHE_M(x) ((x & 0xf) << 20)
+#define HDS_AXI_REG_CONF2_SD_AWCACHE_M(x) ((x & 0xf) << 16)
+#define HDS_AXI_REG_CONF2_RESERVED(x) ((x & 0x3) << 14)
+#define HDS_AXI_REG_CONF2_HDA_ARPRO(x) ((x & 0x7) << 11)
+#define HDS_AXI_REG_CONF2_HDA_AWPROT(x) ((x & 0x7) << 8)
+#define HDS_AXI_REG_CONF2_HDA_ARCACHE_M(x) ((x & 0xf) << 4)
+#define HDS_AXI_REG_CONF2_HDA_AWCACHE_M(x) ((x & 0xf) << 0)
+
+/* 中断状态寄存器 */
+#define NORMAL_INT_STATUS_EI (1U << 15) /* 命令错误中断 */
+#define NORMAL_INT_STATUS_CR (1U << 1) /* 卡移除中断 */
+#define NORMAL_INT_STATUS_CC 1U /* 命令完成中断 */
+#define NORMAL_INT_STATUS_ALL_MASK (NORMAL_INT_STATUS_EI | NORMAL_INT_STATUS_CR | NORMAL_INT_STATUS_CC)
+
+/* error 中断寄存器 */
+#define ERROR_INT_STATUS_CNR (1U << 4) /* 命令响应错误中断 */
+#define ERROR_INT_STATUS_CIR (1U << 3) /* 命令索引错误中断 */
+#define ERROR_INT_STATUS_CCRCE (1U << 1) /* 命令 CRC 错误中断 */
+#define ERROR_INT_STATUS_CTE 1U /* 命令超时错误中断 */
+#define ERROR_INT_STATUS_ALL_MASK (ERROR_INT_STATUS_CNR | ERROR_INT_STATUS_CIR | ERROR_INT_STATUS_CCRCE | ERROR_INT_STATUS_CTE)
+
+/* 数据传输中断状态寄存器 */
+#define BD_ISR_REG_DAIS (1U << 15) /* DMA 错误中断*/
+#define BD_ISR_REG_RESPE (1U << 8) /* 读 SD 卡操作,AXI BR 通道完成中断*/
+#define BD_ISR_REG_DATFRAX (1U << 7) /* axi 总线强制释放中断*/
+#define BD_ISR_REG_NRCRC (1U << 6) /* 无 CRC 响应中断*/
+#define BD_ISR_REG_TRE (1U << 5) /* CRC 响应错误中断*/
+#define BD_ISR_REG_CMDE (1U << 4) /* 命令响应错误中断*/
+#define BD_ISR_REG_DTE (1U << 3) /* 超时中断*/
+#define BD_ISR_REG_TRS (1U << 0) /* DMA 传输完成中断*/
+
+/* bd 描述符寄存器 */
+#define BD_STATUS_REG(x) (x & 0xffffffff) /* bd 描述符寄存器 */
+
+/* 状态寄存器 */
+#define STATUS_REG_DATMAST(x) ((x & 0xf) << 27) /* data_master 状态机 */
+#define STATUS_REG_CDIF (1U << 26) /* 卡在位标志 */
+#define STATUS_REG_CDRF (1U << 25) /* 卡不在位标志 */
+#define STATUS_REG_CLSL (1U << 24) /* 命令闲信号 */
+#define STATUS_REG_DLSL(x) ((x & 0xf) << 20) /* 线信号 */
+#define STATUS_REG_CDSL (1U << 19) /* 卡检测管脚信号 */
+#define STATUS_REG_CST(x) ((x & 0xf) << 12) /* cmd_host state 状态机 */
+#define STATUS_REG_CSM(x) ((x & 0X1F) << 7)
+#define STATUS_REG_DAT_AVA (1 << 6) /* DAT_AVA 当前命令状态流程运转完 */
+#define STATUS_REG_CRC_VALID (1 << 5)
+#define STATUS_REG_CICMD 1U /* RO 0x0 CMD 总线状态 */
+
+/* 块长度寄存器 */
+#define BLOCK_RGE(x) (x & 0xffffffff) /* 块长度寄存器 */
+
+/* 命令响应寄存器 1 */
+#define CMD_RESP_1_REG(x) (x & 0xffffffff)
+
+/* 命令响应寄存器 2 */
+#define CMD_RESP_2_REG(x) (x & 0xffffffff)
+
+/* 命令响应寄存器 3 */
+#define CMD_RESP_3_REG(x) (x & 0xffffffff)
+
+/* 命令响应寄存器 4 */
+#define CMD_RESP_4_REG(x) (x & 0xffffffff)
+
+#endif // !
diff --git a/bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl_intr.c b/bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl_intr.c
new file mode 100644
index 0000000000..88bbc41f53
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl_intr.c
@@ -0,0 +1,110 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-03-31 14:59:20
+ * @LastEditTime: 2021-05-25 16:46:54
+ * @Description:  This files is for sd ctrl irq handling
+ *
+ * @Modify History: * * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_sdctrl.h"
+#include "ft_sdctrl_hw.h"
+#include "ft_assert.h"
+#include "ft_types.h"
+#include "ft_io.h"
+#include "ft_printf.h"
+#include "ft_debug.h"
+
+#ifndef LOG_LOCAL_LEVEL
+#define LOG_LOCAL_LEVEL FT_LOG_NONE
+#endif
+#define FT_SD_CTRL_DEBUG_I(format, ...) FT_DEBUG_PRINT_I(FT_SD_CTRL_DEBUG_TAG, format, ##__VA_ARGS__)
+#define FT_SD_CTRL_DEBUG_E(format, ...) FT_DEBUG_PRINT_E(FT_SD_CTRL_DEBUG_TAG, format, ##__VA_ARGS__)
+#define FT_SD_CTRL_DEBUG_W(format, ...) FT_DEBUG_PRINT_W(FT_SD_CTRL_DEBUG_TAG, format, ##__VA_ARGS__)
+
+void FSdCtrl_NormalIrq(FT_INOUT FtsdCtrl_t *pFtsdCtrl)
+{
+ FSdCtrl_Config_t *pConfig;
+ FSdCtrl_IrqConfig_t *irqConfig;
+ Ft_assertVoid(FT_NULL != pFtsdCtrl);
+ pConfig = &pFtsdCtrl->config;
+ irqConfig = &pFtsdCtrl->irqConfig;
+
+ //FT_SD_CTRL_DEBUG_I("enter cmd irq procedure\r\n");
+ if (irqConfig->pCmdCallback)
+ {
+ irqConfig->pCmdCallback(irqConfig->pCmdArgs);
+ }
+
+ /* clear interrupts */
+ Ft_out32(pConfig->baseAddress + NORMAL_INT_STATUS_REG, NORMAL_INT_STATUS_ALL_MASK);
+ Ft_out32(pConfig->baseAddress + NORMAL_INT_STATUS_REG, 0);
+}
+
+void FSdCtrl_DmaIrq(FT_INOUT FtsdCtrl_t *pFtsdCtrl)
+{
+ FSdCtrl_Config_t *pConfig;
+ FSdCtrl_IrqConfig_t *irqConfig;
+ Ft_assertVoid(FT_NULL != pFtsdCtrl);
+ pConfig = &pFtsdCtrl->config;
+ irqConfig = &pFtsdCtrl->irqConfig;
+
+ if (irqConfig->pDmaDataCallback)
+ {
+ irqConfig->pDmaDataCallback(irqConfig->pDmaDataArgs);
+ }
+
+ /* clear interrupts */
+ Ft_out32(pConfig->baseAddress + BD_ISR_REG, BD_ISR_ALL_MASK);
+ Ft_out32(pConfig->baseAddress + BD_ISR_REG, 0);
+}
+
+void FSdCtrl_ErrIrq(FT_INOUT FtsdCtrl_t *pFtsdCtrl)
+{
+ FSdCtrl_Config_t *pConfig;
+ FSdCtrl_IrqConfig_t *irqConfig;
+ Ft_assertVoid(FT_NULL != pFtsdCtrl);
+ pConfig = &pFtsdCtrl->config;
+ irqConfig = &pFtsdCtrl->irqConfig;
+
+ if (irqConfig->pErrorCallback)
+ {
+ irqConfig->pErrorCallback(irqConfig->pErrorArgs);
+ }
+
+ /* clear interrupts */
+ Ft_out32(pConfig->baseAddress + ERROR_INT_STATUS_REG, ERROR_INT_STATUS_ALL_MASK);
+ Ft_out32(pConfig->baseAddress + ERROR_INT_STATUS_REG, 0);
+}
+
+ft_error_t FSdCtrl_SetHandler(FT_INOUT FtsdCtrl_t *pFtsdCtrl, FT_IN FSdCtrl_IrqCallbackSelect_t selectIndex,
+ void *FuncPtr, void *Args)
+{
+ Ft_assertNonvoid(pFtsdCtrl != NULL);
+ Ft_assertNonvoid(FuncPtr != NULL);
+ Ft_assertNonvoid(pFtsdCtrl->isReady == FT_COMPONENT_IS_READLY);
+
+ switch (selectIndex)
+ {
+ case FTSDCTRL_DMADATAIRQID:
+ pFtsdCtrl->irqConfig.pDmaDataCallback = FuncPtr;
+ pFtsdCtrl->irqConfig.pDmaDataArgs = Args;
+ break;
+ case FTSDCTRL_CMDIRQID:
+ pFtsdCtrl->irqConfig.pCmdCallback = FuncPtr;
+ pFtsdCtrl->irqConfig.pCmdArgs = Args;
+ break;
+ case FTSDCTRL_ERRORIRQID:
+ pFtsdCtrl->irqConfig.pErrorCallback = FuncPtr;
+ pFtsdCtrl->irqConfig.pErrorArgs = Args;
+ break;
+ default:
+ return FTSDC_FAILURE;
+ }
+
+ return FTSDC_SUCCESS;
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl_option.c b/bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl_option.c
new file mode 100644
index 0000000000..0799b0be4c
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl_option.c
@@ -0,0 +1,61 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-03-31 14:59:20
+ * @LastEditTime: 2021-05-25 16:47:05
+ * @Description:  This files is for sd ctrl option setting
+ *
+ * @Modify History: * * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_sdctrl.h"
+#include "ft_sdctrl_hw.h"
+#include "ft_types.h"
+#include "ft_io.h"
+#include "ft_printf.h"
+#include "ft_assert.h"
+
+void FSdCtrl_NormalIrqSet(FtsdCtrl_t *pFtsdCtrl, FT_IN FSdCtrl_NormalIrqSelect_t flgs)
+{
+ FSdCtrl_Config_t *pConfig;
+ u32 regValue;
+ Ft_assertVoid(FT_NULL != pFtsdCtrl);
+ pConfig = &pFtsdCtrl->config;
+
+ /* */
+ regValue = ((flgs & NORMAL_IRQ_CC) ? NORMAL_INT_EN_ECC : 0) | ((flgs & NORMAL_IRQ_CR) ? NORMAL_INT_EN_ECCRCE : 0) |
+ ((flgs & NORMAL_IRQ_EI) ? NORMAL_INT_EN_ECIE : 0);
+
+ Ft_out32(pConfig->baseAddress + NORMAL_INT_EN_REG_OFFSET, regValue);
+}
+
+void FsdCtrl_errorIrqSet(FtsdCtrl_t *pFtsdCtrl, FT_IN FSdCtrl_ErrorIrqSelect_t flgs)
+{
+ FSdCtrl_Config_t *pConfig;
+ u32 regValue;
+ Ft_assertVoid(FT_NULL != pFtsdCtrl);
+ pConfig = &pFtsdCtrl->config;
+
+ regValue = ((flgs & ERROR_IRQ_CTE) ? ERROR_INT_EN_CTE : 0) | ((flgs & ERROR_IRQ_CCRCE) ? ERROR_INT_EN_CCRCE : 0) |
+ ((flgs & ERROR_IRQ_CIR) ? ERROR_INT_EN_CIR : 0) | ((flgs & ERROR_IRQ_CNR) ? ERROR_INT_EN_CNR : 0);
+
+ Ft_out32(pConfig->baseAddress + ERROR_INT_EN_REG_OFFSET, regValue);
+}
+
+void FSdCtrl_BdIrqSet(FtsdCtrl_t *pFtsdCtrl, FT_IN FSdCtrl_BdIrqSelect flgs)
+{
+ FSdCtrl_Config_t *pConfig;
+ u32 regValue;
+ Ft_assertVoid(FT_NULL != pFtsdCtrl);
+ pConfig = &pFtsdCtrl->config;
+
+ regValue = ((flgs & BD_IRQ_TRS) ? BD_ISR_EN_ETRS : 0) | ((flgs & BD_IRQ_DTE) ? BD_ISR_EN_EDTE : 0) |
+ ((flgs & BD_IRQ_CMDE) ? BD_ISR_EN_ECMDE : 0) | ((flgs & BD_IRQ_TRE) ? BD_ISR_EN_ETRE : 0) |
+ ((flgs & BD_IRQ_NRCRC) ? BD_ISR_EN_ENRCRCE : 0) | ((flgs & BD_IRQ_DATFRAX) ? BD_ISR_EN_EDATFRAXE : 0) |
+ ((flgs & BD_IRQ_RESPE) ? BD_ISR_EN_RESPE : 0) | ((flgs & BD_IRQ_DAIS) ? BD_ISR_EN_EDAISE : 0);
+
+ Ft_out32(pConfig->baseAddress + BD_ISR_EN_REG_OFFSET, regValue);
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl_sinit.c b/bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl_sinit.c
new file mode 100644
index 0000000000..47827413d2
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_sd/ft_sdctrl_sinit.c
@@ -0,0 +1,33 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-03-31 14:59:20
+ * @LastEditTime: 2021-05-25 16:47:14
+ * @Description:  This files is for sd ctrl static initialization
+ *
+ * @Modify History: * * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_sdctrl.h"
+#include "ft_parameters.h"
+
+extern FSdCtrl_Config_t FSdCtrl_Config[FT_SDC_NUM];
+
+FSdCtrl_Config_t *FSdCtrl_LookupConfig(u32 instanceId)
+{
+ FSdCtrl_Config_t *CfgPtr = NULL;
+ u32 Index;
+ for (Index = 0; Index < (u32)FT_GMAC_INSTANCES_NUM; Index++)
+ {
+ if (FSdCtrl_Config[Index].instanceId == instanceId)
+ {
+ CfgPtr = &FSdCtrl_Config[Index];
+ break;
+ }
+ }
+
+ return (FSdCtrl_Config_t *)CfgPtr;
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_spi/ft_spi.c b/bsp/ft2004/libraries/bsp/ft_spi/ft_spi.c
new file mode 100644
index 0000000000..cc2a74a045
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_spi/ft_spi.c
@@ -0,0 +1,192 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-25 14:00:25
+ * @LastEditTime: 2021-05-24 14:34:28
+ * @Description:  This files is for
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_assert.h"
+#include "ft_spi.h"
+#include "ft_spi_hw.h"
+#include "ft_generic_timer.h"
+#include "ft_gpio.h"
+
+void FSpi_DumpAllStatus(FT_IN FSpi_Ctrl_t *pCtrl, FT_IN char *tag)
+{
+ FT_SPI_DEBUG_I("***%s status******\r\n", tag);
+ FT_SPI_DEBUG_I("busy: %d", SPI_STATUS_REG(pCtrl)->val.Busy);
+ FT_SPI_DEBUG_I("tx fifo not empty: %d", SPI_STATUS_REG(pCtrl)->val.Tfnf);
+ FT_SPI_DEBUG_I("tx fifo empty: %d", SPI_STATUS_REG(pCtrl)->val.Tfe);
+ FT_SPI_DEBUG_I("rx fifo not empty: %d", SPI_STATUS_REG(pCtrl)->val.Rfne);
+ FT_SPI_DEBUG_I("rx fifo full: %d", SPI_STATUS_REG(pCtrl)->val.Rff);
+ FT_SPI_DEBUG_I("trans error: %d", SPI_STATUS_REG(pCtrl)->val.Txe);
+ FT_SPI_DEBUG_I("trans conflict error: %d", SPI_STATUS_REG(pCtrl)->val.Dcol);
+}
+
+u32 FSpi_ReadWriteByte(FT_INOUT FSpi_Ctrl_t *pCtrl, FT_IN u8 TxData,
+ FT_OUT u8 *pRxData)
+{
+ u32 Retry = 0;
+ u32 Ret = ERR_SPI_OK;
+ u16 RxData;
+
+ if (!pCtrl->IsReady)
+ {
+ return ERR_SPI_NOT_READY;
+ }
+
+ while (FSPI_TX_FIFO_NOT_EMPTY(pCtrl))
+ {
+ //Ft_GenericTimer_UsDelay(2);
+ if ((Retry++) > SPI_TIMEOUT)
+ {
+ Ret = ERR_SPI_TX_TIMEOUT;
+ goto __EXIT;
+ }
+ }
+ FSPI_WRITE_DATA(pCtrl, (u16)TxData);
+
+ Retry = 0;
+
+ while (FSPI_RX_FIFO_EMPTY(pCtrl))
+ {
+ //Ft_GenericTimer_UsDelay(2);
+ if ((Retry++) > SPI_TIMEOUT)
+ {
+ Ret = ERR_SPI_RX_TIMEOUT;
+ goto __EXIT;
+ }
+ }
+ RxData = FSPI_READ_DATA(pCtrl);
+
+ if (pRxData)
+ {
+ *pRxData = (u8)RxData;
+ }
+
+__EXIT:
+ return Ret;
+}
+
+u32 FSpi_Init(FT_INOUT FSpi_Ctrl_t *pCtrl)
+{
+ u32 Ret = ERR_SPI_OK;
+
+ FSPI_DISABLE(pCtrl);
+
+ /* config spi ctrl register */
+ SPI_CTRL0_REG(pCtrl)->val.Dfs = SPI_DFS_DEFAULT;
+ SPI_CTRL0_REG(pCtrl)->val.Frf = SPI_FRF_DEFAULT;
+
+ if (SPI_CTRL_CPHA_1EDGE == pCtrl->Config.Cpha)
+ {
+ SPI_CTRL0_REG(pCtrl)->val.Scph = SPI_SCPH_SW_CLK_AT_DATA_BEG;
+ }
+ else if (SPI_CTRL_CPHA_2EDGE == pCtrl->Config.Cpha)
+ {
+ SPI_CTRL0_REG(pCtrl)->val.Scph = SPI_SCPH_SW_CLK_AT_DATA_MID;
+ }
+ else
+ {
+ Ft_assertNoneReturn(0);
+ }
+
+ if (SPI_CTRL_CPOL_LOW == pCtrl->Config.Cpol)
+ {
+ SPI_CTRL0_REG(pCtrl)->val.Scpol = SPI_SCPOL_NOT_ACT_LOW;
+ }
+ else if (SPI_CTRL_CPOL_HIGH == pCtrl->Config.Cpol)
+ {
+ SPI_CTRL0_REG(pCtrl)->val.Scpol = SPI_SCPOL_NOT_ACT_HIGH;
+ }
+ else
+ {
+ Ft_assertNoneReturn(0);
+ }
+
+ SPI_CTRL0_REG(pCtrl)->val.Tmod = SPI_TMOD_TX_RX_MODE;
+ SPI_CTRL0_REG(pCtrl)->val.SlvOE = SPI_SLV_OE_DISABLE;
+ SPI_CTRL0_REG(pCtrl)->val.Srl = SPI_SRL_NORMAL_MODE;
+ SPI_CTRL0_REG(pCtrl)->val.Cfs = SPI_CFS_DEFAULT;
+
+ /* config spi clock */
+ FSPI_SET_BAUDR(pCtrl, pCtrl->Config.BaudRDiv);
+
+ /* config rx and tx fifo, fifo depth to trigger intr */
+ SPI_TXFTL_REG(pCtrl)->val.Tft = 0;
+ SPI_RXFTL_REG(pCtrl)->val.Rft = 0;
+ SPI_TXFL_REG(pCtrl)->val.Txtfl = 0;
+ SPI_RXFL_REG(pCtrl)->val.Rxtfl = 0;
+
+ SPI_RXSAMPLE_DLY_REG(pCtrl)->val.Rsd = SPI_DEFAULT_RSD;
+
+ FSPI_ENABLE(pCtrl);
+
+ /* set spi ready flag */
+ if (ERR_SPI_OK == Ret)
+ {
+ pCtrl->IsReady = TRUE;
+ }
+
+ return Ret;
+}
+
+static void FSpi_ToggleCSPin(FT_INOUT FSpi_Ctrl_t *pCtrl, FT_IN FSpi_DevId_t DevId,
+ FT_IN bool_t select)
+{
+ u32 setVal = ((TRUE == select) ? GPIO_OFF : GPIO_ON);
+
+ Ft_assertNoneReturn(NULL != pCtrl);
+
+ if (FGpio_ReadPinA(GPIO_CTRL_ID_1, pCtrl->CsPin) != setVal)
+ {
+ FGpio_WritePinA(GPIO_CTRL_ID_1, pCtrl->CsPin, setVal);
+ }
+
+ Ft_GenericTimer_UsDelay(10);
+ return;
+}
+
+void FSpi_SelectSlave(FT_INOUT FSpi_Ctrl_t *pCtrl, FT_IN FSpi_DevId_t DevId,
+ FT_IN bool_t select)
+{
+ FSpi_SeReg_t *pSelReg;
+ u32 setVal = ((TRUE == select) ? SPI_SE_SELECTED : SPI_SE_UNSELECTED);
+
+ FSPI_DISABLE(pCtrl);
+ /* enable or disable specific spi slave device */
+ pSelReg = SPI_SE_REG(pCtrl);
+ switch (DevId)
+ {
+ case SPI_DEV_ID_0:
+ pSelReg->val.SelSlave_0 = setVal;
+ break;
+ case SPI_DEV_ID_1:
+ pSelReg->val.SelSlave_1 = setVal;
+ Ft_assertNoneReturn(0);
+ break;
+ case SPI_DEV_ID_2:
+ pSelReg->val.SelSlave_2 = setVal;
+ Ft_assertNoneReturn(0);
+ break;
+ case SPI_DEV_ID_3:
+ pSelReg->val.SelSlave_3 = setVal;
+ Ft_assertNoneReturn(0);
+ break;
+ default:
+ Ft_assertNoneReturn(0);
+ break;
+ }
+
+ FSpi_ToggleCSPin(pCtrl, DevId, select);
+ FSPI_ENABLE(pCtrl);
+
+ return;
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_spi/ft_spi.h b/bsp/ft2004/libraries/bsp/ft_spi/ft_spi.h
new file mode 100644
index 0000000000..15893f0eaa
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_spi/ft_spi.h
@@ -0,0 +1,95 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-25 13:59:05
+ * @LastEditTime: 2021-04-30 16:11:46
+ * @Description:  This files is for
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef FT_BSP_SPI_H
+#define FT_BSP_SPI_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "ft_types.h"
+#include "ft_spi_hw.h"
+#include "ft_error_code.h"
+#include "ft_debug.h"
+
+ typedef struct
+ {
+ u8 WorkMode;
+#define SPI_CTRL_MASTER_MODE (u8)0x0
+#define SPI_CTRL_SLAVE_MODE (u8)0x1
+ u8 DevAddrLen;
+#define SPI_3_BYTE_ADDR (u8)0x3
+#define SPI_4_BYTE_ADDR (u8)0x4
+ u8 Cpol;
+#define SPI_CTRL_CPOL_LOW (u8)0x0
+#define SPI_CTRL_CPOL_HIGH (u8)0x1
+ u8 Cpha;
+#define SPI_CTRL_CPHA_1EDGE (u8)0x0
+#define SPI_CTRL_CPHA_2EDGE (u8)0x1
+ u8 DevAddr[4];
+ u32 BaudRDiv;
+ } FSpi_Conf_t;
+
+ typedef struct
+ {
+ FSpi_Conf_t Config;
+ FSpi_CtrlId_t CtrlId;
+ FSpi_DevId_t DevId; /* support only one slave at the moment */
+ bool_t IsReady;
+ u16 CsPin; /* cs pin in gpio group A */
+ } FSpi_Ctrl_t;
+
+/* misc marco */
+#define SPI_TIMEOUT 5000
+#define SPI_DUMMY_TX_DATA 0xFF
+
+/* ctrl member shortcut */
+#define FSPI_DEV_ADDR_LEN(pCtrl) (pCtrl->Config.DevAddrLen)
+#define FSPI_IS_3_BYTE_ADDR(pCtrl) (SPI_3_BYTE_ADDR == FSPI_DEV_ADDR_LEN(pCtrl))
+#define FSPI_DEV_ADDR(pCtrl) (pCtrl->Config.DevAddr)
+
+/* define error code */
+#define ERR_SPI_OK ERR_SUCCESS
+#define ERR_SPI_GENERAL FT_CODE_ERR(ERR_MODE_SPI, 0, 1)
+#define ERR_SPI_NOT_READY FT_CODE_ERR(ERR_MODE_SPI, 0, 2)
+#define ERR_SPI_TX_TIMEOUT FT_CODE_ERR(ERR_MODE_SPI, 0, 3)
+#define ERR_SPI_RX_TIMEOUT FT_CODE_ERR(ERR_MODE_SPI, 0, 4)
+
+/* spi flash error code */
+#define ERR_SPI_WAIT_TIMEOUT FT_CODE_ERR(ERR_MODE_SPI, 1, 1)
+
+/* define debug utilities */
+#define FT_SPI_DEBUG_TAG "FT_SPI"
+#define FT_SPI_ENABLE_DEBUG
+#define FT_SPI_ERROR(format, ...) FT_DEBUG_PRINT_E(FT_SPI_DEBUG_TAG, format, ##__VA_ARGS__)
+#ifdef FT_SPI_ENABLE_DEBUG
+#define FT_SPI_DEBUG_I(format, ...) FT_DEBUG_PRINT_I(FT_SPI_DEBUG_TAG, format, ##__VA_ARGS__)
+#define FT_SPI_DEBUG_W(format, ...) FT_DEBUG_PRINT_W(FT_SPI_DEBUG_TAG, format, ##__VA_ARGS__)
+#else
+#define FT_SPI_DEBUG_I(format, ...)
+#define FT_SPI_DEBUG_W(format, ...)
+#endif
+
+ u32 FSpi_Init(FT_INOUT FSpi_Ctrl_t *pCtrl);
+ u32 FSpi_ReadWriteByte(FT_INOUT FSpi_Ctrl_t *pCtrl, FT_IN u8 TxData,
+ FT_OUT u8 *pRxData);
+ void FSpi_SelectSlave(FT_INOUT FSpi_Ctrl_t *pCtrl, FT_IN FSpi_DevId_t DevId,
+ FT_IN bool_t select);
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/bsp/ft2004/libraries/bsp/ft_spi/ft_spi_hw.h b/bsp/ft2004/libraries/bsp/ft_spi/ft_spi_hw.h
new file mode 100644
index 0000000000..b4872e0de3
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_spi/ft_spi_hw.h
@@ -0,0 +1,330 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-25 13:59:44
+ * @LastEditTime: 2021-04-30 15:42:30
+ * @Description:  This files is for
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+#ifndef FT_BSP_SPI_HW_H
+#define FT_BSP_SPI_HW_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "ft_types.h"
+
+/* offset map of SPI register */
+#define SPI_CTRL_R0 0x00 //Ctrl register 0
+#define SPI_CTRL_R1 0x04 //Ctrl register 1
+#define SPI_SSI_EN_R 0x08 //SPI enable register
+#define SPI_MW_CR 0x0c //Microwire ctrl register
+#define SPI_SE_R 0x10 //Slave enable register
+#define SPI_BAUD_R 0x14 //Baudrate set register
+#define SPI_TXFTL_R 0x18 //Tx threshold register
+#define SPI_RXFTL_R 0x1c //Rx threshold register
+#define SPI_TXFL_R 0x20 //Tx level register
+#define SPI_RXFL_R 0x24 //Rx level register
+#define SPI_S_R 0x28 //Status register
+#define SPI_IM_R 0x2c //Intr mask register
+#define SPI_RIS_R 0x34 //Intr status register
+#define SPI_TXOI_CR 0x38 //TX FIFO overflow intr clear register
+#define SPI_RXOI_CR 0x3c //RX FIFO overflow intr clear register
+#define SPI_RXUI_CR 0x40 //TX FIFO underflow intr clear register
+#define SPI_MSTI_CR 0x44 //Multi slave intr clear register
+#define SPI_IC_R 0x48 //Intr clear register
+#define SPI_DMA_CR 0x4c //DMA ctrl register
+#define SPI_DMA_TDL_R 0x50 //DMA TX Data level register
+#define SPI_DMA_RDL_R 0x54 //DMA RX Data level register
+#define SPI_ID_R 0x58 //Identification register
+#define SPI_D_R 0xec //Data register
+#define SPI_RX_SAMPLE_DLY 0xfc //RX Data delay register
+
+ typedef enum
+ {
+ SPI_CTRL_ID_0 = 0,
+ SPI_CTRL_ID_1,
+
+ NUM_OF_SPI_CTRL,
+ } FSpi_CtrlId_t;
+
+ typedef enum
+ {
+ SPI_DEV_ID_0 = 0,
+ SPI_DEV_ID_1,
+ SPI_DEV_ID_2,
+ SPI_DEV_ID_3,
+
+ NUM_OF_SPI_DEV,
+ } FSpi_DevId_t;
+
+ /* base address of SPI register */
+ const static u32 g_SpiBaseAddr[NUM_OF_SPI_CTRL] = {0x2800c000, 0x28013000};
+
+ typedef union
+ {
+ u32 data;
+ struct
+ {
+ u32 Dfs : 4; /* 3:0, select data length */
+#define SPI_DFS_DEFAULT 0x7
+ u32 Frf : 2; /* 5:4, selcet trans mode */
+#define SPI_FRF_DEFAULT 0x0
+ u32 Scph : 1; /* 6, serial clock phase */
+#define SPI_SCPH_SW_CLK_AT_DATA_MID 0x0 /* second edge */
+#define SPI_SCPH_SW_CLK_AT_DATA_BEG 0x1 /* first edge */
+ u32 Scpol : 1; /* 7, serial clock Polarity */
+#define SPI_SCPOL_NOT_ACT_LOW 0x0
+#define SPI_SCPOL_NOT_ACT_HIGH 0x1
+ u32 Tmod : 2; /* 9:8, ctrl trans mode, indicate if tx rx data is valid */
+#define SPI_TMOD_TX_RX_MODE 0x0
+#define SPI_TMOD_TX_MODE 0x1
+#define SPI_TMOD_RX_MODE 0x2
+#define SPI_TMOD_EEPROM_MODE 0x3
+ u32 SlvOE : 1; /* 10, enable slave tx logic */
+#define SPI_SLV_OE_ENABLE 0x0
+#define SPI_SLV_OE_DISABLE 0x1
+ u32 Srl : 1; /* 11, shift register loopback */
+#define SPI_SRL_NORMAL_MODE 0x0
+#define SPI_SRL_TEST_MODE 0x1
+ u32 Cfs : 4; /* 15:12, ctrl data size, applied in Microwire mode */
+#define SPI_CFS_DEFAULT 0x0
+ u32 Reserve : 16;
+ } val;
+ } FSpi_CtrlReg0_t;
+
+ typedef union
+ {
+ u32 data;
+ struct
+ {
+ u32 ndf : 16; /* 15:0 valid when TMOD = 10, TMOD = 11 */
+#define SPI_NDF_DEFAULT 16
+ u32 Reserve : 16;
+ } val;
+ } FSpi_CtrlReg1_t;
+
+ typedef struct
+ {
+ u32 CPOL;
+ u32 CPHA;
+ } FSpi_ClockMode_t;
+
+ static const FSpi_ClockMode_t g_FSpi_ClockMode[4] =
+ {
+ {.CPOL = SPI_SCPOL_NOT_ACT_LOW, .CPHA = SPI_SCPH_SW_CLK_AT_DATA_BEG}, /* low level logic, sample at rising edge, shift at falling edge */
+ {.CPOL = SPI_SCPOL_NOT_ACT_LOW, .CPHA = SPI_SCPH_SW_CLK_AT_DATA_MID}, /* low level logic, sample at falling edge, shift at rising edge */
+ {.CPOL = SPI_SCPOL_NOT_ACT_HIGH, .CPHA = SPI_SCPH_SW_CLK_AT_DATA_MID}, /* high level logic, sample at falling edge, shift at rising edge */
+ {.CPOL = SPI_SCPOL_NOT_ACT_HIGH, .CPHA = SPI_SCPH_SW_CLK_AT_DATA_BEG}, /* high level logic, sample at rising edge, shift at falling edge */
+ };
+
+ typedef union
+ {
+ u32 data;
+ struct
+ {
+ u32 SsiEn : 1; /* 0, enable or disable all SPI op */
+ u32 Reserve : 31;
+ } val;
+ } FSpi_SsiEnReg_t;
+
+ typedef union
+ {
+ u32 data;
+ struct
+ {
+ u32 MwMod : 1; /* 0 microwire trans mode */
+#define SPI_MWMODE_NO_CONTINUOUES 0
+#define SPI_MWMODE_CONTINUOUES 1
+ u32 Mdd : 1; /* 1 microwire ctrl bit */
+#define SPI_MWMDD_RXFROM_EXT_DEV 0
+#define SPI_MWMDD_TXTO_EXT_DEV 1
+ u32 Mhs : 1; /* 2 microwire handshake */
+#define SPI_MWMHS_DISABLE 0
+#define SPI_MWMHS_ENABLE 1
+ u32 Reserve : 29;
+ } val;
+ } FSpi_MwcrReg_t;
+
+ typedef union
+ {
+ u32 data;
+ struct
+ {
+ u32 SelSlave_0 : 1; /* 3:0, select specifc slave device */
+ u32 SelSlave_1 : 1;
+ u32 SelSlave_2 : 1;
+ u32 SelSlave_3 : 1;
+#define SPI_SE_SELECTED 0x1
+#define SPI_SE_UNSELECTED 0x0
+ u32 Reserve : 28;
+ } val;
+ } FSpi_SeReg_t;
+
+ typedef union
+ {
+ u32 data;
+ struct
+ {
+ u32 Sckdv : 16; /* 15:0, SSI clk divider, must be times of 2 */
+#define SPI_SCKDV_MIN (2)
+#define SPI_SCKDV_4 (4)
+#define SPI_SCKDV_8 (8)
+#define SPI_SCKDV_16 (16)
+#define SPI_SCKDV_32 (20)
+#define SPI_SCKDV_64 (28)
+#define SPI_SCKDV_128 (128)
+#define SPI_SCKDV_256 (256)
+#define SPI_SCKDV_1024 (1024)
+#define SPI_SCKDV_4096 (4096)
+#define SPI_SCKDV_12800 (12800)
+#define SPI_SCKDV_56800 (56800)
+#define SPI_SCKDV_MAX (65534)
+ u32 Reserve : 16;
+ } val;
+ } FSpi_BaudrReg_t;
+
+ typedef union
+ {
+ u32 data;
+ struct
+ {
+ u32 Tft : 8; /* 7:0, TX FIFO threshold */
+ u32 Reserve : 24;
+ } val;
+
+ } FSpi_TxFtlrReg_t;
+
+ typedef union
+ {
+ u32 data;
+ struct
+ {
+ u32 Rft : 8; /* 7:0, RX FIFO threshold */
+ u32 Reserve : 24;
+ } val;
+
+ } FSpi_RxFtlrReg_t;
+
+ typedef union
+ {
+ u32 data;
+ struct
+ {
+ u32 Txtfl : 8; /* 7:0, TX FIFO level, num of valid num */
+ u32 Reserve : 24;
+ } val;
+
+ } FSpi_TxFlrReg_t;
+
+ typedef union
+ {
+ u32 data;
+ struct
+ {
+ u32 Rxtfl : 8; /* 7:0, RX FIFO level, num of valid num */
+ u32 Reserve : 24;
+ } val;
+
+ } FSpi_RxFlrReg_t;
+
+ typedef union
+ {
+ u32 data;
+ struct
+ {
+ u32 Busy : 1; /* 0, SPI bus busy bit */
+ u32 Tfnf : 1; /* 1, tx FIFO not empty */
+#define SPI_TX_FIFO_FULL 0x0
+#define SPI_TX_FIFO_NOT_FULL 0x1
+ u32 Tfe : 1; /* 2, tx FIFO empty */
+#define SPI_TX_FIFO_NOT_EMPTY 0x0
+#define SPI_TX_FIFO_EMPTY 0x1
+ u32 Rfne : 1; /* 3, rx FIFO not emptu */
+#define SPI_RX_FIFO_EMPTY 0x0
+#define SPI_RX_FIFO_NOT_EMPTY 0x1
+ u32 Rff : 1; /* 4, rx FIFO full */
+#define SPI_RX_FIFO_NOT_FULL 0x0
+#define SPI_RX_FIFO_FULL 0x1
+ u32 Txe : 1; /* 5, trans error */
+#define SPI_TX_NO_ERR 0x0
+#define SPI_TX_ERR 0x1
+ u32 Dcol : 1; /* 6, trans conflict error */
+#define SPI_TX_NO_COLERR 0x0
+#define SPI_TX_COLERR 0x1
+ u32 Reserve : 25;
+ } val;
+ } FSpi_StatusReg_t; /* Read-Only */
+
+ typedef union
+ {
+ u32 IdCode : 32;
+ } FSpi_IDReg_t;
+
+ typedef union
+ {
+ u32 data;
+ struct
+ {
+ u32 Dr : 16; /* 15:0, RX and TX fifo */
+#define SPI_8BIT_MASK 0xFF
+#define SPI_16BIT_MASK 0xFFFF
+ u32 Reserve : 16;
+ } val;
+ } FSpi_DataReg_t;
+
+ typedef union
+ {
+ u32 data;
+ struct
+ {
+ u32 Rsd : 8; /* 7:0, RX data delay */
+#define SPI_DEFAULT_RSD 0x6
+ u32 Reserve : 24;
+ } val;
+ } FSpi_RxSampleDlyReg_t;
+
+#define SPI_CTL_ID(pCtrl) ((pCtrl)->CtrlId)
+#define SPI_BASE_ADDR(pCtrl) (g_SpiBaseAddr[SPI_CTL_ID(pCtrl)])
+
+/* select slave device */
+#define SPI_SE_REG(pCtrl) ((FSpi_SeReg_t *)(SPI_BASE_ADDR(pCtrl) + SPI_SE_R))
+/* set speed */
+#define SPI_BAUDR_REG(pCtrl) ((FSpi_BaudrReg_t *)(SPI_BASE_ADDR(pCtrl) + SPI_BAUD_R))
+#define FSPI_SET_BAUDR(pCtrl, div) (SPI_BAUDR_REG(pCtrl)->val.Sckdv = (div))
+#define FSPI_GET_BAUDR(pCtrl) (SPI_BAUDR_REG(pCtrl)->val.Sckdv)
+/* check status */
+#define SPI_STATUS_REG(pCtrl) ((FSpi_StatusReg_t *)(SPI_BASE_ADDR(pCtrl) + SPI_S_R))
+#define FSPI_TX_FIFO_NOT_EMPTY(pCtrl) (SPI_TX_FIFO_NOT_EMPTY == (SPI_STATUS_REG(pCtrl)->val.Tfe))
+#define FSPI_RX_FIFO_EMPTY(pCtrl) (SPI_RX_FIFO_EMPTY == (SPI_STATUS_REG(pCtrl)->val.Rfne))
+/* enable/disable spi bus */
+#define SPI_SSIEN_REG(pCtrl) ((FSpi_SsiEnReg_t *)(SPI_BASE_ADDR(pCtrl) + SPI_SSI_EN_R))
+#define FSPI_ENABLE(pCtrl) (SPI_SSIEN_REG(pCtrl)->val.SsiEn = 1)
+#define FSPI_DISABLE(pCtrl) (SPI_SSIEN_REG(pCtrl)->val.SsiEn = 0)
+/* shortcut to access register */
+#define SPI_CTRL0_REG(pCtrl) ((FSpi_CtrlReg0_t *)(SPI_BASE_ADDR(pCtrl) + SPI_CTRL_R0))
+#define SPI_CTRL1_REG(pCtrl) ((FSpi_CtrlReg1_t *)(SPI_BASE_ADDR(pCtrl) + SPI_CTRL_R1))
+#define SPI_TXFTL_REG(pCtrl) ((FSpi_TxFtlrReg_t *)(SPI_BASE_ADDR(pCtrl) + SPI_TXFTL_R))
+#define SPI_RXFTL_REG(pCtrl) ((FSpi_RxFtlrReg_t *)(SPI_BASE_ADDR(pCtrl) + SPI_RXFTL_R))
+#define SPI_TXFL_REG(pCtrl) ((FSpi_TxFlrReg_t *)(SPI_BASE_ADDR(pCtrl) + SPI_TXFL_R))
+#define SPI_RXFL_REG(pCtrl) ((FSpi_RxFlrReg_t *)(SPI_BASE_ADDR(pCtrl) + SPI_RXFL_R))
+#define SPI_ID_REG(pCtrl) ((FSpi_IDReg_t *)(SPI_BASE_ADDR(pCtrl) + SPI_ID_R))
+#define FSPI_GET_ID(pCtrl) (SPI_ID_REG(pCtrl)->IdCode)
+#define SPI_DATA_REG(pCtrl) ((FSpi_DataReg_t *)(SPI_BASE_ADDR(pCtrl) + SPI_D_R))
+#define FSPI_READ_DATA(pCtrl) (u16)(SPI_DATA_REG(pCtrl)->val.Dr)
+#define FSPI_WRITE_DATA(pCtrl, dat) (SPI_DATA_REG(pCtrl)->val.Dr = (u16)(dat))
+#define SPI_RXSAMPLE_DLY_REG(pCtrl) ((FSpi_RxSampleDlyReg_t *)(SPI_BASE_ADDR(pCtrl) + SPI_RX_SAMPLE_DLY))
+#define SPI_MWCTRL_REG(pCtrl) ((FSpi_MwcrReg_t *)SPI_BASE_ADDR(pCtrl) + SPI_MW_CR)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/bsp/ft2004/libraries/bsp/ft_spi/ft_spi_irq.c b/bsp/ft2004/libraries/bsp/ft_spi/ft_spi_irq.c
new file mode 100644
index 0000000000..a3a0b7a429
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_spi/ft_spi_irq.c
@@ -0,0 +1,13 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-25 14:00:39
+ * @LastEditTime: 2021-04-25 14:00:39
+ * @Description:  This files is for
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
diff --git a/bsp/ft2004/libraries/bsp/ft_uart/ft_uart.c b/bsp/ft2004/libraries/bsp/ft_uart/ft_uart.c
new file mode 100644
index 0000000000..a72c66841e
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_uart/ft_uart.c
@@ -0,0 +1,329 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-05-24 10:48:22
+ * @Description:  This files is for uart functions
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+/***************************** Include Files ********************************/
+
+#include "ft_status.h"
+#include "ft_uart.h"
+#include "ft_io.h"
+#include "ft_error_code.h"
+
+u32 FUart_SendBuffer(Ft_Uart *UartPtr);
+u32 FUart_ReceiveBuffer(Ft_Uart *UartPtr);
+
+static void FUart_StubHandler(void *Args, u32 Event,
+ u32 ByteCount);
+
+/**
+ * @name: FUart_CfgInitialize
+ * @msg: initalize uart configure
+ * @return {*}
+ * @param {Ft_Uart} *UartPtr
+ * @param {FUart_Config_t} *Config
+ */
+s32 FUart_CfgInitialize(Ft_Uart *UartPtr, FUart_Config_t *Config)
+{
+ u32 RegValue = 0;
+
+ Ft_assertNonvoid(UartPtr != NULL);
+ Ft_assertNonvoid(Config != NULL);
+
+ UartPtr->Config.InstanceId = Config->InstanceId;
+ UartPtr->Config.BaseAddress = Config->BaseAddress;
+ UartPtr->Config.RefClockHz = Config->RefClockHz;
+ UartPtr->Config.IsrNum = Config->IsrNum;
+
+ UartPtr->Handler = FUart_StubHandler;
+
+ UartPtr->SendBuffer.BytePtr = NULL;
+ UartPtr->SendBuffer.RequestedBytes = 0;
+ UartPtr->SendBuffer.RemainingBytes = 0;
+
+ UartPtr->ReceiveBuffer.BytePtr = NULL;
+ UartPtr->ReceiveBuffer.RequestedBytes = 0;
+ UartPtr->ReceiveBuffer.RemainingBytes = 0;
+ UartPtr->rxbs_error = 0;
+ UartPtr->IsReady = FT_COMPONENT_IS_READLY;
+ //<! 设置波特率
+
+ /*
+ * Set up the default data format: 8 bit data, 1 stop bit, no
+ * parity
+ */
+ RegValue = ((FUART_FORMAT_WORDLENGTH_8BIT << 5) & UARTLCR_H_WLEN); //<! 8bit word length
+ RegValue |= (0 << 3) & UARTLCR_H_STP2; //<! 1 stopbit
+ RegValue |= (0 << 1) & UARTLCR_H_PEN; //<! no parity
+ RegValue |= (1 << 4) & UARTLCR_H_FEN; //<! fifo en
+ FT_UART_WriteReg(UartPtr->Config.BaseAddress, UARTLCR_H_OFFSET, RegValue);
+
+ /* Set the RX FIFO trigger at 8 data bytes.Tx FIFO trigger is 8 data bytes*/
+ RegValue = (1 << 3) | (1 << 0);
+ FT_UART_WriteReg(UartPtr->Config.BaseAddress, UARTIFLS_OFFSET, RegValue);
+
+ /* Disable all interrupts, polled mode is the default */
+ RegValue = 0;
+ FT_UART_WriteReg(UartPtr->Config.BaseAddress, UARTIMSC_OFFSET, RegValue);
+ return FST_SUCCESS;
+}
+
+/**
+ * @name: FUart_Send
+ * @msg:
+ * @param {Ft_Uart} *UartPtr
+ * @param {u8} *Buffer
+ * @param {u32} Length
+ * @return {u32} The Number of bytes actully sent.
+ */
+u32 FUart_Send(Ft_Uart *UartPtr, u8 *BytePtr, u32 Length)
+{
+ u32 RegValue = 0;
+ u32 SentCount = 0;
+ Ft_assertNonvoid(UartPtr != NULL);
+ Ft_assertNonvoid(BytePtr != NULL);
+ Ft_assertNonvoid(UartPtr->IsReady == FT_COMPONENT_IS_READLY);
+
+ /*
+ * Disable the UART transmit interrupts to allow this call to stop a
+ * previous operation that may be interrupt driven.
+ */
+ RegValue = FT_UART_ReadReg(UartPtr->Config.BaseAddress, UARTIMSC_OFFSET);
+ RegValue &= ~(UARTIMSC_TXIM);
+ FT_UART_WriteReg(UartPtr->Config.BaseAddress, UARTIMSC_OFFSET, RegValue);
+
+ UartPtr->SendBuffer.BytePtr = BytePtr;
+ UartPtr->SendBuffer.RequestedBytes = Length;
+ UartPtr->SendBuffer.RemainingBytes = Length;
+
+ SentCount = FUart_SendBuffer(UartPtr);
+
+ return SentCount;
+}
+
+/**
+ * @name: FUart_PutChar
+ * @msg: send a char through uart
+ * @return {*}
+ * @param {Ft_Uart} *UartPtr
+ * @param {s8} Data
+ */
+void FUart_PutChar(Ft_Uart *UartPtr, s8 Data)
+{
+ Ft_assertVoid(UartPtr != NULL);
+ Ft_assertVoid(UartPtr->IsReady == FT_COMPONENT_IS_READLY);
+
+ while (!FT_UART_IsTransmitFull(UartPtr->Config.BaseAddress))
+ {
+ FT_UART_WriteReg(UartPtr->Config.BaseAddress, UARTDR_OFFSET, Data);
+ break;
+ }
+}
+
+static void FUart_StubHandler(void *Args, u32 Event,
+ u32 ByteCount)
+{
+ (void)Args;
+ (void)Event;
+ (void)ByteCount;
+
+ Ft_assertVoidAlways();
+}
+
+/**
+ * @name: FUart_SendBuffer
+ * @msg: send data buffer through uart
+ * @return {*}
+ * @param {Ft_Uart} *UartPtr
+ */
+u32 FUart_SendBuffer(Ft_Uart *UartPtr)
+{
+ u32 SentCount = 0U;
+ u32 RegValue;
+
+ /*
+ * If the TX FIFO is full, send nothing.
+ * Otherwise put bytes into the TX FIFO unil it is full, or all of the
+ * data has been put into the FIFO.
+ */
+ while ((!FT_UART_IsTransmitFull(UartPtr->Config.BaseAddress)) && (UartPtr->SendBuffer.RemainingBytes > SentCount))
+ {
+ FT_UART_WriteReg(UartPtr->Config.BaseAddress, UARTDR_OFFSET, (u32)UartPtr->SendBuffer.BytePtr[SentCount]);
+ SentCount++;
+ }
+
+ /* Update the buffer to reflect the bytes that were sent from it */
+ UartPtr->SendBuffer.BytePtr += SentCount;
+ UartPtr->SendBuffer.RemainingBytes -= SentCount;
+
+ RegValue = FT_UART_ReadReg(UartPtr->Config.BaseAddress, UARTIMSC_OFFSET);
+ RegValue |= (UARTIMSC_TXIM);
+ FT_UART_WriteReg(UartPtr->Config.BaseAddress, UARTIMSC_OFFSET, RegValue);
+
+ return SentCount;
+}
+
+/**
+ * @name: FUart_Receive
+ * @msg: receive data through uart
+ * @return {*}
+ * @param {Ft_Uart} *UartPtr
+ * @param {u8} *BytePtr
+ * @param {u32} Length
+ */
+u32 FUart_Receive(Ft_Uart *UartPtr, u8 *BytePtr, u32 Length)
+{
+ u32 Received;
+ u32 BackRegValue;
+
+ Ft_assertNonvoid(UartPtr != NULL);
+ Ft_assertNonvoid(BytePtr != NULL);
+ Ft_assertNonvoid(UartPtr->IsReady == FT_COMPONENT_IS_READLY);
+
+ /*
+ * Disable all the interrupts.
+ * This stops a previous operation that may be interrupt driven
+ */
+ BackRegValue = FT_UART_ReadReg(UartPtr->Config.BaseAddress, UARTIMSC_OFFSET);
+ FT_UART_WriteReg(UartPtr->Config.BaseAddress, UARTIMSC_OFFSET, 0);
+
+ UartPtr->ReceiveBuffer.BytePtr = BytePtr;
+ UartPtr->ReceiveBuffer.RequestedBytes = Length;
+ UartPtr->ReceiveBuffer.RemainingBytes = Length;
+
+ Received = FUart_ReceiveBuffer(UartPtr);
+ FT_UART_WriteReg(UartPtr->Config.BaseAddress, UARTIMSC_OFFSET, BackRegValue);
+
+ return Received;
+}
+
+/**
+ * @name: Ft_Uart_ReceiveBuffer
+ * @msg: handling uart receive buffer
+ * @return {*}
+ * @param {Ft_Uart} *UartPtr
+ */
+u32 FUart_ReceiveBuffer(Ft_Uart *UartPtr)
+{
+
+ u32 ReceivedCount = 0U;
+ u32 Event;
+ u32 EventData;
+ u32 ByteValue;
+
+ while ((ReceivedCount < UartPtr->ReceiveBuffer.RemainingBytes) && !FT_UART_IsReceiveData(UartPtr->Config.BaseAddress))
+ {
+ ByteValue = FT_UART_ReadReg(UartPtr->Config.BaseAddress, UARTDR_OFFSET);
+
+ if (UartPtr->rxbs_error)
+ {
+ if ((ByteValue & UARTDR_ALLE) != 0)
+ {
+ EventData = ByteValue;
+ Event = FUART_EVENT_PARE_FRAME_BRKE;
+
+ if (UartPtr->Handler)
+ {
+ UartPtr->Handler(UartPtr->Args, Event, EventData);
+ }
+ }
+ }
+ UartPtr->ReceiveBuffer.BytePtr[ReceivedCount] = (u8)(ByteValue & 0xff);
+ ReceivedCount++;
+ }
+
+ UartPtr->rxbs_error = 0;
+
+ if (UartPtr->ReceiveBuffer.BytePtr != NULL)
+ {
+ UartPtr->ReceiveBuffer.BytePtr += ReceivedCount;
+ }
+ UartPtr->ReceiveBuffer.RemainingBytes -= ReceivedCount;
+
+ return ReceivedCount;
+}
+
+/**
+ * @name: FUart_BlockSend
+ * @msg: initiate uart block send
+ * @return {*}
+ * @param {Ft_Uart} *UartPtr
+ * @param {u8} *BytePtr
+ * @param {u32} Length
+ */
+void FUart_BlockSend(Ft_Uart *UartPtr, u8 *BytePtr, u32 Length)
+{
+ u32 index;
+
+ Ft_assertVoid(UartPtr != NULL);
+ Ft_assertVoid(BytePtr != NULL);
+ Ft_assertVoid(UartPtr->IsReady == FT_COMPONENT_IS_READLY);
+
+ for (index = 0; index < Length; index++)
+ {
+ FUart_SendByte(UartPtr->Config.BaseAddress, BytePtr[index]);
+ }
+}
+
+/**
+ * @name: FUart_BlockReceive
+ * @msg: initiate uart block receive
+ * @return {*}
+ * @param {Ft_Uart} *UartPtr
+ */
+u8 FUart_BlockReceive(Ft_Uart *UartPtr)
+{
+ Ft_assertNonvoid(UartPtr != NULL);
+ Ft_assertNonvoid(UartPtr->IsReady == FT_COMPONENT_IS_READLY);
+ return FUart_RecvByte(UartPtr->Config.BaseAddress);
+}
+
+/**
+ * @name: FUart_SetBaudRate
+ * @msg: set baudrate of UART trans
+ * @return {*}
+ * @param {Ft_Uart} *UartPtr
+ * @param {u32} BaudRate
+ */
+u32 FUart_SetBaudRate(Ft_Uart *UartPtr, u32 BaudRate)
+{
+ u32 temp;
+ u32 divider;
+ u32 remainder;
+ u32 fraction;
+
+ Ft_assertNonvoid(NULL != UartPtr);
+ if ((BaudRate * 2) > UartPtr->Config.RefClockHz)
+ {
+ return ERR_INPUT_BAUD_NO_SUPPORT;
+ }
+
+ /* calculate baud rate divisor */
+ temp = 16 * BaudRate;
+ divider = UartPtr->Config.RefClockHz / temp;
+ remainder = UartPtr->Config.RefClockHz % temp;
+ temp = (128 * remainder) / temp;
+ fraction = temp / 2;
+
+ if (0 != (temp & 1))
+ {
+ fraction++;
+ }
+
+ FUart_ClearSpecificOptions(UartPtr, FUART_OPTION_RXEN | FUART_OPTION_TXEN);
+ /* set baud register */
+ FT_UART_WriteReg(UartPtr->Config.BaseAddress, UARTIBRD_OFFSET, divider);
+ FT_UART_WriteReg(UartPtr->Config.BaseAddress, UARTFBRD_OFFSET, fraction);
+ FUart_SetSpecificOptions(UartPtr, FUART_OPTION_RXEN | FUART_OPTION_TXEN);
+
+ return ERR_SUCCESS;
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_uart/ft_uart.h b/bsp/ft2004/libraries/bsp/ft_uart/ft_uart.h
new file mode 100644
index 0000000000..e342067030
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_uart/ft_uart.h
@@ -0,0 +1,120 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-05-24 10:13:51
+ * @Description:  This files is for uart functions
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef FT_UART_H
+#define FT_UART_H
+
+#include "ft_types.h"
+#include "ft_assert.h"
+#include "ft_status.h"
+#include "ft_uart_hw.h"
+
+#define FUART_BAUDRATE 115200U
+
+/* Config options */
+#define FUART_OPTION_UARTEN 0x1U
+#define FUART_OPTION_RXEN 0x2U
+#define FUART_OPTION_TXEN 0x4U
+#define FUART_OPTION_FIFOEN 0x8U
+
+/* Data format values */
+#define FUART_FORMAT_WORDLENGTH_8BIT 0x3
+#define FUART_FORMAT_WORDLENGTH_7BIT 0x2
+#define FUART_FORMAT_WORDLENGTH_6BIT 0x1
+#define FUART_FORMAT_WORDLENGTH_5BIT 0x0
+
+#define FUART_FORMAT_NO_PARITY 0U
+#define FUART_FORMAT_MARK_PARITY 1U
+#define FUART_FORMAT_SPACE_PARITY 2U
+#define FUART_FORMAT_ODD_PARTY 3U
+#define FUART_FORMAT_EVEN_PARITY 4U
+
+#define FUART_FORMAT_2_STOP_BIT 0U
+#define FUART_FORMAT_1_STOP_BIT 1U
+
+/* Callback events */
+
+#define FUART_EVENT_RECV_DATA 1U /**< Data receiving done */
+#define FUART_EVENT_RECV_TOUT 2U /**< A receive timeout occurred */
+#define FUART_EVENT_SENT_DATA 3U /**< Data transmission done */
+#define FUART_EVENT_RECV_ERROR 4U /**< A receive error detected */
+#define FUART_EVENT_MODEM 5U /**< Modem status changed */
+#define FUART_EVENT_PARE_FRAME_BRKE 6U /**< A receive parity, frame, break \
+ * error detected */
+#define FUART_EVENT_RECV_ORERR 7U /**< A receive overrun error detected */
+
+/**************************** Type Definitions ******************************/
+typedef struct
+{
+ u32 InstanceId; /* Id of device*/
+ u32 BaseAddress;
+ u32 RefClockHz;
+ u32 IsrNum;
+} FUart_Config_t;
+
+typedef struct
+{
+ u8 *BytePtr;
+ u32 RequestedBytes;
+ u32 RemainingBytes;
+} FUart_Buffer_t;
+
+typedef struct
+{
+ u32 BaudRate; /**< In bps, ie 1200 */
+ u32 DataBits; /**< Number of data bits */
+ u32 Parity; /**< Parity */
+ u8 StopBits; /**< Number of stop bits */
+} FUart_Format_t;
+
+typedef void (*FUart_Handler_t)(void *Args, u32 Event, u32 EventData);
+
+typedef struct
+{
+ FUart_Config_t Config; /* Configuration data structure */
+ u32 InputClockHz;
+ u32 IsReady; /* Device is ininitialized and ready*/
+ u32 BaudRate;
+
+ FUart_Buffer_t SendBuffer;
+ FUart_Buffer_t ReceiveBuffer;
+
+ FUart_Handler_t Handler;
+ void *Args;
+ uint8_t rxbs_error; /* 接收过程中出现错误 ,0 无错误,1 存在错误*/
+
+} Ft_Uart;
+
+/* define SD MMC error code */
+typedef enum
+{
+ ERR_SUB_MODE_UART_GENERAL = 0
+} FT_UART_ERR_SUB_MODE;
+
+#define ERR_INPUT_BAUD_NO_SUPPORT FT_CODE_ERR(ERR_MODE_UART, ERR_SUB_MODE_UART_GENERAL, 0x1)
+
+void FUart_PutChar(Ft_Uart *UartPtr, s8 Data);
+u32 FUart_Send(Ft_Uart *UartPtr, u8 *Buffer, u32 Length);
+u32 FUart_Receive(Ft_Uart *UartPtr, u8 *BytePtr, u32 Length);
+s32 FUart_CfgInitialize(Ft_Uart *UartPtr, FUart_Config_t *Config);
+FUart_Config_t *FUart_LookupConfig(u32 InstanceId);
+void FUart_SetOptions(Ft_Uart *UartPtr, u32 Options);
+void FUart_SetSpecificOptions(Ft_Uart *UartPtr, u32 Options);
+void FUart_ClearSpecificOptions(Ft_Uart *UartPtr, u32 Options);
+void FUart_InterruptHandler(Ft_Uart *UartPtr);
+void FUart_SetHandler(Ft_Uart *UartPtr, FUart_Handler_t FuncPtr,
+ void *Args);
+void FUart_SetInterruptMask(Ft_Uart *UartPtr, u32 Mask);
+u32 FUart_SetBaudRate(Ft_Uart *UartPtr, u32 BaudRate);
+#endif // !
diff --git a/bsp/ft2004/libraries/bsp/ft_uart/ft_uart_g.c b/bsp/ft2004/libraries/bsp/ft_uart/ft_uart_g.c
new file mode 100644
index 0000000000..87e76f92d9
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_uart/ft_uart_g.c
@@ -0,0 +1,34 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-04-07 13:42:30
+ * @Description:  This files is for uart config
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_uart.h"
+#include "ft_parameters.h"
+
+FUart_Config_t FUart_Config_tTable[FT_UART_NUM] = {
+ {FT_UART0_ID,
+ FT_UART0_BASE_ADDR,
+ FT_UART0_CLK_FREQ_HZ,
+ 38},
+ {FT_UART1_ID,
+ FT_UART1_BASE_ADDR,
+ FT_UART1_CLK_FREQ_HZ,
+ 39},
+ {FT_UART2_ID,
+ FT_UART2_BASE_ADDR,
+ FT_UART2_CLK_FREQ_HZ,
+ 40},
+ {FT_UART3_ID,
+ FT_UART3_BASE_ADDR,
+ FT_UART3_CLK_FREQ_HZ,
+ 41}};
diff --git a/bsp/ft2004/libraries/bsp/ft_uart/ft_uart_hw.c b/bsp/ft2004/libraries/bsp/ft_uart/ft_uart_hw.c
new file mode 100644
index 0000000000..541f86a6a1
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_uart/ft_uart_hw.c
@@ -0,0 +1,46 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-05-25 16:49:30
+ * @Description:  This files is for uart register function
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_uart_hw.h"
+
+void FUart_SendByte(u32 BaseAddress, u8 Byte)
+{
+ while (FT_UART_IsTransmitFull(BaseAddress))
+ {
+ ;
+ }
+ FT_UART_WriteReg(BaseAddress, UARTDR_OFFSET, (u32)Byte);
+}
+
+u8 FUart_RecvByte(u32 BaseAddress)
+{
+ u32 RecievedByte;
+ while (FT_UART_IsReceiveData(BaseAddress))
+ {
+ ;
+ }
+ RecievedByte = FT_UART_ReadReg(BaseAddress, UARTDR_OFFSET);
+ return RecievedByte;
+}
+
+u8 FUart_GetChar(u32 BaseAddress)
+{
+ u32 RecievedByte;
+ if (FT_UART_IsReceiveData(BaseAddress))
+ {
+ return 0xff;
+ }
+ RecievedByte = FT_UART_ReadReg(BaseAddress, UARTDR_OFFSET);
+ return RecievedByte;
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_uart/ft_uart_hw.h b/bsp/ft2004/libraries/bsp/ft_uart/ft_uart_hw.h
new file mode 100644
index 0000000000..8cadd40419
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_uart/ft_uart_hw.h
@@ -0,0 +1,221 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-03-31 14:59:20
+ * @LastEditTime: 2021-04-02 14:14:34
+ * @Description:  This files is for definition of uart register
+ *
+ * @Modify History: * * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef FT_UART_HW_H
+#define FT_UART_HW_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "ft_types.h"
+#include "ft_assert.h"
+#include "ft_io.h"
+
+ /************************** Constant Definitions *****************************/
+
+ /** @name Register Map
+ *
+ * Register offsets for the UART.
+ * @{
+ */
+
+#define UARTDR_OFFSET 0U /* 数据寄存器 */
+#define UARTRSR_OFFSET 4U /* 接收状态寄存器/错误清除寄存器 */
+#define UARTECR_OFFSET UARTRSR_OFFSET
+#define UARTFTR_OFFSET 0x18U /* 标志寄存器 */
+#define UARTILPR_OFFSET 0x020U /* 低功耗计数寄存器 */
+#define UARTIBRD_OFFSET 0x024U /* 波特率整数值配置寄存器 */
+#define UARTFBRD_OFFSET 0x028U /* 波特率小数值配置寄存器 */
+#define UARTLCR_H_OFFSET 0x02cU /* 线控寄存器 */
+#define UARTCR_OFFSET 0x030U /* 控制寄存器 */
+#define UARTIFLS_OFFSET 0x034U /* FIFO阈值选择寄存器 */
+#define UARTIMSC_OFFSET 0x038U /* 中断屏蔽选择清除寄存器 */
+#define UARTRIS_OFFSET 0x03cU /* 中断状态寄存器 */
+#define UARTMIS_OFFSET 0x040U /* 中断屏蔽状态寄存器 */
+#define UARTICR_OFFSET 0x044U /* 中断清除寄存器 */
+#define UARTDMACR_OFFSET 0x048U /* DMA控制寄存器 */
+
+ /* 数据寄存器 RW */
+
+#define UARTDR_OE 0x800U /* 如果接收到数据并且接收的 FIFO 已满,该位设置为 1 */
+#define UARTDR_BE 0x400U /* 突发错误 */
+#define UARTDR_PE 0x200U /* 奇偶校验错误。 */
+#define UARTDR_FE 0x100U /* 帧错误。 */
+#define UARTDR_ALLE (UARTDR_OE | UARTDR_BE | UARTDR_PE | UARTDR_FE)
+#define UARTDR_DATA 0xffU /* R 接收数据 ,W 传输数据 */
+
+ /* 接收状态寄存器 RW */
+
+#define UARTRSR_OE 0x8U /* 溢出错误。 */
+#define UARTRSR_BE 0x4U /* 突发错误 */
+#define UARTRSR_PE 0x2U /* 奇偶校验错误。 */
+#define UARTRSR_FE 0x1U /* 帧错误 */
+
+#define UARTECR_CLE 0xffU /* 清除 */
+
+/* 标志寄存器 RO */
+#define UARTFTR_RI 0x100U /* Ring indicator */
+#define UARTFTR_TXFE 0x80U /* Transmit FIFO empty */
+#define UARTFTR_RXFF 0x40U /* Receive FIFO full */
+#define UARTFTR_TXFF 0x20U /* Transmit FIFO full. */
+#define UARTFTR_RXFE 0x10U /* Receive FIFO empty */
+#define UARTFTR_BUSY 0x08U /* UART busy */
+#define UARTFTR_DCD 0x04U /* Data carrier detect. */
+#define UARTFTR_DSR 0x02U /* Data set ready. */
+#define UARTFTR_CTS 0x1U /* Clear to send */
+
+/* IrDA 低功耗计数寄存器 RW */
+#define UARTILPR_ILPDVSR 0xffU /* 8-bit low-power divisor value. These bits are cleared to 0 at reset */
+
+/* 波特率整数值配置寄存器 RW */
+#define UARTIBRD_BAUD_DIVFRAC 0xffffU /* The fractional baud rate divisor. */
+
+/* 波特率小数值配置寄存器 RW */
+#define UARTFBRD_BAUD_DIVFRAC 0x3fU /* The fractional baud rate divisor. */
+
+/* 线控寄存器 RW */
+#define UARTLCR_H_SPS 0x80U /* Stick parity select. */
+#define UARTLCR_H_WLEN 0x60U /* Word length. */
+#define UARTLCR_H_FEN 0x10U /* Enable FIFOs. */
+#define UARTLCR_H_STP2 0x08U /* Two stop bits select. */
+#define UARTLCR_H_EPS 0x04U /* Even parity select. */
+#define UARTLCR_H_PEN 0x02U /* Parity enable. */
+#define UARTLCR_H_BRK 0x01U /* send break */
+
+/* 控制寄存器 RW */
+#define UARTCR_CTSEN 0x8000U /* CTS hardware flow control enable. */
+#define UARTCR_RTSEN 0x4000U /* RTS hardware flow control enable. */
+#define UARTCR_OUT2 0x2000U /* This bit is the complement of the UART Out2 (nUARTOut2) modem status output. */
+#define UARTCR_Out1 0x1000U /* This bit is the complement of the UART Out1 (nUARTOut1) modem status output. */
+#define UARTCR_RTS 0x0800U /* Request to send. */
+#define UARTCR_DTR 0x0400U /* Data transmit ready */
+#define UARTCR_RXE 0x0200U /* Receive enable. */
+#define UARTCR_TXE 0x0100U /* Transmit enable. */
+#define UARTCR_LBE 0x0080U /* Loop back enable.*/
+#define UARTCR_SIRLP 0x4U /* IrDA SIR low power mode. */
+#define UARTCR_SIREN 0x2U /* SIR enable. */
+#define UARTCR_UARTEN 0x1U /* UART enable. */
+
+/* FIFO阈值选择寄存器 RW */
+#define UARTIFLS_RXIFLSEL 0x38U /* Receive interrupt FIFO level select. */
+#define UARTIFLS_TXIFLSEL 0x7U /* Transmit interrupt FIFO level select. */
+
+/* 中断屏蔽选择清除寄存器 RW */
+#define UARTIMSC_OEIM 0x400U /* Overrun error interrupt mask. */
+#define UARTIMSC_BEIM 0x200U /* Break error interrupt mask */
+#define UARTIMSC_PEIM 0x100U /* Parity error interrupt mask. */
+#define UARTIMSC_FEIM 0x80U /* Framing error interrupt mask. */
+#define UARTIMSC_RTIM 0x40U /* Receive timeout interrupt mask. */
+#define UARTIMSC_TXIM 0x20U /* Transmit interrupt mask. */
+#define UARTIMSC_RXIM 0x10U /* Receive interrupt mask. */
+#define UARTIMSC_DSRMIM 0x8U /* nUARTDSR modem interrupt mask. */
+#define UARTIMSC_DCDMIM 0x4U /* nUARTDCD modem interrupt mask. */
+#define UARTIMSC_CTSMIM 0x2U /* nUARTCTS modem interrupt mask. */
+#define UARTIMSC_RIMIM 0x1U /* nUARTRI modem interrupt mask. */
+#define UARTIMSC_ALLM 0x3ffU /* all interrupt mask */
+
+ /* 中断状态寄存器 RO */
+
+#define UARTRIS_OEIS 0x400U /* Overrun error interrupt mask. */
+#define UARTRIS_BEIS 0x200U /* Break error interrupt mask */
+#define UARTRIS_PEIS 0x100U /* Parity error interrupt mask. */
+#define UARTRIS_FEIS 0x80U /* Framing error interrupt mask. */
+#define UARTRIS_RTIS 0x40U /* Receive timeout interrupt mask. */
+#define UARTRIS_TXIS 0x20U /* Transmit interrupt mask. */
+#define UARTRIS_RXIS 0x10U /* Receive interrupt mask. */
+#define UARTRIS_DSRMIS 0x8U /* nUARTDSR modem interrupt mask. */
+#define UARTRIS_DCDMIS 0x4U /* nUARTDCD modem interrupt mask. */
+#define UARTRIS_CTSMIS 0x2U /* nUARTCTS modem interrupt mask. */
+#define UARTRIS_RIMIS 0x1U /* nUARTRI modem interrupt mask. */
+
+ /* 中断屏蔽状态寄存器 R0 */
+
+#define UARTMIS_OEMIS 0x400U /* Overrun error interrupt mask. */
+#define UARTMIS_BEMIS 0x200U /* Break error interrupt mask */
+#define UARTMIS_PEMIS 0x100U /* Parity error interrupt mask. */
+#define UARTMIS_FEMIS 0x80U /* Framing error interrupt mask. */
+#define UARTMIS_RTMIS 0x40U /* Receive timeout interrupt mask. */
+#define UARTMIS_TXMIS 0x20U /* Transmit interrupt mask. */
+#define UARTMIS_RXMIS 0x10U /* Receive interrupt mask. */
+#define UARTMIS_DSRMMIS 0x8U /* nUARTDSR modem interrupt mask. */
+#define UARTMIS_DCDMMIS 0x4U /* nUARTDCD modem interrupt mask. */
+#define UARTMIS_CTSMMIS 0x2U /* nUARTCTS modem interrupt mask. */
+#define UARTMIS_RIMMIS 0x1U /* nUARTRI modem interrupt mask. */
+
+/* 中断清除寄存器 WO */
+#define UARTICR_OEIC 0x400U /* Overrun error interrupt mask. */
+#define UARTICR_BEIC 0x200U /* Break error interrupt mask */
+#define UARTICR_PEIC 0x100U /* Parity error interrupt mask. */
+#define UARTICR_FEIC 0x80U /* Framing error interrupt mask. */
+#define UARTICR_RTIC 0x40U /* Receive timeout interrupt mask. */
+#define UARTICR_TXIC 0x20U /* Transmit interrupt mask. */
+#define UARTICR_RXIC 0x10U /* Receive interrupt mask. */
+#define UARTICR_DSRMIC 0x8U /* nUARTDSR modem interrupt mask. */
+#define UARTICR_DCDMIC 0x4U /* nUARTDCD modem interrupt mask. */
+#define UARTICR_CTSMIC 0x2U /* nUARTCTS modem interrupt mask. */
+#define UARTICR_RIMIC 0x1U /* nUARTRI modem interrupt mask. */
+
+/* DMA控制寄存器 RW */
+#define UARTDMACR_DMAONERR 0x4U /* DMA on error. */
+#define UARTDMACR_TXDMAE 0x2U /* Transmit DMA enable. */
+#define UARTDMACR_RXDMAE 0x1U /* Receive DMA enable. */
+
+/***************** Macros (Inline Functions) Definitions *********************/
+
+/**
+ * @name: FT_UART_ReadReg
+ * @msg: 读取串口寄存器
+ * @param {u32} BaseAddress 串口的基地址
+ * @param {u32} RegOffset 串口的寄存器的偏移
+ * @return {u32} 寄存器参数
+ */
+#define FT_UART_ReadReg(BaseAddress, RegOffset) Ft_in32(BaseAddress + (u32)RegOffset)
+
+/**
+ * @name: FT_UART_WriteReg
+ * @msg: 写入串口寄存器
+ * @param {u32} BaseAddress 串口的基地址
+ * @param {u32} RegOffset 串口的寄存器的偏移
+ * @param {u32} RegisterValue 写入寄存器参数
+ * @return {void}
+ */
+#define FT_UART_WriteReg(BaseAddress, RegOffset, RegisterValue) Ft_out32(BaseAddress + (u32)RegOffset, (u32)RegisterValue)
+
+/**
+ * @name: FT_UART_ISRECEIVEDATA
+ * @msg: 用于确认是否接收到数据
+ * @param {u32} BaseAddress 串口的基地址
+ * @return {bool} true 是存在数据 , false 是不存在数据
+ *
+ */
+#define FT_UART_IsReceiveData(BaseAddress) (Ft_in32(BaseAddress + UARTFTR_OFFSET) & UARTFTR_RXFE)
+
+/**
+ * @name: FT_UART_ISTRANSMITFULL
+ * @msg: 用于确认是否能够发送数据
+ * @param {u32} BaseAddress 串口的基地址
+ * @return {bool} true 是数据已满 , false 可以发送数据
+ */
+#define FT_UART_IsTransmitFull(BaseAddress) ((Ft_in32(BaseAddress + UARTFTR_OFFSET) & (u32)UARTFTR_TXFF) == UARTFTR_TXFF)
+
+ void FUart_SendByte(u32 BaseAddress, u8 Byte);
+ u8 FUart_RecvByte(u32 BaseAddress);
+ u8 FUart_GetChar(u32 BaseAddress);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/bsp/ft2004/libraries/bsp/ft_uart/ft_uart_intr.c b/bsp/ft2004/libraries/bsp/ft_uart/ft_uart_intr.c
new file mode 100644
index 0000000000..de1e92649f
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_uart/ft_uart_intr.c
@@ -0,0 +1,196 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-05-25 16:49:42
+ * @Description:  This files is for uart irq functions
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_uart.h"
+
+extern u32 FUart_SendBuffer(Ft_Uart *UartPtr);
+extern u32 FUart_ReceiveBuffer(Ft_Uart *UartPtr);
+
+static void FUart_receiveErrorHandler(Ft_Uart *UartPtr, u32 InterruptStatus);
+static void FUart_receiveDataHandler(Ft_Uart *UartPtr);
+static void FUart_receiveTimeoutHandler(Ft_Uart *UartPtr);
+static void FUart_sendDataHandler(Ft_Uart *UartPtr, u32 InterruptStatus);
+
+/**
+ * @name: FUart_GetInterruptMask
+ * @msg: 此函数获取所有串口中断的mask。
+ * @param {Ft_Uart} *UartPtr
+ * @return {u32} mask
+ */
+u32 FUart_GetInterruptMask(Ft_Uart *UartPtr)
+{
+ Ft_assertNonvoid(UartPtr != NULL);
+
+ return FT_UART_ReadReg(UartPtr->Config.BaseAddress, UARTIMSC_OFFSET);
+}
+
+void FUart_SetInterruptMask(Ft_Uart *UartPtr, u32 Mask)
+{
+ u32 TempMask = Mask;
+ Ft_assertVoid(UartPtr != NULL);
+
+ TempMask &= UARTIMSC_ALLM;
+
+ FT_UART_WriteReg(UartPtr->Config.BaseAddress, UARTIMSC_OFFSET, TempMask);
+}
+
+/**
+ * @name: FUart_SetHandler
+ * @msg: 设置中断回调函数
+ * @param {*}
+ * @return {*}
+ */
+void FUart_SetHandler(Ft_Uart *UartPtr, FUart_Handler_t FuncPtr,
+ void *Args)
+{
+ Ft_assertVoid(UartPtr != NULL);
+ Ft_assertVoid(FuncPtr != NULL);
+ Ft_assertVoid(UartPtr->IsReady == FT_COMPONENT_IS_READLY);
+
+ UartPtr->Handler = FuncPtr;
+ UartPtr->Args = Args;
+}
+
+/**
+ * @name: FUart_InterruptHandler
+ * @msg: 串口中断函数入口
+ * @param {Ft_Uart} *UartPtr
+ * @return {*}
+ */
+void FUart_InterruptHandler(Ft_Uart *UartPtr)
+{
+ u32 RegValue = 0;
+ Ft_assertVoid(UartPtr != NULL);
+ Ft_assertVoid(UartPtr->IsReady == FT_COMPONENT_IS_READLY);
+ //Ft_printf("FUart_InterruptHandler %x\r\n", UartPtr);
+ RegValue = FT_UART_ReadReg(UartPtr->Config.BaseAddress, UARTIMSC_OFFSET);
+
+ RegValue &= FT_UART_ReadReg(UartPtr->Config.BaseAddress, UARTMIS_OFFSET);
+
+ if ((RegValue & ((u32)UARTMIS_RXMIS)) != (u32)0)
+ {
+ /* Received data interrupt */
+ FUart_receiveDataHandler(UartPtr);
+ }
+
+ if ((RegValue & ((u32)UARTMIS_TXMIS)) != (u32)0)
+ {
+ /* Transmit data interrupt */
+ FUart_sendDataHandler(UartPtr, RegValue);
+ }
+
+ if (((RegValue) & ((u32)UARTMIS_OEMIS | (u32)UARTMIS_BEMIS | (u32)UARTMIS_PEMIS | (u32)UARTMIS_FEMIS)) != (u32)0)
+ {
+ /* Received Error Status interrupt */
+ FUart_receiveErrorHandler(UartPtr, RegValue);
+ }
+
+ if ((RegValue & ((u32)UARTMIS_RTMIS)) != (u32)0)
+ {
+ /* Received Timeout interrupt */
+ FUart_receiveTimeoutHandler(UartPtr);
+ }
+
+ if (((RegValue) & ((u32)UARTMIS_DSRMMIS | (u32)UARTMIS_DCDMMIS | (u32)UARTMIS_CTSMMIS | (u32)UARTMIS_RIMMIS)) != (u32)0)
+ {
+ /* Modem status interrupt */
+ }
+
+ /* Clear the interrupt status. */
+ FT_UART_WriteReg(UartPtr->Config.BaseAddress, UARTICR_OFFSET,
+ RegValue);
+}
+
+static void FUart_receiveErrorHandler(Ft_Uart *UartPtr, u32 InterruptStatus)
+{
+ UartPtr->rxbs_error = 0;
+
+ if (((InterruptStatus) & ((u32)UARTMIS_OEMIS | (u32)UARTMIS_BEMIS | (u32)UARTMIS_PEMIS | (u32)UARTMIS_FEMIS)) != 0)
+ {
+ UartPtr->rxbs_error = 1;
+ }
+
+ (void)FUart_ReceiveBuffer(UartPtr);
+
+ if (0 == UartPtr->rxbs_error)
+ {
+ if (UartPtr->Handler)
+ {
+ UartPtr->Handler(UartPtr->Args, FUART_EVENT_RECV_ERROR, UartPtr->ReceiveBuffer.RequestedBytes - UartPtr->ReceiveBuffer.RemainingBytes);
+ }
+ }
+}
+
+static void FUart_receiveDataHandler(Ft_Uart *UartPtr)
+{
+ if ((u32)0 != UartPtr->ReceiveBuffer.RemainingBytes)
+ {
+ (void)FUart_ReceiveBuffer(UartPtr);
+ }
+
+ if ((u32)0 == UartPtr->ReceiveBuffer.RemainingBytes)
+ {
+ if (UartPtr->Handler)
+ {
+ UartPtr->Handler(UartPtr->Args, FUART_EVENT_RECV_DATA, UartPtr->ReceiveBuffer.RequestedBytes - UartPtr->ReceiveBuffer.RemainingBytes);
+ }
+ }
+}
+
+static void FUart_receiveTimeoutHandler(Ft_Uart *UartPtr)
+{
+ u32 Event;
+
+ if ((u32)0 != UartPtr->ReceiveBuffer.RemainingBytes)
+ {
+ (void)FUart_ReceiveBuffer(UartPtr);
+ }
+
+ if ((u32)0 == UartPtr->ReceiveBuffer.RemainingBytes)
+ {
+ Event = FUART_EVENT_RECV_TOUT;
+ }
+ else
+ {
+ Event = FUART_EVENT_RECV_DATA;
+ }
+
+ if (UartPtr->Handler)
+ {
+ UartPtr->Handler(UartPtr->Args, Event, UartPtr->ReceiveBuffer.RequestedBytes - UartPtr->ReceiveBuffer.RemainingBytes);
+ }
+}
+
+static void FUart_sendDataHandler(Ft_Uart *UartPtr, u32 InterruptStatus)
+{
+ u32 RegValue;
+ if (UartPtr->SendBuffer.RemainingBytes == (u32)0)
+ {
+ //<! close send isr
+ RegValue = FT_UART_ReadReg(UartPtr->Config.BaseAddress, UARTIMSC_OFFSET);
+ RegValue &= ~UARTIMSC_TXIM;
+ FT_UART_WriteReg(UartPtr->Config.BaseAddress, UARTIMSC_OFFSET, RegValue);
+ if (UartPtr->Handler)
+ {
+ UartPtr->Handler(UartPtr->Args, FUART_EVENT_RECV_DATA, UartPtr->ReceiveBuffer.RequestedBytes - UartPtr->ReceiveBuffer.RemainingBytes);
+ }
+ }
+ else if (InterruptStatus & UARTMIS_TXMIS)
+ {
+ FUart_SendBuffer(UartPtr);
+ }
+ else
+ {
+ }
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_uart/ft_uart_options.c b/bsp/ft2004/libraries/bsp/ft_uart/ft_uart_options.c
new file mode 100644
index 0000000000..0016f0c732
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_uart/ft_uart_options.c
@@ -0,0 +1,102 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-05-24 10:47:33
+ * @Description:  This files is for uart option setting
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_uart.h"
+#include "ft_uart_hw.h"
+#include "ft_types.h"
+/************************** Variable Definitions ****************************/
+/*
+ * The following data type is a map from an option to the offset in the
+ * register to which it belongs as well as its bit mask in that register.
+ */
+typedef struct
+{
+ u32 Option;
+ u32 RegisterOffset;
+ u32 Mask;
+} Mapping;
+
+static Mapping OptionTable[] = {
+ {FUART_OPTION_UARTEN, UARTCR_OFFSET, UARTCR_UARTEN},
+ {FUART_OPTION_RXEN, UARTCR_OFFSET, UARTCR_RXE},
+ {FUART_OPTION_TXEN, UARTCR_OFFSET, UARTCR_TXE},
+ {FUART_OPTION_FIFOEN, UARTLCR_H_OFFSET, UARTLCR_H_FEN}};
+
+#define FT_UART_NUM_OPITIONS (sizeof(OptionTable) / sizeof(Mapping))
+
+void FUart_SetOptions(Ft_Uart *UartPtr, u32 Options)
+{
+ u32 Index;
+ u32 RegValue;
+ Ft_assertVoid(UartPtr != NULL);
+ Ft_assertVoid(UartPtr->IsReady == FT_COMPONENT_IS_READLY);
+
+ for (Index = 0; Index < FT_UART_NUM_OPITIONS; Index++)
+ {
+ RegValue = FT_UART_ReadReg(UartPtr->Config.BaseAddress, OptionTable[Index].RegisterOffset);
+
+ if ((Options & OptionTable[Index].Option) != (u32)(0))
+ {
+ RegValue |= OptionTable[Index].Mask;
+ }
+ else
+ {
+ RegValue &= ~OptionTable[Index].Mask;
+ }
+
+ FT_UART_WriteReg(UartPtr->Config.BaseAddress, OptionTable[Index].RegisterOffset, RegValue);
+ }
+}
+
+void FUart_SetSpecificOptions(Ft_Uart *UartPtr, u32 Options)
+{
+ u32 Index;
+ u32 RegValue;
+ Ft_assertVoid(UartPtr != NULL);
+
+ for (Index = 0; Index < FT_UART_NUM_OPITIONS; Index++)
+ {
+ if ((Options & OptionTable[Index].Option) == (u32)(0))
+ {
+ continue;
+ }
+
+ RegValue = FT_UART_ReadReg(UartPtr->Config.BaseAddress, OptionTable[Index].RegisterOffset);
+
+ /* set specific options */
+ RegValue |= OptionTable[Index].Mask;
+ FT_UART_WriteReg(UartPtr->Config.BaseAddress, OptionTable[Index].RegisterOffset, RegValue);
+ }
+}
+
+void FUart_ClearSpecificOptions(FT_IN Ft_Uart *UartPtr, FT_IN u32 Options)
+{
+ u32 Index;
+ u32 RegValue;
+ Ft_assertVoid(UartPtr != NULL);
+
+ for (Index = 0; Index < FT_UART_NUM_OPITIONS; Index++)
+ {
+ if ((Options & OptionTable[Index].Option) == (u32)(0))
+ {
+ continue;
+ }
+
+ RegValue = FT_UART_ReadReg(UartPtr->Config.BaseAddress, OptionTable[Index].RegisterOffset);
+
+ /* remove specific options */
+ RegValue &= ~OptionTable[Index].Mask;
+ FT_UART_WriteReg(UartPtr->Config.BaseAddress, OptionTable[Index].RegisterOffset, RegValue);
+ }
+}
diff --git a/bsp/ft2004/libraries/bsp/ft_uart/ft_uart_selftest.c b/bsp/ft2004/libraries/bsp/ft_uart/ft_uart_selftest.c
new file mode 100644
index 0000000000..b31a0e2ed0
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_uart/ft_uart_selftest.c
@@ -0,0 +1,13 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-04-07 13:44:41
+ * @Description:  This files is for uart test cases
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
diff --git a/bsp/ft2004/libraries/bsp/ft_uart/ft_uart_sinit.c b/bsp/ft2004/libraries/bsp/ft_uart/ft_uart_sinit.c
new file mode 100644
index 0000000000..8c228db78c
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/ft_uart/ft_uart_sinit.c
@@ -0,0 +1,41 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-04-07 13:44:56
+ * @Description:  This files is for uart static init
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_uart.h"
+#include "ft_parameters.h"
+
+extern FUart_Config_t FUart_Config_tTable[FT_UART_NUM];
+
+/**
+ * @name: Ft_Uart_LookupConfig
+ * @msg: 获取串口的基本配置
+ * @param {u16} InstanceId FT_UARTX_ID
+ * @return {*}
+ */
+FUart_Config_t *FUart_LookupConfig(u32 InstanceId)
+{
+ FUart_Config_t *CfgPtr = NULL;
+ u32 Index;
+
+ for (Index = 0; Index < (u32)FT_UART_NUM; Index++)
+ {
+ if (FUart_Config_tTable[Index].InstanceId == InstanceId)
+ {
+ CfgPtr = &FUart_Config_tTable[Index];
+ break;
+ }
+ }
+
+ return (FUart_Config_t *)CfgPtr;
+}
diff --git a/bsp/ft2004/libraries/bsp/include/ft_parameters.h b/bsp/ft2004/libraries/bsp/include/ft_parameters.h
new file mode 100644
index 0000000000..9764bfae30
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/include/ft_parameters.h
@@ -0,0 +1,180 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * Date: 2021-03-30 14:57:03
+ * @LastEditTime: 2021-05-24 14:35:00
+ * Description:  definitions of BSP parameters
+ * Modify History:
+ * * * Ver Who Date Changes
+ * * ----- ------ -------- ----------------------------------------------
+ * 1.00 Huanghe 2021/3/1 init
+ */
+
+#ifndef FT_PARAMETERS_H
+#define FT_PARAMETERS_H
+
+/* Device register address */
+#define FT_DEV_BASE_ADDR 0x28000000
+#define FT_DEV_END_ADDR 0x2FFFFFFF
+
+/******** UART ************/
+
+#define FT_UART_NUM 4
+#define FT_UART_REG_LENGTH 0x18000
+
+#define FT_UART0_ID 0
+#define FT_UART0_BASE_ADDR 0x28000000
+#define FT_UART0_CLK_FREQ_HZ 48000000
+
+#define FT_UART1_ID 1
+#define FT_UART1_BASE_ADDR 0x28001000
+#define FT_UART1_CLK_FREQ_HZ 48000000
+
+#define FT_UART2_ID 2
+#define FT_UART2_BASE_ADDR 0x28002000
+#define FT_UART2_CLK_FREQ_HZ 48000000
+
+#define FT_UART3_BASE_ADDR 0x28003000
+#define FT_UART3_ID 3
+#define FT_UART3_CLK_FREQ_HZ 48000000
+
+#define FT_STDOUT_BASEADDRESS FT_UART1_BASE_ADDR
+#define FT_STDIN_BASEADDRESS FT_UART1_BASE_ADDR
+
+/****** GIC v3 *****/
+#define FT_GICV3_INSTANCES_NUM 1U
+#define GICV3_REG_LENGTH 0x00009000
+
+/*
+ * The maximum priority value that can be used in the GIC.
+ */
+#define GICV3_MAX_INTR_PRIO_VAL 240U
+#define GICV3_INTR_PRIO_MASK 0x000000f0U
+
+#define ARM_GIC_IPI_COUNT 16 /* MPCore IPI count */
+#define SGI_INT_MAX 16
+#define SPI_START_INT_NUM 32 /* SPI start at ID32 */
+#define PPI_START_INT_NUM 16 /* PPI start at ID16 */
+#define GIC_INT_MAX_NUM 1020 /* GIC max interrupts count */
+
+#define FT_GICV3_BASEADDRESS 0x29900000U
+#define FT_GICV3_DISTRIBUTOR_BASEADDRESS (FT_GICV3_BASEADDRESS + 0)
+#define FT_GICV3_RD_BASEADDRESS (FT_GICV3_BASEADDRESS + 0x80000U)
+#define FT_GICV3_SGI_BASEADDRESS (FT_GICV3_RD_BASEADDRESS + (1U << 16))
+
+#define FT_GICV3_VECTORTABLE_NUM GIC_INT_MAX_NUM
+
+/** Gmac **/
+#define FT_GMAC_INSTANCES_NUM 2U
+#define FT_GMAC_REG_LENGTH 0x00009000
+
+#define FT_GMAC_COMMON_ADDR 0x2820B000U
+
+#define FT_GMAC0_ID 0
+#define FT_GMAC0_BASEADDR 0x2820C000U
+#define FT_GMAC0_DEFAULT_ADDR \
+ { \
+ 0x11, 0x1c, 0x2c, 0x5c, 0x66, 0x88 \
+ }
+
+#define FT_GMAC1_ID 1
+#define FT_GMAC1_BASEADDR 0x28210000U
+
+/** @defgroup ENET_Buffers_setting
+ * @{
+ */
+#define GMAC_MAX_PACKET_SIZE 1600 /* GMAC_HEADER + GMAC_EXTRA + VLAN_TAG + MAX_GMAC_PAYLOAD + GMAC_CRC */
+#define GMAC_HEADER 14 /* 6 byte Dest addr, 6 byte Src addr, 2 byte length/type */
+#define GMAC_CRC 4 /* Gmac CRC */
+#define GMAC_EXTRA 2 /* Extra bytes in some cases */
+#define VLAN_TAG 4 /* optional 802.1q VLAN Tag */
+#define MIN_GMAC_PAYLOAD 46 /* Minimum Gmac payload size */
+#define MAX_GMAC_PAYLOAD 1500 /* Maximum Gmac payload size */
+#define JUMBO_FRAME_PAYLOAD 9000 /* Jumbo frame payload size */
+#define RX_DESCNUM 1024U /* Rx buffers of size GMAC_MAX_PACKET_SIZE */
+#define TX_DESCNUM 1024U /* Tx buffers of size GMAC_MAX_PACKET_SIZE */
+
+#define PHY_USING_AR8035
+
+#define GMAC0_ISRNUM 81
+#define GMAC0_ISRPRIORITY 0
+
+#define GMAC1_ISRNUM 82
+#define GMAC1_ISRPRIORITY 0
+
+/* SDC */
+#define FT_SDC_NUM 1
+#define FT_SDC_INSTANCE 0
+#define FT_SDC_BASEADDR 0x28207C00U
+#define FT_SDC_REG_LENGTH 0x4000
+#define FT_SDC_FREQ 600000000
+
+/* pin MUX/DEMUX */
+
+#define FT_PIN_MUX_BASEADDR 0x28180000
+#define FT_PIN_MUX_REG_LENGTH 0x10000
+
+/* CAN */
+
+#define FT_CAN_NUM 3
+#define FT_CAN_REG_LENGTH 0x1000
+#define FT_CAN0_BASEADDR 0x28207000
+#define FT_CAN1_BASEADDR 0x28207400
+#define FT_CAN2_BASEADDR 0x28207800
+#define FT_CAN0_IRQNUM 119
+#define FT_CAN1_IRQNUM 123
+#define FT_CAN2_IRQNUM 124
+#define FT_CAN_BAUDRATE 1000000 /* 1M */
+#define FT_CAN_CLK 600000000
+
+/* pci */
+
+#define FT_PCI_CONFIG_BASEADDR 0x40000000
+#define FT_PCI_CONFIG_REG_LENGTH 0x10000000
+
+#define FT_PCI_IO_CONFIG_BASEADDR 0x50000000
+#define FT_PCI_IO_CONFIG_REG_LENGTH 0x08000000
+
+#define FT_PCI_MEM32_BASEADDR 0x58000000
+#define FT_PCI_MEM32_REG_LENGTH 0x27000000
+
+/* qspi */
+#define FT_QSPI_NUM 1U
+#define FT_QSPI_INSTANCE 0
+#define FT_QSPI_MAX_CS_NUM 4
+#define FT_QSPI_BASEADDR 0x28014000
+
+#define FT_QSPI_FLASH_CAP_4MB 0
+#define FT_QSPI_FLASH_CAP_8MB 1
+#define FT_QSPI_FLASH_CAP_16MB 2
+#define FT_QSPI_FLASH_CAP_32MB 3
+#define FT_QSPI_FLASH_CAP_64MB 4
+#define FT_QSPI_FLASH_CAP_128MB 5
+#define FT_QSPI_FLASH_CAP_256MB 6
+
+#define FT_QSPI_ADDR_SEL_3 0
+#define FT_QSPI_ADDR_SEL_4 1
+
+#define FT_QSPI_SCK_DIV_128 0
+#define FT_QSPI_SCK_DIV_2 1
+#define FT_QSPI_SCK_DIV_4 2
+#define FT_QSPI_SCK_DIV_8 3
+#define FT_QSPI_SCK_DIV_16 4
+#define FT_QSPI_SCK_DIV_32 5
+#define FT_QSPI_SCK_DIV_64 6
+
+#define FT_QSPI_TRANSFER_1_1_1 0
+#define FT_QSPI_TRANSFER_1_1_2 1
+#define FT_QSPI_TRANSFER_1_1_4 2
+#define FT_QSPI_TRANSFER_1_2_2 3
+#define FT_QSPI_TRANSFER_1_4_4 4
+#define FT_QSPI_TRANSFER_2_2_2 5
+#define FT_QSPI_TRANSFER_4_4_4 6
+
+/* smp */
+
+#define FT_SMP_EN
+
+#endif // !
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_assert.c b/bsp/ft2004/libraries/bsp/standlone/ft_assert.c
new file mode 100644
index 0000000000..7ec987b2be
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_assert.c
@@ -0,0 +1,43 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-05-18 13:43:09
+ * @Description:  This files is for type definition
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_types.h"
+#include "ft_assert.h"
+
+/************* 全局变量 用于判断驱动是否出现断言 *****************/
+u32 Ft_assertStatus;
+
+/************** 断言是否需要无限等待,1 等待,0不等待 ******************/
+s32 Ft_assertWait = 1;
+
+/* 当断言发生时,将会调用此函数 */
+static Ft_assertCallback Ft_assertCallbackRoutine = NULL;
+
+/************************** Function Prototypes ******************************/
+void Ft_assert(FT_IN char *File, s32 Line)
+{
+ if (Ft_assertCallbackRoutine != NULL)
+ {
+ Ft_assertCallbackRoutine(File, Line);
+ }
+
+ while (Ft_assertWait != 0)
+ {
+ }
+}
+
+void Ft_assertSetCallBack(Ft_assertCallback Routine)
+{
+ Ft_assertCallbackRoutine = Routine;
+}
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_assert.h b/bsp/ft2004/libraries/bsp/standlone/ft_assert.h
new file mode 100644
index 0000000000..09e685e4af
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_assert.h
@@ -0,0 +1,154 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-05-18 13:43:19
+ * @Description:  This files is for assert function
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef Ft_assert_H
+#define Ft_assert_H
+
+#include "ft_types.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#define Fassert_NONE 0U
+#define Fassert_OCCURRED 1U
+
+ extern u32 Ft_assertStatus;
+ extern s32 Ft_assertWait;
+ extern void Ft_assert(FT_IN char *File, s32 Line);
+
+ typedef void (*Ft_assertCallback)(FT_IN char *File, s32 Line);
+
+/**
+ * @name: Ft_assertVoid
+ * @msg: 断言函数不带返回值
+ * @param {*}
+ * @return {*}
+ */
+#define Ft_assertVoid(Expression) \
+ { \
+ if (Expression) \
+ { \
+ Ft_assertStatus = Fassert_NONE; \
+ } \
+ else \
+ { \
+ Ft_assert(__FILE__, __LINE__); \
+ Ft_assertStatus = Fassert_OCCURRED; \
+ return; \
+ } \
+ }
+
+/**
+ * @name:
+ * @msg:
+ * @in param:
+ * @inout param:
+ * @out param:
+ * @return {*}
+ */
+#define Ft_assertBool(Expression) \
+ { \
+ if (Expression) \
+ { \
+ Ft_assertStatus = Fassert_NONE; \
+ } \
+ else \
+ { \
+ Ft_assert(__FILE__, __LINE__); \
+ Ft_assertStatus = Fassert_OCCURRED; \
+ return FALSE; \
+ } \
+ }
+
+/**
+ * @name: Ft_assertZeroNum
+ * @msg: 断言函数带返回值0
+ * @param {*}
+ * @return {*}
+ */
+#define Ft_assertZeroNum(Expression) \
+ { \
+ if (Expression) \
+ { \
+ Ft_assertStatus = Fassert_NONE; \
+ } \
+ else \
+ { \
+ Ft_assert(__FILE__, __LINE__); \
+ Ft_assertStatus = Fassert_OCCURRED; \
+ return FST_ASSERT_RETURN; \
+ } \
+ }
+
+/**
+ * @name: Ft_assertNonvoid
+ * @msg: 断言函数带返回值FST_ASSERT_RETURN
+ * @param {*}
+ * @return {*}
+ */
+#define Ft_assertNonvoid(Expression) \
+ { \
+ if (Expression) \
+ { \
+ Ft_assertStatus = Fassert_NONE; \
+ } \
+ else \
+ { \
+ Ft_assert(__FILE__, __LINE__); \
+ Ft_assertStatus = Fassert_OCCURRED; \
+ return FST_ASSERT_RETURN; \
+ } \
+ }
+
+/**
+ * @name: Ft_assertNoneReturn
+ * @msg: 断言函数不返回
+ * @param {*}
+ * @return {*}
+ */
+#define Ft_assertNoneReturn(Expression) \
+ { \
+ if (Expression) \
+ { \
+ Ft_assertStatus = Fassert_NONE; \
+ } \
+ else \
+ { \
+ Ft_assert(__FILE__, __LINE__); \
+ Ft_assertStatus = Fassert_OCCURRED; \
+ } \
+ }
+
+#define Ft_assertVoidAlways() \
+ { \
+ Ft_assert(__FILE__, __LINE__); \
+ Ft_assertStatus = Fassert_OCCURRED; \
+ return; \
+ }
+
+#define Ft_assertNonvoidAlways() \
+ { \
+ Ft_assert(__FILE__, __LINE__); \
+ Ft_assertStatus = Fassert_OCCURRED; \
+ return FST_ASSERT_RETURN; \
+ }
+
+ void Ft_assertSetCallBack(Ft_assertCallback routine);
+#ifdef __cplusplus
+}
+#endif
+
+#endif // !
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_cache.c b/bsp/ft2004/libraries/bsp/standlone/ft_cache.c
new file mode 100644
index 0000000000..d99c8d3350
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_cache.c
@@ -0,0 +1,86 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-16 14:00:59
+ * @LastEditTime: 2021-04-16 16:07:27
+ * @Description:  This files is for
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_cache.h"
+
+__STATIC_INLINE u32 FCache_cacheLineSize(void)
+{
+ u32 ctr;
+ asm volatile("mrc p15, 0, %0, c0, c0, 1"
+ : "=r"(ctr));
+ return 4 << ((ctr >> 16) & 0xF);
+}
+
+void FCache_cpuDcacheInvalidate(void *addr, ft_base_t size)
+{
+ u32 lineSize = FCache_cacheLineSize();
+ u32 startAddr = (u32)addr;
+ u32 endAddr = (u32)addr + size + lineSize - 1;
+
+ asm volatile("dmb" ::
+ : "memory");
+
+ startAddr &= ~(lineSize - 1);
+ endAddr &= ~(lineSize - 1);
+
+ while (startAddr < endAddr)
+ {
+ asm volatile("mcr p15, 0, %0, c7, c6, 1" ::"r"(startAddr)); /* dcimvac */
+ startAddr += lineSize;
+ }
+
+ asm volatile("dsb" ::
+ : "memory");
+}
+
+void FCache_cpuDcacheClean(void *addr, ft_base_t size)
+{
+ u32 lineSize = FCache_cacheLineSize();
+ u32 startAddr = (u32)addr;
+ u32 endAddr = (u32)addr + size + lineSize - 1;
+
+ asm volatile("dmb" ::
+ : "memory");
+
+ startAddr &= ~(lineSize - 1);
+ endAddr &= ~(lineSize - 1);
+
+ while (startAddr < endAddr)
+ {
+ asm volatile("mcr p15, 0, %0, c7, c10, 1" ::"r"(startAddr)); /* dccmvac */
+ startAddr += lineSize;
+ }
+
+ asm volatile("dsb" ::
+ : "memory");
+}
+
+void FCache_cpuIcacheInvalidate(void *addr, ft_base_t size)
+{
+ u32 lineSize = FCache_cacheLineSize();
+ u32 startAddr = (u32)addr;
+ u32 endAddr = (u32)addr + size + lineSize - 1;
+
+ asm volatile("dmb" ::
+ : "memory");
+ startAddr &= ~(lineSize - 1);
+ endAddr &= ~(lineSize - 1);
+ while (startAddr < endAddr)
+ {
+ asm volatile("mcr p15, 0, %0, c7, c5, 1" ::"r"(startAddr)); /* icimvau */
+ startAddr += lineSize;
+ }
+ asm volatile("dsb\n\tisb" ::
+ : "memory");
+}
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_cache.h b/bsp/ft2004/libraries/bsp/standlone/ft_cache.h
new file mode 100644
index 0000000000..a0c78d7a9c
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_cache.h
@@ -0,0 +1,32 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-13 21:52:20
+ * @LastEditTime: 2021-04-13 21:52:20
+ * @Description:  Description of file
+ * @Modify History:
+ * * * Ver   Who        Date         Changes
+ * * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef FT_CACHE_H
+#define FT_CACHE_H
+
+#include "ft_types.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ void FCache_cpuDcacheInvalidate(void *addr, ft_base_t size);
+ void FCache_cpuDcacheClean(void *addr, ft_base_t size);
+ void FCache_cpuIcacheInvalidate(void *addr, ft_base_t size);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // !FT_CACHE_H
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_cpu.c b/bsp/ft2004/libraries/bsp/standlone/ft_cpu.c
new file mode 100644
index 0000000000..5162395c25
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_cpu.c
@@ -0,0 +1,145 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-20 11:32:32
+ * @LastEditTime: 2021-05-25 10:51:19
+ * @Description:  Description of file
+ * @Modify History:
+ * * * Ver   Who        Date         Changes
+ * * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_parameters.h"
+#include "ft_cpu.h"
+#include "ft_assert.h"
+#include "ft_printf.h"
+
+#ifdef FT_SMP_EN
+
+typedef union
+{
+ u32 Slock;
+ struct ArchTicket
+ {
+ u16 owner;
+ u16 next;
+ } Tickets;
+} FCpu_Lock_t;
+
+struct FCpu
+{
+ u32 IsReady;
+ FCpu_Lock_t Clock;
+};
+
+struct FCpu FCpu_Lock = {0};
+
+const u32 SoftAffiTable[4] = {0, 1, 0x100, 0x101};
+
+/**
+ * @name: FCpu_IdGet
+ * @msg: In a multiprocessor system, provides an additional PE identification mechanism for scheduling
+ purposes.
+ * @return {Aff0} Affinity level 0. The most significant affinity level field, for this PE in the system.
+ */
+s32 FCpu_IdGet(void)
+{
+ s32 cpu_id;
+ __asm__ volatile(
+ "mrc p15, 0, %0, c0, c0, 5"
+ : "=r"(cpu_id));
+ // Ft_printf("error cpu_id %x \r\n", cpu_id);
+ // cpu_id &= 0xf;
+
+ switch ((cpu_id & 0xfff))
+ {
+ case 1:
+ return 1;
+ case 0x100:
+ return 2;
+ case 0x101:
+ return 3;
+ default:
+ return (cpu_id & 0xf);
+ }
+}
+
+s32 FCpu_AffinityGet(void)
+{
+ s32 AffinityId;
+ __asm__ volatile(
+ "mrc p15, 0, %0, c0, c0, 5"
+ : "=r"(AffinityId));
+
+ return AffinityId & 0xfff;
+}
+
+void FCpu_SpinLockInit(void)
+{
+ FCpu_Lock.Clock.Slock = 0;
+ FCpu_Lock.IsReady = FT_COMPONENT_IS_READLY;
+}
+
+void FCpu_SpinLock(void)
+{
+ u32 Tmp;
+ u32 Newval;
+ FCpu_Lock_t LockVal;
+ Ft_assertVoid(FCpu_Lock.IsReady == FT_COMPONENT_IS_READLY);
+
+ __asm__ __volatile__(
+ "pld [%0]" ::"r"(&FCpu_Lock.Clock.Slock));
+
+ __asm__ __volatile__(
+ "1: ldrex %0, [%3]\n"
+ " add %1, %0, %4\n"
+ " strex %2, %1, [%3]\n"
+ " teq %2, #0\n"
+ " bne 1b"
+ : "=&r"(LockVal), "=&r"(Newval), "=&r"(Tmp)
+ : "r"(&FCpu_Lock.Clock.Slock), "I"(1 << 16)
+ : "cc");
+
+ while (LockVal.Tickets.next != LockVal.Tickets.owner)
+ {
+ __asm__ __volatile__("wfe" ::
+ : "memory");
+ LockVal.Tickets.owner = *(volatile unsigned short *)(&FCpu_Lock.Clock.Tickets.owner);
+ }
+
+ __asm__ volatile("dmb" ::
+ : "memory");
+}
+
+void FCpu_SpinUnlock(void)
+{
+ Ft_assertVoid(FCpu_Lock.IsReady == FT_COMPONENT_IS_READLY);
+ __asm__ volatile("dmb" ::
+ : "memory");
+ FCpu_Lock.Clock.Tickets.owner++;
+ __asm__ volatile("dsb ishst\nsev" ::
+ : "memory");
+}
+
+#else /*RT_USING_SMP*/
+
+s32 FCpu_IdGet(void)
+{
+ return 0;
+}
+void FCpu_SpinLockInit(void)
+{
+ return;
+}
+void FCpu_SpinLock(void)
+{
+ return;
+}
+void FCpu_SpinUnlock(void)
+{
+ return;
+}
+
+#endif
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_cpu.h b/bsp/ft2004/libraries/bsp/standlone/ft_cpu.h
new file mode 100644
index 0000000000..7d941f00e1
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_cpu.h
@@ -0,0 +1,26 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-20 11:33:54
+ * @LastEditTime: 2021-04-20 11:33:55
+ * @Description:  Description of file
+ * @Modify History:
+ * * * Ver   Who        Date         Changes
+ * * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef FT_CPU_H
+#define FT_CPU_H
+
+#include "ft_types.h"
+#include "ft_error_code.h"
+extern const u32 SoftAffiTable[4];
+s32 FCpu_IdGet(void);
+void FCpu_SpinLockInit(void);
+void FCpu_SpinLock(void);
+void FCpu_SpinUnlock(void);
+s32 FCpu_AffinityGet(void);
+
+#endif // !FT_SPIN_H
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_debug.c b/bsp/ft2004/libraries/bsp/standlone/ft_debug.c
new file mode 100644
index 0000000000..79628b7def
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_debug.c
@@ -0,0 +1,67 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-25 16:44:23
+ * @LastEditTime: 2021-04-25 16:44:23
+ * @Description:  Description of file
+ * @Modify History:
+ * * * Ver   Who        Date         Changes
+ * * ----- ------     --------    --------------------------------------
+ */
+#include "ft_debug.h"
+
+#define __is_print(ch) ((unsigned int)((ch) - ' ') < 127u - ' ')
+void Ft_DumpHexByte(const u8 *ptr, ft_base_t buflen)
+{
+ unsigned char *buf = (unsigned char *)ptr;
+ int i, j;
+
+ for (i = 0; i < buflen; i += 16)
+ {
+ Ft_printf("0x%08X: ", ptr + i);
+
+ for (j = 0; j < 16; j++)
+ if (i + j < buflen)
+ Ft_printf("%02X ", buf[i + j]);
+ else
+ Ft_printf(" ");
+ Ft_printf(" ");
+
+ for (j = 0; j < 16; j++)
+ if (i + j < buflen)
+ Ft_printf("%c", __is_print(buf[i + j]) ? buf[i + j] : '.');
+ Ft_printf("\r\n");
+ }
+}
+
+void Ft_DumpHexWord(const u32 *ptr, ft_base_t buflen)
+{
+ u32 *buf = (u32 *)ptr;
+ int i, j;
+ buflen = buflen / 4;
+ for (i = 0; i < buflen; i += 4)
+ {
+ Ft_printf("0x%08X: ", ptr + i);
+
+ for (j = 0; j < 4; j++)
+ {
+ if (i + j < buflen)
+ {
+ Ft_printf("%08X ", buf[i + j]);
+ }
+ else
+ {
+ Ft_printf(" ");
+ }
+ }
+
+ Ft_printf(" ");
+
+ for (j = 0; j < 16; j++)
+ if (i + j < buflen)
+ Ft_printf("%c", __is_print(buf[i + j]) ? buf[i + j] : '.');
+ Ft_printf("\r\n");
+ }
+}
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_debug.h b/bsp/ft2004/libraries/bsp/standlone/ft_debug.h
new file mode 100644
index 0000000000..ef11bd8d9b
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_debug.h
@@ -0,0 +1,78 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-04-25 17:19:03
+ * @Description:  This files is for debug functions
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef FT_DEBUG_H
+#define FT_DEBUG_H
+
+#include "ft_printf.h"
+
+typedef enum
+{
+ FT_LOG_NONE, /*!< No log output */
+ FT_LOG_ERROR, /*!< Critical errors, software module can not recover on its own */
+ FT_LOG_WARN, /*!< Error conditions from which recovery measures have been taken */
+ FT_LOG_INFO, /*!< Information messages which describe normal flow of events */
+ FT_LOG_DEBUG, /*!< Extra information which is not necessary for normal use (values, pointers, sizes, etc). */
+ FT_LOG_VERBOSE /*!< Bigger chunks of debugging information, or frequent messages which can potentially flood the output. */
+} ft_log_level_t;
+
+#define LOG_COLOR_BLACK "30"
+#define LOG_COLOR_RED "31"
+#define LOG_COLOR_GREEN "32"
+#define LOG_COLOR_BROWN "33"
+#define LOG_COLOR_BLUE "34"
+#define LOG_COLOR_PURPLE "35"
+#define LOG_COLOR_CYAN "36"
+#define LOG_COLOR(COLOR) "\033[0;" COLOR "m"
+#define LOG_BOLD(COLOR) "\033[1;" COLOR "m"
+#define LOG_RESET_COLOR "\033[0m"
+#define LOG_COLOR_E LOG_COLOR(LOG_COLOR_RED)
+#define LOG_COLOR_W LOG_COLOR(LOG_COLOR_BROWN)
+#define LOG_COLOR_I LOG_COLOR(LOG_COLOR_GREEN)
+#define LOG_COLOR_D
+#define LOG_COLOR_V
+
+#ifndef LOG_LOCAL_LEVEL
+#define LOG_LOCAL_LEVEL FT_LOG_VERBOSE
+#endif
+
+#define LOG_FORMAT(letter, format) LOG_COLOR_##letter " %s: " format LOG_RESET_COLOR "\r\n"
+
+#define PORT_KPRINTF Ft_printf
+
+#define LOG_EARLY_IMPL(tag, format, log_level, log_tag_letter, ...) \
+ do \
+ { \
+ if (LOG_LOCAL_LEVEL < log_level) \
+ break; \
+ PORT_KPRINTF(LOG_FORMAT(log_tag_letter, format), tag, ##__VA_ARGS__); \
+ } while (0)
+
+#define EARLY_LOGE(tag, format, ...) LOG_EARLY_IMPL(tag, format, FT_LOG_ERROR, E, ##__VA_ARGS__)
+#define EARLY_LOGI(tag, format, ...) LOG_EARLY_IMPL(tag, format, FT_LOG_INFO, I, ##__VA_ARGS__)
+#define EARLY_LOGD(tag, format, ...) LOG_EARLY_IMPL(tag, format, FT_LOG_DEBUG, D, ##__VA_ARGS__)
+#define EARLY_LOGW(tag, format, ...) LOG_EARLY_IMPL(tag, format, FT_LOG_WARN, W, ##__VA_ARGS__)
+#define EARLY_LOGV(tag, format, ...) LOG_EARLY_IMPL(tag, format, FT_LOG_VERBOSE, W, ##__VA_ARGS__)
+
+#define FT_DEBUG_PRINT_I(TAG, format, ...) EARLY_LOGI(TAG, format, ##__VA_ARGS__)
+#define FT_DEBUG_PRINT_E(TAG, format, ...) EARLY_LOGE(TAG, format, ##__VA_ARGS__)
+#define FT_DEBUG_PRINT_D(TAG, format, ...) EARLY_LOGD(TAG, format, ##__VA_ARGS__)
+#define FT_DEBUG_PRINT_W(TAG, format, ...) EARLY_LOGW(TAG, format, ##__VA_ARGS__)
+#define FT_DEBUG_PRINT_V(TAG, format, ...) EARLY_LOGV(TAG, format, ##__VA_ARGS__)
+
+#define FT_RAW_PRINTF(format, ...) PORT_KPRINTF(format, ##__VA_ARGS__)
+
+void Ft_DumpHexWord(const u32 *ptr, ft_base_t buflen);
+void Ft_DumpHexByte(const u8 *ptr, ft_base_t buflen);
+#endif // !
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_error_code.h b/bsp/ft2004/libraries/bsp/standlone/ft_error_code.h
new file mode 100644
index 0000000000..9c1a309367
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_error_code.h
@@ -0,0 +1,72 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:30
+ * @LastEditTime: 2021-05-24 10:12:07
+ * @Description:  This files is for error code functions
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef _FT_ERROR_CODE_H
+#define _FT_ERROR_CODE_H
+
+#include "ft_status.h"
+#include "ft_types.h"
+
+typedef ft_base_t ft_error_t;
+
+/* 系统错误码模块定义 */
+typedef enum _ft_errcode_module_mask
+{
+ errModGeneral = 0,
+ errModBsp,
+ ERR_MODE_UART,
+ errModeI2c,
+ errModeGmac,
+ errModeSdCtrl,
+ errCan,
+ errGicV3,
+ errQspi,
+ ERR_MODE_SD_MMC,
+ ERR_MODE_SPI,
+
+ errModMaxMask = 255,
+} ft_errcode_module_mask_t;
+
+/* BSP模块的错误子模块定义 */
+typedef enum _ft_errcode_bsp_mask
+{
+ errBspGeneral = 0,
+ errBspClk,
+ errBspRtc,
+ errPort,
+ errBspModMaxMask = 255
+} ft_errcode_bsp_mask_t;
+
+#define FT_ERRCODE_SYS_MODULE_OFFSET 24
+#define FT_ERRCODE_SUB_MODULE_OFFSET 16
+
+#define FT_ERRCODE_SYS_MODULE_MASK (0xff << FT_ERRCODE_SYS_MODULE_OFFSET) /* bit 24 .. 31 */
+#define FT_ERRCODE_SUB_MODULE_MASK (0xff << FT_ERRCODE_SUB_MODULE_OFFSET) /* bit 16 .. 23 */
+#define FT_ERRCODE_TAIL_VALUE_MASK (0xffff) /* bit 1 .. 15 */
+
+/* Offset error code */
+#define FT_ERRCODE_OFFSET(code, offset, mask) \
+ (((code) << offset) & mask)
+
+/* Assembly error code */
+#define FT_MAKE_ERRCODE(sys_mode, sub_mode, tail) \
+ ((FT_ERRCODE_OFFSET(sys_mode, FT_ERRCODE_SYS_MODULE_OFFSET, FT_ERRCODE_SYS_MODULE_MASK)) | \
+ (FT_ERRCODE_OFFSET(sub_mode, FT_ERRCODE_SUB_MODULE_OFFSET, FT_ERRCODE_SUB_MODULE_MASK)) | \
+ (tail & FT_ERRCODE_TAIL_VALUE_MASK))
+#define FT_CODE_ERR FT_MAKE_ERRCODE
+
+#define ERR_SUCCESS FT_MAKE_ERRCODE(errModGeneral, errBspGeneral, FST_SUCCESS) /* 成功 */
+#define ERR_GENERAL FT_MAKE_ERRCODE(errModGeneral, errBspGeneral, FST_FAILURE) /* 一般错误 */
+
+#endif
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_generic_timer.c b/bsp/ft2004/libraries/bsp/standlone/ft_generic_timer.c
new file mode 100644
index 0000000000..e4e1ab6d5f
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_generic_timer.c
@@ -0,0 +1,327 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-05-25 10:51:35
+ * @Description:  This files is for generic timer functions
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_status.h"
+#include "ft_types.h"
+#include "ft_generic_timer.h"
+#include "ft_printf.h"
+#include "ft_assert.h"
+#include "ft_aarch32_asm.h"
+#include "ft_cpu.h"
+
+#define GENERICTIMER_ASM(x) __asm__ volatile(x)
+#define USEVIRTUAL 0
+#define USE_ISRNUM GEN_TIMER_PHYSICAL_NOSECURE_IRQN
+
+static volatile u32 _TickCnt;
+static volatile u32 _Tickms;
+
+typedef struct ft_Generictimer
+{
+ u64 Frequency;
+ u64 MaxCount;
+ u64 TicksPerUs;
+ u32 Isr_PeriodMsec;
+ u32 Isr_PeriodCnt; //<! 中断周期填充值
+ u8 UseVirtual;
+ u8 InitFlg; //<! 初始化标志,1 is 完成初始化,0 is 尚未初始化
+ u8 Isr_IsEnable; //<! 1 is init , 2 is open, 0 is close
+ Ft_GenericTimer_Isr_Callback Callback;
+} ft_Generictimer_handler_t;
+
+ft_Generictimer_handler_t Ft_GenericTimer_Handler = {0};
+
+/**
+ * @name: GenericTimer_WriteReg
+ * @msg:
+ * @in IsVirtual{u8}: 1 使用 虚拟计数器,0 使用物理计数器
+ * @in reg{u32}: 需要写入寄存器类型, GEN_TIMER_REG_CTL ,GEN_TIMER_REG_TVAL 。
+ * @in val{u32}: 需要写入参数 GEN_TIMER_CTRL_ENABLE GEN_TIMER_CTRL_IMASK GEN_TIMER_CTRL_ISTATUS
+ * @return {*}
+ */
+__STATIC_INLINE void GenericTimer_WriteReg(FT_IN u8 IsVirtual, FT_IN u32 reg, FT_IN u32 val)
+{
+ if (IsVirtual)
+ {
+ if (reg == GEN_TIMER_REG_CTL)
+ {
+ arm_aarch32_cnthv_ctl_set(val);
+ }
+ else
+ {
+ arm_aarch32_cnthv_tval_set(val);
+ }
+ }
+ else
+ {
+ if (reg == GEN_TIMER_REG_CTL)
+ {
+ arm_aarch32_cntp_ctl_set(val);
+ }
+ else
+ {
+ arm_aarch32_cntp_tval_set(val);
+ }
+ }
+
+ GENERICTIMER_ASM("ISB");
+}
+
+/**
+ * @name: GenericTimer_ReadReg
+ * @msg: 读取GenericTimer 寄存器参数。
+ * @in IsVirtual{u8}: 1 使用 虚拟计数器,0 使用物理计数器
+ * @in reg{u32}: 需要写入寄存器类型, GEN_TIMER_REG_CTL ,GEN_TIMER_REG_TVAL 。
+ * @return {u32} 读取寄存器参数
+ */
+__STATIC_INLINE u32 GenericTimer_ReadReg(FT_IN u8 IsVirtual, FT_IN u32 reg)
+{
+ u32 val = 0;
+
+ if (IsVirtual)
+ {
+ if (reg == GEN_TIMER_REG_CTL)
+ {
+ val = arm_aarch32_cnthv_ctl_get();
+ }
+ else
+ {
+ val = arm_aarch32_cnthv_tval_get();
+ }
+ }
+ else
+ {
+ if (reg == GEN_TIMER_REG_CTL)
+ {
+ val = arm_aarch32_cntp_ctl_get();
+ }
+ else
+ {
+ val = arm_aarch32_cntp_ctl_get();
+ }
+ }
+
+ return val;
+}
+
+/**
+ * @name: GenericTimer_GetTimerCnt
+ * @msg: 获取定时器定时器计数值。
+ * @in IsVirtual{u8}: 1 使用 虚拟计数器,0 使用物理计数器
+ * @return {u64} timer count value.
+ */
+__STATIC_INLINE u64 GenericTimer_GetTimerCnt(FT_IN u8 IsVirtual)
+{
+
+ GENERICTIMER_ASM("ISB");
+
+ if (IsVirtual)
+ {
+ return arm_aarch32_cntvct_get();
+ }
+ else
+ {
+ return arm_aarch32_cntpct_get();
+ }
+}
+
+/**
+ * @name: Ft_GenericTimer_UsDelay
+ * @msg: 使用定时器进行us级别延时
+ * @in param{u32}: DelayUs 需要延时的us
+ * @param {u32} DelayUs
+ */
+int32_t Ft_GenericTimer_UsDelay(FT_IN u32 DelayUs)
+{
+ register volatile u64 oldVal;
+ register volatile u64 newVal;
+ register volatile u64 decElapsed = 0;
+ register volatile u64 totalDelta;
+
+ int loopcount = 0;
+
+ if (Ft_GenericTimer_Handler.InitFlg == 0)
+ {
+ return FST_FAILURE;
+ }
+
+ if (DelayUs == 0)
+ {
+ return FST_FAILURE;
+ }
+
+ if (Ft_GenericTimer_Handler.TicksPerUs != 48)
+ {
+ //Ft_printf("ticksPerUs-%d should be 48 for this board, please check it!\r\n", Ft_GenericTimer_Handler.TicksPerUs);
+ }
+
+ totalDelta = Ft_GenericTimer_Handler.TicksPerUs * (u64)DelayUs;
+ oldVal = GenericTimer_GetTimerCnt(Ft_GenericTimer_Handler.UseVirtual);
+
+ while (decElapsed < totalDelta)
+ {
+ loopcount++;
+ newVal = GenericTimer_GetTimerCnt(Ft_GenericTimer_Handler.UseVirtual);
+
+ if (newVal == oldVal)
+ {
+ continue;
+ }
+
+ /* no rollover. count down... */
+
+ if (newVal < oldVal)
+ {
+ decElapsed += (oldVal - newVal);
+ }
+ /* rollover */
+ else
+ {
+ decElapsed += ((Ft_GenericTimer_Handler.MaxCount - oldVal) + newVal);
+ }
+
+ oldVal = newVal;
+ }
+
+ return FST_SUCCESS;
+}
+
+/**
+ * @name: Ft_GenericTimer_IsrSet
+ * @msg: 配置与控制 GenericTimer 中断参数
+ * @in param{u32}: HzRate 设置需要中断频率,输入参数应该小于等于 1000。
+ * @in param{u32}: Cmd 1 使能中断,0关闭中断。
+ * @return {int32_t}: 设置是否成功
+ */
+int32_t Ft_GenericTimer_IsrSet(FT_IN u32 HzRate, FT_IN u32 Cmd)
+{
+
+ Ft_assertNonvoid(HzRate <= 1000);
+ Ft_assertNonvoid(Ft_GenericTimer_Handler.InitFlg != 0);
+
+ if (Cmd == 1)
+ {
+ if (Ft_GenericTimer_Handler.Isr_IsEnable == 2)
+ {
+ //<! turn off isr
+ GenericTimer_WriteReg(Ft_GenericTimer_Handler.UseVirtual, GEN_TIMER_REG_CTL,
+ GEN_TIMER_CTRL_IMASK);
+ }
+
+ Ft_GenericTimer_Handler.Isr_IsEnable = 1;
+ Ft_GenericTimer_Handler.Isr_PeriodCnt = Ft_GenericTimer_Handler.Frequency / HzRate;
+ Ft_GenericTimer_Handler.Isr_PeriodMsec = 1000 / HzRate;
+ /* update the timer value register with maxTimerCount */
+ GenericTimer_WriteReg(Ft_GenericTimer_Handler.UseVirtual, GEN_TIMER_REG_TVAL,
+ Ft_GenericTimer_Handler.Isr_PeriodCnt);
+
+ /* set up the timer control register */
+ GenericTimer_WriteReg(Ft_GenericTimer_Handler.UseVirtual, GEN_TIMER_REG_CTL,
+ GEN_TIMER_CTRL_ENABLE);
+ }
+ else if (Cmd == 0)
+ {
+ Ft_GenericTimer_Handler.Isr_IsEnable = 0;
+ Ft_GenericTimer_Handler.Isr_PeriodCnt = Ft_GenericTimer_Handler.Frequency / HzRate;
+ //<! turn off isr
+ GenericTimer_WriteReg(Ft_GenericTimer_Handler.UseVirtual, GEN_TIMER_REG_CTL,
+ GEN_TIMER_CTRL_IMASK);
+ }
+ else
+ {
+ return FST_FAILURE;
+ }
+ return FST_SUCCESS;
+}
+
+/**
+ * @name: Ft_GenericTimer_IrqHandler
+ * @msg: 中断函数
+ * @in param{void *}: param 用户定义变量。
+ */
+void Ft_GenericTimer_IrqHandler(void *param)
+{
+ /* update the timer value register with maxTimerCount */
+ GenericTimer_WriteReg(Ft_GenericTimer_Handler.UseVirtual, GEN_TIMER_REG_TVAL,
+ Ft_GenericTimer_Handler.Isr_PeriodCnt);
+
+ /* set up the timer control register */
+ GenericTimer_WriteReg(Ft_GenericTimer_Handler.UseVirtual, GEN_TIMER_REG_CTL,
+ GEN_TIMER_CTRL_ENABLE);
+
+ if (Ft_GenericTimer_Handler.Callback)
+ {
+ Ft_GenericTimer_Handler.Callback(param);
+ }
+
+ _TickCnt++;
+
+ _Tickms += Ft_GenericTimer_Handler.Isr_PeriodMsec;
+}
+
+void Ft_GenericTimer_Debug(void)
+{
+ Ft_printf("GenericTimer_ReadReg %x \r\n", GenericTimer_ReadReg(Ft_GenericTimer_Handler.UseVirtual, GEN_TIMER_REG_CTL));
+}
+
+/**
+ * @name: Ft_GenericTimer_GetTick
+ * @msg: 获取中断计数次数
+ * @return {u32} _TickCnt
+ */
+u32 Ft_GenericTimer_GetTick(void)
+{
+ return _TickCnt;
+}
+
+/**
+ * @name: Ft_GenericTimer_Msec
+ * @msg: 获取中断ms级别计数
+ * @return {u32}
+ */
+u32 Ft_GenericTimer_Msec(void)
+{
+ return _Tickms;
+}
+
+/**
+ * @name: Ft_GenericTimer_Init
+ * @msg: GenericTimer 初始化
+ * @in param { u8} UseVirtual 1 使用 虚拟时钟,0使用真实时钟。
+ * @in param { Ft_GenericTimer_Isr_Callback} 中断回调函数。
+ * @return {*}
+ */
+void Ft_GenericTimer_Init(FT_IN u8 UseVirtual, FT_IN Ft_GenericTimer_Isr_Callback Callback)
+{
+ Ft_GenericTimer_Handler.Frequency = arm_aarch32_cntfrq_get();
+
+ Ft_GenericTimer_Handler.TicksPerUs = Ft_GenericTimer_Handler.Frequency / 1000000;
+
+ Ft_GenericTimer_Handler.MaxCount = 0xffffffffffffffffull;
+ Ft_GenericTimer_Handler.Callback = Callback;
+ Ft_GenericTimer_Handler.UseVirtual = UseVirtual;
+ Ft_GenericTimer_Handler.InitFlg = 1;
+ Ft_GenericTimer_Handler.Isr_IsEnable = 0;
+ _Tickms = 0;
+ _TickCnt = 0;
+
+ //<! 开启时钟
+ /* update the timer value register with maxTimerCount */
+ GenericTimer_WriteReg(Ft_GenericTimer_Handler.UseVirtual, GEN_TIMER_REG_TVAL,
+ Ft_GenericTimer_Handler.MaxCount);
+
+ /* set up the timer control register */
+ GenericTimer_WriteReg(Ft_GenericTimer_Handler.UseVirtual, GEN_TIMER_REG_CTL,
+ GEN_TIMER_CTRL_ENABLE);
+}
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_generic_timer.h b/bsp/ft2004/libraries/bsp/standlone/ft_generic_timer.h
new file mode 100644
index 0000000000..98d2860440
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_generic_timer.h
@@ -0,0 +1,57 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-04-07 15:27:27
+ * @Description:  This files is for generic timer functions
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef FT_GENERIC_TIMER_H
+#define FT_GENERIC_TIMER_H
+
+#include "ft_types.h"
+
+/* GenericTimer */
+
+#define ARMV7_GEN_TIMER_NAME "armv7GenTimer"
+#define ARMV7_GEN_TIMER_MAX_COUNT 0x7fffffff
+#define ARMV7_GEN_TIMER_DEFAULT_TPS 60
+#define ARMV7_GEN_TIMER_DEFAULT_MIN_FREQ 10
+#define ARMV7_GEN_TIMER_DEFAULT_MAX_FREQ 5000
+#define ARMV7_GEN_TIMER_MAX_CLK_FREQ 50000000
+#define ARMV7_GEN_TIMER_MIN_CLK_FREQ 1000000
+
+#define GEN_TIMER_REG_CTL 0 //<! Control register for the Hyp mode physical timer.
+#define GEN_TIMER_REG_TVAL 1 //<! Holds the timer value for the Hyp mode physical timer.
+
+#define GEN_TIMER_CTRL_ENABLE (1 << 0)
+#define GEN_TIMER_CTRL_IMASK (1 << 1)
+#define GEN_TIMER_CTRL_ISTATUS (1 << 2)
+
+#define GEN_TIMER_SECURE_PHY_PPI (0)
+#define GEN_TIMER_NON_SECURE_PHY_PPI (1)
+#define GEN_TIMER_VIRTURE_PPI (2)
+#define GEN_TIMER_HYP_PPI (3)
+#define GEN_TIMER_MAX_PPI (4)
+
+#define GEN_TIMER_VIRTUAL_IRQN 27 /**< Virtual Timer Interrupt */
+#define GEN_TIMER_VIRTUAL_NOSECURE_IRQN 28
+#define GEN_TIMER_PHYSICAL_IRQn 29
+#define GEN_TIMER_PHYSICAL_NOSECURE_IRQN 30 /**< Secure Physical Timer Interrupt */
+
+typedef void (*Ft_GenericTimer_Isr_Callback)(void *args);
+
+void Ft_GenericTimer_Init(FT_IN u8 UseVirtual, FT_IN Ft_GenericTimer_Isr_Callback Callback);
+int32_t Ft_GenericTimer_IsrSet(FT_IN u32 HzRate, FT_IN u32 Cmd);
+void Ft_GenericTimer_IrqHandler(void *param);
+int32_t Ft_GenericTimer_UsDelay(FT_IN u32 DelayUs);
+u32 Ft_GenericTimer_GetTick(void);
+u32 Ft_GenericTimer_Msec(void);
+
+#endif // !
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_io.h b/bsp/ft2004/libraries/bsp/standlone/ft_io.h
new file mode 100644
index 0000000000..50b9b9ff65
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_io.h
@@ -0,0 +1,164 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-04-07 15:29:06
+ * @Description:  This files is for general reigster io functions
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef FT_IO_H
+#define FT_IO_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "ft_types.h"
+
+#if defined(__GNUC__) || defined(__ICCARM__) || defined(__MICROBLAZE__)
+#define INLINE inline
+#else
+#define INLINE __inline
+#endif
+
+ /**
+ * @name: Ft_in8
+ * @msg: Read byte value
+ * @in param {UINTPTR}: Addr 需要读取的地址
+ * @return {u8} Byte Value
+ */
+ static INLINE u8 Ft_in8(FT_IN UINTPTR Addr)
+ {
+ return *(volatile u8 *)Addr;
+ }
+
+ /**
+ * @name: Ft_in16
+ * @msg: Read half-word value
+ * @in param {UINTPTR}: Addr 需要读取的地址
+ * @return {u16} Half-word Value
+ */
+ static INLINE u16 Ft_in16(FT_IN UINTPTR Addr)
+ {
+ return *(volatile u16 *)Addr;
+ }
+
+ /**
+ * @name: Ft_in32
+ * @msg: Read word value
+ * @in param {UINTPTR}: Addr 需要读取的地址
+ * @return {u16} Word Value
+ */
+ static INLINE u32 Ft_in32(FT_IN UINTPTR Addr)
+ {
+ return *(volatile u32 *)Addr;
+ }
+
+ /**
+ * @name: Ft_in64
+ * @msg: Read u64 value
+ * @in param {UINTPTR}: Addr 需要读取的地址
+ * @return {u16} u64 Value
+ */
+ static INLINE u64 Ft_in64(FT_IN UINTPTR Addr)
+ {
+ return *(volatile u64 *)Addr;
+ }
+
+ /**
+ * @name: Ft_out8
+ * @msg: write byte value
+ * @in param {UINTPTR}: Addr 需要写入的地址
+ * @in param {u8}: Need write value
+ * @return {*}
+ */
+ static INLINE void Ft_out8(FT_IN UINTPTR Addr, FT_IN u8 Value)
+ {
+ volatile u8 *LocalAddr = (volatile u8 *)Addr;
+ *LocalAddr = Value;
+ }
+
+ /**
+ * @name: Ft_out16
+ * @msg: write half-word value
+ * @in param {UINTPTR}: Addr 需要写入的地址
+ * @in param {u16}: Need write value
+ * @return {*}
+ */
+ static INLINE void Ft_out16(FT_IN UINTPTR Addr, FT_IN u16 Value)
+ {
+ volatile u16 *LocalAddr = (volatile u16 *)Addr;
+ *LocalAddr = Value;
+ }
+
+ /**
+ * @name: Ft_out32
+ * @msg: write half-word value
+ * @in param {UINTPTR}: Addr 需要写入的地址
+ * @in param {u32}: Need write value
+ * @return {*}
+ */
+ static INLINE void Ft_out32(FT_IN UINTPTR Addr, FT_IN u32 Value)
+ {
+ volatile u32 *LocalAddr = (volatile u32 *)Addr;
+ *LocalAddr = Value;
+ }
+
+ /**
+ * @name: Ft_out64
+ * @msg: write u64 value
+ * @in param {UINTPTR}: Addr 需要写入的地址
+ * @in param {u64}: Need write value
+ * @return {*}
+ */
+ static INLINE void Ft_out64(FT_IN UINTPTR Addr, FT_IN u64 Value)
+ {
+ volatile u64 *LocalAddr = (volatile u64 *)Addr;
+ *LocalAddr = Value;
+ }
+
+ /**
+ * @name: Ft_setBit32
+ * @msg:
+ * @in param {FT_INUINTPTR} addr
+ * @in param {FT_INu32} offset
+ * @in param {FT_INu32} value
+ */
+ static INLINE void Ft_setBit32(FT_IN UINTPTR addr, FT_IN u32 value)
+ {
+ u32 lastValue;
+ lastValue = Ft_in32(addr);
+ lastValue |= value;
+ Ft_out32(addr, lastValue);
+ }
+
+ /**
+ * @name: Ft_clearBit32
+ * @msg:
+ * @in param:
+ * @inout param:
+ * @out param:
+ * @return {*}
+ * @param {FT_INUINTPTR} addr
+ * @param {FT_INu32} value
+ */
+ static INLINE void Ft_clearBit32(FT_IN UINTPTR addr, FT_IN u32 value)
+ {
+ u32 lastValue;
+ lastValue = Ft_in32(addr);
+ lastValue &= ~value;
+ Ft_out32(addr, lastValue);
+ }
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // !
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_list.h b/bsp/ft2004/libraries/bsp/standlone/ft_list.h
new file mode 100644
index 0000000000..bbb3e4e78f
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_list.h
@@ -0,0 +1,23 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-04-07 15:29:20
+ * @Description:  This files is for list data structure
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef FT_LIST_H
+#define FT_LIST_H
+
+#include "ft_types.h"
+
+#define container_of(ptr, type, member) \
+ ((type *)((s8 *)(ptr) - (u32)(&((type *)0)->member)))
+
+#endif // ! FT_LIST_H
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_math.c b/bsp/ft2004/libraries/bsp/standlone/ft_math.c
new file mode 100644
index 0000000000..244ed1700e
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_math.c
@@ -0,0 +1,19 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-28 22:15:48
+ * @LastEditTime: 2021-04-28 22:15:48
+ * @Description:  Description of file
+ * @Modify History:
+ * * * Ver   Who        Date         Changes
+ * * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_math.h"
+
+u32 Ft_Abs(s32 num)
+{
+ return (num >= 0 ? num : -num);
+}
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_math.h b/bsp/ft2004/libraries/bsp/standlone/ft_math.h
new file mode 100644
index 0000000000..7456f18386
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_math.h
@@ -0,0 +1,24 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-28 22:15:19
+ * @LastEditTime: 2021-04-28 22:15:19
+ * @Description:  Description of file
+ * @Modify History:
+ * * * Ver   Who        Date         Changes
+ * * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef FT_MATH_H
+#define FT_MATH_H
+
+#include "ft_types.h"
+
+#define FT_INT_MAX 2147483647
+#define FT_UINT_MAX (FT_INT_MAX * 2U + 1)
+
+u32 Ft_Abs(s32 num);
+
+#endif // !FT_MATH_H
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_mux.c b/bsp/ft2004/libraries/bsp/standlone/ft_mux.c
new file mode 100644
index 0000000000..7127b9e564
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_mux.c
@@ -0,0 +1,90 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-05-25 10:51:59
+ * @Description:  This files is for pin mux
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_mux.h"
+#include "ft_io.h"
+#include "ft_assert.h"
+#include "ft_printf.h"
+
+/**
+ * Description: enable i2c 1 ~ 3 pin pad mux
+ * Date: 2021-03-24 13:34:06
+ * Param:
+ * return {*}
+ * param {FT_IN u32} I2cId, i2c 0 ~ 3
+ */
+void Ft_setI2cMux(FT_IN u32 I2cId)
+{
+ u32 RegValue;
+
+ switch (I2cId)
+ {
+ case I2C0_ID:
+ /* i2c0 is by default enabled */
+ break;
+ case I2C1_ID:
+ /* select i2c1 SCL, SDA mux */
+ RegValue = Ft_in32(FT_PIN_DEMUX_BASE + FT_PIN_DEMUX_REG200_OFFSET);
+ RegValue |= (I2C1_SCL_PIN_REG200_BIT | I2C1_SDA_PIN_REG200_BIT);
+ Ft_out32(FT_PIN_DEMUX_BASE + FT_PIN_DEMUX_REG200_OFFSET, RegValue);
+ break;
+ case I2C2_ID:
+ Ft_assertNoneReturn(0);
+ break;
+ case I2C3_ID:
+ Ft_assertNoneReturn(0);
+ break;
+ default:
+ Ft_assertNoneReturn(0);
+ break;
+ }
+
+ return;
+}
+
+void Ft_setSpiMux(FT_IN u32 SpiId)
+{
+ u32 RegValue;
+
+ switch (SpiId)
+ {
+ case SPI0_ID:
+ /* spi0 is by default enabled */
+ RegValue = Ft_in32(FT_PIN_DEMUX_BASE + FT_PIN_DEMUX_REG208_OFFSET);
+ /* clear specific bits to choose Func 0 */
+ RegValue |= SPI1_PORTA5_PIN_REG208_BIT;
+ Ft_out32(FT_PIN_DEMUX_BASE + FT_PIN_DEMUX_REG208_OFFSET, RegValue);
+ Ft_printf("bef reg 208 0x%x\r\n", Ft_in32(FT_PIN_DEMUX_BASE + FT_PIN_DEMUX_REG208_OFFSET));
+
+ break;
+ case SPI1_ID:
+ /* select spi cs, sck, so, si pin mux */
+ Ft_printf("bef reg 210 0x%x\r\n", Ft_in32(FT_PIN_DEMUX_BASE + FT_PIN_DEMUX_REG210_OFFSET));
+ RegValue = Ft_in32(FT_PIN_DEMUX_BASE + FT_PIN_DEMUX_REG210_OFFSET);
+ RegValue |= SPI1_CSN0_PIN_REG210_BIT;
+ Ft_out32(FT_PIN_DEMUX_BASE + FT_PIN_DEMUX_REG210_OFFSET, RegValue);
+ Ft_printf("aft reg 210 0x%x\r\n", Ft_in32(FT_PIN_DEMUX_BASE + FT_PIN_DEMUX_REG210_OFFSET));
+
+ Ft_printf("bef reg 214 0x%x\r\n", Ft_in32(FT_PIN_DEMUX_BASE + FT_PIN_DEMUX_REG214_OFFSET));
+ RegValue = Ft_in32(FT_PIN_DEMUX_BASE + FT_PIN_DEMUX_REG214_OFFSET);
+ RegValue |= SPI1_SCK_PIN_REG214_BIT | SPI1_SO_PIN_REG214_BIT | SPI1_SI_PIN_REG214_BIT;
+ Ft_out32(FT_PIN_DEMUX_BASE + FT_PIN_DEMUX_REG214_OFFSET, RegValue);
+ Ft_printf("aft reg 214 0x%x\r\n", Ft_in32(FT_PIN_DEMUX_BASE + FT_PIN_DEMUX_REG214_OFFSET));
+ break;
+ default:
+ break;
+ }
+
+ return;
+}
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_mux.h b/bsp/ft2004/libraries/bsp/standlone/ft_mux.h
new file mode 100644
index 0000000000..c482154353
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_mux.h
@@ -0,0 +1,75 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-05-26 15:39:16
+ * @Description:  This files is for pin mux
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef FT_BSP_MUX_H
+#define FT_BSP_MUX_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "ft_types.h"
+
+/* pad pin multi-function demu */
+#define FT_PIN_DEMUX_BASE 0x28180000
+#define FT_PIN_DEMUX_REG200_OFFSET 0x200
+#define FT_PIN_DEMUX_REG204_OFFSET 0x204
+#define FT_PIN_DEMUX_REG208_OFFSET 0x208
+#define FT_PIN_DEMUX_REG210_OFFSET 0x210
+#define FT_PIN_DEMUX_REG214_OFFSET 0x214
+
+/* i2c mux function option */
+#define I2C1_SCL_PIN_REG200_MASK ((u32)0x3 << 28) /* all_pll_lock_pad [29:28] */
+#define I2C1_SCL_PIN_REG200_BIT ((u32)0x2 << 28)
+#define I2C1_SDA_PIN_REG200_MASK ((u32)0x3 << 24) /* cru_clk_obv_pad [25:24] */
+#define I2C1_SDA_PIN_REG200_BIT ((u32)0x2 << 24)
+#define I2C2_SCL_PIN_REG204_MASK ((u32)0x3 << 8) /* swdo_swj_pad [9: 8] */
+#define I2C2_SCL_PIN_REG204_BIT ((u32)0x2 << 8)
+#define I2C2_SDA_PIN_REG204_MASK ((u32)0x3 << 6) /* tdo_swj_pad [7: 6] */
+#define I2C2_SDA_PIN_REG204_BIT ((u32)0x2 << 6)
+#define I2C3_SCL_PIN_REG204_MASK ((u32)0x3 << 0) /* hdt_mb_done_state_pad [1 : 0] */
+#define I2C3_SCL_PIN_REG204_BIT ((u32)0x2 << 0)
+#define I2C3_SDA_PIN_REG208_MASK ((u32)0x3 << 30) /* hdt_mb_fail_state_pad [31 : 30] */
+#define I2C3_SDA_PIN_REG208_BIT ((u32)0x2 << 30)
+
+#define SPI1_PORTA5_PIN_REG208_BIT ((u32)0x1 << 16)
+
+#define SPI1_CSN0_PIN_REG210_MASK ((u32)0x3 << 0) /* uart_2_rxd_pad [1 : 0] */
+#define SPI1_CSN0_PIN_REG210_BIT ((u32)0x1 << 0)
+#define SPI1_SCK_PIN_REG214_MASK ((u32)0x3 << 28) /* uart_2_txd_pad [29 : 28] */
+#define SPI1_SCK_PIN_REG214_BIT ((u32)0x1 << 28)
+#define SPI1_SO_PIN_REG214_MASK ((u32)0x3 << 24) /* uart_3_rxd_pad [25 : 24] */
+#define SPI1_SO_PIN_REG214_BIT ((u32)0x1 << 24)
+#define SPI1_SI_PIN_REG214_MASK ((u32)0x3 << 20) /* uart_3_txd_pad [21 : 20] */
+#define SPI1_SI_PIN_REG214_BIT ((u32)0x1 << 20)
+
+/* i2c ctrl instance */
+#define I2C0_ID 0
+#define I2C1_ID 1
+#define I2C2_ID 2
+#define I2C3_ID 3
+
+/* spi ctrl instance */
+#define SPI0_ID 0
+#define SPI1_ID 1
+
+ void Ft_setI2cMux(FT_IN u32 I2cId);
+ void Ft_setSpiMux(FT_IN u32 SpiId);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_printf.c b/bsp/ft2004/libraries/bsp/standlone/ft_printf.c
new file mode 100644
index 0000000000..db6a50f532
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_printf.c
@@ -0,0 +1,96 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-05-26 15:20:14
+ * @Description:  This files is for printf function
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_printf.h"
+#include "stdio.h"
+#include "ft_aarch32_asm.h"
+
+static char print_buffer[PRINTF_BUFFER_LENGTH];
+
+extern void outbyte(char byte);
+
+vsprintf_p Vsprintf_pFun = (vsprintf_p)vsprintf;
+
+void Ft_vsprintfRegister(vsprintf_p f)
+{
+ Vsprintf_pFun = f;
+}
+
+void Ft_printf(const char *fmt, ...)
+{
+ va_list args;
+ size_t i;
+ size_t length;
+#ifdef NEED_CLOSE_ISR
+ IRQ_DISABLE();
+#endif
+ va_start(args, fmt);
+
+ length = Vsprintf_pFun(print_buffer, fmt, args);
+ va_end(args);
+ for (i = 0; i < length; i++)
+ {
+ outbyte(print_buffer[i]);
+ }
+
+#ifdef NEED_CLOSE_ISR
+ IRQ_ENABLE();
+#endif
+}
+
+char *Ft_itoa(int num, char *str, int radix)
+{
+ char index[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+ unsigned unum;
+ int i = 0;
+ int j;
+ int k;
+ char temp;
+
+ if (radix == 10 && num < 0)
+ {
+ unum = (unsigned)-num;
+ str[i++] = '-';
+ }
+ else
+ {
+ unum = (unsigned)num;
+ }
+
+ do
+ {
+ str[i++] = index[unum % (unsigned)radix];
+ unum /= radix;
+ } while (unum);
+
+ str[i] = '\0';
+
+ if (str[0] == '-')
+ {
+ k = 1;
+ }
+ else
+ {
+ k = 0;
+ }
+
+ for (j = k; j <= (i - 1) / 2; j++)
+ {
+ temp = str[j];
+ str[j] = str[i - 1 + k - j];
+ str[i - 1 + k - j] = temp;
+ }
+
+ return str;
+}
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_printf.h b/bsp/ft2004/libraries/bsp/standlone/ft_printf.h
new file mode 100644
index 0000000000..4d1d3ea867
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_printf.h
@@ -0,0 +1,29 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-05-26 15:39:25
+ * @Description:  This files is for printf functions
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef Ft_printf_H
+#define Ft_printf_H
+
+#include <stdarg.h>
+#include "ft_types.h"
+
+#define PRINTF_BUFFER_LENGTH 4096
+
+typedef s32 (*vsprintf_p)(char *buf, const char *format, va_list arg_ptr);
+
+void Ft_vsprintfRegister(vsprintf_p f);
+void Ft_printf(const char *fmt, ...);
+char *Ft_itoa(int num, char *str, int radix);
+
+#endif // !
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_psci.c b/bsp/ft2004/libraries/bsp/standlone/ft_psci.c
new file mode 100644
index 0000000000..1ca9e3379f
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_psci.c
@@ -0,0 +1,78 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-21 10:43:52
+ * @LastEditTime: 2021-04-21 10:43:53
+ * @Description:  Description of file
+ * @Modify History:
+ * * * Ver   Who        Date         Changes
+ * * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_psci.h"
+#include "ft_smc.h"
+#include "ft_cpu.h"
+#include "ft_printf.h"
+
+#define PSCI_CPUON_NUM 0x84000003
+#define PSCI_RESET_NUM 0x84000009
+
+/**
+ * @name: FPsci_CpuOn
+ * @msg: Power up a core
+ * @in param CpuList: Bits[24:31]: Must be zero.
+ * Bits[16:23] Aff2: Match Aff2 of target core MPIDR
+ * Bits[8:15] Aff1: Match Aff1 of target core MPIDR
+ * Bits[0:7] Aff0: Match Aff0 of target core MPIDR
+ * @in param BootAddr: a 32-bit entry point physical address (or IPA).
+ * @return {None}
+ */
+void FPsci_CpuOn(s32 CpuIdMask, u32 BootAddr)
+{
+
+ FSmc_Data_t Input = {0};
+ FSmc_Data_t Output = {0};
+ Input.FunctionIdentifier = PSCI_CPUON_NUM;
+
+ if ((1 << 0) == CpuIdMask)
+ {
+ Input.a1 = SoftAffiTable[0];
+ }
+ else if ((1 << 1) == CpuIdMask)
+ {
+ Input.a1 = SoftAffiTable[1];
+ }
+ else if ((1 << 2) == CpuIdMask)
+ {
+ Input.a1 = SoftAffiTable[2];
+ }
+ else if ((1 << 3) == CpuIdMask)
+ {
+ Input.a1 = SoftAffiTable[3];
+ }
+ else
+ {
+ return;
+ }
+
+ /*input.a2 = (u32)(BootAddr >> 32);*/
+ Input.a2 = (u32)(BootAddr & 0xFFFFFFFF);
+ FSmc_Call(&Input, &Output);
+ __asm__ volatile("NOP");
+}
+
+void FPsci_Reset(void)
+{
+
+ FSmc_Data_t Input = {0};
+ FSmc_Data_t Output = {0};
+
+ Input.FunctionIdentifier = PSCI_RESET_NUM;
+ FSmc_Call(&Input, &Output);
+
+ __asm__ volatile("NOP");
+ while (1)
+ ;
+}
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_psci.h b/bsp/ft2004/libraries/bsp/standlone/ft_psci.h
new file mode 100644
index 0000000000..b963c0092a
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_psci.h
@@ -0,0 +1,31 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-21 10:43:59
+ * @LastEditTime: 2021-04-21 10:44:00
+ * @Description:  Description of file
+ * @Modify History:
+ * * * Ver   Who        Date         Changes
+ * * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef FT_PSCI_H
+#define FT_PSCI_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "ft_types.h"
+
+ void FPsci_CpuOn(s32 CpuIdMask, u32 BootAddr);
+ void FPsci_Reset(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // !
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_smc.S b/bsp/ft2004/libraries/bsp/standlone/ft_smc.S
new file mode 100644
index 0000000000..c610350eb5
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_smc.S
@@ -0,0 +1,36 @@
+
+
+/*******************************************************************************
+*
+* FSmc_Call - initiate SMC call
+*
+* This routine initiates SMC call which traps the processor into Monitor Mode.
+* The ARM SMC Call Convetion defines that up to eight registers can be exchanged
+* during an SMC call. The input parameter contains eight INT32 valeus which are
+* to be passed in the SMC call; similarily the output parameter also contains
+* eight INT32 values which are returned from the SMC call.
+*
+* \NOMANUAL
+*
+* RETURNS: OK
+*
+* void FSmc_Call
+* (
+* FSmc_Data_t * input, /@ r0 - input register values @/
+* FSmc_Data_t * output /@ r1 - output register values @/
+* )
+*/
+
+.arm
+.align 4
+.globl FSmc_Call
+FSmc_Call:
+ STMDB sp!, {r0-r7} /* save clobbered registers to stack */
+ ldr r12, [sp, #(4 * 0)] /* get 1st argument (ptr to input struct) */
+ ldmia r12, {r0-r7} /* save input argument to r0-r7 */
+ smc #0
+ ldr r12, [sp, #(4 * 1)] /* get 2th argument (ptr to output result) */
+ stmia r12, {r0-r7} /* get output argument from r0-r7 */
+ ldmfd sp!, {r0-r7} /* restore clobbered registers from stack */
+ bx lr
+.size FSmc_Call, .- FSmc_Call
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_smc.h b/bsp/ft2004/libraries/bsp/standlone/ft_smc.h
new file mode 100644
index 0000000000..c241c09eca
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_smc.h
@@ -0,0 +1,43 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-21 11:53:38
+ * @LastEditTime: 2021-04-21 11:53:38
+ * @Description:  Description of file
+ * @Modify History:
+ * * * Ver   Who        Date         Changes
+ * * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef FT_SMC_H
+#define FT_SMC_H
+
+#include "ft_types.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ typedef struct
+ {
+ /* data */
+ u32 FunctionIdentifier;
+ u32 a1;
+ u32 a2;
+ u32 a3;
+ u32 a4;
+ u32 a5;
+ u32 a6;
+
+ } FSmc_Data_t;
+
+ void FSmc_Call(FSmc_Data_t *Input, FSmc_Data_t *Output);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // !FT_SMC_H
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_status.h b/bsp/ft2004/libraries/bsp/standlone/ft_status.h
new file mode 100644
index 0000000000..a30ac32cf8
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_status.h
@@ -0,0 +1,82 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-04-07 15:31:10
+ * @Description:  This files is for definition of status
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef FT_STATUS_H
+#define FT_STATUS_H
+
+/**
+@name Common Status Codes
+*/
+
+typedef enum
+{
+ FST_SUCCESS = 0L,
+ FST_FAILURE = 1L,
+ FST_INSTANCE_NOT_FOUND = 2L,
+ FST_DEVICE_BLOCK_NOT_FOUND = 3L,
+ FST_INVALID_VERSION = 4L,
+ FST_DEVICE_IS_STARTED = 5L,
+ FST_DEVICE_IS_STOPPED = 6L,
+ FST_FIFO_ERROR = 7L, /* An error occurred during an \
+ operation with a FIFO such as \
+ an underrun or overrun, this \
+ error requires the device to \
+ be reset */
+ FST_RESET_ERROR = 8L, /* An error occurred which requires \
+ the device to be reset */
+ FST_DMA_ERROR = 9L, /* A DMA error occurred, this error \
+ typically requires the device \
+ using the DMA to be reset */
+ FST_NOT_POLLED = 10L, /* The device is not configured for \
+ polled mode operation */
+ FST_FIFO_NO_ROOM = 11L, /* A FIFO did not have room to put \
+ the specified data into */
+ FST_BUFFER_TOO_SMALL = 12L, /* The buffer is not large enough \
+ to hold the expected data */
+ FST_NO_DATA = 13L, /* There was no data available */
+ FST_REGISTER_ERROR = 14L, /* A register did not contain the \
+ expected value */
+ FST_INVALID_PARAM = 15L, /* An invalid parameter was passed \
+ into the function */
+ FST_NOT_SGDMA = 16L, /* The device is not configured for \
+ scatter-gather DMA operation */
+ FST_LOOPBACK_ERROR = 17L, /* A loopback test failed */
+ FST_NO_CALLBACK = 18L, /* A callback has not yet been \
+ registered */
+ FST_NO_FEATURE = 19L, /* Device is not configured with \
+ the requested feature */
+ FST_NOT_INTERRUPT = 20L, /* Device is not configured for \
+ interrupt mode operation */
+ FST_DEVICE_BUSY = 21L, /* Device is busy */
+ FST_ERROR_COUNT_MAX = 22L, /* The error counters of a device \
+ have maxed out */
+ FST_IS_STARTED = 23L, /* Used when part of device is \
+ already started i.e. \
+ sub channel */
+ FST_IS_STOPPED = 24L, /* Used when part of device is \
+ already stopped i.e. \
+ sub channel */
+ FST_DATA_LOST = 26L, /* Driver defined error */
+ FST_RECV_ERROR = 27L, /* Generic receive error */
+ FST_SEND_ERROR = 28L, /* Generic transmit error */
+ FST_NOT_ENABLED = 29L, /* A requested service is not \
+ available because it has not \
+ been enabled */
+ FST_ASSERT_RETURN = 30L, /* Assert occurs defined error */
+ FST_TIMEOUT = 31L,
+ FST_EILSEQ = 32L, /* Illegal byte sequence. */
+ FST_STATUS_MAX_VALUE = 0xffff /* Status max value */
+} Common_status;
+
+#endif // !FT_STATUS_H
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_trace.c b/bsp/ft2004/libraries/bsp/standlone/ft_trace.c
new file mode 100644
index 0000000000..b3cc4d831d
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_trace.c
@@ -0,0 +1,57 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-15 11:27:24
+ * @LastEditTime: 2021-05-25 10:52:32
+ * @Description:  This files is for
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+
+#include "ft_trace.h"
+#include "ft_printf.h"
+
+
+void Sdmmc_TraceHeapAlloc(const char *tag)
+{
+
+}
+
+void dump_hex(const u8 *ptr, u32 buflen, const char *tag)
+{
+ unsigned char *buf = (unsigned char *)ptr;
+ u32 i, j;
+
+ Ft_printf("dump hex for %s\r\n", tag);
+ for (i = 0; i < buflen; i += 16)
+ {
+ Ft_printf("%08X: ", ptr + i);
+
+ for (j = 0; j < 16; j++)
+ {
+ if (i + j < buflen)
+ {
+ Ft_printf("%02X ", buf[i + j]);
+ }
+ else
+ {
+ Ft_printf(" ");
+ }
+ }
+ Ft_printf(" ");
+
+ for (j = 0; j < 16; j++)
+ {
+ if (i + j < buflen)
+ {
+ Ft_printf("%c", __is_print(buf[i + j]) ? buf[i + j] : '.');
+ }
+ }
+ Ft_printf("\r\n");
+ }
+}
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_trace.h b/bsp/ft2004/libraries/bsp/standlone/ft_trace.h
new file mode 100644
index 0000000000..1c2ac0cb2d
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_trace.h
@@ -0,0 +1,52 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-15 11:27:14
+ * @LastEditTime: 2021-04-16 13:40:55
+ * @Description:  This files is for
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef _FT_TRACE_H_
+#define _FT_TRACE_H_
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "ft_debug.h"
+
+/* define debug log function */
+#define FT_MEM_TRACE_ENABLED
+#define FT_MEM_TRACE_TAG "FT_MEM"
+#ifdef FT_MEM_TRACE_ENABLED
+#define FT_MEM_TRACE(format, ...) FT_DEBUG_PRINT_I(FT_MEM_TRACE_TAG, format, ##__VA_ARGS__)
+#else
+#define FT_MEM_TRACE(format, ...)
+#endif
+
+#define FT_LOGIC_TRACE_ENABLED
+#define FT_LOGIC_TRACE_TAG "FT_LOGIC"
+#ifdef FT_LOGIC_TRACE_ENABLED
+#define FT_LOGIC_TRACE(format, ...) FT_DEBUG_PRINT_I(FT_LOGIC_TRACE_TAG, format, ##__VA_ARGS__)
+#define FT_MEM_TRACE_DUMP(buf, buflen, tag) dump_hex((buf), (buflen), (tag))
+#else
+#define FT_LOGIC_TRACE(format, ...)
+#define FT_MEM_TRACE_DUMP(buf, buflen, tag)
+#endif
+
+#define __is_print(ch) ((unsigned int)((ch) - ' ') < 127u - ' ')
+ void dump_hex(const u8 *ptr, u32 buflen, const char *tag);
+ void Sdmmc_TraceHeapAlloc(const char *tag);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/bsp/ft2004/libraries/bsp/standlone/ft_types.h b/bsp/ft2004/libraries/bsp/standlone/ft_types.h
new file mode 100644
index 0000000000..970d3e4e06
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/ft_types.h
@@ -0,0 +1,75 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-05-11 10:18:14
+ * @Description:  This files is for definition of system-level types
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#ifndef FT_TYPES_H
+#define FT_TYPES_H
+#include <stdint.h>
+#include <stddef.h>
+
+/* Constant Definitions */
+
+#ifndef TRUE
+#define TRUE 1U
+#endif
+
+#ifndef FALSE
+#define FALSE 0U
+#endif
+
+#ifndef NULL
+#define NULL 0U
+#endif
+
+#define FT_NULL NULL
+
+#define FT_COMPONENT_IS_READLY 0x11111111U
+#define FT_COMPONENT_IS_STARTED 0x22222222U
+
+#define __STATIC_INLINE static inline
+
+#define FT_OUT /* 表示输出参数,指针指向的值会修改,且不会读 */
+#define FT_IN /* 表示输入参数,指针指向的值不会修改 */
+#define FT_INOUT /* 表示输入输出参数,指针指向的值会修改,且会读取 */
+#define FT_IO volatile
+
+typedef char s8;
+typedef unsigned char u8;
+typedef short s16;
+typedef unsigned short u16;
+typedef int s32;
+typedef unsigned int u32;
+typedef unsigned long long u64;
+typedef long long s64;
+typedef int ft_base_t;
+typedef ft_base_t bool_t;
+
+typedef intptr_t INTPTR;
+typedef uintptr_t UINTPTR;
+typedef ptrdiff_t PTRDIFF;
+
+#define __STATIC_INLINE static inline
+#define LOCAL static
+
+#define LLSB(x) ((x)&0xff) /* 32bit word byte/word swap macros */
+#define LNLSB(x) (((x) >> 8) & 0xff)
+#define LNMSB(x) (((x) >> 16) & 0xff)
+#define LMSB(x) (((x) >> 24) & 0xff)
+#define U32SWAP(x) ((LLSB(x) << 24) | \
+ (LNLSB(x) << 16) | \
+ (LNMSB(x) << 8) | \
+ (LMSB(x)))
+
+#define FT_SWAP32(x) U32SWAP((u32)x)
+
+#endif //
diff --git a/bsp/ft2004/libraries/bsp/standlone/inbyte.c b/bsp/ft2004/libraries/bsp/standlone/inbyte.c
new file mode 100644
index 0000000000..6eff625890
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/inbyte.c
@@ -0,0 +1,21 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-04-07 15:31:34
+ * @Description:  This files is for
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_parameters.h"
+#include "ft_uart_hw.h"
+
+u8 inbyte(void)
+{
+ return FUart_RecvByte(FT_STDIN_BASEADDRESS);
+}
diff --git a/bsp/ft2004/libraries/bsp/standlone/outbyte.c b/bsp/ft2004/libraries/bsp/standlone/outbyte.c
new file mode 100644
index 0000000000..3a9a1bb21c
--- /dev/null
+++ b/bsp/ft2004/libraries/bsp/standlone/outbyte.c
@@ -0,0 +1,21 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-04-07 09:53:07
+ * @LastEditTime: 2021-04-07 17:54:32
+ * @Description:  This files is for
+ *
+ * @Modify History:
+ * Ver   Who        Date         Changes
+ * ----- ------     --------    --------------------------------------
+ */
+
+#include "ft_parameters.h"
+#include "ft_uart_hw.h"
+
+void outbyte(char byte)
+{
+ FUart_SendByte(FT_STDOUT_BASEADDRESS, byte);
+}
diff --git a/bsp/ft2004/libraries/cpu/ft_aarch32_asm.h b/bsp/ft2004/libraries/cpu/ft_aarch32_asm.h
new file mode 100644
index 0000000000..d39b221a2d
--- /dev/null
+++ b/bsp/ft2004/libraries/cpu/ft_aarch32_asm.h
@@ -0,0 +1,319 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-01-22 16:30:56
+ * @LastEditTime: 2021-05-24 14:35:53
+ * @LastEditors: Please set LastEditors
+ * @Description: In User Settings Edit
+ * @FilePath: \project_freertos\devices\ft2004\bsp\core\ft_asm.h
+ */
+
+#ifndef FT_AARCH32_ASM_H
+#define FT_AARCH32_ASM_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "ft_types.h"
+
+#define __ASM __asm
+#define __STRINGIFY(x) #x
+/* C语言实现MCR指令 */
+#define __MCR(coproc, opcode_1, src, CRn, CRm, opcode_2) \
+ __ASM volatile("MCR " __STRINGIFY(p##coproc) ", " __STRINGIFY(opcode_1) ", " \
+ "%0, " __STRINGIFY(c##CRn) ", " __STRINGIFY(c##CRm) ", " __STRINGIFY(opcode_2) \
+ : \
+ : "r"(src) \
+ : "memory");
+
+/* C语言实现MRC指令 */
+#define __MRC(coproc, opcode_1, CRn, CRm, opcode_2) \
+ ({ \
+ u32 __dst; \
+ __ASM volatile("MRC " __STRINGIFY(p##coproc) ", " __STRINGIFY(opcode_1) ", " \
+ "%0, " __STRINGIFY(c##CRn) ", " __STRINGIFY(c##CRm) ", " __STRINGIFY(opcode_2) \
+ : "=r"(__dst)::"memory"); \
+ __dst; \
+ })
+
+ __attribute__((always_inline)) __STATIC_INLINE u32 __get_VBAR(void)
+ {
+ return __MRC(15, 0, 12, 0, 0);
+ }
+
+ __attribute__((always_inline)) __STATIC_INLINE void __set_VBAR(u32 vbar)
+ {
+ __MCR(15, 0, vbar, 12, 0, 0);
+ }
+
+ __attribute__((always_inline)) __STATIC_INLINE void sys_icc_igrpen0_set(u32 value)
+ {
+ __MCR(15, 0, value, 12, 12, 6);
+ }
+
+ __attribute__((always_inline)) __STATIC_INLINE u32 sys_icc_igrpen0_get(void)
+ {
+ return __MRC(15, 0, 12, 12, 6);
+ }
+
+ __attribute__((always_inline)) __STATIC_INLINE void sys_icc_igrpen1_set(u32 value)
+ {
+ __MCR(15, 0, value, 12, 12, 7);
+ }
+
+ __attribute__((always_inline)) __STATIC_INLINE u32 sys_icc_igrpen1_get(void)
+ {
+ return __MRC(15, 0, 12, 12, 7);
+ }
+
+ __attribute__((always_inline)) __STATIC_INLINE void sys_icc_ctlr_set(u32 value)
+ {
+ __MCR(15, 0, value, 12, 12, 4);
+ }
+
+ __attribute__((always_inline)) __STATIC_INLINE u32 sys_icc_ctlr_get(void)
+ {
+ return __MRC(15, 0, 12, 12, 4);
+ }
+
+ __attribute__((always_inline)) __STATIC_INLINE u32 sys_icc_hppir0_get(void)
+ {
+ return __MRC(15, 0, 12, 8, 2);
+ }
+
+ __attribute__((always_inline)) __STATIC_INLINE void sys_icc_bpr_set(u32 value)
+ {
+ __MCR(15, 0, value, 12, 12, 3);
+ }
+
+ __attribute__((always_inline)) __STATIC_INLINE u32 sys_icc_bpr_get(void)
+ {
+ return __MRC(15, 0, 12, 12, 3);
+ }
+
+ __attribute__((always_inline)) __STATIC_INLINE u32 sys_icc_hppir1_get(void)
+ {
+ return __MRC(15, 0, 12, 12, 2);
+ }
+
+ __attribute__((always_inline)) __STATIC_INLINE void sys_icc_eoir0_set(u32 value)
+ {
+ __MCR(15, 0, value, 12, 8, 1);
+ }
+
+ __attribute__((always_inline)) __STATIC_INLINE void sys_icc_eoir1_set(u32 value)
+ {
+ __MCR(15, 0, value, 12, 12, 1);
+ }
+
+ __attribute__((always_inline)) __STATIC_INLINE void sys_icc_pmr_set(u32 value)
+ {
+ __MCR(15, 0, value, 4, 6, 0);
+ }
+
+ __attribute__((always_inline)) __STATIC_INLINE u32 sys_icc_pmr_get(void)
+ {
+ return __MRC(15, 0, 4, 6, 0);
+ }
+
+ __attribute__((always_inline)) __STATIC_INLINE u32 sys_icc_iar1_get(void)
+ {
+ return __MRC(15, 0, 12, 12, 0);
+ }
+
+ __attribute__((always_inline)) __STATIC_INLINE void sys_icc_sre_set(u32 value)
+ {
+ __MCR(15, 0, value, 12, 12, 5);
+ }
+
+ __attribute__((always_inline)) __STATIC_INLINE u32 sys_icc_sre_get(void)
+ {
+ return __MRC(15, 0, 12, 12, 5);
+ }
+
+ __attribute__((always_inline)) __STATIC_INLINE u32 sys_icc_rpr_get(void)
+ {
+ return __MRC(15, 0, 12, 11, 3);
+ }
+
+ /* Generic Timer registers */
+ /**
+ * @name: arm_aarch32_cntfrq_get
+ * @msg: This register is provided so that software can discover the frequency of the system counter.
+ * @return {__STATIC_INLINEu32}: frequency of the system counter
+ */
+ __attribute__((always_inline)) __STATIC_INLINE u32 arm_aarch32_cntfrq_get(void)
+ {
+ return __MRC(15, 0, 14, 0, 0);
+ }
+
+ /**
+ * @name: arm_aarch32_cnthv_tval_get
+ * @msg: Provides AArch32 access to the timer value for the EL2 virtual timer.
+ * @return {__STATIC_INLINEu32}: EL2 virtual timer Cnt.
+ */
+ __attribute__((always_inline)) __STATIC_INLINE u32 arm_aarch32_cnthv_tval_get(void)
+ {
+ return __MRC(15, 0, 14, 3, 0);
+ }
+
+ /**
+ * @name: arm_aarch32_cnthv_ctl_set
+ * @msg: Provides AArch32 access to the control register for the EL2 virtual timer.
+ * @in param {u32}: RegValue;ENABLE: bit [0] 0 Timer disabled,1 Timer enabled.
+ * IMASK,bit [1]: 0 Timer interrupt is not masked by the IMASK bit. 1 Timer interrupt is masked by the IMASK bit.
+ * ISTATUS, bit [2]: 0 Timer condition is not met. 1 Timer condition is met. rea-only
+ */
+ __attribute__((always_inline)) __STATIC_INLINE void arm_aarch32_cnthv_ctl_set(u32 RegValue)
+ {
+ __MCR(15, 0, RegValue, 14, 3, 1);
+ }
+
+ /**
+ * @name: arm_aarch32_cnthv_ctl_get
+ * @msg: Provides AArch32 access to the control register for the EL2 virtual timer.
+ * @return {__STATIC_INLINEu32}: RegValue;ENABLE: bit [0] 0 Timer disabled,1 Timer enabled.
+ * IMASK,bit [1]: 0 Timer interrupt is not masked by the IMASK bit. 1 Timer interrupt is masked by the IMASK bit.
+ * ISTATUS, bit [2]: 0 Timer condition is not met. 1 Timer condition is met. read-only
+ */
+ __attribute__((always_inline)) __STATIC_INLINE u32 arm_aarch32_cnthv_ctl_get(void)
+ {
+ return __MRC(15, 0, 14, 3, 1);
+ }
+
+ /**
+ * @name: arm_aarch32_cnthv_tval_set
+ * @msg: Provides AArch32 access to the timer value for the EL2 virtual timer.
+ * @in param {u32}: TimerValue, bits [31:0] The TimerValue view of the EL2 virtual timer.
+ */
+ __attribute__((always_inline)) __STATIC_INLINE void arm_aarch32_cnthv_tval_set(u32 RegValue)
+ {
+ __MCR(15, 0, RegValue, 14, 3, 0);
+ }
+
+ /**
+ * @name: arm_aarch32_cntvct_get
+ * @msg: Read the register that holds the 64-bit virtual count value. The virtual count value is equal to the physical count value visible in CNTPCT minus the virtual offset visible in CNTVOFF.
+ * @return {__STATIC_INLINEu64}Bits [63:0] Virtual count value.
+ */
+ __attribute__((always_inline)) __STATIC_INLINE u64 arm_aarch32_cntvct_get(void)
+ {
+ /* "r0" --- low,
+ "r1" --- hi
+ */
+ u32 low;
+ u32 hi;
+ __asm__ volatile(
+ ".word 0xec510f1e \n" /* mrrc p15, 1, r0, r1, c14 */
+ "mov %0, r0 \n"
+ "mov %1, r1 \n"
+ : "=&r"(low), "=&r"(hi));
+ return (((u64)hi) << 32) | low;
+ }
+
+ /* physical */
+
+ /**
+ * @name: arm_aarch32_cntp_tval_get
+ * @msg: Read the register that holds the timer value for the EL1 physical timer.
+ * @return {__STATIC_INLINEu32}: TimerValue, bits [31:0] The TimerValue view of the EL1 physical timer.
+ */
+ __attribute__((always_inline)) __STATIC_INLINE u32 arm_aarch32_cntp_tval_get(void)
+ {
+ return __MRC(15, 0, 14, 2, 0);
+ }
+
+ /**
+ * @name: arm_aarch32_cntp_tval_set
+ * @msg: write the register that control register for the EL1 physical timer.
+ * @in param {u32}: TimerValue, bits [31:0] The TimerValue view of the EL1 physical timer.
+ */
+ __attribute__((always_inline)) __STATIC_INLINE void arm_aarch32_cntp_tval_set(u32 RegValue)
+ {
+ __MCR(15, 0, RegValue, 14, 2, 0);
+ }
+
+ /**
+ * @name: arm_aarch32_cntp_ctl_set
+ * @msg: write the register that control register for the EL1 physical timer.
+ * @in param {u32}: ENABLE, bit[0] Enables the timer ; IMASK, bit [1] Timer interrupt mask bit; ISTATUS, bit [2] The status of the timer.
+ */
+ __attribute__((always_inline)) __STATIC_INLINE void arm_aarch32_cntp_ctl_set(u32 RegValue)
+ {
+ __MCR(15, 0, RegValue, 14, 2, 1);
+ }
+
+ /**
+ * @name: arm_aarch32_cntp_ctl_get
+ * @msg: Read the register that control register for the EL1 physical timer.
+ * @return {__STATIC_INLINEu32}: ENABLE, bit[0] Enables the timer ; IMASK, bit [1] Timer interrupt mask bit; ISTATUS, bit [2] The status of the timer.
+ */
+ __attribute__((always_inline)) __STATIC_INLINE u32 arm_aarch32_cntp_ctl_get(void)
+ {
+ return __MRC(15, 0, 14, 2, 1);
+ }
+
+ /**
+ * @name: arm_aarch32_cntpct_get
+ * @msg: Read the register that holds the 64-bit physical count value.
+ * @return {__STATIC_INLINEu64} CompareValue, bits [63:0] Physical count value.
+ */
+ __attribute__((always_inline)) __STATIC_INLINE u64 arm_aarch32_cntpct_get(void)
+ {
+ /* "r0" --- low,
+ "r1" --- hi
+ */
+ u32 low;
+ u32 hi;
+ __asm__ volatile(
+
+ ".word 0xec510f0e \n" /* mrrc p15, 0, r0, r1, c14 */
+ "mov %0, r0 \n"
+ "mov %1, r1 \n"
+ : "=&r"(low), "=&r"(hi));
+ return (((u64)hi) << 32) | low;
+ }
+
+#define IRQ_DISABLE() \
+ __asm volatile("CPSID i" :: \
+ : "memory"); \
+ __asm volatile("DSB"); \
+ __asm volatile("ISB");
+
+#define IRQ_ENABLE() \
+ __asm volatile("CPSIE i" :: \
+ : "memory"); \
+ __asm volatile("DSB"); \
+ __asm volatile("ISB");
+
+ /* the exception stack without VFP registers */
+ struct ft_hw_exp_stack
+ {
+ u32 r0;
+ u32 r1;
+ u32 r2;
+ u32 r3;
+ u32 r4;
+ u32 r5;
+ u32 r6;
+ u32 r7;
+ u32 r8;
+ u32 r9;
+ u32 r10;
+ u32 fp;
+ u32 ip;
+ u32 sp;
+ u32 lr;
+ u32 pc;
+ u32 cpsr;
+ };
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // !
diff --git a/bsp/ft2004/libraries/doc/ChangeLog.md b/bsp/ft2004/libraries/doc/ChangeLog.md
new file mode 100644
index 0000000000..b0d6bd9d11
--- /dev/null
+++ b/bsp/ft2004/libraries/doc/ChangeLog.md
@@ -0,0 +1,90 @@
+# FT2004-driver ChangeLog
+
+Change log since v0.1.0
+
+# FT2004-driver V0.4.2 Change Log
+
+## bsp/ft_can
+
+1. support can controller
+
+## drivers/rtthread
+
+1. adapt can drivers to rt-thread
+
+# FT2004-driver V0.4.2 Change Log
+
+## bsp/ft_spi
+
+1. support spi ctrl to read and write spi flash in rt-thread
+2. notes that spi chip select pin is ctrl in the way of gpio
+
+## bsp/ft_gpio
+
+1. support group A gpio ctrl, include w/r status, change direction
+
+## component/s25fsxx
+
+1. support s24fs serial spi flash operations
+
+## drivers/rtthread
+
+1. adapt spi drivers to rt-thread SFUD flash support component
+
+# FT2004-driver V0.4.1 Change Log
+
+## bsp/ft_i2c
+
+1. support irq read and write for i2c
+2. delete unused rtc and eeprom component
+
+# FT2004-driver V0.4.0 Change Log
+
+## component/sdmmc
+
+1. add sd2.0 comand support
+2. modify function and variable name by code convention
+
+# FT2004-driver V0.3.2 Change Log
+
+## Docs
+
+1. add ChangeLog.md
+
+## bsp/standlone
+
+1. Added ft_cache.c ft_cache.h
+
+## bsp/ft_gmac
+
+1. Added descriptor cache handling
+
+## drivers/rtthread
+
+1. Modify the bug for drv_qspi
+
+1. Added cache to drv_sdctrl
+
+# FT2004-driver V0.3.1 Change Log
+
+## Docs
+
+1. add ChangeLog.md
+
+## bsp/ft_qspi
+
+1. Complete the writing of QSPI driver
+
+2. Test bsp api in rtthread
+
+## drivers/rtthread
+
+1. add drv_qspi.c
+
+2. Access to the SUFD framework
+
+3. Test functions through the rtthread device management framework
+
+## exhibition
+
+![](./figures/v0.3.0_add.png)
diff --git a/bsp/ft2004/libraries/doc/figures/v0.3.0_add.png b/bsp/ft2004/libraries/doc/figures/v0.3.0_add.png
new file mode 100644
index 0000000000..d7e6b39849
--- /dev/null
+++ b/bsp/ft2004/libraries/doc/figures/v0.3.0_add.png
Binary files differ
diff --git a/bsp/ft2004/libraries/include/asmArm.h b/bsp/ft2004/libraries/include/asmArm.h
new file mode 100644
index 0000000000..7dd7153690
--- /dev/null
+++ b/bsp/ft2004/libraries/include/asmArm.h
@@ -0,0 +1,37 @@
+/*
+ * @ : Copyright (c) 2021 Phytium Information Technology, Inc.
+ *
+ * SPDX-License-Identifier: Apache-2.0.
+ *
+ * @Date: 2021-01-20 10:07:04
+ * @LastEditTime: 2021-05-24 14:36:34
+ * @LastEditors: Please set LastEditors
+ * @Description: In User Settings Edit
+ * @FilePath: \project_freertos\devices\ft2004\gcc\asmArm.h
+ */
+#ifndef ASMARM_H
+#define ASMARM_H
+
+#define FUNC_LABEL(func) \
+ func:
+
+#if (defined __GNUC__)
+#define FUNC_BEGIN(func) \
+ .thumb; \
+ .thumb_func; \
+ .balign 4; \
+ FUNC_LABEL(func)
+#else /* !__GNUC__ */
+#define FUNC_BEGIN(func) \
+ .thumb; \
+ .balign 4; \
+ FUNC_LABEL(func)
+#endif /* __GNUC__ */
+
+#define FUNC(sym) sym
+#define FUNC_END(func) .size FUNC(func), .- FUNC(func)
+
+#define Swap64(var64) var64
+#define Swap32(var32) var32
+
+#endif // !ASMARM_H
diff --git a/bsp/ft2004/libraries/readme.md b/bsp/ft2004/libraries/readme.md
new file mode 100644
index 0000000000..c8d372b5f2
--- /dev/null
+++ b/bsp/ft2004/libraries/readme.md
@@ -0,0 +1,69 @@
+# README
+
+- FT2004 rtos 驱动介绍
+
+## 1. 当前版本
+
+- V0.4.2
+
+## 2. 关于此文档
+
+- 本文档提供此项目框架性和基本功能介绍
+
+- 详细的硬件 bsp 介绍请阅读 doc 文件中模块子文档。
+
+## 3. 编译器版本
+
+- gcc-arm-none-eabi-10-2020-q4-major
+
+## 4. 文件结构介绍
+
+| 目录名 | 内容 |
+| --------- | ---------------------------------------- |
+| bsp | 存放芯片上的外设,例如网卡,i2c 和串口等 |
+| component | 板载外设驱动 ,rtc、eeprom、sdmmc 等 |
+| cpu | cpu 架构方面指令 |
+| doc | 具体外设文档 |
+| drivers | 与不同 rtos 进行耦合的驱动 |
+| gcc | gcc 编译环境下的启动、链接文件 |
+| include | 平台相关的包含 |
+
+## 5. 支持外设
+
+| 外设名 | 备注 |
+| -------- | ---------------------- |
+| ft_gicv3 | gicv3 中断控制器 |
+| ft_gmac | ft gmac 千兆网卡控制器 |
+| ft_i2c | FT I2C |
+| ft_qspi | FT qspi 控制器 |
+| ft_sd | FT mmcsd 控制器 |
+| ft_uart | PrimeCell PL011 |
+| ft_spi | FT spi 控制器 |
+| ft_gpio | FT gpio 控制器 |
+| ft_can | FT can 控制器 |
+
+## 6. 使用实例
+
+[freertos](https://gitee.com/phytium_embedded/ft2004-freertos)
+
+## 7. 参考资源
+
+armv8 Architecture Reference Manual
+
+FT-2000/4 软件编程手册-V1.4
+
+FT-2000/4 硬件设计指导手册
+
+FT-2000 四核处理器数据手册 V1.6
+
+## 8. 贡献方法
+
+请联系飞腾嵌入式软件部
+
+
+
+## 9. 许可协议
+
+Apache License.
diff --git a/bsp/ft2004/make.sh b/bsp/ft2004/make.sh
new file mode 100644
index 0000000000..4fd5c685e0
--- /dev/null
+++ b/bsp/ft2004/make.sh
@@ -0,0 +1,16 @@
+###
+ # @Author: hh
+ # @Date: 2020-12-23 13:53:50
+ # @LastEditTime: 2021-05-18 16:48:25
+ # @LastEditors: Please set LastEditors
+ # @Description: In User Settings Edit
+ # @FilePath: \ft\bare\2_base\factory.sh
+###
+#/bin/sh
+# scons --clean
+# ./update.sh
+scons -j8
+rm /mnt/d/project/tftp/rtthread.bin
+cp ./rtthread.bin /mnt/d/project/tftp/
+
+# arm-none-eabi-objdump -D -m arm ft2004.elf > rtt.dis \ No newline at end of file
diff --git a/bsp/ft2004/rtconfig.h b/bsp/ft2004/rtconfig.h
new file mode 100644
index 0000000000..17f4dd20e8
--- /dev/null
+++ b/bsp/ft2004/rtconfig.h
@@ -0,0 +1,287 @@
+#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 32
+#define RT_USING_SMP
+#define RT_CPUS_NR 4
+#define RT_ALIGN_SIZE 128
+#define RT_THREAD_PRIORITY_32
+#define RT_THREAD_PRIORITY_MAX 32
+#define RT_TICK_PER_SECOND 100
+#define RT_USING_OVERFLOW_CHECK
+#define RT_USING_HOOK
+#define RT_USING_IDLE_HOOK
+#define RT_IDLE_HOOK_LIST_SIZE 4
+#define IDLE_THREAD_STACK_SIZE 4096
+#define RT_USING_TIMER_SOFT
+#define RT_TIMER_THREAD_PRIO 4
+#define RT_TIMER_THREAD_STACK_SIZE 512
+
+/* kservice optimization */
+
+#define RT_DEBUG
+#define RT_DEBUG_COLOR
+
+/* Inter-Thread communication */
+
+#define RT_USING_SEMAPHORE
+#define RT_USING_MUTEX
+#define RT_USING_EVENT
+#define RT_USING_MAILBOX
+#define RT_USING_MESSAGEQUEUE
+
+/* Memory Management */
+
+#define RT_USING_MEMHEAP
+#define RT_USING_SLAB
+#define RT_USING_HEAP
+
+/* Kernel Device Object */
+
+#define RT_USING_DEVICE
+#define RT_USING_INTERRUPT_INFO
+#define RT_USING_CONSOLE
+#define RT_CONSOLEBUF_SIZE 4096
+#define RT_CONSOLE_DEVICE_NAME "uart1"
+#define RT_VER_NUM 0x40004
+#define ARCH_ARM
+#define RT_USING_CPU_FFS
+#define ARCH_ARM_CORTEX_A
+#define RT_USING_GIC_V3
+
+/* RT-Thread Components */
+
+#define RT_USING_COMPONENTS_INIT
+#define RT_USING_USER_MAIN
+#define RT_MAIN_THREAD_STACK_SIZE 2048
+#define RT_MAIN_THREAD_PRIORITY 10
+
+/* C++ features */
+
+
+/* Command shell */
+
+#define RT_USING_FINSH
+#define FINSH_THREAD_NAME "tshell"
+#define FINSH_USING_HISTORY
+#define FINSH_HISTORY_LINES 5
+#define FINSH_USING_SYMTAB
+#define FINSH_USING_DESCRIPTION
+#define FINSH_THREAD_PRIORITY 20
+#define FINSH_THREAD_STACK_SIZE 4096
+#define FINSH_CMD_SIZE 128
+#define FINSH_USING_MSH
+#define FINSH_USING_MSH_DEFAULT
+#define FINSH_ARG_MAX 10
+
+/* Device virtual file system */
+
+#define RT_USING_DFS
+#define DFS_USING_WORKDIR
+#define DFS_FILESYSTEMS_MAX 2
+#define DFS_FILESYSTEM_TYPES_MAX 2
+#define DFS_FD_MAX 16
+#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_USING_DFS_DEVFS
+
+/* Device Drivers */
+
+#define RT_USING_DEVICE_IPC
+#define RT_PIPE_BUFSZ 512
+#define RT_USING_SERIAL
+#define RT_SERIAL_USING_DMA
+#define RT_SERIAL_RB_BUFSZ 256
+#define RT_USING_CAN
+#define RT_USING_SDIO
+#define RT_SDIO_STACK_SIZE 512
+#define RT_SDIO_THREAD_PRIORITY 15
+#define RT_MMCSD_STACK_SIZE 1024
+#define RT_MMCSD_THREAD_PREORITY 22
+#define RT_MMCSD_MAX_PARTITION 16
+#define RT_USING_SPI
+#define RT_USING_QSPI
+#define RT_USING_SFUD
+#define RT_SFUD_USING_SFDP
+#define RT_SFUD_USING_FLASH_INFO_TABLE
+#define RT_SFUD_USING_QSPI
+#define RT_SFUD_SPI_MAX_HZ 50000000
+
+/* Using USB */
+
+
+/* POSIX layer and C standard library */
+
+#define RT_USING_LIBC
+#define RT_USING_POSIX
+#define RT_LIBC_FIXED_TIMEZONE 8
+
+/* Network */
+
+/* Socket abstraction layer */
+
+
+/* Network interface device */
+
+#define RT_USING_NETDEV
+#define NETDEV_USING_IFCONFIG
+#define NETDEV_USING_PING
+#define NETDEV_USING_NETSTAT
+#define NETDEV_USING_AUTO_DEFAULT
+#define NETDEV_IPV4 1
+#define NETDEV_IPV6 0
+
+/* light weight TCP/IP stack */
+
+#define RT_USING_LWIP
+#define RT_USING_LWIP212
+#define RT_LWIP_MEM_ALIGNMENT 4
+#define RT_LWIP_IGMP
+#define RT_LWIP_ICMP
+#define RT_LWIP_DNS
+
+/* Static IPv4 Address */
+
+#define RT_LWIP_IPADDR "192.168.3.20"
+#define RT_LWIP_GWADDR "192.168.3.1"
+#define RT_LWIP_MSKADDR "255.255.255.0"
+#define RT_LWIP_UDP
+#define RT_LWIP_TCP
+#define RT_LWIP_RAW
+#define RT_MEMP_NUM_NETCONN 8
+#define RT_LWIP_PBUF_NUM 16
+#define RT_LWIP_RAW_PCB_NUM 4
+#define RT_LWIP_UDP_PCB_NUM 4
+#define RT_LWIP_TCP_PCB_NUM 4
+#define RT_LWIP_TCP_SEG_NUM 40
+#define RT_LWIP_TCP_SND_BUF 8196
+#define RT_LWIP_TCP_WND 8196
+#define RT_LWIP_TCPTHREAD_PRIORITY 10
+#define RT_LWIP_TCPTHREAD_MBOX_SIZE 8
+#define RT_LWIP_TCPTHREAD_STACKSIZE 1024
+#define RT_LWIP_ETHTHREAD_PRIORITY 12
+#define RT_LWIP_ETHTHREAD_STACKSIZE 1024
+#define RT_LWIP_ETHTHREAD_MBOX_SIZE 8
+#define LWIP_NETIF_STATUS_CALLBACK 1
+#define LWIP_NETIF_LINK_CALLBACK 1
+#define SO_REUSE 1
+#define LWIP_SO_RCVTIMEO 1
+#define LWIP_SO_SNDTIMEO 1
+#define LWIP_SO_RCVBUF 1
+#define LWIP_SO_LINGER 0
+#define LWIP_NETIF_LOOPBACK 0
+#define RT_LWIP_USING_PING
+
+/* AT commands */
+
+
+/* VBUS(Virtual Software BUS) */
+
+
+/* Utilities */
+
+#define RT_USING_ULOG
+#define ULOG_OUTPUT_LVL_W
+#define ULOG_OUTPUT_LVL 4
+#define ULOG_ASSERT_ENABLE
+#define ULOG_LINE_BUF_SIZE 128
+
+/* log format */
+
+#define ULOG_USING_COLOR
+#define ULOG_OUTPUT_TIME
+#define ULOG_OUTPUT_LEVEL
+#define ULOG_OUTPUT_TAG
+#define ULOG_BACKEND_USING_CONSOLE
+
+/* RT-Thread Utestcases */
+
+
+/* RT-Thread online packages */
+
+/* IoT - internet of things */
+
+
+/* Wi-Fi */
+
+/* Marvell WiFi */
+
+
+/* Wiced WiFi */
+
+
+/* IoT Cloud */
+
+
+/* security packages */
+
+
+/* language packages */
+
+
+/* multimedia packages */
+
+
+/* tools packages */
+
+
+/* system packages */
+
+/* acceleration: Assembly language or algorithmic acceleration packages */
+
+
+/* Micrium: Micrium software products porting for RT-Thread */
+
+
+/* peripheral libraries and drivers */
+
+
+/* AI packages */
+
+
+/* miscellaneous packages */
+
+
+/* samples: kernel and components samples */
+
+
+/* entertainment: terminal games and other interesting software packages */
+
+#define FT2004
+
+/* Hardware Drivers Config */
+
+/* On-chip Peripheral Drivers */
+
+#define BSP_USING_UART
+#define RT_USING_UART1
+#define BSP_USING_SDC
+#define BSP_USING_GMAC
+#define BSP_USING_GMAC1
+#define RT_LWIP_ETH_PAD_SIZE 2
+#define BSP_USE_SPI
+#define BSP_USE_GPIO
+#define BSP_USE_CAN
+#define BSP_USING_CAN0
+
+/* Board extended module Drivers */
+
+
+#endif
diff --git a/bsp/ft2004/rtconfig.py b/bsp/ft2004/rtconfig.py
new file mode 100644
index 0000000000..ea482b8282
--- /dev/null
+++ b/bsp/ft2004/rtconfig.py
@@ -0,0 +1,59 @@
+import os
+
+
+# toolchains options
+ARCH='arm'
+CPU='cortex-a'
+CROSS_TOOL='gcc'
+
+if os.getenv('RTT_CC'):
+ CROSS_TOOL = os.getenv('RTT_CC')
+
+# only support GNU GCC compiler.
+PLATFORM = 'gcc'
+EXEC_PATH = '/usr/lib/arm-none-eabi/bin'
+if os.getenv('RTT_EXEC_PATH'):
+ EXEC_PATH = os.getenv('RTT_EXEC_PATH')
+
+BUILD = 'debug'
+
+LIBPATH = '/usr/lib/arm-none-eabi/lib'
+
+
+if PLATFORM == 'gcc':
+ # toolchains
+ PREFIX = 'arm-none-eabi-'
+ CC = PREFIX + 'gcc'
+ CXX = PREFIX + 'g++'
+ AS = PREFIX + 'gcc'
+ AR = PREFIX + 'ar'
+ LINK = PREFIX + 'gcc'
+ TARGET_EXT = 'elf'
+ SIZE = PREFIX + 'size'
+ OBJDUMP = PREFIX + 'objdump'
+ OBJCPY = PREFIX + 'objcopy'
+ STRIP = PREFIX + 'strip'
+
+
+ DEVICE = ' -march=armv8-a -mfpu=vfpv4-d16 -ftree-vectorize -ffast-math -mfloat-abi=soft --specs=nano.specs --specs=nosys.specs -fno-builtin '
+ # DEVICE = ' -march=armv7-a -mfpu=vfpv3-d16 -ftree-vectorize -ffast-math -mfloat-abi=hard'
+ CFLAGS = DEVICE + ' -Wall'
+ AFLAGS = ' -c'+ DEVICE + ' -fsingle-precision-constant -fno-builtin -x assembler-with-cpp -D__ASSEMBLY__'
+ LINK_SCRIPT = 'ft_aarch32.lds'
+ LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread.map,-cref,-u,system_vectors'+\
+ ' -T %s' % LINK_SCRIPT
+
+ CPATH = ''
+ LPATH = LIBPATH
+
+ # generate debug info in all cases
+ AFLAGS += ' -gdwarf-2'
+ CFLAGS += ' -g -gdwarf-2'
+
+ if BUILD == 'debug':
+ CFLAGS += ' -O0'
+ else:
+ CFLAGS += ' -O2'
+
+ POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' +\
+ SIZE + ' $TARGET \n'
diff --git a/bsp/gd32303e-eval/cconfig.h b/bsp/gd32303e-eval/cconfig.h
deleted file mode 100644
index fb19b36e8e..0000000000
--- a/bsp/gd32303e-eval/cconfig.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef CCONFIG_H__
-#define CCONFIG_H__
-/* Automatically generated file; DO NOT EDIT. */
-/* compiler configure file for RT-Thread in GCC*/
-
-#define HAVE_NEWLIB_H 1
-#define LIBC_VERSION "newlib 2.4.0"
-
-#define HAVE_SYS_SIGNAL_H 1
-#define HAVE_SYS_SELECT_H 1
-#define HAVE_PTHREAD_H 1
-
-#define HAVE_FDSET 1
-#define HAVE_SIGACTION 1
-#define GCC_VERSION "5.4.1 20160919 (release) [ARM/embedded-5-branch revision 240496]"
-#define STDC "2011"
-
-#endif
diff --git a/bsp/gd32450z-eval/Libraries/CMSIS/GD/GD32F4xx/Include/gd32f4xx.h b/bsp/gd32450z-eval/Libraries/CMSIS/GD/GD32F4xx/Include/gd32f4xx.h
index 722e943b88..a901975bbd 100644
--- a/bsp/gd32450z-eval/Libraries/CMSIS/GD/GD32F4xx/Include/gd32f4xx.h
+++ b/bsp/gd32450z-eval/Libraries/CMSIS/GD/GD32F4xx/Include/gd32f4xx.h
@@ -1,27 +1,55 @@
/*!
- \file gd32f4xx.h
- \brief general definitions for GD32F4xx
+ \file gd32f4xx.h
+ \brief general definitions for GD32F4xx
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware update for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#ifndef GD32F4XX_H
#define GD32F4XX_H
-#ifdef cplusplus
+#ifdef __cplusplus
extern "C" {
-#endif
+#endif
/* define GD32F4xx */
-#if !defined (GD32F4xx)
- #define GD32F4xx
+#if !defined (GD32F450) && !defined (GD32F405) && !defined (GD32F407)
+ /* #define GD32F450 */
+ /* #define GD32F405 */
+ /* #define GD32F407 */
#endif /* define GD32F4xx */
-#if !defined (GD32F4xx)
- #error "Please select the target GD32F4xx device used in your application (in gd32f4xx.h file)"
+
+#if !defined (GD32F450) && !defined (GD32F405) && !defined (GD32F407)
+ #error "Please select the target GD32F4xx device in gd32f4xx.h file"
#endif /* undefine GD32F4xx tip */
/* define value of high speed crystal oscillator (HXTAL) in Hz */
@@ -31,11 +59,11 @@
/* define startup timeout value of high speed crystal oscillator (HXTAL) */
#if !defined (HXTAL_STARTUP_TIMEOUT)
-#define HXTAL_STARTUP_TIMEOUT ((uint16_t)0x0800)
+#define HXTAL_STARTUP_TIMEOUT ((uint16_t)0xFFFF)
#endif /* high speed crystal oscillator startup timeout */
/* define value of internal 16MHz RC oscillator (IRC16M) in Hz */
-#if !defined (IRC16M_VALUE)
+#if !defined (IRC16M_VALUE)
#define IRC16M_VALUE ((uint32_t)16000000)
#endif /* internal 16MHz RC oscillator value */
@@ -45,12 +73,12 @@
#endif /* internal 16MHz RC oscillator startup timeout */
/* define value of internal 32KHz RC oscillator(IRC32K) in Hz */
-#if !defined (IRC32K_VALUE)
+#if !defined (IRC32K_VALUE)
#define IRC32K_VALUE ((uint32_t)32000)
#endif /* internal 32KHz RC oscillator value */
/* define value of low speed crystal oscillator (LXTAL)in Hz */
-#if !defined (LXTAL_VALUE)
+#if !defined (LXTAL_VALUE)
#define LXTAL_VALUE ((uint32_t)32768)
#endif /* low speed crystal oscillator value */
@@ -61,35 +89,35 @@
#define __GD32F4xx_STDPERIPH_VERSION_MAIN (0x03) /*!< [31:24] main version */
#define __GD32F4xx_STDPERIPH_VERSION_SUB1 (0x00) /*!< [23:16] sub1 version */
#define __GD32F4xx_STDPERIPH_VERSION_SUB2 (0x00) /*!< [15:8] sub2 version */
-#define __GD32F4xx_STDPERIPH_VERSION_RC (0x00) /*!< [7:0] release candidate */
+#define __GD32F4xx_STDPERIPH_VERSION_RC (0x00) /*!< [7:0] release candidate */
#define __GD32F4xx_STDPERIPH_VERSION ((__GD32F4xx_STDPERIPH_VERSION_MAIN << 24)\
|(__GD32F4xx_STDPERIPH_VERSION_SUB1 << 16)\
|(__GD32F4xx_STDPERIPH_VERSION_SUB2 << 8)\
|(__GD32F4xx_STDPERIPH_VERSION_RC))
-/* configuration of the Cortex-M4 processor and core peripherals */
-#define __CM4_REV 0x0001 /*!< Core revision r0p1 */
-#define __MPU_PRESENT 1 /*!< GD32F4xx do not provide MPU */
+/* configuration of the cortex-M4 processor and core peripherals */
+#define __CM4_REV 0x0001 /*!< core revision r0p1 */
+#define __MPU_PRESENT 1 /*!< GD32F4xx provide MPU */
#define __NVIC_PRIO_BITS 4 /*!< GD32F4xx uses 4 bits for the priority levels */
-#define __VENDOR_SYSTICKCONFIG 0 /*!< set to 1 if different sysTick config is used */
+#define __Vendor_SysTickConfig 0 /*!< set to 1 if different sysTick config is used */
#define __FPU_PRESENT 1 /*!< FPU present */
/* define interrupt number */
typedef enum IRQn
{
- /* Cortex-M4 processor exceptions numbers */
+ /* cortex-M4 processor exceptions numbers */
NonMaskableInt_IRQn = -14, /*!< 2 non maskable interrupt */
- MemoryManagement_IRQn = -12, /*!< 4 Cortex-M4 memory management interrupt */
- BusFault_IRQn = -11, /*!< 5 Cortex-M4 bus fault interrupt */
- UsageFault_IRQn = -10, /*!< 6 Cortex-M4 usage fault interrupt */
- SVCall_IRQn = -5, /*!< 11 Cortex-M4 SV call interrupt */
- DebugMonitor_IRQn = -4, /*!< 12 Cortex-M4 debug monitor interrupt */
- PendSV_IRQn = -2, /*!< 14 Cortex-M4 pend SV interrupt */
- SysTick_IRQn = -1, /*!< 15 Cortex-M4 system tick interrupt */
+ MemoryManagement_IRQn = -12, /*!< 4 cortex-M4 memory management interrupt */
+ BusFault_IRQn = -11, /*!< 5 cortex-M4 bus fault interrupt */
+ UsageFault_IRQn = -10, /*!< 6 cortex-M4 usage fault interrupt */
+ SVCall_IRQn = -5, /*!< 11 cortex-M4 SV call interrupt */
+ DebugMonitor_IRQn = -4, /*!< 12 cortex-M4 debug monitor interrupt */
+ PendSV_IRQn = -2, /*!< 14 cortex-M4 pend SV interrupt */
+ SysTick_IRQn = -1, /*!< 15 cortex-M4 system tick interrupt */
/* interruput numbers */
- WWDGT_IRQn = 0, /*!< window watchDog timer interrupt */
+ WWDGT_IRQn = 0, /*!< window watchdog timer interrupt */
LVD_IRQn = 1, /*!< LVD through EXTI line detect interrupt */
- TAMPER_STAMP_IRQn = 2, /*!< Tamper and TimeStamp through EXTI Line detect */
- RTC_WKUP_IRQn = 3, /*!< RTC Wakeup through EXTI line interrupt */
+ TAMPER_STAMP_IRQn = 2, /*!< tamper and timestamp through EXTI line detect */
+ RTC_WKUP_IRQn = 3, /*!< RTC wakeup through EXTI line interrupt */
FMC_IRQn = 4, /*!< FMC interrupt */
RCU_CTC_IRQn = 5, /*!< RCU and CTC interrupt */
EXTI0_IRQn = 6, /*!< EXTI line 0 interrupts */
@@ -97,23 +125,23 @@ typedef enum IRQn
EXTI2_IRQn = 8, /*!< EXTI line 2 interrupts */
EXTI3_IRQn = 9, /*!< EXTI line 3 interrupts */
EXTI4_IRQn = 10, /*!< EXTI line 4 interrupts */
- DMA0_Channel0_IRQn = 11, /*!< DMA0 Channel0 Interrupt */
- DMA0_Channel1_IRQn = 12, /*!< DMA0 Channel1 Interrupt */
- DMA0_Channel2_IRQn = 13, /*!< DMA0 Channel2 Interrupt */
- DMA0_Channel3_IRQn = 14, /*!< DMA0 Channel3 Interrupt */
- DMA0_Channel4_IRQn = 15, /*!< DMA0 Channel4 Interrupt */
- DMA0_Channel5_IRQn = 16, /*!< DMA0 Channel5 Interrupt */
- DMA0_Channel6_IRQn = 17, /*!< DMA0 Channel6 Interrupt */
+ DMA0_Channel0_IRQn = 11, /*!< DMA0 channel0 Interrupt */
+ DMA0_Channel1_IRQn = 12, /*!< DMA0 channel1 Interrupt */
+ DMA0_Channel2_IRQn = 13, /*!< DMA0 channel2 interrupt */
+ DMA0_Channel3_IRQn = 14, /*!< DMA0 channel3 interrupt */
+ DMA0_Channel4_IRQn = 15, /*!< DMA0 channel4 interrupt */
+ DMA0_Channel5_IRQn = 16, /*!< DMA0 channel5 interrupt */
+ DMA0_Channel6_IRQn = 17, /*!< DMA0 channel6 interrupt */
ADC_IRQn = 18, /*!< ADC interrupt */
- CAN0_TX_IRQn = 19, /*!< CAN0 TX interrupts */
- CAN0_RX0_IRQn = 20, /*!< CAN0 RX0 interrupts */
- CAN0_RX1_IRQn = 21, /*!< CAN0 RX1 interrupts */
- CAN0_EWMC_IRQn = 22, /*!< CAN0 EWMC interrupts */
+ CAN0_TX_IRQn = 19, /*!< CAN0 TX interrupt */
+ CAN0_RX0_IRQn = 20, /*!< CAN0 RX0 interrupt */
+ CAN0_RX1_IRQn = 21, /*!< CAN0 RX1 interrupt */
+ CAN0_EWMC_IRQn = 22, /*!< CAN0 EWMC interrupt */
EXTI5_9_IRQn = 23, /*!< EXTI[9:5] interrupts */
- TIMER0_BRK_TIMER8_IRQn = 24, /*!< TIMER0 Break and TIMER8 interrupts */
- TIMER0_UP_TIMER9_IRQn = 25, /*!< TIMER0 Update and TIMER9 interrupts */
- TIMER0_TRG_CMT_TIMER10_IRQn = 26, /*!< TIMER0 Trigger and Commutation and TIMER10 interrupts */
- TIMER0_CC_IRQn = 27, /*!< TIMER0 Capture Compare interrupts */
+ TIMER0_BRK_TIMER8_IRQn = 24, /*!< TIMER0 break and TIMER8 interrupts */
+ TIMER0_UP_TIMER9_IRQn = 25, /*!< TIMER0 update and TIMER9 interrupts */
+ TIMER0_TRG_CMT_TIMER10_IRQn = 26, /*!< TIMER0 trigger and commutation and TIMER10 interrupts */
+ TIMER0_Channel_IRQn = 27, /*!< TIMER0 channel capture compare interrupt */
TIMER1_IRQn = 28, /*!< TIMER1 interrupt */
TIMER2_IRQn = 29, /*!< TIMER2 interrupt */
TIMER3_IRQn = 30, /*!< TIMER3 interrupts */
@@ -127,54 +155,127 @@ typedef enum IRQn
USART1_IRQn = 38, /*!< USART1 interrupt */
USART2_IRQn = 39, /*!< USART2 interrupt */
EXTI10_15_IRQn = 40, /*!< EXTI[15:10] interrupts */
- RTC_Alarm_IRQn = 41, /*!< RTC Alarm interrupt */
- USBFS_WKUP_IRQn = 42, /*!< USBFS Wakeup interrupt */
- TIMER7_BRK_TIMER11_IRQn = 43, /*!< TIMER7 Break and TIMER11 interrupts */
- TIMER7_UP_TIMER12_IRQn = 44, /*!< TIMER7 Update and TIMER12 interrupts */
- TIMER7_TRG_CMT_TIMER13_IRQn = 45, /*!< TIMER7 Trigger and Commutation and TIMER13 interrupts */
- TIMER7_CC_IRQn = 46, /*!< TIMER7 Capture Compare interrupts */
- DMA0_Channel7_IRQn = 47, /*!< DMA0 Channel7 Interrupt */
- EXMC_IRQn = 48, /*!< EXMC Interrupt */
- SDIO_IRQn = 49, /*!< SDIO Interrupt */
- TIMER4_IRQn = 50, /*!< TIMER4 Interrupt */
- SPI2_IRQn = 51, /*!< SPI2 Interrupt */
- UART3_IRQn = 52, /*!< UART3 Interrupt */
- UART4_IRQn = 53, /*!< UART4 Interrupt */
- TIMER5_DAC_IRQn = 54, /*!< TIMER5 and DAC0 DAC1 Underrun error Interrupt */
- TIMER6_IRQn = 55, /*!< TIMER6 Interrupt */
- DMA1_Channel0_IRQn = 56, /*!< DMA1 Channel0 Interrupt */
- DMA1_Channel1_IRQn = 57, /*!< DMA1 Channel1 Interrupt */
- DMA1_Channel2_IRQn = 58, /*!< DMA1 Channel2 Interrupt */
- DMA1_Channel3_IRQn = 59, /*!< DMA1 Channel3 Interrupt */
- DMA1_Channel4_IRQn = 60, /*!< DMA1 Channel4 Interrupt */
- ENET_IRQn = 61, /*!< Ethernet Interrupt */
- ENET_WKUP_IRQn = 62, /*!< Ethernet Wakeup through EXTI Line Interrupt */
- CAN1_TX_IRQn = 63, /*!< CAN1 TX Interrupt */
- CAN1_RX0_IRQn = 64, /*!< CAN1 RX0 Interrupt */
- CAN1_RX1_IRQn = 65, /*!< CAN1 RX1 Interrupt */
- CAN1_EWMC_IRQn = 66, /*!< CAN1 EWMC Interrupt */
- USBFS_IRQn = 67, /*!< USBFS Interrupt */
- DMA1_Channel5_IRQn = 68, /*!< DMA1 Channel5 Interrupt */
- DMA1_Channel6_IRQn = 69, /*!< DMA1 Channel6 Interrupt */
- DMA1_Channel7_IRQn = 70, /*!< DMA1 Channel7 Interrupt */
- USART5_IRQn = 71, /*!< USART5 Interrupt */
- I2C2_EV_IRQn = 72, /*!< I2C2 Event Interrupt */
- I2C2_ER_IRQn = 73, /*!< I2C2 Error Interrupt */
- USBHS_EP1_Out_IRQn = 74, /*!< USBHS Endpoint 1 Out Interrupt */
- USBHS_EP1_In_IRQn = 75, /*!< USBHS Endpoint 1 in Interrupt */
- USBHS_WKUP_IRQn = 76, /*!< USBHS Wakeup through EXTI Line Interrupt */
- USBHS_IRQn = 77, /*!< USBHS Interrupt */
- DCI_IRQn = 78, /*!< DCI Interrupt */
- TRNG_IRQn = 80, /*!< TRNG Interrupt */
- FPU_IRQn = 81, /*!< FPU Interrupt */
- UART6_IRQn = 82, /*!< UART6 Interrupt */
- UART7_IRQn = 83, /*!< UART7 Interrupt */
- SPI3_IRQn = 84, /*!< SPI3 Interrupt */
- SPI4_IRQn = 85, /*!< SPI4 Interrupt */
- SPI5_IRQn = 86, /*!< SPI5 Interrupt */
- TLI_IRQn = 88, /*!< TLI Interrupt */
- TLI_ER_IRQn = 89, /*!< TLI Error Interrupt */
- IPA_IRQn = 90, /*!< IPA Interrupt */
+ RTC_Alarm_IRQn = 41, /*!< RTC alarm interrupt */
+ USBFS_WKUP_IRQn = 42, /*!< USBFS wakeup interrupt */
+ TIMER7_BRK_TIMER11_IRQn = 43, /*!< TIMER7 break and TIMER11 interrupts */
+ TIMER7_UP_TIMER12_IRQn = 44, /*!< TIMER7 update and TIMER12 interrupts */
+ TIMER7_TRG_CMT_TIMER13_IRQn = 45, /*!< TIMER7 trigger and commutation and TIMER13 interrupts */
+ TIMER7_Channel_IRQn = 46, /*!< TIMER7 channel capture compare interrupt */
+ DMA0_Channel7_IRQn = 47, /*!< DMA0 channel7 interrupt */
+
+#if defined (GD32F450)
+ EXMC_IRQn = 48, /*!< EXMC interrupt */
+ SDIO_IRQn = 49, /*!< SDIO interrupt */
+ TIMER4_IRQn = 50, /*!< TIMER4 interrupt */
+ SPI2_IRQn = 51, /*!< SPI2 interrupt */
+ UART3_IRQn = 52, /*!< UART3 interrupt */
+ UART4_IRQn = 53, /*!< UART4 interrupt */
+ TIMER5_DAC_IRQn = 54, /*!< TIMER5 and DAC0 DAC1 underrun error interrupts */
+ TIMER6_IRQn = 55, /*!< TIMER6 interrupt */
+ DMA1_Channel0_IRQn = 56, /*!< DMA1 channel0 interrupt */
+ DMA1_Channel1_IRQn = 57, /*!< DMA1 channel1 interrupt */
+ DMA1_Channel2_IRQn = 58, /*!< DMA1 channel2 interrupt */
+ DMA1_Channel3_IRQn = 59, /*!< DMA1 channel3 interrupt */
+ DMA1_Channel4_IRQn = 60, /*!< DMA1 channel4 interrupt */
+ ENET_IRQn = 61, /*!< ENET interrupt */
+ ENET_WKUP_IRQn = 62, /*!< ENET wakeup through EXTI line interrupt */
+ CAN1_TX_IRQn = 63, /*!< CAN1 TX interrupt */
+ CAN1_RX0_IRQn = 64, /*!< CAN1 RX0 interrupt */
+ CAN1_RX1_IRQn = 65, /*!< CAN1 RX1 interrupt */
+ CAN1_EWMC_IRQn = 66, /*!< CAN1 EWMC interrupt */
+ USBFS_IRQn = 67, /*!< USBFS interrupt */
+ DMA1_Channel5_IRQn = 68, /*!< DMA1 channel5 interrupt */
+ DMA1_Channel6_IRQn = 69, /*!< DMA1 channel6 interrupt */
+ DMA1_Channel7_IRQn = 70, /*!< DMA1 channel7 interrupt */
+ USART5_IRQn = 71, /*!< USART5 interrupt */
+ I2C2_EV_IRQn = 72, /*!< I2C2 event interrupt */
+ I2C2_ER_IRQn = 73, /*!< I2C2 error interrupt */
+ USBHS_EP1_Out_IRQn = 74, /*!< USBHS endpoint 1 out interrupt */
+ USBHS_EP1_In_IRQn = 75, /*!< USBHS endpoint 1 in interrupt */
+ USBHS_WKUP_IRQn = 76, /*!< USBHS wakeup through EXTI line interrupt */
+ USBHS_IRQn = 77, /*!< USBHS interrupt */
+ DCI_IRQn = 78, /*!< DCI interrupt */
+ TRNG_IRQn = 80, /*!< TRNG interrupt */
+ FPU_IRQn = 81, /*!< FPU interrupt */
+ UART6_IRQn = 82, /*!< UART6 interrupt */
+ UART7_IRQn = 83, /*!< UART7 interrupt */
+ SPI3_IRQn = 84, /*!< SPI3 interrupt */
+ SPI4_IRQn = 85, /*!< SPI4 interrupt */
+ SPI5_IRQn = 86, /*!< SPI5 interrupt */
+ TLI_IRQn = 88, /*!< TLI interrupt */
+ TLI_ER_IRQn = 89, /*!< TLI error interrupt */
+ IPA_IRQn = 90, /*!< IPA interrupt */
+#endif /* GD32F450 */
+
+#if defined (GD32F405)
+ SDIO_IRQn = 49, /*!< SDIO interrupt */
+ TIMER4_IRQn = 50, /*!< TIMER4 interrupt */
+ SPI2_IRQn = 51, /*!< SPI2 interrupt */
+ UART3_IRQn = 52, /*!< UART3 interrupt */
+ UART4_IRQn = 53, /*!< UART4 interrupt */
+ TIMER5_DAC_IRQn = 54, /*!< TIMER5 and DAC0 DAC1 underrun error interrupts */
+ TIMER6_IRQn = 55, /*!< TIMER6 interrupt */
+ DMA1_Channel0_IRQn = 56, /*!< DMA1 channel0 interrupt */
+ DMA1_Channel1_IRQn = 57, /*!< DMA1 channel1 interrupt */
+ DMA1_Channel2_IRQn = 58, /*!< DMA1 channel2 interrupt */
+ DMA1_Channel3_IRQn = 59, /*!< DMA1 channel3 interrupt */
+ DMA1_Channel4_IRQn = 60, /*!< DMA1 channel4 interrupt */
+ CAN1_TX_IRQn = 63, /*!< CAN1 TX interrupt */
+ CAN1_RX0_IRQn = 64, /*!< CAN1 RX0 interrupt */
+ CAN1_RX1_IRQn = 65, /*!< CAN1 RX1 interrupt */
+ CAN1_EWMC_IRQn = 66, /*!< CAN1 EWMC interrupt */
+ USBFS_IRQn = 67, /*!< USBFS interrupt */
+ DMA1_Channel5_IRQn = 68, /*!< DMA1 channel5 interrupt */
+ DMA1_Channel6_IRQn = 69, /*!< DMA1 channel6 interrupt */
+ DMA1_Channel7_IRQn = 70, /*!< DMA1 channel7 interrupt */
+ USART5_IRQn = 71, /*!< USART5 interrupt */
+ I2C2_EV_IRQn = 72, /*!< I2C2 event interrupt */
+ I2C2_ER_IRQn = 73, /*!< I2C2 error interrupt */
+ USBHS_EP1_Out_IRQn = 74, /*!< USBHS endpoint 1 Out interrupt */
+ USBHS_EP1_In_IRQn = 75, /*!< USBHS endpoint 1 in interrupt */
+ USBHS_WKUP_IRQn = 76, /*!< USBHS wakeup through EXTI line interrupt */
+ USBHS_IRQn = 77, /*!< USBHS interrupt */
+ DCI_IRQn = 78, /*!< DCI interrupt */
+ TRNG_IRQn = 80, /*!< TRNG interrupt */
+ FPU_IRQn = 81, /*!< FPU interrupt */
+#endif /* GD32F405 */
+
+#if defined (GD32F407)
+ EXMC_IRQn = 48, /*!< EXMC interrupt */
+ SDIO_IRQn = 49, /*!< SDIO interrupt */
+ TIMER4_IRQn = 50, /*!< TIMER4 interrupt */
+ SPI2_IRQn = 51, /*!< SPI2 interrupt */
+ UART3_IRQn = 52, /*!< UART3 interrupt */
+ UART4_IRQn = 53, /*!< UART4 interrupt */
+ TIMER5_DAC_IRQn = 54, /*!< TIMER5 and DAC0 DAC1 underrun error interrupts */
+ TIMER6_IRQn = 55, /*!< TIMER6 interrupt */
+ DMA1_Channel0_IRQn = 56, /*!< DMA1 channel0 interrupt */
+ DMA1_Channel1_IRQn = 57, /*!< DMA1 channel1 interrupt */
+ DMA1_Channel2_IRQn = 58, /*!< DMA1 channel2 interrupt */
+ DMA1_Channel3_IRQn = 59, /*!< DMA1 channel3 interrupt */
+ DMA1_Channel4_IRQn = 60, /*!< DMA1 channel4 interrupt */
+ ENET_IRQn = 61, /*!< ENET interrupt */
+ ENET_WKUP_IRQn = 62, /*!< ENET wakeup through EXTI line interrupt */
+ CAN1_TX_IRQn = 63, /*!< CAN1 TX interrupt */
+ CAN1_RX0_IRQn = 64, /*!< CAN1 RX0 interrupt */
+ CAN1_RX1_IRQn = 65, /*!< CAN1 RX1 interrupt */
+ CAN1_EWMC_IRQn = 66, /*!< CAN1 EWMC interrupt */
+ USBFS_IRQn = 67, /*!< USBFS interrupt */
+ DMA1_Channel5_IRQn = 68, /*!< DMA1 channel5 interrupt */
+ DMA1_Channel6_IRQn = 69, /*!< DMA1 channel6 interrupt */
+ DMA1_Channel7_IRQn = 70, /*!< DMA1 channel7 interrupt */
+ USART5_IRQn = 71, /*!< USART5 interrupt */
+ I2C2_EV_IRQn = 72, /*!< I2C2 event interrupt */
+ I2C2_ER_IRQn = 73, /*!< I2C2 error interrupt */
+ USBHS_EP1_Out_IRQn = 74, /*!< USBHS endpoint 1 out interrupt */
+ USBHS_EP1_In_IRQn = 75, /*!< USBHS endpoint 1 in interrupt */
+ USBHS_WKUP_IRQn = 76, /*!< USBHS wakeup through EXTI line interrupt */
+ USBHS_IRQn = 77, /*!< USBHS interrupt */
+ DCI_IRQn = 78, /*!< DCI interrupt */
+ TRNG_IRQn = 80, /*!< TRNG interrupt */
+ FPU_IRQn = 81, /*!< FPU interrupt */
+#endif /* GD32F407 */
+
} IRQn_Type;
/* includes */
@@ -193,7 +294,7 @@ typedef enum {ERROR = 0, SUCCESS = !ERROR} ErrStatus;
#define REG16(addr) (*(volatile uint16_t *)(uint32_t)(addr))
#define REG8(addr) (*(volatile uint8_t *)(uint32_t)(addr))
#define BIT(x) ((uint32_t)((uint32_t)0x01U<<(x)))
-#define BITS(start, end) ((0xFFFFFFFFUL << (start)) & (0xFFFFFFFFUL >> (31U - (uint32_t)(end))))
+#define BITS(start, end) ((0xFFFFFFFFUL << (start)) & (0xFFFFFFFFUL >> (31U - (uint32_t)(end))))
#define GET_BITS(regval, start, end) (((regval) & BITS((start),(end))) >> (start))
/* main flash and SRAM memory map */
@@ -254,7 +355,7 @@ typedef enum {ERROR = 0, SUCCESS = !ERROR} ErrStatus;
/* define marco USE_STDPERIPH_DRIVER */
#if !defined USE_STDPERIPH_DRIVER
#define USE_STDPERIPH_DRIVER
-#endif
+#endif
#ifdef USE_STDPERIPH_DRIVER
#include "gd32f4xx_libopt.h"
#endif /* USE_STDPERIPH_DRIVER */
@@ -262,4 +363,4 @@ typedef enum {ERROR = 0, SUCCESS = !ERROR} ErrStatus;
#ifdef cplusplus
}
#endif
-#endif
+#endif
diff --git a/bsp/gd32450z-eval/Libraries/CMSIS/GD/GD32F4xx/Source/system_gd32f4xx.c b/bsp/gd32450z-eval/Libraries/CMSIS/GD/GD32F4xx/Source/system_gd32f4xx.c
index 6da45fa40e..2ea97ae3f8 100644
--- a/bsp/gd32450z-eval/Libraries/CMSIS/GD/GD32F4xx/Source/system_gd32f4xx.c
+++ b/bsp/gd32450z-eval/Libraries/CMSIS/GD/GD32F4xx/Source/system_gd32f4xx.c
@@ -56,6 +56,9 @@
#define SEL_IRC16M 0x00U
#define SEL_HXTAL 0x01U
#define SEL_PLLP 0x02U
+#define RCU_MODIFY {volatile uint32_t i; \
+ RCU_CFG0 |= RCU_AHB_CKSYS_DIV2; \
+ for(i=0;i<50000;i++);}
/* set the system clock frequency and declare the system clock configuration function */
#ifdef __SYSTEM_CLOCK_IRC16M
@@ -109,10 +112,12 @@ void SystemInit (void)
#if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */
#endif
- /* Reset the RCC clock configuration to the default reset state ------------*/
+ /* Reset the RCU clock configuration to the default reset state ------------*/
/* Set IRC16MEN bit */
RCU_CTL |= RCU_CTL_IRC16MEN;
+ RCU_MODIFY
+
/* Reset CFG0 register */
RCU_CFG0 = 0x00000000U;
@@ -127,12 +132,10 @@ void SystemInit (void)
/* Disable all interrupts */
RCU_INT = 0x00000000U;
-
- /* Configure the System clock source, PLL Multiplier and Divider factors,
+
+ /* Configure the System clock source, PLL Multiplier and Divider factors,
AHB/APBx prescalers and Flash settings ----------------------------------*/
system_clock_config();
-
-
}
/*!
\brief configure the system clock
@@ -164,7 +167,7 @@ static void system_clock_config(void)
system_clock_200m_8m_hxtal();
#elif defined (__SYSTEM_CLOCK_200M_PLL_25M_HXTAL)
system_clock_200m_25m_hxtal();
-#endif /* __SYSTEM_CLOCK_IRC16M */
+#endif /* __SYSTEM_CLOCK_IRC16M */
}
#ifdef __SYSTEM_CLOCK_IRC16M
@@ -178,34 +181,33 @@ static void system_clock_16m_irc16m(void)
{
uint32_t timeout = 0U;
uint32_t stab_flag = 0U;
-
+
/* enable IRC16M */
RCU_CTL |= RCU_CTL_IRC16MEN;
-
+
/* wait until IRC16M is stable or the startup time is longer than IRC16M_STARTUP_TIMEOUT */
do{
timeout++;
stab_flag = (RCU_CTL & RCU_CTL_IRC16MSTB);
- }
- while((0U == stab_flag) && (IRC16M_STARTUP_TIMEOUT != timeout));
-
+ }while((0U == stab_flag) && (IRC16M_STARTUP_TIMEOUT != timeout));
+
/* if fail */
if(0U == (RCU_CTL & RCU_CTL_IRC16MSTB)){
- while(1){
- }
+ while(1){
+ }
}
-
+
/* AHB = SYSCLK */
RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
/* APB2 = AHB */
RCU_CFG0 |= RCU_APB2_CKAHB_DIV1;
/* APB1 = AHB */
RCU_CFG0 |= RCU_APB1_CKAHB_DIV1;
-
+
/* select IRC16M as system clock */
RCU_CFG0 &= ~RCU_CFG0_SCS;
RCU_CFG0 |= RCU_CKSYSSRC_IRC16M;
-
+
/* wait until IRC16M is selected as system clock */
while(0 != (RCU_CFG0 & RCU_SCSS_IRC16M)){
}
@@ -222,34 +224,33 @@ static void system_clock_hxtal(void)
{
uint32_t timeout = 0U;
uint32_t stab_flag = 0U;
-
+
/* enable HXTAL */
RCU_CTL |= RCU_CTL_HXTALEN;
-
+
/* wait until HXTAL is stable or the startup time is longer than HXTAL_STARTUP_TIMEOUT */
do{
timeout++;
stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
- }
- while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
-
+ }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
+
/* if fail */
if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
- while(1){
- }
+ while(1){
+ }
}
-
+
/* AHB = SYSCLK */
RCU_CFG0 |= RCU_AHB_CKSYS_DIV1;
/* APB2 = AHB */
RCU_CFG0 |= RCU_APB2_CKAHB_DIV1;
/* APB1 = AHB */
RCU_CFG0 |= RCU_APB1_CKAHB_DIV1;
-
+
/* select HXTAL as system clock */
RCU_CFG0 &= ~RCU_CFG0_SCS;
RCU_CFG0 |= RCU_CKSYSSRC_HXTAL;
-
+
/* wait until HXTAL is selected as system clock */
while(0 == (RCU_CFG0 & RCU_SCSS_HXTAL)){
}
@@ -266,7 +267,7 @@ static void system_clock_120m_irc16m(void)
{
uint32_t timeout = 0U;
uint32_t stab_flag = 0U;
-
+
/* enable IRC16M */
RCU_CTL |= RCU_CTL_IRC16MEN;
@@ -274,15 +275,14 @@ static void system_clock_120m_irc16m(void)
do{
timeout++;
stab_flag = (RCU_CTL & RCU_CTL_IRC16MSTB);
- }
- while((0U == stab_flag) && (IRC16M_STARTUP_TIMEOUT != timeout));
+ }while((0U == stab_flag) && (IRC16M_STARTUP_TIMEOUT != timeout));
/* if fail */
if(0U == (RCU_CTL & RCU_CTL_IRC16MSTB)){
- while(1){
- }
+ while(1){
+ }
}
-
+
RCU_APB1EN |= RCU_APB1EN_PMUEN;
PMU_CTL |= PMU_CTL_LDOVS;
@@ -294,7 +294,7 @@ static void system_clock_120m_irc16m(void)
/* APB1 = AHB/4 */
RCU_CFG0 |= RCU_APB1_CKAHB_DIV4;
- /* Configure the main PLL, PLL_M = 16, PLL_N = 240, PLL_P = 2, PLL_Q = 5 */
+ /* Configure the main PLL, PSC = 16, PLL_N = 240, PLL_P = 2, PLL_Q = 5 */
RCU_PLL = (16U | (240U << 6U) | (((2U >> 1U) - 1U) << 16U) |
(RCU_PLLSRC_IRC16M) | (5U << 24U));
@@ -304,19 +304,17 @@ static void system_clock_120m_irc16m(void)
/* wait until PLL is stable */
while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
}
-
+
/* Enable the high-drive to extend the clock frequency to 120 Mhz */
PMU_CTL |= PMU_CTL_HDEN;
- while(0U == (PMU_CS & PMU_CS_HDRF))
- {
+ while(0U == (PMU_CS & PMU_CS_HDRF)){
}
-
+
/* select the high-drive mode */
PMU_CTL |= PMU_CTL_HDS;
- while(0U == (PMU_CS & PMU_CS_HDSRF))
- {
- }
-
+ while(0U == (PMU_CS & PMU_CS_HDSRF)){
+ }
+
/* select PLL as system clock */
RCU_CFG0 &= ~RCU_CFG0_SCS;
RCU_CFG0 |= RCU_CKSYSSRC_PLLP;
@@ -337,7 +335,7 @@ static void system_clock_120m_8m_hxtal(void)
{
uint32_t timeout = 0U;
uint32_t stab_flag = 0U;
-
+
/* enable HXTAL */
RCU_CTL |= RCU_CTL_HXTALEN;
@@ -345,15 +343,14 @@ static void system_clock_120m_8m_hxtal(void)
do{
timeout++;
stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
- }
- while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
+ }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
/* if fail */
if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
- while(1){
- }
+ while(1){
+ }
}
-
+
RCU_APB1EN |= RCU_APB1EN_PMUEN;
PMU_CTL |= PMU_CTL_LDOVS;
@@ -365,7 +362,7 @@ static void system_clock_120m_8m_hxtal(void)
/* APB1 = AHB/4 */
RCU_CFG0 |= RCU_APB1_CKAHB_DIV4;
- /* Configure the main PLL, PLL_M = 8, PLL_N = 240, PLL_P = 2, PLL_Q = 5 */
+ /* Configure the main PLL, PSC = 8, PLL_N = 240, PLL_P = 2, PLL_Q = 5 */
RCU_PLL = (8U | (240U << 6U) | (((2U >> 1U) - 1U) << 16U) |
(RCU_PLLSRC_HXTAL) | (5U << 24U));
@@ -375,19 +372,17 @@ static void system_clock_120m_8m_hxtal(void)
/* wait until PLL is stable */
while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
}
-
+
/* Enable the high-drive to extend the clock frequency to 120 Mhz */
PMU_CTL |= PMU_CTL_HDEN;
- while(0U == (PMU_CS & PMU_CS_HDRF))
- {
+ while(0U == (PMU_CS & PMU_CS_HDRF)){
}
-
+
/* select the high-drive mode */
PMU_CTL |= PMU_CTL_HDS;
- while(0U == (PMU_CS & PMU_CS_HDSRF))
- {
- }
-
+ while(0U == (PMU_CS & PMU_CS_HDSRF)){
+ }
+
/* select PLL as system clock */
RCU_CFG0 &= ~RCU_CFG0_SCS;
RCU_CFG0 |= RCU_CKSYSSRC_PLLP;
@@ -408,7 +403,7 @@ static void system_clock_120m_25m_hxtal(void)
{
uint32_t timeout = 0U;
uint32_t stab_flag = 0U;
-
+
/* enable HXTAL */
RCU_CTL |= RCU_CTL_HXTALEN;
@@ -416,15 +411,14 @@ static void system_clock_120m_25m_hxtal(void)
do{
timeout++;
stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
- }
- while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
+ }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
/* if fail */
if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
- while(1){
- }
+ while(1){
+ }
}
-
+
RCU_APB1EN |= RCU_APB1EN_PMUEN;
PMU_CTL |= PMU_CTL_LDOVS;
@@ -436,7 +430,7 @@ static void system_clock_120m_25m_hxtal(void)
/* APB1 = AHB/4 */
RCU_CFG0 |= RCU_APB1_CKAHB_DIV4;
- /* Configure the main PLL, PLL_M = 25, PLL_N = 240, PLL_P = 2, PLL_Q = 5 */
+ /* Configure the main PLL, PSC = 25, PLL_N = 240, PLL_P = 2, PLL_Q = 5 */
RCU_PLL = (25U | (240U << 6U) | (((2U >> 1U) - 1U) << 16U) |
(RCU_PLLSRC_HXTAL) | (5U << 24U));
@@ -446,19 +440,17 @@ static void system_clock_120m_25m_hxtal(void)
/* wait until PLL is stable */
while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
}
-
+
/* Enable the high-drive to extend the clock frequency to 120 Mhz */
PMU_CTL |= PMU_CTL_HDEN;
- while(0U == (PMU_CS & PMU_CS_HDRF))
- {
+ while(0U == (PMU_CS & PMU_CS_HDRF)){
}
-
+
/* select the high-drive mode */
PMU_CTL |= PMU_CTL_HDS;
- while(0U == (PMU_CS & PMU_CS_HDSRF))
- {
- }
-
+ while(0U == (PMU_CS & PMU_CS_HDSRF)){
+ }
+
/* select PLL as system clock */
RCU_CFG0 &= ~RCU_CFG0_SCS;
RCU_CFG0 |= RCU_CKSYSSRC_PLLP;
@@ -479,7 +471,7 @@ static void system_clock_168m_irc16m(void)
{
uint32_t timeout = 0U;
uint32_t stab_flag = 0U;
-
+
/* enable IRC16M */
RCU_CTL |= RCU_CTL_IRC16MEN;
@@ -487,15 +479,14 @@ static void system_clock_168m_irc16m(void)
do{
timeout++;
stab_flag = (RCU_CTL & RCU_CTL_IRC16MSTB);
- }
- while((0U == stab_flag) && (IRC16M_STARTUP_TIMEOUT != timeout));
+ }while((0U == stab_flag) && (IRC16M_STARTUP_TIMEOUT != timeout));
/* if fail */
if(0U == (RCU_CTL & RCU_CTL_IRC16MSTB)){
- while(1){
- }
+ while(1){
+ }
}
-
+
RCU_APB1EN |= RCU_APB1EN_PMUEN;
PMU_CTL |= PMU_CTL_LDOVS;
@@ -507,7 +498,7 @@ static void system_clock_168m_irc16m(void)
/* APB1 = AHB/4 */
RCU_CFG0 |= RCU_APB1_CKAHB_DIV4;
- /* Configure the main PLL, PLL_M = 16, PLL_N = 336, PLL_P = 2, PLL_Q = 7 */
+ /* Configure the main PLL, PSC = 16, PLL_N = 336, PLL_P = 2, PLL_Q = 7 */
RCU_PLL = (16U | (336U << 6U) | (((2U >> 1U) - 1U) << 16U) |
(RCU_PLLSRC_IRC16M) | (7U << 24U));
@@ -517,19 +508,17 @@ static void system_clock_168m_irc16m(void)
/* wait until PLL is stable */
while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
}
-
+
/* Enable the high-drive to extend the clock frequency to 168 Mhz */
PMU_CTL |= PMU_CTL_HDEN;
- while(0U == (PMU_CS & PMU_CS_HDRF))
- {
+ while(0U == (PMU_CS & PMU_CS_HDRF)){
}
-
+
/* select the high-drive mode */
PMU_CTL |= PMU_CTL_HDS;
- while(0U == (PMU_CS & PMU_CS_HDSRF))
- {
- }
-
+ while(0U == (PMU_CS & PMU_CS_HDSRF)){
+ }
+
/* select PLL as system clock */
RCU_CFG0 &= ~RCU_CFG0_SCS;
RCU_CFG0 |= RCU_CKSYSSRC_PLLP;
@@ -549,7 +538,7 @@ static void system_clock_168m_irc16m(void)
static void system_clock_168m_8m_hxtal(void)
{
uint32_t timeout = 0U;
-
+
/* enable HXTAL */
RCU_CTL |= RCU_CTL_HXTALEN;
@@ -559,8 +548,8 @@ static void system_clock_168m_8m_hxtal(void)
/* if fail */
if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
- while(1){
- }
+ while(1){
+ }
}
RCU_APB1EN |= RCU_APB1EN_PMUEN;
@@ -573,7 +562,7 @@ static void system_clock_168m_8m_hxtal(void)
/* APB1 = AHB/4 */
RCU_CFG0 |= RCU_APB1_CKAHB_DIV4;
- /* Configure the main PLL, PLL_M = 8, PLL_N = 336, PLL_P = 2, PLL_Q = 7 */
+ /* Configure the main PLL, PSC = 8, PLL_N = 336, PLL_P = 2, PLL_Q = 7 */
RCU_PLL = (8U | (336 << 6U) | (((2 >> 1U) -1U) << 16U) |
(RCU_PLLSRC_HXTAL) | (7 << 24U));
@@ -583,17 +572,15 @@ static void system_clock_168m_8m_hxtal(void)
/* wait until PLL is stable */
while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
}
-
+
/* Enable the high-drive to extend the clock frequency to 168 Mhz */
PMU_CTL |= PMU_CTL_HDEN;
- while(0U == (PMU_CS & PMU_CS_HDRF))
- {
+ while(0U == (PMU_CS & PMU_CS_HDRF)){
}
-
+
/* select the high-drive mode */
PMU_CTL |= PMU_CTL_HDS;
- while(0U == (PMU_CS & PMU_CS_HDSRF))
- {
+ while(0U == (PMU_CS & PMU_CS_HDSRF)){
}
/* select PLL as system clock */
@@ -616,7 +603,7 @@ static void system_clock_168m_25m_hxtal(void)
{
uint32_t timeout = 0U;
uint32_t stab_flag = 0U;
-
+
/* enable HXTAL */
RCU_CTL |= RCU_CTL_HXTALEN;
@@ -624,15 +611,14 @@ static void system_clock_168m_25m_hxtal(void)
do{
timeout++;
stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
- }
- while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
+ }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
/* if fail */
if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
- while(1){
- }
+ while(1){
+ }
}
-
+
RCU_APB1EN |= RCU_APB1EN_PMUEN;
PMU_CTL |= PMU_CTL_LDOVS;
@@ -644,7 +630,7 @@ static void system_clock_168m_25m_hxtal(void)
/* APB1 = AHB */
RCU_CFG0 |= RCU_APB1_CKAHB_DIV4;
- /* Configure the main PLL, PLL_M = 25, PLL_N = 336, PLL_P = 2, PLL_Q = 7 */
+ /* Configure the main PLL, PSC = 25, PLL_N = 336, PLL_P = 2, PLL_Q = 7 */
RCU_PLL = (25U | (336U << 6U) | (((2U >> 1U) - 1U) << 16U) |
(RCU_PLLSRC_HXTAL) | (7U << 24U));
@@ -654,19 +640,17 @@ static void system_clock_168m_25m_hxtal(void)
/* wait until PLL is stable */
while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
}
-
+
/* Enable the high-drive to extend the clock frequency to 168 Mhz */
PMU_CTL |= PMU_CTL_HDEN;
- while(0U == (PMU_CS & PMU_CS_HDRF))
- {
+ while(0U == (PMU_CS & PMU_CS_HDRF)){
}
-
+
/* select the high-drive mode */
PMU_CTL |= PMU_CTL_HDS;
- while(0U == (PMU_CS & PMU_CS_HDSRF))
- {
- }
-
+ while(0U == (PMU_CS & PMU_CS_HDSRF)){
+ }
+
/* select PLL as system clock */
RCU_CFG0 &= ~RCU_CFG0_SCS;
RCU_CFG0 |= RCU_CKSYSSRC_PLLP;
@@ -687,7 +671,7 @@ static void system_clock_200m_irc16m(void)
{
uint32_t timeout = 0U;
uint32_t stab_flag = 0U;
-
+
/* enable IRC16M */
RCU_CTL |= RCU_CTL_IRC16MEN;
@@ -695,15 +679,14 @@ static void system_clock_200m_irc16m(void)
do{
timeout++;
stab_flag = (RCU_CTL & RCU_CTL_IRC16MSTB);
- }
- while((0U == stab_flag) && (IRC16M_STARTUP_TIMEOUT != timeout));
+ }while((0U == stab_flag) && (IRC16M_STARTUP_TIMEOUT != timeout));
/* if fail */
if(0U == (RCU_CTL & RCU_CTL_IRC16MSTB)){
- while(1){
- }
+ while(1){
+ }
}
-
+
RCU_APB1EN |= RCU_APB1EN_PMUEN;
PMU_CTL |= PMU_CTL_LDOVS;
@@ -715,7 +698,7 @@ static void system_clock_200m_irc16m(void)
/* APB1 = AHB/4 */
RCU_CFG0 |= RCU_APB1_CKAHB_DIV4;
- /* Configure the main PLL, PLL_M = 16, PLL_N = 400, PLL_P = 2, PLL_Q = 9 */
+ /* Configure the main PLL, PSC = 16, PLL_N = 400, PLL_P = 2, PLL_Q = 9 */
RCU_PLL = (16U | (400U << 6U) | (((2U >> 1U) - 1U) << 16U) |
(RCU_PLLSRC_IRC16M) | (9U << 24U));
@@ -725,19 +708,17 @@ static void system_clock_200m_irc16m(void)
/* wait until PLL is stable */
while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
}
-
+
/* Enable the high-drive to extend the clock frequency to 200 Mhz */
PMU_CTL |= PMU_CTL_HDEN;
- while(0U == (PMU_CS & PMU_CS_HDRF))
- {
+ while(0U == (PMU_CS & PMU_CS_HDRF)){
}
-
+
/* select the high-drive mode */
PMU_CTL |= PMU_CTL_HDS;
- while(0U == (PMU_CS & PMU_CS_HDSRF))
- {
- }
-
+ while(0U == (PMU_CS & PMU_CS_HDSRF)){
+ }
+
/* select PLL as system clock */
RCU_CFG0 &= ~RCU_CFG0_SCS;
RCU_CFG0 |= RCU_CKSYSSRC_PLLP;
@@ -758,7 +739,7 @@ static void system_clock_200m_8m_hxtal(void)
{
uint32_t timeout = 0U;
uint32_t stab_flag = 0U;
-
+
/* enable HXTAL */
RCU_CTL |= RCU_CTL_HXTALEN;
@@ -766,15 +747,14 @@ static void system_clock_200m_8m_hxtal(void)
do{
timeout++;
stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
- }
- while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
+ }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
/* if fail */
if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
- while(1){
- }
+ while(1){
+ }
}
-
+
RCU_APB1EN |= RCU_APB1EN_PMUEN;
PMU_CTL |= PMU_CTL_LDOVS;
@@ -786,7 +766,7 @@ static void system_clock_200m_8m_hxtal(void)
/* APB1 = AHB/4 */
RCU_CFG0 |= RCU_APB1_CKAHB_DIV4;
- /* Configure the main PLL, PLL_M = 8, PLL_N = 400, PLL_P = 2, PLL_Q = 9 */
+ /* Configure the main PLL, PSC = 8, PLL_N = 400, PLL_P = 2, PLL_Q = 9 */
RCU_PLL = (8U | (400U << 6U) | (((2U >> 1U) - 1U) << 16U) |
(RCU_PLLSRC_HXTAL) | (9U << 24U));
@@ -796,19 +776,17 @@ static void system_clock_200m_8m_hxtal(void)
/* wait until PLL is stable */
while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
}
-
+
/* Enable the high-drive to extend the clock frequency to 200 Mhz */
PMU_CTL |= PMU_CTL_HDEN;
- while(0U == (PMU_CS & PMU_CS_HDRF))
- {
+ while(0U == (PMU_CS & PMU_CS_HDRF)){
}
-
+
/* select the high-drive mode */
PMU_CTL |= PMU_CTL_HDS;
- while(0U == (PMU_CS & PMU_CS_HDSRF))
- {
- }
-
+ while(0U == (PMU_CS & PMU_CS_HDSRF)){
+ }
+
/* select PLL as system clock */
RCU_CFG0 &= ~RCU_CFG0_SCS;
RCU_CFG0 |= RCU_CKSYSSRC_PLLP;
@@ -829,7 +807,7 @@ static void system_clock_200m_25m_hxtal(void)
{
uint32_t timeout = 0U;
uint32_t stab_flag = 0U;
-
+
/* enable HXTAL */
RCU_CTL |= RCU_CTL_HXTALEN;
@@ -837,15 +815,14 @@ static void system_clock_200m_25m_hxtal(void)
do{
timeout++;
stab_flag = (RCU_CTL & RCU_CTL_HXTALSTB);
- }
- while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
+ }while((0U == stab_flag) && (HXTAL_STARTUP_TIMEOUT != timeout));
/* if fail */
if(0U == (RCU_CTL & RCU_CTL_HXTALSTB)){
- while(1){
- }
+ while(1){
+ }
}
-
+
RCU_APB1EN |= RCU_APB1EN_PMUEN;
PMU_CTL |= PMU_CTL_LDOVS;
@@ -857,7 +834,7 @@ static void system_clock_200m_25m_hxtal(void)
/* APB1 = AHB/4 */
RCU_CFG0 |= RCU_APB1_CKAHB_DIV4;
- /* Configure the main PLL, PLL_M = 25, PLL_N = 400, PLL_P = 2, PLL_Q = 9 */
+ /* Configure the main PLL, PSC = 25, PLL_N = 400, PLL_P = 2, PLL_Q = 9 */
RCU_PLL = (25U | (400U << 6U) | (((2U >> 1U) - 1U) << 16U) |
(RCU_PLLSRC_HXTAL) | (9U << 24U));
@@ -867,19 +844,17 @@ static void system_clock_200m_25m_hxtal(void)
/* wait until PLL is stable */
while(0U == (RCU_CTL & RCU_CTL_PLLSTB)){
}
-
+
/* Enable the high-drive to extend the clock frequency to 200 Mhz */
PMU_CTL |= PMU_CTL_HDEN;
- while(0U == (PMU_CS & PMU_CS_HDRF))
- {
+ while(0U == (PMU_CS & PMU_CS_HDRF)){
}
-
+
/* select the high-drive mode */
PMU_CTL |= PMU_CTL_HDS;
- while(0U == (PMU_CS & PMU_CS_HDSRF))
- {
- }
-
+ while(0U == (PMU_CS & PMU_CS_HDSRF)){
+ }
+
/* select PLL as system clock */
RCU_CFG0 &= ~RCU_CFG0_SCS;
RCU_CFG0 |= RCU_CKSYSSRC_PLLP;
@@ -900,7 +875,7 @@ void SystemCoreClockUpdate (void)
{
uint32_t sws;
uint32_t pllpsc, plln, pllsel, pllp, ck_src, idx, clk_exp;
-
+
/* exponent of AHB, APB1 and APB2 clock divider */
const uint8_t ahb_exp[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
diff --git a/bsp/gd32450z-eval/Libraries/CMSIS/core_cm4.h b/bsp/gd32450z-eval/Libraries/CMSIS/core_cm4.h
index d82841442c..e3cd89f728 100644
--- a/bsp/gd32450z-eval/Libraries/CMSIS/core_cm4.h
+++ b/bsp/gd32450z-eval/Libraries/CMSIS/core_cm4.h
@@ -100,7 +100,7 @@
#define __INLINE inline /*!< inline keyword for TASKING Compiler */
#define __STATIC_INLINE static inline
-#elif defined ( __CSMC__ ) /* Cosmic */
+#elif defined ( __CSMC__ ) /* Cosmic */
#define __packed
#define __ASM _asm /*!< asm keyword for COSMIC Compiler */
#define __INLINE inline /*use -pc99 on compile line !< inline keyword for COSMIC Compiler */
@@ -170,8 +170,8 @@
#define __FPU_USED 0
#endif
-#elif defined ( __CSMC__ ) /* Cosmic */
- #if ( __CSMC__ & 0x400) // FPU present for parser
+#elif defined ( __CSMC__ ) /* Cosmic */
+ #if ( __CSMC__ & 0x400) // FPU present for parser
#if (__FPU_PRESENT == 1)
#define __FPU_USED 1
#else
diff --git a/bsp/gd32450z-eval/Libraries/CMSIS/core_cmFunc.h b/bsp/gd32450z-eval/Libraries/CMSIS/core_cmFunc.h
index b6ad0a4c5f..834bd17645 100644
--- a/bsp/gd32450z-eval/Libraries/CMSIS/core_cmFunc.h
+++ b/bsp/gd32450z-eval/Libraries/CMSIS/core_cmFunc.h
@@ -552,7 +552,7 @@ __attribute__( ( always_inline ) ) __STATIC_INLINE void __set_BASEPRI(uint32_t v
/** \brief Set Base Priority with condition
This function assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
- or the new value increases the BASEPRI priority level.
+ or the new value increases the BASEPRI priority level.
\param [in] basePri Base Priority value to set
*/
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_adc.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_adc.h
index 694428f07c..4f6020a50a 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_adc.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_adc.h
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_adc.h
- \brief definitions for the ADC
+ \file gd32f4xx_adc.h
+ \brief definitions for the ADC
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#ifndef GD32F4XX_ADC_H
@@ -68,7 +93,7 @@
#define ADC_CTL0_IWDEN BIT(22) /*!< analog watchdog enable on inserted channels */
#define ADC_CTL0_RWDEN BIT(23) /*!< analog watchdog enable on regular channels */
#define ADC_CTL0_DRES BITS(24,25) /*!< ADC data resolution */
-#define ADC_CTL0_ROVFIE BIT(26) /*!< interrupt enable for ROVF */
+#define ADC_CTL0_ROVFIE BIT(26) /*!< interrupt enable for ROVF */
/* ADC_CTL1 */
#define ADC_CTL1_ADCON BIT(0) /*!< ADC converter on */
@@ -152,65 +177,6 @@
#define ADC_SYNCDATA_SYNCDATA1 BITS(16,31) /*!< regular data2 in ADC synchronization mode */
/* constants definitions */
-/* ADC channel group definitions */
-#define ADC_REGULAR_CHANNEL ((uint8_t)0x00U) /*!< adc regular channel group */
-#define ADC_INSERTED_CHANNEL ((uint8_t)0x01U) /*!< adc inserted channel group */
-#define ADC_REGULAR_INSERTED_CHANNEL ((uint8_t)0x02U) /*!< both regular and inserted channel group */
-
-/* external trigger mode for regular and inserted channel */
-#define EXTERNAL_TRIGGER_DISABLE ((uint32_t)0x00000000U) /*!< external trigger disable */
-#define EXTERNAL_TRIGGER_RISING ((uint32_t)0x00000001U) /*!< rising edge of external trigger */
-#define EXTERNAL_TRIGGER_FALLING ((uint32_t)0x00000002U) /*!< falling edge of external trigger */
-#define EXTERNAL_TRIGGER_RISING_FALLING ((uint32_t)0x00000003U) /*!< rising and falling edge of external trigger */
-
-/* ADC inserted channel definitions */
-#define ADC_INSERTED_CHANNEL_0 ((uint8_t)0x00U) /*!< adc inserted channel 0 */
-#define ADC_INSERTED_CHANNEL_1 ((uint8_t)0x01U) /*!< adc inserted channel 1 */
-#define ADC_INSERTED_CHANNEL_2 ((uint8_t)0x02U) /*!< adc inserted channel 2 */
-#define ADC_INSERTED_CHANNEL_3 ((uint8_t)0x03U) /*!< adc inserted channel 3 */
-
-/* ADC special function definitions */
-#define ADC_SCAN_MODE ((uint8_t)0x00U) /*!< scan mode */
-#define ADC_INSERTED_CHANNEL_AUTO ((uint8_t)0x01U) /*!< inserted channel group convert automatically */
-#define ADC_VBAT_CHANNEL_SWITCH ((uint8_t)0x02U) /*!< VBAT channel */
-#define ADC_TEMP_VREF_CHANNEL_SWITCH ((uint8_t)0x03U) /*!< Vref and Vtemp channel */
-#define ADC_CONTINUOUS_MODE ((uint8_t)0x04U) /*!< continuous mode */
-
-/* ADC channel definitions */
-#define ADC_CHANNEL_0 ((uint8_t)0x00U) /*!< ADC channel 0 */
-#define ADC_CHANNEL_1 ((uint8_t)0x01U) /*!< ADC channel 1 */
-#define ADC_CHANNEL_2 ((uint8_t)0x02U) /*!< ADC channel 2 */
-#define ADC_CHANNEL_3 ((uint8_t)0x03U) /*!< ADC channel 3 */
-#define ADC_CHANNEL_4 ((uint8_t)0x04U) /*!< ADC channel 4 */
-#define ADC_CHANNEL_5 ((uint8_t)0x05U) /*!< ADC channel 5 */
-#define ADC_CHANNEL_6 ((uint8_t)0x06U) /*!< ADC channel 6 */
-#define ADC_CHANNEL_7 ((uint8_t)0x07U) /*!< ADC channel 7 */
-#define ADC_CHANNEL_8 ((uint8_t)0x08U) /*!< ADC channel 8 */
-#define ADC_CHANNEL_9 ((uint8_t)0x09U) /*!< ADC channel 9 */
-#define ADC_CHANNEL_10 ((uint8_t)0x0AU) /*!< ADC channel 10 */
-#define ADC_CHANNEL_11 ((uint8_t)0x0BU) /*!< ADC channel 11 */
-#define ADC_CHANNEL_12 ((uint8_t)0x0CU) /*!< ADC channel 12 */
-#define ADC_CHANNEL_13 ((uint8_t)0x0DU) /*!< ADC channel 13 */
-#define ADC_CHANNEL_14 ((uint8_t)0x0EU) /*!< ADC channel 14 */
-#define ADC_CHANNEL_15 ((uint8_t)0x0FU) /*!< ADC channel 15 */
-#define ADC_CHANNEL_16 ((uint8_t)0x10U) /*!< ADC channel 16 */
-#define ADC_CHANNEL_17 ((uint8_t)0x11U) /*!< ADC channel 17 */
-#define ADC_CHANNEL_18 ((uint8_t)0x12U) /*!< ADC channel 18 */
-
-/* ADC channel sample time */
-#define ADC_SAMPLETIME_3 ((uint8_t)0x00U) /*!< 3 sampling cycles */
-#define ADC_SAMPLETIME_15 ((uint8_t)0x01U) /*!< 15 sampling cycles */
-#define ADC_SAMPLETIME_28 ((uint8_t)0x02U) /*!< 28 sampling cycles */
-#define ADC_SAMPLETIME_56 ((uint8_t)0x03U) /*!< 56 sampling cycles */
-#define ADC_SAMPLETIME_84 ((uint8_t)0x04U) /*!< 84 sampling cycles */
-#define ADC_SAMPLETIME_112 ((uint8_t)0x05U) /*!< 112 sampling cycles */
-#define ADC_SAMPLETIME_144 ((uint8_t)0x06U) /*!< 144 sampling cycles */
-#define ADC_SAMPLETIME_480 ((uint8_t)0x07U) /*!< 480 sampling cycles */
-
-/* ADC data alignment */
-#define ADC_DATAALIGN_RIGHT ((uint8_t)0x00U) /*!< LSB alignment */
-#define ADC_DATAALIGN_LEFT ((uint8_t)0x01U) /*!< MSB alignment */
-
/* ADC status flag */
#define ADC_FLAG_WDE ADC_STAT_WDE /*!< analog watchdog event flag */
#define ADC_FLAG_EOC ADC_STAT_EOC /*!< end of conversion */
@@ -219,18 +185,43 @@
#define ADC_FLAG_STRC ADC_STAT_STRC /*!< regular channel start flag */
#define ADC_FLAG_ROVF ADC_STAT_ROVF /*!< regular data register overflow */
-/* ADC interrupt flag */
-#define ADC_INT_WDE ADC_STAT_WDE /*!< analog watchdog event interrupt */
-#define ADC_INT_EOC ADC_STAT_EOC /*!< end of group conversion interrupt */
-#define ADC_INT_EOIC ADC_STAT_EOIC /*!< end of inserted group conversion interrupt */
-#define ADC_INT_ROVF ADC_STAT_ROVF /*!< regular data register overflow */
+/* adc_ctl0 register value */
+#define CTL0_DISNUM(regval) (BITS(13,15) & ((uint32_t)(regval) << 13)) /*!< write value to ADC_CTL0_DISNUM bit field */
+
+/* ADC special function definitions */
+#define ADC_SCAN_MODE ADC_CTL0_SM /*!< scan mode */
+#define ADC_INSERTED_CHANNEL_AUTO ADC_CTL0_ICA /*!< inserted channel group convert automatically */
+#define ADC_CONTINUOUS_MODE ADC_CTL1_CTN /*!< continuous mode */
-/* ADC resolution definitions */
-#define CTL0_DRES(regval) (BITS(24,25) & ((uint32_t)(regval) << 24))
-#define ADC_RESOLUTION_12B CTL0_DRES(0) /*!< 12-bit ADC resolution */
-#define ADC_RESOLUTION_10B CTL0_DRES(1) /*!< 10-bit ADC resolution */
-#define ADC_RESOLUTION_8B CTL0_DRES(2) /*!< 8-bit ADC resolution */
-#define ADC_RESOLUTION_6B CTL0_DRES(3) /*!< 6-bit ADC resolution */
+/* temperature sensor channel, internal reference voltage channel, VBAT channel */
+#define ADC_VBAT_CHANNEL_SWITCH ADC_SYNCCTL_VBATEN /*!< VBAT channel */
+#define ADC_TEMP_VREF_CHANNEL_SWITCH ADC_SYNCCTL_TSVREN /*!< Vref and Vtemp channel */
+
+/* ADC synchronization mode */
+#define SYNCCTL_SYNCM(regval) (BITS(0,4) & ((uint32_t)(regval))) /*!< write value to ADC_CTL0_SYNCM bit field */
+#define ADC_SYNC_MODE_INDEPENDENT SYNCCTL_SYNCM(0) /*!< ADC synchronization mode disabled.All the ADCs work independently */
+#define ADC_DAUL_REGULAL_PARALLEL_INSERTED_PARALLEL SYNCCTL_SYNCM(1) /*!< ADC0 and ADC1 work in combined regular parallel & inserted parallel mode. ADC2 works independently */
+#define ADC_DAUL_REGULAL_PARALLEL_INSERTED_ROTATION SYNCCTL_SYNCM(2) /*!< ADC0 and ADC1 work in combined regular parallel & trigger rotation mode. ADC2 works independently */
+#define ADC_DAUL_INSERTED_PARALLEL SYNCCTL_SYNCM(5) /*!< ADC0 and ADC1 work in inserted parallel mode. ADC2 works independently */
+#define ADC_DAUL_REGULAL_PARALLEL SYNCCTL_SYNCM(6) /*!< ADC0 and ADC1 work in regular parallel mode. ADC2 works independently */
+#define ADC_DAUL_REGULAL_FOLLOW_UP SYNCCTL_SYNCM(7) /*!< ADC0 and ADC1 work in follow-up mode. ADC2 works independently */
+#define ADC_DAUL_INSERTED_TRRIGGER_ROTATION SYNCCTL_SYNCM(9) /*!< ADC0 and ADC1 work in trigger rotation mode. ADC2 works independently */
+#define ADC_ALL_REGULAL_PARALLEL_INSERTED_PARALLEL SYNCCTL_SYNCM(17) /*!< all ADCs work in combined regular parallel & inserted parallel mode */
+#define ADC_ALL_REGULAL_PARALLEL_INSERTED_ROTATION SYNCCTL_SYNCM(18) /*!< all ADCs work in combined regular parallel & trigger rotation mode */
+#define ADC_ALL_INSERTED_PARALLEL SYNCCTL_SYNCM(21) /*!< all ADCs work in inserted parallel mode */
+#define ADC_ALL_REGULAL_PARALLEL SYNCCTL_SYNCM(22) /*!< all ADCs work in regular parallel mode */
+#define ADC_ALL_REGULAL_FOLLOW_UP SYNCCTL_SYNCM(23) /*!< all ADCs work in follow-up mode */
+#define ADC_ALL_INSERTED_TRRIGGER_ROTATION SYNCCTL_SYNCM(25) /*!< all ADCs work in trigger rotation mode */
+
+/* ADC data alignment */
+#define ADC_DATAALIGN_RIGHT ((uint32_t)0x00000000U) /*!< LSB alignment */
+#define ADC_DATAALIGN_LEFT ADC_CTL1_DAL /*!< MSB alignment */
+
+/* external trigger mode for regular and inserted channel */
+#define EXTERNAL_TRIGGER_DISABLE ((uint32_t)0x00000000U) /*!< external trigger disable */
+#define EXTERNAL_TRIGGER_RISING ((uint32_t)0x00000001U) /*!< rising edge of external trigger */
+#define EXTERNAL_TRIGGER_FALLING ((uint32_t)0x00000002U) /*!< falling edge of external trigger */
+#define EXTERNAL_TRIGGER_RISING_FALLING ((uint32_t)0x00000003U) /*!< rising and falling edge of external trigger */
/* ADC external trigger select for regular channel */
#define CTL1_ETSRC(regval) (BITS(24,27) & ((uint32_t)(regval) << 24))
@@ -270,32 +261,111 @@
#define ADC_EXTTRIG_INSERTED_T7_CH3 CTL1_ETSIC(14) /*!< timer7 capture compare 3 */
#define ADC_EXTTRIG_INSERTED_EXTI_15 CTL1_ETSIC(15) /*!< external interrupt line 15 */
-/* ADC oversampling mode */
-#define ADC_OVERSAMPLING_ALL_CONVERT 0U /*!< all oversampled conversions for a channel are done consecutively after a trigger */
-#define ADC_OVERSAMPLING_ONE_CONVERT 1U /*!< each oversampled conversion for a channel needs a trigger */
+/* ADC channel sample time */
+#define SAMPTX_SPT(regval) (BITS(0,2) & ((uint32_t)(regval) << 0)) /*!< write value to ADC_SAMPTX_SPT bit field */
+#define ADC_SAMPLETIME_3 SAMPTX_SPT(0) /*!< 3 sampling cycles */
+#define ADC_SAMPLETIME_15 SAMPTX_SPT(1) /*!< 15 sampling cycles */
+#define ADC_SAMPLETIME_28 SAMPTX_SPT(2) /*!< 28 sampling cycles */
+#define ADC_SAMPLETIME_56 SAMPTX_SPT(3) /*!< 56 sampling cycles */
+#define ADC_SAMPLETIME_84 SAMPTX_SPT(4) /*!< 84 sampling cycles */
+#define ADC_SAMPLETIME_112 SAMPTX_SPT(5) /*!< 112 sampling cycles */
+#define ADC_SAMPLETIME_144 SAMPTX_SPT(6) /*!< 144 sampling cycles */
+#define ADC_SAMPLETIME_480 SAMPTX_SPT(7) /*!< 480 sampling cycles */
+
+/* adc_ioffx register value */
+#define IOFFX_IOFF(regval) (BITS(0,11) & ((uint32_t)(regval) << 0)) /*!< write value to ADC_IOFFX_IOFF bit field */
+
+/* adc_wdht register value */
+#define WDHT_WDHT(regval) (BITS(0,11) & ((uint32_t)(regval) << 0)) /*!< write value to ADC_WDHT_WDHT bit field */
+
+/* adc_wdlt register value */
+#define WDLT_WDLT(regval) (BITS(0,11) & ((uint32_t)(regval) << 0)) /*!< write value to ADC_WDLT_WDLT bit field */
+
+/* adc_rsqx register value */
+#define RSQ0_RL(regval) (BITS(20,23) & ((uint32_t)(regval) << 20)) /*!< write value to ADC_RSQ0_RL bit field */
+
+/* adc_isq register value */
+#define ISQ_IL(regval) (BITS(20,21) & ((uint32_t)(regval) << 20)) /*!< write value to ADC_ISQ_IL bit field */
+
+/* adc_ovsampctl register value */
+/* ADC resolution */
+#define CTL0_DRES(regval) (BITS(24,25) & ((uint32_t)(regval) << 24)) /*!< write value to ADC_CTL0_DRES bit field */
+#define ADC_RESOLUTION_12B CTL0_DRES(0) /*!< 12-bit ADC resolution */
+#define ADC_RESOLUTION_10B CTL0_DRES(1) /*!< 10-bit ADC resolution */
+#define ADC_RESOLUTION_8B CTL0_DRES(2) /*!< 8-bit ADC resolution */
+#define ADC_RESOLUTION_6B CTL0_DRES(3) /*!< 6-bit ADC resolution */
+
+/* oversampling shift */
+#define OVSAMPCTL_OVSS(regval) (BITS(5,8) & ((uint32_t)(regval) << 5)) /*!< write value to ADC_OVSAMPCTL_OVSS bit field */
+#define ADC_OVERSAMPLING_SHIFT_NONE OVSAMPCTL_OVSS(0) /*!< no oversampling shift */
+#define ADC_OVERSAMPLING_SHIFT_1B OVSAMPCTL_OVSS(1) /*!< 1-bit oversampling shift */
+#define ADC_OVERSAMPLING_SHIFT_2B OVSAMPCTL_OVSS(2) /*!< 2-bit oversampling shift */
+#define ADC_OVERSAMPLING_SHIFT_3B OVSAMPCTL_OVSS(3) /*!< 3-bit oversampling shift */
+#define ADC_OVERSAMPLING_SHIFT_4B OVSAMPCTL_OVSS(4) /*!< 4-bit oversampling shift */
+#define ADC_OVERSAMPLING_SHIFT_5B OVSAMPCTL_OVSS(5) /*!< 5-bit oversampling shift */
+#define ADC_OVERSAMPLING_SHIFT_6B OVSAMPCTL_OVSS(6) /*!< 6-bit oversampling shift */
+#define ADC_OVERSAMPLING_SHIFT_7B OVSAMPCTL_OVSS(7) /*!< 7-bit oversampling shift */
+#define ADC_OVERSAMPLING_SHIFT_8B OVSAMPCTL_OVSS(8) /*!< 8-bit oversampling shift */
+
+/* oversampling ratio */
+#define OVSAMPCTL_OVSR(regval) (BITS(2,4) & ((uint32_t)(regval) << 2)) /*!< write value to ADC_OVSAMPCTL_OVSR bit field */
+#define ADC_OVERSAMPLING_RATIO_MUL2 OVSAMPCTL_OVSR(0) /*!< oversampling ratio multiple 2 */
+#define ADC_OVERSAMPLING_RATIO_MUL4 OVSAMPCTL_OVSR(1) /*!< oversampling ratio multiple 4 */
+#define ADC_OVERSAMPLING_RATIO_MUL8 OVSAMPCTL_OVSR(2) /*!< oversampling ratio multiple 8 */
+#define ADC_OVERSAMPLING_RATIO_MUL16 OVSAMPCTL_OVSR(3) /*!< oversampling ratio multiple 16 */
+#define ADC_OVERSAMPLING_RATIO_MUL32 OVSAMPCTL_OVSR(4) /*!< oversampling ratio multiple 32 */
+#define ADC_OVERSAMPLING_RATIO_MUL64 OVSAMPCTL_OVSR(5) /*!< oversampling ratio multiple 64 */
+#define ADC_OVERSAMPLING_RATIO_MUL128 OVSAMPCTL_OVSR(6) /*!< oversampling ratio multiple 128 */
+#define ADC_OVERSAMPLING_RATIO_MUL256 OVSAMPCTL_OVSR(7) /*!< oversampling ratio multiple 256 */
+
+/* triggered Oversampling */
+#define ADC_OVERSAMPLING_ALL_CONVERT ((uint32_t)0x00000000U) /*!< all oversampled conversions for a channel are done consecutively after a trigger */
+#define ADC_OVERSAMPLING_ONE_CONVERT ADC_OVSAMPCTL_TOVS /*!< each oversampled conversion for a channel needs a trigger */
+
+/* ADC channel group definitions */
+#define ADC_REGULAR_CHANNEL ((uint8_t)0x01U) /*!< adc regular channel group */
+#define ADC_INSERTED_CHANNEL ((uint8_t)0x02U) /*!< adc inserted channel group */
+#define ADC_REGULAR_INSERTED_CHANNEL ((uint8_t)0x03U) /*!< both regular and inserted channel group */
+#define ADC_CHANNEL_DISCON_DISABLE ((uint8_t)0x04U) /*!< disable discontinuous mode of regular & inserted channel */
+
+/* ADC inserted channel definitions */
+#define ADC_INSERTED_CHANNEL_0 ((uint8_t)0x00U) /*!< adc inserted channel 0 */
+#define ADC_INSERTED_CHANNEL_1 ((uint8_t)0x01U) /*!< adc inserted channel 1 */
+#define ADC_INSERTED_CHANNEL_2 ((uint8_t)0x02U) /*!< adc inserted channel 2 */
+#define ADC_INSERTED_CHANNEL_3 ((uint8_t)0x03U) /*!< adc inserted channel 3 */
+
+/* ADC channel definitions */
+#define ADC_CHANNEL_0 ((uint8_t)0x00U) /*!< ADC channel 0 */
+#define ADC_CHANNEL_1 ((uint8_t)0x01U) /*!< ADC channel 1 */
+#define ADC_CHANNEL_2 ((uint8_t)0x02U) /*!< ADC channel 2 */
+#define ADC_CHANNEL_3 ((uint8_t)0x03U) /*!< ADC channel 3 */
+#define ADC_CHANNEL_4 ((uint8_t)0x04U) /*!< ADC channel 4 */
+#define ADC_CHANNEL_5 ((uint8_t)0x05U) /*!< ADC channel 5 */
+#define ADC_CHANNEL_6 ((uint8_t)0x06U) /*!< ADC channel 6 */
+#define ADC_CHANNEL_7 ((uint8_t)0x07U) /*!< ADC channel 7 */
+#define ADC_CHANNEL_8 ((uint8_t)0x08U) /*!< ADC channel 8 */
+#define ADC_CHANNEL_9 ((uint8_t)0x09U) /*!< ADC channel 9 */
+#define ADC_CHANNEL_10 ((uint8_t)0x0AU) /*!< ADC channel 10 */
+#define ADC_CHANNEL_11 ((uint8_t)0x0BU) /*!< ADC channel 11 */
+#define ADC_CHANNEL_12 ((uint8_t)0x0CU) /*!< ADC channel 12 */
+#define ADC_CHANNEL_13 ((uint8_t)0x0DU) /*!< ADC channel 13 */
+#define ADC_CHANNEL_14 ((uint8_t)0x0EU) /*!< ADC channel 14 */
+#define ADC_CHANNEL_15 ((uint8_t)0x0FU) /*!< ADC channel 15 */
+#define ADC_CHANNEL_16 ((uint8_t)0x10U) /*!< ADC channel 16 */
+#define ADC_CHANNEL_17 ((uint8_t)0x11U) /*!< ADC channel 17 */
+#define ADC_CHANNEL_18 ((uint8_t)0x12U) /*!< ADC channel 18 */
-/* ADC oversampling shift */
-#define OVCTL_OVSS(regval) (BITS(5,8) & ((uint32_t)(regval) << 5))
-#define ADC_OVERSAMPLING_SHIFT_NONE OVCTL_OVSS(0) /*!< no oversampling shift */
-#define ADC_OVERSAMPLING_SHIFT_1B OVCTL_OVSS(1) /*!< 1-bit oversampling shift */
-#define ADC_OVERSAMPLING_SHIFT_2B OVCTL_OVSS(2) /*!< 2-bit oversampling shift */
-#define ADC_OVERSAMPLING_SHIFT_3B OVCTL_OVSS(3) /*!< 3-bit oversampling shift */
-#define ADC_OVERSAMPLING_SHIFT_4B OVCTL_OVSS(4) /*!< 4-bit oversampling shift */
-#define ADC_OVERSAMPLING_SHIFT_5B OVCTL_OVSS(5) /*!< 5-bit oversampling shift */
-#define ADC_OVERSAMPLING_SHIFT_6B OVCTL_OVSS(6) /*!< 6-bit oversampling shift */
-#define ADC_OVERSAMPLING_SHIFT_7B OVCTL_OVSS(7) /*!< 7-bit oversampling shift */
-#define ADC_OVERSAMPLING_SHIFT_8B OVCTL_OVSS(8) /*!< 8-bit oversampling shift */
+/* ADC interrupt flag */
+#define ADC_INT_WDE ADC_CTL0_WDEIE /*!< analog watchdog event interrupt */
+#define ADC_INT_EOC ADC_CTL0_EOCIE /*!< end of group conversion interrupt */
+#define ADC_INT_EOIC ADC_CTL0_EOICIE /*!< end of inserted group conversion interrupt */
+#define ADC_INT_ROVF ADC_CTL0_ROVFIE /*!< regular data register overflow */
-/* ADC oversampling ratio */
-#define OVCTL_OVSR(regval) (BITS(2,4) & ((uint32_t)(regval) << 2))
-#define ADC_OVERSAMPLING_RATIO_MUL2 OVCTL_OVSR(0) /*!< oversampling ratio multiple 2 */
-#define ADC_OVERSAMPLING_RATIO_MUL4 OVCTL_OVSR(1) /*!< oversampling ratio multiple 4 */
-#define ADC_OVERSAMPLING_RATIO_MUL8 OVCTL_OVSR(2) /*!< oversampling ratio multiple 8 */
-#define ADC_OVERSAMPLING_RATIO_MUL16 OVCTL_OVSR(3) /*!< oversampling ratio multiple 16 */
-#define ADC_OVERSAMPLING_RATIO_MUL32 OVCTL_OVSR(4) /*!< oversampling ratio multiple 32 */
-#define ADC_OVERSAMPLING_RATIO_MUL64 OVCTL_OVSR(5) /*!< oversampling ratio multiple 64 */
-#define ADC_OVERSAMPLING_RATIO_MUL128 OVCTL_OVSR(6) /*!< oversampling ratio multiple 128 */
-#define ADC_OVERSAMPLING_RATIO_MUL256 OVCTL_OVSR(7) /*!< oversampling ratio multiple 256 */
+/* ADC interrupt flag */
+#define ADC_INT_FLAG_WDE ADC_STAT_WDE /*!< analog watchdog event interrupt */
+#define ADC_INT_FLAG_EOC ADC_STAT_EOC /*!< end of group conversion interrupt */
+#define ADC_INT_FLAG_EOIC ADC_STAT_EOIC /*!< end of inserted group conversion interrupt */
+#define ADC_INT_FLAG_ROVF ADC_STAT_ROVF /*!< regular data register overflow */
/* configure the ADC clock for all the ADCs */
#define SYNCCTL_ADCCK(regval) (BITS(16,18) & ((uint32_t)(regval) << 16))
@@ -308,21 +378,6 @@
#define ADC_ADCCK_HCLK_DIV10 SYNCCTL_ADCCK(6) /*!< HCLK div10 */
#define ADC_ADCCK_HCLK_DIV20 SYNCCTL_ADCCK(7) /*!< HCLK div20 */
-/* ADC synchronization mode */
-#define ADC_SYNC_MODE_INDEPENDENT ((uint32_t)0x00000000U) /*!< ADC synchronization mode disabled.All the ADCs work independently */
-#define ADC_DAUL_REGULAL_PARALLEL_INSERTED_PARALLEL ((uint32_t)0x00000001U) /*!< ADC0 and ADC1 work in combined regular parallel & inserted parallel mode. ADC2 works independently */
-#define ADC_DAUL_REGULAL_PARALLEL_INSERTED_ROTATION ((uint32_t)0x00000002U) /*!< ADC0 and ADC1 work in combined regular parallel & trigger rotation mode. ADC2 works independently */
-#define ADC_DAUL_INSERTED_PARALLEL ((uint32_t)0x00000005U) /*!< ADC0 and ADC1 work in inserted parallel mode. ADC2 works independently */
-#define ADC_DAUL_REGULAL_PARALLEL ((uint32_t)0x00000006U) /*!< ADC0 and ADC1 work in regular parallel mode. ADC2 works independently */
-#define ADC_DAUL_REGULAL_FOLLOW_UP ((uint32_t)0x00000007U) /*!< ADC0 and ADC1 work in follow-up mode. ADC2 works independently */
-#define ADC_DAUL_INSERTED_TRRIGGER_ROTATION ((uint32_t)0x00000009U) /*!< ADC0 and ADC1 work in trigger rotation mode. ADC2 works independently */
-#define ADC_ALL_REGULAL_PARALLEL_INSERTED_PARALLEL ((uint32_t)0x00000011U) /*!< all ADCs work in combined regular parallel & inserted parallel mode */
-#define ADC_ALL_REGULAL_PARALLEL_INSERTED_ROTATION ((uint32_t)0x00000012U) /*!< all ADCs work in combined regular parallel & trigger rotation mode */
-#define ADC_ALL_INSERTED_PARALLEL ((uint32_t)0x00000015U) /*!< all ADCs work in inserted parallel mode */
-#define ADC_ALL_REGULAL_PARALLEL ((uint32_t)0x00000016U) /*!< all ADCs work in regular parallel mode */
-#define ADC_ALL_REGULAL_FOLLOW_UP ((uint32_t)0x00000017U) /*!< all ADCs work in follow-up mode */
-#define ADC_ALL_INSERTED_TRRIGGER_ROTATION ((uint32_t)0x00000019U) /*!< all ADCs work in trigger rotation mode */
-
/* ADC synchronization delay */
#define ADC_SYNC_DELAY_5CYCLE ((uint32_t)0x00000000U) /*!< the delay between 2 sampling phases in ADC synchronization modes to 5 ADC clock cycles. */
#define ADC_SYNC_DELAY_6CYCLE ((uint32_t)0x00000100U) /*!< the delay between 2 sampling phases in ADC synchronization modes to 6 ADC clock cycles. */
@@ -351,99 +406,98 @@
#define ADC_EOC_SET_CONVERSION ((uint8_t)0x01U) /*!< at the end of each regular conversion, the EOC bit is set */
/* function declarations */
-/* ADC reset */
+/* initialization config */
+/* reset ADC */
void adc_deinit(void);
+/* configure the ADC clock for all the ADCs */
+void adc_clock_config(uint32_t prescaler);
+/* enable or disable ADC special function */
+void adc_special_function_config(uint32_t adc_periph , uint32_t function , ControlStatus newvalue);
+/* configure ADC data alignment */
+void adc_data_alignment_config(uint32_t adc_periph , uint32_t data_alignment);
/* enable ADC interface */
void adc_enable(uint32_t adc_periph);
/* disable ADC interface */
void adc_disable(uint32_t adc_periph);
-/* ADC data alignment config */
-void adc_data_alignment_config(uint32_t adc_periph , uint8_t data_alignment);
-/* ADC resolution config */
-void adc_resolution_config(uint32_t adc_periph , uint32_t resolution);
/* ADC calibration and reset calibration */
void adc_calibration_enable(uint32_t adc_periph);
-/* ADC discontinuous mode config */
-void adc_discontinuous_mode_config(uint32_t adc_periph , uint8_t adc_channel_group , uint8_t length);
-/* config end of conversion mode */
-void adc_end_of_conversion_config(uint32_t adc_periph , uint8_t end_selection);
-/* ADC special function enable or disable */
-void adc_special_function_config(uint32_t adc_periph , uint8_t function , ControlStatus newvalue);
-/* configure the ADC clock for all the ADCs */
-void adc_clock_config(uint32_t prescaler);
+/* configure temperature sensor and internal reference voltage channel or VBAT channel function */
+void adc_channel_16_to_18(uint32_t function, ControlStatus newvalue);
+/* configure ADC resolution */
+void adc_resolution_config(uint32_t adc_periph, uint32_t resolution);
+/* configure ADC oversample mode */
+void adc_oversample_mode_config(uint32_t adc_periph, uint32_t mode, uint16_t shift, uint8_t ratio);
+/* enable ADC oversample mode */
+void adc_oversample_mode_enable(uint32_t adc_periph);
+/* disable ADC oversample mode */
+void adc_oversample_mode_disable(uint32_t adc_periph);
-/* ADC channel */
-/* configure the ADC clock for all the ADCs */
-void adc_channel_16_to_18(uint8_t function,ControlStatus newvalue);
-/* config the length of regular channel group or inserted channel group */
-void adc_channel_length_config(uint32_t adc_periph , uint8_t adc_channel_group , uint32_t length);
+/* DMA config */
+/* enable DMA request */
+void adc_dma_mode_enable(uint32_t adc_periph);
+/* disable DMA request */
+void adc_dma_mode_disable(uint32_t adc_periph);
+/* when DMA=1, the DMA engine issues a request at end of each regular conversion */
+void adc_dma_request_after_last_enable(uint32_t adc_periph);
+/* the DMA engine is disabled after the end of transfer signal from DMA controller is detected */
+void adc_dma_request_after_last_disable(uint32_t adc_periph);
-/* ADC trigger */
-/* ADC external trigger enable */
-void adc_external_trigger_config(uint32_t adc_periph , uint8_t adc_channel_group , uint32_t trigger_mode);
-/* ADC external trigger source config */
+/* regular group and inserted group config */
+/* configure ADC discontinuous mode */
+void adc_discontinuous_mode_config(uint32_t adc_periph , uint8_t adc_channel_group , uint8_t length);
+/* configure the length of regular channel group or inserted channel group */
+void adc_channel_length_config(uint32_t adc_periph , uint8_t adc_channel_group , uint32_t length);
+/* configure ADC regular channel */
+void adc_regular_channel_config(uint32_t adc_periph , uint8_t rank , uint8_t adc_channel , uint32_t sample_time);
+/* configure ADC inserted channel */
+void adc_inserted_channel_config(uint32_t adc_periph , uint8_t rank , uint8_t adc_channel , uint32_t sample_time);
+/* configure ADC inserted channel offset */
+void adc_inserted_channel_offset_config(uint32_t adc_periph , uint8_t inserted_channel , uint16_t offset);
+/* configure ADC external trigger source */
void adc_external_trigger_source_config(uint32_t adc_periph , uint8_t adc_channel_group , uint32_t external_trigger_source);
-/* ADC software trigger enable */
+/* enable ADC external trigger */
+void adc_external_trigger_config(uint32_t adc_periph , uint8_t adc_channel_group , uint32_t trigger_mode);
+/* enable ADC software trigger */
void adc_software_trigger_enable(uint32_t adc_periph , uint8_t adc_channel_group);
+/* configure end of conversion mode */
+void adc_end_of_conversion_config(uint32_t adc_periph , uint8_t end_selection);
-/* ADC flag and interrupt */
+/* get channel data */
+/* read ADC regular group data register */
+uint16_t adc_regular_data_read(uint32_t adc_periph);
+/* read ADC inserted group data register */
+uint16_t adc_inserted_data_read(uint32_t adc_periph , uint8_t inserted_channel);
+
+/* watchdog config */
+/* disable ADC analog watchdog single channel */
+void adc_watchdog_single_channel_disable(uint32_t adc_periph );
+/* enable ADC analog watchdog single channel */
+void adc_watchdog_single_channel_enable(uint32_t adc_periph , uint8_t adc_channel);
+/* configure ADC analog watchdog group channel */
+void adc_watchdog_group_channel_enable(uint32_t adc_periph , uint8_t adc_channel_group);
+/* disable ADC analog watchdog */
+void adc_watchdog_disable(uint32_t adc_periph , uint8_t adc_channel_group);
+/* configure ADC analog watchdog threshold */
+void adc_watchdog_threshold_config(uint32_t adc_periph , uint16_t low_threshold , uint16_t high_threshold);
+
+/* interrupt & flag functions */
/* get the ADC flag bits */
FlagStatus adc_flag_get(uint32_t adc_periph , uint32_t adc_flag);
/* clear the ADC flag bits */
void adc_flag_clear(uint32_t adc_periph , uint32_t adc_flag);
+/* get the bit state of ADCx software start conversion */
+FlagStatus adc_regular_software_startconv_flag_get(uint32_t adc_periph);
+/* get the bit state of ADCx software inserted channel start conversion */
+FlagStatus adc_inserted_software_startconv_flag_get(uint32_t adc_periph);
/* get the ADC interrupt bits */
FlagStatus adc_interrupt_flag_get(uint32_t adc_periph , uint32_t adc_interrupt);
/* clear the ADC flag */
void adc_interrupt_flag_clear(uint32_t adc_periph , uint32_t adc_interrupt);
-/* ADC interrupt enable */
+/* enable ADC interrupt */
void adc_interrupt_enable(uint32_t adc_periph , uint32_t adc_interrupt);
-/* ADC interrupt disable */
+/* disable ADC interrupt */
void adc_interrupt_disable(uint32_t adc_periph , uint32_t adc_interrupt);
-/* ADC analog watchdog */
-/* ADC analog watchdog single channel disable */
-void adc_watchdog_single_channel_disable(uint32_t adc_periph );
-/* ADC analog watchdog single channel enable */
-void adc_watchdog_single_channel_enable(uint32_t adc_periph , uint8_t adc_channel);
-/* adc analog watchdog group channel config */
-void adc_watchdog_enable(uint32_t adc_periph , uint8_t adc_channel_group);
-/* ADC analog watchdog disable */
-void adc_watchdog_disable(uint32_t adc_periph , uint8_t adc_channel_group);
-/* ADC analog watchdog threshold config */
-void adc_watchdog_threshold_config(uint32_t adc_periph , uint16_t low_threshold , uint16_t high_threshold);
-
-/* regular channel */
-/* ADC regular channel config */
-void adc_regular_channel_config(uint32_t adc_periph , uint8_t rank , uint8_t adc_channel , uint32_t sample_time);
-/* ADC regular group data register read */
-uint16_t adc_regular_data_read(uint32_t adc_periph);
-
-/* inserted channel */
-/* ADC inserted channel config */
-void adc_inserted_channel_config(uint32_t adc_periph , uint8_t rank , uint8_t adc_channel , uint8_t sample_time);
-/* ADC inserted channel offset config */
-void adc_inserted_channel_offset_config(uint32_t adc_periph , uint8_t inserted_channel , uint16_t offset);
-/* ADC inserted group data register read */
-uint16_t adc_inserted_data_read(uint32_t adc_periph , uint8_t inserted_channel);
-
-/* ADC DMA */
-/* DMA request enable */
-void adc_dma_mode_enable(uint32_t adc_periph);
-/* DMA request disable */
-void adc_dma_mode_disable(uint32_t adc_periph);
-/* when DMA=1, the DMA engine issues a request at end of each regular conversion */
-void adc_dma_request_after_last_enable(uint32_t adc_periph);
-/* the DMA engine is disabled after the end of transfer signal from DMA controller is detected */
-void adc_dma_request_after_last_disable(uint32_t adc_periph);
-
-/* ADC oversample */
-/* ADC oversample mode config */
-void adc_oversample_mode_config(uint32_t adc_periph , uint8_t mode , uint16_t shift , uint8_t ratio);
-/* ADC oversample mode enable */
-void adc_oversample_mode_enable(uint32_t adc_periph );
-/* ADC oversample mode disable */
-void adc_oversample_mode_disable(uint32_t adc_periph );
-
/* ADC synchronization */
/* configure the ADC sync mode */
void adc_sync_mode_config(uint32_t sync_mode);
@@ -455,7 +509,7 @@ void adc_sync_dma_config(uint32_t dma_mode );
void adc_sync_dma_request_after_last_enable(void);
/* configure ADC sync DMA engine issues requests according to the SYNCDMA bits */
void adc_sync_dma_request_after_last_disable(void);
-/* ADC sync regular data register read */
+/* read ADC sync regular data register */
uint32_t adc_sync_regular_data_read(void);
#endif /* GD32F4XX_ADC_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_can.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_can.h
index 2be5832462..7310f63a75 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_can.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_can.h
@@ -1,12 +1,38 @@
/*!
- \file gd32f4xx_can.h
- \brief definitions for the CAN
+ \file gd32f4xx_can.h
+ \brief definitions for the CAN
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2019-11-27, V2.0.1, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#ifndef GD32F4XX_CAN_H
@@ -42,7 +68,7 @@
#define CAN_RFIFOMI0(canx) REG32((canx) + 0x1B0U) /*!< CAN receive FIFO0 mailbox identifier register */
#define CAN_RFIFOMP0(canx) REG32((canx) + 0x1B4U) /*!< CAN receive FIFO0 mailbox property register */
#define CAN_RFIFOMDATA00(canx) REG32((canx) + 0x1B8U) /*!< CAN receive FIFO0 mailbox data0 register */
-#define CAN_RFIFOMDATA10(canx) REG32((canx) + 0x1CCU) /*!< CAN receive FIFO0 mailbox data1 register */
+#define CAN_RFIFOMDATA10(canx) REG32((canx) + 0x1BCU) /*!< CAN receive FIFO0 mailbox data1 register */
#define CAN_RFIFOMI1(canx) REG32((canx) + 0x1C0U) /*!< CAN receive FIFO1 mailbox identifier register */
#define CAN_RFIFOMP1(canx) REG32((canx) + 0x1C4U) /*!< CAN receive FIFO1 mailbox property register */
#define CAN_RFIFOMDATA01(canx) REG32((canx) + 0x1C8U) /*!< CAN receive FIFO1 mailbox data0 register */
@@ -110,20 +136,20 @@
#define CAN_F27DATA1(canx) REG32((canx) + 0x31CU) /*!< CAN filter 27 data 1 register */
/* CAN transmit mailbox bank */
-#define CAN_TMI(canx, bank) REG32((canx) + 0x180U + ((bank) * 0x10U)) /*!< CAN transmit mailbox identifier register */
-#define CAN_TMP(canx, bank) REG32((canx) + 0x184U + ((bank) * 0x10U)) /*!< CAN transmit mailbox property register */
-#define CAN_TMDATA0(canx, bank) REG32((canx) + 0x188U + ((bank) * 0x10U)) /*!< CAN transmit mailbox data0 register */
-#define CAN_TMDATA1(canx, bank) REG32((canx) + 0x18CU + ((bank) * 0x10U)) /*!< CAN transmit mailbox data1 register */
+#define CAN_TMI(canx, bank) REG32((canx) + 0x180U + ((bank) * 0x10U)) /*!< CAN transmit mailbox identifier register */
+#define CAN_TMP(canx, bank) REG32((canx) + 0x184U + ((bank) * 0x10U)) /*!< CAN transmit mailbox property register */
+#define CAN_TMDATA0(canx, bank) REG32((canx) + 0x188U + ((bank) * 0x10U)) /*!< CAN transmit mailbox data0 register */
+#define CAN_TMDATA1(canx, bank) REG32((canx) + 0x18CU + ((bank) * 0x10U)) /*!< CAN transmit mailbox data1 register */
/* CAN filter bank */
-#define CAN_FDATA0(canx, bank) REG32((canx) + 0x240U + ((bank) * 0x8U) + 0x0U) /*!< CAN filter data 0 register */
-#define CAN_FDATA1(canx, bank) REG32((canx) + 0x240U + ((bank) * 0x8U) + 0x4U) /*!< CAN filter data 1 register */
+#define CAN_FDATA0(canx, bank) REG32((canx) + 0x240U + ((bank) * 0x8U) + 0x0U) /*!< CAN filter data 0 register */
+#define CAN_FDATA1(canx, bank) REG32((canx) + 0x240U + ((bank) * 0x8U) + 0x4U) /*!< CAN filter data 1 register */
/* CAN receive fifo mailbox bank */
-#define CAN_RFIFOMI(canx, bank) REG32((canx) + 0x1B0U + ((bank) * 0x10U)) /*!< CAN receive FIFO mailbox identifier register */
-#define CAN_RFIFOMP(canx, bank) REG32((canx) + 0x1B4U + ((bank) * 0x10U)) /*!< CAN receive FIFO mailbox property register */
-#define CAN_RFIFOMDATA0(canx, bank) REG32((canx) + 0x1B8U + ((bank) * 0x10U)) /*!< CAN receive FIFO mailbox data0 register */
-#define CAN_RFIFOMDATA1(canx, bank) REG32((canx) + 0x1BCU + ((bank) * 0x10U)) /*!< CAN receive FIFO mailbox data1 register */
+#define CAN_RFIFOMI(canx, bank) REG32((canx) + 0x1B0U + ((bank) * 0x10U)) /*!< CAN receive FIFO mailbox identifier register */
+#define CAN_RFIFOMP(canx, bank) REG32((canx) + 0x1B4U + ((bank) * 0x10U)) /*!< CAN receive FIFO mailbox property register */
+#define CAN_RFIFOMDATA0(canx, bank) REG32((canx) + 0x1B8U + ((bank) * 0x10U)) /*!< CAN receive FIFO mailbox data0 register */
+#define CAN_RFIFOMDATA1(canx, bank) REG32((canx) + 0x1BCU + ((bank) * 0x10U)) /*!< CAN receive FIFO mailbox data1 register */
/* bits definitions */
/* CAN_CTL */
@@ -198,7 +224,7 @@
#define CAN_INTEN_BOIE BIT(10) /*!< bus-off interrupt enable */
#define CAN_INTEN_ERRNIE BIT(11) /*!< error number interrupt enable */
#define CAN_INTEN_ERRIE BIT(15) /*!< error interrupt enable */
-#define CAN_INTEN_WUIE BIT(16) /*!< wakeup interrupt enable */
+#define CAN_INTEN_WIE BIT(16) /*!< wakeup interrupt enable */
#define CAN_INTEN_SLPWIE BIT(17) /*!< sleep working interrupt enable */
/* CAN_ERR */
@@ -280,11 +306,19 @@
/* CAN_FW */
#define CAN_FW_FW(regval) BIT(regval) /*!< filter working */
+/* CAN_FxDATAy */
+#define CAN_FDATA_FD(regval) BIT(regval) /*!< filter data */
+
/* consts definitions */
/* define the CAN bit position and its register index offset */
-#define CAN_REGIDX_BIT(regidx, bitpos) (((uint32_t)(regidx) << 6) | (uint32_t)(bitpos))
-#define CAN_REG_VAL(canx, offset) (REG32((canx) + ((uint32_t)(offset) >> 6)))
-#define CAN_BIT_POS(val) ((uint32_t)(val) & 0x1FU)
+#define CAN_REGIDX_BIT(regidx, bitpos) (((uint32_t)(regidx) << 6) | (uint32_t)(bitpos))
+#define CAN_REG_VAL(canx, offset) (REG32((canx) + ((uint32_t)(offset) >> 6)))
+#define CAN_BIT_POS(val) ((uint32_t)(val) & 0x1FU)
+
+#define CAN_REGIDX_BITS(regidx, bitpos0, bitpos1) (((uint32_t)(regidx) << 12) | ((uint32_t)(bitpos0) << 6) | (uint32_t)(bitpos1))
+#define CAN_REG_VALS(canx, offset) (REG32((canx) + ((uint32_t)(offset) >> 12)))
+#define CAN_BIT_POS0(val) (((uint32_t)(val) >> 6) & 0x1FU)
+#define CAN_BIT_POS1(val) ((uint32_t)(val) & 0x1FU)
/* register offset */
#define STAT_REG_OFFSET ((uint8_t)0x04U) /*!< STAT register offset */
@@ -296,45 +330,84 @@
/* CAN flags */
typedef enum
{
+ /* flags in STAT register */
+ CAN_FLAG_RXL = CAN_REGIDX_BIT(STAT_REG_OFFSET, 11U), /*!< RX level */
+ CAN_FLAG_LASTRX = CAN_REGIDX_BIT(STAT_REG_OFFSET, 10U), /*!< last sample value of RX pin */
+ CAN_FLAG_RS = CAN_REGIDX_BIT(STAT_REG_OFFSET, 9U), /*!< receiving state */
+ CAN_FLAG_TS = CAN_REGIDX_BIT(STAT_REG_OFFSET, 8U), /*!< transmitting state */
+ CAN_FLAG_SLPIF = CAN_REGIDX_BIT(STAT_REG_OFFSET, 4U), /*!< status change flag of entering sleep working mode */
+ CAN_FLAG_WUIF = CAN_REGIDX_BIT(STAT_REG_OFFSET, 3U), /*!< status change flag of wakeup from sleep working mode */
+ CAN_FLAG_ERRIF = CAN_REGIDX_BIT(STAT_REG_OFFSET, 2U), /*!< error flag */
+ CAN_FLAG_SLPWS = CAN_REGIDX_BIT(STAT_REG_OFFSET, 1U), /*!< sleep working state */
+ CAN_FLAG_IWS = CAN_REGIDX_BIT(STAT_REG_OFFSET, 0U), /*!< initial working state */
/* flags in TSTAT register */
- CAN_FLAG_MTE2 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 19U), /*!< mailbox 2 transmit error */
- CAN_FLAG_MTE1 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 11U), /*!< mailbox 1 transmit error */
- CAN_FLAG_MTE0 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 3U), /*!< mailbox 0 transmit error */
- CAN_FLAG_MTF2 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 16U), /*!< mailbox 2 transmit finished */
- CAN_FLAG_MTF1 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 8U), /*!< mailbox 1 transmit finished */
- CAN_FLAG_MTF0 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 0U), /*!< mailbox 0 transmit finished */
+ CAN_FLAG_TMLS2 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 31U), /*!< transmit mailbox 2 last sending in Tx FIFO */
+ CAN_FLAG_TMLS1 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 30U), /*!< transmit mailbox 1 last sending in Tx FIFO */
+ CAN_FLAG_TMLS0 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 29U), /*!< transmit mailbox 0 last sending in Tx FIFO */
+ CAN_FLAG_TME2 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 28U), /*!< transmit mailbox 2 empty */
+ CAN_FLAG_TME1 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 27U), /*!< transmit mailbox 1 empty */
+ CAN_FLAG_TME0 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 26U), /*!< transmit mailbox 0 empty */
+ CAN_FLAG_MTE2 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 19U), /*!< mailbox 2 transmit error */
+ CAN_FLAG_MTE1 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 11U), /*!< mailbox 1 transmit error */
+ CAN_FLAG_MTE0 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 3U), /*!< mailbox 0 transmit error */
+ CAN_FLAG_MAL2 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 18U), /*!< mailbox 2 arbitration lost */
+ CAN_FLAG_MAL1 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 10U), /*!< mailbox 1 arbitration lost */
+ CAN_FLAG_MAL0 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 2U), /*!< mailbox 0 arbitration lost */
+ CAN_FLAG_MTFNERR2 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 17U), /*!< mailbox 2 transmit finished with no error */
+ CAN_FLAG_MTFNERR1 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 9U), /*!< mailbox 1 transmit finished with no error */
+ CAN_FLAG_MTFNERR0 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 1U), /*!< mailbox 0 transmit finished with no error */
+ CAN_FLAG_MTF2 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 16U), /*!< mailbox 2 transmit finished */
+ CAN_FLAG_MTF1 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 8U), /*!< mailbox 1 transmit finished */
+ CAN_FLAG_MTF0 = CAN_REGIDX_BIT(TSTAT_REG_OFFSET, 0U), /*!< mailbox 0 transmit finished */
/* flags in RFIFO0 register */
- CAN_FLAG_RFO0 = CAN_REGIDX_BIT(RFIFO0_REG_OFFSET, 4U), /*!< receive FIFO0 overfull */
- CAN_FLAG_RFF0 = CAN_REGIDX_BIT(RFIFO0_REG_OFFSET, 3U), /*!< receive FIFO0 full */
+ CAN_FLAG_RFO0 = CAN_REGIDX_BIT(RFIFO0_REG_OFFSET, 4U), /*!< receive FIFO0 overfull */
+ CAN_FLAG_RFF0 = CAN_REGIDX_BIT(RFIFO0_REG_OFFSET, 3U), /*!< receive FIFO0 full */
/* flags in RFIFO1 register */
- CAN_FLAG_RFO1 = CAN_REGIDX_BIT(RFIFO1_REG_OFFSET, 4U), /*!< receive FIFO1 overfull */
- CAN_FLAG_RFF1 = CAN_REGIDX_BIT(RFIFO1_REG_OFFSET, 3U), /*!< receive FIFO1 full */
+ CAN_FLAG_RFO1 = CAN_REGIDX_BIT(RFIFO1_REG_OFFSET, 4U), /*!< receive FIFO1 overfull */
+ CAN_FLAG_RFF1 = CAN_REGIDX_BIT(RFIFO1_REG_OFFSET, 3U), /*!< receive FIFO1 full */
/* flags in ERR register */
- CAN_FLAG_BOERR = CAN_REGIDX_BIT(ERR_REG_OFFSET, 2U), /*!< bus-off error */
- CAN_FLAG_PERR = CAN_REGIDX_BIT(ERR_REG_OFFSET, 1U), /*!< passive error */
- CAN_FLAG_WERR = CAN_REGIDX_BIT(ERR_REG_OFFSET, 0U), /*!< warning error */
+ CAN_FLAG_BOERR = CAN_REGIDX_BIT(ERR_REG_OFFSET, 2U), /*!< bus-off error */
+ CAN_FLAG_PERR = CAN_REGIDX_BIT(ERR_REG_OFFSET, 1U), /*!< passive error */
+ CAN_FLAG_WERR = CAN_REGIDX_BIT(ERR_REG_OFFSET, 0U), /*!< warning error */
}can_flag_enum;
/* CAN interrupt flags */
typedef enum
{
/* interrupt flags in STAT register */
- CAN_INT_SLPIF = CAN_REGIDX_BIT(STAT_REG_OFFSET, 4U), /*!< status change interrupt flag of sleep working mode entering */
- CAN_INT_WUIF = CAN_REGIDX_BIT(STAT_REG_OFFSET, 3U), /*!< status change interrupt flag of wakeup from sleep working mode */
- CAN_INT_ERRIF = CAN_REGIDX_BIT(STAT_REG_OFFSET, 2U), /*!< error interrupt flag */
+ CAN_INT_FLAG_SLPIF = CAN_REGIDX_BITS(STAT_REG_OFFSET, 4U, 17U), /*!< status change interrupt flag of sleep working mode entering */
+ CAN_INT_FLAG_WUIF = CAN_REGIDX_BITS(STAT_REG_OFFSET, 3U, 16), /*!< status change interrupt flag of wakeup from sleep working mode */
+ CAN_INT_FLAG_ERRIF = CAN_REGIDX_BITS(STAT_REG_OFFSET, 2U, 15), /*!< error interrupt flag */
+ /* interrupt flags in TSTAT register */
+ CAN_INT_FLAG_MTF2 = CAN_REGIDX_BITS(TSTAT_REG_OFFSET, 16U, 0U), /*!< mailbox 2 transmit finished interrupt flag */
+ CAN_INT_FLAG_MTF1 = CAN_REGIDX_BITS(TSTAT_REG_OFFSET, 8U, 0U), /*!< mailbox 1 transmit finished interrupt flag */
+ CAN_INT_FLAG_MTF0 = CAN_REGIDX_BITS(TSTAT_REG_OFFSET, 0U, 0U), /*!< mailbox 0 transmit finished interrupt flag */
+ /* interrupt flags in RFIFO0 register */
+ CAN_INT_FLAG_RFO0 = CAN_REGIDX_BITS(RFIFO0_REG_OFFSET, 4U, 3U), /*!< receive FIFO0 overfull interrupt flag */
+ CAN_INT_FLAG_RFF0 = CAN_REGIDX_BITS(RFIFO0_REG_OFFSET, 3U, 2U), /*!< receive FIFO0 full interrupt flag */
+ CAN_INT_FLAG_RFL0 = CAN_REGIDX_BITS(RFIFO0_REG_OFFSET, 2U, 1U), /*!< receive FIFO0 not empty interrupt flag */
+ /* interrupt flags in RFIFO0 register */
+ CAN_INT_FLAG_RFO1 = CAN_REGIDX_BITS(RFIFO1_REG_OFFSET, 4U, 6U), /*!< receive FIFO1 overfull interrupt flag */
+ CAN_INT_FLAG_RFF1 = CAN_REGIDX_BITS(RFIFO1_REG_OFFSET, 3U, 5U), /*!< receive FIFO1 full interrupt flag */
+ CAN_INT_FLAG_RFL1 = CAN_REGIDX_BITS(RFIFO1_REG_OFFSET, 2U, 4U), /*!< receive FIFO0 not empty interrupt flag */
+ /* interrupt flags in ERR register */
+ CAN_INT_FLAG_ERRN = CAN_REGIDX_BITS(ERR_REG_OFFSET, 3U, 11U), /*!< error number interrupt flag */
+ CAN_INT_FLAG_BOERR = CAN_REGIDX_BITS(ERR_REG_OFFSET, 2U, 10U), /*!< bus-off error interrupt flag */
+ CAN_INT_FLAG_PERR = CAN_REGIDX_BITS(ERR_REG_OFFSET, 1U, 9U), /*!< passive error interrupt flag */
+ CAN_INT_FLAG_WERR = CAN_REGIDX_BITS(ERR_REG_OFFSET, 0U, 8U), /*!< warning error interrupt flag */
}can_interrupt_flag_enum;
/* CAN initiliaze parameters struct */
typedef struct
{
- uint8_t working_mode; /*!< CAN working mode */
+ uint8_t working_mode; /*!< CAN working mode */
uint8_t resync_jump_width; /*!< CAN resynchronization jump width */
uint8_t time_segment_1; /*!< time segment 1 */
uint8_t time_segment_2; /*!< time segment 2 */
ControlStatus time_triggered; /*!< time triggered communication mode */
ControlStatus auto_bus_off_recovery; /*!< automatic bus-off recovery */
ControlStatus auto_wake_up; /*!< automatic wake-up mode */
- ControlStatus auto_retrans; /*!< automatic retransmission mode */
+ ControlStatus no_auto_retrans; /*!< automatic retransmission mode disable */
ControlStatus rec_fifo_overwrite; /*!< receive FIFO overwrite mode */
ControlStatus trans_fifo_order; /*!< transmit FIFO order */
uint16_t prescaler; /*!< baudrate prescaler */
@@ -387,18 +460,26 @@ typedef enum
CAN_ERROR_BITRECESSIVE, /*!< bit recessive error */
CAN_ERROR_BITDOMINANTER, /*!< bit dominant error */
CAN_ERROR_CRC, /*!< CRC error */
- CAN_ERROR_SOFTWARECFG /*!< software configure */
+ CAN_ERROR_SOFTWARECFG, /*!< software configure */
}can_error_enum;
/* transmit states */
typedef enum
{
- CAN_TRANSMIT_FAILED = 0, /*!< CAN transmitted failure */
- CAN_TRANSMIT_OK = 1, /*!< CAN transmitted success */
- CAN_TRANSMIT_PENDING = 2, /*!< CAN transmitted pending */
- CAN_TRANSMIT_NOMAILBOX = 4, /*!< no empty mailbox to be used for CAN */
+ CAN_TRANSMIT_FAILED = 0U, /*!< CAN transmitted failure */
+ CAN_TRANSMIT_OK = 1U, /*!< CAN transmitted success */
+ CAN_TRANSMIT_PENDING = 2U, /*!< CAN transmitted pending */
+ CAN_TRANSMIT_NOMAILBOX = 4U, /*!< no empty mailbox to be used for CAN */
}can_transmit_state_enum;
+typedef enum
+{
+ CAN_INIT_STRUCT = 0, /* CAN initiliaze parameters struct */
+ CAN_FILTER_STRUCT, /* CAN filter parameters struct */
+ CAN_TX_MESSAGE_STRUCT, /* CAN transmit message struct */
+ CAN_RX_MESSAGE_STRUCT, /* CAN receive message struct */
+}can_struct_type_enum;
+
/* CAN baudrate prescaler*/
#define BT_BAUDPSC(regval) (BITS(0,9) & ((uint32_t)(regval) << 0))
@@ -438,66 +519,76 @@ typedef enum
/* transmit data byte 2 */
#define TMDATA0_DB2(regval) (BITS(16,23) & ((uint32_t)(regval) << 16))
-/* transmit data byte 3 */
+/* transmit data byte 3 */
#define TMDATA0_DB3(regval) (BITS(24,31) & ((uint32_t)(regval) << 24))
-/* transmit data byte 4 */
+/* transmit data byte 4 */
#define TMDATA1_DB4(regval) (BITS(0,7) & ((uint32_t)(regval) << 0))
-/* transmit data byte 5 */
+/* transmit data byte 5 */
#define TMDATA1_DB5(regval) (BITS(8,15) & ((uint32_t)(regval) << 8))
-/* transmit data byte 6 */
+/* transmit data byte 6 */
#define TMDATA1_DB6(regval) (BITS(16,23) & ((uint32_t)(regval) << 16))
-/* transmit data byte 7 */
+/* transmit data byte 7 */
#define TMDATA1_DB7(regval) (BITS(24,31) & ((uint32_t)(regval) << 24))
/* receive mailbox extended identifier*/
-#define RFIFOMI_EFID(regval) GET_BITS((uint32_t)(regval), 3, 31)
+#define GET_RFIFOMI_EFID(regval) GET_BITS((uint32_t)(regval), 3U, 31U)
/* receive mailbox standrad identifier*/
-#define RFIFOMI_SFID(regval) GET_BITS((uint32_t)(regval), 21, 31)
+#define GET_RFIFOMI_SFID(regval) GET_BITS((uint32_t)(regval), 21U, 31U)
/* receive data length */
-#define RFIFOMP_DLENC(regval) GET_BITS((uint32_t)(regval), 0, 3)
+#define GET_RFIFOMP_DLENC(regval) GET_BITS((uint32_t)(regval), 0U, 3U)
-#define RFIFOMP_FI(regval) GET_BITS((uint32_t)(regval), 8, 15)
+/* the index of the filter by which the frame is passed */
+#define GET_RFIFOMP_FI(regval) GET_BITS((uint32_t)(regval), 8U, 15U)
/* receive data byte 0 */
-#define RFIFOMDATA0_DB0(regval) GET_BITS((uint32_t)(regval), 0, 7)
+#define GET_RFIFOMDATA0_DB0(regval) GET_BITS((uint32_t)(regval), 0U, 7U)
/* receive data byte 1 */
-#define RFIFOMDATA0_DB1(regval) GET_BITS((uint32_t)(regval), 8, 15)
+#define GET_RFIFOMDATA0_DB1(regval) GET_BITS((uint32_t)(regval), 8U, 15U)
/* receive data byte 2 */
-#define RFIFOMDATA0_DB2(regval) GET_BITS((uint32_t)(regval), 16, 23)
+#define GET_RFIFOMDATA0_DB2(regval) GET_BITS((uint32_t)(regval), 16U, 23U)
/* receive data byte 3 */
-#define RFIFOMDATA0_DB3(regval) GET_BITS((uint32_t)(regval), 24, 31)
+#define GET_RFIFOMDATA0_DB3(regval) GET_BITS((uint32_t)(regval), 24U, 31U)
/* receive data byte 4 */
-#define RFIFOMDATA1_DB4(regval) GET_BITS((uint32_t)(regval), 0, 7)
+#define GET_RFIFOMDATA1_DB4(regval) GET_BITS((uint32_t)(regval), 0U, 7U)
/* receive data byte 5 */
-#define RFIFOMDATA1_DB5(regval) GET_BITS((uint32_t)(regval), 8, 15)
+#define GET_RFIFOMDATA1_DB5(regval) GET_BITS((uint32_t)(regval), 8U, 15U)
/* receive data byte 6 */
-#define RFIFOMDATA1_DB6(regval) GET_BITS((uint32_t)(regval), 16, 23)
+#define GET_RFIFOMDATA1_DB6(regval) GET_BITS((uint32_t)(regval), 16U, 23U)
/* receive data byte 7 */
-#define RFIFOMDATA1_DB7(regval) GET_BITS((uint32_t)(regval), 24, 31)
+#define GET_RFIFOMDATA1_DB7(regval) GET_BITS((uint32_t)(regval), 24U, 31U)
+
+/* error number */
+#define GET_ERR_ERRN(regval) GET_BITS((uint32_t)(regval), 4U, 6U)
+
+/* transmit error count */
+#define GET_ERR_TECNT(regval) GET_BITS((uint32_t)(regval), 16U, 23U)
+
+/* receive error count */
+#define GET_ERR_RECNT(regval) GET_BITS((uint32_t)(regval), 24U, 31U)
/* CAN errors */
#define ERR_ERRN(regval) (BITS(4,6) & ((uint32_t)(regval) << 4))
-#define CAN_ERRN_0 ERR_ERRN(0) /* no error */
-#define CAN_ERRN_1 ERR_ERRN(1) /*!< fill error */
-#define CAN_ERRN_2 ERR_ERRN(2) /*!< format error */
-#define CAN_ERRN_3 ERR_ERRN(3) /*!< ACK error */
-#define CAN_ERRN_4 ERR_ERRN(4) /*!< bit recessive error */
-#define CAN_ERRN_5 ERR_ERRN(5) /*!< bit dominant error */
-#define CAN_ERRN_6 ERR_ERRN(6) /*!< CRC error */
-#define CAN_ERRN_7 ERR_ERRN(7) /*!< software error */
+#define CAN_ERRN_0 ERR_ERRN(0U) /* no error */
+#define CAN_ERRN_1 ERR_ERRN(1U) /*!< fill error */
+#define CAN_ERRN_2 ERR_ERRN(2U) /*!< format error */
+#define CAN_ERRN_3 ERR_ERRN(3U) /*!< ACK error */
+#define CAN_ERRN_4 ERR_ERRN(4U) /*!< bit recessive error */
+#define CAN_ERRN_5 ERR_ERRN(5U) /*!< bit dominant error */
+#define CAN_ERRN_6 ERR_ERRN(6U) /*!< CRC error */
+#define CAN_ERRN_7 ERR_ERRN(7U) /*!< software error */
#define CAN_STATE_PENDING ((uint32_t)0x00000000U) /*!< CAN pending */
@@ -556,7 +647,7 @@ typedef enum
#define CAN_FIFO1 ((uint8_t)0x01U) /*!< receive FIFO1 */
/* frame number of receive fifo */
-#define CAN_RFIFO_RFL0_MASK ((uint32_t)0x00000003U) /*!< mask for frame number in receive FIFO0 */
+#define CAN_RFIF_RFL_MASK ((uint32_t)0x00000003U) /*!< mask for frame number in receive FIFOx */
#define CAN_SFID_MASK ((uint32_t)0x000007FFU) /*!< mask of standard identifier */
#define CAN_EFID_MASK ((uint32_t)0x1FFFFFFFU) /*!< mask of extended identifier */
@@ -575,7 +666,7 @@ typedef enum
#define CAN_FILTERMODE_LIST ((uint8_t)0x01U) /*!< list mode */
/* filter 16 bits mask */
-#define CAN_FILTER_MASK_16BITS ((uint32_t)0x0000FFFFU)
+#define CAN_FILTER_MASK_16BITS ((uint32_t)0x0000FFFFU) /*!< can filter 16 bits mask */
/* frame type */
#define CAN_FT_DATA ((uint32_t)0x00000000U) /*!< data frame */
@@ -584,62 +675,72 @@ typedef enum
/* CAN timeout */
#define CAN_TIMEOUT ((uint32_t)0x0000FFFFU) /*!< timeout value */
+/* interrupt enable bits */
+#define CAN_INT_TME CAN_INTEN_TMEIE /*!< transmit mailbox empty interrupt enable */
+#define CAN_INT_RFNE0 CAN_INTEN_RFNEIE0 /*!< receive FIFO0 not empty interrupt enable */
+#define CAN_INT_RFF0 CAN_INTEN_RFFIE0 /*!< receive FIFO0 full interrupt enable */
+#define CAN_INT_RFO0 CAN_INTEN_RFOIE0 /*!< receive FIFO0 overfull interrupt enable */
+#define CAN_INT_RFNE1 CAN_INTEN_RFNEIE1 /*!< receive FIFO1 not empty interrupt enable */
+#define CAN_INT_RFF1 CAN_INTEN_RFFIE1 /*!< receive FIFO1 full interrupt enable */
+#define CAN_INT_RFO1 CAN_INTEN_RFOIE1 /*!< receive FIFO1 overfull interrupt enable */
+#define CAN_INT_WERR CAN_INTEN_WERRIE /*!< warning error interrupt enable */
+#define CAN_INT_PERR CAN_INTEN_PERRIE /*!< passive error interrupt enable */
+#define CAN_INT_BO CAN_INTEN_BOIE /*!< bus-off interrupt enable */
+#define CAN_INT_ERRN CAN_INTEN_ERRNIE /*!< error number interrupt enable */
+#define CAN_INT_ERR CAN_INTEN_ERRIE /*!< error interrupt enable */
+#define CAN_INT_WAKEUP CAN_INTEN_WIE /*!< wakeup interrupt enable */
+#define CAN_INT_SLPW CAN_INTEN_SLPWIE /*!< sleep working interrupt enable */
+
/* function declarations */
-/* initialization functions */
-/* CAN deinit */
+/* deinitialize CAN */
void can_deinit(uint32_t can_periph);
-/* CAN init */
+/* initialize CAN struct */
+void can_struct_para_init(can_struct_type_enum type, void* p_struct);
+/* initialize CAN */
ErrStatus can_init(uint32_t can_periph, can_parameter_struct* can_parameter_init);
-
-/* transmit functions */
-/* CAN transmit message */
-uint8_t can_message_transmit(uint32_t can_periph, can_trasnmit_message_struct* transmit_message);
-/* CAN transmit state */
-can_transmit_state_enum can_transmit_states(uint32_t can_periph, uint8_t mailbox_number);
-/* CAN stop transmission */
-void can_transmission_stop(uint32_t can_periph, uint8_t mailbox_number);
-/* CAN transmit error number */
-uint8_t can_transmit_error_number(uint32_t can_periph);
-
-/* filter functions */
/* CAN filter init */
void can_filter_init(can_filter_parameter_struct* can_filter_parameter_init);
/* set can1 fliter start bank number */
void can1_filter_start_bank(uint8_t start_bank);
-
/* enable functions */
/* CAN debug freeze enable */
void can_debug_freeze_enable(uint32_t can_periph);
/* CAN debug freeze disable */
void can_debug_freeze_disable(uint32_t can_periph);
-/* CAN time triggle mode enable */
+/* CAN time trigger mode enable */
void can_time_trigger_mode_enable(uint32_t can_periph);
-/* CAN time triggle mode disable */
+/* CAN time trigger mode disable */
void can_time_trigger_mode_disable(uint32_t can_periph);
-/* CAN interrupt enable */
-void can_interrupt_enable(uint32_t can_periph, uint32_t interrupt);
-/* CAN interrupt disable */
-void can_interrupt_disable(uint32_t can_periph, uint32_t interrupt);
-/* receive functions */
+/* transmit functions */
+/* transmit CAN message */
+uint8_t can_message_transmit(uint32_t can_periph, can_trasnmit_message_struct* transmit_message);
+/* get CAN transmit state */
+can_transmit_state_enum can_transmit_states(uint32_t can_periph, uint8_t mailbox_number);
+/* stop CAN transmission */
+void can_transmission_stop(uint32_t can_periph, uint8_t mailbox_number);
/* CAN receive message */
void can_message_receive(uint32_t can_periph, uint8_t fifo_number, can_receive_message_struct* receive_message);
/* CAN release fifo */
void can_fifo_release(uint32_t can_periph, uint8_t fifo_number);
/* CAN receive message length */
-uint8_t can_receive_message_length(uint32_t can_periph, uint8_t fifo_number);
-/* CAN receive error number */
-uint8_t can_receive_error_number(uint32_t can_periph);
-
-/* mode functions */
+uint8_t can_receive_message_length_get(uint32_t can_periph, uint8_t fifo_number);
/* CAN working mode */
ErrStatus can_working_mode_set(uint32_t can_periph, uint8_t working_mode);
/* CAN wakeup from sleep mode */
ErrStatus can_wakeup(uint32_t can_periph);
-/* flag functions */
/* CAN get error */
can_error_enum can_error_get(uint32_t can_periph);
+/* get CAN receive error number */
+uint8_t can_receive_error_number_get(uint32_t can_periph);
+/* get CAN transmit error number */
+uint8_t can_transmit_error_number_get(uint32_t can_periph);
+
+/* CAN interrupt enable */
+void can_interrupt_enable(uint32_t can_periph, uint32_t interrupt);
+/* CAN interrupt disable */
+void can_interrupt_disable(uint32_t can_periph, uint32_t interrupt);
/* CAN get flag state */
FlagStatus can_flag_get(uint32_t can_periph, can_flag_enum flag);
/* CAN clear flag state */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_crc.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_crc.h
index 983dd944a5..01f2c6bc3f 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_crc.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_crc.h
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_crc.h
- \brief definitions for the CRC
+ \file gd32f4xx_crc.h
+ \brief definitions for the CRC
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#ifndef GD32F4XX_CRC_H
@@ -37,19 +62,19 @@
/* deinit CRC calculation unit */
void crc_deinit(void);
-/* reset data register to the value of initializaiton data register */
+/* reset data register(CRC_DATA) to the value of 0xFFFFFFFF */
void crc_data_register_reset(void);
-/* read the data register */
+/* read the value of the data register */
uint32_t crc_data_register_read(void);
-/* read the free data register */
+/* read the value of the free data register */
uint8_t crc_free_data_register_read(void);
-/* write the free data register */
+/* write data to the free data register */
void crc_free_data_register_write(uint8_t free_data);
-/* CRC calculate a 32-bit data */
+/* calculate the CRC value of a 32-bit data */
uint32_t crc_single_data_calculate(uint32_t sdata);
-/* CRC calculate a 32-bit data array */
+/* calculate the CRC value of an array of 32-bit values */
uint32_t crc_block_data_calculate(uint32_t array[], uint32_t size);
#endif /* GD32F4XX_CRC_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_ctc.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_ctc.h
index 605d5530d5..00e4e7f298 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_ctc.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_ctc.h
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_ctc.h
- \brief definitions for the CTC
+ \file gd32f4xx_ctc.h
+ \brief definitions for the CTC
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#ifndef GD32F4XX_CTC_H
@@ -25,7 +50,7 @@
/* bits definitions */
/* CTC_CTL0 */
-#define CTC_CTL0_CKOKIE BIT(0) /*!< clock trim OK(CKOKIF) interrupt enable */
+#define CTC_CTL0_CKOKIE BIT(0) /*!< clock trim OK(CKOKIF) interrupt enable */
#define CTC_CTL0_CKWARNIE BIT(1) /*!< clock trim warning(CKWARNIF) interrupt enable */
#define CTC_CTL0_ERRIE BIT(2) /*!< error(ERRIF) interrupt enable */
#define CTC_CTL0_EREFIE BIT(3) /*!< EREFIF interrupt enable */
@@ -90,19 +115,19 @@
#define CTC_REFSOURCE_PSC_DIV128 CTL1_REFPSC(7) /*!< reference signal divided by 128 */
/* CTC interrupt enable definitions */
-#define CTC_INT_CKOKIE CTC_CTL0_CKOKIE /*!< clock trim OK interrupt enable */
-#define CTC_INT_CKWARNIE CTC_CTL0_CKWARNIE /*!< clock trim warning interrupt enable */
-#define CTC_INT_ERRIE CTC_CTL0_ERRIE /*!< error interrupt enable */
-#define CTC_INT_EREFIE CTC_CTL0_EREFIE /*!< expect reference interrupt enable */
+#define CTC_INT_CKOK CTC_CTL0_CKOKIE /*!< clock trim OK interrupt enable */
+#define CTC_INT_CKWARN CTC_CTL0_CKWARNIE /*!< clock trim warning interrupt enable */
+#define CTC_INT_ERR CTC_CTL0_ERRIE /*!< error interrupt enable */
+#define CTC_INT_EREF CTC_CTL0_EREFIE /*!< expect reference interrupt enable */
/* CTC interrupt source definitions */
-#define CTC_INT_CKOK CTC_STAT_CKOKIF /*!< clock trim OK interrupt flag */
-#define CTC_INT_CKWARN CTC_STAT_CKWARNIF /*!< clock trim warning interrupt flag */
-#define CTC_INT_ERR CTC_STAT_ERRIF /*!< error interrupt flag */
-#define CTC_INT_EREF CTC_STAT_EREFIF /*!< expect reference interrupt flag */
-#define CTC_INT_CKERR CTC_STAT_CKERR /*!< clock trim error bit */
-#define CTC_INT_REFMISS CTC_STAT_REFMISS /*!< reference sync pulse miss */
-#define CTC_INT_TRIMERR CTC_STAT_TRIMERR /*!< trim value error */
+#define CTC_INT_FLAG_CKOK CTC_STAT_CKOKIF /*!< clock trim OK interrupt flag */
+#define CTC_INT_FLAG_CKWARN CTC_STAT_CKWARNIF /*!< clock trim warning interrupt flag */
+#define CTC_INT_FLAG_ERR CTC_STAT_ERRIF /*!< error interrupt flag */
+#define CTC_INT_FLAG_EREF CTC_STAT_EREFIF /*!< expect reference interrupt flag */
+#define CTC_INT_FLAG_CKERR CTC_STAT_CKERR /*!< clock trim error bit */
+#define CTC_INT_FLAG_REFMISS CTC_STAT_REFMISS /*!< reference sync pulse miss */
+#define CTC_INT_FLAG_TRIMERR CTC_STAT_TRIMERR /*!< trim value error */
/* CTC flag definitions */
#define CTC_FLAG_CKOK CTC_STAT_CKOKIF /*!< clock trim OK flag */
@@ -116,45 +141,30 @@
/* function declarations */
/* reset ctc clock trim controller */
void ctc_deinit(void);
-
-/* enable the CTC interrupt */
-void ctc_interrupt_enable(uint32_t ctc_interrupt);
-/* disable the CTC interrupt */
-void ctc_interrupt_disable(uint32_t ctc_interrupt);
-/* get CTC interrupt flag */
-FlagStatus ctc_interrupt_flag_get(uint32_t ctc_interrupt);
-/* clear CTC interrupt flag */
-void ctc_interrupt_flag_clear(uint32_t ctc_interrupt);
-
-/* get CTC flag */
-FlagStatus ctc_flag_get(uint32_t ctc_flag);
-/* clear CTC flag */
-void ctc_flag_clear(uint32_t ctc_flag);
+/* enable CTC trim counter */
+void ctc_counter_enable(void);
+/* disable CTC trim counter */
+void ctc_counter_disable(void);
/* configure the IRC48M trim value */
-void ctc_irc48m_trim_value_config(uint8_t ctc_trim_value);
+void ctc_irc48m_trim_value_config(uint8_t trim_value);
/* generate software reference source sync pulse */
void ctc_software_refsource_pulse_generate(void);
/* configure hardware automatically trim mode */
-void ctc_hardware_trim_mode_config(uint32_t ctc_hardmode);
-
-/* enable CTC counter */
-void ctc_counter_enable(void);
-/* disable CTC counter */
-void ctc_counter_disable(void);
+void ctc_hardware_trim_mode_config(uint32_t hardmode);
/* configure reference signal source polarity */
-void ctc_refsource_polarity_config(uint32_t ctc_polarity);
+void ctc_refsource_polarity_config(uint32_t polarity);
/* select USBFS or USBHS SOF signal */
-void ctc_usbsof_signal_select(uint32_t ctc_usbsof);
+void ctc_usbsof_signal_select(uint32_t usbsof);
/* select reference signal source */
-void ctc_refsource_signal_select(uint32_t ctc_refs);
+void ctc_refsource_signal_select(uint32_t refs);
/* configure reference signal source prescaler */
-void ctc_refsource_prescaler_config(uint32_t ctc_prescaler);
+void ctc_refsource_prescaler_config(uint32_t prescaler);
/* configure clock trim base limit value */
-void ctc_clock_limit_value_config(uint8_t ctc_limit_value);
+void ctc_clock_limit_value_config(uint8_t limit_value);
/* configure CTC counter reload value */
-void ctc_counter_reload_value_config(uint16_t ctc_reload_value);
+void ctc_counter_reload_value_config(uint16_t reload_value);
/* read CTC counter capture value when reference sync pulse occurred */
uint16_t ctc_counter_capture_value_read(void);
@@ -165,4 +175,18 @@ uint16_t ctc_counter_reload_value_read(void);
/* read the IRC48M trim value */
uint8_t ctc_irc48m_trim_value_read(void);
+/* interrupt & flag functions */
+/* enable the CTC interrupt */
+void ctc_interrupt_enable(uint32_t interrupt);
+/* disable the CTC interrupt */
+void ctc_interrupt_disable(uint32_t interrupt);
+/* get CTC interrupt flag */
+FlagStatus ctc_interrupt_flag_get(uint32_t int_flag);
+/* clear CTC interrupt flag */
+void ctc_interrupt_flag_clear(uint32_t int_flag);
+/* get CTC flag */
+FlagStatus ctc_flag_get(uint32_t flag);
+/* clear CTC flag */
+void ctc_flag_clear(uint32_t flag);
+
#endif /* GD32F4XX_CTC_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_dac.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_dac.h
index 8a668fcc0c..573fb31336 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_dac.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_dac.h
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_dac.h
- \brief definitions for the DAC
+ \file gd32f4xx_dac.h
+ \brief definitions for the DAC
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#ifndef GD32F4XX_DAC_H
@@ -20,152 +45,153 @@
#define DAC1 1U
/* registers definitions */
-#define DAC_CTL REG32(DAC + 0x00U) /*!< DAC control register */
-#define DAC_SWT REG32(DAC + 0x04U) /*!< DAC software trigger register */
-#define DAC0_R12DH REG32(DAC + 0x08U) /*!< DAC0 12-bit right-aligned data holding register */
-#define DAC0_L12DH REG32(DAC + 0x0CU) /*!< DAC0 12-bit left-aligned data holding register */
-#define DAC0_R8DH REG32(DAC + 0x10U) /*!< DAC0 8-bit right-aligned data holding register */
-#define DAC1_R12DH REG32(DAC + 0x14U) /*!< DAC1 12-bit right-aligned data holding register */
-#define DAC1_L12DH REG32(DAC + 0x18U) /*!< DAC1 12-bit left-aligned data holding register */
-#define DAC1_R8DH REG32(DAC + 0x1CU) /*!< DAC1 8-bit right-aligned data holding register */
-#define DACC_R12DH REG32(DAC + 0x20U) /*!< DAC concurrent mode 12-bit right-aligned data holding register */
-#define DACC_L12DH REG32(DAC + 0x24U) /*!< DAC concurrent mode 12-bit left-aligned data holding register */
-#define DACC_R8DH REG32(DAC + 0x28U) /*!< DAC concurrent mode 8-bit right-aligned data holding register */
-#define DAC0_DO REG32(DAC + 0x2CU) /*!< DAC0 data output register */
-#define DAC1_DO REG32(DAC + 0x30U) /*!< DAC1 data output register */
-#define DAC_STAT REG32(DAC + 0x34U) /*!< DAC status register */
+#define DAC_CTL REG32(DAC + 0x00U) /*!< DAC control register */
+#define DAC_SWT REG32(DAC + 0x04U) /*!< DAC software trigger register */
+#define DAC0_R12DH REG32(DAC + 0x08U) /*!< DAC0 12-bit right-aligned data holding register */
+#define DAC0_L12DH REG32(DAC + 0x0CU) /*!< DAC0 12-bit left-aligned data holding register */
+#define DAC0_R8DH REG32(DAC + 0x10U) /*!< DAC0 8-bit right-aligned data holding register */
+#define DAC1_R12DH REG32(DAC + 0x14U) /*!< DAC1 12-bit right-aligned data holding register */
+#define DAC1_L12DH REG32(DAC + 0x18U) /*!< DAC1 12-bit left-aligned data holding register */
+#define DAC1_R8DH REG32(DAC + 0x1CU) /*!< DAC1 8-bit right-aligned data holding register */
+#define DACC_R12DH REG32(DAC + 0x20U) /*!< DAC concurrent mode 12-bit right-aligned data holding register */
+#define DACC_L12DH REG32(DAC + 0x24U) /*!< DAC concurrent mode 12-bit left-aligned data holding register */
+#define DACC_R8DH REG32(DAC + 0x28U) /*!< DAC concurrent mode 8-bit right-aligned data holding register */
+#define DAC0_DO REG32(DAC + 0x2CU) /*!< DAC0 data output register */
+#define DAC1_DO REG32(DAC + 0x30U) /*!< DAC1 data output register */
+#define DAC_STAT REG32(DAC + 0x34U) /*!< DAC status register */
/* bits definitions */
-/* DAC_CLT */
-#define DAC_CTL_DEN0 BIT(0) /*!< DAC0 enable/disable bit */
-#define DAC_CTL_DBOFF0 BIT(1) /*!< DAC0 output buffer turn on/turn off bit */
-#define DAC_CTL_DTEN0 BIT(2) /*!< DAC0 trigger enable/disable bit */
-#define DAC_CTL_DTSEL0 BITS(3,5) /*!< DAC0 trigger source selection enable/disable bits */
-#define DAC_CTL_DWM0 BITS(6,7) /*!< DAC0 noise wave mode */
-#define DAC_CTL_DWBW0 BITS(8,11) /*!< DAC0 noise wave bit width */
-#define DAC_CTL_DDMAEN0 BIT(12) /*!< DAC0 DMA enable/disanle bit */
-#define DAC_CTL_DDUDRIE0 BIT(13) /*!< DAC0 DMA underrun interrupt enable/disable bit */
-#define DAC_CTL_DEN1 BIT(16) /*!< DAC1 enable/disable bit */
-#define DAC_CTL_DBOFF1 BIT(17) /*!< DAC1 output buffer turn on/turn off bit */
-#define DAC_CTL_DTEN1 BIT(18) /*!< DAC1 trigger enable/disable bit */
-#define DAC_CTL_DTSEL1 BITS(19,21) /*!< DAC1 trigger source selection enable/disable bits */
-#define DAC_CTL_DWM1 BITS(22,23) /*!< DAC1 noise wave mode */
-#define DAC_CTL_DWBW1 BITS(24,27) /*!< DAC1 noise wave bit width */
-#define DAC_CTL_DDMAEN1 BIT(28) /*!< DAC1 DMA enable/disanle bit */
-#define DAC_CTL_DDUDRIE1 BIT(29) /*!< DAC1 DMA underrun interrupt enable/disable bit */
+/* DAC_CTL */
+#define DAC_CTL_DEN0 BIT(0) /*!< DAC0 enable/disable bit */
+#define DAC_CTL_DBOFF0 BIT(1) /*!< DAC0 output buffer turn on/turn off bit */
+#define DAC_CTL_DTEN0 BIT(2) /*!< DAC0 trigger enable/disable bit */
+#define DAC_CTL_DTSEL0 BITS(3,5) /*!< DAC0 trigger source selection enable/disable bits */
+#define DAC_CTL_DWM0 BITS(6,7) /*!< DAC0 noise wave mode */
+#define DAC_CTL_DWBW0 BITS(8,11) /*!< DAC0 noise wave bit width */
+#define DAC_CTL_DDMAEN0 BIT(12) /*!< DAC0 DMA enable/disable bit */
+#define DAC_CTL_DDUDRIE0 BIT(13) /*!< DAC0 DMA underrun interrupt enable/disable bit */
+#define DAC_CTL_DEN1 BIT(16) /*!< DAC1 enable/disable bit */
+#define DAC_CTL_DBOFF1 BIT(17) /*!< DAC1 output buffer turn on/turn off bit */
+#define DAC_CTL_DTEN1 BIT(18) /*!< DAC1 trigger enable/disable bit */
+#define DAC_CTL_DTSEL1 BITS(19,21) /*!< DAC1 trigger source selection enable/disable bits */
+#define DAC_CTL_DWM1 BITS(22,23) /*!< DAC1 noise wave mode */
+#define DAC_CTL_DWBW1 BITS(24,27) /*!< DAC1 noise wave bit width */
+#define DAC_CTL_DDMAEN1 BIT(28) /*!< DAC1 DMA enable/disable bit */
+#define DAC_CTL_DDUDRIE1 BIT(29) /*!< DAC1 DMA underrun interrupt enable/disable bit */
/* DAC_SWT */
-#define DAC_SWT_SWTR0 BIT(0) /*!< DAC0 software trigger bit, cleared by hardware */
-#define DAC_SWT_SWTR1 BIT(1) /*!< DAC1 software trigger bit, cleared by hardware */
+#define DAC_SWT_SWTR0 BIT(0) /*!< DAC0 software trigger bit, cleared by hardware */
+#define DAC_SWT_SWTR1 BIT(1) /*!< DAC1 software trigger bit, cleared by hardware */
/* DAC0_R12DH */
-#define DAC0_R12DH_DAC0_DH BITS(0,11) /*!< DAC0 12-bit right-aligned data bits */
+#define DAC0_R12DH_DAC0_DH BITS(0,11) /*!< DAC0 12-bit right-aligned data bits */
/* DAC0_L12DH */
-#define DAC0_L12DH_DAC0_DH BITS(4,15) /*!< DAC0 12-bit left-aligned data bits */
+#define DAC0_L12DH_DAC0_DH BITS(4,15) /*!< DAC0 12-bit left-aligned data bits */
/* DAC0_R8DH */
-#define DAC0_R8DH_DAC0_DH BITS(0,7) /*!< DAC0 8-bit right-aligned data bits */
+#define DAC0_R8DH_DAC0_DH BITS(0,7) /*!< DAC0 8-bit right-aligned data bits */
/* DAC1_R12DH */
-#define DAC1_R12DH_DAC1_DH BITS(0,11) /*!< DAC1 12-bit right-aligned data bits */
+#define DAC1_R12DH_DAC1_DH BITS(0,11) /*!< DAC1 12-bit right-aligned data bits */
/* DAC1_L12DH */
-#define DAC1_L12DH_DAC1_DH BITS(4,15) /*!< DAC1 12-bit left-aligned data bits */
+#define DAC1_L12DH_DAC1_DH BITS(4,15) /*!< DAC1 12-bit left-aligned data bits */
/* DAC1_R8DH */
-#define DAC1_R8DH_DAC1_DH BITS(0,7) /*!< DAC1 8-bit right-aligned data bits */
+#define DAC1_R8DH_DAC1_DH BITS(0,7) /*!< DAC1 8-bit right-aligned data bits */
/* DACC_R12DH */
-#define DACC_R12DH_DAC0_DH BITS(0,11) /*!< DAC concurrent mode DAC0 12-bit right-aligned data bits */
-#define DACC_R12DH_DAC1_DH BITS(16,27) /*!< DAC concurrent mode DAC1 12-bit right-aligned data bits */
+#define DACC_R12DH_DAC0_DH BITS(0,11) /*!< DAC concurrent mode DAC0 12-bit right-aligned data bits */
+#define DACC_R12DH_DAC1_DH BITS(16,27) /*!< DAC concurrent mode DAC1 12-bit right-aligned data bits */
/* DACC_L12DH */
-#define DACC_L12DH_DAC0_DH BITS(4,15) /*!< DAC concurrent mode DAC0 12-bit left-aligned data bits */
-#define DACC_L12DH_DAC1_DH BITS(20,31) /*!< DAC concurrent mode DAC1 12-bit left-aligned data bits */
+#define DACC_L12DH_DAC0_DH BITS(4,15) /*!< DAC concurrent mode DAC0 12-bit left-aligned data bits */
+#define DACC_L12DH_DAC1_DH BITS(20,31) /*!< DAC concurrent mode DAC1 12-bit left-aligned data bits */
/* DACC_R8DH */
-#define DACC_R8DH_DAC0_DH BITS(0,7) /*!< DAC concurrent mode DAC0 8-bit right-aligned data bits */
-#define DACC_R8DH_DAC1_DH BITS(16,23) /*!< DAC concurrent mode DAC1 8-bit right-aligned data bits */
+#define DACC_R8DH_DAC0_DH BITS(0,7) /*!< DAC concurrent mode DAC0 8-bit right-aligned data bits */
+#define DACC_R8DH_DAC1_DH BITS(8,15) /*!< DAC concurrent mode DAC1 8-bit right-aligned data bits */
/* DAC0_DO */
-#define DAC0_DO_DAC0_DO BITS(0,11) /*!< DAC0 12-bit output data bits */
+#define DAC0_DO_DAC0_DO BITS(0,11) /*!< DAC0 12-bit output data bits */
/* DAC1_DO */
-#define DAC1_DO_DAC1_DO BITS(0,11) /*!< DAC1 12-bit output data bits */
+#define DAC1_DO_DAC1_DO BITS(0,11) /*!< DAC1 12-bit output data bits */
/* DAC_STAT */
-#define DAC_STAT_DDUDR0 BIT(13) /*!< DAC0 DMA underrun flag */
-#define DAC_STAT_DDUDR1 BIT(29) /*!< DAC1 DMA underrun flag */
+#define DAC_STAT_DDUDR0 BIT(13) /*!< DAC0 DMA underrun flag */
+#define DAC_STAT_DDUDR1 BIT(29) /*!< DAC1 DMA underrun flag */
/* constants definitions */
/* DAC trigger source */
#define CTL_DTSEL(regval) (BITS(3,5) & ((uint32_t)(regval) << 3))
-#define DAC_TRIGGER_T5_TRGO CTL_DTSEL(0) /*!< TIMER5 TRGO */
-#define DAC_TRIGGER_T7_TRGO CTL_DTSEL(1) /*!< TIMER7 TRGO */
-#define DAC_TRIGGER_T6_TRGO CTL_DTSEL(2) /*!< TIMER6 TRGO */
-#define DAC_TRIGGER_T4_TRGO CTL_DTSEL(3) /*!< TIMER4 TRGO */
-#define DAC_TRIGGER_T1_TRGO CTL_DTSEL(4) /*!< TIMER1 TRGO */
-#define DAC_TRIGGER_T3_TRGO CTL_DTSEL(5) /*!< TIMER3 TRGO */
-#define DAC_TRIGGER_EXTI_9 CTL_DTSEL(6) /*!< EXTI interrupt line9 event */
-#define DAC_TRIGGER_SOFTWARE CTL_DTSEL(7) /*!< software trigger */
+#define DAC_TRIGGER_T5_TRGO CTL_DTSEL(0) /*!< TIMER5 TRGO */
+#define DAC_TRIGGER_T7_TRGO CTL_DTSEL(1) /*!< TIMER7 TRGO */
+#define DAC_TRIGGER_T6_TRGO CTL_DTSEL(2) /*!< TIMER6 TRGO */
+#define DAC_TRIGGER_T4_TRGO CTL_DTSEL(3) /*!< TIMER4 TRGO */
+#define DAC_TRIGGER_T1_TRGO CTL_DTSEL(4) /*!< TIMER1 TRGO */
+#define DAC_TRIGGER_T3_TRGO CTL_DTSEL(5) /*!< TIMER3 TRGO */
+#define DAC_TRIGGER_EXTI_9 CTL_DTSEL(6) /*!< EXTI interrupt line9 event */
+#define DAC_TRIGGER_SOFTWARE CTL_DTSEL(7) /*!< software trigger */
/* DAC noise wave mode */
#define CTL_DWM(regval) (BITS(6,7) & ((uint32_t)(regval) << 6))
-#define DAC_WAVE_DISABLE CTL_DWM(0) /*!< wave disable */
-#define DAC_WAVE_MODE_LFSR CTL_DWM(1) /*!< LFSR noise mode */
-#define DAC_WAVE_MODE_TRIANGLE CTL_DWM(2) /*!< triangle noise mode */
+#define DAC_WAVE_DISABLE CTL_DWM(0) /*!< wave disable */
+#define DAC_WAVE_MODE_LFSR CTL_DWM(1) /*!< LFSR noise mode */
+#define DAC_WAVE_MODE_TRIANGLE CTL_DWM(2) /*!< triangle noise mode */
/* DAC noise wave bit width */
#define DWBW(regval) (BITS(8,11) & ((uint32_t)(regval) << 8))
-#define DAC_WAVE_BIT_WIDTH_1 DWBW(0) /*!< bit width of the wave signal is 1 */
-#define DAC_WAVE_BIT_WIDTH_2 DWBW(1) /*!< bit width of the wave signal is 2 */
-#define DAC_WAVE_BIT_WIDTH_3 DWBW(2) /*!< bit width of the wave signal is 3 */
-#define DAC_WAVE_BIT_WIDTH_4 DWBW(3) /*!< bit width of the wave signal is 4 */
-#define DAC_WAVE_BIT_WIDTH_5 DWBW(4) /*!< bit width of the wave signal is 5 */
-#define DAC_WAVE_BIT_WIDTH_6 DWBW(5) /*!< bit width of the wave signal is 6 */
-#define DAC_WAVE_BIT_WIDTH_7 DWBW(6) /*!< bit width of the wave signal is 7 */
-#define DAC_WAVE_BIT_WIDTH_8 DWBW(7) /*!< bit width of the wave signal is 8 */
-#define DAC_WAVE_BIT_WIDTH_9 DWBW(8) /*!< bit width of the wave signal is 9 */
-#define DAC_WAVE_BIT_WIDTH_10 DWBW(9) /*!< bit width of the wave signal is 10 */
-#define DAC_WAVE_BIT_WIDTH_11 DWBW(10) /*!< bit width of the wave signal is 11 */
-#define DAC_WAVE_BIT_WIDTH_12 DWBW(11) /*!< bit width of the wave signal is 12 */
+#define DAC_WAVE_BIT_WIDTH_1 DWBW(0) /*!< bit width of the wave signal is 1 */
+#define DAC_WAVE_BIT_WIDTH_2 DWBW(1) /*!< bit width of the wave signal is 2 */
+#define DAC_WAVE_BIT_WIDTH_3 DWBW(2) /*!< bit width of the wave signal is 3 */
+#define DAC_WAVE_BIT_WIDTH_4 DWBW(3) /*!< bit width of the wave signal is 4 */
+#define DAC_WAVE_BIT_WIDTH_5 DWBW(4) /*!< bit width of the wave signal is 5 */
+#define DAC_WAVE_BIT_WIDTH_6 DWBW(5) /*!< bit width of the wave signal is 6 */
+#define DAC_WAVE_BIT_WIDTH_7 DWBW(6) /*!< bit width of the wave signal is 7 */
+#define DAC_WAVE_BIT_WIDTH_8 DWBW(7) /*!< bit width of the wave signal is 8 */
+#define DAC_WAVE_BIT_WIDTH_9 DWBW(8) /*!< bit width of the wave signal is 9 */
+#define DAC_WAVE_BIT_WIDTH_10 DWBW(9) /*!< bit width of the wave signal is 10 */
+#define DAC_WAVE_BIT_WIDTH_11 DWBW(10) /*!< bit width of the wave signal is 11 */
+#define DAC_WAVE_BIT_WIDTH_12 DWBW(11) /*!< bit width of the wave signal is 12 */
/* unmask LFSR bits in DAC LFSR noise mode */
-#define DAC_LFSR_BIT0 DAC_WAVE_BIT_WIDTH_1 /*!< unmask the LFSR bit0 */
-#define DAC_LFSR_BITS1_0 DAC_WAVE_BIT_WIDTH_2 /*!< unmask the LFSR bits[1:0] */
-#define DAC_LFSR_BITS2_0 DAC_WAVE_BIT_WIDTH_3 /*!< unmask the LFSR bits[2:0] */
-#define DAC_LFSR_BITS3_0 DAC_WAVE_BIT_WIDTH_4 /*!< unmask the LFSR bits[3:0] */
-#define DAC_LFSR_BITS4_0 DAC_WAVE_BIT_WIDTH_5 /*!< unmask the LFSR bits[4:0] */
-#define DAC_LFSR_BITS5_0 DAC_WAVE_BIT_WIDTH_6 /*!< unmask the LFSR bits[5:0] */
-#define DAC_LFSR_BITS6_0 DAC_WAVE_BIT_WIDTH_7 /*!< unmask the LFSR bits[6:0] */
-#define DAC_LFSR_BITS7_0 DAC_WAVE_BIT_WIDTH_8 /*!< unmask the LFSR bits[7:0] */
-#define DAC_LFSR_BITS8_0 DAC_WAVE_BIT_WIDTH_9 /*!< unmask the LFSR bits[8:0] */
-#define DAC_LFSR_BITS9_0 DAC_WAVE_BIT_WIDTH_10 /*!< unmask the LFSR bits[9:0] */
-#define DAC_LFSR_BITS10_0 DAC_WAVE_BIT_WIDTH_11 /*!< unmask the LFSR bits[10:0] */
-#define DAC_LFSR_BITS11_0 DAC_WAVE_BIT_WIDTH_12 /*!< unmask the LFSR bits[11:0] */
-
-/* triangle amplitude in DAC triangle noise mode */
-#define DAC_TRIANGLE_AMPLITUDE_1 DAC_WAVE_BIT_WIDTH_1 /*!< triangle amplitude is 1 */
-#define DAC_TRIANGLE_AMPLITUDE_3 DAC_WAVE_BIT_WIDTH_2 /*!< triangle amplitude is 3 */
-#define DAC_TRIANGLE_AMPLITUDE_7 DAC_WAVE_BIT_WIDTH_3 /*!< triangle amplitude is 7 */
-#define DAC_TRIANGLE_AMPLITUDE_15 DAC_WAVE_BIT_WIDTH_4 /*!< triangle amplitude is 15 */
-#define DAC_TRIANGLE_AMPLITUDE_31 DAC_WAVE_BIT_WIDTH_5 /*!< triangle amplitude is 31 */
-#define DAC_TRIANGLE_AMPLITUDE_63 DAC_WAVE_BIT_WIDTH_6 /*!< triangle amplitude is 63 */
-#define DAC_TRIANGLE_AMPLITUDE_127 DAC_WAVE_BIT_WIDTH_7 /*!< triangle amplitude is 127 */
-#define DAC_TRIANGLE_AMPLITUDE_255 DAC_WAVE_BIT_WIDTH_8 /*!< triangle amplitude is 255 */
-#define DAC_TRIANGLE_AMPLITUDE_511 DAC_WAVE_BIT_WIDTH_9 /*!< triangle amplitude is 511 */
-#define DAC_TRIANGLE_AMPLITUDE_1023 DAC_WAVE_BIT_WIDTH_10 /*!< triangle amplitude is 1023 */
-#define DAC_TRIANGLE_AMPLITUDE_2047 DAC_WAVE_BIT_WIDTH_11 /*!< triangle amplitude is 2047 */
-#define DAC_TRIANGLE_AMPLITUDE_4095 DAC_WAVE_BIT_WIDTH_12 /*!< triangle amplitude is 4095 */
+#define DAC_LFSR_BIT0 DAC_WAVE_BIT_WIDTH_1 /*!< unmask the LFSR bit0 */
+#define DAC_LFSR_BITS1_0 DAC_WAVE_BIT_WIDTH_2 /*!< unmask the LFSR bits[1:0] */
+#define DAC_LFSR_BITS2_0 DAC_WAVE_BIT_WIDTH_3 /*!< unmask the LFSR bits[2:0] */
+#define DAC_LFSR_BITS3_0 DAC_WAVE_BIT_WIDTH_4 /*!< unmask the LFSR bits[3:0] */
+#define DAC_LFSR_BITS4_0 DAC_WAVE_BIT_WIDTH_5 /*!< unmask the LFSR bits[4:0] */
+#define DAC_LFSR_BITS5_0 DAC_WAVE_BIT_WIDTH_6 /*!< unmask the LFSR bits[5:0] */
+#define DAC_LFSR_BITS6_0 DAC_WAVE_BIT_WIDTH_7 /*!< unmask the LFSR bits[6:0] */
+#define DAC_LFSR_BITS7_0 DAC_WAVE_BIT_WIDTH_8 /*!< unmask the LFSR bits[7:0] */
+#define DAC_LFSR_BITS8_0 DAC_WAVE_BIT_WIDTH_9 /*!< unmask the LFSR bits[8:0] */
+#define DAC_LFSR_BITS9_0 DAC_WAVE_BIT_WIDTH_10 /*!< unmask the LFSR bits[9:0] */
+#define DAC_LFSR_BITS10_0 DAC_WAVE_BIT_WIDTH_11 /*!< unmask the LFSR bits[10:0] */
+#define DAC_LFSR_BITS11_0 DAC_WAVE_BIT_WIDTH_12 /*!< unmask the LFSR bits[11:0] */
/* DAC data alignment */
#define DATA_ALIGN(regval) (BITS(0,1) & ((uint32_t)(regval) << 0))
-#define DAC_ALIGN_12B_R DATA_ALIGN(0) /*!< data right 12b alignment */
-#define DAC_ALIGN_12B_L DATA_ALIGN(1) /*!< data left 12b alignment */
-#define DAC_ALIGN_8B_R DATA_ALIGN(2) /*!< data right 8b alignment */
+#define DAC_ALIGN_12B_R DATA_ALIGN(0) /*!< data right 12 bit alignment */
+#define DAC_ALIGN_12B_L DATA_ALIGN(1) /*!< data left 12 bit alignment */
+#define DAC_ALIGN_8B_R DATA_ALIGN(2) /*!< data right 8 bit alignment */
+
+/* triangle amplitude in DAC triangle noise mode */
+#define DAC_TRIANGLE_AMPLITUDE_1 DAC_WAVE_BIT_WIDTH_1 /*!< triangle amplitude is 1 */
+#define DAC_TRIANGLE_AMPLITUDE_3 DAC_WAVE_BIT_WIDTH_2 /*!< triangle amplitude is 3 */
+#define DAC_TRIANGLE_AMPLITUDE_7 DAC_WAVE_BIT_WIDTH_3 /*!< triangle amplitude is 7 */
+#define DAC_TRIANGLE_AMPLITUDE_15 DAC_WAVE_BIT_WIDTH_4 /*!< triangle amplitude is 15 */
+#define DAC_TRIANGLE_AMPLITUDE_31 DAC_WAVE_BIT_WIDTH_5 /*!< triangle amplitude is 31 */
+#define DAC_TRIANGLE_AMPLITUDE_63 DAC_WAVE_BIT_WIDTH_6 /*!< triangle amplitude is 63 */
+#define DAC_TRIANGLE_AMPLITUDE_127 DAC_WAVE_BIT_WIDTH_7 /*!< triangle amplitude is 127 */
+#define DAC_TRIANGLE_AMPLITUDE_255 DAC_WAVE_BIT_WIDTH_8 /*!< triangle amplitude is 255 */
+#define DAC_TRIANGLE_AMPLITUDE_511 DAC_WAVE_BIT_WIDTH_9 /*!< triangle amplitude is 511 */
+#define DAC_TRIANGLE_AMPLITUDE_1023 DAC_WAVE_BIT_WIDTH_10 /*!< triangle amplitude is 1023 */
+#define DAC_TRIANGLE_AMPLITUDE_2047 DAC_WAVE_BIT_WIDTH_11 /*!< triangle amplitude is 2047 */
+#define DAC_TRIANGLE_AMPLITUDE_4095 DAC_WAVE_BIT_WIDTH_12 /*!< triangle amplitude is 4095 */
/* function declarations */
+/* initialization functions */
/* deinitialize DAC */
void dac_deinit(void);
/* enable DAC */
@@ -175,26 +201,29 @@ void dac_disable(uint32_t dac_periph);
/* enable DAC DMA */
void dac_dma_enable(uint32_t dac_periph);
/* disable DAC DMA */
-void dac_dma_disable(uint32_t dac_periph);
+void dac_dma_disable(uint32_t dac_periph);
/* enable DAC output buffer */
void dac_output_buffer_enable(uint32_t dac_periph);
/* disable DAC output buffer */
void dac_output_buffer_disable(uint32_t dac_periph);
+/* get the last data output value */
+uint16_t dac_output_value_get(uint32_t dac_periph);
+/* set DAC data holding register value */
+void dac_data_set(uint32_t dac_periph, uint32_t dac_align, uint16_t data);
+
+/* DAC trigger configuration */
/* enable DAC trigger */
void dac_trigger_enable(uint32_t dac_periph);
/* disable DAC trigger */
void dac_trigger_disable(uint32_t dac_periph);
+/* configure DAC trigger source */
+void dac_trigger_source_config(uint32_t dac_periph, uint32_t triggersource);
/* enable DAC software trigger */
void dac_software_trigger_enable(uint32_t dac_periph);
/* disable DAC software trigger */
void dac_software_trigger_disable(uint32_t dac_periph);
-/* enable DAC interrupt(DAC0 DMA underrun interrupt) */
-void dac_interrupt_enable(uint32_t dac_periph);
-/* disable DAC interrupt(DAC0 DMA underrun interrupt) */
-void dac_interrupt_disable(uint32_t dac_periph);
-/* configure DAC trigger source */
-void dac_trigger_source_config(uint32_t dac_periph, uint32_t triggersource);
+/* DAC wave mode configuration */
/* configure DAC wave mode */
void dac_wave_mode_config(uint32_t dac_periph, uint32_t wave_mode);
/* configure DAC wave bit width */
@@ -203,14 +232,8 @@ void dac_wave_bit_width_config(uint32_t dac_periph, uint32_t bit_width);
void dac_lfsr_noise_config(uint32_t dac_periph, uint32_t unmask_bits);
/* configure DAC triangle noise mode */
void dac_triangle_noise_config(uint32_t dac_periph, uint32_t amplitude);
-/* get the last data output value */
-uint16_t dac_output_value_get(uint32_t dac_periph);
-
-/* set DAC data holding register value */
-void dac_data_set(uint32_t dac_periph, uint32_t dac_align, uint16_t data);
-/* set DAC concurrent mode data holding register value */
-void dac_concurrent_data_set(uint32_t dac_align, uint16_t data0, uint16_t data1);
+/* DAC concurrent mode configuration */
/* enable DAC concurrent mode */
void dac_concurrent_enable(void);
/* disable DAC concurrent mode */
@@ -223,11 +246,18 @@ void dac_concurrent_software_trigger_disable(void);
void dac_concurrent_output_buffer_enable(void);
/* disable DAC concurrent buffer function */
void dac_concurrent_output_buffer_disable(void);
+/* set DAC concurrent mode data holding register value */
+void dac_concurrent_data_set(uint32_t dac_align, uint16_t data0, uint16_t data1);
/* enable DAC concurrent interrupt */
void dac_concurrent_interrupt_enable(void);
/* disable DAC concurrent interrupt */
void dac_concurrent_interrupt_disable(void);
+/* DAC interrupt configuration */
+/* enable DAC interrupt(DAC DMA underrun interrupt) */
+void dac_interrupt_enable(uint32_t dac_periph);
+/* disable DAC interrupt(DAC DMA underrun interrupt) */
+void dac_interrupt_disable(uint32_t dac_periph);
/* get the specified DAC flag(DAC DMA underrun flag) */
FlagStatus dac_flag_get(uint32_t dac_periph);
/* clear the specified DAC flag(DAC DMA underrun flag) */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_dbg.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_dbg.h
index 273b13e7fb..fde91597f7 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_dbg.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_dbg.h
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_dbg.h
- \brief definitions for the DBG
+ \file gd32f4xx_dbg.h
+ \brief definitions for the DBG
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#ifndef GD32F4XX_DBG_H
@@ -65,30 +90,43 @@
#define DBG_LOW_POWER_DEEPSLEEP DBG_CTL0_DSLP_HOLD /*!< keep debugger connection during deepsleep mode */
#define DBG_LOW_POWER_STANDBY DBG_CTL0_STB_HOLD /*!< keep debugger connection during standby mode */
+/* define the peripheral debug hold bit position and its register index offset */
+#define DBG_REGIDX_BIT(regidx, bitpos) (((regidx) << 6) | (bitpos))
+#define DBG_REG_VAL(periph) (REG32(DBG + ((uint32_t)(periph) >> 6)))
+#define DBG_BIT_POS(val) ((uint32_t)(val) & 0x1FU)
+
+/* register index */
+enum dbg_reg_idx
+{
+ DBG_IDX_CTL0 = 0x04U,
+ DBG_IDX_CTL1 = 0x08U,
+ DBG_IDX_CTL2 = 0x0CU
+};
+
typedef enum
{
- DBG_TIMER1_HOLD = BIT(0), /*!< hold TIMER1 counter when core is halted */
- DBG_TIMER2_HOLD = BIT(1), /*!< hold TIMER2 counter when core is halted */
- DBG_TIMER3_HOLD = BIT(2), /*!< hold TIMER3 counter when core is halted */
- DBG_TIMER4_HOLD = BIT(3), /*!< hold TIMER4 counter when core is halted */
- DBG_TIMER5_HOLD = BIT(4), /*!< hold TIMER5 counter when core is halted */
- DBG_TIMER6_HOLD = BIT(5), /*!< hold TIMER6 counter when core is halted */
- DBG_TIMER11_HOLD = BIT(6), /*!< hold TIMER11 counter when core is halted */
- DBG_TIMER12_HOLD = BIT(7), /*!< hold TIMER12 counter when core is halted */
- DBG_TIMER13_HOLD = BIT(8), /*!< hold TIMER13 counter when core is halted */
- DBG_RTC_HOLD = BIT(10), /*!< hold RTC calendar and wakeup counter when core is halted */
- DBG_WWDGT_HOLD = BIT(11), /*!< debug WWDGT kept when core is halted */
- DBG_FWDGT_HOLD = BIT(12), /*!< debug FWDGT kept when core is halted */
- DBG_I2C0_HOLD = BIT(21), /*!< hold I2C0 smbus when core is halted */
- DBG_I2C1_HOLD = BIT(22), /*!< hold I2C1 smbus when core is halted */
- DBG_I2C2_HOLD = BIT(23), /*!< hold I2C2 smbus when core is halted */
- DBG_CAN0_HOLD = BIT(25), /*!< debug CAN0 kept when core is halted */
- DBG_CAN1_HOLD = BIT(26), /*!< debug CAN1 kept when core is halted */
- DBG_TIMER0_HOLD = (BIT(0) | BIT(30)), /*!< hold TIMER0 counter when core is halted */
- DBG_TIMER7_HOLD = (BIT(1) | BIT(30)), /*!< hold TIMER7 counter when core is halted */
- DBG_TIMER8_HOLD = (BIT(16) | BIT(30)), /*!< hold TIMER8 counter when core is halted */
- DBG_TIMER9_HOLD = (BIT(17) | BIT(30)), /*!< hold TIMER9 counter when core is halted */
- DBG_TIMER10_HOLD = (BIT(18) | BIT(30)), /*!< hold TIMER10 counter when core is halted */
+ DBG_TIMER1_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL1, 0U), /*!< hold TIMER1 counter when core is halted */
+ DBG_TIMER2_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL1, 1U), /*!< hold TIMER2 counter when core is halted */
+ DBG_TIMER3_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL1, 2U), /*!< hold TIMER3 counter when core is halted */
+ DBG_TIMER4_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL1, 3U), /*!< hold TIMER4 counter when core is halted */
+ DBG_TIMER5_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL1, 4U), /*!< hold TIMER5 counter when core is halted */
+ DBG_TIMER6_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL1, 5U), /*!< hold TIMER6 counter when core is halted */
+ DBG_TIMER11_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL1, 6U), /*!< hold TIMER11 counter when core is halted */
+ DBG_TIMER12_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL1, 7U), /*!< hold TIMER12 counter when core is halted */
+ DBG_TIMER13_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL1, 8U), /*!< hold TIMER13 counter when core is halted */
+ DBG_RTC_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL1, 10U), /*!< hold RTC calendar and wakeup counter when core is halted */
+ DBG_WWDGT_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL1, 11U), /*!< debug WWDGT kept when core is halted */
+ DBG_FWDGT_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL1, 12U), /*!< debug FWDGT kept when core is halted */
+ DBG_I2C0_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL1, 21U), /*!< hold I2C0 smbus when core is halted */
+ DBG_I2C1_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL1, 22U), /*!< hold I2C1 smbus when core is halted */
+ DBG_I2C2_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL1, 23U), /*!< hold I2C2 smbus when core is halted */
+ DBG_CAN0_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL1, 25U), /*!< debug CAN0 kept when core is halted */
+ DBG_CAN1_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL1, 26U), /*!< debug CAN1 kept when core is halted */
+ DBG_TIMER0_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL2, 0U), /*!< hold TIMER0 counter when core is halted */
+ DBG_TIMER7_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL2, 1U), /*!< hold TIMER7 counter when core is halted */
+ DBG_TIMER8_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL2, 16U), /*!< hold TIMER8 counter when core is halted */
+ DBG_TIMER9_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL2, 17U), /*!< hold TIMER9 counter when core is halted */
+ DBG_TIMER10_HOLD = DBG_REGIDX_BIT(DBG_IDX_CTL2, 18U) /*!< hold TIMER10 counter when core is halted */
}dbg_periph_enum;
#define CTL0_TRACE_MODE(regval) (BITS(6,7)&((uint32_t)(regval)<<6))
@@ -98,6 +136,8 @@ typedef enum
#define TRACE_MODE_SYNC_DATASIZE_4 CTL0_TRACE_MODE(3) /*!< trace pin used for sync mode and data size is 4 */
/* function declarations */
+/* deinitialize the DBG */
+void dbg_deinit(void);
/* read DBG_ID code register */
uint32_t dbg_id_get(void);
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_dci.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_dci.h
index 7c9b445138..4986d5afd4 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_dci.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_dci.h
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_dci.h
- \brief definitions for the DCI
+ \file gd32f4xx_dci.h
+ \brief definitions for the DCI
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#ifndef GD32F4XX_DCI_H
@@ -32,17 +57,17 @@
/* bits definitions */
/* DCI_CTL */
-#define DCI_CTL_CAP BIT(0) /*!< capture enable */
-#define DCI_CTL_SNAP BIT(1) /*!< snapshot mode */
-#define DCI_CTL_WDEN BIT(2) /*!< window enable */
-#define DCI_CTL_JM BIT(3) /*!< jpeg mode */
-#define DCI_CTL_ESM BIT(4) /*!< embedded synchronous mode */
-#define DCI_CTL_CKS BIT(5) /*!< clock polarity selection */
-#define DCI_CTL_HPS BIT(6) /*!< horizontal polarity selection */
-#define DCI_CTL_VPS BIT(7) /*!< vertical polarity selection */
-#define DCI_CTL_FR BITS(8,9) /*!< frame rate */
-#define DCI_CTL_DCIF BITS(10,11) /*!< digital camera interface format */
-#define DCI_CTL_DCIEN BIT(14) /*!< dci enable */
+#define DCI_CTL_CAP BIT(0) /*!< capture enable */
+#define DCI_CTL_SNAP BIT(1) /*!< snapshot mode */
+#define DCI_CTL_WDEN BIT(2) /*!< window enable */
+#define DCI_CTL_JM BIT(3) /*!< JPEG mode */
+#define DCI_CTL_ESM BIT(4) /*!< embedded synchronous mode */
+#define DCI_CTL_CKS BIT(5) /*!< clock polarity selection */
+#define DCI_CTL_HPS BIT(6) /*!< horizontal polarity selection */
+#define DCI_CTL_VPS BIT(7) /*!< vertical polarity selection */
+#define DCI_CTL_FR BITS(8,9) /*!< frame rate */
+#define DCI_CTL_DCIF BITS(10,11) /*!< digital camera interface format */
+#define DCI_CTL_DCIEN BIT(14) /*!< DCI enable */
/* DCI_STAT0 */
#define DCI_STAT0_HS BIT(0) /*!< HS line status */
@@ -98,16 +123,16 @@
#define DCI_CWSZ_WVSZ BITS(16,29) /*!< window vertical size */
/* constants definitions */
-/* DCI parameter struct definitions */
+/* DCI parameter structure definitions */
typedef struct
-{
+{
uint32_t capture_mode; /*!< DCI capture mode: continuous or snapshot */
uint32_t clock_polarity; /*!< clock polarity selection */
uint32_t hsync_polarity; /*!< horizontal polarity selection */
uint32_t vsync_polarity; /*!< vertical polarity selection */
uint32_t frame_rate; /*!< frame capture rate */
uint32_t interface_format; /*!< digital camera interface format */
-}dci_parameter_struct;
+}dci_parameter_struct;
#define DCI_CAPTURE_MODE_CONTINUOUS ((uint32_t)0x00000000U) /*!< continuous capture mode */
#define DCI_CAPTURE_MODE_SNAPSHOT DCI_CTL_SNAP /*!< snapshot capture mode */
@@ -120,36 +145,44 @@ typedef struct
#define DCI_VSYNC_POLARITY_LOW ((uint32_t)0x00000000U) /*!< low level during blanking period */
#define DCI_VSYNC_POLARITY_HIGH DCI_CTL_VPS /*!< high level during blanking period*/
-
-#define CTL_FR(regval) (BITS(8,9)&((uint32_t)(regval) << 8U))
+
+#define CTL_FR(regval) (BITS(8,9)&((uint32_t)(regval) << 8U))
#define DCI_FRAME_RATE_ALL CTL_FR(0) /*!< capture all frames */
#define DCI_FRAME_RATE_1_2 CTL_FR(1) /*!< capture one in 2 frames */
#define DCI_FRAME_RATE_1_4 CTL_FR(2) /*!< capture one in 4 frames */
-#define CTL_DCIF(regval) (BITS(10,11)&((uint32_t)(regval) << 10U))
+#define CTL_DCIF(regval) (BITS(10,11)&((uint32_t)(regval) << 10U))
#define DCI_INTERFACE_FORMAT_8BITS CTL_DCIF(0) /*!< 8-bit data on every pixel clock */
#define DCI_INTERFACE_FORMAT_10BITS CTL_DCIF(1) /*!< 10-bit data on every pixel clock */
#define DCI_INTERFACE_FORMAT_12BITS CTL_DCIF(2) /*!< 12-bit data on every pixel clock */
#define DCI_INTERFACE_FORMAT_14BITS CTL_DCIF(3) /*!< 14-bit data on every pixel clock */
/* DCI interrupt constants definitions */
-#define DCI_INT_EF ((uint32_t)0x00000001U) /*!< end of frame interrupt */
-#define DCI_INT_OVR ((uint32_t)0x00000002U) /*!< FIFO overrun interrupt */
-#define DCI_INT_ESE ((uint32_t)0x00000004U) /*!< embedded synchronous error interrupt */
-#define DCI_INT_VS ((uint32_t)0x00000008U) /*!< vsync interrupt */
-#define DCI_INT_EL ((uint32_t)0x00000010U) /*!< end of line interrupt */
+#define DCI_INT_EF BIT(0) /*!< end of frame interrupt */
+#define DCI_INT_OVR BIT(1) /*!< FIFO overrun interrupt */
+#define DCI_INT_ESE BIT(2) /*!< embedded synchronous error interrupt */
+#define DCI_INT_VSYNC BIT(3) /*!< vsync interrupt */
+#define DCI_INT_EL BIT(4) /*!< end of line interrupt */
+
+/* DCI interrupt flag definitions */
+#define DCI_INT_FLAG_EF BIT(0) /*!< end of frame interrupt flag */
+#define DCI_INT_FLAG_OVR BIT(1) /*!< FIFO overrun interrupt flag */
+#define DCI_INT_FLAG_ESE BIT(2) /*!< embedded synchronous error interrupt flag */
+#define DCI_INT_FLAG_VSYNC BIT(3) /*!< vsync interrupt flag */
+#define DCI_INT_FLAG_EL BIT(4) /*!< end of line interrupt flag */
-/* DCI flag definitions */
-#define DCI_FLAG_HS ((uint8_t)0x01U) /*!< HS line status */
-#define DCI_FLAG_VS ((uint8_t)0x02U) /*!< VS line status */
-#define DCI_FLAG_FV ((uint8_t)0x03U) /*!< FIFO valid */
-#define DCI_FLAG_EFF ((uint8_t)0x04U) /*!< end of frame flag */
-#define DCI_FLAG_OVRF ((uint8_t)0x05U) /*!< FIFO overrun flag */
-#define DCI_FLAG_ESEF ((uint8_t)0x06U) /*!< embedded synchronous error flag */
-#define DCI_FLAG_VSF ((uint8_t)0x07U) /*!< vsync flag */
-#define DCI_FLAG_ELF ((uint8_t)0x08U) /*!< end of line flag */
+/* DCI flag definitions */
+#define DCI_FLAG_HS DCI_STAT0_HS /*!< HS line status */
+#define DCI_FLAG_VS DCI_STAT0_VS /*!< VS line status */
+#define DCI_FLAG_FV DCI_STAT0_FV /*!< FIFO valid */
+#define DCI_FLAG_EF (DCI_STAT1_EFF | BIT(31)) /*!< end of frame flag */
+#define DCI_FLAG_OVR (DCI_STAT1_OVRF | BIT(31)) /*!< FIFO overrun flag */
+#define DCI_FLAG_ESE (DCI_STAT1_ESEF | BIT(31)) /*!< embedded synchronous error flag */
+#define DCI_FLAG_VSYNC (DCI_STAT1_VSF | BIT(31)) /*!< vsync flag */
+#define DCI_FLAG_EL (DCI_STAT1_ELF | BIT(31)) /*!< end of line flag */
/* function declarations */
+/* initialization functions */
/* DCI deinit */
void dci_deinit(void);
/* initialize DCI registers */
@@ -157,44 +190,49 @@ void dci_init(dci_parameter_struct* dci_struct);
/* enable DCI function */
void dci_enable(void);
-/* disble DCI function */
+/* disable DCI function */
void dci_disable(void);
/* enable DCI capture */
void dci_capture_enable(void);
-/* disble DCI capture */
+/* disable DCI capture */
void dci_capture_disable(void);
/* enable DCI jpeg mode */
void dci_jpeg_enable(void);
-/* disble DCI jpeg mode */
+/* disable DCI jpeg mode */
void dci_jpeg_disable(void);
+/* function configuration */
/* enable cropping window function */
void dci_crop_window_enable(void);
-/* disble cropping window function */
+/* disable cropping window function */
void dci_crop_window_disable(void);
-/* config DCI cropping window */
+/* configure DCI cropping window */
void dci_crop_window_config(uint16_t start_x, uint16_t start_y, uint16_t size_width, uint16_t size_height);
-/* enable sync codes function */
-void dci_sync_codes_enable(void);
-/* disble sync codes function */
-void dci_sync_codes_disable(void);
-/* config sync codes */
+/* enable embedded synchronous mode */
+void dci_embedded_sync_enable(void);
+/* disable embedded synchronous mode */
+void dci_embedded_sync_disable(void);
+/* configure synchronous codes in embedded synchronous mode */
void dci_sync_codes_config(uint8_t frame_start, uint8_t line_start, uint8_t line_end, uint8_t frame_end);
-/* config sync codes unmask */
+/* configure synchronous codes unmask in embedded synchronous mode */
void dci_sync_codes_unmask_config(uint8_t frame_start, uint8_t line_start, uint8_t line_end, uint8_t frame_end);
/* read DCI data register */
uint32_t dci_data_read(void);
+/* interrupt & flag functions */
+/* get specified flag */
+FlagStatus dci_flag_get(uint32_t flag);
/* enable specified DCI interrupt */
void dci_interrupt_enable(uint32_t interrupt);
-/* disble specified DCI interrupt */
+/* disable specified DCI interrupt */
void dci_interrupt_disable(uint32_t interrupt);
-/* clear specified interrupt */
-void dci_interrupt_clear(uint32_t interrupt);
-/* get specified flag */
-FlagStatus dci_flag_get(uint32_t flag);
+
+
/* get specified interrupt flag */
-FlagStatus dci_interrupt_flag_get(uint32_t interrupt);
+FlagStatus dci_interrupt_flag_get(uint32_t int_flag);
+/* clear specified interrupt flag */
+void dci_interrupt_flag_clear(uint32_t int_flag);
+
#endif /* GD32F4XX_DCI_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_dma.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_dma.h
index be59a229f6..cac70b85eb 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_dma.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_dma.h
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_dma.h
- \brief definitions for the DMA
+ \file gd32f4xx_dma.c
+ \brief definitions for the DMA
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#ifndef GD32F4XX_DMA_H
@@ -123,10 +148,10 @@
#define DMA_CHXPADDR_PADDR BITS(0,31) /*!< peripheral base address */
/* DMA_CHxM0ADDR,x=0..7 */
-#define DMA_CHXM0ADDR_PADDR BITS(0,31) /*!< memory 0 base address */
+#define DMA_CHXM0ADDR_M0ADDR BITS(0,31) /*!< memory 0 base address */
/* DMA_CHxM1ADDR,x=0..7 */
-#define DMA_CHXM1ADDR_PADDR BITS(0,31) /*!< memory 1 base address */
+#define DMA_CHXM1ADDR_M0ADDR BITS(0,31) /*!< memory 1 base address */
/* DMA_CHxFCTL,x=0..7 */
#define DMA_CHXFCTL_FCCV BITS(0,1) /*!< FIFO counter critical value */
@@ -136,7 +161,7 @@
/* constants definitions */
/* DMA channel select */
-typedef enum
+typedef enum
{
DMA_CH0 = 0, /*!< DMA Channel 0 */
DMA_CH1, /*!< DMA Channel 1 */
@@ -149,7 +174,7 @@ typedef enum
} dma_channel_enum;
/* DMA peripheral select */
-typedef enum
+typedef enum
{
DMA_SUBPERI0 = 0, /*!< DMA Peripheral 0 */
DMA_SUBPERI1, /*!< DMA Peripheral 1 */
@@ -166,7 +191,7 @@ typedef struct
{
uint32_t periph_addr; /*!< peripheral base address */
uint32_t periph_width; /*!< transfer data size of peripheral */
- uint32_t periph_inc; /*!< peripheral increasing mode */
+ uint32_t periph_inc; /*!< peripheral increasing mode */
uint32_t memory0_addr; /*!< memory 0 base address */
uint32_t memory_width; /*!< transfer data size of memory */
@@ -176,7 +201,7 @@ typedef struct
uint32_t periph_burst_width; /*!< multi data mode enable */
uint32_t critical_value; /*!< FIFO critical */
- uint32_t circular_mode;
+ uint32_t circular_mode; /*!< DMA circular mode */
uint32_t direction; /*!< channel data transfer direction */
uint32_t number; /*!< channel transfer number */
uint32_t priority; /*!< channel priority level */
@@ -186,7 +211,7 @@ typedef struct
typedef struct
{
uint32_t periph_addr; /*!< peripheral base address */
- uint32_t periph_inc; /*!< peripheral increasing mode */
+ uint32_t periph_inc; /*!< peripheral increasing mode */
uint32_t memory0_addr; /*!< memory 0 base address */
uint32_t memory_inc; /*!< memory increasing mode */
@@ -296,85 +321,108 @@ typedef struct
#define DMA_FIFO_STATUS_FULL ((uint32_t)0x00000005U) /*!< the data in the FIFO is full */
/* DMA reset value */
-#define DMA_CHCTL_RESET_VALUE ((uint32_t)0x00000000U) /*!< the reset value of DMA channel CHXCTL register */
-#define DMA_CHCNT_RESET_VALUE ((uint32_t)0x00000000U) /*!< the reset value of DMA channel CHXCNT register */
-#define DMA_CHPADDR_RESET_VALUE ((uint32_t)0x00000000U) /*!< the reset value of DMA channel CHXPADDR register */
-#define DMA_CHMADDR_RESET_VALUE ((uint32_t)0x00000000U) /*!< the reset value of DMA channel CHXMADDR register */
-#define DMA_CHINTF_RESET_VALUE ((uint32_t)0x0000003DU) /*!< clear DMA channel CHXINTFS register */
-#define DMA_CHFCTL_RESET_VALUE ((uint32_t)0x00000000U) /*!< the reset value of DMA channel CHXFCTL register */
+#define DMA_CHCTL_RESET_VALUE ((uint32_t)0x00000000U) /*!< the reset value of DMA channel CHXCTL register */
+#define DMA_CHCNT_RESET_VALUE ((uint32_t)0x00000000U) /*!< the reset value of DMA channel CHXCNT register */
+#define DMA_CHPADDR_RESET_VALUE ((uint32_t)0x00000000U) /*!< the reset value of DMA channel CHXPADDR register */
+#define DMA_CHMADDR_RESET_VALUE ((uint32_t)0x00000000U) /*!< the reset value of DMA channel CHXMADDR register */
+#define DMA_CHINTF_RESET_VALUE ((uint32_t)0x0000003DU) /*!< clear DMA channel CHXINTFS register */
+#define DMA_CHFCTL_RESET_VALUE ((uint32_t)0x00000000U) /*!< the reset value of DMA channel CHXFCTL register */
+
+/* DMA_INTF register */
+/* interrupt flag bits */
+#define DMA_INT_FLAG_FEE DMA_INTF_FEEIF /*!< FIFO error and exception flag */
+#define DMA_INT_FLAG_SDE DMA_INTF_SDEIF /*!< single data mode exception flag */
+#define DMA_INT_FLAG_TAE DMA_INTF_TAEIF /*!< transfer access error flag */
+#define DMA_INT_FLAG_HTF DMA_INTF_HTFIF /*!< half transfer finish flag */
+#define DMA_INT_FLAG_FTF DMA_INTF_FTFIF /*!< full transfer finish flag */
+
+/* flag bits */
+#define DMA_FLAG_FEE DMA_INTF_FEEIF /*!< FIFO error and exception flag */
+#define DMA_FLAG_SDE DMA_INTF_SDEIF /*!< single data mode exception flag */
+#define DMA_FLAG_TAE DMA_INTF_TAEIF /*!< transfer access error flag */
+#define DMA_FLAG_HTF DMA_INTF_HTFIF /*!< half transfer finish flag */
+#define DMA_FLAG_FTF DMA_INTF_FTFIF /*!< full transfer finish flag */
+
/* function declarations */
+/* DMA deinitialization and initialization functions */
/* deinitialize DMA a channel registers */
-void dma_deinit(uint32_t dma_periph,dma_channel_enum channelx);
+void dma_deinit(uint32_t dma_periph, dma_channel_enum channelx);
+/* initialize the DMA single data mode parameters struct with the default values */
+void dma_single_data_para_struct_init(dma_single_data_parameter_struct* init_struct);
+/* initialize the DMA multi data mode parameters struct with the default values */
+void dma_multi_data_para_struct_init(dma_multi_data_parameter_struct* init_struct);
/* DMA single data mode initialize */
-void dma_single_data_mode_init(uint32_t dma_periph,dma_channel_enum channelx,dma_single_data_parameter_struct init_struct);
+void dma_single_data_mode_init(uint32_t dma_periph, dma_channel_enum channelx, dma_single_data_parameter_struct* init_struct);
/* DMA multi data mode initialize */
-void dma_multi_data_mode_init(uint32_t dma_periph,dma_channel_enum channelx,dma_multi_data_parameter_struct init_struct);
+void dma_multi_data_mode_init(uint32_t dma_periph, dma_channel_enum channelx, dma_multi_data_parameter_struct* init_struct);
+/* DMA configuration functions */
/* set DMA peripheral base address */
-void dma_periph_address_config(uint32_t dma_periph,dma_channel_enum channelx,uint32_t address);
+void dma_periph_address_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t address);
/* set DMA Memory base address */
-void dma_memory_address_config(uint32_t dma_periph,dma_channel_enum channelx,uint8_t memory_flag,uint32_t address);
+void dma_memory_address_config(uint32_t dma_periph, dma_channel_enum channelx, uint8_t memory_flag, uint32_t address);
/* set the number of remaining data to be transferred by the DMA */
-void dma_transfer_number_config(uint32_t dma_periph,dma_channel_enum channelx,uint32_t number);
+void dma_transfer_number_config(uint32_t dma_periph,dma_channel_enum channelx, uint32_t number);
/* get the number of remaining data to be transferred by the DMA */
-uint32_t dma_transfer_number_get(uint32_t dma_periph,dma_channel_enum channelx);
+uint32_t dma_transfer_number_get(uint32_t dma_periph, dma_channel_enum channelx);
/* configure priority level of DMA channel */
-void dma_priority_config(uint32_t dma_periph,dma_channel_enum channelx,uint32_t priority);
+void dma_priority_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t priority);
/* configure transfer burst beats of memory */
-void dma_memory_burst_beats_config (uint32_t dma_periph,dma_channel_enum channelx,uint32_t mbeat);
+void dma_memory_burst_beats_config (uint32_t dma_periph, dma_channel_enum channelx, uint32_t mbeat);
/* configure transfer burst beats of peripheral */
-void dma_periph_burst_beats_config (uint32_t dma_periph,dma_channel_enum channelx,uint32_t pbeat);
+void dma_periph_burst_beats_config (uint32_t dma_periph, dma_channel_enum channelx, uint32_t pbeat);
/* configure transfer data size of memory */
-void dma_memory_width_config (uint32_t dma_periph,dma_channel_enum channelx,uint32_t msize);
+void dma_memory_width_config (uint32_t dma_periph, dma_channel_enum channelx, uint32_t msize);
/* configure transfer data size of peripheral */
-void dma_periph_width_config (uint32_t dma_periph,dma_channel_enum channelx,uint32_t psize);
+void dma_periph_width_config (uint32_t dma_periph, dma_channel_enum channelx, uint32_t psize);
/* configure next address increasement algorithm of memory */
-void dma_memory_address_generation_config(uint32_t dma_periph,dma_channel_enum channelx,uint8_t generation_algorithm);
+void dma_memory_address_generation_config(uint32_t dma_periph, dma_channel_enum channelx, uint8_t generation_algorithm);
/* configure next address increasement algorithm of peripheral */
-void dma_peripheral_address_generation_config(uint32_t dma_periph,dma_channel_enum channelx,uint8_t generation_algorithm);
+void dma_peripheral_address_generation_config(uint32_t dma_periph, dma_channel_enum channelx, uint8_t generation_algorithm);
/* enable DMA circulation mode */
-void dma_circulation_enable(uint32_t dma_periph,dma_channel_enum channelx);
+void dma_circulation_enable(uint32_t dma_periph, dma_channel_enum channelx);
/* disable DMA circulation mode */
-void dma_circulation_disable(uint32_t dma_periph,dma_channel_enum channelx);
+void dma_circulation_disable(uint32_t dma_periph, dma_channel_enum channelx);
/* enable DMA channel */
-void dma_channel_enable(uint32_t dma_periph,dma_channel_enum channelx);
+void dma_channel_enable(uint32_t dma_periph, dma_channel_enum channelx);
/* disable DMA channel */
-void dma_channel_disable(uint32_t dma_periph,dma_channel_enum channelx);
+void dma_channel_disable(uint32_t dma_periph, dma_channel_enum channelx);
/* configure the direction of data transfer on the channel */
-void dma_transfer_direction_config(uint32_t dma_periph,dma_channel_enum channelx,uint8_t direction);
+void dma_transfer_direction_config(uint32_t dma_periph, dma_channel_enum channelx, uint8_t direction);
/* DMA switch buffer mode config */
-void dma_switch_buffer_mode_config(uint32_t dma_periph,dma_channel_enum channelx,uint32_t memory1_addr,uint32_t memory_select);
+void dma_switch_buffer_mode_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t memory1_addr, uint32_t memory_select);
/* DMA using memory get */
-uint32_t dma_using_memory_get(uint32_t dma_periph,dma_channel_enum channelx);
+uint32_t dma_using_memory_get(uint32_t dma_periph, dma_channel_enum channelx);
/* DMA channel peripheral select */
-void dma_channel_subperipheral_select(uint32_t dma_periph,dma_channel_enum channelx,dma_subperipheral_enum sub_periph);
+void dma_channel_subperipheral_select(uint32_t dma_periph, dma_channel_enum channelx, dma_subperipheral_enum sub_periph);
/* DMA flow controller configure */
-void dma_flow_controller_config(uint32_t dma_periph,dma_channel_enum channelx,uint32_t controller);
+void dma_flow_controller_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t controller);
/* DMA flow controller enable */
-void dma_switch_buffer_mode_enable(uint32_t dma_periph,dma_channel_enum channelx,ControlStatus newvalue);
+void dma_switch_buffer_mode_enable(uint32_t dma_periph, dma_channel_enum channelx, ControlStatus newvalue);
/* DMA FIFO status get */
-uint32_t dma_fifo_status_get(uint32_t dma_periph,dma_channel_enum channelx);
+uint32_t dma_fifo_status_get(uint32_t dma_periph, dma_channel_enum channelx);
+/* flag and interrupt functions */
/* check DMA flag is set or not */
-FlagStatus dma_flag_get(uint32_t dma_periph,dma_channel_enum channelx,uint32_t flag);
+FlagStatus dma_flag_get(uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag);
/* clear DMA a channel flag */
-void dma_flag_clear(uint32_t dma_periph,dma_channel_enum channelx,uint32_t flag);
+void dma_flag_clear(uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag);
/* check DMA flag is set or not */
-FlagStatus dma_interrupt_flag_get(uint32_t dma_periph,dma_channel_enum channelx,uint32_t interrupt);
+FlagStatus dma_interrupt_flag_get(uint32_t dma_periph, dma_channel_enum channelx, uint32_t interrupt);
/* clear DMA a channel flag */
-void dma_interrupt_flag_clear(uint32_t dma_periph,dma_channel_enum channelx,uint32_t interrupt);
+void dma_interrupt_flag_clear(uint32_t dma_periph, dma_channel_enum channelx, uint32_t interrupt);
/* enable DMA interrupt */
-void dma_interrupt_enable(uint32_t dma_periph,dma_channel_enum channelx,uint32_t source);
+void dma_interrupt_enable(uint32_t dma_periph, dma_channel_enum channelx, uint32_t source);
/* disable DMA interrupt */
-void dma_interrupt_disable(uint32_t dma_periph,dma_channel_enum channelx,uint32_t source);
+void dma_interrupt_disable(uint32_t dma_periph, dma_channel_enum channelx, uint32_t source);
#endif /* GD32F4XX_DMA_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_enet.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_enet.h
index 7a0de03860..1dfc880d37 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_enet.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_enet.h
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_enet.h
- \brief definitions for the ENET
+ \file gd32f4xx_enet.h
+ \brief definitions for the ENET
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.1, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#ifndef GD32F4XX_ENET_H
@@ -36,7 +61,7 @@
#define ENET_TXBUF_SIZE ENET_MAX_FRAME_SIZE /*!< ethernet transmit buffer size */
#endif
-//#define SELECT_DESCRIPTORS_ENHANCED_MODE
+//#define SELECT_DESCRIPTORS_ENHANCED_MODE
//#define USE_DELAY
@@ -47,7 +72,7 @@
#define PHY_ADDRESS ((uint16_t)1U) /*!< phy address determined by the hardware */
-/* PHY read write timeouts */
+/* PHY read write timeouts */
#define PHY_READ_TO ((uint32_t)0x0004FFFFU) /*!< PHY read timeout */
#define PHY_WRITE_TO ((uint32_t)0x0004FFFFU) /*!< PHY write timeout */
@@ -55,7 +80,7 @@
#define PHY_RESETDELAY ((uint32_t)0x008FFFFFU) /*!< PHY reset delay */
#define PHY_CONFIGDELAY ((uint32_t)0x00FFFFFFU) /*!< PHY configure delay */
-/* PHY register address */
+/* PHY register address */
#define PHY_REG_BCR 0U /*!< tranceiver basic control register */
#define PHY_REG_BSR 1U /*!< tranceiver basic status register */
@@ -76,7 +101,7 @@
#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< valid link established */
#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< jabber condition detected */
-#if(PHY_TYPE == LAN8700)
+#if(PHY_TYPE == LAN8700)
#define PHY_SR 31U /*!< tranceiver status register */
#define PHY_SPEED_STATUS ((uint16_t)0x0004) /*!< configured information of speed: 10Mbit/s */
#define PHY_DUPLEX_STATUS ((uint16_t)0x0010) /*!< configured information of duplex: full-duplex */
@@ -93,55 +118,55 @@
#define ENET ENET_BASE
/* registers definitions */
-#define ENET_MAC_CFG REG32((ENET) + 0x00U) /*!< ethernet MAC configuration register */
-#define ENET_MAC_FRMF REG32((ENET) + 0x04U) /*!< ethernet MAC frame filter register */
-#define ENET_MAC_HLH REG32((ENET) + 0x08U) /*!< ethernet MAC hash list high register */
-#define ENET_MAC_HLL REG32((ENET) + 0x0CU) /*!< ethernet MAC hash list low register */
-#define ENET_MAC_PHY_CTL REG32((ENET) + 0x10U) /*!< ethernet MAC PHY control register */
-#define ENET_MAC_PHY_DATA REG32((ENET) + 0x14U) /*!< ethernet MAC MII data register */
-#define ENET_MAC_FCTL REG32((ENET) + 0x18U) /*!< ethernet MAC flow control register */
-#define ENET_MAC_VLT REG32((ENET) + 0x1CU) /*!< ethernet MAC VLAN tag register */
-#define ENET_MAC_RWFF REG32((ENET) + 0x28U) /*!< ethernet MAC remote wakeup frame filter register */
-#define ENET_MAC_WUM REG32((ENET) + 0x2CU) /*!< ethernet MAC wakeup management register */
-#define ENET_MAC_DBG REG32((ENET) + 0x34U) /*!< ethernet MAC debug register */
-#define ENET_MAC_INTF REG32((ENET) + 0x38U) /*!< ethernet MAC interrupt flag register */
-#define ENET_MAC_INTMSK REG32((ENET) + 0x3CU) /*!< ethernet MAC interrupt mask register */
-#define ENET_MAC_ADDR0H REG32((ENET) + 0x40U) /*!< ethernet MAC address 0 high register */
-#define ENET_MAC_ADDR0L REG32((ENET) + 0x44U) /*!< ethernet MAC address 0 low register */
-#define ENET_MAC_ADDR1H REG32((ENET) + 0x48U) /*!< ethernet MAC address 1 high register */
-#define ENET_MAC_ADDR1L REG32((ENET) + 0x4CU) /*!< ethernet MAC address 1 low register */
-#define ENET_MAC_ADDT2H REG32((ENET) + 0x50U) /*!< ethernet MAC address 2 high register */
-#define ENET_MAC_ADDR2L REG32((ENET) + 0x54U) /*!< ethernet MAC address 2 low register */
-#define ENET_MAC_ADDR3H REG32((ENET) + 0x58U) /*!< ethernet MAC address 3 high register */
-#define ENET_MAC_ADDR3L REG32((ENET) + 0x5CU) /*!< ethernet MAC address 3 low register */
+#define ENET_MAC_CFG REG32((ENET) + 0x0000U) /*!< ethernet MAC configuration register */
+#define ENET_MAC_FRMF REG32((ENET) + 0x0004U) /*!< ethernet MAC frame filter register */
+#define ENET_MAC_HLH REG32((ENET) + 0x0008U) /*!< ethernet MAC hash list high register */
+#define ENET_MAC_HLL REG32((ENET) + 0x000CU) /*!< ethernet MAC hash list low register */
+#define ENET_MAC_PHY_CTL REG32((ENET) + 0x0010U) /*!< ethernet MAC PHY control register */
+#define ENET_MAC_PHY_DATA REG32((ENET) + 0x0014U) /*!< ethernet MAC MII data register */
+#define ENET_MAC_FCTL REG32((ENET) + 0x0018U) /*!< ethernet MAC flow control register */
+#define ENET_MAC_VLT REG32((ENET) + 0x001CU) /*!< ethernet MAC VLAN tag register */
+#define ENET_MAC_RWFF REG32((ENET) + 0x0028U) /*!< ethernet MAC remote wakeup frame filter register */
+#define ENET_MAC_WUM REG32((ENET) + 0x002CU) /*!< ethernet MAC wakeup management register */
+#define ENET_MAC_DBG REG32((ENET) + 0x0034U) /*!< ethernet MAC debug register */
+#define ENET_MAC_INTF REG32((ENET) + 0x0038U) /*!< ethernet MAC interrupt flag register */
+#define ENET_MAC_INTMSK REG32((ENET) + 0x003CU) /*!< ethernet MAC interrupt mask register */
+#define ENET_MAC_ADDR0H REG32((ENET) + 0x0040U) /*!< ethernet MAC address 0 high register */
+#define ENET_MAC_ADDR0L REG32((ENET) + 0x0044U) /*!< ethernet MAC address 0 low register */
+#define ENET_MAC_ADDR1H REG32((ENET) + 0x0048U) /*!< ethernet MAC address 1 high register */
+#define ENET_MAC_ADDR1L REG32((ENET) + 0x004CU) /*!< ethernet MAC address 1 low register */
+#define ENET_MAC_ADDT2H REG32((ENET) + 0x0050U) /*!< ethernet MAC address 2 high register */
+#define ENET_MAC_ADDR2L REG32((ENET) + 0x0054U) /*!< ethernet MAC address 2 low register */
+#define ENET_MAC_ADDR3H REG32((ENET) + 0x0058U) /*!< ethernet MAC address 3 high register */
+#define ENET_MAC_ADDR3L REG32((ENET) + 0x005CU) /*!< ethernet MAC address 3 low register */
#define ENET_MAC_FCTH REG32((ENET) + 0x1080U) /*!< ethernet MAC flow control threshold register */
-#define ENET_MSC_CTL REG32((ENET) + 0x100U) /*!< ethernet MSC control register */
-#define ENET_MSC_RINTF REG32((ENET) + 0x104U) /*!< ethernet MSC receive interrupt flag register */
-#define ENET_MSC_TINTF REG32((ENET) + 0x108U) /*!< ethernet MSC transmit interrupt flag register */
-#define ENET_MSC_RINTMSK REG32((ENET) + 0x10CU) /*!< ethernet MSC receive interrupt mask register */
-#define ENET_MSC_TINTMSK REG32((ENET) + 0x110U) /*!< ethernet MSC transmit interrupt mask register */
-#define ENET_MSC_SCCNT REG32((ENET) + 0x14CU) /*!< ethernet MSC transmitted good frames after a single collision counter register */
-#define ENET_MSC_MSCCNT REG32((ENET) + 0x150U) /*!< ethernet MSC transmitted good frames after more than a single collision counter register */
-#define ENET_MSC_TGFCNT REG32((ENET) + 0x168U) /*!< ethernet MSC transmitted good frames counter register */
-#define ENET_MSC_RFCECNT REG32((ENET) + 0x194U) /*!< ethernet MSC received frames with CRC error counter register */
-#define ENET_MSC_RFAECNT REG32((ENET) + 0x198U) /*!< ethernet MSC received frames with alignment error counter register */
-#define ENET_MSC_RGUFCNT REG32((ENET) + 0x1C4U) /*!< ethernet MSC received good unicast frames counter register */
+#define ENET_MSC_CTL REG32((ENET) + 0x0100U) /*!< ethernet MSC control register */
+#define ENET_MSC_RINTF REG32((ENET) + 0x0104U) /*!< ethernet MSC receive interrupt flag register */
+#define ENET_MSC_TINTF REG32((ENET) + 0x0108U) /*!< ethernet MSC transmit interrupt flag register */
+#define ENET_MSC_RINTMSK REG32((ENET) + 0x010CU) /*!< ethernet MSC receive interrupt mask register */
+#define ENET_MSC_TINTMSK REG32((ENET) + 0x0110U) /*!< ethernet MSC transmit interrupt mask register */
+#define ENET_MSC_SCCNT REG32((ENET) + 0x014CU) /*!< ethernet MSC transmitted good frames after a single collision counter register */
+#define ENET_MSC_MSCCNT REG32((ENET) + 0x0150U) /*!< ethernet MSC transmitted good frames after more than a single collision counter register */
+#define ENET_MSC_TGFCNT REG32((ENET) + 0x0168U) /*!< ethernet MSC transmitted good frames counter register */
+#define ENET_MSC_RFCECNT REG32((ENET) + 0x0194U) /*!< ethernet MSC received frames with CRC error counter register */
+#define ENET_MSC_RFAECNT REG32((ENET) + 0x0198U) /*!< ethernet MSC received frames with alignment error counter register */
+#define ENET_MSC_RGUFCNT REG32((ENET) + 0x01C4U) /*!< ethernet MSC received good unicast frames counter register */
-#define ENET_PTP_TSCTL REG32((ENET) + 0x700U) /*!< ethernet PTP time stamp control register */
-#define ENET_PTP_SSINC REG32((ENET) + 0x704U) /*!< ethernet PTP subsecond increment register */
-#define ENET_PTP_TSH REG32((ENET) + 0x708U) /*!< ethernet PTP time stamp high register */
-#define ENET_PTP_TSL REG32((ENET) + 0x70CU) /*!< ethernet PTP time stamp low register */
-#define ENET_PTP_TSUH REG32((ENET) + 0x710U) /*!< ethernet PTP time stamp update high register */
-#define ENET_PTP_TSUL REG32((ENET) + 0x714U) /*!< ethernet PTP time stamp update low register */
-#define ENET_PTP_TSADDEND REG32((ENET) + 0x718U) /*!< ethernet PTP time stamp addend register */
-#define ENET_PTP_ETH REG32((ENET) + 0x71CU) /*!< ethernet PTP expected time high register */
-#define ENET_PTP_ETL REG32((ENET) + 0x720U) /*!< ethernet PTP expected time low register */
-#define ENET_PTP_TSF REG32((ENET) + 0x728U) /*!< ethernet PTP time stamp flag register */
-#define ENET_PTP_PPSCTL REG32((ENET) + 0x72CU) /*!< ethernet PTP PPS control register */
+#define ENET_PTP_TSCTL REG32((ENET) + 0x0700U) /*!< ethernet PTP time stamp control register */
+#define ENET_PTP_SSINC REG32((ENET) + 0x0704U) /*!< ethernet PTP subsecond increment register */
+#define ENET_PTP_TSH REG32((ENET) + 0x0708U) /*!< ethernet PTP time stamp high register */
+#define ENET_PTP_TSL REG32((ENET) + 0x070CU) /*!< ethernet PTP time stamp low register */
+#define ENET_PTP_TSUH REG32((ENET) + 0x0710U) /*!< ethernet PTP time stamp update high register */
+#define ENET_PTP_TSUL REG32((ENET) + 0x0714U) /*!< ethernet PTP time stamp update low register */
+#define ENET_PTP_TSADDEND REG32((ENET) + 0x0718U) /*!< ethernet PTP time stamp addend register */
+#define ENET_PTP_ETH REG32((ENET) + 0x071CU) /*!< ethernet PTP expected time high register */
+#define ENET_PTP_ETL REG32((ENET) + 0x0720U) /*!< ethernet PTP expected time low register */
+#define ENET_PTP_TSF REG32((ENET) + 0x0728U) /*!< ethernet PTP time stamp flag register */
+#define ENET_PTP_PPSCTL REG32((ENET) + 0x072CU) /*!< ethernet PTP PPS control register */
#define ENET_DMA_BCTL REG32((ENET) + 0x1000U) /*!< ethernet DMA bus control register */
-#define ENET_DMA_TPEN REG32((ENET) + 0x1004U) /*!< ethernet DMA transmit poll enable register */
+#define ENET_DMA_TPEN REG32((ENET) + 0x1004U) /*!< ethernet DMA transmit poll enable register */
#define ENET_DMA_RPEN REG32((ENET) + 0x1008U) /*!< ethernet DMA receive poll enable register */
#define ENET_DMA_RDTADDR REG32((ENET) + 0x100CU) /*!< ethernet DMA receive descriptor table address register */
#define ENET_DMA_TDTADDR REG32((ENET) + 0x1010U) /*!< ethernet DMA transmit descriptor table address register */
@@ -150,7 +175,7 @@
#define ENET_DMA_INTEN REG32((ENET) + 0x101CU) /*!< ethernet DMA interrupt enable register */
#define ENET_DMA_MFBOCNT REG32((ENET) + 0x1020U) /*!< ethernet DMA missed frame and buffer overflow counter register */
#define ENET_DMA_RSWDC REG32((ENET) + 0x1024U) /*!< ethernet DMA receive state watchdog counter register */
-#define ENET_DMA_CTDADDR REG32((ENET) + 0x1048U) /*!< ethernet DMA current transmit descriptor address register */
+#define ENET_DMA_CTDADDR REG32((ENET) + 0x1048U) /*!< ethernet DMA current transmit descriptor address register */
#define ENET_DMA_CRDADDR REG32((ENET) + 0x104CU) /*!< ethernet DMA current receive descriptor address register */
#define ENET_DMA_CTBADDR REG32((ENET) + 0x1050U) /*!< ethernet DMA current transmit buffer address register */
#define ENET_DMA_CRBADDR REG32((ENET) + 0x1054U) /*!< ethernet DMA current receive buffer address register */
@@ -169,7 +194,7 @@
#define ENET_MAC_CFG_ROD BIT(13) /*!< receive own disable */
#define ENET_MAC_CFG_SPD BIT(14) /*!< fast eneternet speed */
#define ENET_MAC_CFG_CSD BIT(16) /*!< carrier sense disable */
-#define ENET_MAC_CFG_IGBS BITS(17,19) /*!< inter-frame gap bit selection */
+#define ENET_MAC_CFG_IGBS BITS(17,19) /*!< inter-frame gap bit selection */
#define ENET_MAC_CFG_JBD BIT(22) /*!< jabber disable */
#define ENET_MAC_CFG_WDD BIT(23) /*!< watchdog disable */
#define ENET_MAC_CFG_TFCD BIT(25) /*!< type frame CRC dropping */
@@ -177,49 +202,49 @@
/* ENET_MAC_FRMF */
#define ENET_MAC_FRMF_PM BIT(0) /*!< promiscuous mode */
#define ENET_MAC_FRMF_HUF BIT(1) /*!< hash unicast filter */
-#define ENET_MAC_FRMF_HMF BIT(2) /*!< hash multicast filter */
-#define ENET_MAC_FRMF_DAIFLT BIT(3) /*!< destination address inverse filtering enable */
-#define ENET_MAC_FRMF_MFD BIT(4) /*!< multicast filter disable */
-#define ENET_MAC_FRMF_BFRMD BIT(5) /*!< broadcast frame disable */
-#define ENET_MAC_FRMF_PCFRM BITS(6,7) /*!< pass control frames */
-#define ENET_MAC_FRMF_SAIFLT BIT(8) /*!< source address inverse filtering */
-#define ENET_MAC_FRMF_SAFLT BIT(9) /*!< source address filter */
-#define ENET_MAC_FRMF_HPFLT BIT(10) /*!< hash or perfect filter */
-#define ENET_MAC_FRMF_FAR BIT(31) /*!< frames all receive */
-
+#define ENET_MAC_FRMF_HMF BIT(2) /*!< hash multicast filter */
+#define ENET_MAC_FRMF_DAIFLT BIT(3) /*!< destination address inverse filtering enable */
+#define ENET_MAC_FRMF_MFD BIT(4) /*!< multicast filter disable */
+#define ENET_MAC_FRMF_BFRMD BIT(5) /*!< broadcast frame disable */
+#define ENET_MAC_FRMF_PCFRM BITS(6,7) /*!< pass control frames */
+#define ENET_MAC_FRMF_SAIFLT BIT(8) /*!< source address inverse filtering */
+#define ENET_MAC_FRMF_SAFLT BIT(9) /*!< source address filter */
+#define ENET_MAC_FRMF_HPFLT BIT(10) /*!< hash or perfect filter */
+#define ENET_MAC_FRMF_FAR BIT(31) /*!< frames all receive */
+
/* ENET_MAC_HLH */
#define ENET_MAC_HLH_HLH BITS(0,31) /*!< hash list high */
-
+
/* ENET_MAC_HLL */
#define ENET_MAC_HLL_HLL BITS(0,31) /*!< hash list low */
-
+
/* ENET_MAC_PHY_CTL */
-#define ENET_MAC_PHY_CTL_PB BIT(0) /*!< PHY busy */
-#define ENET_MAC_PHY_CTL_PW BIT(1) /*!< PHY write */
-#define ENET_MAC_PHY_CTL_CLR BITS(2,4) /*!< clock range */
-#define ENET_MAC_PHY_CTL_PR BITS(6,10) /*!< PHY register */
-#define ENET_MAC_PHY_CTL_PA BITS(11,15) /*!< PHY address */
-
+#define ENET_MAC_PHY_CTL_PB BIT(0) /*!< PHY busy */
+#define ENET_MAC_PHY_CTL_PW BIT(1) /*!< PHY write */
+#define ENET_MAC_PHY_CTL_CLR BITS(2,4) /*!< clock range */
+#define ENET_MAC_PHY_CTL_PR BITS(6,10) /*!< PHY register */
+#define ENET_MAC_PHY_CTL_PA BITS(11,15) /*!< PHY address */
+
/* ENET_MAC_PHY_DATA */
#define ENET_MAC_PHY_DATA_PD BITS(0,15) /*!< PHY data */
-
+
/* ENET_MAC_FCTL */
#define ENET_MAC_FCTL_FLCBBKPA BIT(0) /*!< flow control busy(in full duplex mode)/backpressure activate(in half duplex mode) */
#define ENET_MAC_FCTL_TFCEN BIT(1) /*!< transmit flow control enable */
#define ENET_MAC_FCTL_RFCEN BIT(2) /*!< receive flow control enable */
#define ENET_MAC_FCTL_UPFDT BIT(3) /*!< unicast pause frame detect */
-#define ENET_MAC_FCTL_PLTS BITS(4,5) /*!< pause low threshold */
+#define ENET_MAC_FCTL_PLTS BITS(4,5) /*!< pause low threshold */
#define ENET_MAC_FCTL_DZQP BIT(7) /*!< disable zero-quanta pause */
#define ENET_MAC_FCTL_PTM BITS(16,31) /*!< pause time */
-
+
/* ENET_MAC_VLT */
#define ENET_MAC_VLT_VLTI BITS(0,15) /*!< VLAN tag identifier(for receive frames) */
#define ENET_MAC_VLT_VLTC BIT(16) /*!< 12-bit VLAN tag comparison */
-
+
/* ENET_MAC_RWFF */
#define ENET_MAC_RWFF_DATA BITS(0,31) /*!< wakeup frame filter register data */
-
-/* ENET_MAC_WUM */
+
+/* ENET_MAC_WUM */
#define ENET_MAC_WUM_PWD BIT(0) /*!< power down */
#define ENET_MAC_WUM_MPEN BIT(1) /*!< magic packet enable */
#define ENET_MAC_WUM_WFEN BIT(2) /*!< wakeup frame enable */
@@ -228,7 +253,7 @@
#define ENET_MAC_WUM_GU BIT(9) /*!< global unicast */
#define ENET_MAC_WUM_WUFFRPR BIT(31) /*!< wakeup frame filter register pointer reset */
-/* ENET_MAC_DBG */
+/* ENET_MAC_DBG */
#define ENET_MAC_DBG_MRNI BIT(0) /*!< MAC receive state not idle */
#define ENET_MAC_DBG_RXAFS BITS(1,2) /*!< Rx asynchronous FIFO status */
#define ENET_MAC_DBG_RXFW BIT(4) /*!< RxFIFO is writing */
@@ -242,7 +267,7 @@
#define ENET_MAC_DBG_TXFNE BIT(24) /*!< TxFIFO not empty flag */
#define ENET_MAC_DBG_TXFF BIT(25) /*!< TxFIFO full flag */
-/* ENET_MAC_INTF */
+/* ENET_MAC_INTF */
#define ENET_MAC_INTF_WUM BIT(3) /*!< WUM status */
#define ENET_MAC_INTF_MSC BIT(4) /*!< MSC status */
#define ENET_MAC_INTF_MSCR BIT(5) /*!< MSC receive status */
@@ -256,28 +281,28 @@
/* ENET_MAC_ADDR0H */
#define ENET_MAC_ADDR0H_ADDR0H BITS(0,15) /*!< MAC address0 high */
#define ENET_MAC_ADDR0H_MO BIT(31) /*!< always read 1 and must be kept */
-
+
/* ENET_MAC_ADDR0L */
#define ENET_MAC_ADDR0L_ADDR0L BITS(0,31) /*!< MAC address0 low */
-
+
/* ENET_MAC_ADDR1H */
#define ENET_MAC_ADDR1H_ADDR1H BITS(0,15) /*!< MAC address1 high */
-#define ENET_MAC_ADDR1H_MB BITS(24,29) /*!< mask byte */
+#define ENET_MAC_ADDR1H_MB BITS(24,29) /*!< mask byte */
#define ENET_MAC_ADDR1H_SAF BIT(30) /*!< source address filter */
#define ENET_MAC_ADDR1H_AFE BIT(31) /*!< address filter enable */
-
+
/* ENET_MAC_ADDR1L */
#define ENET_MAC_ADDR1L_ADDR1L BITS(0,31) /*!< MAC address1 low */
-
+
/* ENET_MAC_ADDR2H */
#define ENET_MAC_ADDR2H_ADDR2H BITS(0,15) /*!< MAC address2 high */
#define ENET_MAC_ADDR2H_MB BITS(24,29) /*!< mask byte */
#define ENET_MAC_ADDR2H_SAF BIT(30) /*!< source address filter */
#define ENET_MAC_ADDR2H_AFE BIT(31) /*!< address filter enable */
-
+
/* ENET_MAC_ADDR2L */
#define ENET_MAC_ADDR2L_ADDR2L BITS(0,31) /*!< MAC address2 low */
-
+
/* ENET_MAC_ADDR3H */
#define ENET_MAC_ADDR3H_ADDR3H BITS(0,15) /*!< MAC address3 high */
#define ENET_MAC_ADDR3H_MB BITS(24,29) /*!< mask byte */
@@ -286,11 +311,11 @@
/* ENET_MAC_ADDR3L */
#define ENET_MAC_ADDR3L_ADDR3L BITS(0,31) /*!< MAC address3 low */
-
+
/* ENET_MAC_FCTH */
#define ENET_MAC_FCTH_RFA BITS(0,2) /*!< threshold of active flow control */
#define ENET_MAC_FCTH_RFD BITS(4,6) /*!< threshold of deactive flow control */
-
+
/* ENET_MSC_CTL */
#define ENET_MSC_CTL_CTR BIT(0) /*!< counter reset */
#define ENET_MSC_CTL_CTSR BIT(1) /*!< counter stop rollover */
@@ -303,7 +328,7 @@
#define ENET_MSC_RINTF_RFCE BIT(5) /*!< received frames CRC error */
#define ENET_MSC_RINTF_RFAE BIT(6) /*!< received frames alignment error */
#define ENET_MSC_RINTF_RGUF BIT(17) /*!< receive good unicast frames */
-
+
/* ENET_MSC_TINTF */
#define ENET_MSC_TINTF_TGFSC BIT(14) /*!< transmitted good frames single collision */
#define ENET_MSC_TINTF_TGFMSC BIT(15) /*!< transmitted good frames more single collision */
@@ -313,30 +338,30 @@
#define ENET_MSC_RINTMSK_RFCEIM BIT(5) /*!< received frame CRC error interrupt mask */
#define ENET_MSC_RINTMSK_RFAEIM BIT(6) /*!< received frames alignment error interrupt mask */
#define ENET_MSC_RINTMSK_RGUFIM BIT(17) /*!< received good unicast frames interrupt mask */
-
+
/* ENET_MSC_TINTMSK */
#define ENET_MSC_TINTMSK_TGFSCIM BIT(14) /*!< transmitted good frames single collision interrupt mask */
#define ENET_MSC_TINTMSK_TGFMSCIM BIT(15) /*!< transmitted good frames more single collision interrupt mask */
#define ENET_MSC_TINTMSK_TGFIM BIT(21) /*!< transmitted good frames interrupt mask */
-
+
/* ENET_MSC_SCCNT */
#define ENET_MSC_SCCNT_SCC BITS(0,31) /*!< transmitted good frames single collision counter */
-
+
/* ENET_MSC_MSCCNT */
#define ENET_MSC_MSCCNT_MSCC BITS(0,31) /*!< transmitted good frames more one single collision counter */
-
+
/* ENET_MSC_TGFCNT */
#define ENET_MSC_TGFCNT_TGF BITS(0,31) /*!< transmitted good frames counter */
-
+
/* ENET_MSC_RFCECNT */
#define ENET_MSC_RFCECNT_RFCER BITS(0,31) /*!< received frames with CRC error counter */
-
+
/* ENET_MSC_RFAECNT */
#define ENET_MSC_RFAECNT_RFAER BITS(0,31) /*!< received frames alignment error counter */
-
+
/* ENET_MSC_RGUFCNT */
#define ENET_MSC_RGUFCNT_RGUF BITS(0,31) /*!< received good unicast frames counter */
-
+
/* ENET_PTP_TSCTL */
#define PTP_TSCTL_CKNT(regval) (BITS(16,17) & ((uint32_t)(regval) << 16)) /*!< write value to ENET_PTP_TSCTL_CKNT bit field */
@@ -356,37 +381,37 @@
#define ENET_PTP_TSCTL_MNMSEN BIT(15) /*!< received master node message snapshot enable */
#define ENET_PTP_TSCTL_CKNT BITS(16,17) /*!< clock node type for time stamp */
#define ENET_PTP_TSCTL_MAFEN BIT(18) /*!< MAC address filter enable for PTP frame */
-
+
/* ENET_PTP_SSINC */
#define ENET_PTP_SSINC_STMSSI BITS(0,7) /*!< system time subsecond increment */
-
+
/* ENET_PTP_TSH */
#define ENET_PTP_TSH_STMS BITS(0,31) /*!< system time second */
-
+
/* ENET_PTP_TSL */
#define ENET_PTP_TSL_STMSS BITS(0,30) /*!< system time subseconds */
#define ENET_PTP_TSL_STS BIT(31) /*!< system time sign */
-
+
/* ENET_PTP_TSUH */
#define ENET_PTP_TSUH_TMSUS BITS(0,31) /*!< timestamp update seconds */
-
+
/* ENET_PTP_TSUL */
#define ENET_PTP_TSUL_TMSUSS BITS(0,30) /*!< timestamp update subseconds */
#define ENET_PTP_TSUL_TMSUPNS BIT(31) /*!< timestamp update positive or negative sign */
/* ENET_PTP_TSADDAND */
#define ENET_PTP_TSADDAND_TMSA BITS(0,31) /*!< timestamp addend */
-
+
/* ENET_PTP_ETH */
#define ENET_PTP_ETH_ETSH BITS(0,31) /*!< expected time high */
-
+
/* ENET_PTP_ETL */
#define ENET_PTP_ETL_ETSL BITS(0,31) /*!< expected time low */
-
+
/* ENET_PTP_TSF */
#define ENET_PTP_TSF_TSSCO BIT(0) /*!< timestamp second counter overflow */
#define ENET_PTP_TSF_TTM BIT(1) /*!< target time match */
-
+
/* ENET_PTP_PPSCTL */
#define ENET_PTP_PPSCTL_PPSOFC BITS(0,3) /*!< PPS output frequency configure */
@@ -403,19 +428,19 @@
#define ENET_DMA_BCTL_FPBL BIT(24) /*!< four times PGBL mode */
#define ENET_DMA_BCTL_AA BIT(25) /*!< address-aligned */
#define ENET_DMA_BCTL_MB BIT(26) /*!< mixed burst */
-
+
/* ENET_DMA_TPEN */
#define ENET_DMA_TPEN_TPE BITS(0,31) /*!< transmit poll enable */
-
+
/* ENET_DMA_RPEN */
#define ENET_DMA_RPEN_RPE BITS(0,31) /*!< receive poll enable */
/* ENET_DMA_RDTADDR */
#define ENET_DMA_RDTADDR_SRT BITS(0,31) /*!< start address of receive table */
-
+
/* ENET_DMA_TDTADDR */
#define ENET_DMA_TDTADDR_STT BITS(0,31) /*!< start address of transmit table */
-
+
/* ENET_DMA_STAT */
#define ENET_DMA_STAT_TS BIT(0) /*!< transmit status */
#define ENET_DMA_STAT_TPS BIT(1) /*!< transmit process stopped status */
@@ -438,7 +463,7 @@
#define ENET_DMA_STAT_MSC BIT(27) /*!< MSC status */
#define ENET_DMA_STAT_WUM BIT(28) /*!< WUM status */
#define ENET_DMA_STAT_TST BIT(29) /*!< timestamp trigger status */
-
+
/* ENET_DMA_CTL */
#define ENET_DMA_CTL_SRE BIT(1) /*!< start/stop receive enable */
#define ENET_DMA_CTL_OSF BIT(2) /*!< operate on second frame */
@@ -452,7 +477,7 @@
#define ENET_DMA_CTL_DAFRF BIT(24) /*!< disable flushing of received frames */
#define ENET_DMA_CTL_RSFD BIT(25) /*!< receive store-and-forward */
#define ENET_DMA_CTL_DTCERFD BIT(26) /*!< dropping of TCP/IP checksum error frames disable */
-
+
/* ENET_DMA_INTEN */
#define ENET_DMA_INTEN_TIE BIT(0) /*!< transmit interrupt enable */
#define ENET_DMA_INTEN_TPSIE BIT(1) /*!< transmit process stopped interrupt enable */
@@ -469,7 +494,7 @@
#define ENET_DMA_INTEN_ERIE BIT(14) /*!< early receive interrupt enable */
#define ENET_DMA_INTEN_AIE BIT(15) /*!< abnormal interrupt summary enable */
#define ENET_DMA_INTEN_NIE BIT(16) /*!< normal interrupt summary enable */
-
+
/* ENET_DMA_MFBOCNT */
#define ENET_DMA_MFBOCNT_MSFC BITS(0,15) /*!< missed frames by the controller */
#define ENET_DMA_MFBOCNT_MSFA BITS(17,27) /*!< missed frames by the application */
@@ -482,10 +507,10 @@
/* ENET_DMA_CRDADDR */
#define ENET_DMA_CRDADDR_RDAP BITS(0,31) /*!< receive descriptor address pointer */
-
+
/* ENET_DMA_CTBADDR */
#define ENET_DMA_CTBADDR_TBAP BITS(0,31) /*!< transmit buffer address pointer */
-
+
/* ENET_DMA_CRBADDR */
#define ENET_DMA_CRBADDR_RBAP BITS(0,31) /*!< receive buffer address pointer */
@@ -545,7 +570,7 @@
#define ENET_RDES0_LCO BIT(6) /*!< late collision */
#define ENET_RDES0_IPHERR BIT(7) /*!< IP frame header error */
#define ENET_RDES0_TSV BIT(7) /*!< timestamp valid */
-#define ENET_RDES0_LDES BIT(8) /*!< last descriptor */
+#define ENET_RDES0_LDES BIT(8) /*!< last descriptor */
#define ENET_RDES0_FDES BIT(9) /*!< first descriptor */
#define ENET_RDES0_VTAG BIT(10) /*!< VLAN tag */
#define ENET_RDES0_OERR BIT(11) /*!< overflow Error */
@@ -557,7 +582,7 @@
#define ENET_RDES0_DAFF BIT(30) /*!< destination address filter fail */
#define ENET_RDES0_DAV BIT(31) /*!< descriptor available */
-/* ENET DMA Rx descriptor RDES1 */
+/* ENET DMA Rx descriptor RDES1 */
#define ENET_RDES1_RB1S BITS(0,12) /*!< receive buffer 1 size */
#define ENET_RDES1_RCHM BIT(14) /*!< receive chained mode for second address */
#define ENET_RDES1_RERM BIT(15) /*!< receive end of ring mode*/
@@ -592,53 +617,53 @@
/* constants definitions */
/* define bit position and its register index offset */
#define ENET_REGIDX_BIT(regidx, bitpos) (((uint32_t)(regidx) << 6) | (uint32_t)(bitpos))
-#define ENET_REG_VAL(periph) (REG32(ENET + ((uint32_t)(periph)>>6)))
+#define ENET_REG_VAL(periph) (REG32(ENET + ((uint32_t)(periph) >> 6)))
#define ENET_BIT_POS(val) ((uint32_t)(val) & 0x1FU)
/* ENET clock range judgement */
#define ENET_RANGE(hclk, n, m) (((hclk) >= (n))&&((hclk) < (m)))
/* define MAC address configuration and reference address */
-#define ENET_SET_MACADDRH(p) (((uint32_t)(p)[5] << 8) | (uint32_t)(p)[4])
+#define ENET_SET_MACADDRH(p) (((uint32_t)(p)[5] << 8) | (uint32_t)(p)[4])
#define ENET_SET_MACADDRL(p) (((uint32_t)(p)[3] << 24) | ((uint32_t)(p)[2] << 16) | ((uint32_t)(p)[1] << 8) | (uint32_t)(p)[0])
#define ENET_ADDRH_BASE ((ENET) + 0x40U)
#define ENET_ADDRL_BASE ((ENET) + 0x44U)
#define ENET_GET_MACADDR(offset, n) ((uint8_t)((REG32((ENET_ADDRL_BASE + (offset)) - (((n) / 4U) * 4U)) >> (8U * ((n) % 4U))) & 0xFFU))
/* register offset */
-#define MAC_FCTL_REG_OFFSET 0x0018U /*!< MAC flow control register offset */
-#define MAC_WUM_REG_OFFSET 0x002CU /*!< MAC wakeup management register offset */
-#define MAC_INTF_REG_OFFSET 0x0038U /*!< MAC interrupt flag register offset */
-#define MAC_INTMSK_REG_OFFSET 0x003CU /*!< MAC interrupt mask register offset */
+#define MAC_FCTL_REG_OFFSET ((uint16_t)0x0018U) /*!< MAC flow control register offset */
+#define MAC_WUM_REG_OFFSET ((uint16_t)0x002CU) /*!< MAC wakeup management register offset */
+#define MAC_INTF_REG_OFFSET ((uint16_t)0x0038U) /*!< MAC interrupt flag register offset */
+#define MAC_INTMSK_REG_OFFSET ((uint16_t)0x003CU) /*!< MAC interrupt mask register offset */
+
+#define MSC_RINTF_REG_OFFSET ((uint16_t)0x0104U) /*!< MSC receive interrupt flag register offset */
+#define MSC_TINTF_REG_OFFSET ((uint16_t)0x0108U) /*!< MSC transmit interrupt flag register offset */
+#define MSC_RINTMSK_REG_OFFSET ((uint16_t)0x010CU) /*!< MSC receive interrupt mask register offset */
+#define MSC_TINTMSK_REG_OFFSET ((uint16_t)0x0110U) /*!< MSC transmit interrupt mask register offset */
+#define MSC_SCCNT_REG_OFFSET ((uint16_t)0x014CU) /*!< MSC transmitted good frames after a single collision counter register offset */
+#define MSC_MSCCNT_REG_OFFSET ((uint16_t)0x0150U) /*!< MSC transmitted good frames after more than a single collision counter register offset */
+#define MSC_TGFCNT_REG_OFFSET ((uint16_t)0x0168U) /*!< MSC transmitted good frames counter register offset */
+#define MSC_RFCECNT_REG_OFFSET ((uint16_t)0x0194U) /*!< MSC received frames with CRC error counter register offset */
+#define MSC_RFAECNT_REG_OFFSET ((uint16_t)0x0198U) /*!< MSC received frames with alignment error counter register offset */
+#define MSC_RGUFCNT_REG_OFFSET ((uint16_t)0x01C4U) /*!< MSC received good unicast frames counter register offset */
-#define MSC_RINTF_REG_OFFSET 0x0104U /*!< MSC receive interrupt flag register offset */
-#define MSC_TINTF_REG_OFFSET 0x0108U /*!< MSC transmit interrupt flag register offset */
-#define MSC_RINTMSK_REG_OFFSET 0x010CU /*!< MSC receive interrupt mask register offset */
-#define MSC_TINTMSK_REG_OFFSET 0x0110U /*!< MSC transmit interrupt mask register offset */
-#define MSC_SCCNT_REG_OFFSET 0x014CU /*!< MSC transmitted good frames after a single collision counter register offset */
-#define MSC_MSCCNT_REG_OFFSET 0x0150U /*!< MSC transmitted good frames after more than a single collision counter register offset */
-#define MSC_TGFCNT_REG_OFFSET 0x0168U /*!< MSC transmitted good frames counter register offset */
-#define MSC_RFCECNT_REG_OFFSET 0x0194U /*!< MSC received frames with CRC error counter register offset */
-#define MSC_RFAECNT_REG_OFFSET 0x0198U /*!< MSC received frames with alignment error counter register offset */
-#define MSC_RGUFCNT_REG_OFFSET 0x01C4U /*!< MSC received good unicast frames counter register offset */
-
-#define PTP_TSF_REG_OFFSET 0x0728U /*!< PTP time stamp flag register offset */
+#define PTP_TSF_REG_OFFSET ((uint16_t)0x0728U) /*!< PTP time stamp flag register offset */
-#define DMA_STAT_REG_OFFSET 0x1014U /*!< DMA status register offset */
-#define DMA_INTEN_REG_OFFSET 0x101CU /*!< DMA interrupt enable register offset */
-#define DMA_TDTADDR_REG_OFFSET 0x1010U /*!< DMA transmit descriptor table address register offset */
-#define DMA_CTDADDR_REG_OFFSET 0x1048U /*!< DMA current transmit descriptor address register */
-#define DMA_CTBADDR_REG_OFFSET 0x1050U /*!< DMA current transmit buffer address register */
-#define DMA_RDTADDR_REG_OFFSET 0x100CU /*!< DMA receive descriptor table address register */
-#define DMA_CRDADDR_REG_OFFSET 0x104CU /*!< DMA current receive descriptor address register */
-#define DMA_CRBADDR_REG_OFFSET 0x1054U /*!< DMA current receive buffer address register */
+#define DMA_STAT_REG_OFFSET ((uint16_t)0x1014U) /*!< DMA status register offset */
+#define DMA_INTEN_REG_OFFSET ((uint16_t)0x101CU) /*!< DMA interrupt enable register offset */
+#define DMA_TDTADDR_REG_OFFSET ((uint16_t)0x1010U) /*!< DMA transmit descriptor table address register offset */
+#define DMA_CTDADDR_REG_OFFSET ((uint16_t)0x1048U) /*!< DMA current transmit descriptor address register */
+#define DMA_CTBADDR_REG_OFFSET ((uint16_t)0x1050U) /*!< DMA current transmit buffer address register */
+#define DMA_RDTADDR_REG_OFFSET ((uint16_t)0x100CU) /*!< DMA receive descriptor table address register */
+#define DMA_CRDADDR_REG_OFFSET ((uint16_t)0x104CU) /*!< DMA current receive descriptor address register */
+#define DMA_CRBADDR_REG_OFFSET ((uint16_t)0x1054U) /*!< DMA current receive buffer address register */
/* ENET status flag get */
typedef enum
{
/* ENET_MAC_WUM register */
ENET_MAC_FLAG_MPKR = ENET_REGIDX_BIT(MAC_WUM_REG_OFFSET, 5U), /*!< magic packet received flag */
- ENET_MAC_FLAG_WUFR = ENET_REGIDX_BIT(MAC_WUM_REG_OFFSET, 6U), /*!< wakeup frame received flag */
+ ENET_MAC_FLAG_WUFR = ENET_REGIDX_BIT(MAC_WUM_REG_OFFSET, 6U), /*!< wakeup frame received flag */
/* ENET_MAC_FCTL register */
ENET_MAC_FLAG_FLOWCONTROL = ENET_REGIDX_BIT(MAC_FCTL_REG_OFFSET, 0U), /*!< flow control status flag */
/* ENET_MAC_INTF register */
@@ -648,13 +673,13 @@ typedef enum
ENET_MAC_FLAG_MSCT = ENET_REGIDX_BIT(MAC_INTF_REG_OFFSET, 6U), /*!< MSC transmit status flag */
ENET_MAC_FLAG_TMST = ENET_REGIDX_BIT(MAC_INTF_REG_OFFSET, 9U), /*!< timestamp trigger status flag */
/* ENET_PTP_TSF register */
- ENET_PTP_FLAG_TSSCO = ENET_REGIDX_BIT(PTP_TSF_REG_OFFSET, 0U), /*!< timestamp second counter overflow flag */
+ ENET_PTP_FLAG_TSSCO = ENET_REGIDX_BIT(PTP_TSF_REG_OFFSET, 0U), /*!< timestamp second counter overflow flag */
ENET_PTP_FLAG_TTM = ENET_REGIDX_BIT(PTP_TSF_REG_OFFSET, 1U), /*!< target time match flag */
/* ENET_MSC_RINTF register */
ENET_MSC_FLAG_RFCE = ENET_REGIDX_BIT(MSC_RINTF_REG_OFFSET, 5U), /*!< received frames CRC error flag */
ENET_MSC_FLAG_RFAE = ENET_REGIDX_BIT(MSC_RINTF_REG_OFFSET, 6U), /*!< received frames alignment error flag */
ENET_MSC_FLAG_RGUF = ENET_REGIDX_BIT(MSC_RINTF_REG_OFFSET, 17U), /*!< received good unicast frames flag */
- /* ENET_MSC_TINTF register */
+ /* ENET_MSC_TINTF register */
ENET_MSC_FLAG_TGFSC = ENET_REGIDX_BIT(MSC_TINTF_REG_OFFSET, 14U), /*!< transmitted good frames single collision flag */
ENET_MSC_FLAG_TGFMSC = ENET_REGIDX_BIT(MSC_TINTF_REG_OFFSET, 15U), /*!< transmitted good frames more single collision flag */
ENET_MSC_FLAG_TGF = ENET_REGIDX_BIT(MSC_TINTF_REG_OFFSET, 21U), /*!< transmitted good frames flag */
@@ -679,7 +704,7 @@ typedef enum
ENET_DMA_FLAG_EB_ACCESS_ERROR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 25U), /*!< error during data buffer/descriptor access flag */
ENET_DMA_FLAG_MSC = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 27U), /*!< MSC status flag */
ENET_DMA_FLAG_WUM = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 28U), /*!< WUM status flag */
- ENET_DMA_FLAG_TST = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 29U), /*!< timestamp trigger status flag */
+ ENET_DMA_FLAG_TST = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 29U), /*!< timestamp trigger status flag */
}enet_flag_enum;
/* ENET stutus flag clear */
@@ -700,7 +725,7 @@ typedef enum
ENET_DMA_FLAG_FBE_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 13U), /*!< fatal bus error status flag */
ENET_DMA_FLAG_ER_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 14U), /*!< early receive status flag */
ENET_DMA_FLAG_AI_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 15U), /*!< abnormal interrupt summary flag */
- ENET_DMA_FLAG_NI_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 16U), /*!< normal interrupt summary flag */
+ ENET_DMA_FLAG_NI_CLR = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 16U), /*!< normal interrupt summary flag */
}enet_flag_clear_enum;
/* ENET interrupt enable/disable */
@@ -709,15 +734,15 @@ typedef enum
/* ENET_MAC_INTMSK register */
ENET_MAC_INT_WUMIM = ENET_REGIDX_BIT(MAC_INTMSK_REG_OFFSET, 3U), /*!< WUM interrupt mask */
ENET_MAC_INT_TMSTIM = ENET_REGIDX_BIT(MAC_INTMSK_REG_OFFSET, 9U), /*!< timestamp trigger interrupt mask */
- /* ENET_MSC_RINTMSK register */
+ /* ENET_MSC_RINTMSK register */
ENET_MSC_INT_RFCEIM = ENET_REGIDX_BIT(MSC_RINTMSK_REG_OFFSET, 5U), /*!< received frame CRC error interrupt mask */
ENET_MSC_INT_RFAEIM = ENET_REGIDX_BIT(MSC_RINTMSK_REG_OFFSET, 6U), /*!< received frames alignment error interrupt mask */
ENET_MSC_INT_RGUFIM = ENET_REGIDX_BIT(MSC_RINTMSK_REG_OFFSET, 17U), /*!< received good unicast frames interrupt mask */
- /* ENET_MSC_TINTMSK register */
+ /* ENET_MSC_TINTMSK register */
ENET_MSC_INT_TGFSCIM = ENET_REGIDX_BIT(MSC_TINTMSK_REG_OFFSET, 14U), /*!< transmitted good frames single collision interrupt mask */
ENET_MSC_INT_TGFMSCIM = ENET_REGIDX_BIT(MSC_TINTMSK_REG_OFFSET, 15U), /*!< transmitted good frames more single collision interrupt mask */
ENET_MSC_INT_TGFIM = ENET_REGIDX_BIT(MSC_TINTMSK_REG_OFFSET, 21U), /*!< transmitted good frames interrupt mask */
- /* ENET_DMA_INTEN register */
+ /* ENET_DMA_INTEN register */
ENET_DMA_INT_TIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 0U), /*!< transmit interrupt enable */
ENET_DMA_INT_TPSIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 1U), /*!< transmit process stopped interrupt enable */
ENET_DMA_INT_TBUIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 2U), /*!< transmit buffer unavailable interrupt enable */
@@ -734,7 +759,7 @@ typedef enum
ENET_DMA_INT_AIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 15U), /*!< abnormal interrupt summary enable */
ENET_DMA_INT_NIE = ENET_REGIDX_BIT(DMA_INTEN_REG_OFFSET, 16U), /*!< normal interrupt summary enable */
}enet_int_enum;
-
+
/* ENET interrupt flag get */
typedef enum
{
@@ -770,7 +795,7 @@ typedef enum
ENET_DMA_INT_FLAG_NI = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 16U), /*!< normal interrupt summary flag */
ENET_DMA_INT_FLAG_MSC = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 27U), /*!< MSC status flag */
ENET_DMA_INT_FLAG_WUM = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 28U), /*!< WUM status flag */
- ENET_DMA_INT_FLAG_TST = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 29U), /*!< timestamp trigger status flag */
+ ENET_DMA_INT_FLAG_TST = ENET_REGIDX_BIT(DMA_STAT_REG_OFFSET, 29U), /*!< timestamp trigger status flag */
}enet_int_flag_enum;
/* ENET interrupt flag clear */
@@ -814,7 +839,7 @@ typedef enum
ENET_MSC_RX_RFCECNT = MSC_RFCECNT_REG_OFFSET, /*!< MSC received frames with CRC error counter */
ENET_MSC_RX_RFAECNT = MSC_RFAECNT_REG_OFFSET, /*!< MSC received frames with alignment error counter */
ENET_MSC_RX_RGUFCNT = MSC_RGUFCNT_REG_OFFSET /*!< MSC received good unicast frames counter */
-}enet_msc_counter_enum;
+}enet_msc_counter_enum;
/* function option, used for ENET initialization */
typedef enum
@@ -838,7 +863,7 @@ typedef enum
/* phy mode and mac loopback configurations */
typedef enum
{
- ENET_AUTO_NEGOTIATION = 0x01u, /*!< PHY auto negotiation */
+ ENET_AUTO_NEGOTIATION = 0x01U, /*!< PHY auto negotiation */
ENET_100M_FULLDUPLEX = (ENET_MAC_CFG_SPD | ENET_MAC_CFG_DPM), /*!< 100Mbit/s, full-duplex */
ENET_100M_HALFDUPLEX = ENET_MAC_CFG_SPD , /*!< 100Mbit/s, half-duplex */
ENET_10M_FULLDUPLEX = ENET_MAC_CFG_DPM, /*!< 10Mbit/s, full-duplex */
@@ -867,10 +892,10 @@ typedef enum
/* register group value get */
typedef enum
{
- ALL_MAC_REG = 0, /*!< MAC register group */
- ALL_MSC_REG = 22, /*!< MSC register group */
- ALL_PTP_REG = 33, /*!< PTP register group */
- ALL_DMA_REG = 44, /*!< DMA register group */
+ ALL_MAC_REG = 0U, /*!< MAC register group */
+ ALL_MSC_REG = 22U, /*!< MSC register group */
+ ALL_PTP_REG = 33U, /*!< PTP register group */
+ ALL_DMA_REG = 44U, /*!< DMA register group */
}enet_registers_type_enum;
/* dma direction select */
@@ -894,7 +919,7 @@ typedef enum
ENET_REG_WRITE /*!< write register */
}enet_regdirection_enum;
-/* ENET MAC addresses */
+/* ENET MAC addresses */
typedef enum
{
ENET_MAC_ADDRESS0 = ((uint32_t)0x00000000), /*!< MAC address0 */
@@ -928,7 +953,7 @@ typedef enum{
ENET_CKNT_END_TO_END = PTP_TSCTL_CKNT(2), /*!< type of end-to-end transparent clock node type for timestamp */
ENET_CKNT_PEER_TO_PEER = PTP_TSCTL_CKNT(3), /*!< type of peer-to-peer transparent clock node type for timestamp */
ENET_PTP_SYSTIME_INIT = ENET_PTP_TSCTL_TMSSTI, /*!< timestamp initialize */
- ENET_PTP_SYSTIME_UPDATE = ENET_PTP_TSCTL_TMSSTU, /*!< timestamp update */
+ ENET_PTP_SYSTIME_UPDATE = ENET_PTP_TSCTL_TMSSTU, /*!< timestamp update */
ENET_PTP_ADDEND_UPDATE = ENET_PTP_TSCTL_TMSARU, /*!< addend register update */
ENET_PTP_FINEMODE = (int32_t)(ENET_PTP_TSCTL_TMSFCU| BIT(31)), /*!< the system timestamp uses the fine method for updating */
ENET_PTP_COARSEMODE = ENET_PTP_TSCTL_TMSFCU, /*!< the system timestamp uses the coarse method for updating */
@@ -946,24 +971,24 @@ typedef enum{
typedef struct
{
uint32_t option_enable; /*!< select which function to configure */
- uint32_t forward_frame; /*!< frame forward related parameters */
+ uint32_t forward_frame; /*!< frame forward related parameters */
uint32_t dmabus_mode; /*!< DMA bus mode related parameters */
uint32_t dma_maxburst; /*!< DMA max burst related parameters */
uint32_t dma_arbitration; /*!< DMA Tx and Rx arbitration related parameters */
uint32_t store_forward_mode; /*!< store forward mode related parameters */
uint32_t dma_function; /*!< DMA control related parameters */
- uint32_t vlan_config; /*!< VLAN tag related parameters */
+ uint32_t vlan_config; /*!< VLAN tag related parameters */
uint32_t flow_control; /*!< flow control related parameters */
uint32_t hashtable_high; /*!< hash list high 32-bit related parameters */
uint32_t hashtable_low; /*!< hash list low 32-bit related parameters */
uint32_t framesfilter_mode; /*!< frame filter control related parameters */
- uint32_t halfduplex_param; /*!< halfduplex related parameters */
+ uint32_t halfduplex_param; /*!< halfduplex related parameters */
uint32_t timer_config; /*!< frame timer related parameters */
uint32_t interframegap; /*!< inter frame gap related parameters */
}enet_initpara_struct;
-/* structure for ENET DMA desciptors */
-typedef struct
+/* structure for ENET DMA desciptors */
+typedef struct
{
uint32_t status; /*!< status */
uint32_t control_buffer_size; /*!< control and buffer1, buffer2 lengths */
@@ -974,12 +999,12 @@ typedef struct
uint32_t extended_status; /*!< extended status */
uint32_t reserved; /*!< reserved */
uint32_t timestamp_low; /*!< timestamp low */
- uint32_t timestamp_high; /*!< timestamp high */
-#endif /* SELECT_DESCRIPTORS_ENHANCED_MODE */
-
+ uint32_t timestamp_high; /*!< timestamp high */
+#endif /* SELECT_DESCRIPTORS_ENHANCED_MODE */
+
} enet_descriptors_struct;
-/* structure of PTP system time */
+/* structure of PTP system time */
typedef struct
{
uint32_t second; /*!< second of system time */
@@ -992,17 +1017,17 @@ typedef struct
#define ENET_BACKOFFLIMIT_10 MAC_CFG_BOL(0) /*!< min (n, 10) */
#define ENET_BACKOFFLIMIT_8 MAC_CFG_BOL(1) /*!< min (n, 8) */
#define ENET_BACKOFFLIMIT_4 MAC_CFG_BOL(2) /*!< min (n, 4) */
-#define ENET_BACKOFFLIMIT_1 MAC_CFG_BOL(3) /*!< min (n, 1) */
+#define ENET_BACKOFFLIMIT_1 MAC_CFG_BOL(3) /*!< min (n, 1) */
#define MAC_CFG_IGBS(regval) (BITS(17,19) & ((uint32_t)(regval) << 17)) /*!< write value to ENET_MAC_CFG_IGBS bit field */
-#define ENET_INTERFRAMEGAP_96BIT MAC_CFG_IGBS(0) /*!< minimum 96 bit times */
+#define ENET_INTERFRAMEGAP_96BIT MAC_CFG_IGBS(0) /*!< minimum 96 bit times */
#define ENET_INTERFRAMEGAP_88BIT MAC_CFG_IGBS(1) /*!< minimum 88 bit times */
#define ENET_INTERFRAMEGAP_80BIT MAC_CFG_IGBS(2) /*!< minimum 80 bit times */
#define ENET_INTERFRAMEGAP_72BIT MAC_CFG_IGBS(3) /*!< minimum 72 bit times */
-#define ENET_INTERFRAMEGAP_64BIT MAC_CFG_IGBS(4) /*!< minimum 64 bit times */
+#define ENET_INTERFRAMEGAP_64BIT MAC_CFG_IGBS(4) /*!< minimum 64 bit times */
#define ENET_INTERFRAMEGAP_56BIT MAC_CFG_IGBS(5) /*!< minimum 56 bit times */
#define ENET_INTERFRAMEGAP_48BIT MAC_CFG_IGBS(6) /*!< minimum 48 bit times */
-#define ENET_INTERFRAMEGAP_40BIT MAC_CFG_IGBS(7) /*!< minimum 40 bit times */
+#define ENET_INTERFRAMEGAP_40BIT MAC_CFG_IGBS(7) /*!< minimum 40 bit times */
#define ENET_TYPEFRAME_CRC_DROP_ENABLE ENET_MAC_CFG_TFCD /*!< FCS field(last 4 bytes) of frame will be dropped before forwarding */
#define ENET_TYPEFRAME_CRC_DROP_DISABLE ((uint32_t)0x00000000U) /*!< FCS field(last 4 bytes) of frame will not be dropped before forwarding */
@@ -1010,13 +1035,13 @@ typedef struct
#define ENET_WATCHDOG_ENABLE ((uint32_t)0x00000000U) /*!< the MAC allows no more than 2048 bytes of the frame being received */
#define ENET_WATCHDOG_DISABLE ENET_MAC_CFG_WDD /*!< the MAC disables the watchdog timer on the receiver, and can receive frames of up to 16384 bytes */
-
+
#define ENET_JABBER_ENABLE ((uint32_t)0x00000000U) /*!< the maximum transmission byte is 2048 */
#define ENET_JABBER_DISABLE ENET_MAC_CFG_JBD /*!< the maximum transmission byte can be 16384 */
#define ENET_CARRIERSENSE_ENABLE ((uint32_t)0x00000000U) /*!< the MAC transmitter generates carrier sense error and aborts the transmission */
#define ENET_CARRIERSENSE_DISABLE ENET_MAC_CFG_CSD /*!< the MAC transmitter ignores the MII CRS signal during frame transmission in half-duplex mode */
-
+
#define ENET_SPEEDMODE_10M ((uint32_t)0x00000000U) /*!< 10 Mbit/s */
#define ENET_SPEEDMODE_100M ENET_MAC_CFG_SPD /*!< 100 Mbit/s */
@@ -1048,10 +1073,10 @@ typedef struct
#define ENET_PCFRM_PREVENT_PAUSEFRAME MAC_FRMF_PCFRM(1) /*!< MAC only forwards all other control frames except pause control frame */
#define ENET_PCFRM_FORWARD_ALL MAC_FRMF_PCFRM(2) /*!< MAC forwards all control frames to application even if they fail the address filter */
#define ENET_PCFRM_FORWARD_FILTERED MAC_FRMF_PCFRM(3) /*!< MAC forwards control frames that only pass the address filter */
-
+
#define ENET_RX_FILTER_DISABLE ENET_MAC_FRMF_FAR /*!< all received frame are forwarded to application */
#define ENET_RX_FILTER_ENABLE ((uint32_t)0x00000000U) /*!< only the frame passed the filter can be forwarded to application */
-
+
#define ENET_SRC_FILTER_NORMAL_ENABLE ENET_MAC_FRMF_SAFLT /*!< filter source address */
#define ENET_SRC_FILTER_INVERSE_ENABLE (ENET_MAC_FRMF_SAFLT | ENET_MAC_FRMF_SAIFLT) /*!< inverse source address filtering result */
#define ENET_SRC_FILTER_DISABLE ((uint32_t)0x00000000U) /*!< source address function in filter disable */
@@ -1060,14 +1085,14 @@ typedef struct
#define ENET_BROADCASTFRAMES_ENABLE ((uint32_t)0x00000000U) /*!< the address filters pass all received broadcast frames */
#define ENET_BROADCASTFRAMES_DISABLE ENET_MAC_FRMF_BFRMD /*!< the address filters filter all incoming broadcast frames */
-
+
#define ENET_DEST_FILTER_INVERSE_ENABLE ENET_MAC_FRMF_DAIFLT /*!< inverse DA filtering result */
#define ENET_DEST_FILTER_INVERSE_DISABLE ((uint32_t)0x00000000U) /*!< not inverse DA filtering result */
#define ENET_DEST_FILTER_INVERSE ENET_MAC_FRMF_DAIFLT /*!< inverse DA filtering result function */
#define ENET_PROMISCUOUS_ENABLE ENET_MAC_FRMF_PM /*!< promiscuous mode enabled */
#define ENET_PROMISCUOUS_DISABLE ((uint32_t)0x00000000U) /*!< promiscuous mode disabled */
-
+
#define ENET_MULTICAST_FILTER_HASH_OR_PERFECT (ENET_MAC_FRMF_HMF | ENET_MAC_FRMF_HPFLT) /*!< pass multicast frames that match either the perfect or the hash filtering */
#define ENET_MULTICAST_FILTER_HASH ENET_MAC_FRMF_HMF /*!< pass multicast frames that match the hash filtering */
#define ENET_MULTICAST_FILTER_PERFECT ((uint32_t)0x00000000U) /*!< pass multicast frames that match the perfect filtering */
@@ -1101,7 +1126,7 @@ typedef struct
#define ENET_PAUSETIME_MINUS4 MAC_FCTL_PLTS(0) /*!< pause time minus 4 slot times */
#define ENET_PAUSETIME_MINUS28 MAC_FCTL_PLTS(1) /*!< pause time minus 28 slot times */
#define ENET_PAUSETIME_MINUS144 MAC_FCTL_PLTS(2) /*!< pause time minus 144 slot times */
-#define ENET_PAUSETIME_MINUS256 MAC_FCTL_PLTS(3) /*!< pause time minus 256 slot times */
+#define ENET_PAUSETIME_MINUS256 MAC_FCTL_PLTS(3) /*!< pause time minus 256 slot times */
#define ENET_ZERO_QUANTA_PAUSE_ENABLE ((uint32_t)0x00000000U) /*!< enable the automatic zero-quanta generation function */
#define ENET_ZERO_QUANTA_PAUSE_DISABLE ENET_MAC_FCTL_DZQP /*!< disable the automatic zero-quanta generation function */
@@ -1109,7 +1134,7 @@ typedef struct
#define ENET_MAC0_AND_UNIQUE_ADDRESS_PAUSEDETECT ENET_MAC_FCTL_UPFDT /*!< besides the unique multicast address, MAC also use the MAC0 address to detect pause frame */
#define ENET_UNIQUE_PAUSEDETECT ((uint32_t)0x00000000U) /*!< only the unique multicast address for pause frame which is specified in IEEE802.3 can be detected */
-
+
#define ENET_RX_FLOWCONTROL_ENABLE ENET_MAC_FCTL_RFCEN /*!< enable decoding function for the received pause frame and process it */
#define ENET_RX_FLOWCONTROL_DISABLE ((uint32_t)0x00000000U) /*!< decode function for pause frame is disabled */
#define ENET_RX_FLOWCONTROL ENET_MAC_FCTL_RFCEN /*!< decoding function for the received pause frame and process it */
@@ -1121,33 +1146,34 @@ typedef struct
#define ENET_BACK_PRESSURE_ENABLE ENET_MAC_FCTL_FLCBBKPA /*!< enable the back pressure operation in the MAC */
#define ENET_BACK_PRESSURE_DISABLE ((uint32_t)0x00000000U) /*!< disable the back pressure operation in the MAC */
#define ENET_BACK_PRESSURE ENET_MAC_FCTL_FLCBBKPA /*!< the back pressure operation in the MAC */
-
+
#define MAC_FCTL_PTM(regval) (BITS(16,31) & ((uint32_t)(regval) << 16)) /*!< write value to ENET_MAC_FCTL_PTM bit field */
/* mac_vlt register value */
#define MAC_VLT_VLTI(regval) (BITS(0,15) & ((uint32_t)(regval) << 0)) /*!< write value to ENET_MAC_VLT_VLTI bit field */
-
+
#define ENET_VLANTAGCOMPARISON_12BIT ENET_MAC_VLT_VLTC /*!< only low 12 bits of the VLAN tag are used for comparison */
#define ENET_VLANTAGCOMPARISON_16BIT ((uint32_t)0x00000000U) /*!< all 16 bits of the VLAN tag are used for comparison */
-/* mac_wum register value */
+/* mac_wum register value */
#define ENET_WUM_FLAG_WUFFRPR ENET_MAC_WUM_WUFFRPR /*!< wakeup frame filter register poniter reset */
#define ENET_WUM_FLAG_WUFR ENET_MAC_WUM_WUFR /*!< wakeup frame received */
#define ENET_WUM_FLAG_MPKR ENET_MAC_WUM_MPKR /*!< magic packet received */
-#define ENET_WUM_POWER_DOWN ENET_MAC_WUM_PWD /*!< power down mode */
-#define ENET_WUM_MAGIC_PACKET_FRAME ENET_MAC_WUM_MPEN /*!< enable a wakeup event due to magic packet reception */
-#define ENET_WUM_WAKE_UP_FRAME ENET_MAC_WUM_WFEN /*!< enable a wakeup event due to wakeup frame reception */
+#define ENET_WUM_POWER_DOWN ENET_MAC_WUM_PWD /*!< power down mode */
+#define ENET_WUM_MAGIC_PACKET_FRAME ENET_MAC_WUM_MPEN /*!< enable a wakeup event due to magic packet reception */
+#define ENET_WUM_WAKE_UP_FRAME ENET_MAC_WUM_WFEN /*!< enable a wakeup event due to wakeup frame reception */
#define ENET_WUM_GLOBAL_UNICAST ENET_MAC_WUM_GU /*!< any received unicast frame passed filter is considered to be a wakeup frame */
+
/* mac_dbg register value */
#define ENET_MAC_RECEIVER_NOT_IDLE ENET_MAC_DBG_MRNI /*!< MAC receiver is not in idle state */
#define ENET_RX_ASYNCHRONOUS_FIFO_STATE ENET_MAC_DBG_RXAFS /*!< Rx asynchronous FIFO status */
-#define ENET_RXFIFO_NOT_WRITING ENET_MAC_DBG_RXFW /*!< RxFIFO is not doing write operation */
+#define ENET_RXFIFO_WRITING ENET_MAC_DBG_RXFW /*!< RxFIFO is doing write operation */
#define ENET_RXFIFO_READ_STATUS ENET_MAC_DBG_RXFRS /*!< RxFIFO read operation status */
#define ENET_RXFIFO_STATE ENET_MAC_DBG_RXFS /*!< RxFIFO state */
#define ENET_MAC_TRANSMITTER_NOT_IDLE ENET_MAC_DBG_MTNI /*!< MAC transmitter is not in idle state */
#define ENET_MAC_TRANSMITTER_STATUS ENET_MAC_DBG_SOMT /*!< status of MAC transmitter */
#define ENET_PAUSE_CONDITION_STATUS ENET_MAC_DBG_PCS /*!< pause condition status */
#define ENET_TXFIFO_READ_STATUS ENET_MAC_DBG_TXFRS /*!< TxFIFO read operation status */
-#define ENET_TXFIFO_NOT_WRITING ENET_MAC_DBG_TXFW /*!< TxFIFO is not doing write operation */
+#define ENET_TXFIFO_WRITING ENET_MAC_DBG_TXFW /*!< TxFIFO is doing write operation */
#define ENET_TXFIFO_NOT_EMPTY ENET_MAC_DBG_TXFNE /*!< TxFIFO is not empty */
#define ENET_TXFIFO_FULL ENET_MAC_DBG_TXFF /*!< TxFIFO is full */
@@ -1176,7 +1202,7 @@ typedef struct
#define ENET_ADDRESS_FILTER_SA BIT(30) /*!< use MAC address[47:0] is to compare with the SA fields of the received frame */
#define ENET_ADDRESS_FILTER_DA ((uint32_t)0x00000000) /*!< use MAC address[47:0] is to compare with the DA fields of the received frame */
-
+
/* mac_fcth register value */
#define MAC_FCTH_RFA(regval) ((BITS(0,2) & ((uint32_t)(regval) << 0))<<8) /*!< write value to ENET_MAC_FCTH_RFA bit field */
#define ENET_ACTIVE_THRESHOLD_256BYTES MAC_FCTH_RFA(0) /*!< threshold level is 256 bytes */
@@ -1215,7 +1241,7 @@ typedef struct
/* ptp_tsl register value */
#define GET_PTP_TSL_STMSS(regval) GET_BITS((uint32_t)(regval),0,30) /*!< get value of ENET_PTP_TSL_STMSS bit field */
-
+
#define ENET_PTP_TIME_POSITIVE ((uint32_t)0x00000000) /*!< time value is positive */
#define ENET_PTP_TIME_NEGATIVE ENET_PTP_TSL_STS /*!< time value is negative */
@@ -1259,7 +1285,7 @@ typedef struct
#define ENET_PGBL_4BEAT DMA_BCTL_PGBL(4) /*!< maximum number of beats is 4 */
#define ENET_PGBL_8BEAT DMA_BCTL_PGBL(8) /*!< maximum number of beats is 8 */
#define ENET_PGBL_16BEAT DMA_BCTL_PGBL(16) /*!< maximum number of beats is 16 */
-#define ENET_PGBL_32BEAT DMA_BCTL_PGBL(32) /*!< maximum number of beats is 32 */
+#define ENET_PGBL_32BEAT DMA_BCTL_PGBL(32) /*!< maximum number of beats is 32 */
#define ENET_PGBL_4xPGBL_4BEAT (DMA_BCTL_PGBL(1)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats is 4 */
#define ENET_PGBL_4xPGBL_8BEAT (DMA_BCTL_PGBL(2)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats is 8 */
#define ENET_PGBL_4xPGBL_16BEAT (DMA_BCTL_PGBL(4)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats is 16 */
@@ -1271,7 +1297,7 @@ typedef struct
#define ENET_ARBITRATION_RXTX_1_1 DMA_BCTL_RTPR(0) /*!< receive and transmit priority ratio is 1:1*/
#define ENET_ARBITRATION_RXTX_2_1 DMA_BCTL_RTPR(1) /*!< receive and transmit priority ratio is 2:1*/
#define ENET_ARBITRATION_RXTX_3_1 DMA_BCTL_RTPR(2) /*!< receive and transmit priority ratio is 3:1 */
-#define ENET_ARBITRATION_RXTX_4_1 DMA_BCTL_RTPR(3) /*!< receive and transmit priority ratio is 4:1 */
+#define ENET_ARBITRATION_RXTX_4_1 DMA_BCTL_RTPR(3) /*!< receive and transmit priority ratio is 4:1 */
#define ENET_ARBITRATION_RXPRIORTX ENET_DMA_BCTL_DAB /*!< RxDMA has higher priority than TxDMA */
#define ENET_FIXED_BURST_ENABLE ENET_DMA_BCTL_FB /*!< AHB can only use SINGLE/INCR4/INCR8/INCR16 during start of normal burst transfers */
@@ -1283,13 +1309,13 @@ typedef struct
#define ENET_RXDP_4BEAT DMA_BCTL_RXDP(4) /*!< maximum number of beats 4 */
#define ENET_RXDP_8BEAT DMA_BCTL_RXDP(8) /*!< maximum number of beats 8 */
#define ENET_RXDP_16BEAT DMA_BCTL_RXDP(16) /*!< maximum number of beats 16 */
-#define ENET_RXDP_32BEAT DMA_BCTL_RXDP(32) /*!< maximum number of beats 32 */
+#define ENET_RXDP_32BEAT DMA_BCTL_RXDP(32) /*!< maximum number of beats 32 */
#define ENET_RXDP_4xPGBL_4BEAT (DMA_BCTL_RXDP(1)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats 4 */
#define ENET_RXDP_4xPGBL_8BEAT (DMA_BCTL_RXDP(2)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats 8 */
#define ENET_RXDP_4xPGBL_16BEAT (DMA_BCTL_RXDP(4)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats 16 */
#define ENET_RXDP_4xPGBL_32BEAT (DMA_BCTL_RXDP(8)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats 32 */
#define ENET_RXDP_4xPGBL_64BEAT (DMA_BCTL_RXDP(16)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats 64 */
-#define ENET_RXDP_4xPGBL_128BEAT (DMA_BCTL_RXDP(32)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats 128 */
+#define ENET_RXDP_4xPGBL_128BEAT (DMA_BCTL_RXDP(32)|ENET_DMA_BCTL_FPBL) /*!< maximum number of beats 128 */
#define ENET_RXTX_DIFFERENT_PGBL ENET_DMA_BCTL_UIP /*!< RxDMA uses the RXDP[5:0], while TxDMA uses the PGBL[5:0] */
#define ENET_RXTX_SAME_PGBL ((uint32_t)0x00000000) /*!< RxDMA/TxDMA uses PGBL[5:0] */
@@ -1347,7 +1373,7 @@ typedef struct
#define ENET_FLUSH_RXFRAME_ENABLE ((uint32_t)0x00000000) /*!< RxDMA flushes all frames */
#define ENET_FLUSH_RXFRAME_DISABLE ENET_DMA_CTL_DAFRF /*!< RxDMA does not flush any frames */
-#define ENET_FLUSH_RXFRAME ENET_DMA_CTL_DAFRF /*!< RxDMA flushes frames function */
+#define ENET_NO_FLUSH_RXFRAME ENET_DMA_CTL_DAFRF /*!< RxDMA flushes frames function */
#define ENET_TX_MODE_STOREFORWARD ENET_DMA_CTL_TSFD /*!< TxFIFO operates in store-and-forward mode */
#define ENET_TX_MODE_CUTTHROUGH ((uint32_t)0x00000000) /*!< TxFIFO operates in cut-through mode */
@@ -1357,7 +1383,7 @@ typedef struct
#define ENET_FORWARD_ERRFRAMES (ENET_DMA_CTL_FERF<<2) /*!< the function that all frame received with error except runt error are forwarded to memory */
#define ENET_FORWARD_UNDERSZ_GOODFRAMES_ENABLE (ENET_DMA_CTL_FUF<<2) /*!< forward undersized good frames */
-#define ENET_FORWARD_UNDERSZ_GOODFRAMES_DISABLE ((uint32_t)0x00000000) /*!< RxFIFO drops all frames whose length is less than 64 bytes */
+#define ENET_FORWARD_UNDERSZ_GOODFRAMES_DISABLE ((uint32_t)0x00000000) /*!< RxFIFO drops all frames whose length is less than 64 bytes */
#define ENET_FORWARD_UNDERSZ_GOODFRAMES (ENET_DMA_CTL_FUF<<2) /*!< the function that forwarding undersized good frames */
#define ENET_SECONDFRAME_OPT_ENABLE ENET_DMA_CTL_OSF /*!< TxDMA controller operate on second frame mode enable*/
@@ -1376,10 +1402,10 @@ typedef struct
#define GET_TDES0_COCNT(regval) GET_BITS((regval),3,6) /*!< get value of ENET DMA TDES0 CONT bit field */
#define TDES0_CM(regval) (BITS(22,23) & ((uint32_t)(regval) << 22)) /*!< write value to ENET DMA TDES0 CM bit field */
-#define ENET_CHECKSUM_DISABLE TDES0_CM(0) /*!< checksum insertion disabled */
-#define ENET_CHECKSUM_IPV4HEADER TDES0_CM(1) /*!< only IP header checksum calculation and insertion are enabled */
-#define ENET_CHECKSUM_TCPUDPICMP_SEGMENT TDES0_CM(2) /*!< TCP/UDP/ICMP checksum insertion calculated but pseudo-header */
-#define ENET_CHECKSUM_TCPUDPICMP_FULL TDES0_CM(3) /*!< TCP/UDP/ICMP checksum insertion fully calculated */
+#define ENET_CHECKSUM_DISABLE TDES0_CM(0) /*!< checksum insertion disabled */
+#define ENET_CHECKSUM_IPV4HEADER TDES0_CM(1) /*!< only IP header checksum calculation and insertion are enabled */
+#define ENET_CHECKSUM_TCPUDPICMP_SEGMENT TDES0_CM(2) /*!< TCP/UDP/ICMP checksum insertion calculated but pseudo-header */
+#define ENET_CHECKSUM_TCPUDPICMP_FULL TDES0_CM(3) /*!< TCP/UDP/ICMP checksum insertion fully calculated */
/* dma tx descriptor tdes1 register value */
#define TDES1_TB1S(regval) (BITS(0,12) & ((uint32_t)(regval) << 0)) /*!< write value to ENET DMA TDES1 TB1S bit field */
@@ -1413,18 +1439,18 @@ typedef struct
#define ENET_MSC_PRESET_MASK (~(ENET_MSC_CTL_PMC | ENET_MSC_CTL_AFHPM)) /*!< ENET_MSC_CTL preset mask */
#ifdef SELECT_DESCRIPTORS_ENHANCED_MODE
-#define ETH_DMATXDESC_SIZE 0x20U /*!< TxDMA enhanced descriptor size */
-#define ETH_DMARXDESC_SIZE 0x20U /*!< RxDMA enhanced descriptor size */
+#define ETH_DMATXDESC_SIZE ((uint32_t)0x00000020U) /*!< TxDMA enhanced descriptor size */
+#define ETH_DMARXDESC_SIZE ((uint32_t)0x00000020U) /*!< RxDMA enhanced descriptor size */
#else
-#define ETH_DMATXDESC_SIZE 0x10U /*!< TxDMA descriptor size */
-#define ETH_DMARXDESC_SIZE 0x10U /*!< RxDMA descriptor size */
-#endif /* SELECT_DESCRIPTORS_ENHANCED_MODE */
+#define ETH_DMATXDESC_SIZE ((uint32_t)0x00000010U) /*!< TxDMA descriptor size */
+#define ETH_DMARXDESC_SIZE ((uint32_t)0x00000010U) /*!< RxDMA descriptor size */
+#endif /* SELECT_DESCRIPTORS_ENHANCED_MODE */
/* ENET remote wake-up frame register length */
#define ETH_WAKEUP_REGISTER_LENGTH 8U /*!< remote wake-up frame register length */
-/* ENET frame size */
-#define ENET_MAX_FRAME_SIZE 1524U /*!< header + frame_extra + payload + CRC */
+/* ENET frame size */
+#define ENET_MAX_FRAME_SIZE 1524U /*!< header + frame_extra + payload + CRC */
/* ENET delay timeout */
#define ENET_DELAY_TO ((uint32_t)0x0004FFFFU) /*!< ENET delay timeout */
@@ -1459,12 +1485,12 @@ ErrStatus enet_frame_transmit(uint8_t *buffer, uint32_t length);
/* configure the transmit IP frame checksum offload calculation and insertion */
void enet_transmit_checksum_config(enet_descriptors_struct *desc, uint32_t checksum);
/* ENET Tx and Rx function enable (include MAC and DMA module) */
-void enet_enable(void);
+void enet_enable(void);
/* ENET Tx and Rx function disable (include MAC and DMA module) */
void enet_disable(void);
/* configure MAC address */
void enet_mac_address_set(enet_macaddress_enum mac_addr, uint8_t paddr[]);
-/* get MAC address */
+/* get MAC address */
void enet_mac_address_get(enet_macaddress_enum mac_addr, uint8_t paddr[]);
/* get the ENET MAC/MSC/PTP/DMA status flag */
@@ -1532,7 +1558,7 @@ void enet_flowcontrol_feature_disable(uint32_t feature);
/* DMA function */
/* get the dma transmit/receive process state */
-uint32_t enet_dmaprocess_state_get(enet_dmadirection_enum direction);
+uint32_t enet_dmaprocess_state_get(enet_dmadirection_enum direction);
/* poll the dma transmission/reception enable */
void enet_dmaprocess_resume(enet_dmadirection_enum direction);
/* check and recover the Rx process */
@@ -1552,7 +1578,7 @@ FlagStatus enet_desc_flag_get(enet_descriptors_struct *desc, uint32_t desc_flag)
/* set the bit flag of ENET dma tx descriptor */
void enet_desc_flag_set(enet_descriptors_struct *desc, uint32_t desc_flag);
/* clear the bit flag of ENET dma tx descriptor */
-void enet_desc_flag_clear(enet_descriptors_struct *desc, uint32_t desc_flag);
+void enet_desc_flag_clear(enet_descriptors_struct *desc, uint32_t desc_flag);
/* when receiving the completed, set RS bit in ENET_DMA_STAT register will immediately set */
void enet_rx_desc_immediate_receive_complete_interrupt(enet_descriptors_struct *desc);
/* when receiving the completed, set RS bit in ENET_DMA_STAT register will is set after a configurable delay time */
@@ -1616,13 +1642,13 @@ void enet_wum_feature_disable(uint32_t feature);
/* MSC function */
/* reset the MAC statistics counters */
void enet_msc_counters_reset(void);
-/* enable the MAC statistics counter features */
+/* enable the MAC statistics counter features */
void enet_msc_feature_enable(uint32_t feature);
-/* disable the MAC statistics counter features */
+/* disable the MAC statistics counter features */
void enet_msc_feature_disable(uint32_t feature);
/* configure MAC statistics counters preset mode */
void enet_msc_counters_preset_config(enet_msc_preset_enum mode);
-/* get MAC statistics counter */
+/* get MAC statistics counter */
uint32_t enet_msc_counters_get(enet_msc_counter_enum counter);
/* PTP function */
@@ -1649,16 +1675,6 @@ void enet_ptp_pps_output_frequency_config(uint32_t freq);
/* internal function */
/* reset the ENET initpara struct, call it before using enet_initpara_config() */
void enet_initpara_reset(void);
-/* initialize ENET peripheral with generally concerned parameters, call it by enet_init() */
-static void enet_default_init(void);
-#ifdef USE_DELAY
-/* user can provide more timing precise _ENET_DELAY_ function */
-#define _ENET_DELAY_ delay_ms
-#else
-/* insert a delay time */
-static void enet_delay(uint32_t ncount);
-/* default _ENET_DELAY_ function with less precise timing */
-#define _ENET_DELAY_ enet_delay
-#endif
+
#endif /* GD32F4XX_ENET_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_exmc.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_exmc.h
index 3844c699d2..94baf2f6f3 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_exmc.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_exmc.h
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_exmc.h
- \brief definitions for the EXMC
+ \file gd32f4xx_exmc.h
+ \brief definitions for the EXMC
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#ifndef GD32F4XX_EXMC_H
@@ -15,224 +40,224 @@
#include "gd32f4xx.h"
/* EXMC definitions */
-#define EXMC (EXMC_BASE) /*!< EXMC register base address */
-#define EXMC_NOR_PSRAM (EXMC_BASE - 0x40000000) /*!< EXMC NOR/PSRAM base address */
-#define EXMC_NAND (EXMC_BASE - 0x30000000) /*!< EXMC NAND base address */
-#define EXMC_PCCARD (EXMC_BASE - 0x10000000) /*!< EXMC PC card base address */
-#define EXMC_SDRAM (EXMC_BASE + 0x20000000) /*!< EXMC SDRAM base address */
+#define EXMC (EXMC_BASE) /*!< EXMC register base address */
+#define EXMC_NOR_PSRAM (EXMC_BASE - 0x40000000) /*!< EXMC NOR/PSRAM base address */
+#define EXMC_NAND (EXMC_BASE - 0x30000000) /*!< EXMC NAND base address */
+#define EXMC_PCCARD (EXMC_BASE - 0x10000000) /*!< EXMC PC card base address */
+#define EXMC_SDRAM (EXMC_BASE + 0x20000000) /*!< EXMC SDRAM base address */
/* registers definitions */
/* NOR/PSRAM */
-#define EXMC_SNCTL0 REG32(EXMC + 0x00U) /*!< EXMC SRAM/NOR flash control register */
-#define EXMC_SNTCFG0 REG32(EXMC + 0x04U) /*!< EXMC SRAM/NOR flash timing configuration register */
-#define EXMC_SNWTCFG0 REG32(EXMC + 0x104U) /*!< EXMC SRAM/NOR flash write timing configuration register */
+#define EXMC_SNCTL0 REG32(EXMC + 0x00U) /*!< EXMC SRAM/NOR flash control register for region0 */
+#define EXMC_SNTCFG0 REG32(EXMC + 0x04U) /*!< EXMC SRAM/NOR flash timing configuration register for region0 */
+#define EXMC_SNWTCFG0 REG32(EXMC + 0x104U) /*!< EXMC SRAM/NOR flash write timing configuration register for region0 */
-#define EXMC_SNCTL1 REG32(EXMC + 0x08U) /*!< EXMC SRAM/NOR flash control register */
-#define EXMC_SNTCFG1 REG32(EXMC + 0x0CU) /*!< EXMC SRAM/NOR flash timing configuration register */
-#define EXMC_SNWTCFG1 REG32(EXMC + 0x10CU) /*!< EXMC SRAM/NOR flash write timing configuration register */
+#define EXMC_SNCTL1 REG32(EXMC + 0x08U) /*!< EXMC SRAM/NOR flash control register for region1 */
+#define EXMC_SNTCFG1 REG32(EXMC + 0x0CU) /*!< EXMC SRAM/NOR flash timing configuration register for region1 */
+#define EXMC_SNWTCFG1 REG32(EXMC + 0x10CU) /*!< EXMC SRAM/NOR flash write timing configuration register for region1 */
-#define EXMC_SNCTL2 REG32(EXMC + 0x10U) /*!< EXMC SRAM/NOR flash control register */
-#define EXMC_SNTCFG2 REG32(EXMC + 0x14U) /*!< EXMC SRAM/NOR flash timing configuration register */
-#define EXMC_SNWTCFG2 REG32(EXMC + 0x114U) /*!< EXMC SRAM/NOR flash write timing configuration register */
+#define EXMC_SNCTL2 REG32(EXMC + 0x10U) /*!< EXMC SRAM/NOR flash control register for region2 */
+#define EXMC_SNTCFG2 REG32(EXMC + 0x14U) /*!< EXMC SRAM/NOR flash timing configuration register for region2 */
+#define EXMC_SNWTCFG2 REG32(EXMC + 0x114U) /*!< EXMC SRAM/NOR flash write timing configuration register for region2 */
-#define EXMC_SNCTL3 REG32(EXMC + 0x18U) /*!< EXMC SRAM/NOR flash control register */
-#define EXMC_SNTCFG3 REG32(EXMC + 0x1CU) /*!< EXMC SRAM/NOR flash timing configuration register */
-#define EXMC_SNWTCFG3 REG32(EXMC + 0x11CU) /*!< EXMC SRAM/NOR flash write timing configuration register */
+#define EXMC_SNCTL3 REG32(EXMC + 0x18U) /*!< EXMC SRAM/NOR flash control register for region3 */
+#define EXMC_SNTCFG3 REG32(EXMC + 0x1CU) /*!< EXMC SRAM/NOR flash timing configuration register for region3 */
+#define EXMC_SNWTCFG3 REG32(EXMC + 0x11CU) /*!< EXMC SRAM/NOR flash write timing configuration register for region3 */
/* NAND/PC card */
-#define EXMC_NPCTL1 REG32(EXMC + 0x40U) /*!< EXMC NAND/PC card control register */
-#define EXMC_NPINTEN1 REG32(EXMC + 0x44U) /*!< EXMC NAND/PC card interrupt enable register */
-#define EXMC_NPCTCFG1 REG32(EXMC + 0x48U) /*!< EXMC NAND/PC card common space timing configuration register */
-#define EXMC_NPATCFG1 REG32(EXMC + 0x4CU) /*!< EXMC NAND/PC card attribute space timing configuration register */
-#define EXMC_NECC1 REG32(EXMC + 0x54U) /*!< EXMC NAND ECC register */
+#define EXMC_NPCTL1 REG32(EXMC + 0x60U) /*!< EXMC NAND/PC card control register for bank1 */
+#define EXMC_NPINTEN1 REG32(EXMC + 0x64U) /*!< EXMC NAND/PC card interrupt enable register for bank1 */
+#define EXMC_NPCTCFG1 REG32(EXMC + 0x68U) /*!< EXMC NAND/PC card common space timing configuration register for bank1 */
+#define EXMC_NPATCFG1 REG32(EXMC + 0x6CU) /*!< EXMC NAND/PC card attribute space timing configuration register for bank1 */
+#define EXMC_NECC1 REG32(EXMC + 0x74U) /*!< EXMC NAND ECC register */
-#define EXMC_NPCTL2 REG32(EXMC + 0x60U) /*!< EXMC NAND/PC card control register */
-#define EXMC_NPINTEN2 REG32(EXMC + 0x64U) /*!< EXMC NAND/PC card interrupt enable register */
-#define EXMC_NPCTCFG2 REG32(EXMC + 0x68U) /*!< EXMC NAND/PC card common space timing configuration register */
-#define EXMC_NPATCFG2 REG32(EXMC + 0x6CU) /*!< EXMC NAND/PC card attribute space timing configuration register */
-#define EXMC_NECC2 REG32(EXMC + 0x74U) /*!< EXMC NAND ECC register */
+#define EXMC_NPCTL2 REG32(EXMC + 0x80U) /*!< EXMC NAND/PC card control register for bank2 */
+#define EXMC_NPINTEN2 REG32(EXMC + 0x84U) /*!< EXMC NAND/PC card interrupt enable register for bank2 */
+#define EXMC_NPCTCFG2 REG32(EXMC + 0x88U) /*!< EXMC NAND/PC card common space timing configuration register for bank2 */
+#define EXMC_NPATCFG2 REG32(EXMC + 0x8CU) /*!< EXMC NAND/PC card attribute space timing configuration register for bank2 */
+#define EXMC_NECC2 REG32(EXMC + 0x94U) /*!< EXMC NAND ECC register */
-#define EXMC_NPCTL3 REG32(EXMC + 0x80U) /*!< EXMC NAND/PC card control register */
-#define EXMC_NPINTEN3 REG32(EXMC + 0x84U) /*!< EXMC NAND/PC card interrupt enable register */
-#define EXMC_NPCTCFG3 REG32(EXMC + 0x88U) /*!< EXMC NAND/PC card common space timing configuration register */
-#define EXMC_NPATCFG3 REG32(EXMC + 0x8CU) /*!< EXMC NAND/PC card attribute space timing configuration register */
-#define EXMC_PIOTCFG3 REG32(EXMC + 0xB0U) /*!< EXMC PC card I/O space timing configuration register */
+#define EXMC_NPCTL3 REG32(EXMC + 0xA0U) /*!< EXMC NAND/PC card control register for bank3 */
+#define EXMC_NPINTEN3 REG32(EXMC + 0xA4U) /*!< EXMC NAND/PC card interrupt enable register for bank3 */
+#define EXMC_NPCTCFG3 REG32(EXMC + 0xA8U) /*!< EXMC NAND/PC card common space timing configuration register for bank3 */
+#define EXMC_NPATCFG3 REG32(EXMC + 0xACU) /*!< EXMC NAND/PC card attribute space timing configuration register for bank3 */
+#define EXMC_PIOTCFG3 REG32(EXMC + 0xB0U) /*!< EXMC PC card I/O space timing configuration register for bank3 */
/* SDRAM */
-#define EXMC_SDCTL0 REG32(EXMC + 0x140U) /*!< EXMC SDRAM control register */
-#define EXMC_SDTCFG0 REG32(EXMC + 0x148U) /*!< EXMC SDRAM timing configuration register register */
+#define EXMC_SDCTL0 REG32(EXMC + 0x140U) /*!< EXMC SDRAM control register for device0 */
+#define EXMC_SDTCFG0 REG32(EXMC + 0x148U) /*!< EXMC SDRAM timing configuration register register for device0 */
-#define EXMC_SDCTL1 REG32(EXMC + 0x144U) /*!< EXMC SDRAM control register */
-#define EXMC_SDTCFG1 REG32(EXMC + 0x14CU) /*!< EXMC SDRAM timing configuration register register */
+#define EXMC_SDCTL1 REG32(EXMC + 0x144U) /*!< EXMC SDRAM control register for device1 */
+#define EXMC_SDTCFG1 REG32(EXMC + 0x14CU) /*!< EXMC SDRAM timing configuration register register for device1 */
-#define EXMC_SDCMD REG32(EXMC + 0x150U) /*!< EXMC SDRAM command register */
-#define EXMC_SDARI REG32(EXMC + 0x154U) /*!< EXMC SDRAM auto-refresh interval register */
-#define EXMC_SDSTAT REG32(EXMC + 0x158U) /*!< EXMC SDRAM status register */
-#define EXMC_SDRSCTL REG32(EXMC + 0x180U) /*!< EXMC SDRAM read sample control register */
+#define EXMC_SDCMD REG32(EXMC + 0x150U) /*!< EXMC SDRAM command register */
+#define EXMC_SDARI REG32(EXMC + 0x154U) /*!< EXMC SDRAM auto-refresh interval register */
+#define EXMC_SDSTAT REG32(EXMC + 0x158U) /*!< EXMC SDRAM status register */
+#define EXMC_SDRSCTL REG32(EXMC + 0x180U) /*!< EXMC SDRAM read sample control register */
/* SQPI PSRAM */
-#define EXMC_SINIT REG32(EXMC + 0x310U) /*!< EXMC SPI initialization register */
-#define EXMC_SRCMD REG32(EXMC + 0x320U) /*!< EXMC SPI read command register */
-#define EXMC_SWCMD REG32(EXMC + 0x330U) /*!< EXMC SPI write command register */
-#define EXMC_SIDL REG32(EXMC + 0x340U) /*!< EXMC SPI ID low register */
-#define EXMC_SIDH REG32(EXMC + 0x350U) /*!< EXMC SPI ID high register */
+#define EXMC_SINIT REG32(EXMC + 0x310U) /*!< EXMC SPI initialization register */
+#define EXMC_SRCMD REG32(EXMC + 0x320U) /*!< EXMC SPI read command register */
+#define EXMC_SWCMD REG32(EXMC + 0x330U) /*!< EXMC SPI write command register */
+#define EXMC_SIDL REG32(EXMC + 0x340U) /*!< EXMC SPI ID low register */
+#define EXMC_SIDH REG32(EXMC + 0x350U) /*!< EXMC SPI ID high register */
/* bits definitions */
/* EXMC_SNCTLx,x=0..3 */
-#define EXMC_SNCTL_NRBKEN BIT(0) /*!< NOR bank enable */
-#define EXMC_SNCTL_NRMUX BIT(1) /*!< NOR bank memory address/data multiplexing */
-#define EXMC_SNCTL_NRTP BITS(2,3) /*!< NOR bank memory type */
-#define EXMC_SNCTL_NRW BITS(4,5) /*!< NOR bank memory data bus width */
-#define EXMC_SNCTL_NREN BIT(6) /*!< NOR flash access enable */
-#define EXMC_SNCTL_SBRSTEN BIT(8) /*!< synchronous burst enable */
-#define EXMC_SNCTL_NRWTPOL BIT(9) /*!< NWAIT signal polarity */
-#define EXMC_SNCTL_WRAPEN BIT(10) /*!< wrapped burst mode enable */
-#define EXMC_SNCTL_NRWTCFG BIT(11) /*!< NWAIT signal configuration, only work in synchronous mode */
-#define EXMC_SNCTL_WREN BIT(12) /*!< write enable */
-#define EXMC_SNCTL_NRWTEN BIT(13) /*!< NWAIT signal enable */
-#define EXMC_SNCTL_EXMODEN BIT(14) /*!< extended mode enable */
-#define EXMC_SNCTL_ASYNCWAIT BIT(15) /*!< asynchronous wait */
-#define EXMC_SNCTL_CPS BITS(16,18) /*!< CRAM page size */
-#define EXMC_SNCTL_SYNCWR BIT(19) /*!< synchronous write */
-#define EXMC_SNCTL_CCK BIT(20) /*!< consecutive clock */
+#define EXMC_SNCTL_NRBKEN BIT(0) /*!< NOR bank enable */
+#define EXMC_SNCTL_NRMUX BIT(1) /*!< NOR bank memory address/data multiplexing enable */
+#define EXMC_SNCTL_NRTP BITS(2,3) /*!< NOR bank memory type */
+#define EXMC_SNCTL_NRW BITS(4,5) /*!< NOR bank memory data bus width */
+#define EXMC_SNCTL_NREN BIT(6) /*!< NOR flash access enable */
+#define EXMC_SNCTL_SBRSTEN BIT(8) /*!< synchronous burst enable */
+#define EXMC_SNCTL_NRWTPOL BIT(9) /*!< NWAIT signal polarity */
+#define EXMC_SNCTL_WRAPEN BIT(10) /*!< wrapped burst mode enable */
+#define EXMC_SNCTL_NRWTCFG BIT(11) /*!< NWAIT signal configuration, only work in synchronous mode */
+#define EXMC_SNCTL_WREN BIT(12) /*!< write enable */
+#define EXMC_SNCTL_NRWTEN BIT(13) /*!< NWAIT signal enable */
+#define EXMC_SNCTL_EXMODEN BIT(14) /*!< extended mode enable */
+#define EXMC_SNCTL_ASYNCWAIT BIT(15) /*!< asynchronous wait enable */
+#define EXMC_SNCTL_CPS BITS(16,18) /*!< CRAM page size */
+#define EXMC_SNCTL_SYNCWR BIT(19) /*!< synchronous write config */
+#define EXMC_SNCTL_CCK BIT(20) /*!< consecutive clock config */
/* EXMC_SNTCFGx,x=0..3 */
-#define EXMC_SNTCFG_ASET BITS(0,3) /*!< address setup time */
-#define EXMC_SNTCFG_AHLD BITS(4,7) /*!< address hold time */
-#define EXMC_SNTCFG_DSET BITS(8,15) /*!< data setup time */
-#define EXMC_SNTCFG_BUSLAT BITS(16,19) /*!< bus latency */
-#define EXMC_SNTCFG_CKDIV BITS(20,23) /*!< synchronous clock divide ratio */
-#define EXMC_SNTCFG_DLAT BITS(24,27) /*!< data latency for NOR flash */
-#define EXMC_SNTCFG_ASYNCMOD BITS(28,29) /*!< asynchronous access mode */
+#define EXMC_SNTCFG_ASET BITS(0,3) /*!< asynchronous address setup time */
+#define EXMC_SNTCFG_AHLD BITS(4,7) /*!< asynchronous address hold time */
+#define EXMC_SNTCFG_DSET BITS(8,15) /*!< asynchronous data setup time */
+#define EXMC_SNTCFG_BUSLAT BITS(16,19) /*!< bus latency */
+#define EXMC_SNTCFG_CKDIV BITS(20,23) /*!< synchronous clock divide ratio */
+#define EXMC_SNTCFG_DLAT BITS(24,27) /*!< synchronous data latency for NOR flash */
+#define EXMC_SNTCFG_ASYNCMOD BITS(28,29) /*!< asynchronous access mode */
/* EXMC_SNWTCFGx,x=0..3 */
-#define EXMC_SNWTCFG_WASET BITS(0,3) /*!< address setup time */
-#define EXMC_SNWTCFG_WAHLD BITS(4,7) /*!< address hold time */
-#define EXMC_SNWTCFG_WDSET BITS(8,15) /*!< data setup time */
-#define EXMC_SNWTCFG_WBUSLAT BITS(16,19) /*!< bus latency */
-#define EXMC_SNWTCFG_WASYNCMOD BITS(28,29) /*!< asynchronous access mode */
+#define EXMC_SNWTCFG_WASET BITS(0,3) /*!< asynchronous address setup time */
+#define EXMC_SNWTCFG_WAHLD BITS(4,7) /*!< asynchronous address hold time */
+#define EXMC_SNWTCFG_WDSET BITS(8,15) /*!< asynchronous data setup time */
+#define EXMC_SNWTCFG_WBUSLAT BITS(16,19) /*!< bus latency */
+#define EXMC_SNWTCFG_WASYNCMOD BITS(28,29) /*!< asynchronous access mode */
/* EXMC_NPCTLx,x=1..3 */
-#define EXMC_NPCTL_NDWTEN BIT(1) /*!< wait feature enable */
-#define EXMC_NPCTL_NDBKEN BIT(2) /*!< NAND bank enable */
-#define EXMC_NPCTL_NDTP BIT(3) /*!< NAND bank memory type */
-#define EXMC_NPCTL_NDW BITS(4,5) /*!< NAND bank memory data bus width */
-#define EXMC_NPCTL_ECCEN BIT(6) /*!< ECC enable */
-#define EXMC_NPCTL_CTR BITS(9,12) /*!< CLE to RE delay */
-#define EXMC_NPCTL_ATR BITS(13,16) /*!< ALE to RE delay */
-#define EXMC_NPCTL_ECCSZ BITS(17,19) /*!< ECC size */
+#define EXMC_NPCTL_NDWTEN BIT(1) /*!< wait feature enable */
+#define EXMC_NPCTL_NDBKEN BIT(2) /*!< NAND bank enable */
+#define EXMC_NPCTL_NDTP BIT(3) /*!< NAND bank memory type */
+#define EXMC_NPCTL_NDW BITS(4,5) /*!< NAND bank memory data bus width */
+#define EXMC_NPCTL_ECCEN BIT(6) /*!< ECC enable */
+#define EXMC_NPCTL_CTR BITS(9,12) /*!< CLE to RE delay */
+#define EXMC_NPCTL_ATR BITS(13,16) /*!< ALE to RE delay */
+#define EXMC_NPCTL_ECCSZ BITS(17,19) /*!< ECC size */
/* EXMC_NPINTENx,x=1..3 */
-#define EXMC_NPINTEN_INTRS BIT(0) /*!< interrupt rising edge status */
-#define EXMC_NPINTEN_INTHS BIT(1) /*!< interrupt high-level status */
-#define EXMC_NPINTEN_INTFS BIT(2) /*!< interrupt falling edge status */
-#define EXMC_NPINTEN_INTREN BIT(3) /*!< interrupt rising edge detection enable */
-#define EXMC_NPINTEN_INTHEN BIT(4) /*!< interrupt high-level detection enable */
-#define EXMC_NPINTEN_INTFEN BIT(5) /*!< interrupt falling edge detection enable */
-#define EXMC_NPINTEN_INTEPT BIT(6) /*!< FIFO empty flag */
+#define EXMC_NPINTEN_INTRS BIT(0) /*!< interrupt rising edge status */
+#define EXMC_NPINTEN_INTHS BIT(1) /*!< interrupt high-level status */
+#define EXMC_NPINTEN_INTFS BIT(2) /*!< interrupt falling edge status */
+#define EXMC_NPINTEN_INTREN BIT(3) /*!< interrupt rising edge detection enable */
+#define EXMC_NPINTEN_INTHEN BIT(4) /*!< interrupt high-level detection enable */
+#define EXMC_NPINTEN_INTFEN BIT(5) /*!< interrupt falling edge detection enable */
+#define EXMC_NPINTEN_FFEPT BIT(6) /*!< FIFO empty flag */
/* EXMC_NPCTCFGx,x=1..3 */
-#define EXMC_NPCTCFG_COMSET BITS(0,7) /*!< common memory data bus HiZ time */
-#define EXMC_NPCTCFG_COMWAIT BITS(8,15) /*!< common memory hold time */
-#define EXMC_NPCTCFG_COMHLD BITS(16,23) /*!< common memory wait time */
-#define EXMC_NPCTCFG_COMHIZ BITS(24,31) /*!< common memory setup time */
+#define EXMC_NPCTCFG_COMSET BITS(0,7) /*!< common memory setup time */
+#define EXMC_NPCTCFG_COMWAIT BITS(8,15) /*!< common memory wait time */
+#define EXMC_NPCTCFG_COMHLD BITS(16,23) /*!< common memory hold time */
+#define EXMC_NPCTCFG_COMHIZ BITS(24,31) /*!< common memory data bus HiZ time */
/* EXMC_NPATCFGx,x=1..3 */
-#define EXMC_NPATCFG_ATTSET BITS(0,7) /*!< attribute memory data bus HiZ time */
-#define EXMC_NPATCFG_ATTWAIT BITS(8,15) /*!< attribute memory hold time */
-#define EXMC_NPATCFG_ATTHLD BITS(16,23) /*!< attribute memory wait time */
-#define EXMC_NPATCFG_ATTHIZ BITS(24,31) /*!< attribute memory setup time */
+#define EXMC_NPATCFG_ATTSET BITS(0,7) /*!< attribute memory setup time */
+#define EXMC_NPATCFG_ATTWAIT BITS(8,15) /*!< attribute memory wait time */
+#define EXMC_NPATCFG_ATTHLD BITS(16,23) /*!< attribute memory hold time */
+#define EXMC_NPATCFG_ATTHIZ BITS(24,31) /*!< attribute memory data bus HiZ time */
/* EXMC_PIOTCFG3 */
-#define EXMC_PIOTCFG3_IOSET BITS(0,7) /*!< IO space data bus HiZ time */
-#define EXMC_PIOTCFG3_IOWAIT BITS(8,15) /*!< IO space hold time */
-#define EXMC_PIOTCFG3_IOHLD BITS(16,23) /*!< IO space wait time */
-#define EXMC_PIOTCFG3_IOHIZ BITS(24,31) /*!< IO space setup time */
+#define EXMC_PIOTCFG3_IOSET BITS(0,7) /*!< IO space setup time */
+#define EXMC_PIOTCFG3_IOWAIT BITS(8,15) /*!< IO space wait time */
+#define EXMC_PIOTCFG3_IOHLD BITS(16,23) /*!< IO space hold time */
+#define EXMC_PIOTCFG3_IOHIZ BITS(24,31) /*!< IO space data bus HiZ time */
/* EXMC_NECCx,x=1..2 */
-#define EXMC_NECC_ECC BITS(0,31) /*!< ECC result */
+#define EXMC_NECC_ECC BITS(0,31) /*!< ECC result */
/* EXMC_SDCTLx,x=0..1 */
-#define EXMC_SDCTL_CAW BITS(0,1) /*!< column address bit width */
-#define EXMC_SDCTL_RAW BITS(2,3) /*!< row address bit width */
-#define EXMC_SDCTL_SDW BITS(4,5) /*!< SDRAM data bus width */
-#define EXMC_SDCTL_NBK BIT(6) /*!< number of banks */
-#define EXMC_SDCTL_CL BIT(7,8) /*!< CAS Latency */
-#define EXMC_SDCTL_WPEN BIT(9) /*!< write protection enable */
-#define EXMC_SDCTL_SDCLK BITS(10,11) /*!< SDRAM clock configuration */
-#define EXMC_SDCTL_BRSTRD BIT(12) /*!< burst read */
-#define EXMC_SDCTL_PIPED BITS(13,14) /*!< pipeline delay */
+#define EXMC_SDCTL_CAW BITS(0,1) /*!< column address bit width */
+#define EXMC_SDCTL_RAW BITS(2,3) /*!< row address bit width */
+#define EXMC_SDCTL_SDW BITS(4,5) /*!< SDRAM data bus width */
+#define EXMC_SDCTL_NBK BIT(6) /*!< number of banks */
+#define EXMC_SDCTL_CL BIT(7,8) /*!< CAS Latency */
+#define EXMC_SDCTL_WPEN BIT(9) /*!< write protection enable */
+#define EXMC_SDCTL_SDCLK BITS(10,11) /*!< SDRAM clock configuration */
+#define EXMC_SDCTL_BRSTRD BIT(12) /*!< burst read enable */
+#define EXMC_SDCTL_PIPED BITS(13,14) /*!< pipeline delay */
/* EXMC_SDTCFGx,x=0..1 */
-#define EXMC_SDTCFG_LMRD BITS(0,3) /*!< load mode register delay */
-#define EXMC_SDTCFG_XSRD BITS(4,7) /*!< exit self-refresh delay */
-#define EXMC_SDTCFG_RASD BITS(8,11) /*!< row address select delay */
-#define EXMC_SDTCFG_ARFD BITS(12,15) /*!< auto refresh delay */
-#define EXMC_SDTCFG_WRD BITS(16,19) /*!< write recovery delay */
-#define EXMC_SDTCFG_RPD BITS(20,23) /*!< row precharge delay */
-#define EXMC_SDTCFG_RCD BITS(24,27) /*!< row to column delay */
+#define EXMC_SDTCFG_LMRD BITS(0,3) /*!< load mode register delay */
+#define EXMC_SDTCFG_XSRD BITS(4,7) /*!< exit self-refresh delay */
+#define EXMC_SDTCFG_RASD BITS(8,11) /*!< row address select delay */
+#define EXMC_SDTCFG_ARFD BITS(12,15) /*!< auto refresh delay */
+#define EXMC_SDTCFG_WRD BITS(16,19) /*!< write recovery delay */
+#define EXMC_SDTCFG_RPD BITS(20,23) /*!< row precharge delay */
+#define EXMC_SDTCFG_RCD BITS(24,27) /*!< row to column delay */
/* EXMC_SDCMD */
-#define EXMC_SDCMD_CMD BITS(0,2) /*!< command */
-#define EXMC_SDCMD_DS1 BIT(3) /*!< device select 1 */
-#define EXMC_SDCMD_DS0 BIT(4) /*!< device select 0 */
-#define EXMC_SDCMD_NARF BITS(5,8) /*!< number of successive auto-refresh */
-#define EXMC_SDCMD_MRC BITS(9,21) /*!< mode register content */
+#define EXMC_SDCMD_CMD BITS(0,2) /*!< command */
+#define EXMC_SDCMD_DS1 BIT(3) /*!< select device1 */
+#define EXMC_SDCMD_DS0 BIT(4) /*!< select device0 */
+#define EXMC_SDCMD_NARF BITS(5,8) /*!< number of successive auto-refresh */
+#define EXMC_SDCMD_MRC BITS(9,21) /*!< mode register content */
/* EXMC_SDARI */
-#define EXMC_SDARI_REC BIT(0) /*!< refresh error flag clear */
-#define EXMC_SDARI_ARINTV BITS(1,13) /*!< auto-refresh interval */
-#define EXMC_SDARI_REIE BIT(14) /*!< interrupt refresh error enable */
+#define EXMC_SDARI_REC BIT(0) /*!< refresh error flag clear */
+#define EXMC_SDARI_ARINTV BITS(1,13) /*!< auto-refresh interval */
+#define EXMC_SDARI_REIE BIT(14) /*!< interrupt refresh error enable */
/* EXMC_SDSTAT */
-#define EXMC_SDSDAT_REIF BIT(0) /*!< refresh error interrupt flag */
-#define EXMC_SDSDAT_STA0 BITS(1,2) /*!< device 0 status */
-#define EXMC_SDSDAT_STA1 BITS(3,4) /*!< device 1 status */
-#define EXMC_SDSDAT_NRDY BIT(5) /*!< not ready status */
+#define EXMC_SDSDAT_REIF BIT(0) /*!< refresh error interrupt flag */
+#define EXMC_SDSDAT_STA0 BITS(1,2) /*!< device0 status */
+#define EXMC_SDSDAT_STA1 BITS(3,4) /*!< device1 status */
+#define EXMC_SDSDAT_NRDY BIT(5) /*!< not ready status */
/* EXMC_SDRSCTL */
-#define EXMC_SDRSCTL_RSEN BIT(0) /*!< read sample enable */
-#define EXMC_SDRSCTL_SSCR BIT(1) /*!< select sample cycle of read data */
-#define EXMC_SDRSCTL_SDSC BITS(4,7) /*!< select the delayed sample clock of read data */
+#define EXMC_SDRSCTL_RSEN BIT(0) /*!< read sample enable */
+#define EXMC_SDRSCTL_SSCR BIT(1) /*!< select sample cycle of read data */
+#define EXMC_SDRSCTL_SDSC BITS(4,7) /*!< select the delayed sample clock of read data */
/* EXMC_SINIT */
-#define EXMC_SINIT_CMDBIT BITS(16,17) /*!< bit number of SPI PSRAM command phase */
-#define EXMC_SINIT_ARDBIT BITS(24,28) /*!< bit number of SPI PSRAM address phase */
-#define EXMC_SINIT_IDL BITS(29,30) /*!< SPI PSRAM ID length */
-#define EXMC_SINIT_POL BIT(31) /*!< read data sample polarity */
+#define EXMC_SINIT_CMDBIT BITS(16,17) /*!< bit number of SPI PSRAM command phase */
+#define EXMC_SINIT_ARDBIT BITS(24,28) /*!< bit number of SPI PSRAM address phase */
+#define EXMC_SINIT_IDL BITS(29,30) /*!< SPI PSRAM ID length */
+#define EXMC_SINIT_POL BIT(31) /*!< read data sample polarity */
/* EXMC_SRCMD */
-#define EXMC_SRCMD_RCMD BITS(0,15) /*!< SPI read command for AHB read transfer */
-#define EXMC_SRCMD_RWAITCYCLE BITS(16,19) /*!< SPI read wait cycle number after address phase */
-#define EXMC_SRCMD_RMODE BITS(20,21) /*!< SPI PSRAM read command mode */
-#define EXMC_SRCMD_RDID BIT(31) /*!< send SPI read ID command */
+#define EXMC_SRCMD_RCMD BITS(0,15) /*!< SPI read command for AHB read transfer */
+#define EXMC_SRCMD_RWAITCYCLE BITS(16,19) /*!< SPI read wait cycle number after address phase */
+#define EXMC_SRCMD_RMODE BITS(20,21) /*!< SPI PSRAM read command mode */
+#define EXMC_SRCMD_RDID BIT(31) /*!< send SPI read ID command */
/* EXMC_SWCMD */
-#define EXMC_SWCMD_WCMD BITS(0,15) /*!< send SPI special command */
-#define EXMC_SWCMD_WWAITCYCLE BITS(16,19) /*!< SPI PSRAM write command mode */
-#define EXMC_SWCMD_WMODE BITS(20,21) /*!< SPI write wait cycle number after address phase */
-#define EXMC_SWCMD_SC BIT(31) /*!< SPI write command for AHB write transfer */
+#define EXMC_SWCMD_WCMD BITS(0,15) /*!< SPI write command for AHB write transfer */
+#define EXMC_SWCMD_WWAITCYCLE BITS(16,19) /*!< SPI write wait cycle number after address phase */
+#define EXMC_SWCMD_WMODE BITS(20,21) /*!< SPI PSRAM write command mode */
+#define EXMC_SWCMD_SC BIT(31) /*!< send SPI special command */
/* EXMC_SIDL */
-#define EXMC_SIDL_SIDL BITS(0,31) /*!< ID low data saved for SPI read ID command */
+#define EXMC_SIDL_SIDL BITS(0,31) /*!< ID low data saved for SPI read ID command */
/* EXMC_SIDH */
-#define EXMC_SIDL_SIDH BITS(0,31) /*!< ID high Data saved for SPI read ID command */
+#define EXMC_SIDL_SIDH BITS(0,31) /*!< ID high Data saved for SPI read ID command */
/* constants definitions */
-/* EXMC NOR/SRAM timing initialize struct */
+/* EXMC NOR/SRAM timing initialize structure */
typedef struct
{
uint32_t asyn_access_mode; /*!< asynchronous access mode */
uint32_t syn_data_latency; /*!< configure the data latency */
uint32_t syn_clk_division; /*!< configure the clock divide ratio */
uint32_t bus_latency; /*!< configure the bus latency */
- uint32_t asyn_data_setuptime; /*!< configure the data setup time,asynchronous access mode valid */
- uint32_t asyn_address_holdtime; /*!< configure the address hold time,asynchronous access mode valid */
- uint32_t asyn_address_setuptime; /*!< configure the data setup time,asynchronous access mode valid */
+ uint32_t asyn_data_setuptime; /*!< configure the data setup time, asynchronous access mode valid */
+ uint32_t asyn_address_holdtime; /*!< configure the address hold time, asynchronous access mode valid */
+ uint32_t asyn_address_setuptime; /*!< configure the address setup time, asynchronous access mode valid */
}exmc_norsram_timing_parameter_struct;
-/* EXMC NOR/SRAM initialize struct */
+/* EXMC NOR/SRAM initialize structure */
typedef struct
{
uint32_t norsram_region; /*!< select the region of EXMC NOR/SRAM bank */
@@ -248,7 +273,7 @@ typedef struct
uint32_t databus_width; /*!< specifies the databus width of external memory */
uint32_t memory_type; /*!< specifies the type of external memory */
uint32_t address_data_mux; /*!< specifies whether the data bus and address bus are multiplexed */
- exmc_norsram_timing_parameter_struct* read_write_timing; /*!< timing parameters for read and write if the extendedmode is not used or the timing
+ exmc_norsram_timing_parameter_struct* read_write_timing; /*!< timing parameters for read and write if the extendedmode is not used or the timing
parameters for read if the extendedmode is used. */
exmc_norsram_timing_parameter_struct* write_timing; /*!< timing parameters for write when the extendedmode is used. */
}exmc_norsram_parameter_struct;
@@ -265,15 +290,15 @@ typedef struct
/* EXMC NAND initialize struct */
typedef struct
{
- uint32_t nand_bank; /*!< select the bank of NAND */
+ uint32_t nand_bank; /*!< select the bank of NAND */
uint32_t ecc_size; /*!< the page size for the ECC calculation */
uint32_t atr_latency; /*!< configure the latency of ALE low to RB low */
uint32_t ctr_latency; /*!< configure the latency of CLE low to RB low */
uint32_t ecc_logic; /*!< enable or disable the ECC calculation logic */
uint32_t databus_width; /*!< the NAND flash databus width */
- uint32_t wait_feature; /*!< enables or disables the wait feature */
- exmc_nand_pccard_timing_parameter_struct* common_space_timing; /*!< the timing parameters for NAND flash Common Space */
- exmc_nand_pccard_timing_parameter_struct* attribute_space_timing; /*!< the timing parameters for NAND flash Attribute Space */
+ uint32_t wait_feature; /*!< enable or disable the wait feature */
+ exmc_nand_pccard_timing_parameter_struct* common_space_timing; /*!< the timing parameters for NAND flash common space */
+ exmc_nand_pccard_timing_parameter_struct* attribute_space_timing; /*!< the timing parameters for NAND flash attribute space */
}exmc_nand_parameter_struct;
/* EXMC PC card initialize struct */
@@ -281,11 +306,11 @@ typedef struct
{
uint32_t atr_latency; /*!< configure the latency of ALE low to RB low */
uint32_t ctr_latency; /*!< configure the latency of CLE low to RB low */
- uint32_t wait_feature; /*!< enables or disables the Wait feature */
- exmc_nand_pccard_timing_parameter_struct* common_space_timing; /*!< the timing parameters for NAND flash Common Space */
- exmc_nand_pccard_timing_parameter_struct* attribute_space_timing; /*!< the timing parameters for NAND flash Attribute Space */
- exmc_nand_pccard_timing_parameter_struct* io_space_timing; /*!< the timing parameters for NAND flash IO Space */
-}exmc_pccard_parameter_struct;;
+ uint32_t wait_feature; /*!< enable or disable the wait feature */
+ exmc_nand_pccard_timing_parameter_struct* common_space_timing; /*!< the timing parameters for PC card common space */
+ exmc_nand_pccard_timing_parameter_struct* attribute_space_timing; /*!< the timing parameters for PC card attribute space */
+ exmc_nand_pccard_timing_parameter_struct* io_space_timing; /*!< the timing parameters for PC card IO space */
+}exmc_pccard_parameter_struct;
/* EXMC SDRAM timing initialize struct */
typedef struct
@@ -293,7 +318,7 @@ typedef struct
uint32_t row_to_column_delay; /*!< configure the row to column delay */
uint32_t row_precharge_delay; /*!< configure the row precharge delay */
uint32_t write_recovery_delay; /*!< configure the write recovery delay */
- uint32_t auto_refresh_delay; /*!< configure the auto refresh delay */
+ uint32_t auto_refresh_delay; /*!< configure the auto refresh delay */
uint32_t row_address_select_delay; /*!< configure the row address select delay */
uint32_t exit_selfrefresh_delay; /*!< configure the exit self-refresh delay */
uint32_t load_mode_register_delay; /*!< configure the load mode register delay */
@@ -308,7 +333,7 @@ typedef struct
uint32_t sdclock_config; /*!< the SDCLK memory clock for both SDRAM banks */
uint32_t write_protection; /*!< enable or disable SDRAM bank write protection function */
uint32_t cas_latency; /*!< configure the SDRAM CAS latency */
- uint32_t internal_bank_number; /*!< the number internal banks */
+ uint32_t internal_bank_number; /*!< the number of internal bank */
uint32_t data_width; /*!< the databus width of SDRAM memory */
uint32_t row_address_width; /*!< the bit width of a row address */
uint32_t column_address_width; /*!< the bit width of a column address */
@@ -333,400 +358,414 @@ typedef struct{
}exmc_sqpipsram_parameter_struct;
/* EXMC_register address */
-#define EXMC_SNCTL(bank) REG32(EXMC + 0x08U*((uint32_t)(bank))) /*!< EXMC SRAM/NOR flash control register */
-#define EXMC_SNTCFG(bank) REG32(EXMC + 0x04U + 0x08U*(bank)) /*!< EXMC SRAM/NOR flash timing configuration register */
-#define EXMC_SNWTCFG(bank) REG32(EXMC + 0x104U + 0x08U*(bank)) /*!< EXMC SRAM/NOR flash write timing configuration register */
+#define EXMC_SNCTL(region) REG32(EXMC + 0x08U*((uint32_t)(region))) /*!< EXMC SRAM/NOR flash control registers, region = 0,1,2,3 */
+#define EXMC_SNTCFG(region) REG32(EXMC + 0x04U + 0x08U*((uint32_t)(region))) /*!< EXMC SRAM/NOR flash timing configuration registers, region = 0,1,2,3 */
+#define EXMC_SNWTCFG(region) REG32(EXMC + 0x104U + 0x08U*((uint32_t)(region))) /*!< EXMC SRAM/NOR flash write timing configuration registers, region = 0,1,2,3 */
-#define EXMC_NPCTL(bank) REG32(EXMC + 0x40U + 0x20U*(bank)) /*!< EXMC NAND/PC card control register */
-#define EXMC_NPINTEN(bank) REG32(EXMC + 0x44U + 0x20U*(bank)) /*!< EXMC NAND/PC card interrupt enable register */
-#define EXMC_NPCTCFG(bank) REG32(EXMC + 0x48U + 0x20U*(bank)) /*!< EXMC NAND/PC card common space timing configuration register */
-#define EXMC_NPATCFG(bank) REG32(EXMC + 0x4CU + 0x20U*(bank)) /*!< EXMC NAND/PC card attribute space timing configuration register */
-#define EXMC_NECC(bank) REG32(EXMC + 0x54U + 0x20U*(bank)) /*!< EXMC NAND ECC register */
+#define EXMC_NPCTL(bank) REG32(EXMC + 0x40U + 0x20U*((uint32_t)(bank))) /*!< EXMC NAND/PC card control registers, bank = 1,2,3 */
+#define EXMC_NPINTEN(bank) REG32(EXMC + 0x44U + 0x20U*((uint32_t)(bank))) /*!< EXMC NAND/PC card interrupt enable registers, bank = 1,2,3 */
+#define EXMC_NPCTCFG(bank) REG32(EXMC + 0x48U + 0x20U*((uint32_t)(bank))) /*!< EXMC NAND/PC card common space timing configuration registers, bank = 1,2,3 */
+#define EXMC_NPATCFG(bank) REG32(EXMC + 0x4CU + 0x20U*((uint32_t)(bank))) /*!< EXMC NAND/PC card attribute space timing configuration registers, bank = 1,2,3 */
+#define EXMC_NECC(bank) REG32(EXMC + 0x54U + 0x20U*((uint32_t)(bank))) /*!< EXMC NAND ECC registers, bank = 1,2 */
-#define EXMC_SDCTL(bank) REG32(EXMC + 0x140U + 0x4U*((bank) - 0x4U)) /*!< EXMC SDRAM control register */
-#define EXMC_SDTCFG(bank) REG32(EXMC + 0x148U + 0x4U*((bank) - 0x4U)) /*!< EXMC SDRAM timing configuration register */
+#define EXMC_SDCTL(device) REG32(EXMC + 0x140U + 0x4U*(((uint32_t)(device)) - 0x4U)) /*!< EXMC SDRAM control registers,device = 0,1 */
+#define EXMC_SDTCFG(device) REG32(EXMC + 0x148U + 0x4U*(((uint32_t)(device)) - 0x4U)) /*!< EXMC SDRAM timing configuration registers,device = 0,1 */
/* CRAM page size */
-#define SNCTL_CPS(regval) (BITS(16,18) & ((uint32_t)(regval) << 16))
-#define EXMC_CRAM_AUTO_SPLIT SNCTL_CPS(0) /*!< automatic burst split on page boundary crossing */
-#define EXMC_CRAM_PAGE_SIZE_128_BYTES SNCTL_CPS(1) /*!< page size is 128 bytes */
-#define EXMC_CRAM_PAGE_SIZE_256_BYTES SNCTL_CPS(2) /*!< page size is 256 bytes */
-#define EXMC_CRAM_PAGE_SIZE_512_BYTES SNCTL_CPS(3) /*!< page size is 512 bytes */
-#define EXMC_CRAM_PAGE_SIZE_1024_BYTES SNCTL_CPS(4) /*!< page size is 1024 bytes */
+#define SNCTL_CPS(regval) (BITS(16,18) & ((uint32_t)(regval) << 16))
+#define EXMC_CRAM_AUTO_SPLIT SNCTL_CPS(0) /*!< automatic burst split on page boundary crossing */
+#define EXMC_CRAM_PAGE_SIZE_128_BYTES SNCTL_CPS(1) /*!< page size is 128 bytes */
+#define EXMC_CRAM_PAGE_SIZE_256_BYTES SNCTL_CPS(2) /*!< page size is 256 bytes */
+#define EXMC_CRAM_PAGE_SIZE_512_BYTES SNCTL_CPS(3) /*!< page size is 512 bytes */
+#define EXMC_CRAM_PAGE_SIZE_1024_BYTES SNCTL_CPS(4) /*!< page size is 1024 bytes */
/* NOR bank memory data bus width */
-#define SNCTL_NRW(regval) (BITS(4,5) & ((uint32_t)(regval) << 4))
-#define EXMC_NOR_DATABUS_WIDTH_8B SNCTL_NRW(0) /*!< NOR data width 8 bits */
-#define EXMC_NOR_DATABUS_WIDTH_16B SNCTL_NRW(1) /*!< NOR data width 16 bits */
+#define SNCTL_NRW(regval) (BITS(4,5) & ((uint32_t)(regval) << 4))
+#define EXMC_NOR_DATABUS_WIDTH_8B SNCTL_NRW(0) /*!< NOR data width is 8 bits */
+#define EXMC_NOR_DATABUS_WIDTH_16B SNCTL_NRW(1) /*!< NOR data width is 16 bits */
/* NOR bank memory type */
-#define SNCTL_NRTP(regval) (BITS(2,3) & ((uint32_t)(regval) << 2))
-#define EXMC_MEMORY_TYPE_SRAM SNCTL_NRTP(0) /*!< SRAM,ROM */
-#define EXMC_MEMORY_TYPE_PSRAM SNCTL_NRTP(1) /*!< PSRAM,CRAM */
-#define EXMC_MEMORY_TYPE_NOR SNCTL_NRTP(2) /*!< NOR flash */
+#define SNCTL_NRTP(regval) (BITS(2,3) & ((uint32_t)(regval) << 2))
+#define EXMC_MEMORY_TYPE_SRAM SNCTL_NRTP(0) /*!< SRAM,ROM */
+#define EXMC_MEMORY_TYPE_PSRAM SNCTL_NRTP(1) /*!< PSRAM,CRAM */
+#define EXMC_MEMORY_TYPE_NOR SNCTL_NRTP(2) /*!< NOR flash */
/* asynchronous access mode */
-#define SNTCFG_ASYNCMOD(regval) (BITS(28,29) & ((uint32_t)(regval) << 28))
-#define EXMC_ACCESS_MODE_A SNTCFG_ASYNCMOD(0) /*!< mode A access */
-#define EXMC_ACCESS_MODE_B SNTCFG_ASYNCMOD(1) /*!< mode B access */
-#define EXMC_ACCESS_MODE_C SNTCFG_ASYNCMOD(2) /*!< mode C access */
-#define EXMC_ACCESS_MODE_D SNTCFG_ASYNCMOD(3) /*!< mode D access */
+#define SNTCFG_ASYNCMOD(regval) (BITS(28,29) & ((uint32_t)(regval) << 28))
+#define EXMC_ACCESS_MODE_A SNTCFG_ASYNCMOD(0) /*!< mode A access */
+#define EXMC_ACCESS_MODE_B SNTCFG_ASYNCMOD(1) /*!< mode B access */
+#define EXMC_ACCESS_MODE_C SNTCFG_ASYNCMOD(2) /*!< mode C access */
+#define EXMC_ACCESS_MODE_D SNTCFG_ASYNCMOD(3) /*!< mode D access */
/* data latency for NOR flash */
-#define SNTCFG_DLAT(regval) (BITS(24,27) & ((uint32_t)(regval) << 24))
-#define EXMC_DATALAT_2_CLK SNTCFG_DLAT(0) /*!< data latency 2 EXMC_CLK */
-#define EXMC_DATALAT_3_CLK SNTCFG_DLAT(1) /*!< data latency 3 EXMC_CLK */
-#define EXMC_DATALAT_4_CLK SNTCFG_DLAT(2) /*!< data latency 4 EXMC_CLK */
-#define EXMC_DATALAT_5_CLK SNTCFG_DLAT(3) /*!< data latency 5 EXMC_CLK */
-#define EXMC_DATALAT_6_CLK SNTCFG_DLAT(4) /*!< data latency 6 EXMC_CLK */
-#define EXMC_DATALAT_7_CLK SNTCFG_DLAT(5) /*!< data latency 7 EXMC_CLK */
-#define EXMC_DATALAT_8_CLK SNTCFG_DLAT(6) /*!< data latency 8 EXMC_CLK */
-#define EXMC_DATALAT_9_CLK SNTCFG_DLAT(7) /*!< data latency 9 EXMC_CLK */
-#define EXMC_DATALAT_10_CLK SNTCFG_DLAT(8) /*!< data latency 10 EXMC_CLK */
-#define EXMC_DATALAT_11_CLK SNTCFG_DLAT(9) /*!< data latency 11 EXMC_CLK */
-#define EXMC_DATALAT_12_CLK SNTCFG_DLAT(10) /*!< data latency 12 EXMC_CLK */
-#define EXMC_DATALAT_13_CLK SNTCFG_DLAT(11) /*!< data latency 13 EXMC_CLK */
-#define EXMC_DATALAT_14_CLK SNTCFG_DLAT(12) /*!< data latency 14 EXMC_CLK */
-#define EXMC_DATALAT_15_CLK SNTCFG_DLAT(13) /*!< data latency 15 EXMC_CLK */
-#define EXMC_DATALAT_16_CLK SNTCFG_DLAT(14) /*!< data latency 16 EXMC_CLK */
-#define EXMC_DATALAT_17_CLK SNTCFG_DLAT(15) /*!< data latency 17 EXMC_CLK */
+#define SNTCFG_DLAT(regval) (BITS(24,27) & ((uint32_t)(regval) << 24))
+#define EXMC_DATALAT_2_CLK SNTCFG_DLAT(0) /*!< data latency of first burst access is 2 EXMC_CLK */
+#define EXMC_DATALAT_3_CLK SNTCFG_DLAT(1) /*!< data latency of first burst access is 3 EXMC_CLK */
+#define EXMC_DATALAT_4_CLK SNTCFG_DLAT(2) /*!< data latency of first burst access is 4 EXMC_CLK */
+#define EXMC_DATALAT_5_CLK SNTCFG_DLAT(3) /*!< data latency of first burst access is 5 EXMC_CLK */
+#define EXMC_DATALAT_6_CLK SNTCFG_DLAT(4) /*!< data latency of first burst access is 6 EXMC_CLK */
+#define EXMC_DATALAT_7_CLK SNTCFG_DLAT(5) /*!< data latency of first burst access is 7 EXMC_CLK */
+#define EXMC_DATALAT_8_CLK SNTCFG_DLAT(6) /*!< data latency of first burst access is 8 EXMC_CLK */
+#define EXMC_DATALAT_9_CLK SNTCFG_DLAT(7) /*!< data latency of first burst access is 9 EXMC_CLK */
+#define EXMC_DATALAT_10_CLK SNTCFG_DLAT(8) /*!< data latency of first burst access is 10 EXMC_CLK */
+#define EXMC_DATALAT_11_CLK SNTCFG_DLAT(9) /*!< data latency of first burst access is 11 EXMC_CLK */
+#define EXMC_DATALAT_12_CLK SNTCFG_DLAT(10) /*!< data latency of first burst access is 12 EXMC_CLK */
+#define EXMC_DATALAT_13_CLK SNTCFG_DLAT(11) /*!< data latency of first burst access is 13 EXMC_CLK */
+#define EXMC_DATALAT_14_CLK SNTCFG_DLAT(12) /*!< data latency of first burst access is 14 EXMC_CLK */
+#define EXMC_DATALAT_15_CLK SNTCFG_DLAT(13) /*!< data latency of first burst access is 15 EXMC_CLK */
+#define EXMC_DATALAT_16_CLK SNTCFG_DLAT(14) /*!< data latency of first burst access is 16 EXMC_CLK */
+#define EXMC_DATALAT_17_CLK SNTCFG_DLAT(15) /*!< data latency of first burst access is 17 EXMC_CLK */
/* synchronous clock divide ratio */
-#define SNTCFG_CKDIV(regval) (BITS(20,23) & ((uint32_t)(regval) << 20))
-#define EXMC_SYN_CLOCK_RATIO_DISABLE SNTCFG_CKDIV(0) /*!< EXMC_CLK disable */
-#define EXMC_SYN_CLOCK_RATIO_2_CLK SNTCFG_CKDIV(1) /*!< EXMC_CLK = 2*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_3_CLK SNTCFG_CKDIV(2) /*!< EXMC_CLK = 3*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_4_CLK SNTCFG_CKDIV(3) /*!< EXMC_CLK = 4*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_5_CLK SNTCFG_CKDIV(4) /*!< EXMC_CLK = 5*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_6_CLK SNTCFG_CKDIV(5) /*!< EXMC_CLK = 6*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_7_CLK SNTCFG_CKDIV(6) /*!< EXMC_CLK = 7*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_8_CLK SNTCFG_CKDIV(7) /*!< EXMC_CLK = 8*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_9_CLK SNTCFG_CKDIV(8) /*!< EXMC_CLK = 9*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_10_CLK SNTCFG_CKDIV(9) /*!< EXMC_CLK = 10*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_11_CLK SNTCFG_CKDIV(10) /*!< EXMC_CLK = 11*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_12_CLK SNTCFG_CKDIV(11) /*!< EXMC_CLK = 12*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_13_CLK SNTCFG_CKDIV(12) /*!< EXMC_CLK = 13*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_14_CLK SNTCFG_CKDIV(13) /*!< EXMC_CLK = 14*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_15_CLK SNTCFG_CKDIV(14) /*!< EXMC_CLK = 15*HCLK */
-#define EXMC_SYN_CLOCK_RATIO_16_CLK SNTCFG_CKDIV(15) /*!< EXMC_CLK = 16*HCLK */
+#define SNTCFG_CKDIV(regval) (BITS(20,23) & ((uint32_t)(regval) << 20))
+#define EXMC_SYN_CLOCK_RATIO_2_CLK SNTCFG_CKDIV(1) /*!< EXMC_CLK = 2*HCLK */
+#define EXMC_SYN_CLOCK_RATIO_3_CLK SNTCFG_CKDIV(2) /*!< EXMC_CLK = 3*HCLK */
+#define EXMC_SYN_CLOCK_RATIO_4_CLK SNTCFG_CKDIV(3) /*!< EXMC_CLK = 4*HCLK */
+#define EXMC_SYN_CLOCK_RATIO_5_CLK SNTCFG_CKDIV(4) /*!< EXMC_CLK = 5*HCLK */
+#define EXMC_SYN_CLOCK_RATIO_6_CLK SNTCFG_CKDIV(5) /*!< EXMC_CLK = 6*HCLK */
+#define EXMC_SYN_CLOCK_RATIO_7_CLK SNTCFG_CKDIV(6) /*!< EXMC_CLK = 7*HCLK */
+#define EXMC_SYN_CLOCK_RATIO_8_CLK SNTCFG_CKDIV(7) /*!< EXMC_CLK = 8*HCLK */
+#define EXMC_SYN_CLOCK_RATIO_9_CLK SNTCFG_CKDIV(8) /*!< EXMC_CLK = 9*HCLK */
+#define EXMC_SYN_CLOCK_RATIO_10_CLK SNTCFG_CKDIV(9) /*!< EXMC_CLK = 10*HCLK */
+#define EXMC_SYN_CLOCK_RATIO_11_CLK SNTCFG_CKDIV(10) /*!< EXMC_CLK = 11*HCLK */
+#define EXMC_SYN_CLOCK_RATIO_12_CLK SNTCFG_CKDIV(11) /*!< EXMC_CLK = 12*HCLK */
+#define EXMC_SYN_CLOCK_RATIO_13_CLK SNTCFG_CKDIV(12) /*!< EXMC_CLK = 13*HCLK */
+#define EXMC_SYN_CLOCK_RATIO_14_CLK SNTCFG_CKDIV(13) /*!< EXMC_CLK = 14*HCLK */
+#define EXMC_SYN_CLOCK_RATIO_15_CLK SNTCFG_CKDIV(14) /*!< EXMC_CLK = 15*HCLK */
+#define EXMC_SYN_CLOCK_RATIO_16_CLK SNTCFG_CKDIV(15) /*!< EXMC_CLK = 16*HCLK */
/* ECC size */
-#define NPCTL_ECCSZ(regval) (BITS(17,19) & ((uint32_t)(regval) << 17))
-#define EXMC_ECC_SIZE_256BYTES NPCTL_ECCSZ(0) /* 256 bytes */
-#define EXMC_ECC_SIZE_512BYTES NPCTL_ECCSZ(1) /* 512 bytes */
-#define EXMC_ECC_SIZE_1024BYTES NPCTL_ECCSZ(2) /* 1024 bytes */
-#define EXMC_ECC_SIZE_2048BYTES NPCTL_ECCSZ(3) /* 2048 bytes */
-#define EXMC_ECC_SIZE_4096BYTES NPCTL_ECCSZ(4) /* 4096 bytes */
-#define EXMC_ECC_SIZE_8192BYTES NPCTL_ECCSZ(5) /* 8192 bytes */
+#define NPCTL_ECCSZ(regval) (BITS(17,19) & ((uint32_t)(regval) << 17))
+#define EXMC_ECC_SIZE_256BYTES NPCTL_ECCSZ(0) /* ECC size is 256 bytes */
+#define EXMC_ECC_SIZE_512BYTES NPCTL_ECCSZ(1) /* ECC size is 512 bytes */
+#define EXMC_ECC_SIZE_1024BYTES NPCTL_ECCSZ(2) /* ECC size is 1024 bytes */
+#define EXMC_ECC_SIZE_2048BYTES NPCTL_ECCSZ(3) /* ECC size is 2048 bytes */
+#define EXMC_ECC_SIZE_4096BYTES NPCTL_ECCSZ(4) /* ECC size is 4096 bytes */
+#define EXMC_ECC_SIZE_8192BYTES NPCTL_ECCSZ(5) /* ECC size is 8192 bytes */
/* ALE to RE delay */
-#define NPCTL_ATR(regval) (BITS(13,16) & ((uint32_t)(regval) << 13))
-#define EXMC_ALE_RE_DELAY_1_HCLK NPCTL_ATR(0) /* ALE to RE delay = 1*HCLK */
-#define EXMC_ALE_RE_DELAY_2_HCLK NPCTL_ATR(1) /* ALE to RE delay = 2*HCLK */
-#define EXMC_ALE_RE_DELAY_3_HCLK NPCTL_ATR(2) /* ALE to RE delay = 3*HCLK */
-#define EXMC_ALE_RE_DELAY_4_HCLK NPCTL_ATR(3) /* ALE to RE delay = 4*HCLK */
-#define EXMC_ALE_RE_DELAY_5_HCLK NPCTL_ATR(4) /* ALE to RE delay = 5*HCLK */
-#define EXMC_ALE_RE_DELAY_6_HCLK NPCTL_ATR(5) /* ALE to RE delay = 6*HCLK */
-#define EXMC_ALE_RE_DELAY_7_HCLK NPCTL_ATR(6) /* ALE to RE delay = 7*HCLK */
-#define EXMC_ALE_RE_DELAY_8_HCLK NPCTL_ATR(7) /* ALE to RE delay = 8*HCLK */
-#define EXMC_ALE_RE_DELAY_9_HCLK NPCTL_ATR(8) /* ALE to RE delay = 9*HCLK */
-#define EXMC_ALE_RE_DELAY_10_HCLK NPCTL_ATR(9) /* ALE to RE delay = 10*HCLK */
-#define EXMC_ALE_RE_DELAY_11_HCLK NPCTL_ATR(10) /* ALE to RE delay = 11*HCLK */
-#define EXMC_ALE_RE_DELAY_12_HCLK NPCTL_ATR(11) /* ALE to RE delay = 12*HCLK */
-#define EXMC_ALE_RE_DELAY_13_HCLK NPCTL_ATR(12) /* ALE to RE delay = 13*HCLK */
-#define EXMC_ALE_RE_DELAY_14_HCLK NPCTL_ATR(13) /* ALE to RE delay = 14*HCLK */
-#define EXMC_ALE_RE_DELAY_15_HCLK NPCTL_ATR(14) /* ALE to RE delay = 15*HCLK */
-#define EXMC_ALE_RE_DELAY_16_HCLK NPCTL_ATR(15) /* ALE to RE delay = 16*HCLK */
+#define NPCTL_ATR(regval) (BITS(13,16) & ((uint32_t)(regval) << 13))
+#define EXMC_ALE_RE_DELAY_1_HCLK NPCTL_ATR(0) /* ALE to RE delay = 1*HCLK */
+#define EXMC_ALE_RE_DELAY_2_HCLK NPCTL_ATR(1) /* ALE to RE delay = 2*HCLK */
+#define EXMC_ALE_RE_DELAY_3_HCLK NPCTL_ATR(2) /* ALE to RE delay = 3*HCLK */
+#define EXMC_ALE_RE_DELAY_4_HCLK NPCTL_ATR(3) /* ALE to RE delay = 4*HCLK */
+#define EXMC_ALE_RE_DELAY_5_HCLK NPCTL_ATR(4) /* ALE to RE delay = 5*HCLK */
+#define EXMC_ALE_RE_DELAY_6_HCLK NPCTL_ATR(5) /* ALE to RE delay = 6*HCLK */
+#define EXMC_ALE_RE_DELAY_7_HCLK NPCTL_ATR(6) /* ALE to RE delay = 7*HCLK */
+#define EXMC_ALE_RE_DELAY_8_HCLK NPCTL_ATR(7) /* ALE to RE delay = 8*HCLK */
+#define EXMC_ALE_RE_DELAY_9_HCLK NPCTL_ATR(8) /* ALE to RE delay = 9*HCLK */
+#define EXMC_ALE_RE_DELAY_10_HCLK NPCTL_ATR(9) /* ALE to RE delay = 10*HCLK */
+#define EXMC_ALE_RE_DELAY_11_HCLK NPCTL_ATR(10) /* ALE to RE delay = 11*HCLK */
+#define EXMC_ALE_RE_DELAY_12_HCLK NPCTL_ATR(11) /* ALE to RE delay = 12*HCLK */
+#define EXMC_ALE_RE_DELAY_13_HCLK NPCTL_ATR(12) /* ALE to RE delay = 13*HCLK */
+#define EXMC_ALE_RE_DELAY_14_HCLK NPCTL_ATR(13) /* ALE to RE delay = 14*HCLK */
+#define EXMC_ALE_RE_DELAY_15_HCLK NPCTL_ATR(14) /* ALE to RE delay = 15*HCLK */
+#define EXMC_ALE_RE_DELAY_16_HCLK NPCTL_ATR(15) /* ALE to RE delay = 16*HCLK */
/* CLE to RE delay */
-#define NPCTL_CTR(regval) (BITS(9,12) & ((uint32_t)(regval) << 9))
-#define EXMC_CLE_RE_DELAY_1_HCLK NPCTL_CTR(0) /* CLE to RE delay = 1*HCLK */
-#define EXMC_CLE_RE_DELAY_2_HCLK NPCTL_CTR(1) /* CLE to RE delay = 2*HCLK */
-#define EXMC_CLE_RE_DELAY_3_HCLK NPCTL_CTR(2) /* CLE to RE delay = 3*HCLK */
-#define EXMC_CLE_RE_DELAY_4_HCLK NPCTL_CTR(3) /* CLE to RE delay = 4*HCLK */
-#define EXMC_CLE_RE_DELAY_5_HCLK NPCTL_CTR(4) /* CLE to RE delay = 5*HCLK */
-#define EXMC_CLE_RE_DELAY_6_HCLK NPCTL_CTR(5) /* CLE to RE delay = 6*HCLK */
-#define EXMC_CLE_RE_DELAY_7_HCLK NPCTL_CTR(6) /* CLE to RE delay = 7*HCLK */
-#define EXMC_CLE_RE_DELAY_8_HCLK NPCTL_CTR(7) /* CLE to RE delay = 8*HCLK */
-#define EXMC_CLE_RE_DELAY_9_HCLK NPCTL_CTR(8) /* CLE to RE delay = 9*HCLK */
-#define EXMC_CLE_RE_DELAY_10_HCLK NPCTL_CTR(9) /* CLE to RE delay = 10*HCLK */
-#define EXMC_CLE_RE_DELAY_11_HCLK NPCTL_CTR(10) /* CLE to RE delay = 11*HCLK */
-#define EXMC_CLE_RE_DELAY_12_HCLK NPCTL_CTR(11) /* CLE to RE delay = 12*HCLK */
-#define EXMC_CLE_RE_DELAY_13_HCLK NPCTL_CTR(12) /* CLE to RE delay = 13*HCLK */
-#define EXMC_CLE_RE_DELAY_14_HCLK NPCTL_CTR(13) /* CLE to RE delay = 14*HCLK */
-#define EXMC_CLE_RE_DELAY_15_HCLK NPCTL_CTR(14) /* CLE to RE delay = 15*HCLK */
-#define EXMC_CLE_RE_DELAY_16_HCLK NPCTL_CTR(15) /* CLE to RE delay = 16*HCLK */
+#define NPCTL_CTR(regval) (BITS(9,12) & ((uint32_t)(regval) << 9))
+#define EXMC_CLE_RE_DELAY_1_HCLK NPCTL_CTR(0) /* CLE to RE delay = 1*HCLK */
+#define EXMC_CLE_RE_DELAY_2_HCLK NPCTL_CTR(1) /* CLE to RE delay = 2*HCLK */
+#define EXMC_CLE_RE_DELAY_3_HCLK NPCTL_CTR(2) /* CLE to RE delay = 3*HCLK */
+#define EXMC_CLE_RE_DELAY_4_HCLK NPCTL_CTR(3) /* CLE to RE delay = 4*HCLK */
+#define EXMC_CLE_RE_DELAY_5_HCLK NPCTL_CTR(4) /* CLE to RE delay = 5*HCLK */
+#define EXMC_CLE_RE_DELAY_6_HCLK NPCTL_CTR(5) /* CLE to RE delay = 6*HCLK */
+#define EXMC_CLE_RE_DELAY_7_HCLK NPCTL_CTR(6) /* CLE to RE delay = 7*HCLK */
+#define EXMC_CLE_RE_DELAY_8_HCLK NPCTL_CTR(7) /* CLE to RE delay = 8*HCLK */
+#define EXMC_CLE_RE_DELAY_9_HCLK NPCTL_CTR(8) /* CLE to RE delay = 9*HCLK */
+#define EXMC_CLE_RE_DELAY_10_HCLK NPCTL_CTR(9) /* CLE to RE delay = 10*HCLK */
+#define EXMC_CLE_RE_DELAY_11_HCLK NPCTL_CTR(10) /* CLE to RE delay = 11*HCLK */
+#define EXMC_CLE_RE_DELAY_12_HCLK NPCTL_CTR(11) /* CLE to RE delay = 12*HCLK */
+#define EXMC_CLE_RE_DELAY_13_HCLK NPCTL_CTR(12) /* CLE to RE delay = 13*HCLK */
+#define EXMC_CLE_RE_DELAY_14_HCLK NPCTL_CTR(13) /* CLE to RE delay = 14*HCLK */
+#define EXMC_CLE_RE_DELAY_15_HCLK NPCTL_CTR(14) /* CLE to RE delay = 15*HCLK */
+#define EXMC_CLE_RE_DELAY_16_HCLK NPCTL_CTR(15) /* CLE to RE delay = 16*HCLK */
/* NAND bank memory data bus width */
-#define NPCTL_NDW(regval) (BITS(4,5) & ((uint32_t)(regval) << 4))
-#define EXMC_NAND_DATABUS_WIDTH_8B NPCTL_NDW(0) /*!< NAND data width 8 bits */
-#define EXMC_NAND_DATABUS_WIDTH_16B NPCTL_NDW(1) /*!< NAND data width 16 bits */
+#define NPCTL_NDW(regval) (BITS(4,5) & ((uint32_t)(regval) << 4))
+#define EXMC_NAND_DATABUS_WIDTH_8B NPCTL_NDW(0) /*!< NAND data width is 8 bits */
+#define EXMC_NAND_DATABUS_WIDTH_16B NPCTL_NDW(1) /*!< NAND data width is 16 bits */
/* SDRAM pipeline delay */
-#define SDCTL_PIPED(regval) (BITS(13,14) & ((uint32_t)(regval) << 13))
-#define EXMC_PIPELINE_DELAY_0_HCLK SDCTL_PIPED(0) /*!< 0 HCLK clock cycle delay */
-#define EXMC_PIPELINE_DELAY_1_HCLK SDCTL_PIPED(1) /*!< 1 HCLK clock cycle delay */
-#define EXMC_PIPELINE_DELAY_2_HCLK SDCTL_PIPED(2) /*!< 2 HCLK clock cycle delay */
+#define SDCTL_PIPED(regval) (BITS(13,14) & ((uint32_t)(regval) << 13))
+#define EXMC_PIPELINE_DELAY_0_HCLK SDCTL_PIPED(0) /*!< 0 HCLK clock cycle delay */
+#define EXMC_PIPELINE_DELAY_1_HCLK SDCTL_PIPED(1) /*!< 1 HCLK clock cycle delay */
+#define EXMC_PIPELINE_DELAY_2_HCLK SDCTL_PIPED(2) /*!< 2 HCLK clock cycle delay */
/* SDRAM clock configuration */
-#define SDCTL_SDCLK(regval) (BITS(10,11) & ((uint32_t)(regval) << 10))
-#define EXMC_SDCLK_DISABLE SDCTL_SDCLK(0) /*!< SDCLK memory clock disabled */
-#define EXMC_SDCLK_PERIODS_2_HCLK SDCTL_SDCLK(2) /*!< SDCLK memory period = 2*HCLK */
-#define EXMC_SDCLK_PERIODS_3_HCLK SDCTL_SDCLK(3) /*!< SDCLK memory period = 3*HCLK */
+#define SDCTL_SDCLK(regval) (BITS(10,11) & ((uint32_t)(regval) << 10))
+#define EXMC_SDCLK_DISABLE SDCTL_SDCLK(0) /*!< SDCLK memory clock disabled */
+#define EXMC_SDCLK_PERIODS_2_HCLK SDCTL_SDCLK(2) /*!< SDCLK memory period = 2*HCLK */
+#define EXMC_SDCLK_PERIODS_3_HCLK SDCTL_SDCLK(3) /*!< SDCLK memory period = 3*HCLK */
/* CAS latency */
-#define SDCTL_CL(regval) (BITS(7,8) & ((uint32_t)(regval) << 7))
-#define EXMC_CAS_LATENCY_1_SDCLK SDCTL_CL(1) /*!< CAS latency is 1 memory clock cycle */
-#define EXMC_CAS_LATENCY_2_SDCLK SDCTL_CL(2) /*!< CAS latency is 2 memory clock cycle */
-#define EXMC_CAS_LATENCY_3_SDCLK SDCTL_CL(3) /*!< CAS latency is 3 memory clock cycle */
+#define SDCTL_CL(regval) (BITS(7,8) & ((uint32_t)(regval) << 7))
+#define EXMC_CAS_LATENCY_1_SDCLK SDCTL_CL(1) /*!< CAS latency is 1 memory clock cycle */
+#define EXMC_CAS_LATENCY_2_SDCLK SDCTL_CL(2) /*!< CAS latency is 2 memory clock cycle */
+#define EXMC_CAS_LATENCY_3_SDCLK SDCTL_CL(3) /*!< CAS latency is 3 memory clock cycle */
/* SDRAM data bus width */
-#define SDCTL_SDW(regval) (BITS(4,5) & ((uint32_t)(regval) << 4))
-#define EXMC_SDRAM_DATABUS_WIDTH_8B SDCTL_SDW(0) /*!< SDRAM data width 8 bits */
-#define EXMC_SDRAM_DATABUS_WIDTH_16B SDCTL_SDW(1) /*!< SDRAM data width 16 bits */
-#define EXMC_SDRAM_DATABUS_WIDTH_32B SDCTL_SDW(2) /*!< SDRAM data width 32 bits */
+#define SDCTL_SDW(regval) (BITS(4,5) & ((uint32_t)(regval) << 4))
+#define EXMC_SDRAM_DATABUS_WIDTH_8B SDCTL_SDW(0) /*!< SDRAM data width 8 bits */
+#define EXMC_SDRAM_DATABUS_WIDTH_16B SDCTL_SDW(1) /*!< SDRAM data width 16 bits */
+#define EXMC_SDRAM_DATABUS_WIDTH_32B SDCTL_SDW(2) /*!< SDRAM data width 32 bits */
/* SDRAM row address bit width */
-#define SDCTL_RAW(regval) (BITS(2,3) & ((uint32_t)(regval) << 2))
-#define EXMC_SDRAM_ROW_ADDRESS_11 SDCTL_RAW(0) /*!< row address bit width is 11 bits */
-#define EXMC_SDRAM_ROW_ADDRESS_12 SDCTL_RAW(1) /*!< row address bit width is 12 bits */
-#define EXMC_SDRAM_ROW_ADDRESS_13 SDCTL_RAW(2) /*!< row address bit width is 13 bits */
+#define SDCTL_RAW(regval) (BITS(2,3) & ((uint32_t)(regval) << 2))
+#define EXMC_SDRAM_ROW_ADDRESS_11 SDCTL_RAW(0) /*!< row address bit width is 11 bits */
+#define EXMC_SDRAM_ROW_ADDRESS_12 SDCTL_RAW(1) /*!< row address bit width is 12 bits */
+#define EXMC_SDRAM_ROW_ADDRESS_13 SDCTL_RAW(2) /*!< row address bit width is 13 bits */
/* SDRAM column address bit width */
-#define SDCTL_CAW(regval) (BITS(0,1) & ((uint32_t)(regval) << 0))
-#define EXMC_SDRAM_COW_ADDRESS_8 SDCTL_CAW(0) /*!< column address bit width is 8 bits */
-#define EXMC_SDRAM_COW_ADDRESS_9 SDCTL_CAW(1) /*!< column address bit width is 9 bits */
-#define EXMC_SDRAM_COW_ADDRESS_10 SDCTL_CAW(2) /*!< column address bit width is 10 bits */
-#define EXMC_SDRAM_COW_ADDRESS_11 SDCTL_CAW(3) /*!< column address bit width is 11 bits */
+#define SDCTL_CAW(regval) (BITS(0,1) & ((uint32_t)(regval) << 0))
+#define EXMC_SDRAM_COW_ADDRESS_8 SDCTL_CAW(0) /*!< column address bit width is 8 bits */
+#define EXMC_SDRAM_COW_ADDRESS_9 SDCTL_CAW(1) /*!< column address bit width is 9 bits */
+#define EXMC_SDRAM_COW_ADDRESS_10 SDCTL_CAW(2) /*!< column address bit width is 10 bits */
+#define EXMC_SDRAM_COW_ADDRESS_11 SDCTL_CAW(3) /*!< column address bit width is 11 bits */
/* SDRAM number of successive auto-refresh */
-#define SDCMD_NARF(regval) (BITS(5,8) & ((uint32_t)(regval) << 5))
-#define EXMC_SDRAM_AUTO_REFLESH_1_SDCLK SDCMD_NARF(0) /*!< 1 auto-refresh cycle */
-#define EXMC_SDRAM_AUTO_REFLESH_2_SDCLK SDCMD_NARF(1) /*!< 2 auto-refresh cycles */
-#define EXMC_SDRAM_AUTO_REFLESH_3_SDCLK SDCMD_NARF(2) /*!< 3 auto-refresh cycles */
-#define EXMC_SDRAM_AUTO_REFLESH_4_SDCLK SDCMD_NARF(3) /*!< 4 auto-refresh cycles */
-#define EXMC_SDRAM_AUTO_REFLESH_5_SDCLK SDCMD_NARF(4) /*!< 5 auto-refresh cycles */
-#define EXMC_SDRAM_AUTO_REFLESH_6_SDCLK SDCMD_NARF(5) /*!< 6 auto-refresh cycles */
-#define EXMC_SDRAM_AUTO_REFLESH_7_SDCLK SDCMD_NARF(6) /*!< 7 auto-refresh cycles */
-#define EXMC_SDRAM_AUTO_REFLESH_8_SDCLK SDCMD_NARF(7) /*!< 8 auto-refresh cycles */
-#define EXMC_SDRAM_AUTO_REFLESH_9_SDCLK SDCMD_NARF(8) /*!< 9 auto-refresh cycles */
-#define EXMC_SDRAM_AUTO_REFLESH_10_SDCLK SDCMD_NARF(9) /*!< 10 auto-refresh cycles */
-#define EXMC_SDRAM_AUTO_REFLESH_11_SDCLK SDCMD_NARF(10) /*!< 11 auto-refresh cycles */
-#define EXMC_SDRAM_AUTO_REFLESH_12_SDCLK SDCMD_NARF(11) /*!< 12 auto-refresh cycles */
-#define EXMC_SDRAM_AUTO_REFLESH_13_SDCLK SDCMD_NARF(12) /*!< 13 auto-refresh cycles */
-#define EXMC_SDRAM_AUTO_REFLESH_14_SDCLK SDCMD_NARF(13) /*!< 14 auto-refresh cycles */
-#define EXMC_SDRAM_AUTO_REFLESH_15_SDCLK SDCMD_NARF(14) /*!< 15 auto-refresh cycles */
+#define SDCMD_NARF(regval) (BITS(5,8) & ((uint32_t)(regval) << 5))
+#define EXMC_SDRAM_AUTO_REFLESH_1_SDCLK SDCMD_NARF(0) /*!< 1 auto-refresh cycle */
+#define EXMC_SDRAM_AUTO_REFLESH_2_SDCLK SDCMD_NARF(1) /*!< 2 auto-refresh cycles */
+#define EXMC_SDRAM_AUTO_REFLESH_3_SDCLK SDCMD_NARF(2) /*!< 3 auto-refresh cycles */
+#define EXMC_SDRAM_AUTO_REFLESH_4_SDCLK SDCMD_NARF(3) /*!< 4 auto-refresh cycles */
+#define EXMC_SDRAM_AUTO_REFLESH_5_SDCLK SDCMD_NARF(4) /*!< 5 auto-refresh cycles */
+#define EXMC_SDRAM_AUTO_REFLESH_6_SDCLK SDCMD_NARF(5) /*!< 6 auto-refresh cycles */
+#define EXMC_SDRAM_AUTO_REFLESH_7_SDCLK SDCMD_NARF(6) /*!< 7 auto-refresh cycles */
+#define EXMC_SDRAM_AUTO_REFLESH_8_SDCLK SDCMD_NARF(7) /*!< 8 auto-refresh cycles */
+#define EXMC_SDRAM_AUTO_REFLESH_9_SDCLK SDCMD_NARF(8) /*!< 9 auto-refresh cycles */
+#define EXMC_SDRAM_AUTO_REFLESH_10_SDCLK SDCMD_NARF(9) /*!< 10 auto-refresh cycles */
+#define EXMC_SDRAM_AUTO_REFLESH_11_SDCLK SDCMD_NARF(10) /*!< 11 auto-refresh cycles */
+#define EXMC_SDRAM_AUTO_REFLESH_12_SDCLK SDCMD_NARF(11) /*!< 12 auto-refresh cycles */
+#define EXMC_SDRAM_AUTO_REFLESH_13_SDCLK SDCMD_NARF(12) /*!< 13 auto-refresh cycles */
+#define EXMC_SDRAM_AUTO_REFLESH_14_SDCLK SDCMD_NARF(13) /*!< 14 auto-refresh cycles */
+#define EXMC_SDRAM_AUTO_REFLESH_15_SDCLK SDCMD_NARF(14) /*!< 15 auto-refresh cycles */
/* SDRAM command select */
-#define SDCMD_CMD(regval) (BITS(0,2) & ((uint32_t)(regval) << 0))
-#define EXMC_SDRAM_NORMAL_OPERATION SDCMD_CMD(0) /*!< normal operation command */
-#define EXMC_SDRAM_CLOCK_ENABLE SDCMD_CMD(1) /*!< clock enable command */
-#define EXMC_SDRAM_PRECHARGE_ALL SDCMD_CMD(2) /*!< precharge all command */
-#define EXMC_SDRAM_AUTO_REFRESH SDCMD_CMD(3) /*!< auto-refresh command */
-#define EXMC_SDRAM_LOAD_MODE_REGISTER SDCMD_CMD(4) /*!< load mode register command */
-#define EXMC_SDRAM_SELF_REFRESH SDCMD_CMD(5) /*!< self-refresh command */
-#define EXMC_SDRAM_POWERDOWN_ENTRY SDCMD_CMD(6) /*!< power-down entry command */
+#define SDCMD_CMD(regval) (BITS(0,2) & ((uint32_t)(regval) << 0))
+#define EXMC_SDRAM_NORMAL_OPERATION SDCMD_CMD(0) /*!< normal operation command */
+#define EXMC_SDRAM_CLOCK_ENABLE SDCMD_CMD(1) /*!< clock enable command */
+#define EXMC_SDRAM_PRECHARGE_ALL SDCMD_CMD(2) /*!< precharge all command */
+#define EXMC_SDRAM_AUTO_REFRESH SDCMD_CMD(3) /*!< auto-refresh command */
+#define EXMC_SDRAM_LOAD_MODE_REGISTER SDCMD_CMD(4) /*!< load mode register command */
+#define EXMC_SDRAM_SELF_REFRESH SDCMD_CMD(5) /*!< self-refresh command */
+#define EXMC_SDRAM_POWERDOWN_ENTRY SDCMD_CMD(6) /*!< power-down entry command */
/* SDRAM the delayed sample clock of read data */
-#define SDRSCTL_SDSC(regval) (BITS(4,7) & ((uint32_t)(regval) << 4))
-#define EXMC_SDRAM_0_DELAY_CELL SDRSCTL_SDSC(0) /*!< select the clock after 0 delay cell */
-#define EXMC_SDRAM_1_DELAY_CELL SDRSCTL_SDSC(1) /*!< select the clock after 1 delay cell */
-#define EXMC_SDRAM_2_DELAY_CELL SDRSCTL_SDSC(2) /*!< select the clock after 2 delay cell */
-#define EXMC_SDRAM_3_DELAY_CELL SDRSCTL_SDSC(3) /*!< select the clock after 3 delay cell */
-#define EXMC_SDRAM_4_DELAY_CELL SDRSCTL_SDSC(4) /*!< select the clock after 4 delay cell */
-#define EXMC_SDRAM_5_DELAY_CELL SDRSCTL_SDSC(5) /*!< select the clock after 5 delay cell */
-#define EXMC_SDRAM_6_DELAY_CELL SDRSCTL_SDSC(6) /*!< select the clock after 6 delay cell */
-#define EXMC_SDRAM_7_DELAY_CELL SDRSCTL_SDSC(7) /*!< select the clock after 7 delay cell */
-#define EXMC_SDRAM_8_DELAY_CELL SDRSCTL_SDSC(8) /*!< select the clock after 8 delay cell */
-#define EXMC_SDRAM_9_DELAY_CELL SDRSCTL_SDSC(9) /*!< select the clock after 9 delay cell */
-#define EXMC_SDRAM_10_DELAY_CELL SDRSCTL_SDSC(10) /*!< select the clock after 10 delay cell */
-#define EXMC_SDRAM_11_DELAY_CELL SDRSCTL_SDSC(11) /*!< select the clock after 11 delay cell */
-#define EXMC_SDRAM_12_DELAY_CELL SDRSCTL_SDSC(12) /*!< select the clock after 12 delay cell */
-#define EXMC_SDRAM_13_DELAY_CELL SDRSCTL_SDSC(13) /*!< select the clock after 13 delay cell */
-#define EXMC_SDRAM_14_DELAY_CELL SDRSCTL_SDSC(14) /*!< select the clock after 14 delay cell */
-#define EXMC_SDRAM_15_DELAY_CELL SDRSCTL_SDSC(15) /*!< select the clock after 15 delay cell */
+#define SDRSCTL_SDSC(regval) (BITS(4,7) & ((uint32_t)(regval) << 4))
+#define EXMC_SDRAM_0_DELAY_CELL SDRSCTL_SDSC(0) /*!< select the clock after 0 delay cell */
+#define EXMC_SDRAM_1_DELAY_CELL SDRSCTL_SDSC(1) /*!< select the clock after 1 delay cell */
+#define EXMC_SDRAM_2_DELAY_CELL SDRSCTL_SDSC(2) /*!< select the clock after 2 delay cell */
+#define EXMC_SDRAM_3_DELAY_CELL SDRSCTL_SDSC(3) /*!< select the clock after 3 delay cell */
+#define EXMC_SDRAM_4_DELAY_CELL SDRSCTL_SDSC(4) /*!< select the clock after 4 delay cell */
+#define EXMC_SDRAM_5_DELAY_CELL SDRSCTL_SDSC(5) /*!< select the clock after 5 delay cell */
+#define EXMC_SDRAM_6_DELAY_CELL SDRSCTL_SDSC(6) /*!< select the clock after 6 delay cell */
+#define EXMC_SDRAM_7_DELAY_CELL SDRSCTL_SDSC(7) /*!< select the clock after 7 delay cell */
+#define EXMC_SDRAM_8_DELAY_CELL SDRSCTL_SDSC(8) /*!< select the clock after 8 delay cell */
+#define EXMC_SDRAM_9_DELAY_CELL SDRSCTL_SDSC(9) /*!< select the clock after 9 delay cell */
+#define EXMC_SDRAM_10_DELAY_CELL SDRSCTL_SDSC(10) /*!< select the clock after 10 delay cell */
+#define EXMC_SDRAM_11_DELAY_CELL SDRSCTL_SDSC(11) /*!< select the clock after 11 delay cell */
+#define EXMC_SDRAM_12_DELAY_CELL SDRSCTL_SDSC(12) /*!< select the clock after 12 delay cell */
+#define EXMC_SDRAM_13_DELAY_CELL SDRSCTL_SDSC(13) /*!< select the clock after 13 delay cell */
+#define EXMC_SDRAM_14_DELAY_CELL SDRSCTL_SDSC(14) /*!< select the clock after 14 delay cell */
+#define EXMC_SDRAM_15_DELAY_CELL SDRSCTL_SDSC(15) /*!< select the clock after 15 delay cell */
/* SPI PSRAM ID length */
-#define SINIT_IDL(regval) (BITS(29,30) & ((uint32_t)(regval) << 29))
-#define EXMC_SQPIPSRAM_ID_LENGTH_64B SINIT_IDL(0) /*!< SPI PSRAM ID length is 64 bits */
-#define EXMC_SQPIPSRAM_ID_LENGTH_32B SINIT_IDL(1) /*!< SPI PSRAM ID length is 32 bits */
-#define EXMC_SQPIPSRAM_ID_LENGTH_16B SINIT_IDL(2) /*!< SPI PSRAM ID length is 16 bits */
-#define EXMC_SQPIPSRAM_ID_LENGTH_8B SINIT_IDL(3) /*!< SPI PSRAM ID length is 8 bits */
+#define SINIT_IDL(regval) (BITS(29,30) & ((uint32_t)(regval) << 29))
+#define EXMC_SQPIPSRAM_ID_LENGTH_64B SINIT_IDL(0) /*!< SPI PSRAM ID length is 64 bits */
+#define EXMC_SQPIPSRAM_ID_LENGTH_32B SINIT_IDL(1) /*!< SPI PSRAM ID length is 32 bits */
+#define EXMC_SQPIPSRAM_ID_LENGTH_16B SINIT_IDL(2) /*!< SPI PSRAM ID length is 16 bits */
+#define EXMC_SQPIPSRAM_ID_LENGTH_8B SINIT_IDL(3) /*!< SPI PSRAM ID length is 8 bits */
/* SPI PSRAM bit number of address phase */
-#define SINIT_ADRBIT(regval) (BITS(24,28) & ((uint32_t)(regval) << 24))
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_1B SINIT_ADRBIT(1) /*!< SPI PSRAM address is 1 bit */
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_2B SINIT_ADRBIT(2) /*!< SPI PSRAM address is 2 bits */
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_3B SINIT_ADRBIT(3) /*!< SPI PSRAM address is 3 bits */
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_4B SINIT_ADRBIT(4) /*!< SPI PSRAM address is 4 bits */
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_5B SINIT_ADRBIT(5) /*!< SPI PSRAM address is 5 bits */
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_6B SINIT_ADRBIT(6) /*!< SPI PSRAM address is 6 bits */
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_7B SINIT_ADRBIT(7) /*!< SPI PSRAM address is 7 bits */
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_8B SINIT_ADRBIT(8) /*!< SPI PSRAM address is 8 bits */
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_9B SINIT_ADRBIT(9) /*!< SPI PSRAM address is 9 bits */
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_10B SINIT_ADRBIT(10) /*!< SPI PSRAM address is 10 bits */
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_11B SINIT_ADRBIT(11) /*!< SPI PSRAM address is 11 bits */
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_12B SINIT_ADRBIT(12) /*!< SPI PSRAM address is 12 bits */
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_13B SINIT_ADRBIT(13) /*!< SPI PSRAM address is 13 bits */
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_14B SINIT_ADRBIT(14) /*!< SPI PSRAM address is 14 bits */
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_15B SINIT_ADRBIT(15) /*!< SPI PSRAM address is 15 bits */
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_16B SINIT_ADRBIT(16) /*!< SPI PSRAM address is 16 bits */
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_17B SINIT_ADRBIT(17) /*!< SPI PSRAM address is 17 bits */
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_18B SINIT_ADRBIT(18) /*!< SPI PSRAM address is 18 bits */
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_19B SINIT_ADRBIT(19) /*!< SPI PSRAM address is 19 bits */
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_20B SINIT_ADRBIT(20) /*!< SPI PSRAM address is 20 bits */
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_21B SINIT_ADRBIT(21) /*!< SPI PSRAM address is 21 bits */
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_22B SINIT_ADRBIT(22) /*!< SPI PSRAM address is 22 bits */
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_23B SINIT_ADRBIT(23) /*!< SPI PSRAM address is 23 bits */
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_24B SINIT_ADRBIT(24) /*!< SPI PSRAM address is 24 bits */
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_25B SINIT_ADRBIT(25) /*!< SPI PSRAM address is 25 bits */
-#define EXMC_SQPIPSRAM_ADDR_LENGTH_26B SINIT_ADRBIT(26) /*!< SPI PSRAM address is 26 bits */
+#define SINIT_ADRBIT(regval) (BITS(24,28) & ((uint32_t)(regval) << 24))
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_1B SINIT_ADRBIT(1) /*!< SPI PSRAM address is 1 bit */
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_2B SINIT_ADRBIT(2) /*!< SPI PSRAM address is 2 bits */
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_3B SINIT_ADRBIT(3) /*!< SPI PSRAM address is 3 bits */
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_4B SINIT_ADRBIT(4) /*!< SPI PSRAM address is 4 bits */
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_5B SINIT_ADRBIT(5) /*!< SPI PSRAM address is 5 bits */
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_6B SINIT_ADRBIT(6) /*!< SPI PSRAM address is 6 bits */
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_7B SINIT_ADRBIT(7) /*!< SPI PSRAM address is 7 bits */
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_8B SINIT_ADRBIT(8) /*!< SPI PSRAM address is 8 bits */
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_9B SINIT_ADRBIT(9) /*!< SPI PSRAM address is 9 bits */
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_10B SINIT_ADRBIT(10) /*!< SPI PSRAM address is 10 bits */
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_11B SINIT_ADRBIT(11) /*!< SPI PSRAM address is 11 bits */
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_12B SINIT_ADRBIT(12) /*!< SPI PSRAM address is 12 bits */
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_13B SINIT_ADRBIT(13) /*!< SPI PSRAM address is 13 bits */
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_14B SINIT_ADRBIT(14) /*!< SPI PSRAM address is 14 bits */
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_15B SINIT_ADRBIT(15) /*!< SPI PSRAM address is 15 bits */
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_16B SINIT_ADRBIT(16) /*!< SPI PSRAM address is 16 bits */
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_17B SINIT_ADRBIT(17) /*!< SPI PSRAM address is 17 bits */
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_18B SINIT_ADRBIT(18) /*!< SPI PSRAM address is 18 bits */
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_19B SINIT_ADRBIT(19) /*!< SPI PSRAM address is 19 bits */
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_20B SINIT_ADRBIT(20) /*!< SPI PSRAM address is 20 bits */
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_21B SINIT_ADRBIT(21) /*!< SPI PSRAM address is 21 bits */
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_22B SINIT_ADRBIT(22) /*!< SPI PSRAM address is 22 bits */
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_23B SINIT_ADRBIT(23) /*!< SPI PSRAM address is 23 bits */
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_24B SINIT_ADRBIT(24) /*!< SPI PSRAM address is 24 bits */
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_25B SINIT_ADRBIT(25) /*!< SPI PSRAM address is 25 bits */
+#define EXMC_SQPIPSRAM_ADDR_LENGTH_26B SINIT_ADRBIT(26) /*!< SPI PSRAM address is 26 bits */
/* SPI PSRAM bit number of command phase */
-#define SINIT_CMDBIT(regval) (BITS(16,17) & ((uint32_t)(regval) << 16))
-#define EXMC_SQPIPSRAM_COMMAND_LENGTH_4B SINIT_CMDBIT(0) /*!< SPI PSRAM command is 4 bits */
-#define EXMC_SQPIPSRAM_COMMAND_LENGTH_8B SINIT_CMDBIT(1) /*!< SPI PSRAM command is 8 bits */
-#define EXMC_SQPIPSRAM_COMMAND_LENGTH_16B SINIT_CMDBIT(2) /*!< SPI PSRAM command is 16 bits */
+#define SINIT_CMDBIT(regval) (BITS(16,17) & ((uint32_t)(regval) << 16))
+#define EXMC_SQPIPSRAM_COMMAND_LENGTH_4B SINIT_CMDBIT(0) /*!< SPI PSRAM command is 4 bits */
+#define EXMC_SQPIPSRAM_COMMAND_LENGTH_8B SINIT_CMDBIT(1) /*!< SPI PSRAM command is 8 bits */
+#define EXMC_SQPIPSRAM_COMMAND_LENGTH_16B SINIT_CMDBIT(2) /*!< SPI PSRAM command is 16 bits */
/* SPI PSRAM read command mode */
-#define SRCMD_RMODE(regval) (BITS(20,21) & ((uint32_t)(regval) << 20))
-#define EXMC_SQPIPSRAM_READ_MODE_DISABLE SRCMD_RMODE(0) /*!< not SPI mode */
-#define EXMC_SQPIPSRAM_READ_MODE_SPI SRCMD_RMODE(1) /*!< SPI mode */
-#define EXMC_SQPIPSRAM_READ_MODE_SQPI SRCMD_RMODE(2) /*!< SQPI mode */
-#define EXMC_SQPIPSRAM_READ_MODE_QPI SRCMD_RMODE(3) /*!< QPI mode */
+#define SRCMD_RMODE(regval) (BITS(20,21) & ((uint32_t)(regval) << 20))
+#define EXMC_SQPIPSRAM_READ_MODE_DISABLE SRCMD_RMODE(0) /*!< not SPI mode */
+#define EXMC_SQPIPSRAM_READ_MODE_SPI SRCMD_RMODE(1) /*!< SPI mode */
+#define EXMC_SQPIPSRAM_READ_MODE_SQPI SRCMD_RMODE(2) /*!< SQPI mode */
+#define EXMC_SQPIPSRAM_READ_MODE_QPI SRCMD_RMODE(3) /*!< QPI mode */
/* SPI PSRAM write command mode */
-#define SRCMD_WMODE(regval) (BITS(20,21) & ((uint32_t)(regval) << 20))
-#define EXMC_SQPIPSRAM_WRITE_MODE_DISABLE SRCMD_WMODE(0) /*!< not SPI mode */
-#define EXMC_SQPIPSRAM_WRITE_MODE_SPI SRCMD_WMODE(1) /*!< SPI mode */
-#define EXMC_SQPIPSRAM_WRITE_MODE_SQPI SRCMD_WMODE(2) /*!< SQPI mode */
-#define EXMC_SQPIPSRAM_WRITE_MODE_QPI SRCMD_WMODE(3) /*!< QPI mode */
+#define SRCMD_WMODE(regval) (BITS(20,21) & ((uint32_t)(regval) << 20))
+#define EXMC_SQPIPSRAM_WRITE_MODE_DISABLE SRCMD_WMODE(0) /*!< not SPI mode */
+#define EXMC_SQPIPSRAM_WRITE_MODE_SPI SRCMD_WMODE(1) /*!< SPI mode */
+#define EXMC_SQPIPSRAM_WRITE_MODE_SQPI SRCMD_WMODE(2) /*!< SQPI mode */
+#define EXMC_SQPIPSRAM_WRITE_MODE_QPI SRCMD_WMODE(3) /*!< QPI mode */
/* EXMC NOR/SRAM bank region definition */
-#define EXMC_BANK0_NORSRAM_REGION0 ((uint32_t)0x00000000U) /*!< bank0 NOR/SRAM region0 */
-#define EXMC_BANK0_NORSRAM_REGION1 ((uint32_t)0x00000001U) /*!< bank0 NOR/SRAM region1 */
-#define EXMC_BANK0_NORSRAM_REGION2 ((uint32_t)0x00000002U) /*!< bank0 NOR/SRAM region2 */
-#define EXMC_BANK0_NORSRAM_REGION3 ((uint32_t)0x00000003U) /*!< bank0 NOR/SRAM region3 */
+#define EXMC_BANK0_NORSRAM_REGION0 ((uint32_t)0x00000000U) /*!< bank0 NOR/SRAM region0 */
+#define EXMC_BANK0_NORSRAM_REGION1 ((uint32_t)0x00000001U) /*!< bank0 NOR/SRAM region1 */
+#define EXMC_BANK0_NORSRAM_REGION2 ((uint32_t)0x00000002U) /*!< bank0 NOR/SRAM region2 */
+#define EXMC_BANK0_NORSRAM_REGION3 ((uint32_t)0x00000003U) /*!< bank0 NOR/SRAM region3 */
/* EXMC consecutive clock */
-#define EXMC_CLOCK_SYN_MODE ((uint32_t)0x00000000U) /*!< EXMC_CLK is generated only during synchronous access */
-#define EXMC_CLOCK_UNCONDITIONALLY ((uint32_t)0x00010000U) /*!< EXMC_CLK is generated unconditionally */
+#define EXMC_CLOCK_SYN_MODE ((uint32_t)0x00000000U) /*!< EXMC_CLK is generated only during synchronous access */
+#define EXMC_CLOCK_UNCONDITIONALLY EXMC_SNCTL_CCK /*!< EXMC_CLK is generated unconditionally */
/* EXMC NOR/SRAM write mode */
-#define EXMC_ASYN_WRITE ((uint32_t)0x00000000U) /*!< asynchronous write mode */
-#define EXMC_SYN_WRITE ((uint32_t)0x00008000U) /*!< synchronous write mode */
+#define EXMC_ASYN_WRITE ((uint32_t)0x00000000U) /*!< asynchronous write mode */
+#define EXMC_SYN_WRITE EXMC_SNCTL_SYNCWR /*!< synchronous write mode */
/* EXMC NWAIT signal configuration */
-#define EXMC_NWAIT_CONFIG_BEFORE ((uint32_t)0x00000000U) /*!< NWAIT signal is active one data cycle before wait state */
-#define EXMC_NWAIT_CONFIG_DURING ((uint32_t)0x00000800U) /*!< NWAIT signal is active during wait state */
+#define EXMC_NWAIT_CONFIG_BEFORE ((uint32_t)0x00000000U) /*!< NWAIT signal is active one data cycle before wait state */
+#define EXMC_NWAIT_CONFIG_DURING EXMC_SNCTL_NRWTCFG /*!< NWAIT signal is active during wait state */
/* EXMC NWAIT signal polarity configuration */
-#define EXMC_NWAIT_POLARITY_LOW ((uint32_t)0x00000000U) /*!< low level is active of NWAIT */
-#define EXMC_NWAIT_POLARITY_HIGH ((uint32_t)0x00000200U) /*!< high level is active of NWAIT */
+#define EXMC_NWAIT_POLARITY_LOW ((uint32_t)0x00000000U) /*!< low level is active of NWAIT */
+#define EXMC_NWAIT_POLARITY_HIGH EXMC_SNCTL_NRWTPOL /*!< high level is active of NWAIT */
/* EXMC NAND/PC card bank definition */
-#define EXMC_BANK1_NAND ((uint32_t)0x00000001U) /*!< bank1 NAND flash */
-#define EXMC_BANK2_NAND ((uint32_t)0x00000002U) /*!< bank2 NAND flash */
-#define EXMC_BANK3_PCCARD ((uint32_t)0x00000003U) /*!< bank3 PC card */
+#define EXMC_BANK1_NAND ((uint32_t)0x00000001U) /*!< NAND flash bank1 */
+#define EXMC_BANK2_NAND ((uint32_t)0x00000002U) /*!< NAND flash bank2 */
+#define EXMC_BANK3_PCCARD ((uint32_t)0x00000003U) /*!< PC card bank3 */
/* EXMC SDRAM bank definition */
-#define EXMC_SDRAM_DEVICE0 ((uint32_t)0x00000004U) /*!< SDRAM device0 */
-#define EXMC_SDRAM_DEVICE1 ((uint32_t)0x00000005U) /*!< SDRAM device1 */
+#define EXMC_SDRAM_DEVICE0 ((uint32_t)0x00000004U) /*!< SDRAM device0 */
+#define EXMC_SDRAM_DEVICE1 ((uint32_t)0x00000005U) /*!< SDRAM device1 */
/* EXMC SDRAM internal banks */
-#define EXMC_SDRAM_2_INTER_BANK ((uint32_t)0x00000000U) /*!< 2 internal banks */
-#define EXMC_SDRAM_4_INTER_BANK ((uint32_t)0x00000040U) /*!< 4 internal banks */
+#define EXMC_SDRAM_2_INTER_BANK ((uint32_t)0x00000000U) /*!< 2 internal banks */
+#define EXMC_SDRAM_4_INTER_BANK EXMC_SDCTL_NBK /*!< 4 internal banks */
/* SDRAM device0 select */
-#define EXMC_SDRAM_DEVICE0_UNSELECT ((uint32_t)0x00000000U) /*!< NAND data width 8 bits */
-#define EXMC_SDRAM_DEVICE0_SELECT ((uint32_t)0x00000010U) /*!< NAND data width 16 bits */
+#define EXMC_SDRAM_DEVICE0_UNSELECT ((uint32_t)0x00000000U) /*!< SDRAM device0 unselect */
+#define EXMC_SDRAM_DEVICE0_SELECT EXMC_SDCMD_DS0 /*!< SDRAM device0 select */
/* SDRAM device1 select */
-#define EXMC_SDRAM_DEVICE1_UNSELECT ((uint32_t)0x00000000U) /*!< NAND data width 8 bits */
-#define EXMC_SDRAM_DEVICE1_SELECT ((uint32_t)0x00000008U) /*!< NAND data width 16 bits */
+#define EXMC_SDRAM_DEVICE1_UNSELECT ((uint32_t)0x00000000U) /*!< SDRAM device1 unselect */
+#define EXMC_SDRAM_DEVICE1_SELECT EXMC_SDCMD_DS1 /*!< SDRAM device1 select */
/* SDRAM device status */
-#define EXMC_SDRAM_DEVICE_NORMAL ((uint32_t)0x00000000U) /*!< normal status */
-#define EXMC_SDRAM_DEVICE_SELF_REFRESH ((uint32_t)0x00000001U) /*!< self refresh status */
-#define EXMC_SDRAM_DEVICE_POWER_DOWN ((uint32_t)0x00000002U) /*!< power down status */
+#define EXMC_SDRAM_DEVICE_NORMAL ((uint32_t)0x00000000U) /*!< normal status */
+#define EXMC_SDRAM_DEVICE_SELF_REFRESH ((uint32_t)0x00000001U) /*!< self refresh status */
+#define EXMC_SDRAM_DEVICE_POWER_DOWN ((uint32_t)0x00000002U) /*!< power down status */
/* sample cycle of read data */
-#define EXMC_SDRAM_READSAMPLE_0_EXTRAHCLK ((uint32_t)0x00000000U) /*!< add 0 extra HCLK cycle to the read data sample clock besides the delay chain */
-#define EXMC_SDRAM_READSAMPLE_1_EXTRAHCLK ((uint32_t)0x00000002U) /*!< add 1 extra HCLK cycle to the read data sample clock besides the delay chain */
+#define EXMC_SDRAM_READSAMPLE_0_EXTRAHCLK ((uint32_t)0x00000000U) /*!< add 0 extra HCLK cycle to the read data sample clock besides the delay chain */
+#define EXMC_SDRAM_READSAMPLE_1_EXTRAHCLK EXMC_SDRSCTL_SSCR /*!< add 1 extra HCLK cycle to the read data sample clock besides the delay chain */
/* read data sample polarity */
-#define EXMC_SDRAM_SAMPLE_RISING_EDGE ((uint32_t)0x00000000U) /*!< sample data at rising edge */
-#define EXMC_SDRAM_SAMPLE_FALLING_EDGE ((uint32_t)0x80000000U) /*!< sample data at falling edge */
+#define EXMC_SQPIPSRAM_SAMPLE_RISING_EDGE ((uint32_t)0x00000000U) /*!< sample data at rising edge */
+#define EXMC_SQPIPSRAM_SAMPLE_FALLING_EDGE EXMC_SINIT_POL /*!< sample data at falling edge */
/* SQPI SRAM command flag */
-#define EXMC_SEND_COMMAND_FLAG_RDID EXMC_SRCMD_RDID /*!< EXMC_SRCMD_RDID flag bit */
-#define EXMC_SEND_COMMAND_FLAG_SC EXMC_SWCMD_SC /*!< EXMC_SWCMD_SC flag bit */
+#define EXMC_SEND_COMMAND_FLAG_RDID EXMC_SRCMD_RDID /*!< EXMC_SRCMD_RDID flag bit */
+#define EXMC_SEND_COMMAND_FLAG_SC EXMC_SWCMD_SC /*!< EXMC_SWCMD_SC flag bit */
/* EXMC flag bits */
-#define EXMC_NAND_PCCARD_FLAG_RISE EXMC_NPINTENx_INTRS /*!< interrupt rising edge status */
-#define EXMC_NAND_PCCARD_FLAG_LEVEL EXMC_NPINTENx_INTHS /*!< interrupt high-level status */
-#define EXMC_NAND_PCCARD_FLAG_FALL EXMC_NPINTENx_INTFS /*!< interrupt falling edge status */
-#define EXMC_NAND_PCCARD_FLAG_FIFOE EXMC_NPINTENx_INTEPT /*!< FIFO empty flag */
-#define EXMC_SDRAM_FLAG_REFRESH EXMC_SDSDAT_REIF /*!< refresh error interrupt flag */
-#define EXMC_SDRAM_FLAG_NREADY EXMC_SDSDAT_NRDY /*!< not ready status */
+#define EXMC_NAND_PCCARD_FLAG_RISE EXMC_NPINTEN_INTRS /*!< interrupt rising edge status */
+#define EXMC_NAND_PCCARD_FLAG_LEVEL EXMC_NPINTEN_INTHS /*!< interrupt high-level status */
+#define EXMC_NAND_PCCARD_FLAG_FALL EXMC_NPINTEN_INTFS /*!< interrupt falling edge status */
+#define EXMC_NAND_PCCARD_FLAG_FIFOE EXMC_NPINTEN_FFEPT /*!< FIFO empty flag */
+#define EXMC_SDRAM_FLAG_REFRESH EXMC_SDSDAT_REIF /*!< refresh error interrupt flag */
+#define EXMC_SDRAM_FLAG_NREADY EXMC_SDSDAT_NRDY /*!< not ready status */
/* EXMC interrupt flag bits */
-#define EXMC_NAND_PCCARD_INT_RISE EXMC_NPINTENx_INTREN /*!< interrupt rising edge detection enable */
-#define EXMC_NAND_PCCARD_INT_LEVEL EXMC_NPINTENx_INTHEN /*!< interrupt high-level detection enable */
-#define EXMC_NAND_PCCARD_INT_FALL EXMC_NPINTENx_INTFEN /*!< interrupt falling edge detection enable */
-#define EXMC_SDRAM_INT_REFRESH EXMC_SDARI_REIE /*!< interrupt refresh error enable */
+#define EXMC_NAND_PCCARD_INT_FLAG_RISE EXMC_NPINTEN_INTREN /*!< rising edge interrupt and flag */
+#define EXMC_NAND_PCCARD_INT_FLAG_LEVEL EXMC_NPINTEN_INTHEN /*!< high-level interrupt and flag */
+#define EXMC_NAND_PCCARD_INT_FLAG_FALL EXMC_NPINTEN_INTFEN /*!< falling edge interrupt and flag */
+#define EXMC_SDRAM_INT_FLAG_REFRESH EXMC_SDARI_REIE /*!< refresh error interrupt and flag */
/* function declarations */
+/* initialization functions */
+/* NOR/SRAM */
/* deinitialize EXMC NOR/SRAM region */
void exmc_norsram_deinit(uint32_t exmc_norsram_region);
+/* initialize exmc_norsram_parameter_struct with the default values */
+void exmc_norsram_struct_para_init(exmc_norsram_parameter_struct* exmc_norsram_init_struct);
/* initialize EXMC NOR/SRAM region */
void exmc_norsram_init(exmc_norsram_parameter_struct* exmc_norsram_init_struct);
-/* exmc_norsram_parameter_struct parameter initialize */
-void exmc_norsram_parameter_init(exmc_norsram_parameter_struct* exmc_norsram_init_struct);
-/* consecutive clock configure */
-void exmc_norsram_consecutive_clock_config(uint32_t clock_mode);
-/* CRAM page size configure */
-void exmc_norsram_page_size_config(uint32_t page_size);
-/* EXMC NOR/SRAM bank enable */
+/* enable EXMC NOR/SRAM region */
void exmc_norsram_enable(uint32_t exmc_norsram_region);
-/* EXMC NOR/SRAM bank disable */
+/* disable EXMC NOR/SRAM region */
void exmc_norsram_disable(uint32_t exmc_norsram_region);
-
-
+/* NAND */
/* deinitialize EXMC NAND bank */
void exmc_nand_deinit(uint32_t exmc_nand_bank);
+/* initialize exmc_norsram_parameter_struct with the default values */
+void exmc_nand_struct_para_init(exmc_nand_parameter_struct* exmc_nand_init_struct);
/* initialize EXMC NAND bank */
void exmc_nand_init(exmc_nand_parameter_struct* exmc_nand_init_struct);
-/* exmc_norsram_parameter_struct parameter initialize */
-void exmc_nand_parameter_init(exmc_nand_parameter_struct* exmc_nand_init_struct);
-/* EXMC NAND bank enable */
+/* enable EXMC NAND bank */
void exmc_nand_enable(uint32_t exmc_nand_bank);
-/* EXMC NAND bank disable */
+/* disable EXMC NAND bank */
void exmc_nand_disable(uint32_t exmc_nand_bank);
-/* enable or disable the EXMC NAND ECC function */
-void exmc_nand_ecc_config(uint32_t exmc_nand_bank, ControlStatus newvalue);
-/* get the EXMC ECC value */
-uint32_t exmc_ecc_get(uint32_t exmc_nand_bank);
-
-
+/* PC card */
/* deinitialize EXMC PC card bank */
void exmc_pccard_deinit(void);
+/* initialize exmc_pccard_parameter_struct with the default values */
+void exmc_pccard_struct_para_init(exmc_pccard_parameter_struct* exmc_pccard_init_struct);
/* initialize EXMC PC card bank */
void exmc_pccard_init(exmc_pccard_parameter_struct* exmc_pccard_init_struct);
-/* exmc_pccard_parameter_struct parameter initialize */
-void exmc_pccard_parameter_init(exmc_pccard_parameter_struct* exmc_pccard_init_struct);
-/* EXMC PC card bank enable */
+/* enable EXMC PC card bank */
void exmc_pccard_enable(void);
-/* EXMC PC card bank disable */
+/* disable EXMC PC card bank */
void exmc_pccard_disable(void);
-
-
+/* SDRAM */
/* deinitialize EXMC SDRAM device */
void exmc_sdram_deinit(uint32_t exmc_sdram_device);
+/* initialize exmc_sdram_parameter_struct with the default values */
+void exmc_sdram_struct_para_init(exmc_sdram_parameter_struct* exmc_sdram_init_struct);
/* initialize EXMC SDRAM device */
void exmc_sdram_init(exmc_sdram_parameter_struct* exmc_sdram_init_struct);
-/* exmc_sdram_parameter_struct parameter initialize */
-void exmc_sdram_parameter_init(exmc_sdram_parameter_struct* exmc_sdram_init_struct);
+/* SQPIPSRAM */
+/* deinitialize EXMC SQPIPSRAM */
+void exmc_sqpipsram_deinit(void);
+/* initialize exmc_sqpipsram_parameter_struct with the default values */
+void exmc_sqpipsram_struct_para_init(exmc_sqpipsram_parameter_struct* exmc_sqpipsram_init_struct);
+/* initialize EXMC SQPIPSRAM */
+void exmc_sqpipsram_init(exmc_sqpipsram_parameter_struct* exmc_sqpipsram_init_struct);
+
+/* function configuration */
+/* NOR/SRAM */
+/* configure consecutive clock */
+void exmc_norsram_consecutive_clock_config(uint32_t clock_mode);
+/* configure CRAM page size */
+void exmc_norsram_page_size_config(uint32_t exmc_norsram_region, uint32_t page_size);
+/* NAND */
+/* enable or disable the EXMC NAND ECC function */
+void exmc_nand_ecc_config(uint32_t exmc_nand_bank, ControlStatus newvalue);
+/* get the EXMC ECC value */
+uint32_t exmc_ecc_get(uint32_t exmc_nand_bank);
+/* SDRAM */
+/* enable or disable read sample */
+void exmc_sdram_readsample_enable(ControlStatus newvalue);
+/* configure the delayed sample clock of read data */
+void exmc_sdram_readsample_config(uint32_t delay_cell, uint32_t extra_hclk);
/* configure the SDRAM memory command */
void exmc_sdram_command_config(exmc_sdram_command_parameter_struct* exmc_sdram_command_init_struct);
/* set auto-refresh interval */
@@ -737,18 +776,7 @@ void exmc_sdram_autorefresh_number_set(uint32_t exmc_number);
void exmc_sdram_write_protection_config(uint32_t exmc_sdram_device, ControlStatus newvalue);
/* get the status of SDRAM device0 or device1 */
uint32_t exmc_sdram_bankstatus_get(uint32_t exmc_sdram_device);
-/* configure the delayed sample clock of read data */
-void exmc_sdram_readsample_config(uint32_t delay_cell, uint32_t extra_hclk);
-/* enable or disable read sample */
-void exmc_sdram_readsample_enable(ControlStatus newvalue);
-
-
-/* deinitialize EXMC SQPIPSRAM */
-void exmc_sqpipsram_deinit(void);
-/* initialize EXMC SQPIPSRAM */
-void exmc_sqpipsram_init(exmc_sqpipsram_parameter_struct* exmc_sqpipsram_init_struct);
-/* exmc_sqpipsram_parameter_struct parameter initialize */
-void exmc_sqpipsram_parameter_init(exmc_sqpipsram_parameter_struct* exmc_sqpipsram_init_struct);
+/* SQPIPSRAM */
/* set the read command */
void exmc_sqpipsram_read_command_set(uint32_t read_command_mode,uint32_t read_wait_cycle,uint32_t read_command_code);
/* set the write command */
@@ -764,18 +792,18 @@ uint32_t exmc_sqpipsram_high_id_get(void);
/* get the bit value of EXMC send write command bit or read ID command */
FlagStatus exmc_sqpipsram_send_command_state_get(uint32_t send_command_flag);
-
-/* check EXMC flag is set or not */
-FlagStatus exmc_flag_get(uint32_t exmc_bank,uint32_t flag);
-/* clear EXMC flag */
-void exmc_flag_clear(uint32_t exmc_bank,uint32_t flag);
-/* check EXMC flag is set or not */
-FlagStatus exmc_interrupt_flag_get(uint32_t exmc_bank,uint32_t interrupt_source);
-/* clear EXMC one channel flag */
-void exmc_interrupt_flag_clear(uint32_t exmc_bank,uint32_t interrupt_source);
+/* interrupt & flag functions */
/* enable EXMC interrupt */
-void exmc_interrupt_enable(uint32_t exmc_bank,uint32_t interrupt_source);
+void exmc_interrupt_enable(uint32_t exmc_bank,uint32_t interrupt);
/* disable EXMC interrupt */
-void exmc_interrupt_disable(uint32_t exmc_bank,uint32_t interrupt_source);
+void exmc_interrupt_disable(uint32_t exmc_bank,uint32_t interrupt);
+/* get EXMC flag status */
+FlagStatus exmc_flag_get(uint32_t exmc_bank,uint32_t flag);
+/* clear EXMC flag status */
+void exmc_flag_clear(uint32_t exmc_bank,uint32_t flag);
+/* get EXMC interrupt flag */
+FlagStatus exmc_interrupt_flag_get(uint32_t exmc_bank,uint32_t interrupt);
+/* clear EXMC interrupt flag */
+void exmc_interrupt_flag_clear(uint32_t exmc_bank,uint32_t interrupt);
#endif /* GD32F4XX_EXMC_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_exti.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_exti.h
index a0ad59400a..3c2a27149d 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_exti.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_exti.h
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_exti.h
- \brief definitions for the EXTI
+ \file gd32f4xx_exti.h
+ \brief definitions for the EXTI
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.1, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#ifndef GD32F4XX_EXTI_H
@@ -97,6 +122,7 @@
#define EXTI_RTEN_RTEN17 BIT(17) /*!< rising edge from line 17 */
#define EXTI_RTEN_RTEN18 BIT(18) /*!< rising edge from line 18 */
#define EXTI_RTEN_RTEN19 BIT(19) /*!< rising edge from line 19 */
+#define EXTI_RTEN_RTEN20 BIT(20) /*!< rising edge from line 20 */
#define EXTI_RTEN_RTEN21 BIT(21) /*!< rising edge from line 21 */
#define EXTI_RTEN_RTEN22 BIT(22) /*!< rising edge from line 22 */
@@ -121,6 +147,7 @@
#define EXTI_FTEN_FTEN17 BIT(17) /*!< falling edge from line 17 */
#define EXTI_FTEN_FTEN18 BIT(18) /*!< falling edge from line 18 */
#define EXTI_FTEN_FTEN19 BIT(19) /*!< falling edge from line 19 */
+#define EXTI_FTEN_FTEN20 BIT(20) /*!< falling edge from line 20 */
#define EXTI_FTEN_FTEN21 BIT(21) /*!< falling edge from line 21 */
#define EXTI_FTEN_FTEN22 BIT(22) /*!< falling edge from line 22 */
@@ -145,6 +172,7 @@
#define EXTI_SWIEV_SWIEV17 BIT(17) /*!< software interrupt/event request from line 17 */
#define EXTI_SWIEV_SWIEV18 BIT(18) /*!< software interrupt/event request from line 18 */
#define EXTI_SWIEV_SWIEV19 BIT(19) /*!< software interrupt/event request from line 19 */
+#define EXTI_SWIEV_SWIEV20 BIT(20) /*!< software interrupt/event request from line 20 */
#define EXTI_SWIEV_SWIEV21 BIT(21) /*!< software interrupt/event request from line 21 */
#define EXTI_SWIEV_SWIEV22 BIT(22) /*!< software interrupt/event request from line 22 */
@@ -169,13 +197,14 @@
#define EXTI_PD_PD17 BIT(17) /*!< interrupt/event pending status from line 17 */
#define EXTI_PD_PD18 BIT(18) /*!< interrupt/event pending status from line 18 */
#define EXTI_PD_PD19 BIT(19) /*!< interrupt/event pending status from line 19 */
+#define EXTI_PD_PD20 BIT(20) /*!< interrupt/event pending status from line 20 */
#define EXTI_PD_PD21 BIT(21) /*!< interrupt/event pending status from line 21 */
#define EXTI_PD_PD22 BIT(22) /*!< interrupt/event pending status from line 22 */
/* constants definitions */
/* EXTI line number */
typedef enum
-{
+{
EXTI_0 = BIT(0), /*!< EXTI line 0 */
EXTI_1 = BIT(1), /*!< EXTI line 1 */
EXTI_2 = BIT(2), /*!< EXTI line 2 */
@@ -196,7 +225,7 @@ typedef enum
EXTI_17 = BIT(17), /*!< EXTI line 17 */
EXTI_18 = BIT(18), /*!< EXTI line 18 */
EXTI_19 = BIT(19), /*!< EXTI line 19 */
- EXTI_20 = BIT(20), /*!< EXTI line 20 */
+ EXTI_20 = BIT(20), /*!< EXTI line 20 */
EXTI_21 = BIT(21), /*!< EXTI line 21 */
EXTI_22 = BIT(22), /*!< EXTI line 22 */
}exti_line_enum;
@@ -210,10 +239,11 @@ typedef enum
/* interrupt trigger mode */
typedef enum
-{
+{
EXTI_TRIG_RISING = 0, /*!< EXTI rising edge trigger */
EXTI_TRIG_FALLING, /*!< EXTI falling edge trigger */
- EXTI_TRIG_BOTH /*!< EXTI rising and falling edge trigger */
+ EXTI_TRIG_BOTH, /*!< EXTI rising and falling edge trigger */
+ EXTI_TRIG_NONE /*!< none EXTI edge trigger */
}exti_trig_type_enum;
/* function declarations */
@@ -223,13 +253,18 @@ void exti_deinit(void);
void exti_init(exti_line_enum linex, exti_mode_enum mode, exti_trig_type_enum trig_type);
/* enable the interrupts from EXTI line x */
void exti_interrupt_enable(exti_line_enum linex);
-/* enable the events from EXTI line x */
-void exti_event_enable(exti_line_enum linex);
/* disable the interrupts from EXTI line x */
void exti_interrupt_disable(exti_line_enum linex);
+/* enable the events from EXTI line x */
+void exti_event_enable(exti_line_enum linex);
/* disable the events from EXTI line x */
void exti_event_disable(exti_line_enum linex);
+/* EXTI software interrupt event enable */
+void exti_software_interrupt_enable(exti_line_enum linex);
+/* EXTI software interrupt event disable */
+void exti_software_interrupt_disable(exti_line_enum linex);
+/* interrupt & flag functions */
/* get EXTI lines pending flag */
FlagStatus exti_flag_get(exti_line_enum linex);
/* clear EXTI lines pending flag */
@@ -238,9 +273,5 @@ void exti_flag_clear(exti_line_enum linex);
FlagStatus exti_interrupt_flag_get(exti_line_enum linex);
/* clear EXTI lines pending flag */
void exti_interrupt_flag_clear(exti_line_enum linex);
-/* EXTI software interrupt event enable */
-void exti_software_interrupt_enable(exti_line_enum linex);
-/* EXTI software interrupt event disable */
-void exti_software_interrupt_disable(exti_line_enum linex);
#endif /* GD32F4XX_EXTI_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_fmc.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_fmc.h
index c3b360ab02..9b1b82c083 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_fmc.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_fmc.h
@@ -1,13 +1,40 @@
/*!
- \file gd32f4xx_fmc.h
- \brief definitions for the FMC
+ \file gd32f4xx_fmc.h
+ \brief definitions for the FMC
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
+
+
#ifndef GD32F4XX_FMC_H
#define GD32F4XX_FMC_H
@@ -18,15 +45,15 @@
#define OB OB_BASE /*!< option byte base address */
/* registers definitions */
-#define FMC_WS REG32((FMC) + 0x00U) /*!< FMC wait state register */
-#define FMC_KEY REG32((FMC) + 0x04U) /*!< FMC unlock key register */
-#define FMC_OBKEY REG32((FMC) + 0x08U) /*!< FMC option byte unlock key register */
-#define FMC_STAT REG32((FMC) + 0x0CU) /*!< FMC status register */
-#define FMC_CTL REG32((FMC) + 0x10U) /*!< FMC control register */
-#define FMC_OBCTL0 REG32((FMC) + 0x14U) /*!< FMC option byte control register 0 */
-#define FMC_OBCTL1 REG32((FMC) + 0x18U) /*!< FMC option byte control register 1 */
-#define FMC_WSEN REG32((FMC) + 0xFCU) /*!< FMC wait state enable register */
-#define FMC_PID REG32((FMC) + 0x100U) /*!< FMC product ID register */
+#define FMC_WS REG32((FMC) + 0x0000U) /*!< FMC wait state register */
+#define FMC_KEY REG32((FMC) + 0x0004U) /*!< FMC unlock key register */
+#define FMC_OBKEY REG32((FMC) + 0x0008U) /*!< FMC option byte unlock key register */
+#define FMC_STAT REG32((FMC) + 0x000CU) /*!< FMC status register */
+#define FMC_CTL REG32((FMC) + 0x0010U) /*!< FMC control register */
+#define FMC_OBCTL0 REG32((FMC) + 0x0014U) /*!< FMC option byte control register 0 */
+#define FMC_OBCTL1 REG32((FMC) + 0x0018U) /*!< FMC option byte control register 1 */
+#define FMC_WSEN REG32((FMC) + 0x00FCU) /*!< FMC wait state enable register */
+#define FMC_PID REG32((FMC) + 0x0100U) /*!< FMC product ID register */
#define OB_WP1 REG32((OB) + 0x00000008U) /*!< option byte write protection 1 */
#define OB_USER REG32((OB) + 0x00010000U) /*!< option byte user value*/
@@ -98,7 +125,6 @@ typedef enum
FMC_WPERR, /*!< erase/program protection error */
FMC_OPERR, /*!< operation error */
FMC_PGERR, /*!< program error */
- FMC_TOERR /*!< timeout error */
}fmc_state_enum;
/* unlock key */
@@ -108,9 +134,6 @@ typedef enum
#define OB_UNLOCK_KEY0 ((uint32_t)0x08192A3BU) /*!< ob unlock key 0 */
#define OB_UNLOCK_KEY1 ((uint32_t)0x4C5D6E7FU) /*!< ob unlock key 1 */
-/* FMC time out */
-#define FMC_TIMEOUT_COUNT ((uint32_t)0x000F0000) /*!< enable FMC error timeout */
-
/* option byte write protection */
#define OB_LWP ((uint32_t)0x000000FFU) /*!< write protection low bits */
#define OB_HWP ((uint32_t)0x0000FF00U) /*!< write protection high bits */
@@ -146,7 +169,7 @@ typedef enum
#define OB_BB_DISABLE OBCTL0_BB(0) /*!< boot from bank0 */
#define OB_BB_ENABLE OBCTL0_BB(1) /*!< boot from bank1 or bank0 if bank1 is void */
-/* option byte software/hardware free watch dog timer */
+/* option byte software/hardware free watch dog timer */
#define OBCTL0_NWDG_HW(regval) (BIT(5) & ((uint32_t)(regval))<< 5)
#define OB_FWDGT_SW OBCTL0_NWDG_HW(1) /*!< software free watchdog */
#define OB_FWDGT_HW OBCTL0_NWDG_HW(0) /*!< hardware free watchdog */
@@ -179,19 +202,19 @@ typedef enum
#define OB_WP_9 ((uint32_t)0x00000200U) /*!< erase/program protection of sector 9 */
#define OB_WP_10 ((uint32_t)0x00000400U) /*!< erase/program protection of sector 10 */
#define OB_WP_11 ((uint32_t)0x00000800U) /*!< erase/program protection of sector 11 */
-#define OB_WP_12 ((uint32_t)0x00000001U) /*!< erase/program protection of sector 12 */
-#define OB_WP_13 ((uint32_t)0x00000002U) /*!< erase/program protection of sector 13 */
-#define OB_WP_14 ((uint32_t)0x00000004U) /*!< erase/program protection of sector 14 */
-#define OB_WP_15 ((uint32_t)0x00000008U) /*!< erase/program protection of sector 15 */
-#define OB_WP_16 ((uint32_t)0x00000010U) /*!< erase/program protection of sector 16 */
-#define OB_WP_17 ((uint32_t)0x00000020U) /*!< erase/program protection of sector 17 */
-#define OB_WP_18 ((uint32_t)0x00000040U) /*!< erase/program protection of sector 18 */
-#define OB_WP_19 ((uint32_t)0x00000080U) /*!< erase/program protection of sector 19 */
-#define OB_WP_20 ((uint32_t)0x00000100U) /*!< erase/program protection of sector 20 */
-#define OB_WP_21 ((uint32_t)0x00000200U) /*!< erase/program protection of sector 21 */
-#define OB_WP_22 ((uint32_t)0x00000400U) /*!< erase/program protection of sector 22 */
-#define OB_WP_23_30 ((uint32_t)0x00000800U) /*!< erase/program protection of sector 23~30 */
-#define OB_WP_ALL ((uint32_t)0x00000FFFU) /*!< erase/program protection of all sectors */
+#define OB_WP_12 ((uint32_t)0x00010000U) /*!< erase/program protection of sector 12 */
+#define OB_WP_13 ((uint32_t)0x00020000U) /*!< erase/program protection of sector 13 */
+#define OB_WP_14 ((uint32_t)0x00040000U) /*!< erase/program protection of sector 14 */
+#define OB_WP_15 ((uint32_t)0x00080000U) /*!< erase/program protection of sector 15 */
+#define OB_WP_16 ((uint32_t)0x00100000U) /*!< erase/program protection of sector 16 */
+#define OB_WP_17 ((uint32_t)0x00200000U) /*!< erase/program protection of sector 17 */
+#define OB_WP_18 ((uint32_t)0x00400000U) /*!< erase/program protection of sector 18 */
+#define OB_WP_19 ((uint32_t)0x00800000U) /*!< erase/program protection of sector 19 */
+#define OB_WP_20 ((uint32_t)0x01000000U) /*!< erase/program protection of sector 20 */
+#define OB_WP_21 ((uint32_t)0x02000000U) /*!< erase/program protection of sector 21 */
+#define OB_WP_22 ((uint32_t)0x04000000U) /*!< erase/program protection of sector 22 */
+#define OB_WP_23_27 ((uint32_t)0x08000000U) /*!< erase/program protection of sector 23~27 */
+#define OB_WP_ALL ((uint32_t)0x0FFF0FFFU) /*!< erase/program protection of all sectors */
/* option bytes D-bus read protection */
#define OB_DRP_0 ((uint32_t)0x00000001U) /*!< D-bus read protection protection of sector 0 */
@@ -206,26 +229,25 @@ typedef enum
#define OB_DRP_9 ((uint32_t)0x00000200U) /*!< D-bus read protection protection of sector 9 */
#define OB_DRP_10 ((uint32_t)0x00000400U) /*!< D-bus read protection protection of sector 10 */
#define OB_DRP_11 ((uint32_t)0x00000800U) /*!< D-bus read protection protection of sector 11 */
-#define OB_DRP_12 ((uint32_t)0x00000001U) /*!< D-bus read protection protection of sector 12 */
-#define OB_DRP_13 ((uint32_t)0x00000002U) /*!< D-bus read protection protection of sector 13 */
-#define OB_DRP_14 ((uint32_t)0x00000004U) /*!< D-bus read protection protection of sector 14 */
-#define OB_DRP_15 ((uint32_t)0x00000008U) /*!< D-bus read protection protection of sector 15 */
-#define OB_DRP_16 ((uint32_t)0x00000010U) /*!< D-bus read protection protection of sector 16 */
-#define OB_DRP_17 ((uint32_t)0x00000020U) /*!< D-bus read protection protection of sector 17 */
-#define OB_DRP_18 ((uint32_t)0x00000040U) /*!< D-bus read protection protection of sector 18 */
-#define OB_DRP_19 ((uint32_t)0x00000080U) /*!< D-bus read protection protection of sector 19 */
-#define OB_DRP_20 ((uint32_t)0x00000100U) /*!< D-bus read protection protection of sector 20 */
-#define OB_DRP_21 ((uint32_t)0x00000200U) /*!< D-bus read protection protection of sector 21 */
-#define OB_DRP_22 ((uint32_t)0x00000400U) /*!< D-bus read protection protection of sector 22 */
-#define OB_DRP_23_30 ((uint32_t)0x00000800U) /*!< D-bus read protection protection of sector 23~30 */
-#define OB_DRP_ALL ((uint32_t)0x00000FFFU) /*!< D-bus read protection protection of all sectors */
+#define OB_DRP_12 ((uint32_t)0x00010000U) /*!< D-bus read protection protection of sector 12 */
+#define OB_DRP_13 ((uint32_t)0x00020000U) /*!< D-bus read protection protection of sector 13 */
+#define OB_DRP_14 ((uint32_t)0x00040000U) /*!< D-bus read protection protection of sector 14 */
+#define OB_DRP_15 ((uint32_t)0x00080000U) /*!< D-bus read protection protection of sector 15 */
+#define OB_DRP_16 ((uint32_t)0x00100000U) /*!< D-bus read protection protection of sector 16 */
+#define OB_DRP_17 ((uint32_t)0x00200000U) /*!< D-bus read protection protection of sector 17 */
+#define OB_DRP_18 ((uint32_t)0x00400000U) /*!< D-bus read protection protection of sector 18 */
+#define OB_DRP_19 ((uint32_t)0x00800000U) /*!< D-bus read protection protection of sector 19 */
+#define OB_DRP_20 ((uint32_t)0x01000000U) /*!< D-bus read protection protection of sector 20 */
+#define OB_DRP_21 ((uint32_t)0x02000000U) /*!< D-bus read protection protection of sector 21 */
+#define OB_DRP_22 ((uint32_t)0x04000000U) /*!< D-bus read protection protection of sector 22 */
+#define OB_DRP_23_27 ((uint32_t)0x08000000U) /*!< D-bus read protection protection of sector 23~27 */
-/* double banks or single bank selection when flash size is 1M bytes */
+/* double banks or single bank selection when flash size is 1M bytes */
#define OBCTL0_DBS(regval) (BIT(30) & ((uint32_t)(regval)<<30))
#define OB_DBS_DISABLE OBCTL0_DBS(0) /*!< single bank when flash size is 1M bytes */
#define OB_DBS_ENABLE OBCTL0_DBS(1) /*!< double bank when flash size is 1M bytes */
-/* option bytes D-bus read protection mode */
+/* option bytes D-bus read protection mode */
#define OBCTL0_DRP(regval) (BIT(31) & ((uint32_t)(regval)<<31))
#define OB_DRP_DISABLE OBCTL0_DRP(0) /*!< the WPx bits used as erase/program protection of each sector */
#define OB_DRP_ENABLE OBCTL0_DRP(1) /*!< the WPx bits used as erase/program protection and D-bus read protection of each sector */
@@ -260,19 +282,17 @@ typedef enum
#define CTL_SECTOR_NUMBER_21 CTL_SN(25) /*!< sector 21 */
#define CTL_SECTOR_NUMBER_22 CTL_SN(26) /*!< sector 22 */
#define CTL_SECTOR_NUMBER_23 CTL_SN(27) /*!< sector 23 */
-#define CTL_SECTOR_NUMBER_28 CTL_SN(28) /*!< sector 28 */
-#define CTL_SECTOR_NUMBER_29 CTL_SN(29) /*!< sector 29 */
-#define CTL_SECTOR_NUMBER_30 CTL_SN(30) /*!< sector 30 */
-/* FMC program size */
+
+/* FMC program size */
#define CTL_PSZ(regval) (BITS(8,9) & ((uint32_t)(regval))<< 8)
#define CTL_PSZ_BYTE CTL_PSZ(0) /*!< FMC program by byte access */
#define CTL_PSZ_HALF_WORD CTL_PSZ(1) /*!< FMC program by half-word access */
#define CTL_PSZ_WORD CTL_PSZ(2) /*!< FMC program by word access */
/* FMC interrupt enable */
-#define FMC_INTEN_END ((uint32_t)0x01000000U) /*!< enable FMC end of program interrupt */
-#define FMC_INTEN_ERR ((uint32_t)0x02000000U) /*!< enable FMC error interrupt */
+#define FMC_INT_END ((uint32_t)0x01000000U) /*!< enable FMC end of program interrupt */
+#define FMC_INT_ERR ((uint32_t)0x02000000U) /*!< enable FMC error interrupt */
/* FMC flags */
#define FMC_FLAG_END ((uint32_t)0x00000001U) /*!< FMC end of operation flag bit */
@@ -281,7 +301,7 @@ typedef enum
#define FMC_FLAG_PGMERR ((uint32_t)0x00000040U) /*!< FMC program size not match error flag bit */
#define FMC_FLAG_PGSERR ((uint32_t)0x00000080U) /*!< FMC program sequence error flag bit */
#define FMC_FLAG_RDDERR ((uint32_t)0x00000100U) /*!< FMC read D-bus protection error flag bit */
-#define FMC_FLAG_BUSY ((uint32_t)0x00010000U) /*!< FMC busy flag */
+#define FMC_FLAG_BUSY ((uint32_t)0x00010000U) /*!< FMC busy flag */
/* function declarations */
/* FMC main memory programming functions */
@@ -313,25 +333,17 @@ void ob_unlock(void);
void ob_lock(void);
/* send option byte change command */
void ob_start(void);
+/* erase option byte */
+void ob_erase(void);
/* enable write protect */
-void ob_write_protection0_enable(uint32_t ob_wp);
-/* disable write protect */
-void ob_write_protection0_disable(uint32_t ob_wp);
-/* enable write protect */
-void ob_write_protection1_enable(uint32_t ob_wp);
+void ob_write_protection_enable(uint32_t ob_wp);
/* disable write protect */
-void ob_write_protection1_disable(uint32_t ob_wp);
-/* configure the erase/program protection mode */
-void ob_drp_config(uint32_t ob_drp);
-/* enable the erase/program protection mode */
-void ob_drp0_enable(uint32_t ob_drp);
-/* disable the erase/program protection mode */
-void ob_drp0_disable(uint32_t ob_drp);
-/* enable the erase/program protection mode */
-void ob_drp1_enable(uint32_t ob_drp);
-/* disable the erase/program protection mode */
-void ob_drp1_disable(uint32_t ob_drp);
-/* set the option byte security protection level */
+void ob_write_protection_disable(uint32_t ob_wp);
+/* enable erase/program protection and D-bus read protection */
+void ob_drp_enable(uint32_t ob_drp);
+/* disable erase/program protection and D-bus read protection */
+void ob_drp_disable(uint32_t ob_drp);
+/* set the option byte security protection level */
void ob_security_protection_config(uint8_t ob_spc);
/* write the FMC option byte user */
void ob_user_write(uint32_t ob_fwdgt, uint32_t ob_deepsleep, uint32_t ob_stdby);
@@ -366,6 +378,6 @@ void fmc_flag_clear(uint32_t fmc_flag);
/* return the FMC state */
fmc_state_enum fmc_state_get(void);
/* check FMC ready or not */
-fmc_state_enum fmc_ready_wait(uint32_t count);
+fmc_state_enum fmc_ready_wait(void);
#endif /* GD32F4XX_FMC_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_fwdgt.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_fwdgt.h
index b63efc9293..ebee04b637 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_fwdgt.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_fwdgt.h
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_fwdgt.h
- \brief definitions for the FWDGT
+ \file gd32f4xx_fwdgt.h
+ \brief definitions for the FWDGT
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#ifndef GD32F4XX_FWDGT_H
@@ -58,7 +83,13 @@
#define FWDGT_PSC_TIMEOUT ((uint32_t)0x000FFFFFU) /*!< FWDGT_PSC register write operation state flag timeout */
#define FWDGT_RLD_TIMEOUT ((uint32_t)0x000FFFFFU) /*!< FWDGT_RLD register write operation state flag timeout */
+/* FWDGT flag definitions */
+#define FWDGT_FLAG_PUD FWDGT_STAT_PUD /*!< FWDGT prescaler divider value update flag */
+#define FWDGT_FLAG_RUD FWDGT_STAT_RUD /*!< FWDGT counter reload value update flag */
+
/* function declarations */
+/* enable write access to FWDGT_PSC and FWDGT_RLD */
+void fwdgt_write_enable(void);
/* disable write access to FWDGT_PSC and FWDGT_RLD */
void fwdgt_write_disable(void);
/* start the free watchdog timer counter */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_gpio.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_gpio.h
index 257962d6de..81da899427 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_gpio.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_gpio.h
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_gpio.h
- \brief definitions for the GPIO
+ \file gd32f4xx_gpio.h
+ \brief definitions for the GPIO
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#ifndef GD32F4XX_GPIO_H
@@ -41,343 +66,343 @@
/* bits definitions */
/* GPIO_CTL */
-#define GPIO_CTL_CTL0 BITS(0,1) /*!< pin 0 configuration bits */
-#define GPIO_CTL_CTL1 BITS(2,3) /*!< pin 1 configuration bits */
-#define GPIO_CTL_CTL2 BITS(4,5) /*!< pin 2 configuration bits */
-#define GPIO_CTL_CTL3 BITS(6,7) /*!< pin 3 configuration bits */
-#define GPIO_CTL_CTL4 BITS(8,9) /*!< pin 4 configuration bits */
-#define GPIO_CTL_CTL5 BITS(10,11) /*!< pin 5 configuration bits */
-#define GPIO_CTL_CTL6 BITS(12,13) /*!< pin 6 configuration bits */
-#define GPIO_CTL_CTL7 BITS(14,15) /*!< pin 7 configuration bits */
-#define GPIO_CTL_CTL8 BITS(16,17) /*!< pin 8 configuration bits */
-#define GPIO_CTL_CTL9 BITS(18,19) /*!< pin 9 configuration bits */
-#define GPIO_CTL_CTL10 BITS(20,21) /*!< pin 10 configuration bits */
-#define GPIO_CTL_CTL11 BITS(22,23) /*!< pin 11 configuration bits */
-#define GPIO_CTL_CTL12 BITS(24,25) /*!< pin 12 configuration bits */
-#define GPIO_CTL_CTL13 BITS(26,27) /*!< pin 13 configuration bits */
-#define GPIO_CTL_CTL14 BITS(28,29) /*!< pin 14 configuration bits */
-#define GPIO_CTL_CTL15 BITS(30,31) /*!< pin 15 configuration bits */
+#define GPIO_CTL_CTL0 BITS(0,1) /*!< pin 0 configuration bits */
+#define GPIO_CTL_CTL1 BITS(2,3) /*!< pin 1 configuration bits */
+#define GPIO_CTL_CTL2 BITS(4,5) /*!< pin 2 configuration bits */
+#define GPIO_CTL_CTL3 BITS(6,7) /*!< pin 3 configuration bits */
+#define GPIO_CTL_CTL4 BITS(8,9) /*!< pin 4 configuration bits */
+#define GPIO_CTL_CTL5 BITS(10,11) /*!< pin 5 configuration bits */
+#define GPIO_CTL_CTL6 BITS(12,13) /*!< pin 6 configuration bits */
+#define GPIO_CTL_CTL7 BITS(14,15) /*!< pin 7 configuration bits */
+#define GPIO_CTL_CTL8 BITS(16,17) /*!< pin 8 configuration bits */
+#define GPIO_CTL_CTL9 BITS(18,19) /*!< pin 9 configuration bits */
+#define GPIO_CTL_CTL10 BITS(20,21) /*!< pin 10 configuration bits */
+#define GPIO_CTL_CTL11 BITS(22,23) /*!< pin 11 configuration bits */
+#define GPIO_CTL_CTL12 BITS(24,25) /*!< pin 12 configuration bits */
+#define GPIO_CTL_CTL13 BITS(26,27) /*!< pin 13 configuration bits */
+#define GPIO_CTL_CTL14 BITS(28,29) /*!< pin 14 configuration bits */
+#define GPIO_CTL_CTL15 BITS(30,31) /*!< pin 15 configuration bits */
/* GPIO_OMODE */
-#define GPIO_OMODE_OM0 BIT(0) /*!< pin 0 output mode bit */
-#define GPIO_OMODE_OM1 BIT(1) /*!< pin 1 output mode bit */
-#define GPIO_OMODE_OM2 BIT(2) /*!< pin 2 output mode bit */
-#define GPIO_OMODE_OM3 BIT(3) /*!< pin 3 output mode bit */
-#define GPIO_OMODE_OM4 BIT(4) /*!< pin 4 output mode bit */
-#define GPIO_OMODE_OM5 BIT(5) /*!< pin 5 output mode bit */
-#define GPIO_OMODE_OM6 BIT(6) /*!< pin 6 output mode bit */
-#define GPIO_OMODE_OM7 BIT(7) /*!< pin 7 output mode bit */
-#define GPIO_OMODE_OM8 BIT(8) /*!< pin 8 output mode bit */
-#define GPIO_OMODE_OM9 BIT(9) /*!< pin 9 output mode bit */
-#define GPIO_OMODE_OM10 BIT(10) /*!< pin 10 output mode bit */
-#define GPIO_OMODE_OM11 BIT(11) /*!< pin 11 output mode bit */
-#define GPIO_OMODE_OM12 BIT(12) /*!< pin 12 output mode bit */
-#define GPIO_OMODE_OM13 BIT(13) /*!< pin 13 output mode bit */
-#define GPIO_OMODE_OM14 BIT(14) /*!< pin 14 output mode bit */
-#define GPIO_OMODE_OM15 BIT(15) /*!< pin 15 output mode bit */
+#define GPIO_OMODE_OM0 BIT(0) /*!< pin 0 output mode bit */
+#define GPIO_OMODE_OM1 BIT(1) /*!< pin 1 output mode bit */
+#define GPIO_OMODE_OM2 BIT(2) /*!< pin 2 output mode bit */
+#define GPIO_OMODE_OM3 BIT(3) /*!< pin 3 output mode bit */
+#define GPIO_OMODE_OM4 BIT(4) /*!< pin 4 output mode bit */
+#define GPIO_OMODE_OM5 BIT(5) /*!< pin 5 output mode bit */
+#define GPIO_OMODE_OM6 BIT(6) /*!< pin 6 output mode bit */
+#define GPIO_OMODE_OM7 BIT(7) /*!< pin 7 output mode bit */
+#define GPIO_OMODE_OM8 BIT(8) /*!< pin 8 output mode bit */
+#define GPIO_OMODE_OM9 BIT(9) /*!< pin 9 output mode bit */
+#define GPIO_OMODE_OM10 BIT(10) /*!< pin 10 output mode bit */
+#define GPIO_OMODE_OM11 BIT(11) /*!< pin 11 output mode bit */
+#define GPIO_OMODE_OM12 BIT(12) /*!< pin 12 output mode bit */
+#define GPIO_OMODE_OM13 BIT(13) /*!< pin 13 output mode bit */
+#define GPIO_OMODE_OM14 BIT(14) /*!< pin 14 output mode bit */
+#define GPIO_OMODE_OM15 BIT(15) /*!< pin 15 output mode bit */
/* GPIO_OSPD */
-#define GPIO_OSPD_OSPD0 BITS(0,1) /*!< pin 0 output max speed bits */
-#define GPIO_OSPD_OSPD1 BITS(2,3) /*!< pin 1 output max speed bits */
-#define GPIO_OSPD_OSPD2 BITS(4,5) /*!< pin 2 output max speed bits */
-#define GPIO_OSPD_OSPD3 BITS(6,7) /*!< pin 3 output max speed bits */
-#define GPIO_OSPD_OSPD4 BITS(8,9) /*!< pin 4 output max speed bits */
-#define GPIO_OSPD_OSPD5 BITS(10,11) /*!< pin 5 output max speed bits */
-#define GPIO_OSPD_OSPD6 BITS(12,13) /*!< pin 6 output max speed bits */
-#define GPIO_OSPD_OSPD7 BITS(14,15) /*!< pin 7 output max speed bits */
-#define GPIO_OSPD_OSPD8 BITS(16,17) /*!< pin 8 output max speed bits */
-#define GPIO_OSPD_OSPD9 BITS(18,19) /*!< pin 9 output max speed bits */
-#define GPIO_OSPD_OSPD10 BITS(20,21) /*!< pin 10 output max speed bits */
-#define GPIO_OSPD_OSPD11 BITS(22,23) /*!< pin 11 output max speed bits */
-#define GPIO_OSPD_OSPD12 BITS(24,25) /*!< pin 12 output max speed bits */
-#define GPIO_OSPD_OSPD13 BITS(26,27) /*!< pin 13 output max speed bits */
-#define GPIO_OSPD_OSPD14 BITS(28,29) /*!< pin 14 output max speed bits */
-#define GPIO_OSPD_OSPD15 BITS(30,31) /*!< pin 15 output max speed bits */
+#define GPIO_OSPD_OSPD0 BITS(0,1) /*!< pin 0 output max speed bits */
+#define GPIO_OSPD_OSPD1 BITS(2,3) /*!< pin 1 output max speed bits */
+#define GPIO_OSPD_OSPD2 BITS(4,5) /*!< pin 2 output max speed bits */
+#define GPIO_OSPD_OSPD3 BITS(6,7) /*!< pin 3 output max speed bits */
+#define GPIO_OSPD_OSPD4 BITS(8,9) /*!< pin 4 output max speed bits */
+#define GPIO_OSPD_OSPD5 BITS(10,11) /*!< pin 5 output max speed bits */
+#define GPIO_OSPD_OSPD6 BITS(12,13) /*!< pin 6 output max speed bits */
+#define GPIO_OSPD_OSPD7 BITS(14,15) /*!< pin 7 output max speed bits */
+#define GPIO_OSPD_OSPD8 BITS(16,17) /*!< pin 8 output max speed bits */
+#define GPIO_OSPD_OSPD9 BITS(18,19) /*!< pin 9 output max speed bits */
+#define GPIO_OSPD_OSPD10 BITS(20,21) /*!< pin 10 output max speed bits */
+#define GPIO_OSPD_OSPD11 BITS(22,23) /*!< pin 11 output max speed bits */
+#define GPIO_OSPD_OSPD12 BITS(24,25) /*!< pin 12 output max speed bits */
+#define GPIO_OSPD_OSPD13 BITS(26,27) /*!< pin 13 output max speed bits */
+#define GPIO_OSPD_OSPD14 BITS(28,29) /*!< pin 14 output max speed bits */
+#define GPIO_OSPD_OSPD15 BITS(30,31) /*!< pin 15 output max speed bits */
/* GPIO_PUD */
-#define GPIO_PUD_PUD0 BITS(0,1) /*!< pin 0 pull-up or pull-down bits */
-#define GPIO_PUD_PUD1 BITS(2,3) /*!< pin 1 pull-up or pull-down bits */
-#define GPIO_PUD_PUD2 BITS(4,5) /*!< pin 2 pull-up or pull-down bits */
-#define GPIO_PUD_PUD3 BITS(6,7) /*!< pin 3 pull-up or pull-down bits */
-#define GPIO_PUD_PUD4 BITS(8,9) /*!< pin 4 pull-up or pull-down bits */
-#define GPIO_PUD_PUD5 BITS(10,11) /*!< pin 5 pull-up or pull-down bits */
-#define GPIO_PUD_PUD6 BITS(12,13) /*!< pin 6 pull-up or pull-down bits */
-#define GPIO_PUD_PUD7 BITS(14,15) /*!< pin 7 pull-up or pull-down bits */
-#define GPIO_PUD_PUD8 BITS(16,17) /*!< pin 8 pull-up or pull-down bits */
-#define GPIO_PUD_PUD9 BITS(18,19) /*!< pin 9 pull-up or pull-down bits */
-#define GPIO_PUD_PUD10 BITS(20,21) /*!< pin 10 pull-up or pull-down bits */
-#define GPIO_PUD_PUD11 BITS(22,23) /*!< pin 11 pull-up or pull-down bits */
-#define GPIO_PUD_PUD12 BITS(24,25) /*!< pin 12 pull-up or pull-down bits */
-#define GPIO_PUD_PUD13 BITS(26,27) /*!< pin 13 pull-up or pull-down bits */
-#define GPIO_PUD_PUD14 BITS(28,29) /*!< pin 14 pull-up or pull-down bits */
-#define GPIO_PUD_PUD15 BITS(30,31) /*!< pin 15 pull-up or pull-down bits */
+#define GPIO_PUD_PUD0 BITS(0,1) /*!< pin 0 pull-up or pull-down bits */
+#define GPIO_PUD_PUD1 BITS(2,3) /*!< pin 1 pull-up or pull-down bits */
+#define GPIO_PUD_PUD2 BITS(4,5) /*!< pin 2 pull-up or pull-down bits */
+#define GPIO_PUD_PUD3 BITS(6,7) /*!< pin 3 pull-up or pull-down bits */
+#define GPIO_PUD_PUD4 BITS(8,9) /*!< pin 4 pull-up or pull-down bits */
+#define GPIO_PUD_PUD5 BITS(10,11) /*!< pin 5 pull-up or pull-down bits */
+#define GPIO_PUD_PUD6 BITS(12,13) /*!< pin 6 pull-up or pull-down bits */
+#define GPIO_PUD_PUD7 BITS(14,15) /*!< pin 7 pull-up or pull-down bits */
+#define GPIO_PUD_PUD8 BITS(16,17) /*!< pin 8 pull-up or pull-down bits */
+#define GPIO_PUD_PUD9 BITS(18,19) /*!< pin 9 pull-up or pull-down bits */
+#define GPIO_PUD_PUD10 BITS(20,21) /*!< pin 10 pull-up or pull-down bits */
+#define GPIO_PUD_PUD11 BITS(22,23) /*!< pin 11 pull-up or pull-down bits */
+#define GPIO_PUD_PUD12 BITS(24,25) /*!< pin 12 pull-up or pull-down bits */
+#define GPIO_PUD_PUD13 BITS(26,27) /*!< pin 13 pull-up or pull-down bits */
+#define GPIO_PUD_PUD14 BITS(28,29) /*!< pin 14 pull-up or pull-down bits */
+#define GPIO_PUD_PUD15 BITS(30,31) /*!< pin 15 pull-up or pull-down bits */
/* GPIO_ISTAT */
-#define GPIO_ISTAT_ISTAT0 BIT(0) /*!< pin 0 input status */
-#define GPIO_ISTAT_ISTAT1 BIT(1) /*!< pin 1 input status */
-#define GPIO_ISTAT_ISTAT2 BIT(2) /*!< pin 2 input status */
-#define GPIO_ISTAT_ISTAT3 BIT(3) /*!< pin 3 input status */
-#define GPIO_ISTAT_ISTAT4 BIT(4) /*!< pin 4 input status */
-#define GPIO_ISTAT_ISTAT5 BIT(5) /*!< pin 5 input status */
-#define GPIO_ISTAT_ISTAT6 BIT(6) /*!< pin 6 input status */
-#define GPIO_ISTAT_ISTAT7 BIT(7) /*!< pin 7 input status */
-#define GPIO_ISTAT_ISTAT8 BIT(8) /*!< pin 8 input status */
-#define GPIO_ISTAT_ISTAT9 BIT(9) /*!< pin 9 input status */
-#define GPIO_ISTAT_ISTAT10 BIT(10) /*!< pin 10 input status */
-#define GPIO_ISTAT_ISTAT11 BIT(11) /*!< pin 11 input status */
-#define GPIO_ISTAT_ISTAT12 BIT(12) /*!< pin 12 input status */
-#define GPIO_ISTAT_ISTAT13 BIT(13) /*!< pin 13 input status */
-#define GPIO_ISTAT_ISTAT14 BIT(14) /*!< pin 14 input status */
-#define GPIO_ISTAT_ISTAT15 BIT(15) /*!< pin 15 input status */
+#define GPIO_ISTAT_ISTAT0 BIT(0) /*!< pin 0 input status */
+#define GPIO_ISTAT_ISTAT1 BIT(1) /*!< pin 1 input status */
+#define GPIO_ISTAT_ISTAT2 BIT(2) /*!< pin 2 input status */
+#define GPIO_ISTAT_ISTAT3 BIT(3) /*!< pin 3 input status */
+#define GPIO_ISTAT_ISTAT4 BIT(4) /*!< pin 4 input status */
+#define GPIO_ISTAT_ISTAT5 BIT(5) /*!< pin 5 input status */
+#define GPIO_ISTAT_ISTAT6 BIT(6) /*!< pin 6 input status */
+#define GPIO_ISTAT_ISTAT7 BIT(7) /*!< pin 7 input status */
+#define GPIO_ISTAT_ISTAT8 BIT(8) /*!< pin 8 input status */
+#define GPIO_ISTAT_ISTAT9 BIT(9) /*!< pin 9 input status */
+#define GPIO_ISTAT_ISTAT10 BIT(10) /*!< pin 10 input status */
+#define GPIO_ISTAT_ISTAT11 BIT(11) /*!< pin 11 input status */
+#define GPIO_ISTAT_ISTAT12 BIT(12) /*!< pin 12 input status */
+#define GPIO_ISTAT_ISTAT13 BIT(13) /*!< pin 13 input status */
+#define GPIO_ISTAT_ISTAT14 BIT(14) /*!< pin 14 input status */
+#define GPIO_ISTAT_ISTAT15 BIT(15) /*!< pin 15 input status */
/* GPIO_OCTL */
-#define GPIO_OCTL_OCTL0 BIT(0) /*!< pin 0 output bit */
-#define GPIO_OCTL_OCTL1 BIT(1) /*!< pin 1 output bit */
-#define GPIO_OCTL_OCTL2 BIT(2) /*!< pin 2 output bit */
-#define GPIO_OCTL_OCTL3 BIT(3) /*!< pin 3 output bit */
-#define GPIO_OCTL_OCTL4 BIT(4) /*!< pin 4 output bit */
-#define GPIO_OCTL_OCTL5 BIT(5) /*!< pin 5 output bit */
-#define GPIO_OCTL_OCTL6 BIT(6) /*!< pin 6 output bit */
-#define GPIO_OCTL_OCTL7 BIT(7) /*!< pin 7 output bit */
-#define GPIO_OCTL_OCTL8 BIT(8) /*!< pin 8 output bit */
-#define GPIO_OCTL_OCTL9 BIT(9) /*!< pin 9 output bit */
-#define GPIO_OCTL_OCTL10 BIT(10) /*!< pin 10 output bit */
-#define GPIO_OCTL_OCTL11 BIT(11) /*!< pin 11 output bit */
-#define GPIO_OCTL_OCTL12 BIT(12) /*!< pin 12 output bit */
-#define GPIO_OCTL_OCTL13 BIT(13) /*!< pin 13 output bit */
-#define GPIO_OCTL_OCTL14 BIT(14) /*!< pin 14 output bit */
-#define GPIO_OCTL_OCTL15 BIT(15) /*!< pin 15 output bit */
+#define GPIO_OCTL_OCTL0 BIT(0) /*!< pin 0 output bit */
+#define GPIO_OCTL_OCTL1 BIT(1) /*!< pin 1 output bit */
+#define GPIO_OCTL_OCTL2 BIT(2) /*!< pin 2 output bit */
+#define GPIO_OCTL_OCTL3 BIT(3) /*!< pin 3 output bit */
+#define GPIO_OCTL_OCTL4 BIT(4) /*!< pin 4 output bit */
+#define GPIO_OCTL_OCTL5 BIT(5) /*!< pin 5 output bit */
+#define GPIO_OCTL_OCTL6 BIT(6) /*!< pin 6 output bit */
+#define GPIO_OCTL_OCTL7 BIT(7) /*!< pin 7 output bit */
+#define GPIO_OCTL_OCTL8 BIT(8) /*!< pin 8 output bit */
+#define GPIO_OCTL_OCTL9 BIT(9) /*!< pin 9 output bit */
+#define GPIO_OCTL_OCTL10 BIT(10) /*!< pin 10 output bit */
+#define GPIO_OCTL_OCTL11 BIT(11) /*!< pin 11 output bit */
+#define GPIO_OCTL_OCTL12 BIT(12) /*!< pin 12 output bit */
+#define GPIO_OCTL_OCTL13 BIT(13) /*!< pin 13 output bit */
+#define GPIO_OCTL_OCTL14 BIT(14) /*!< pin 14 output bit */
+#define GPIO_OCTL_OCTL15 BIT(15) /*!< pin 15 output bit */
/* GPIO_BOP */
-#define GPIO_BOP_BOP0 BIT(0) /*!< pin 0 set bit */
-#define GPIO_BOP_BOP1 BIT(1) /*!< pin 1 set bit */
-#define GPIO_BOP_BOP2 BIT(2) /*!< pin 2 set bit */
-#define GPIO_BOP_BOP3 BIT(3) /*!< pin 3 set bit */
-#define GPIO_BOP_BOP4 BIT(4) /*!< pin 4 set bit */
-#define GPIO_BOP_BOP5 BIT(5) /*!< pin 5 set bit */
-#define GPIO_BOP_BOP6 BIT(6) /*!< pin 6 set bit */
-#define GPIO_BOP_BOP7 BIT(7) /*!< pin 7 set bit */
-#define GPIO_BOP_BOP8 BIT(8) /*!< pin 8 set bit */
-#define GPIO_BOP_BOP9 BIT(9) /*!< pin 9 set bit */
-#define GPIO_BOP_BOP10 BIT(10) /*!< pin 10 set bit */
-#define GPIO_BOP_BOP11 BIT(11) /*!< pin 11 set bit */
-#define GPIO_BOP_BOP12 BIT(12) /*!< pin 12 set bit */
-#define GPIO_BOP_BOP13 BIT(13) /*!< pin 13 set bit */
-#define GPIO_BOP_BOP14 BIT(14) /*!< pin 14 set bit */
-#define GPIO_BOP_BOP15 BIT(15) /*!< pin 15 set bit */
-#define GPIO_BOP_CR0 BIT(16) /*!< pin 0 clear bit */
-#define GPIO_BOP_CR1 BIT(17) /*!< pin 1 clear bit */
-#define GPIO_BOP_CR2 BIT(18) /*!< pin 2 clear bit */
-#define GPIO_BOP_CR3 BIT(19) /*!< pin 3 clear bit */
-#define GPIO_BOP_CR4 BIT(20) /*!< pin 4 clear bit */
-#define GPIO_BOP_CR5 BIT(21) /*!< pin 5 clear bit */
-#define GPIO_BOP_CR6 BIT(22) /*!< pin 6 clear bit */
-#define GPIO_BOP_CR7 BIT(23) /*!< pin 7 clear bit */
-#define GPIO_BOP_CR8 BIT(24) /*!< pin 8 clear bit */
-#define GPIO_BOP_CR9 BIT(25) /*!< pin 9 clear bit */
-#define GPIO_BOP_CR10 BIT(26) /*!< pin 10 clear bit */
-#define GPIO_BOP_CR11 BIT(27) /*!< pin 11 clear bit */
-#define GPIO_BOP_CR12 BIT(28) /*!< pin 12 clear bit */
-#define GPIO_BOP_CR13 BIT(29) /*!< pin 13 clear bit */
-#define GPIO_BOP_CR14 BIT(30) /*!< pin 14 clear bit */
-#define GPIO_BOP_CR15 BIT(31) /*!< pin 15 clear bit */
+#define GPIO_BOP_BOP0 BIT(0) /*!< pin 0 set bit */
+#define GPIO_BOP_BOP1 BIT(1) /*!< pin 1 set bit */
+#define GPIO_BOP_BOP2 BIT(2) /*!< pin 2 set bit */
+#define GPIO_BOP_BOP3 BIT(3) /*!< pin 3 set bit */
+#define GPIO_BOP_BOP4 BIT(4) /*!< pin 4 set bit */
+#define GPIO_BOP_BOP5 BIT(5) /*!< pin 5 set bit */
+#define GPIO_BOP_BOP6 BIT(6) /*!< pin 6 set bit */
+#define GPIO_BOP_BOP7 BIT(7) /*!< pin 7 set bit */
+#define GPIO_BOP_BOP8 BIT(8) /*!< pin 8 set bit */
+#define GPIO_BOP_BOP9 BIT(9) /*!< pin 9 set bit */
+#define GPIO_BOP_BOP10 BIT(10) /*!< pin 10 set bit */
+#define GPIO_BOP_BOP11 BIT(11) /*!< pin 11 set bit */
+#define GPIO_BOP_BOP12 BIT(12) /*!< pin 12 set bit */
+#define GPIO_BOP_BOP13 BIT(13) /*!< pin 13 set bit */
+#define GPIO_BOP_BOP14 BIT(14) /*!< pin 14 set bit */
+#define GPIO_BOP_BOP15 BIT(15) /*!< pin 15 set bit */
+#define GPIO_BOP_CR0 BIT(16) /*!< pin 0 clear bit */
+#define GPIO_BOP_CR1 BIT(17) /*!< pin 1 clear bit */
+#define GPIO_BOP_CR2 BIT(18) /*!< pin 2 clear bit */
+#define GPIO_BOP_CR3 BIT(19) /*!< pin 3 clear bit */
+#define GPIO_BOP_CR4 BIT(20) /*!< pin 4 clear bit */
+#define GPIO_BOP_CR5 BIT(21) /*!< pin 5 clear bit */
+#define GPIO_BOP_CR6 BIT(22) /*!< pin 6 clear bit */
+#define GPIO_BOP_CR7 BIT(23) /*!< pin 7 clear bit */
+#define GPIO_BOP_CR8 BIT(24) /*!< pin 8 clear bit */
+#define GPIO_BOP_CR9 BIT(25) /*!< pin 9 clear bit */
+#define GPIO_BOP_CR10 BIT(26) /*!< pin 10 clear bit */
+#define GPIO_BOP_CR11 BIT(27) /*!< pin 11 clear bit */
+#define GPIO_BOP_CR12 BIT(28) /*!< pin 12 clear bit */
+#define GPIO_BOP_CR13 BIT(29) /*!< pin 13 clear bit */
+#define GPIO_BOP_CR14 BIT(30) /*!< pin 14 clear bit */
+#define GPIO_BOP_CR15 BIT(31) /*!< pin 15 clear bit */
/* GPIO_LOCK */
-#define GPIO_LOCK_LK0 BIT(0) /*!< pin 0 lock bit */
-#define GPIO_LOCK_LK1 BIT(1) /*!< pin 1 lock bit */
-#define GPIO_LOCK_LK2 BIT(2) /*!< pin 2 lock bit */
-#define GPIO_LOCK_LK3 BIT(3) /*!< pin 3 lock bit */
-#define GPIO_LOCK_LK4 BIT(4) /*!< pin 4 lock bit */
-#define GPIO_LOCK_LK5 BIT(5) /*!< pin 5 lock bit */
-#define GPIO_LOCK_LK6 BIT(6) /*!< pin 6 lock bit */
-#define GPIO_LOCK_LK7 BIT(7) /*!< pin 7 lock bit */
-#define GPIO_LOCK_LK8 BIT(8) /*!< pin 8 lock bit */
-#define GPIO_LOCK_LK9 BIT(9) /*!< pin 9 lock bit */
-#define GPIO_LOCK_LK10 BIT(10) /*!< pin 10 lock bit */
-#define GPIO_LOCK_LK11 BIT(11) /*!< pin 11 lock bit */
-#define GPIO_LOCK_LK12 BIT(12) /*!< pin 12 lock bit */
-#define GPIO_LOCK_LK13 BIT(13) /*!< pin 13 lock bit */
-#define GPIO_LOCK_LK14 BIT(14) /*!< pin 14 lock bit */
-#define GPIO_LOCK_LK15 BIT(15) /*!< pin 15 lock bit */
-#define GPIO_LOCK_LKK BIT(16) /*!< pin sequence lock key */
+#define GPIO_LOCK_LK0 BIT(0) /*!< pin 0 lock bit */
+#define GPIO_LOCK_LK1 BIT(1) /*!< pin 1 lock bit */
+#define GPIO_LOCK_LK2 BIT(2) /*!< pin 2 lock bit */
+#define GPIO_LOCK_LK3 BIT(3) /*!< pin 3 lock bit */
+#define GPIO_LOCK_LK4 BIT(4) /*!< pin 4 lock bit */
+#define GPIO_LOCK_LK5 BIT(5) /*!< pin 5 lock bit */
+#define GPIO_LOCK_LK6 BIT(6) /*!< pin 6 lock bit */
+#define GPIO_LOCK_LK7 BIT(7) /*!< pin 7 lock bit */
+#define GPIO_LOCK_LK8 BIT(8) /*!< pin 8 lock bit */
+#define GPIO_LOCK_LK9 BIT(9) /*!< pin 9 lock bit */
+#define GPIO_LOCK_LK10 BIT(10) /*!< pin 10 lock bit */
+#define GPIO_LOCK_LK11 BIT(11) /*!< pin 11 lock bit */
+#define GPIO_LOCK_LK12 BIT(12) /*!< pin 12 lock bit */
+#define GPIO_LOCK_LK13 BIT(13) /*!< pin 13 lock bit */
+#define GPIO_LOCK_LK14 BIT(14) /*!< pin 14 lock bit */
+#define GPIO_LOCK_LK15 BIT(15) /*!< pin 15 lock bit */
+#define GPIO_LOCK_LKK BIT(16) /*!< pin sequence lock key */
/* GPIO_AFSEL0 */
-#define GPIO_AFSEL0_SEL0 BITS(0,3) /*!< pin 0 alternate function selected */
-#define GPIO_AFSEL0_SEL1 BITS(4,7) /*!< pin 1 alternate function selected */
-#define GPIO_AFSEL0_SEL2 BITS(8,11) /*!< pin 2 alternate function selected */
-#define GPIO_AFSEL0_SEL3 BITS(12,15) /*!< pin 3 alternate function selected */
-#define GPIO_AFSEL0_SEL4 BITS(16,19) /*!< pin 4 alternate function selected */
-#define GPIO_AFSEL0_SEL5 BITS(20,23) /*!< pin 5 alternate function selected */
-#define GPIO_AFSEL0_SEL6 BITS(24,27) /*!< pin 6 alternate function selected */
-#define GPIO_AFSEL0_SEL7 BITS(28,31) /*!< pin 7 alternate function selected */
+#define GPIO_AFSEL0_SEL0 BITS(0,3) /*!< pin 0 alternate function selected */
+#define GPIO_AFSEL0_SEL1 BITS(4,7) /*!< pin 1 alternate function selected */
+#define GPIO_AFSEL0_SEL2 BITS(8,11) /*!< pin 2 alternate function selected */
+#define GPIO_AFSEL0_SEL3 BITS(12,15) /*!< pin 3 alternate function selected */
+#define GPIO_AFSEL0_SEL4 BITS(16,19) /*!< pin 4 alternate function selected */
+#define GPIO_AFSEL0_SEL5 BITS(20,23) /*!< pin 5 alternate function selected */
+#define GPIO_AFSEL0_SEL6 BITS(24,27) /*!< pin 6 alternate function selected */
+#define GPIO_AFSEL0_SEL7 BITS(28,31) /*!< pin 7 alternate function selected */
/* GPIO_AFSEL1 */
-#define GPIO_AFSEL1_SEL8 BITS(0,3) /*!< pin 8 alternate function selected */
-#define GPIO_AFSEL1_SEL9 BITS(4,7) /*!< pin 9 alternate function selected */
-#define GPIO_AFSEL1_SEL10 BITS(8,11) /*!< pin 10 alternate function selected */
-#define GPIO_AFSEL1_SEL11 BITS(12,15) /*!< pin 11 alternate function selected */
-#define GPIO_AFSEL1_SEL12 BITS(16,19) /*!< pin 12 alternate function selected */
-#define GPIO_AFSEL1_SEL13 BITS(20,23) /*!< pin 13 alternate function selected */
-#define GPIO_AFSEL1_SEL14 BITS(24,27) /*!< pin 14 alternate function selected */
-#define GPIO_AFSEL1_SEL15 BITS(28,31) /*!< pin 15 alternate function selected */
+#define GPIO_AFSEL1_SEL8 BITS(0,3) /*!< pin 8 alternate function selected */
+#define GPIO_AFSEL1_SEL9 BITS(4,7) /*!< pin 9 alternate function selected */
+#define GPIO_AFSEL1_SEL10 BITS(8,11) /*!< pin 10 alternate function selected */
+#define GPIO_AFSEL1_SEL11 BITS(12,15) /*!< pin 11 alternate function selected */
+#define GPIO_AFSEL1_SEL12 BITS(16,19) /*!< pin 12 alternate function selected */
+#define GPIO_AFSEL1_SEL13 BITS(20,23) /*!< pin 13 alternate function selected */
+#define GPIO_AFSEL1_SEL14 BITS(24,27) /*!< pin 14 alternate function selected */
+#define GPIO_AFSEL1_SEL15 BITS(28,31) /*!< pin 15 alternate function selected */
/* GPIO_BC */
-#define GPIO_BC_CR0 BIT(0) /*!< pin 0 clear bit */
-#define GPIO_BC_CR1 BIT(1) /*!< pin 1 clear bit */
-#define GPIO_BC_CR2 BIT(2) /*!< pin 2 clear bit */
-#define GPIO_BC_CR3 BIT(3) /*!< pin 3 clear bit */
-#define GPIO_BC_CR4 BIT(4) /*!< pin 4 clear bit */
-#define GPIO_BC_CR5 BIT(5) /*!< pin 5 clear bit */
-#define GPIO_BC_CR6 BIT(6) /*!< pin 6 clear bit */
-#define GPIO_BC_CR7 BIT(7) /*!< pin 7 clear bit */
-#define GPIO_BC_CR8 BIT(8) /*!< pin 8 clear bit */
-#define GPIO_BC_CR9 BIT(9) /*!< pin 9 clear bit */
-#define GPIO_BC_CR10 BIT(10) /*!< pin 10 clear bit */
-#define GPIO_BC_CR11 BIT(11) /*!< pin 11 clear bit */
-#define GPIO_BC_CR12 BIT(12) /*!< pin 12 clear bit */
-#define GPIO_BC_CR13 BIT(13) /*!< pin 13 clear bit */
-#define GPIO_BC_CR14 BIT(14) /*!< pin 14 clear bit */
-#define GPIO_BC_CR15 BIT(15) /*!< pin 15 clear bit */
+#define GPIO_BC_CR0 BIT(0) /*!< pin 0 clear bit */
+#define GPIO_BC_CR1 BIT(1) /*!< pin 1 clear bit */
+#define GPIO_BC_CR2 BIT(2) /*!< pin 2 clear bit */
+#define GPIO_BC_CR3 BIT(3) /*!< pin 3 clear bit */
+#define GPIO_BC_CR4 BIT(4) /*!< pin 4 clear bit */
+#define GPIO_BC_CR5 BIT(5) /*!< pin 5 clear bit */
+#define GPIO_BC_CR6 BIT(6) /*!< pin 6 clear bit */
+#define GPIO_BC_CR7 BIT(7) /*!< pin 7 clear bit */
+#define GPIO_BC_CR8 BIT(8) /*!< pin 8 clear bit */
+#define GPIO_BC_CR9 BIT(9) /*!< pin 9 clear bit */
+#define GPIO_BC_CR10 BIT(10) /*!< pin 10 clear bit */
+#define GPIO_BC_CR11 BIT(11) /*!< pin 11 clear bit */
+#define GPIO_BC_CR12 BIT(12) /*!< pin 12 clear bit */
+#define GPIO_BC_CR13 BIT(13) /*!< pin 13 clear bit */
+#define GPIO_BC_CR14 BIT(14) /*!< pin 14 clear bit */
+#define GPIO_BC_CR15 BIT(15) /*!< pin 15 clear bit */
/* GPIO_TG */
-#define GPIO_TG_TG0 BIT(0) /*!< pin 0 toggle bit */
-#define GPIO_TG_TG1 BIT(1) /*!< pin 1 toggle bit */
-#define GPIO_TG_TG2 BIT(2) /*!< pin 2 toggle bit */
-#define GPIO_TG_TG3 BIT(3) /*!< pin 3 toggle bit */
-#define GPIO_TG_TG4 BIT(4) /*!< pin 4 toggle bit */
-#define GPIO_TG_TG5 BIT(5) /*!< pin 5 toggle bit */
-#define GPIO_TG_TG6 BIT(6) /*!< pin 6 toggle bit */
-#define GPIO_TG_TG7 BIT(7) /*!< pin 7 toggle bit */
-#define GPIO_TG_TG8 BIT(8) /*!< pin 8 toggle bit */
-#define GPIO_TG_TG9 BIT(9) /*!< pin 9 toggle bit */
-#define GPIO_TG_TG10 BIT(10) /*!< pin 10 toggle bit */
-#define GPIO_TG_TG11 BIT(11) /*!< pin 11 toggle bit */
-#define GPIO_TG_TG12 BIT(12) /*!< pin 12 toggle bit */
-#define GPIO_TG_TG13 BIT(13) /*!< pin 13 toggle bit */
-#define GPIO_TG_TG14 BIT(14) /*!< pin 14 toggle bit */
-#define GPIO_TG_TG15 BIT(15) /*!< pin 15 toggle bit */
+#define GPIO_TG_TG0 BIT(0) /*!< pin 0 toggle bit */
+#define GPIO_TG_TG1 BIT(1) /*!< pin 1 toggle bit */
+#define GPIO_TG_TG2 BIT(2) /*!< pin 2 toggle bit */
+#define GPIO_TG_TG3 BIT(3) /*!< pin 3 toggle bit */
+#define GPIO_TG_TG4 BIT(4) /*!< pin 4 toggle bit */
+#define GPIO_TG_TG5 BIT(5) /*!< pin 5 toggle bit */
+#define GPIO_TG_TG6 BIT(6) /*!< pin 6 toggle bit */
+#define GPIO_TG_TG7 BIT(7) /*!< pin 7 toggle bit */
+#define GPIO_TG_TG8 BIT(8) /*!< pin 8 toggle bit */
+#define GPIO_TG_TG9 BIT(9) /*!< pin 9 toggle bit */
+#define GPIO_TG_TG10 BIT(10) /*!< pin 10 toggle bit */
+#define GPIO_TG_TG11 BIT(11) /*!< pin 11 toggle bit */
+#define GPIO_TG_TG12 BIT(12) /*!< pin 12 toggle bit */
+#define GPIO_TG_TG13 BIT(13) /*!< pin 13 toggle bit */
+#define GPIO_TG_TG14 BIT(14) /*!< pin 14 toggle bit */
+#define GPIO_TG_TG15 BIT(15) /*!< pin 15 toggle bit */
/* constants definitions */
typedef FlagStatus bit_status;
/* output mode definitions */
#define CTL_CLTR(regval) (BITS(0,1) & ((uint32_t)(regval) << 0))
-#define GPIO_MODE_INPUT CTL_CLTR(0) /*!< input mode */
-#define GPIO_MODE_OUTPUT CTL_CLTR(1) /*!< output mode */
-#define GPIO_MODE_AF CTL_CLTR(2) /*!< alternate function mode */
-#define GPIO_MODE_ANALOG CTL_CLTR(3) /*!< analog mode */
+#define GPIO_MODE_INPUT CTL_CLTR(0) /*!< input mode */
+#define GPIO_MODE_OUTPUT CTL_CLTR(1) /*!< output mode */
+#define GPIO_MODE_AF CTL_CLTR(2) /*!< alternate function mode */
+#define GPIO_MODE_ANALOG CTL_CLTR(3) /*!< analog mode */
-/* pull up pull down definitions */
+/* pull-up/ pull-down definitions */
#define PUD_PUPD(regval) (BITS(0,1) & ((uint32_t)(regval) << 0))
-#define GPIO_PUPD_NONE PUD_PUPD(0) /*!< without weak pull-up and pull-down resistors */
-#define GPIO_PUPD_PULLUP PUD_PUPD(1) /*!< with weak pull-up resistor */
-#define GPIO_PUPD_PULLDOWN PUD_PUPD(2) /*!< with weak pull-down resistor */
+#define GPIO_PUPD_NONE PUD_PUPD(0) /*!< floating mode, no pull-up and pull-down resistors */
+#define GPIO_PUPD_PULLUP PUD_PUPD(1) /*!< with pull-up resistor */
+#define GPIO_PUPD_PULLDOWN PUD_PUPD(2) /*!< with pull-down resistor */
-/* gpio pin definitions */
-#define GPIO_PIN_0 BIT(0) /*!< GPIO pin 0 */
-#define GPIO_PIN_1 BIT(1) /*!< GPIO pin 1 */
-#define GPIO_PIN_2 BIT(2) /*!< GPIO pin 2 */
-#define GPIO_PIN_3 BIT(3) /*!< GPIO pin 3 */
-#define GPIO_PIN_4 BIT(4) /*!< GPIO pin 4 */
-#define GPIO_PIN_5 BIT(5) /*!< GPIO pin 5 */
-#define GPIO_PIN_6 BIT(6) /*!< GPIO pin 6 */
-#define GPIO_PIN_7 BIT(7) /*!< GPIO pin 7 */
-#define GPIO_PIN_8 BIT(8) /*!< GPIO pin 8 */
-#define GPIO_PIN_9 BIT(9) /*!< GPIO pin 9 */
-#define GPIO_PIN_10 BIT(10) /*!< GPIO pin 10 */
-#define GPIO_PIN_11 BIT(11) /*!< GPIO pin 11 */
-#define GPIO_PIN_12 BIT(12) /*!< GPIO pin 12 */
-#define GPIO_PIN_13 BIT(13) /*!< GPIO pin 13 */
-#define GPIO_PIN_14 BIT(14) /*!< GPIO pin 14 */
-#define GPIO_PIN_15 BIT(15) /*!< GPIO pin 15 */
-#define GPIO_PIN_ALL ((uint32_t)(0xFFFF)) /*!< GPIO pin all */
+/* GPIO pin definitions */
+#define GPIO_PIN_0 BIT(0) /*!< GPIO pin 0 */
+#define GPIO_PIN_1 BIT(1) /*!< GPIO pin 1 */
+#define GPIO_PIN_2 BIT(2) /*!< GPIO pin 2 */
+#define GPIO_PIN_3 BIT(3) /*!< GPIO pin 3 */
+#define GPIO_PIN_4 BIT(4) /*!< GPIO pin 4 */
+#define GPIO_PIN_5 BIT(5) /*!< GPIO pin 5 */
+#define GPIO_PIN_6 BIT(6) /*!< GPIO pin 6 */
+#define GPIO_PIN_7 BIT(7) /*!< GPIO pin 7 */
+#define GPIO_PIN_8 BIT(8) /*!< GPIO pin 8 */
+#define GPIO_PIN_9 BIT(9) /*!< GPIO pin 9 */
+#define GPIO_PIN_10 BIT(10) /*!< GPIO pin 10 */
+#define GPIO_PIN_11 BIT(11) /*!< GPIO pin 11 */
+#define GPIO_PIN_12 BIT(12) /*!< GPIO pin 12 */
+#define GPIO_PIN_13 BIT(13) /*!< GPIO pin 13 */
+#define GPIO_PIN_14 BIT(14) /*!< GPIO pin 14 */
+#define GPIO_PIN_15 BIT(15) /*!< GPIO pin 15 */
+#define GPIO_PIN_ALL BITS(0,15) /*!< GPIO pin all */
-/* gpio ctlr values */
+/* GPIO mode configuration values */
#define GPIO_MODE_SET(n, mode) ((uint32_t)((uint32_t)(mode) << (2U * (n))))
#define GPIO_MODE_MASK(n) (0x3U << (2U * (n)))
-/* gpio pull up pull down values */
+/* GPIO pull-up/ pull-down values */
#define GPIO_PUPD_SET(n, pupd) ((uint32_t)((uint32_t)(pupd) << (2U * (n))))
#define GPIO_PUPD_MASK(n) (0x3U << (2U * (n)))
-/* gpio output speed values */
+/* GPIO output speed values */
#define GPIO_OSPEED_SET(n, speed) ((uint32_t)((uint32_t)(speed) << (2U * (n))))
#define GPIO_OSPEED_MASK(n) (0x3U << (2U * (n)))
-/* gpio output type */
-#define GPIO_OTYPE_PP ((uint8_t)(0x00)) /*!< push pull mode */
-#define GPIO_OTYPE_OD ((uint8_t)(0x01)) /*!< open drain mode */
+/* GPIO output type */
+#define GPIO_OTYPE_PP ((uint8_t)(0x00U)) /*!< push pull mode */
+#define GPIO_OTYPE_OD ((uint8_t)(0x01U)) /*!< open drain mode */
-/* gpio output max speed level */
+/* GPIO output max speed level */
#define OSPD_OSPD(regval) (BITS(0,1) & ((uint32_t)(regval) << 0))
-#define GPIO_OSPEED_LEVEL0 OSPD_OSPD(0) /*!< output max speed level 0 */
-#define GPIO_OSPEED_LEVEL1 OSPD_OSPD(1) /*!< output max speed level 1 */
-#define GPIO_OSPEED_LEVEL2 OSPD_OSPD(2) /*!< output max speed level 2 */
-#define GPIO_OSPEED_LEVEL3 OSPD_OSPD(3) /*!< output max speed level 3 */
+#define GPIO_OSPEED_LEVEL0 OSPD_OSPD(0) /*!< output max speed level 0 */
+#define GPIO_OSPEED_LEVEL1 OSPD_OSPD(1) /*!< output max speed level 1 */
+#define GPIO_OSPEED_LEVEL2 OSPD_OSPD(2) /*!< output max speed level 2 */
+#define GPIO_OSPEED_LEVEL3 OSPD_OSPD(3) /*!< output max speed level 3 */
-/* gpio output max speed value */
-#define GPIO_OSPEED_2MHZ GPIO_OSPEED_LEVEL0 /*!< output max speed 2M */
-#define GPIO_OSPEED_25MHZ GPIO_OSPEED_LEVEL1 /*!< output max speed 25M */
-#define GPIO_OSPEED_50MHZ GPIO_OSPEED_LEVEL2 /*!< output max speed 50M */
-#define GPIO_OSPEED_200MHZ GPIO_OSPEED_LEVEL3 /*!< output max speed 200M */
+/* GPIO output max speed value */
+#define GPIO_OSPEED_2MHZ GPIO_OSPEED_LEVEL0 /*!< output max speed 2MHz */
+#define GPIO_OSPEED_25MHZ GPIO_OSPEED_LEVEL1 /*!< output max speed 25MHz */
+#define GPIO_OSPEED_50MHZ GPIO_OSPEED_LEVEL2 /*!< output max speed 50MHz */
+#define GPIO_OSPEED_200MHZ GPIO_OSPEED_LEVEL3 /*!< output max speed 200MHz */
-/* gpio alternate function values */
+/* GPIO alternate function values */
#define GPIO_AFR_SET(n, af) ((uint32_t)((uint32_t)(af) << (4U * (n))))
#define GPIO_AFR_MASK(n) (0xFU << (4U * (n)))
-
-/* gpio alternate function */
-#define AF(regval) (BITS(0,3) & ((uint32_t)(regval) << 0))
-#define GPIO_AF_0 AF(0) /*!< alternate function selected 0 */
-#define GPIO_AF_1 AF(1) /*!< alternate function selected 1 */
-#define GPIO_AF_2 AF(2) /*!< alternate function selected 2 */
-#define GPIO_AF_3 AF(3) /*!< alternate function selected 3 */
-#define GPIO_AF_4 AF(4) /*!< alternate function selected 4 */
-#define GPIO_AF_5 AF(5) /*!< alternate function selected 5 */
-#define GPIO_AF_6 AF(6) /*!< alternate function selected 6 */
-#define GPIO_AF_7 AF(7) /*!< alternate function selected 7 */
-#define GPIO_AF_8 AF(8) /*!< alternate function selected 8 */
-#define GPIO_AF_9 AF(9) /*!< alternate function selected 9 */
-#define GPIO_AF_10 AF(10) /*!< alternate function selected 10 */
-#define GPIO_AF_11 AF(11) /*!< alternate function selected 11 */
-#define GPIO_AF_12 AF(12) /*!< alternate function selected 12 */
-#define GPIO_AF_13 AF(13) /*!< alternate function selected 13 */
-#define GPIO_AF_14 AF(14) /*!< alternate function selected 14 */
-#define GPIO_AF_15 AF(15) /*!< alternate function selected 15 */
+
+/* GPIO alternate function */
+#define AF(regval) (BITS(0,3) & ((uint32_t)(regval) << 0))
+#define GPIO_AF_0 AF(0) /*!< alternate function 0 selected */
+#define GPIO_AF_1 AF(1) /*!< alternate function 1 selected */
+#define GPIO_AF_2 AF(2) /*!< alternate function 2 selected */
+#define GPIO_AF_3 AF(3) /*!< alternate function 3 selected */
+#define GPIO_AF_4 AF(4) /*!< alternate function 4 selected */
+#define GPIO_AF_5 AF(5) /*!< alternate function 5 selected */
+#define GPIO_AF_6 AF(6) /*!< alternate function 6 selected */
+#define GPIO_AF_7 AF(7) /*!< alternate function 7 selected */
+#define GPIO_AF_8 AF(8) /*!< alternate function 8 selected */
+#define GPIO_AF_9 AF(9) /*!< alternate function 9 selected */
+#define GPIO_AF_10 AF(10) /*!< alternate function 10 selected */
+#define GPIO_AF_11 AF(11) /*!< alternate function 11 selected */
+#define GPIO_AF_12 AF(12) /*!< alternate function 12 selected */
+#define GPIO_AF_13 AF(13) /*!< alternate function 13 selected */
+#define GPIO_AF_14 AF(14) /*!< alternate function 14 selected */
+#define GPIO_AF_15 AF(15) /*!< alternate function 15 selected */
/* function declarations */
-/* reset gpio port */
+/* reset GPIO port */
void gpio_deinit(uint32_t gpio_periph);
-/* set gpio mode */
-void gpio_mode_set(uint32_t gpio_periph,uint32_t mode,uint32_t pull_up_down,uint32_t pin);
-/* set gpio output type and speed */
-void gpio_output_options_set(uint32_t gpio_periph,uint8_t otype,uint32_t speed,uint32_t pin);
+/* set GPIO mode */
+void gpio_mode_set(uint32_t gpio_periph, uint32_t mode, uint32_t pull_up_down, uint32_t pin);
+/* set GPIO output type and speed */
+void gpio_output_options_set(uint32_t gpio_periph, uint8_t otype, uint32_t speed, uint32_t pin);
-/* set gpio pin bit */
-void gpio_bit_set(uint32_t gpio_periph,uint32_t pin);
-/* reset gpio pin bit */
-void gpio_bit_reset(uint32_t gpio_periph,uint32_t pin);
-/* write data to the specified gpio pin */
-void gpio_bit_write(uint32_t gpio_periph,uint32_t pin,bit_status bit_value);
-/* write data to the specified gpio port */
-void gpio_port_write(uint32_t gpio_periph,uint16_t data);
+/* set GPIO pin bit */
+void gpio_bit_set(uint32_t gpio_periph, uint32_t pin);
+/* reset GPIO pin bit */
+void gpio_bit_reset(uint32_t gpio_periph, uint32_t pin);
+/* write data to the specified GPIO pin */
+void gpio_bit_write(uint32_t gpio_periph, uint32_t pin, bit_status bit_value);
+/* write data to the specified GPIO port */
+void gpio_port_write(uint32_t gpio_periph, uint16_t data);
-/* get gpio pin input status */
-FlagStatus gpio_input_bit_get(uint32_t gpio_periph,uint32_t pin);
-/* get gpio port input status */
+/* get GPIO pin input status */
+FlagStatus gpio_input_bit_get(uint32_t gpio_periph, uint32_t pin);
+/* get GPIO port input status */
uint16_t gpio_input_port_get(uint32_t gpio_periph);
-/* get gpio pin output status */
-FlagStatus gpio_output_bit_get(uint32_t gpio_periph,uint32_t pin);
-/* get gpio port output status */
+/* get GPIO pin output status */
+FlagStatus gpio_output_bit_get(uint32_t gpio_periph, uint32_t pin);
+/* get GPIO port output status */
uint16_t gpio_output_port_get(uint32_t gpio_periph);
-/* set gpio alternate function */
-void gpio_af_set(uint32_t gpio_periph,uint32_t alt_func_num,uint32_t pin);
-/* lock gpio pin bit */
-void gpio_pin_lock(uint32_t gpio_periph,uint32_t pin);
+/* set GPIO alternate function */
+void gpio_af_set(uint32_t gpio_periph, uint32_t alt_func_num, uint32_t pin);
+/* lock GPIO pin bit */
+void gpio_pin_lock(uint32_t gpio_periph, uint32_t pin);
-/* toggle gpio pin status */
-void gpio_bit_toggle(uint32_t gpio_periph,uint32_t pin);
-/* toggle gpio port status */
+/* toggle GPIO pin status */
+void gpio_bit_toggle(uint32_t gpio_periph, uint32_t pin);
+/* toggle GPIO port status */
void gpio_port_toggle(uint32_t gpio_periph);
#endif /* GD32F4XX_GPIO_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_i2c.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_i2c.h
index f7e93d3357..121e42f497 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_i2c.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_i2c.h
@@ -1,29 +1,56 @@
/*!
- \file gd32f4xx_i2c.h
- \brief definitions for the I2C
+ \file gd32f4xx_i2c.h
+ \brief definitions for the I2C
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2019-04-16, V2.0.1, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
+
#ifndef GD32F4XX_I2C_H
#define GD32F4XX_I2C_H
#include "gd32f4xx.h"
/* I2Cx(x=0,1,2) definitions */
-#define I2C0 I2C_BASE
-#define I2C1 (I2C_BASE+0x400U)
-#define I2C2 (I2C_BASE+0x800U)
+#define I2C0 I2C_BASE /*!< I2C0 base address */
+#define I2C1 (I2C_BASE+0x400U) /*!< I2C1 base address */
+#define I2C2 (I2C_BASE+0x800U) /*!< I2C2 base address */
/* registers definitions */
#define I2C_CTL0(i2cx) REG32((i2cx) + 0x00U) /*!< I2C control register 0 */
#define I2C_CTL1(i2cx) REG32((i2cx) + 0x04U) /*!< I2C control register 1 */
-#define I2C_SADDR0(i2cx) REG32((i2cx) + 0x08U) /*!< I2C slave address register 0*/
-#define I2C_SADDR1(i2cx) REG32((i2cx) + 0x0CU) /*!< I2C slave address register */
+#define I2C_SADDR0(i2cx) REG32((i2cx) + 0x08U) /*!< I2C slave address register 0 */
+#define I2C_SADDR1(i2cx) REG32((i2cx) + 0x0CU) /*!< I2C slave address register 1 */
#define I2C_DATA(i2cx) REG32((i2cx) + 0x10U) /*!< I2C transfer buffer register */
#define I2C_STAT0(i2cx) REG32((i2cx) + 0x14U) /*!< I2C transfer status register 0 */
#define I2C_STAT1(i2cx) REG32((i2cx) + 0x18U) /*!< I2C transfer status register */
@@ -32,7 +59,6 @@
#define I2C_FCTL(i2cx) REG32((i2cx) + 0x24U) /*!< I2C filter control register */
#define I2C_SAMCS(i2cx) REG32((i2cx) + 0x80U) /*!< I2C SAM control and status register */
-
/* bits definitions */
/* I2Cx_CTL0 */
#define I2C_CTL0_I2CEN BIT(0) /*!< peripheral enable */
@@ -41,7 +67,7 @@
#define I2C_CTL0_ARPEN BIT(4) /*!< ARP enable */
#define I2C_CTL0_PECEN BIT(5) /*!< PEC enable */
#define I2C_CTL0_GCEN BIT(6) /*!< general call enable */
-#define I2C_CTL0_DISSTRC BIT(7) /*!< clock stretching disable (slave mode) */
+#define I2C_CTL0_SS BIT(7) /*!< clock stretching disable (slave mode) */
#define I2C_CTL0_START BIT(8) /*!< start generation */
#define I2C_CTL0_STOP BIT(9) /*!< stop generation */
#define I2C_CTL0_ACKEN BIT(10) /*!< acknowledge enable */
@@ -52,7 +78,7 @@
/* I2Cx_CTL1 */
#define I2C_CTL1_I2CCLK BITS(0,5) /*!< I2CCLK[5:0] bits (peripheral clock frequency) */
-#define I2C_CTL1_ERRIE BIT(8) /*!< error interrupt inable */
+#define I2C_CTL1_ERRIE BIT(8) /*!< error interrupt enable */
#define I2C_CTL1_EVIE BIT(9) /*!< event interrupt enable */
#define I2C_CTL1_BUFIE BIT(10) /*!< buffer interrupt enable */
#define I2C_CTL1_DMAON BIT(11) /*!< DMA requests enable */
@@ -90,12 +116,12 @@
/* I2Cx_STAT1 */
#define I2C_STAT1_MASTER BIT(0) /*!< master/slave */
#define I2C_STAT1_I2CBSY BIT(1) /*!< bus busy */
-#define I2C_STAT1_TRS BIT(2) /*!< transmitter/receiver */
+#define I2C_STAT1_TR BIT(2) /*!< transmitter/receiver */
#define I2C_STAT1_RXGC BIT(4) /*!< general call address (slave mode) */
#define I2C_STAT1_DEFSMB BIT(5) /*!< SMBus device default address (slave mode) */
#define I2C_STAT1_HSTSMB BIT(6) /*!< SMBus host header (slave mode) */
#define I2C_STAT1_DUMODF BIT(7) /*!< dual flag (slave mode) */
-#define I2C_STAT1_ECV BITS(8,15) /*!< packet error checking register */
+#define I2C_STAT1_PECV BITS(8,15) /*!< packet error checking value */
/* I2Cx_CKCFG */
#define I2C_CKCFG_CLKC BITS(0,11) /*!< clock control register in fast/standard mode (master mode) */
@@ -123,7 +149,6 @@
#define I2C_SAMCS_RFF BIT(14) /*!< rxframe fall flag, cleared by software write 0 */
#define I2C_SAMCS_RFR BIT(15) /*!< rxframe rise flag, cleared by software write 0 */
-
/* constants definitions */
/* the digital noise filter can filter spikes's length */
@@ -146,6 +171,94 @@ typedef enum {
I2C_DF_15PCLKS /*!< enable digital noise filter and the maximum filtered spiker's length 15 PCLK1 */
}i2c_digital_filter_enum;
+/* constants definitions */
+/* define the I2C bit position and its register index offset */
+#define I2C_REGIDX_BIT(regidx, bitpos) (((uint32_t)(regidx) << 6) | (uint32_t)(bitpos))
+#define I2C_REG_VAL(i2cx, offset) (REG32((i2cx) + (((uint32_t)(offset) & 0xFFFFU) >> 6)))
+#define I2C_BIT_POS(val) ((uint32_t)(val) & 0x1FU)
+#define I2C_REGIDX_BIT2(regidx, bitpos, regidx2, bitpos2) (((uint32_t)(regidx2) << 22) | (uint32_t)((bitpos2) << 16)\
+ | (((uint32_t)(regidx) << 6) | (uint32_t)(bitpos)))
+#define I2C_REG_VAL2(i2cx, offset) (REG32((i2cx) + ((uint32_t)(offset) >> 22)))
+#define I2C_BIT_POS2(val) (((uint32_t)(val) & 0x1F0000U) >> 16)
+
+/* register offset */
+#define I2C_CTL1_REG_OFFSET 0x04U /*!< CTL1 register offset */
+#define I2C_STAT0_REG_OFFSET 0x14U /*!< STAT0 register offset */
+#define I2C_STAT1_REG_OFFSET 0x18U /*!< STAT1 register offset */
+#define I2C_SAMCS_REG_OFFSET 0x80U /*!< SAMCS register offset */
+
+/* I2C flags */
+typedef enum
+{
+ /* flags in STAT0 register */
+ I2C_FLAG_SBSEND = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 0U), /*!< start condition sent out in master mode */
+ I2C_FLAG_ADDSEND = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 1U), /*!< address is sent in master mode or received and matches in slave mode */
+ I2C_FLAG_BTC = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 2U), /*!< byte transmission finishes */
+ I2C_FLAG_ADD10SEND = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 3U), /*!< header of 10-bit address is sent in master mode */
+ I2C_FLAG_STPDET = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 4U), /*!< stop condition detected in slave mode */
+ I2C_FLAG_RBNE = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 6U), /*!< I2C_DATA is not Empty during receiving */
+ I2C_FLAG_TBE = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 7U), /*!< I2C_DATA is empty during transmitting */
+ I2C_FLAG_BERR = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 8U), /*!< a bus error occurs indication a unexpected start or stop condition on I2C bus */
+ I2C_FLAG_LOSTARB = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 9U), /*!< arbitration lost in master mode */
+ I2C_FLAG_AERR = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 10U), /*!< acknowledge error */
+ I2C_FLAG_OUERR = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 11U), /*!< over-run or under-run situation occurs in slave mode */
+ I2C_FLAG_PECERR = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 12U), /*!< PEC error when receiving data */
+ I2C_FLAG_SMBTO = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 14U), /*!< timeout signal in SMBus mode */
+ I2C_FLAG_SMBALT = I2C_REGIDX_BIT(I2C_STAT0_REG_OFFSET, 15U), /*!< SMBus alert status */
+ /* flags in STAT1 register */
+ I2C_FLAG_MASTER = I2C_REGIDX_BIT(I2C_STAT1_REG_OFFSET, 0U), /*!< a flag indicating whether I2C block is in master or slave mode */
+ I2C_FLAG_I2CBSY = I2C_REGIDX_BIT(I2C_STAT1_REG_OFFSET, 1U), /*!< busy flag */
+ I2C_FLAG_TRS = I2C_REGIDX_BIT(I2C_STAT1_REG_OFFSET, 2U), /*!< whether the I2C is a transmitter or a receiver */
+ I2C_FLAG_RXGC = I2C_REGIDX_BIT(I2C_STAT1_REG_OFFSET, 4U), /*!< general call address (00h) received */
+ I2C_FLAG_DEFSMB = I2C_REGIDX_BIT(I2C_STAT1_REG_OFFSET, 5U), /*!< default address of SMBus device */
+ I2C_FLAG_HSTSMB = I2C_REGIDX_BIT(I2C_STAT1_REG_OFFSET, 6U), /*!< SMBus host header detected in slave mode */
+ I2C_FLAG_DUMOD = I2C_REGIDX_BIT(I2C_STAT1_REG_OFFSET, 7U), /*!< dual flag in slave mode indicating which address is matched in dual-address mode */
+ /* flags in SAMCS register */
+ I2C_FLAG_TFF = I2C_REGIDX_BIT(I2C_SAMCS_REG_OFFSET, 12U), /*!< txframe fall flag */
+ I2C_FLAG_TFR = I2C_REGIDX_BIT(I2C_SAMCS_REG_OFFSET, 13U), /*!< txframe rise flag */
+ I2C_FLAG_RFF = I2C_REGIDX_BIT(I2C_SAMCS_REG_OFFSET, 14U), /*!< rxframe fall flag */
+ I2C_FLAG_RFR = I2C_REGIDX_BIT(I2C_SAMCS_REG_OFFSET, 15U) /*!< rxframe rise flag */
+}i2c_flag_enum;
+
+/* I2C interrupt flags */
+typedef enum
+{
+ /* interrupt flags in CTL1 register */
+ I2C_INT_FLAG_SBSEND = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 9U, I2C_STAT0_REG_OFFSET, 0U), /*!< start condition sent out in master mode interrupt flag */
+ I2C_INT_FLAG_ADDSEND = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 9U, I2C_STAT0_REG_OFFSET, 1U), /*!< address is sent in master mode or received and matches in slave mode interrupt flag */
+ I2C_INT_FLAG_BTC = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 9U, I2C_STAT0_REG_OFFSET, 2U), /*!< byte transmission finishes */
+ I2C_INT_FLAG_ADD10SEND = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 9U, I2C_STAT0_REG_OFFSET, 3U), /*!< header of 10-bit address is sent in master mode interrupt flag */
+ I2C_INT_FLAG_STPDET = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 9U, I2C_STAT0_REG_OFFSET, 4U), /*!< stop condition detected in slave mode interrupt flag */
+ I2C_INT_FLAG_RBNE = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 9U, I2C_STAT0_REG_OFFSET, 6U), /*!< I2C_DATA is not Empty during receiving interrupt flag */
+ I2C_INT_FLAG_TBE = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 9U, I2C_STAT0_REG_OFFSET, 7U), /*!< I2C_DATA is empty during transmitting interrupt flag */
+ I2C_INT_FLAG_BERR = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 8U, I2C_STAT0_REG_OFFSET, 8U), /*!< a bus error occurs indication a unexpected start or stop condition on I2C bus interrupt flag */
+ I2C_INT_FLAG_LOSTARB = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 8U, I2C_STAT0_REG_OFFSET, 9U), /*!< arbitration lost in master mode interrupt flag */
+ I2C_INT_FLAG_AERR = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 8U, I2C_STAT0_REG_OFFSET, 10U), /*!< acknowledge error interrupt flag */
+ I2C_INT_FLAG_OUERR = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 8U, I2C_STAT0_REG_OFFSET, 11U), /*!< over-run or under-run situation occurs in slave mode interrupt flag */
+ I2C_INT_FLAG_PECERR = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 8U, I2C_STAT0_REG_OFFSET, 12U), /*!< PEC error when receiving data interrupt flag */
+ I2C_INT_FLAG_SMBTO = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 8U, I2C_STAT0_REG_OFFSET, 14U), /*!< timeout signal in SMBus mode interrupt flag */
+ I2C_INT_FLAG_SMBALT = I2C_REGIDX_BIT2(I2C_CTL1_REG_OFFSET, 8U, I2C_STAT0_REG_OFFSET, 15U), /*!< SMBus Alert status interrupt flag */
+ /* interrupt flags in SAMCS register */
+ I2C_INT_FLAG_TFF = I2C_REGIDX_BIT2(I2C_SAMCS_REG_OFFSET, 4U, I2C_SAMCS_REG_OFFSET, 12U), /*!< txframe fall interrupt flag */
+ I2C_INT_FLAG_TFR = I2C_REGIDX_BIT2(I2C_SAMCS_REG_OFFSET, 5U, I2C_SAMCS_REG_OFFSET, 13U), /*!< txframe rise interrupt flag */
+ I2C_INT_FLAG_RFF = I2C_REGIDX_BIT2(I2C_SAMCS_REG_OFFSET, 6U, I2C_SAMCS_REG_OFFSET, 14U), /*!< rxframe fall interrupt flag */
+ I2C_INT_FLAG_RFR = I2C_REGIDX_BIT2(I2C_SAMCS_REG_OFFSET, 7U, I2C_SAMCS_REG_OFFSET, 15U) /*!< rxframe rise interrupt flag */
+}i2c_interrupt_flag_enum;
+
+/* I2C interrupt enable or disable */
+typedef enum
+{
+ /* interrupt in CTL1 register */
+ I2C_INT_ERR = I2C_REGIDX_BIT(I2C_CTL1_REG_OFFSET, 8U), /*!< error interrupt enable */
+ I2C_INT_EV = I2C_REGIDX_BIT(I2C_CTL1_REG_OFFSET, 9U), /*!< event interrupt enable */
+ I2C_INT_BUF = I2C_REGIDX_BIT(I2C_CTL1_REG_OFFSET, 10U), /*!< buffer interrupt enable */
+ /* interrupt in SAMCS register */
+ I2C_INT_TFF = I2C_REGIDX_BIT(I2C_SAMCS_REG_OFFSET, 4U), /*!< txframe fall interrupt enable */
+ I2C_INT_TFR = I2C_REGIDX_BIT(I2C_SAMCS_REG_OFFSET, 5U), /*!< txframe rise interrupt enable */
+ I2C_INT_RFF = I2C_REGIDX_BIT(I2C_SAMCS_REG_OFFSET, 6U), /*!< rxframe fall interrupt enable */
+ I2C_INT_RFR = I2C_REGIDX_BIT(I2C_SAMCS_REG_OFFSET, 7U) /*!< rxframe rise interrupt enable */
+}i2c_interrupt_enum;
+
/* SMBus/I2C mode switch and SMBus type selection */
#define I2C_I2CMODE_ENABLE ((uint32_t)0x00000000U) /*!< I2C mode */
#define I2C_SMBUSMODE_ENABLE I2C_CTL0_SMBEN /*!< SMBus mode */
@@ -153,27 +266,28 @@ typedef enum {
/* SMBus/I2C mode switch and SMBus type selection */
#define I2C_SMBUS_DEVICE ((uint32_t)0x00000000U) /*!< SMBus mode device type */
#define I2C_SMBUS_HOST I2C_CTL0_SMBSEL /*!< SMBus mode host type */
+
/* I2C transfer direction */
-#define I2C_TRANSMITTER (~BIT(0)) /*!< transmitter */
-#define I2C_RECEIVER BIT(0) /*!< receiver */
+#define I2C_RECEIVER ((uint32_t)0x00000001U) /*!< receiver */
+#define I2C_TRANSMITTER ((uint32_t)0xFFFFFFFEU) /*!< transmitter */
/* whether or not to send an ACK */
-#define I2C_ACK_ENABLE ((uint8_t)0x01U) /*!< ACK will be sent */
-#define I2C_ACK_DISABLE ((uint8_t)0x00U) /*!< ACK will be not sent */
+#define I2C_ACK_DISABLE ((uint32_t)0x00000000U) /*!< ACK will be not sent */
+#define I2C_ACK_ENABLE ((uint32_t)0x00000001U) /*!< ACK will be sent */
/* I2C POAP position*/
-#define I2C_ACKPOS_CURRENT ((uint8_t)0x01U) /*!< ACKEN bit decides whether to send ACK or not for the current */
-#define I2C_ACKPOS_NEXT ((uint8_t)0x00U) /*!< ACKEN bit decides whether to send ACK or not for the next byte */
+#define I2C_ACKPOS_NEXT ((uint32_t)0x00000000U) /*!< ACKEN bit decides whether or not to send ACK for the next byte */
+#define I2C_ACKPOS_CURRENT ((uint32_t)0x00000001U) /*!< ACKEN bit decides whether or not to send ACK or not for the current byte */
/* I2C dual-address mode switch */
-#define I2C_DUADEN_DISABLE ((uint8_t)0x00U) /*!< dual-address mode disabled */
-#define I2C_DUADEN_ENABLE ((uint8_t)0x01U) /*!< dual-address mode enabled */
+#define I2C_DUADEN_DISABLE ((uint32_t)0x00000000U) /*!< dual-address mode disabled */
+#define I2C_DUADEN_ENABLE ((uint32_t)0x00000001U) /*!< dual-address mode enabled */
/* whether or not to stretch SCL low */
#define I2C_SCLSTRETCH_ENABLE ((uint32_t)0x00000000U) /*!< SCL stretching is enabled */
-#define I2C_SCLSTRETCH_DISABLE I2C_CTL0_DISSTRC /*!< SCL stretching is disabled */
+#define I2C_SCLSTRETCH_DISABLE I2C_CTL0_SS /*!< SCL stretching is disabled */
-/* whether or not to response to a General Call */
+/* whether or not to response to a general call */
#define I2C_GCEN_ENABLE I2C_CTL0_GCEN /*!< slave will response to a general call */
#define I2C_GCEN_DISABLE ((uint32_t)0x00000000U) /*!< slave will not response to a general call */
@@ -185,11 +299,11 @@ typedef enum {
/* DMA mode switch */
#define I2C_DMA_ON I2C_CTL1_DMAON /*!< DMA mode enabled */
#define I2C_DMA_OFF ((uint32_t)0x00000000U) /*!< DMA mode disabled */
+
/* flag indicating DMA last transfer */
#define I2C_DMALST_ON I2C_CTL1_DMALST /*!< next DMA EOT is the last transfer */
#define I2C_DMALST_OFF ((uint32_t)0x00000000U) /*!< next DMA EOT is not the last transfer */
-
/* I2C PEC configure */
/* PEC enable */
#define I2C_PEC_ENABLE I2C_CTL0_PECEN /*!< PEC calculation on */
@@ -203,105 +317,78 @@ typedef enum {
/* issue or not alert through SMBA pin */
#define I2C_SALTSEND_ENABLE I2C_CTL0_SALT /*!< issue alert through SMBA pin */
#define I2C_SALTSEND_DISABLE ((uint32_t)0x00000000U) /*!< not issue alert through SMBA */
+
/* ARP protocol in SMBus switch */
#define I2C_ARP_ENABLE I2C_CTL0_ARPEN /*!< ARP is enabled */
#define I2C_ARP_DISABLE ((uint32_t)0x00000000U) /*!< ARP is disabled */
-/* I2C state */
-/* I2C bit state */
-#define I2C_SBSEND BIT(0) /*!< start condition sent out in master mode */
-#define I2C_ADDSEND BIT(1) /*!< address is sent in master mode or received and matches in slave mode */
-#define I2C_BTC BIT(2) /*!< byte transmission finishes */
-#define I2C_ADD10SEND BIT(3) /*!< header of 10-bit address is sent in master mode */
-#define I2C_STPDET BIT(4) /*!< etop condition detected in slave mode */
-#define I2C_RBNE BIT(6) /*!< I2C_DATA is not Empty during receiving */
-#define I2C_TBE BIT(7) /*!< I2C_DATA is empty during transmitting */
-#define I2C_BERR BIT(8) /*!< a bus error occurs indication a unexpected start or stop condition on I2C bus */
-#define I2C_LOSTARB BIT(9) /*!< arbitration lost in master mode */
-#define I2C_AERR BIT(10) /*!< acknowledge error */
-#define I2C_OUERR BIT(11) /*!< over-run or under-run situation occurs in slave mode */
-#define I2C_PECERR BIT(12) /*!< PEC error when receiving data */
-#define I2C_SMBTO BIT(14) /*!< timeout signal in SMBus mode */
-#define I2C_SMBALT BIT(15) /*!< SMBus alert status */
-#define I2C_MASTER (BIT(0)|BIT(31)) /*!< a flag indicating whether I2C block is in master or slave mode */
-#define I2C_I2CBSY (BIT(1)|BIT(31)) /*!< busy flag */
-#define I2C_TRS (BIT(2)|BIT(31)) /*!< whether the I2C is a transmitter or a receiver */
-#define I2C_RXGC (BIT(4)|BIT(31)) /*!< general call address (00h) received */
-#define I2C_DEFSMB (BIT(5)|BIT(31)) /*!< default address of SMBus device */
-#define I2C_HSTSMB (BIT(6)|BIT(31)) /*!< SMBus host header detected in slave mode */
-#define I2C_DUMODF (BIT(7)|BIT(31)) /*!< dual flag in slave mode indicating which address is matched in dual-address mode */
+/* transmit I2C data */
+#define DATA_TRANS(regval) (BITS(0,7) & ((uint32_t)(regval) << 0))
+
+/* receive I2C data */
+#define DATA_RECV(regval) GET_BITS((uint32_t)(regval), 0, 7)
/* I2C duty cycle in fast mode */
-#define CKCFG_DTCY(regval) (BIT(14) & ((uint32_t)(regval) << 14))
-#define I2C_DTCY_2 CKCFG_DTCY(0) /*!< I2C fast mode Tlow/Thigh = 2 */
-#define I2C_DTCY_16_9 CKCFG_DTCY(1) /*!< I2C fast mode Tlow/Thigh = 16/9 */
+#define I2C_DTCY_2 ((uint32_t)0x00000000U) /*!< I2C fast mode Tlow/Thigh = 2 */
+#define I2C_DTCY_16_9 I2C_CKCFG_DTCY /*!< I2C fast mode Tlow/Thigh = 16/9 */
/* address mode for the I2C slave */
-#define SADDR0_ADDFORMAT(regval) (BIT(15) & ((regval) << 15))
-#define I2C_ADDFORMAT_7BITS SADDR0_ADDFORMAT(0) /*!< address:7 bits */
-#define I2C_ADDFORMAT_10BITS SADDR0_ADDFORMAT(1) /*!< address:10 bits */
+#define I2C_ADDFORMAT_7BITS ((uint32_t)0x00000000U) /*!< address:7 bits */
+#define I2C_ADDFORMAT_10BITS I2C_SADDR0_ADDFORMAT /*!< address:10 bits */
/* function declarations */
/* reset I2C */
void i2c_deinit(uint32_t i2c_periph);
-/* I2C clock configure */
-void i2c_clock_config(uint32_t i2c_periph,uint32_t clkspeed,uint32_t dutycyc);
-/* I2C address configure */
-void i2c_mode_addr_config(uint32_t i2c_periph,uint32_t i2cmod,uint32_t addformat,uint32_t addr);
+/* configure I2C clock */
+void i2c_clock_config(uint32_t i2c_periph, uint32_t clkspeed, uint32_t dutycyc);
+/* configure I2C address */
+void i2c_mode_addr_config(uint32_t i2c_periph, uint32_t mode, uint32_t addformat, uint32_t addr);
/* SMBus type selection */
-void i2c_smbus_type_config(uint32_t i2c_periph,uint32_t type);
+void i2c_smbus_type_config(uint32_t i2c_periph, uint32_t type);
/* whether or not to send an ACK */
-void i2c_ack_config(uint32_t i2c_periph,uint8_t ack);
-/* I2C POAP position configure */
-void i2c_ackpos_config(uint32_t i2c_periph,uint8_t pos);
-/* master send slave address */
-void i2c_master_addressing(uint32_t i2c_periph,uint8_t addr,uint32_t trandirection);
-/* dual-address mode switch */
-void i2c_dualaddr_enable(uint32_t i2c_periph, uint8_t dualaddr);
-
-/* enable i2c */
+void i2c_ack_config(uint32_t i2c_periph, uint32_t ack);
+/* configure I2C POAP position */
+void i2c_ackpos_config(uint32_t i2c_periph, uint32_t pos);
+/* master sends slave address */
+void i2c_master_addressing(uint32_t i2c_periph, uint32_t addr, uint32_t trandirection);
+/* enable dual-address mode */
+void i2c_dualaddr_enable(uint32_t i2c_periph, uint32_t addr);
+/* disable dual-address mode */
+void i2c_dualaddr_disable(uint32_t i2c_periph);
+/* enable I2C */
void i2c_enable(uint32_t i2c_periph);
-/* disable i2c */
+/* disable I2C */
void i2c_disable(uint32_t i2c_periph);
+
/* generate a START condition on I2C bus */
void i2c_start_on_bus(uint32_t i2c_periph);
/* generate a STOP condition on I2C bus */
void i2c_stop_on_bus(uint32_t i2c_periph);
-/* i2c transmit data function */
-void i2c_transmit_data(uint32_t i2c_periph,uint8_t data);
-/* i2c receive data function */
-uint8_t i2c_receive_data(uint32_t i2c_periph);
-/* I2C DMA mode enable */
-void i2c_dma_enable(uint32_t i2c_periph,uint32_t dmastste);
-/* flag indicating DMA last transfer */
-void i2c_dma_last_transfer_enable(uint32_t i2c_periph,uint32_t dmalast);
-/* whether to stretch SCL low when data is not ready in slave mode */
-void i2c_stretch_scl_low_config(uint32_t i2c_periph,uint32_t stretchpara );
-/* whether or not to response to a general call */
-void i2c_slave_response_to_gcall_config(uint32_t i2c_periph,uint32_t gcallpara);
-/* software reset I2C */
+/* I2C transmit data function */
+void i2c_data_transmit(uint32_t i2c_periph, uint8_t data);
+/* I2C receive data function */
+uint8_t i2c_data_receive(uint32_t i2c_periph);
+/* enable I2C DMA mode */
+void i2c_dma_enable(uint32_t i2c_periph, uint32_t dmastate);
+/* configure whether next DMA EOT is DMA last transfer or not */
+void i2c_dma_last_transfer_config(uint32_t i2c_periph, uint32_t dmalast);
+/* whether to stretch SCL low when data is not ready in slave mode */
+void i2c_stretch_scl_low_config(uint32_t i2c_periph, uint32_t stretchpara);
+/* whether or not to response to a general call */
+void i2c_slave_response_to_gcall_config(uint32_t i2c_periph, uint32_t gcallpara);
+/* software reset I2C */
void i2c_software_reset_config(uint32_t i2c_periph, uint32_t sreset);
-/* check i2c state */
-FlagStatus i2c_flag_get(uint32_t i2c_periph,uint32_t state);
-/* clear i2c state */
-void i2c_flag_clear(uint32_t i2c_periph,uint32_t state);
-/* enable i2c interrupt */
-void i2c_interrupt_enable(uint32_t i2c_periph,uint32_t inttype);
-/* disable i2c interrupt */
-void i2c_interrupt_disable(uint32_t i2c_periph,uint32_t inttype);
-
/* I2C PEC calculation on or off */
-void i2c_pec_enable(uint32_t i2c_periph,uint32_t pecstate);
+void i2c_pec_enable(uint32_t i2c_periph, uint32_t pecstate);
/* I2C whether to transfer PEC value */
-void i2c_pec_transfer_enable(uint32_t i2c_periph,uint32_t pecpara);
-/* packet error checking value */
-uint8_t i2c_pec_value(uint32_t i2c_periph);
-
+void i2c_pec_transfer_enable(uint32_t i2c_periph, uint32_t pecpara);
+/* packet error checking value */
+uint8_t i2c_pec_value_get(uint32_t i2c_periph);
/* I2C issue alert through SMBA pin */
-void i2c_smbus_alert_issue(uint32_t i2c_periph,uint32_t smbuspara);
-/* I2C ARP protocol in SMBus switch */
-void i2c_smbus_arp_enable(uint32_t i2c_periph,uint32_t arpstate);
+void i2c_smbus_issue_alert(uint32_t i2c_periph, uint32_t smbuspara);
+/* I2C ARP protocol in SMBus switch */
+void i2c_smbus_arp_enable(uint32_t i2c_periph, uint32_t arpstate);
/* I2C analog noise filter disable */
void i2c_analog_noise_filter_disable(uint32_t i2c_periph);
@@ -318,14 +405,18 @@ void i2c_sam_disable(uint32_t i2c_periph);
void i2c_sam_timeout_enable(uint32_t i2c_periph);
/* disable SAM_V interface timeout detect */
void i2c_sam_timeout_disable(uint32_t i2c_periph);
-/* enable the specified I2C SAM interrupt */
-void i2c_sam_interrupt_enable(uint32_t i2c_periph,uint32_t inttype);
-/* disable the specified I2C SAM interrupt */
-void i2c_sam_interrupt_disable(uint32_t i2c_periph,uint32_t inttype);
-/* check i2c SAM state */
-FlagStatus i2c_sam_flag_get(uint32_t i2c_periph,uint32_t samstate);
-/* clear i2c SAM state */
-void i2c_sam_flag_clear(uint32_t i2c_periph,uint32_t samstate);
+/* check I2C flag is set or not */
+FlagStatus i2c_flag_get(uint32_t i2c_periph, i2c_flag_enum flag);
+/* clear I2C flag */
+void i2c_flag_clear(uint32_t i2c_periph, i2c_flag_enum flag);
+/* enable I2C interrupt */
+void i2c_interrupt_enable(uint32_t i2c_periph, i2c_interrupt_enum interrupt);
+/* disable I2C interrupt */
+void i2c_interrupt_disable(uint32_t i2c_periph, i2c_interrupt_enum interrupt);
+/* check I2C interrupt flag */
+FlagStatus i2c_interrupt_flag_get(uint32_t i2c_periph, i2c_interrupt_flag_enum int_flag);
+/* clear I2C interrupt flag */
+void i2c_interrupt_flag_clear(uint32_t i2c_periph, i2c_interrupt_flag_enum int_flag);
#endif /* GD32F4XX_I2C_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_ipa.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_ipa.h
index d356ac8c3d..d9ae8ce33a 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_ipa.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_ipa.h
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_ipa.h
- \brief definitions for the IPA
+ \file gd32f4xx_ipa.h
+ \brief definitions for the IPA
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#ifndef GD32F4XX_IPA_H
@@ -24,7 +49,7 @@
#define IPA_INTC REG32(IPA + 0x08U) /*!< IPA interrupt flag clear register */
#define IPA_FMADDR REG32(IPA + 0x0CU) /*!< IPA foreground memory base address register */
#define IPA_FLOFF REG32(IPA + 0x10U) /*!< IPA foreground line offset register */
-#define IPA_BMADDR REG32(IPA + 0x14U) /*!< IPA background memory base address register */
+#define IPA_BMADDR REG32(IPA + 0x14U) /*!< IPA background memory base address register */
#define IPA_BLOFF REG32(IPA + 0x18U) /*!< IPA background line offset register */
#define IPA_FPCTL REG32(IPA + 0x1CU) /*!< IPA foreground pixel control register */
#define IPA_FPV REG32(IPA + 0x20U) /*!< IPA foreground pixel value register */
@@ -33,11 +58,11 @@
#define IPA_FLMADDR REG32(IPA + 0x2CU) /*!< IPA foreground LUT memory base address register */
#define IPA_BLMADDR REG32(IPA + 0x30U) /*!< IPA background LUT memory base address register */
#define IPA_DPCTL REG32(IPA + 0x34U) /*!< IPA destination pixel control register */
-#define IPA_DPV REG32(IPA + 0x38U) /*!< IPA destination pixel value register */
+#define IPA_DPV REG32(IPA + 0x38U) /*!< IPA destination pixel value register */
#define IPA_DMADDR REG32(IPA + 0x3CU) /*!< IPA destination memory base address register */
#define IPA_DLOFF REG32(IPA + 0x40U) /*!< IPA destination line offset register */
#define IPA_IMS REG32(IPA + 0x44U) /*!< IPA image size register */
-#define IPA_LM REG32(IPA + 0x48U) /*!< IPA line mark register */
+#define IPA_LM REG32(IPA + 0x48U) /*!< IPA line mark register */
#define IPA_ITCTL REG32(IPA + 0x4CU) /*!< IPA inter-timer control register */
/* IPA_CTL */
@@ -113,7 +138,7 @@
#define IPA_BLMADDR_BLMADDR BITS(0,31) /*!< background LUT memory base address */
/* IPA_DPCTL */
-#define IPA_DPCTL_DPF BITS(0,2) /*!< destination pixel control register */
+#define IPA_DPCTL_DPF BITS(0,2) /*!< destination pixel control register */
/* IPA_DPV */
/* destination pixel format ARGB8888 */
@@ -165,7 +190,7 @@
/* constants definitions */
/* IPA foreground parameter struct definitions */
typedef struct
-{
+{
uint32_t foreground_memaddr; /*!< foreground memory base address */
uint32_t foreground_lineoff; /*!< foreground line offset */
uint32_t foreground_prealpha; /*!< foreground pre-defined alpha value */
@@ -174,25 +199,25 @@ typedef struct
uint32_t foreground_prered; /*!< foreground pre-defined red value */
uint32_t foreground_pregreen; /*!< foreground pre-defined green value */
uint32_t foreground_preblue; /*!< foreground pre-defined blue value */
-}ipa_foreground_parameter_struct;
+}ipa_foreground_parameter_struct;
/* IPA background parameter struct definitions */
typedef struct
-{
+{
uint32_t background_memaddr; /*!< background memory base address */
uint32_t background_lineoff; /*!< background line offset */
uint32_t background_prealpha; /*!< background pre-defined alpha value */
- uint32_t background_alpha_algorithm; /*!< background alpha value calculation algorithm */
+ uint32_t background_alpha_algorithm; /*!< background alpha value calculation algorithm */
uint32_t background_pf; /*!< background pixel format */
uint32_t background_prered; /*!< background pre-defined red value */
uint32_t background_pregreen; /*!< background pre-defined green value */
uint32_t background_preblue; /*!< background pre-defined blue value */
-}ipa_background_parameter_struct;
+}ipa_background_parameter_struct;
/* IPA destination parameter struct definitions */
typedef struct
{
- uint32_t destination_memaddr; /*!< destination memory base address */
+ uint32_t destination_memaddr; /*!< destination memory base address */
uint32_t destination_lineoff; /*!< destination line offset */
uint32_t destination_prealpha; /*!< destination pre-defined alpha value */
uint32_t destination_pf; /*!< destination pixel format */
@@ -200,17 +225,17 @@ typedef struct
uint32_t destination_pregreen; /*!< destination pre-defined green value */
uint32_t destination_preblue; /*!< destination pre-defined blue value */
uint32_t image_width; /*!< width of the image to be processed */
- uint32_t image_height; /*!< height of the image to be processed */
-}ipa_destination_parameter_struct;
+ uint32_t image_height; /*!< height of the image to be processed */
+}ipa_destination_parameter_struct;
/* destination pixel format */
-typedef enum
+typedef enum
{
- IPA_DPF_ARGB8888, /*!< destination pixel format ARGB8888 */
- IPA_DPF_RGB888, /*!< destination pixel format RGB888 */
- IPA_DPF_RGB565, /*!< destination pixel format RGB565 */
- IPA_DPF_ARGB1555, /*!< destination pixel format ARGB1555 */
- IPA_DPF_ARGB4444 /*!< destination pixel format ARGB4444 */
+ IPA_DPF_ARGB8888, /*!< destination pixel format ARGB8888 */
+ IPA_DPF_RGB888, /*!< destination pixel format RGB888 */
+ IPA_DPF_RGB565, /*!< destination pixel format RGB565 */
+ IPA_DPF_ARGB1555, /*!< destination pixel format ARGB1555 */
+ IPA_DPF_ARGB4444 /*!< destination pixel format ARGB4444 */
} ipa_dpf_enum;
/* LUT pixel format */
@@ -218,30 +243,30 @@ typedef enum
#define IPA_LUT_PF_RGB888 ((uint8_t)0x01U) /*!< LUT pixel format RGB888 */
/* Inter-timer */
-#define IPA_INTER_TIMER_DISABLE ((uint8_t)0x00U) /*!< Inter-timer disable */
-#define IPA_INTER_TIMER_ENABLE ((uint8_t)0x01U) /*!< Inter-timer enable */
+#define IPA_INTER_TIMER_DISABLE ((uint8_t)0x00U) /*!< inter-timer disable */
+#define IPA_INTER_TIMER_ENABLE ((uint8_t)0x01U) /*!< inter-timer enable */
/* IPA pixel format convert mode */
-#define CTL_PFCM(regval) (BITS(16,17) & ((regval) << 16))
+#define CTL_PFCM(regval) (BITS(16,17) & ((uint32_t)(regval) << 16))
#define IPA_FGTODE CTL_PFCM(0) /*!< foreground memory to destination memory without pixel format convert */
#define IPA_FGTODE_PF_CONVERT CTL_PFCM(1) /*!< foreground memory to destination memory with pixel format convert */
#define IPA_FGBGTODE CTL_PFCM(2) /*!< blending foreground and background memory to destination memory */
#define IPA_FILL_UP_DE CTL_PFCM(3) /*!< fill up destination memory with specific color */
/* foreground alpha value calculation algorithm */
-#define FPCTL_FAVCA(regval) (BITS(16,17) & ((regval) << 16))
+#define FPCTL_FAVCA(regval) (BITS(16,17) & ((uint32_t)(regval) << 16))
#define IPA_FG_ALPHA_MODE_0 FPCTL_FAVCA(0) /*!< no effect */
#define IPA_FG_ALPHA_MODE_1 FPCTL_FAVCA(1) /*!< FPDAV[7:0] is selected as the foreground alpha value */
#define IPA_FG_ALPHA_MODE_2 FPCTL_FAVCA(2) /*!< FPDAV[7:0] multiplied by read alpha value */
/* background alpha value calculation algorithm */
-#define BPCTL_BAVCA(regval) (BITS(16,17) & ((regval) << 16))
+#define BPCTL_BAVCA(regval) (BITS(16,17) & ((uint32_t)(regval) << 16))
#define IPA_BG_ALPHA_MODE_0 BPCTL_BAVCA(0) /*!< no effect */
#define IPA_BG_ALPHA_MODE_1 BPCTL_BAVCA(1) /*!< BPDAV[7:0] is selected as the background alpha value */
#define IPA_BG_ALPHA_MODE_2 BPCTL_BAVCA(2) /*!< BPDAV[7:0] multiplied by read alpha value */
/* foreground pixel format */
-#define FPCTL_PPF(regval) (BITS(0,3) & ((regval)))
+#define FPCTL_PPF(regval) (BITS(0,3) & ((uint32_t)(regval)))
#define FOREGROUND_PPF_ARGB8888 FPCTL_PPF(0) /*!< foreground pixel format ARGB8888 */
#define FOREGROUND_PPF_RGB888 FPCTL_PPF(1) /*!< foreground pixel format RGB888 */
#define FOREGROUND_PPF_RGB565 FPCTL_PPF(2) /*!< foreground pixel format RGB565 */
@@ -255,7 +280,7 @@ typedef enum
#define FOREGROUND_PPF_A4 FPCTL_PPF(10) /*!< foreground pixel format A4 */
/* background pixel format */
-#define BPCTL_PPF(regval) (BITS(0,3) & ((regval)))
+#define BPCTL_PPF(regval) (BITS(0,3) & ((uint32_t)(regval)))
#define BACKGROUND_PPF_ARGB8888 BPCTL_PPF(0) /*!< background pixel format ARGB8888 */
#define BACKGROUND_PPF_RGB888 BPCTL_PPF(1) /*!< background pixel format RGB888 */
#define BACKGROUND_PPF_RGB565 BPCTL_PPF(2) /*!< background pixel format RGB565 */
@@ -268,53 +293,92 @@ typedef enum
#define BACKGROUND_PPF_A8 BPCTL_PPF(9) /*!< background pixel format A8 */
#define BACKGROUND_PPF_A4 BPCTL_PPF(10) /*!< background pixel format A4 */
+/* IPA flags */
+#define IPA_FLAG_TAE IPA_INTF_TAEIF /*!< transfer access error interrupt flag */
+#define IPA_FLAG_FTF IPA_INTF_FTFIF /*!< full transfer finish interrupt flag */
+#define IPA_FLAG_TLM IPA_INTF_TLMIF /*!< transfer line mark interrupt flag */
+#define IPA_FLAG_LAC IPA_INTF_LACIF /*!< LUT access conflict interrupt flag */
+#define IPA_FLAG_LLF IPA_INTF_LLFIF /*!< LUT loading finish interrupt flag */
+#define IPA_FLAG_WCF IPA_INTF_WCFIF /*!< wrong configuration interrupt flag */
-/* function declarations */
+/* IPA interrupt enable or disable */
+#define IPA_INT_TAE IPA_CTL_TAEIE /*!< transfer access error interrupt */
+#define IPA_INT_FTF IPA_CTL_FTFIE /*!< full transfer finish interrupt */
+#define IPA_INT_TLM IPA_CTL_TLMIE /*!< transfer line mark interrupt */
+#define IPA_INT_LAC IPA_CTL_LACIE /*!< LUT access conflict interrupt */
+#define IPA_INT_LLF IPA_CTL_LLFIE /*!< LUT loading finish interrupt */
+#define IPA_INT_WCF IPA_CTL_WCFIE /*!< wrong configuration interrupt */
+/* IPA interrupt flags */
+#define IPA_INT_FLAG_TAE IPA_INTF_TAEIF /*!< transfer access error interrupt flag */
+#define IPA_INT_FLAG_FTF IPA_INTF_FTFIF /*!< full transfer finish interrupt flag */
+#define IPA_INT_FLAG_TLM IPA_INTF_TLMIF /*!< transfer line mark interrupt flag */
+#define IPA_INT_FLAG_LAC IPA_INTF_LACIF /*!< LUT access conflict interrupt flag */
+#define IPA_INT_FLAG_LLF IPA_INTF_LLFIF /*!< LUT loading finish interrupt flag */
+#define IPA_INT_FLAG_WCF IPA_INTF_WCFIF /*!< wrong configuration interrupt flag */
+
+/* function declarations */
+/* functions enable or disable, pixel format convert mode set */
/* deinitialize IPA */
void ipa_deinit(void);
-/* IPA transfer enable */
+/* enable IPA transfer */
void ipa_transfer_enable(void);
-/* IPA transfer hang up enable */
+/* enable IPA transfer hang up */
void ipa_transfer_hangup_enable(void);
-/* IPA transfer hang up disable */
+/* disable IPA transfer hang up */
void ipa_transfer_hangup_disable(void);
-/* IPA transfer stop enable */
+/* enable IPA transfer stop */
void ipa_transfer_stop_enable(void);
-/* IPA transfer stop disable */
+/* disable IPA transfer stop */
void ipa_transfer_stop_disable(void);
-/* IPA foreground LUT loading enable */
+/* enable IPA foreground LUT loading */
void ipa_foreground_lut_loading_enable(void);
-/* IPA background LUT loading enable */
+/* enable IPA background LUT loading */
void ipa_background_lut_loading_enable(void);
-/* IPA transfer enable */
-void ipa_pixel_format_convert_mod(uint32_t pfcm);
+/* set pixel format convert mode, the function is invalid when the IPA transfer is enabled */
+void ipa_pixel_format_convert_mode_set(uint32_t pfcm);
+/* structure initialization, foreground, background, destination and LUT initialization */
+/* initialize the structure of IPA foreground parameter struct with the default values, it is
+ suggested that call this function after an ipa_foreground_parameter_struct structure is defined */
+void ipa_foreground_struct_para_init(ipa_foreground_parameter_struct* foreground_struct);
/* initialize foreground parameters */
void ipa_foreground_init(ipa_foreground_parameter_struct* foreground_struct);
+/* initialize the structure of IPA background parameter struct with the default values, it is
+ suggested that call this function after an ipa_background_parameter_struct structure is defined */
+void ipa_background_struct_para_init(ipa_background_parameter_struct* background_struct);
/* initialize background parameters */
void ipa_background_init(ipa_background_parameter_struct* background_struct);
+/* initialize the structure of IPA destination parameter struct with the default values, it is
+ suggested that call this function after an ipa_destination_parameter_struct structure is defined */
+void ipa_destination_struct_para_init(ipa_destination_parameter_struct* destination_struct);
/* initialize destination parameters */
void ipa_destination_init(ipa_destination_parameter_struct* destination_struct);
/* initialize IPA foreground LUT parameters */
-void ipa_foreground_lut_init(uint32_t fg_lut_num,uint8_t fg_lut_pf, uint32_t fg_lut_addr);
+void ipa_foreground_lut_init(uint8_t fg_lut_num, uint8_t fg_lut_pf, uint32_t fg_lut_addr);
/* initialize IPA background LUT parameters */
-void ipa_background_lut_init(uint32_t bg_lut_num,uint8_t bg_lut_pf, uint32_t bg_lut_addr);
+void ipa_background_lut_init(uint8_t bg_lut_num, uint8_t bg_lut_pf, uint32_t bg_lut_addr);
-/* configure line mark */
-void ipa_line_mark_config(uint32_t linenum);
-/* Inter-timer enable or disable */
-void ipa_inter_timer_config(uint8_t timercfg);
-/* number of clock cycles interval set */
-void ipa_interval_clock_num_config(uint32_t clk_num );
+/* configuration functions */
+/* configure IPA line mark */
+void ipa_line_mark_config(uint16_t line_num);
+/* inter-timer enable or disable */
+void ipa_inter_timer_config(uint8_t timer_cfg);
+/* configure the number of clock cycles interval */
+void ipa_interval_clock_num_config(uint8_t clk_num);
-/* IPA interrupt enable */
-void ipa_interrupt_enable(uint32_t inttype);
-/* IPA interrupt disable */
-void ipa_interrupt_disable(uint32_t inttype);
+/* flag and interrupt functions */
+/* get IPA flag status in IPA_INTF register */
+FlagStatus ipa_flag_get(uint32_t flag);
+/* clear IPA flag in IPA_INTF register */
+void ipa_flag_clear(uint32_t flag);
+/* enable IPA interrupt */
+void ipa_interrupt_enable(uint32_t int_flag);
+/* disable IPA interrupt */
+void ipa_interrupt_disable(uint32_t int_flag);
/* get IPA interrupt flag */
-FlagStatus ipa_interrupt_flag_get(uint32_t intflag);
+FlagStatus ipa_interrupt_flag_get(uint32_t int_flag);
/* clear IPA interrupt flag */
-void ipa_interrupt_flag_clear(uint32_t intflag);
+void ipa_interrupt_flag_clear(uint32_t int_flag);
#endif /* GD32F4XX_IPA_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_iref.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_iref.h
index 0b7b3224d9..4be9181ed8 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_iref.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_iref.h
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_iref.h
- \brief definitions for the IREF
+ \file gd32f4xx_iref.h
+ \brief definitions for the IREF
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#ifndef GD32F4XX_IREF_H
@@ -25,7 +50,7 @@
#define IREF_CTL_CSDT BITS(0,5) /*!< current step data */
#define IREF_CTL_SCMOD BIT(7) /*!< sink current mode */
#define IREF_CTL_CPT BITS(8,12) /*!< current precision trim */
-#define IREF_CTL_SSEL BIT(14) /*!< step selection */
+#define IREF_CTL_SSEL BIT(14) /*!< step selection */
#define IREF_CTL_CREN BIT(15) /*!< current reference enable */
/* constants definitions */
@@ -130,13 +155,13 @@
#define IREF_CUR_STEP_DATA_61 CTL_CSDT(61) /*!< IREF current step data 61 */
#define IREF_CUR_STEP_DATA_62 CTL_CSDT(62) /*!< IREF current step data 62 */
#define IREF_CUR_STEP_DATA_63 CTL_CSDT(63) /*!< IREF current step data 63 */
-
+
/* IREF mode selection */
#define IREF_STEP(regval) (BIT(14) & ((uint32_t)(regval) << 14))
#define IREF_MODE_LOW_POWER IREF_STEP(0) /*!< low power, 1uA step */
#define IREF_MODE_HIGH_CURRENT IREF_STEP(1) /*!< high current, 8uA step */
-
-/* IREF sink current mode*/
+
+/* IREF sink current mode*/
#define IREF_CURRENT(regval) (BIT(7) & ((uint32_t)(regval) << 7))
#define IREF_SOURCE_CURRENT IREF_CURRENT(0) /*!< IREF source current */
#define IREF_SINK_CURRENT IREF_CURRENT(1) /*!< IREF sink current */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_misc.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_misc.h
index 2052abe9a0..21ae664c14 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_misc.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_misc.h
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_misc.h
- \brief definitions for the MISC
+ \file gd32f4xx_misc.h
+ \brief definitions for the MISC
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#ifndef GD32F4XX_MISC_H
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_pmu.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_pmu.h
index 74a857e96c..f19b1cb2ec 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_pmu.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_pmu.h
@@ -1,14 +1,40 @@
/*!
- \file gd32f4xx_pmu.h
- \brief definitions for the PMU
+ \file gd32f4xx_pmu.h
+ \brief definitions for the PMU
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
+
#ifndef GD32F4XX_PMU_H
#define GD32F4XX_PMU_H
@@ -52,14 +78,14 @@
/* constants definitions */
/* PMU low voltage detector threshold definitions */
#define CTL_LVDT(regval) (BITS(5,7)&((uint32_t)(regval)<<5))
-#define PMU_LVDT_0 CTL_LVDT(0) /*!< voltage threshold is 2.2V */
+#define PMU_LVDT_0 CTL_LVDT(0) /*!< voltage threshold is 2.1V */
#define PMU_LVDT_1 CTL_LVDT(1) /*!< voltage threshold is 2.3V */
#define PMU_LVDT_2 CTL_LVDT(2) /*!< voltage threshold is 2.4V */
-#define PMU_LVDT_3 CTL_LVDT(3) /*!< voltage threshold is 2.5V */
-#define PMU_LVDT_4 CTL_LVDT(4) /*!< voltage threshold is 2.6V */
-#define PMU_LVDT_5 CTL_LVDT(5) /*!< voltage threshold is 2.7V */
-#define PMU_LVDT_6 CTL_LVDT(6) /*!< voltage threshold is 2.8V */
-#define PMU_LVDT_7 CTL_LVDT(7) /*!< voltage threshold is 2.9V */
+#define PMU_LVDT_3 CTL_LVDT(3) /*!< voltage threshold is 2.6V */
+#define PMU_LVDT_4 CTL_LVDT(4) /*!< voltage threshold is 2.7V */
+#define PMU_LVDT_5 CTL_LVDT(5) /*!< voltage threshold is 2.9V */
+#define PMU_LVDT_6 CTL_LVDT(6) /*!< voltage threshold is 3.0V */
+#define PMU_LVDT_7 CTL_LVDT(7) /*!< voltage threshold is 3.1V */
/* PMU LDO output voltage select definitions */
#define CTL_LDOVS(regval) (BITS(14,15)&((uint32_t)(regval)<<14))
@@ -124,7 +150,7 @@
void pmu_deinit(void);
/* select low voltage detector threshold */
-void pmu_lvd_select(uint32_t pmu_lvdt_n);
+void pmu_lvd_select(uint32_t lvdt_n);
/* LDO output voltage select */
void pmu_ldo_output_select(uint32_t ldo_output);
/* PMU lvd disable */
@@ -148,7 +174,7 @@ void pmu_lowdriver_normalpower_config(uint32_t mode);
/* PMU work at sleep mode */
void pmu_to_sleepmode(uint8_t sleepmodecmd);
/* PMU work at deepsleep mode */
-void pmu_to_deepsleepmode(uint32_t pmu_ldo, uint8_t deepsleepmodecmd);
+void pmu_to_deepsleepmode(uint32_t ldo, uint8_t deepsleepmodecmd);
/* PMU work at standby mode */
void pmu_to_standbymode(uint8_t standbymodecmd);
/* PMU wakeup pin enable */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_rcu.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_rcu.h
index 6851c2e22f..0445df4eb0 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_rcu.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_rcu.h
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_rcu.h
- \brief definitions for the RCU
+ \file gd32f4xx_rcu.h
+ \brief definitions for the RCU
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#ifndef GD32F4XX_RCU_H
@@ -34,14 +59,14 @@
#define RCU_APB2EN REG32(RCU + 0x44U) /*!< APB2 enable register */
#define RCU_AHB1SPEN REG32(RCU + 0x50U) /*!< AHB1 sleep mode enable register */
#define RCU_AHB2SPEN REG32(RCU + 0x54U) /*!< AHB2 sleep mode enable register */
-#define RCU_AHB3SPEN REG32(RCU + 0x58U) /*!< AHB3 sleep mode enable register */
+#define RCU_AHB3SPEN REG32(RCU + 0x58U) /*!< AHB3 sleep mode enable register */
#define RCU_APB1SPEN REG32(RCU + 0x60U) /*!< APB1 sleep mode enable register */
#define RCU_APB2SPEN REG32(RCU + 0x64U) /*!< APB2 sleep mode enable register */
#define RCU_BDCTL REG32(RCU + 0x70U) /*!< backup domain control register */
#define RCU_RSTSCK REG32(RCU + 0x74U) /*!< reset source / clock register */
#define RCU_PLLSSCTL REG32(RCU + 0x80U) /*!< PLL clock spread spectrum control register */
-#define RCU_PLLI2S REG32(RCU + 0x84U) /*!< PLLI2S register */
-#define RCU_PLLSAI REG32(RCU + 0x88U) /*!< PLLSAI register */
+#define RCU_PLLI2S REG32(RCU + 0x84U) /*!< PLLI2S register */
+#define RCU_PLLSAI REG32(RCU + 0x88U) /*!< PLLSAI register */
#define RCU_CFG1 REG32(RCU + 0x8CU) /*!< clock configuration register 1 */
#define RCU_ADDCTL REG32(RCU + 0xC0U) /*!< Additional clock control register */
#define RCU_ADDINT REG32(RCU + 0xCCU) /*!< Additional clock interrupt register */
@@ -54,7 +79,7 @@
/* bits definitions */
/* RCU_CTL */
#define RCU_CTL_IRC16MEN BIT(0) /*!< internal high speed oscillator enable */
-#define RCU_CTL_IRC16MSTB BIT(1) /*!< IRC8M high speed internal oscillator stabilization flag */
+#define RCU_CTL_IRC16MSTB BIT(1) /*!< IRC16M high speed internal oscillator stabilization flag */
#define RCU_CTL_IRC16MADJ BITS(3,7) /*!< high speed internal oscillator clock trim adjust value */
#define RCU_CTL_IRC16MCALIB BITS(8,15) /*!< high speed internal oscillator calibration value register */
#define RCU_CTL_HXTALEN BIT(16) /*!< external high speed oscillator enable */
@@ -64,7 +89,7 @@
#define RCU_CTL_PLLEN BIT(24) /*!< PLL enable */
#define RCU_CTL_PLLSTB BIT(25) /*!< PLL Clock Stabilization Flag */
#define RCU_CTL_PLLI2SEN BIT(26) /*!< PLLI2S enable */
-#define RCU_CTL_PLLI2STB BIT(27) /*!< PLLI2S Clock Stabilization Flag */
+#define RCU_CTL_PLLI2SSTB BIT(27) /*!< PLLI2S Clock Stabilization Flag */
#define RCU_CTL_PLLSAIEN BIT(28) /*!< PLLSAI enable */
#define RCU_CTL_PLLSAISTB BIT(29) /*!< PLLSAI Clock Stabilization Flag */
@@ -123,7 +148,7 @@
#define RCU_AHB1RST_PGRST BIT(6) /*!< GPIO port G reset */
#define RCU_AHB1RST_PHRST BIT(7) /*!< GPIO port H reset */
#define RCU_AHB1RST_PIRST BIT(8) /*!< GPIO port I reset */
-#define RCU_AHB1RST_CRCRST BIT(12) /*!< CRC reset */
+#define RCU_AHB1RST_CRCRST BIT(12) /*!< CRC reset */
#define RCU_AHB1RST_DMA0RST BIT(21) /*!< DMA0 reset */
#define RCU_AHB1RST_DMA1RST BIT(22) /*!< DMA1 reset */
#define RCU_AHB1RST_IPARST BIT(23) /*!< IPA reset */
@@ -134,7 +159,7 @@
#define RCU_AHB2RST_DCIRST BIT(0) /*!< DCI reset */
#define RCU_AHB2RST_TRNGRST BIT(6) /*!< TRNG reset */
#define RCU_AHB2RST_USBFSRST BIT(7) /*!< USBFS reset */
-
+
/* RCU_AHB3RST */
#define RCU_AHB3RST_EXMCRST BIT(0) /*!< EXMC reset */
@@ -167,9 +192,9 @@
/* RCU_APB2RST */
#define RCU_APB2RST_TIMER0RST BIT(0) /*!< TIMER0 reset */
-#define RCU_APB2RST_TIMER7RST BIT(1) /*!< TIMER7 reset */
+#define RCU_APB2RST_TIMER7RST BIT(1) /*!< TIMER7 reset */
#define RCU_APB2RST_USART0RST BIT(4) /*!< USART0 reset */
-#define RCU_APB2RST_USART5RST BIT(5) /*!< USART5 reset */
+#define RCU_APB2RST_USART5RST BIT(5) /*!< USART5 reset */
#define RCU_APB2RST_ADCRST BIT(8) /*!< ADC reset */
#define RCU_APB2RST_SDIORST BIT(11) /*!< SDIO reset */
#define RCU_APB2RST_SPI0RST BIT(12) /*!< SPI0 reset */
@@ -361,11 +386,11 @@
#define RCU_RSTSCK_LPRSTF BIT(31) /*!< low-power reset flag */
/* RCU_PLLSSCTL */
-#define RCU_PLLSSCTL_MODCNT BITS(0,12) /*!< these bits configure PLL spread spectrum modulation
- profile amplitude and frequency. the following criteria
+#define RCU_PLLSSCTL_MODCNT BITS(0,12) /*!< these bits configure PLL spread spectrum modulation
+ profile amplitude and frequency. the following criteria
must be met: MODSTEP*MODCNT=215-1 */
-#define RCU_PLLSSCTL_MODSTEP BITS(13,27) /*!< these bits configure PLL spread spectrum modulation
- profile amplitude and frequency. the following criteria
+#define RCU_PLLSSCTL_MODSTEP BITS(13,27) /*!< these bits configure PLL spread spectrum modulation
+ profile amplitude and frequency. the following criteria
must be met: MODSTEP*MODCNT=215-1 */
#define RCU_PLLSSCTL_SS_TYPE BIT(30) /*!< PLL spread spectrum modulation type select */
#define RCU_PLLSSCTL_SSCGON BIT(31) /*!< PLL spread spectrum modulation enable */
@@ -438,7 +463,7 @@
#define ADD_APB1EN_REG_OFFSET 0xE4U /*!< APB1 additional enable register offset */
#define ADD_APB1SPEN_REG_OFFSET 0xE8U /*!< APB1 additional sleep mode enable register offset */
-/* peripherals reset */
+/* peripherals reset */
#define AHB1RST_REG_OFFSET 0x10U /*!< AHB1 reset register offset */
#define AHB2RST_REG_OFFSET 0x14U /*!< AHB2 reset register offset */
#define AHB3RST_REG_OFFSET 0x18U /*!< AHB3 reset register offset */
@@ -504,7 +529,7 @@ typedef enum
RCU_TIMER6 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 5U), /*!< TIMER6 clock */
RCU_TIMER11 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 6U), /*!< TIMER11 clock */
RCU_TIMER12 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 7U), /*!< TIMER12 clock */
- RCU_TIMER13 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 8U), /*!< TIMER13 clock */
+ RCU_TIMER13 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 8U), /*!< TIMER13 clock */
RCU_WWDGT = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 11U), /*!< WWDGT clock */
RCU_SPI1 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 14U), /*!< SPI1 clock */
RCU_SPI2 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 15U), /*!< SPI2 clock */
@@ -514,7 +539,7 @@ typedef enum
RCU_UART4 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 20U), /*!< UART4 clock */
RCU_I2C0 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 21U), /*!< I2C0 clock */
RCU_I2C1 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 22U), /*!< I2C1 clock */
- RCU_I2C2 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 23U), /*!< I2C2 clock */
+ RCU_I2C2 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 23U), /*!< I2C2 clock */
RCU_CAN0 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 25U), /*!< CAN0 clock */
RCU_CAN1 = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 26U), /*!< CAN1 clock */
RCU_PMU = RCU_REGIDX_BIT(APB1EN_REG_OFFSET, 28U), /*!< PMU clock */
@@ -540,7 +565,7 @@ typedef enum
RCU_SPI4 = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 20U), /*!< SPI4 clock */
RCU_SPI5 = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 21U), /*!< SPI5 clock */
RCU_TLI = RCU_REGIDX_BIT(APB2EN_REG_OFFSET, 26U), /*!< TLI clock */
- /* APB2 additional peripherals */
+ /* APB1 additional peripherals */
RCU_CTC = RCU_REGIDX_BIT(ADD_APB1EN_REG_OFFSET, 27U), /*!< CTC clock */
RCU_IREF = RCU_REGIDX_BIT(ADD_APB1EN_REG_OFFSET, 31U), /*!< IREF clock */
}rcu_periph_enum;
@@ -588,7 +613,7 @@ typedef enum
RCU_TIMER6_SLP = RCU_REGIDX_BIT(APB1SPEN_REG_OFFSET, 5U), /*!< TIMER6 clock */
RCU_TIMER11_SLP = RCU_REGIDX_BIT(APB1SPEN_REG_OFFSET, 6U), /*!< TIMER11 clock */
RCU_TIMER12_SLP = RCU_REGIDX_BIT(APB1SPEN_REG_OFFSET, 7U), /*!< TIMER12 clock */
- RCU_TIMER13_SLP = RCU_REGIDX_BIT(APB1SPEN_REG_OFFSET, 8U), /*!< TIMER13 clock */
+ RCU_TIMER13_SLP = RCU_REGIDX_BIT(APB1SPEN_REG_OFFSET, 8U), /*!< TIMER13 clock */
RCU_WWDGT_SLP = RCU_REGIDX_BIT(APB1SPEN_REG_OFFSET, 11U), /*!< WWDGT clock */
RCU_SPI1_SLP = RCU_REGIDX_BIT(APB1SPEN_REG_OFFSET, 14U), /*!< SPI1 clock */
RCU_SPI2_SLP = RCU_REGIDX_BIT(APB1SPEN_REG_OFFSET, 15U), /*!< SPI2 clock */
@@ -598,7 +623,7 @@ typedef enum
RCU_UART4_SLP = RCU_REGIDX_BIT(APB1SPEN_REG_OFFSET, 20U), /*!< UART4 clock */
RCU_I2C0_SLP = RCU_REGIDX_BIT(APB1SPEN_REG_OFFSET, 21U), /*!< I2C0 clock */
RCU_I2C1_SLP = RCU_REGIDX_BIT(APB1SPEN_REG_OFFSET, 22U), /*!< I2C1 clock */
- RCU_I2C2_SLP = RCU_REGIDX_BIT(APB1SPEN_REG_OFFSET, 23U), /*!< I2C2 clock */
+ RCU_I2C2_SLP = RCU_REGIDX_BIT(APB1SPEN_REG_OFFSET, 23U), /*!< I2C2 clock */
RCU_CAN0_SLP = RCU_REGIDX_BIT(APB1SPEN_REG_OFFSET, 25U), /*!< CAN0 clock */
RCU_CAN1_SLP = RCU_REGIDX_BIT(APB1SPEN_REG_OFFSET, 26U), /*!< CAN1 clock */
RCU_PMU_SLP = RCU_REGIDX_BIT(APB1SPEN_REG_OFFSET, 28U), /*!< PMU clock */
@@ -644,8 +669,8 @@ typedef enum
RCU_CRCRST = RCU_REGIDX_BIT(AHB1RST_REG_OFFSET, 12U), /*!< CRC clock reset */
RCU_DMA0RST = RCU_REGIDX_BIT(AHB1RST_REG_OFFSET, 21U), /*!< DMA0 clock reset */
RCU_DMA1RST = RCU_REGIDX_BIT(AHB1RST_REG_OFFSET, 22U), /*!< DMA1 clock reset */
- RCU_IPAENRST = RCU_REGIDX_BIT(AHB1RST_REG_OFFSET, 23U), /*!< IPA clock reset */
- RCU_ENETRST = RCU_REGIDX_BIT(AHB1RST_REG_OFFSET, 25U), /*!< ENET clock reset */
+ RCU_IPARST = RCU_REGIDX_BIT(AHB1RST_REG_OFFSET, 23U), /*!< IPA clock reset */
+ RCU_ENETRST = RCU_REGIDX_BIT(AHB1RST_REG_OFFSET, 25U), /*!< ENET clock reset */
RCU_USBHSRST = RCU_REGIDX_BIT(AHB1RST_REG_OFFSET, 29U), /*!< USBHS clock reset */
/* AHB2 peripherals */
RCU_DCIRST = RCU_REGIDX_BIT(AHB2RST_REG_OFFSET, 0U), /*!< DCI clock reset */
@@ -662,7 +687,7 @@ typedef enum
RCU_TIMER6RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 5U), /*!< TIMER6 clock reset */
RCU_TIMER11RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 6U), /*!< TIMER11 clock reset */
RCU_TIMER12RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 7U), /*!< TIMER12 clock reset */
- RCU_TIMER13RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 8U), /*!< TIMER13 clock reset */
+ RCU_TIMER13RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 8U), /*!< TIMER13 clock reset */
RCU_WWDGTRST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 11U), /*!< WWDGT clock reset */
RCU_SPI1RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 14U), /*!< SPI1 clock reset */
RCU_SPI2RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 15U), /*!< SPI2 clock reset */
@@ -672,7 +697,7 @@ typedef enum
RCU_UART4RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 20U), /*!< UART4 clock reset */
RCU_I2C0RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 21U), /*!< I2C0 clock reset */
RCU_I2C1RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 22U), /*!< I2C1 clock reset */
- RCU_I2C2RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 23U), /*!< I2C2 clock reset */
+ RCU_I2C2RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 23U), /*!< I2C2 clock reset */
RCU_CAN0RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 25U), /*!< CAN0 clock reset */
RCU_CAN1RST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 26U), /*!< CAN1 clock reset */
RCU_PMURST = RCU_REGIDX_BIT(APB1RST_REG_OFFSET, 28U), /*!< PMU clock reset */
@@ -695,7 +720,7 @@ typedef enum
RCU_SPI4RST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 20U), /*!< SPI4 clock reset */
RCU_SPI5RST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 21U), /*!< SPI5 clock reset */
RCU_TLIRST = RCU_REGIDX_BIT(APB2RST_REG_OFFSET, 26U), /*!< TLI clock reset */
- /* APB2 additional peripherals */
+ /* APB1 additional peripherals */
RCU_CTCRST = RCU_REGIDX_BIT(ADD_APB1RST_REG_OFFSET, 27U), /*!< CTC clock reset */
RCU_IREFRST = RCU_REGIDX_BIT(ADD_APB1RST_REG_OFFSET, 31U) /*!< IREF clock reset */
}rcu_periph_reset_enum;
@@ -727,7 +752,7 @@ typedef enum
{
RCU_INT_FLAG_IRC32KSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 0U), /*!< IRC32K stabilization interrupt flag */
RCU_INT_FLAG_LXTALSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 1U), /*!< LXTAL stabilization interrupt flag */
- RCU_INT_FLAG_IRC8MSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 2U), /*!< IRC8M stabilization interrupt flag */
+ RCU_INT_FLAG_IRC16MSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 2U), /*!< IRC16M stabilization interrupt flag */
RCU_INT_FLAG_HXTALSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 3U), /*!< HXTAL stabilization interrupt flag */
RCU_INT_FLAG_PLLSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 4U), /*!< PLL stabilization interrupt flag */
RCU_INT_FLAG_PLLI2SSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 5U), /*!< PLLI2S stabilization interrupt flag */
@@ -755,7 +780,7 @@ typedef enum
{
RCU_INT_IRC32KSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 8U), /*!< IRC32K stabilization interrupt */
RCU_INT_LXTALSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 9U), /*!< LXTAL stabilization interrupt */
- RCU_INT_IRC16MSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 10U), /*!< IRC8M stabilization interrupt */
+ RCU_INT_IRC16MSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 10U), /*!< IRC16M stabilization interrupt */
RCU_INT_HXTALSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 11U), /*!< HXTAL stabilization interrupt */
RCU_INT_PLLSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 12U), /*!< PLL stabilization interrupt */
RCU_INT_PLLI2SSTB = RCU_REGIDX_BIT(INT_REG_OFFSET, 13U), /*!< PLLI2S stabilization interrupt */
@@ -890,7 +915,7 @@ typedef enum
/* CKOUT1 Clock source selection */
#define CFG0_CKOUT1SEL(regval) (BITS(30,31) & ((uint32_t)(regval) << 30))
#define RCU_CKOUT1SRC_SYSTEMCLOCK CFG0_CKOUT1SEL(0) /*!< system clock selected */
-#define RCU_CKOUT1SRC_PLLI2SR CFG0_CKOUT1SEL(1) /*!< low speed crystal oscillator clock (LXTAL) selected */
+#define RCU_CKOUT1SRC_PLLI2SR CFG0_CKOUT1SEL(1) /*!< CK_PLLI2SR clock selected */
#define RCU_CKOUT1SRC_HXTAL CFG0_CKOUT1SEL(2) /*!< high speed crystal oscillator clock (HXTAL) selected */
#define RCU_CKOUT1SRC_PLLP CFG0_CKOUT1SEL(3) /*!< CK_PLLP clock selected */
@@ -938,13 +963,13 @@ typedef enum
#define RCU_PLLSAIR_DIV16 CFG1_PLLSAIRDIV(3) /*!< CK_PLLSAIRDIV clock select CK_PLLSAIR/16 */
/* TIMER clock selection */
-#define RCU_TIMER_PSC_MUL2 ~RCU_CFG1_TIMERSEL /*!< if APB1PSC/APB2PSC in RCU_CFG0 register is 0b0xx(CK_APBx = CK_AHB)
+#define RCU_TIMER_PSC_MUL2 ~RCU_CFG1_TIMERSEL /*!< if APB1PSC/APB2PSC in RCU_CFG0 register is 0b0xx(CK_APBx = CK_AHB)
or 0b100(CK_APBx = CK_AHB/2), the TIMER clock is equal to CK_AHB(CK_TIMERx = CK_AHB).
- or else, the TIMER clock is twice the corresponding APB clock (TIMER in APB1 domain: CK_TIMERx = 2 x CK_APB1;
+ or else, the TIMER clock is twice the corresponding APB clock (TIMER in APB1 domain: CK_TIMERx = 2 x CK_APB1;
TIMER in APB2 domain: CK_TIMERx = 2 x CK_APB2) */
-#define RCU_TIMER_PSC_MUL4 RCU_CFG1_TIMERSEL /*!< if APB1PSC/APB2PSC in RCU_CFG0 register is 0b0xx(CK_APBx = CK_AHB),
- 0b100(CK_APBx = CK_AHB/2), or 0b101(CK_APBx = CK_AHB/4), the TIMER clock is equal to CK_AHB(CK_TIMERx = CK_AHB).
- or else, the TIMER clock is four timers the corresponding APB clock (TIMER in APB1 domain: CK_TIMERx = 4 x CK_APB1;
+#define RCU_TIMER_PSC_MUL4 RCU_CFG1_TIMERSEL /*!< if APB1PSC/APB2PSC in RCU_CFG0 register is 0b0xx(CK_APBx = CK_AHB),
+ 0b100(CK_APBx = CK_AHB/2), or 0b101(CK_APBx = CK_AHB/4), the TIMER clock is equal to CK_AHB(CK_TIMERx = CK_AHB).
+ or else, the TIMER clock is four timers the corresponding APB clock (TIMER in APB1 domain: CK_TIMERx = 4 x CK_APB1;
TIMER in APB2 domain: CK_TIMERx = 4 x CK_APB2) */
/* RCU_PLLSSCTL register bit define */
@@ -966,7 +991,7 @@ typedef enum
/* The PLLP output frequency division factor from PLL VCO clock */
#define RCU_PLLP_DIV_MIN ((uint32_t)2U) /*!< PLLP_DIV min value */
#define RCU_PLLP_DIV_MAX ((uint32_t)8U) /*!< PLLP_DIV max value */
-
+
/* PLL Clock Source Selection */
#define RCU_PLLSRC_IRC16M ((uint32_t)0x00000000U) /*!< IRC16M clock selected as source clock of PLL, PLLSAI, PLLI2S */
#define RCU_PLLSRC_HXTAL RCU_PLL_PLLSEL /*!< HXTAL clock selected as source clock of PLL, PLLSAI, PLLI2S */
@@ -975,10 +1000,10 @@ typedef enum
#define RCU_PLLQ_DIV_MIN ((uint32_t)2U) /*!< PLLQ_DIV min value */
#define RCU_PLLQ_DIV_MAX ((uint32_t)15U) /*!< PLLQ_DIV max value */
-#define CHECK_PLL_PSC_VALID(val) (((val) >= RCU_PLLPSC_DIV_MIN)&&((val) <= RCU_PLLPSC_DIV_MAX))
-#define CHECK_PLL_N_VALID(val, inc) (((val) >= (RCU_PLLN_MUL_MIN + (inc)))&&((val) <= RCU_PLLN_MUL_MAX))
-#define CHECK_PLL_P_VALID(val) (((val) == 2U) || ((val) == 4U) || ((val) == 6U) || ((val) == 8U))
-#define CHECK_PLL_Q_VALID(val) (((val) >= RCU_PLLQ_DIV_MIN)&&((val) <= RCU_PLLQ_DIV_MAX))
+#define CHECK_PLL_PSC_VALID(val) (((val) >= RCU_PLLPSC_DIV_MIN)&&((val) <= RCU_PLLPSC_DIV_MAX))
+#define CHECK_PLL_N_VALID(val, inc) (((val) >= (RCU_PLLN_MUL_MIN + (inc)))&&((val) <= RCU_PLLN_MUL_MAX))
+#define CHECK_PLL_P_VALID(val) (((val) == 2U) || ((val) == 4U) || ((val) == 6U) || ((val) == 8U))
+#define CHECK_PLL_Q_VALID(val) (((val) >= RCU_PLLQ_DIV_MIN)&&((val) <= RCU_PLLQ_DIV_MAX))
/* RCU_BDCTL register bit define */
/* LXTAL drive capability */
@@ -1033,7 +1058,7 @@ typedef enum
#define CHECK_PLLSAI_R_VALID(val) (((val) >= RCU_PLLSAIR_DIV_MIN)&&((val) <= RCU_PLLSAIR_DIV_MAX))
/* RCU_ADDCTL register bit define */
-/* 48MHz clock selection */
+/* 48MHz clock selection */
#define RCU_CK48MSRC_PLL48M ((uint32_t)0x00000000U) /*!< CK48M source clock select PLL48M */
#define RCU_CK48MSRC_IRC48M RCU_ADDCTL_CK48MSEL /*!< CK48M source clock select IRC48M */
@@ -1086,11 +1111,13 @@ void rcu_ckout1_config(uint32_t ckout1_src, uint32_t ckout1_div);
/* configure the PLL clock source selection and PLL multiply factor */
ErrStatus rcu_pll_config(uint32_t pll_src, uint32_t pll_psc, uint32_t pll_n, uint32_t pll_p, uint32_t pll_q);
/* configure the PLLI2S clock */
-ErrStatus rcu_plli2s_config(uint32_t plli2s_n, uint32_t plli2s_q, uint32_t plli2s_r);
+ErrStatus rcu_plli2s_config(uint32_t plli2s_n, uint32_t plli2s_r);
/* configure the PLLSAI clock */
-ErrStatus rcu_pllsai_config(uint32_t pllsai_n, uint32_t pllsai_p, uint32_t pllsai_q, uint32_t pllsai_r);
+ErrStatus rcu_pllsai_config(uint32_t pllsai_n, uint32_t pllsai_p, uint32_t pllsai_r);
/* configure the RTC clock source selection */
void rcu_rtc_clock_config(uint32_t rtc_clock_source);
+/* cconfigure the frequency division of RTC clock when HXTAL was selected as its clock source */
+void rcu_rtc_div_config(uint32_t rtc_div);
/* configure the I2S clock source selection */
void rcu_i2s_clock_config(uint32_t i2s_clock_source);
/* configure the CK48M clock selection */
@@ -1098,7 +1125,7 @@ void rcu_ck48m_clock_config(uint32_t ck48m_clock_source);
/* configure the PLL48M clock selection */
void rcu_pll48m_clock_config(uint32_t pll48m_clock_source);
/* configure the TIMER clock prescaler selection */
-void rcu_timer_clock_prescaler_config(uint32_t timer_clock_prescaler);
+void rcu_timer_clock_prescaler_config(uint32_t timer_clock_prescaler);
/* configure the TLI clock division selection */
void rcu_tli_clock_div_config(uint32_t pllsai_r_div);
@@ -1110,11 +1137,11 @@ void rcu_all_reset_flag_clear(void);
/* get the clock stabilization interrupt and ckm flags */
FlagStatus rcu_interrupt_flag_get(rcu_int_flag_enum int_flag);
/* clear the interrupt flags */
-void rcu_interrupt_flag_clear(rcu_int_flag_clear_enum int_flag_clear);
+void rcu_interrupt_flag_clear(rcu_int_flag_clear_enum int_flag);
/* enable the stabilization interrupt */
-void rcu_interrupt_enable(rcu_int_enum stab_int);
+void rcu_interrupt_enable(rcu_int_enum interrupt);
/* disable the stabilization interrupt */
-void rcu_interrupt_disable(rcu_int_enum stab_int);
+void rcu_interrupt_disable(rcu_int_enum interrupt);
/* configure the LXTAL drive capability */
void rcu_lxtal_drive_capability_config(uint32_t lxtal_dricap);
@@ -1140,7 +1167,7 @@ void rcu_spread_spectrum_config(uint32_t spread_spectrum_type, uint32_t modstep,
/* enable the spread spectrum modulation for the main PLL clock */
void rcu_spread_spectrum_enable(void);
/* disable the spread spectrum modulation for the main PLL clock */
-void rcu_spread_spectrum_disable(void);
+void rcu_spread_spectrum_disable(void);
/* unlock the voltage key */
void rcu_voltage_key_unlock(void);
/* set the deep sleep mode voltage */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_rtc.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_rtc.h
index 27155a3076..75e66f236e 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_rtc.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_rtc.h
@@ -1,14 +1,40 @@
/*!
- \file gd32f4xx_rtc.h
- \brief definitions for the RTC
+ \file gd32f4xx_rtc.c
+ \brief definitions for the RTC
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
+
#ifndef GD32F4XX_RTC_H
#define GD32F4XX_RTC_H
@@ -254,7 +280,7 @@ typedef struct
ControlStatus tamper_precharge_enable; /*!< RTC tamper precharge feature during a voltage level detection */
uint32_t tamper_precharge_time; /*!< RTC tamper precharge duration if precharge feature is enabled */
ControlStatus tamper_with_timestamp; /*!< RTC tamper time-stamp feature */
-}rtc_tamper_struct;
+}rtc_tamper_struct;
/* time register value */
#define TIME_SC(regval) (BITS(0,6) & ((uint32_t)(regval) << 0)) /*!< write value to RTC_TIME_SC bit field */
@@ -380,7 +406,7 @@ typedef struct
#define GET_DTS_DAY(regval) GET_BITS((regval),0,5) /*!< get value of RTC_DTS_DAY bit field */
#define DTS_MON(regval) (BITS(8,12) & ((uint32_t)(regval) << 8)) /*!< write value to RTC_DTS_MON bit field */
-#define GET_DTS_MON(regval) GET_BITS((regval),8,11) /*!< get value of RTC_DTS_MON bit field */
+#define GET_DTS_MON(regval) GET_BITS((regval),8,12) /*!< get value of RTC_DTS_MON bit field */
#define DTS_DOW(regval) (BITS(13,15) & ((uint32_t)(regval) << 13)) /*!< write value to RTC_DTS_DOW bit field */
#define GET_DTS_DOW(regval) GET_BITS((regval),13,15) /*!< get value of RTC_DTS_DOW bit field */
@@ -399,7 +425,7 @@ typedef struct
#define RTC_CALIBRATION_PLUS_RESET ((uint32_t)0x00000000U) /*!< no effect */
/* tamp register value */
-#define TAMP_FREQ(regval) (BITS(8,10) & ((uint32_t)(regval) << 10)) /*!< write value to RTC_TAMP_FREQ bit field */
+#define TAMP_FREQ(regval) (BITS(8,10) & ((uint32_t)(regval) << 8)) /*!< write value to RTC_TAMP_FREQ bit field */
#define RTC_FREQ_DIV32768 TAMP_FREQ(0) /*!< sample once every 32768 RTCCLK(1Hz if RTCCLK=32.768KHz) */
#define RTC_FREQ_DIV16384 TAMP_FREQ(1) /*!< sample once every 16384 RTCCLK(2Hz if RTCCLK=32.768KHz) */
#define RTC_FREQ_DIV8192 TAMP_FREQ(2) /*!< sample once every 8192 RTCCLK(4Hz if RTCCLK=32.768KHz) */
@@ -475,12 +501,12 @@ typedef struct
#define RTC_WUT_RESET ((uint32_t)0x0000FFFFU) /*!< RTC_WUT register reset value */
/* RTC alarm */
-#define RTC_ALARM0 ((uint8_t)0x01U) /*!< RTC alarm 0 */
-#define RTC_ALARM1 ((uint8_t)0x02U) /*!< RTC alarm 1 */
+#define RTC_ALARM0 ((uint8_t)0x01U) /*!< RTC alarm 0 */
+#define RTC_ALARM1 ((uint8_t)0x02U) /*!< RTC alarm 1 */
/* RTC coarse calibration direction */
-#define CALIB_INCREASE ((uint8_t)0x01U) /*!< RTC coarse calibration increase */
-#define CALIB_DECREASE ((uint8_t)0x02U) /*!< RTC coarse calibration decrease */
+#define CALIB_INCREASE ((uint8_t)0x01U) /*!< RTC coarse calibration increase */
+#define CALIB_DECREASE ((uint8_t)0x02U) /*!< RTC coarse calibration decrease */
/* RTC wakeup timer clock */
#define CTL_WTCS(regval) (BITS(0,2) & ((regval)<< 0))
@@ -490,13 +516,30 @@ typedef struct
#define WAKEUP_RTCCK_DIV2 CTL_WTCS(3) /*!< wakeup timer clock is RTC clock divided by 2 */
#define WAKEUP_CKSPRE CTL_WTCS(4) /*!< wakeup timer clock is ckapre */
#define WAKEUP_CKSPRE_2EXP16 CTL_WTCS(6) /*!< wakeup timer clock is ckapre and wakeup timer add 2exp16 */
-
+
/* RTC_AF pin */
#define RTC_AF0_TIMESTAMP ((uint32_t)0x00000000) /*!< RTC_AF0 use for timestamp */
#define RTC_AF1_TIMESTAMP RTC_TAMP_TSSEL /*!< RTC_AF1 use for timestamp */
#define RTC_AF0_TAMPER0 ((uint32_t)0x00000000) /*!< RTC_AF0 use for tamper0 */
#define RTC_AF1_TAMPER0 RTC_TAMP_TP0SEL /*!< RTC_AF1 use for tamper0 */
+/* RTC flags */
+#define RTC_FLAG_ALRM0W RTC_STAT_ALRM0WF /*!< alarm0 configuration can be write flag */
+#define RTC_FLAG_ALRM1W RTC_STAT_ALRM1WF /*!< alarm1 configuration can be write flag */
+#define RTC_FLAG_WTW RTC_STAT_WTWF /*!< wakeup timer can be write flag */
+#define RTC_FLAG_SOP RTC_STAT_SOPF /*!< shift function operation pending flag */
+#define RTC_FLAG_YCM RTC_STAT_YCM /*!< year configuration mark status flag */
+#define RTC_FLAG_RSYN RTC_STAT_RSYNF /*!< register synchronization flag */
+#define RTC_FLAG_INIT RTC_STAT_INITF /*!< initialization state flag */
+#define RTC_FLAG_ALRM0 RTC_STAT_ALRM0F /*!< alarm0 occurs flag */
+#define RTC_FLAG_ALRM1 RTC_STAT_ALRM1F /*!< alarm1 occurs flag */
+#define RTC_FLAG_WT RTC_STAT_WTF /*!< wakeup timer occurs flag */
+#define RTC_FLAG_TS RTC_STAT_TSF /*!< time-stamp flag */
+#define RTC_FLAG_TSOVR RTC_STAT_TSOVRF /*!< time-stamp overflow flag */
+#define RTC_FLAG_TP0 RTC_STAT_TP0F /*!< RTC tamper 0 detected flag */
+#define RTC_FLAG_TP1 RTC_STAT_TP1F /*!< RTC tamper 1 detected flag */
+#define RTC_STAT_SCP RTC_STAT_SCPF /*!< smooth calibration pending flag */
+
/* function declarations */
/* reset most of the RTC registers */
ErrStatus rtc_deinit(void);
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_sdio.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_sdio.h
index bd3b2c8fc6..a18214c023 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_sdio.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_sdio.h
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_sdio.h
- \brief definitions for the SDIO
+ \file gd32f4xx_sdio.h
+ \brief definitions for the SDIO
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#ifndef GD32F4XX_SDIO_H
@@ -179,7 +204,7 @@
#define SDIO_FLAG_SDIOINT BIT(22) /*!< SD I/O interrupt received flag */
#define SDIO_FLAG_ATAEND BIT(23) /*!< CE-ATA command completion signal received (only for CMD61) flag */
-/* SDIO interrupt flags */
+/* SDIO interrupt enable or disable */
#define SDIO_INT_CCRCERR BIT(0) /*!< SDIO CCRCERR interrupt */
#define SDIO_INT_DTCRCERR BIT(1) /*!< SDIO DTCRCERR interrupt */
#define SDIO_INT_CMDTMOUT BIT(2) /*!< SDIO CMDTMOUT interrupt */
@@ -205,6 +230,32 @@
#define SDIO_INT_SDIOINT BIT(22) /*!< SDIO SDIOINT interrupt */
#define SDIO_INT_ATAEND BIT(23) /*!< SDIO ATAEND interrupt */
+/* SDIO interrupt flags */
+#define SDIO_INT_FLAG_CCRCERR BIT(0) /*!< SDIO CCRCERR interrupt flag */
+#define SDIO_INT_FLAG_DTCRCERR BIT(1) /*!< SDIO DTCRCERR interrupt flag */
+#define SDIO_INT_FLAG_CMDTMOUT BIT(2) /*!< SDIO CMDTMOUT interrupt flag */
+#define SDIO_INT_FLAG_DTTMOUT BIT(3) /*!< SDIO DTTMOUT interrupt flag */
+#define SDIO_INT_FLAG_TXURE BIT(4) /*!< SDIO TXURE interrupt flag */
+#define SDIO_INT_FLAG_RXORE BIT(5) /*!< SDIO RXORE interrupt flag */
+#define SDIO_INT_FLAG_CMDRECV BIT(6) /*!< SDIO CMDRECV interrupt flag */
+#define SDIO_INT_FLAG_CMDSEND BIT(7) /*!< SDIO CMDSEND interrupt flag */
+#define SDIO_INT_FLAG_DTEND BIT(8) /*!< SDIO DTEND interrupt flag */
+#define SDIO_INT_FLAG_STBITE BIT(9) /*!< SDIO STBITE interrupt flag */
+#define SDIO_INT_FLAG_DTBLKEND BIT(10) /*!< SDIO DTBLKEND interrupt flag */
+#define SDIO_INT_FLAG_CMDRUN BIT(11) /*!< SDIO CMDRUN interrupt flag */
+#define SDIO_INT_FLAG_TXRUN BIT(12) /*!< SDIO TXRUN interrupt flag */
+#define SDIO_INT_FLAG_RXRUN BIT(13) /*!< SDIO RXRUN interrupt flag */
+#define SDIO_INT_FLAG_TFH BIT(14) /*!< SDIO TFH interrupt flag */
+#define SDIO_INT_FLAG_RFH BIT(15) /*!< SDIO RFH interrupt flag */
+#define SDIO_INT_FLAG_TFF BIT(16) /*!< SDIO TFF interrupt flag */
+#define SDIO_INT_FLAG_RFF BIT(17) /*!< SDIO RFF interrupt flag */
+#define SDIO_INT_FLAG_TFE BIT(18) /*!< SDIO TFE interrupt flag */
+#define SDIO_INT_FLAG_RFE BIT(19) /*!< SDIO RFE interrupt flag */
+#define SDIO_INT_FLAG_TXDTVAL BIT(20) /*!< SDIO TXDTVAL interrupt flag */
+#define SDIO_INT_FLAG_RXDTVAL BIT(21) /*!< SDIO RXDTVAL interrupt flag */
+#define SDIO_INT_FLAG_SDIOINT BIT(22) /*!< SDIO SDIOINT interrupt flag */
+#define SDIO_INT_FLAG_ATAEND BIT(23) /*!< SDIO ATAEND interrupt flag */
+
/* SDIO power control */
#define PWRCTL_PWRCTL(regval) (BITS(0,1) & ((uint32_t)(regval) << 0))
#define SDIO_POWER_OFF PWRCTL_PWRCTL(0) /*!< SDIO power off */
@@ -275,6 +326,7 @@
#define SDIO_READWAITTYPE_CLK SDIO_DATACTL_RWTYPE /*!< read wait control by stopping SDIO_CLK */
/* function declarations */
+/* de/initialization functions, hardware clock, bus mode, power_state and SDIO clock configuration */
/* deinitialize the SDIO */
void sdio_deinit(void);
/* configure the SDIO clock */
@@ -294,7 +346,7 @@ void sdio_clock_enable(void);
/* disable SDIO_CLK clock output */
void sdio_clock_disable(void);
-/* configure the command index, argument, response type, wait type and CSM to send command */
+/* configure the command index, argument, response type, wait type and CSM to send command functions */
/* configure the command and response */
void sdio_command_response_config(uint32_t cmd_index, uint32_t cmd_argument, uint32_t response_type);
/* set the command state machine wait type */
@@ -308,7 +360,7 @@ uint8_t sdio_command_index_get(void);
/* get the response for the last received command */
uint32_t sdio_response_get(uint32_t sdio_responsex);
-/* configure the data timeout, length, block size, transfer mode, direction and DSM for data transfer */
+/* configure the data timeout, length, block size, transfer mode, direction and DSM for data transfer functions */
/* configure the data timeout, data length and data block size */
void sdio_data_config(uint32_t data_timeout, uint32_t data_length, uint32_t data_blocksize);
/* configure the data transfer mode and direction */
@@ -330,6 +382,7 @@ void sdio_dma_enable(void);
/* disable the DMA request for SDIO */
void sdio_dma_disable(void);
+/* flag and interrupt functions */
/* get the flags state of SDIO */
FlagStatus sdio_flag_get(uint32_t flag);
/* clear the pending flags of SDIO */
@@ -343,6 +396,7 @@ FlagStatus sdio_interrupt_flag_get(uint32_t int_flag);
/* clear the interrupt pending flags of SDIO */
void sdio_interrupt_flag_clear(uint32_t int_flag);
+/* SD I/O card functions */
/* enable the read wait mode(SD I/O only) */
void sdio_readwait_enable(void);
/* disable the read wait mode(SD I/O only) */
@@ -362,6 +416,7 @@ void sdio_suspend_enable(void);
/* disable the SD I/O suspend operation(SD I/O only) */
void sdio_suspend_disable(void);
+/* CE-ATA functions */
/* enable the CE-ATA command(CE-ATA only) */
void sdio_ceata_command_enable(void);
/* disable the CE-ATA command(CE-ATA only) */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_spi.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_spi.h
index 422df94a6f..61bf8b1af2 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_spi.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_spi.h
@@ -1,14 +1,40 @@
/*!
- \file gd32f4xx_spi.h
- \brief definitions for the SPI
+ \file gd32f4xx_spi.h
+ \brief definitions for the SPI
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
+
#ifndef GD32F4XX_SPI_H
#define GD32F4XX_SPI_H
@@ -50,7 +76,7 @@
#define I2S_ADD_I2SPSC(i2sx_add) REG32((i2sx_add) + 0x20U) /*!< I2S_ADD I2S clock prescaler register */
/* bits definitions */
-/* SPIx_CTL0 */
+/* SPI_CTL0 */
#define SPI_CTL0_CKPH BIT(0) /*!< clock phase selection*/
#define SPI_CTL0_CKPL BIT(1) /*!< clock polarity selection */
#define SPI_CTL0_MSTMOD BIT(2) /*!< master mode enable */
@@ -66,7 +92,7 @@
#define SPI_CTL0_BDOEN BIT(14) /*!< bidirectional transmit output enable*/
#define SPI_CTL0_BDEN BIT(15) /*!< bidirectional enable */
-/* SPIx_CTL1 */
+/* SPI_CTL1 */
#define SPI_CTL1_DMAREN BIT(0) /*!< receive buffer dma enable */
#define SPI_CTL1_DMATEN BIT(1) /*!< transmit buffer dma enable */
#define SPI_CTL1_NSSDRV BIT(2) /*!< drive nss output */
@@ -75,16 +101,16 @@
#define SPI_CTL1_RBNEIE BIT(6) /*!< receive buffer not empty interrupt enable */
#define SPI_CTL1_TBEIE BIT(7) /*!< transmit buffer empty interrupt enable */
-/* SPIx_STAT */
+/* SPI_STAT */
#define SPI_STAT_RBNE BIT(0) /*!< receive buffer not empty */
#define SPI_STAT_TBE BIT(1) /*!< transmit buffer empty */
#define SPI_STAT_I2SCH BIT(2) /*!< I2S channel side */
#define SPI_STAT_TXURERR BIT(3) /*!< I2S transmission underrun error bit */
#define SPI_STAT_CRCERR BIT(4) /*!< SPI CRC error bit */
-#define SPI_STAT_CONFERR BIT(5) /*!< SPI configuration error */
-#define SPI_STAT_RXORERR BIT(6) /*!< SPI reception overrun error Bit */
-#define SPI_STAT_TRANS BIT(7) /*!< transmitting on-going Bit */
-#define SPI_STAT_FERR BIT(8) /*!< format error */
+#define SPI_STAT_CONFERR BIT(5) /*!< SPI configuration error bit */
+#define SPI_STAT_RXORERR BIT(6) /*!< SPI reception overrun error bit */
+#define SPI_STAT_TRANS BIT(7) /*!< transmitting on-going bit */
+#define SPI_STAT_FERR BIT(8) /*!< format error bit */
/* SPI_DATA */
#define SPI_DATA_DATA BITS(0,15) /*!< data transfer register */
@@ -96,9 +122,9 @@
#define SPI_RCRC_RCR BITS(0,15) /*!< RX CRC register */
/* SPI_TCRC */
-#define SPI_TCRC_TCR BITS(0,15) /*!< RX CRC register */
+#define SPI_TCRC_TCR BITS(0,15) /*!< TX CRC register */
-/* SPIx_I2SCTL */
+/* SPI_I2SCTL */
#define SPI_I2SCTL_CHLEN BIT(0) /*!< channel length */
#define SPI_I2SCTL_DTLEN BITS(1,2) /*!< data length */
#define SPI_I2SCTL_CKPL BIT(3) /*!< idle state clock polarity */
@@ -108,12 +134,12 @@
#define SPI_I2SCTL_I2SEN BIT(10) /*!< I2S enable */
#define SPI_I2SCTL_I2SSEL BIT(11) /*!< I2S mode selection */
-/* SPIx_I2S_PSC */
+/* SPI_I2S_PSC */
#define SPI_I2SPSC_DIV BITS(0,7) /*!< dividing factor for the prescaler */
#define SPI_I2SPSC_OF BIT(8) /*!< odd factor for the prescaler */
#define SPI_I2SPSC_MCKOEN BIT(9) /*!< I2S MCK output enable */
-/* SPIx_SPI_QCTL(only SPI5) */
+/* SPI_SPI_QCTL(only SPI5) */
#define SPI_QCTL_QMOD BIT(0) /*!< quad-SPI mode enable */
#define SPI_QCTL_QRD BIT(1) /*!< quad-SPI mode read select */
#define SPI_QCTL_IO23_DRV BIT(2) /*!< drive SPI_IO2 and SPI_IO3 enable */
@@ -121,7 +147,7 @@
/* constants definitions */
/* SPI and I2S parameter struct definitions */
typedef struct
-{
+{
uint32_t device_mode; /*!< SPI master or slave */
uint32_t trans_mode; /*!< SPI transtype */
uint32_t frame_size; /*!< SPI frame size */
@@ -131,32 +157,39 @@ typedef struct
uint32_t prescale; /*!< SPI prescale factor */
}spi_parameter_struct;
-/* SPI struct parameter options */
+/* SPI mode definitions */
#define SPI_MASTER (SPI_CTL0_MSTMOD | SPI_CTL0_SWNSS) /*!< SPI as master */
#define SPI_SLAVE ((uint32_t)0x00000000U) /*!< SPI as slave */
-#define SPI_BIDIRECTIONAL_TEANSMIT SPI_CTL0_BDOEN /*!< SPI work in transmit-only mode */
-#define SPI_BIDIRECTIONAL_RECEIVE ~SPI_CTL0_BDOEN /*!< SPI work in receive-only mode */
+/* SPI bidirectional transfer direction */
+#define SPI_BIDIRECTIONAL_TRANSMIT SPI_CTL0_BDOEN /*!< SPI work in transmit-only mode */
+#define SPI_BIDIRECTIONAL_RECEIVE (~SPI_CTL0_BDOEN) /*!< SPI work in receive-only mode */
+/* SPI transmit type */
#define SPI_TRANSMODE_FULLDUPLEX ((uint32_t)0x00000000U) /*!< SPI receive and send data at fullduplex communication */
#define SPI_TRANSMODE_RECEIVEONLY SPI_CTL0_RO /*!< SPI only receive data */
#define SPI_TRANSMODE_BDRECEIVE SPI_CTL0_BDEN /*!< bidirectional receive data */
#define SPI_TRANSMODE_BDTRANSMIT (SPI_CTL0_BDEN | SPI_CTL0_BDOEN) /*!< bidirectional transmit data*/
+/* SPI frame size */
#define SPI_FRAMESIZE_16BIT SPI_CTL0_FF16 /*!< SPI frame size is 16 bits */
#define SPI_FRAMESIZE_8BIT ((uint32_t)0x00000000U) /*!< SPI frame size is 8 bits */
+/* SPI NSS control mode */
#define SPI_NSS_SOFT SPI_CTL0_SWNSSEN /*!< SPI nss control by sofrware */
#define SPI_NSS_HARD ((uint32_t)0x00000000U) /*!< SPI nss control by hardware */
-#define SPI_ENDIAN_MSB ((uint32_t)0x00000000U) /*!< SPI transmit way is big endian:transmit MSB first */
-#define SPI_ENDIAN_LSB SPI_CTL0_LF /*!< SPI transmit way is little endian:transmit LSB first */
+/* SPI transmit way */
+#define SPI_ENDIAN_MSB ((uint32_t)0x00000000U) /*!< SPI transmit way is big endian: transmit MSB first */
+#define SPI_ENDIAN_LSB SPI_CTL0_LF /*!< SPI transmit way is little endian: transmit LSB first */
+/* SPI clock polarity and phase */
#define SPI_CK_PL_LOW_PH_1EDGE ((uint32_t)0x00000000U) /*!< SPI clock polarity is low level and phase is first edge */
#define SPI_CK_PL_HIGH_PH_1EDGE SPI_CTL0_CKPL /*!< SPI clock polarity is high level and phase is first edge */
#define SPI_CK_PL_LOW_PH_2EDGE SPI_CTL0_CKPH /*!< SPI clock polarity is low level and phase is second edge */
#define SPI_CK_PL_HIGH_PH_2EDGE (SPI_CTL0_CKPL|SPI_CTL0_CKPH) /*!< SPI clock polarity is high level and phase is second edge */
+/* SPI clock prescale factor */
#define CTL0_PSC(regval) (BITS(3,5)&((uint32_t)(regval)<<3))
#define SPI_PSC_2 CTL0_PSC(0) /*!< SPI clock prescale factor is 2 */
#define SPI_PSC_4 CTL0_PSC(1) /*!< SPI clock prescale factor is 4 */
@@ -167,161 +200,180 @@ typedef struct
#define SPI_PSC_128 CTL0_PSC(6) /*!< SPI clock prescale factor is 128 */
#define SPI_PSC_256 CTL0_PSC(7) /*!< SPI clock prescale factor is 256 */
-/* I2S parameter options */
-#define I2S_AUDIOSAMPLE_8K ((uint32_t)8000U) /*!< I2S audio sample rate is 8khz */
-#define I2S_AUDIOSAMPLE_11K ((uint32_t)11025U) /*!< I2S audio sample rate is 11khz */
-#define I2S_AUDIOSAMPLE_16K ((uint32_t)16000U) /*!< I2S audio sample rate is 16khz */
-#define I2S_AUDIOSAMPLE_22K ((uint32_t)22050U) /*!< I2S audio sample rate is 22khz */
-#define I2S_AUDIOSAMPLE_32K ((uint32_t)32000U) /*!< I2S audio sample rate is 32khz */
-#define I2S_AUDIOSAMPLE_44K ((uint32_t)44100U) /*!< I2S audio sample rate is 44khz */
-#define I2S_AUDIOSAMPLE_48K ((uint32_t)48000U) /*!< I2S audio sample rate is 48khz */
-#define I2S_AUDIOSAMPLE_96K ((uint32_t)96000U) /*!< I2S audio sample rate is 96khz */
-#define I2S_AUDIOSAMPLE_192K ((uint32_t)192000U) /*!< I2S audio sample rate is 192khz */
+/* I2S audio sample rate */
+#define I2S_AUDIOSAMPLE_8K ((uint32_t)8000U) /*!< I2S audio sample rate is 8KHz */
+#define I2S_AUDIOSAMPLE_11K ((uint32_t)11025U) /*!< I2S audio sample rate is 11KHz */
+#define I2S_AUDIOSAMPLE_16K ((uint32_t)16000U) /*!< I2S audio sample rate is 16KHz */
+#define I2S_AUDIOSAMPLE_22K ((uint32_t)22050U) /*!< I2S audio sample rate is 22KHz */
+#define I2S_AUDIOSAMPLE_32K ((uint32_t)32000U) /*!< I2S audio sample rate is 32KHz */
+#define I2S_AUDIOSAMPLE_44K ((uint32_t)44100U) /*!< I2S audio sample rate is 44KHz */
+#define I2S_AUDIOSAMPLE_48K ((uint32_t)48000U) /*!< I2S audio sample rate is 48KHz */
+#define I2S_AUDIOSAMPLE_96K ((uint32_t)96000U) /*!< I2S audio sample rate is 96KHz */
+#define I2S_AUDIOSAMPLE_192K ((uint32_t)192000U) /*!< I2S audio sample rate is 192KHz */
+/* I2S frame format */
#define I2SCTL_DTLEN(regval) (BITS(1,2)&((uint32_t)(regval)<<1))
#define I2S_FRAMEFORMAT_DT16B_CH16B I2SCTL_DTLEN(0) /*!< I2S data length is 16 bit and channel length is 16 bit */
#define I2S_FRAMEFORMAT_DT16B_CH32B (I2SCTL_DTLEN(0)|SPI_I2SCTL_CHLEN) /*!< I2S data length is 16 bit and channel length is 32 bit */
#define I2S_FRAMEFORMAT_DT24B_CH32B (I2SCTL_DTLEN(1)|SPI_I2SCTL_CHLEN) /*!< I2S data length is 24 bit and channel length is 32 bit */
#define I2S_FRAMEFORMAT_DT32B_CH32B (I2SCTL_DTLEN(2)|SPI_I2SCTL_CHLEN) /*!< I2S data length is 32 bit and channel length is 32 bit */
-
+
+/* I2S master clock output */
#define I2S_MCKOUT_DISABLE ((uint32_t)0x00000000U) /*!< I2S master clock output disable */
#define I2S_MCKOUT_ENABLE SPI_I2SPSC_MCKOEN /*!< I2S master clock output enable */
-
+
+/* I2S operation mode */
#define I2SCTL_I2SOPMOD(regval) (BITS(8,9)&((uint32_t)(regval)<<8))
#define I2S_MODE_SLAVETX I2SCTL_I2SOPMOD(0) /*!< I2S slave transmit mode */
#define I2S_MODE_SLAVERX I2SCTL_I2SOPMOD(1) /*!< I2S slave receive mode */
#define I2S_MODE_MASTERTX I2SCTL_I2SOPMOD(2) /*!< I2S master transmit mode */
#define I2S_MODE_MASTERRX I2SCTL_I2SOPMOD(3) /*!< I2S master receive mode */
+/* I2S standard */
#define I2SCTL_I2SSTD(regval) (BITS(4,5)&((uint32_t)(regval)<<4))
#define I2S_STD_PHILLIPS I2SCTL_I2SSTD(0) /*!< I2S phillips standard */
#define I2S_STD_MSB I2SCTL_I2SSTD(1) /*!< I2S MSB standard */
#define I2S_STD_LSB I2SCTL_I2SSTD(2) /*!< I2S LSB standard */
#define I2S_STD_PCMSHORT I2SCTL_I2SSTD(3) /*!< I2S PCM short standard */
-#define I2S_STD_PCMLONG (I2SCTL_I2SSTD(3)|SPI_I2SCTL_PCMSMOD) /*!< I2S PCM long standard */
+#define I2S_STD_PCMLONG (I2SCTL_I2SSTD(3) | SPI_I2SCTL_PCMSMOD) /*!< I2S PCM long standard */
+/* I2S clock polarity */
#define I2S_CKPL_LOW ((uint32_t)0x00000000U) /*!< I2S clock polarity low level */
#define I2S_CKPL_HIGH SPI_I2SCTL_CKPL /*!< I2S clock polarity high level */
-/* SPI dma constants definitions */
-#define SPI_DMA_TRANSMIT ((uint8_t)0x00U) /*!< SPI transmit data DMA */
-#define SPI_DMA_RECEIVE ((uint8_t)0x01U) /*!< SPI receive data DMA */
+/* SPI DMA constants definitions */
+#define SPI_DMA_TRANSMIT ((uint8_t)0x00U) /*!< SPI transmit data use DMA */
+#define SPI_DMA_RECEIVE ((uint8_t)0x01U) /*!< SPI receive data use DMA */
/* SPI CRC constants definitions */
#define SPI_CRC_TX ((uint8_t)0x00U) /*!< SPI transmit CRC value */
#define SPI_CRC_RX ((uint8_t)0x01U) /*!< SPI receive CRC value */
-/* SPI interrupt constants definitions */
+/* SPI/I2S interrupt enable/disable constants definitions */
#define SPI_I2S_INT_TBE ((uint8_t)0x00U) /*!< transmit buffer empty interrupt */
#define SPI_I2S_INT_RBNE ((uint8_t)0x01U) /*!< receive buffer not empty interrupt */
-#define SPI_I2S_INT_RXORERR ((uint8_t)0x02U) /*!< overrun interrupt */
-#define SPI_INT_CONFERR ((uint8_t)0x03U) /*!< config error interrupt */
-#define SPI_INT_CRCERR ((uint8_t)0x04U) /*!< CRC error interrupt */
-#define I2S_INT_TXURERR ((uint8_t)0x05U) /*!< underrun error interrupt */
-#define SPI_I2S_INT_ERR ((uint8_t)0x06U) /*!< error interrupt */
-#define SPI_I2S_INT_FERR ((uint8_t)0x07U) /*!< format error interrupt */
+#define SPI_I2S_INT_ERR ((uint8_t)0x02U) /*!< error interrupt */
-/* SPI flag definitions */
+/* SPI/I2S interrupt flag constants definitions */
+#define SPI_I2S_INT_FLAG_TBE ((uint8_t)0x00U) /*!< transmit buffer empty interrupt flag */
+#define SPI_I2S_INT_FLAG_RBNE ((uint8_t)0x01U) /*!< receive buffer not empty interrupt flag */
+#define SPI_I2S_INT_FLAG_RXORERR ((uint8_t)0x02U) /*!< overrun interrupt flag */
+#define SPI_INT_FLAG_CONFERR ((uint8_t)0x03U) /*!< config error interrupt flag */
+#define SPI_INT_FLAG_CRCERR ((uint8_t)0x04U) /*!< CRC error interrupt flag */
+#define I2S_INT_FLAG_TXURERR ((uint8_t)0x05U) /*!< underrun error interrupt flag */
+#define SPI_I2S_INT_FLAG_FERR ((uint8_t)0x06U) /*!< format error interrupt flag */
+
+/* SPI/I2S flag definitions */
#define SPI_FLAG_RBNE SPI_STAT_RBNE /*!< receive buffer not empty flag */
#define SPI_FLAG_TBE SPI_STAT_TBE /*!< transmit buffer empty flag */
#define SPI_FLAG_CRCERR SPI_STAT_CRCERR /*!< CRC error flag */
#define SPI_FLAG_CONFERR SPI_STAT_CONFERR /*!< mode config error flag */
-#define SPI_FLAG_RXORERR SPI_STAT_RXORERR /*!< receive overrun flag */
+#define SPI_FLAG_RXORERR SPI_STAT_RXORERR /*!< receive overrun error flag */
#define SPI_FLAG_TRANS SPI_STAT_TRANS /*!< transmit on-going flag */
-#define SPI_FLAG_FERR SPI_STAT_FERR /*!< format error interrupt flag */
+#define SPI_FLAG_FERR SPI_STAT_FERR /*!< format error flag */
#define I2S_FLAG_RBNE SPI_STAT_RBNE /*!< receive buffer not empty flag */
#define I2S_FLAG_TBE SPI_STAT_TBE /*!< transmit buffer empty flag */
-#define I2S_FLAG_CH SPI_STAT_I2SCH /*!< transmit buffer empty interrupt */
+#define I2S_FLAG_CH SPI_STAT_I2SCH /*!< channel side flag */
#define I2S_FLAG_TXURERR SPI_STAT_TXURERR /*!< underrun error flag */
-#define I2S_FLAG_RXORERR SPI_STAT_RXORERR /*!< overrun flag */
+#define I2S_FLAG_RXORERR SPI_STAT_RXORERR /*!< overrun error flag */
#define I2S_FLAG_TRANS SPI_STAT_TRANS /*!< transmit on-going flag */
-#define I2S_FLAG_FERR SPI_STAT_FERR /*!< format error interrupt flag */
+#define I2S_FLAG_FERR SPI_STAT_FERR /*!< format error flag */
/* function declarations */
-/* SPI and I2S reset */
+/* initialization functions */
+/* deinitialize SPI and I2S */
void spi_i2s_deinit(uint32_t spi_periph);
-/* SPI parameter initialization */
+/* initialize the parameters of SPI struct with the default values */
+void spi_struct_para_init(spi_parameter_struct* spi_struct);
+/* initialize SPI parameter */
void spi_init(uint32_t spi_periph,spi_parameter_struct* spi_struct);
-/* SPI enable */
+/* enable SPI */
void spi_enable(uint32_t spi_periph);
-/* SPI disable */
+/* disable SPI */
void spi_disable(uint32_t spi_periph);
-/* I2S parameter initialization */
+/* initialize I2S parameter */
void i2s_init(uint32_t spi_periph,uint32_t i2s_mode,uint32_t i2s_standard,uint32_t i2s_ckpl);
-/* I2S prescale configuration */
+/* configure I2S prescale */
void i2s_psc_config(uint32_t spi_periph,uint32_t i2s_audiosample,uint32_t i2s_frameformat,uint32_t i2s_mckout);
-/* I2S enable */
+/* enable I2S */
void i2s_enable(uint32_t spi_periph);
-/* I2S disable */
+/* disable I2S */
void i2s_disable(uint32_t spi_periph);
-/* SPI nss output enable */
+/* NSS functions */
+/* enable SPI nss output */
void spi_nss_output_enable(uint32_t spi_periph);
-/* SPI nss output disable */
+/* disable SPI nss output */
void spi_nss_output_disable(uint32_t spi_periph);
/* SPI nss pin high level in software mode */
void spi_nss_internal_high(uint32_t spi_periph);
/* SPI nss pin low level in software mode */
void spi_nss_internal_low(uint32_t spi_periph);
-/* SPI dma enable */
+/* SPI DMA functions */
+/* enable SPI DMA */
void spi_dma_enable(uint32_t spi_periph,uint8_t spi_dma);
-/* SPI dma disable */
+/* disable SPI DMA */
void spi_dma_disable(uint32_t spi_periph,uint8_t spi_dma);
+/* SPI/I2S transfer configure functions */
/* configure SPI/I2S data frame format */
void spi_i2s_data_frame_format_config(uint32_t spi_periph,uint16_t frame_format);
-/* transmit data */
+/* SPI transmit data */
void spi_i2s_data_transmit(uint32_t spi_periph,uint16_t data);
-/* receive data */
+/* SPI receive data */
uint16_t spi_i2s_data_receive(uint32_t spi_periph);
/* configure SPI bidirectional transfer direction */
void spi_bidirectional_transfer_config(uint32_t spi_periph,uint32_t transfer_direction);
-/* enable SPI interrupt */
-void spi_i2s_interrupt_enable(uint32_t spi_periph,uint8_t spi_i2s_int);
-/* disable SPI interrupt */
-void spi_i2s_interrupt_disable(uint32_t spi_periph,uint8_t spi_i2s_int);
-/* get SPI and I2S interrupt status*/
-FlagStatus spi_i2s_interrupt_flag_get(uint32_t spi_periph,uint8_t spi_i2s_int);
-/* get SPI and I2S flag status */
-FlagStatus spi_i2s_flag_get(uint32_t spi_periph,uint32_t spi_i2s_flag);
-/* clear SPI CRC error flag status */
-void spi_crc_error_clear(uint32_t spi_periph);
-
-/* SPI CRC polynomial set */
+/* SPI CRC functions */
+/* set SPI CRC polynomial */
void spi_crc_polynomial_set(uint32_t spi_periph,uint16_t crc_poly);
-/* SPI CRC polynomial get */
+/* get SPI CRC polynomial */
uint16_t spi_crc_polynomial_get(uint32_t spi_periph);
-/* SPI CRC function turn on */
+/* turn on SPI CRC function */
void spi_crc_on(uint32_t spi_periph);
-/* SPI CRC function turn off */
+/* turn off SPI CRC function */
void spi_crc_off(uint32_t spi_periph);
/* SPI next data is CRC value */
void spi_crc_next(uint32_t spi_periph);
/* get SPI CRC send value or receive value */
uint16_t spi_crc_get(uint32_t spi_periph,uint8_t spi_crc);
-/* SPI TI mode enable */
+/* SPI TI mode functions */
+/* enable SPI TI mode */
void spi_ti_mode_enable(uint32_t spi_periph);
-/* SPI TI mode disable */
+/* disable SPI TI mode */
void spi_ti_mode_disable(uint32_t spi_periph);
/* configure i2s full duplex mode */
void i2s_full_duplex_mode_config(uint32_t i2s_add_periph,uint32_t i2s_mode,uint32_t i2s_standard,uint32_t i2s_ckpl,uint32_t i2s_frameformat);
-/* quad wire SPI enable */
+/* quad wire SPI functions */
+/* enable quad wire SPI */
void qspi_enable(uint32_t spi_periph);
-/* quad wire SPI disable */
+/* disable quad wire SPI */
void qspi_disable(uint32_t spi_periph);
-/* quad wire SPI write enable */
+/* enable quad wire SPI write */
void qspi_write_enable(uint32_t spi_periph);
-/* quad wire SPI read enable */
+/* enable quad wire SPI read */
void qspi_read_enable(uint32_t spi_periph);
-/* quad wire SPI_IO2 and SPI_IO3 pin output enable */
+/* enable quad wire SPI_IO2 and SPI_IO3 pin output */
void qspi_io23_output_enable(uint32_t spi_periph);
-/* quad wire SPI_IO2 and SPI_IO3 pin output disable */
+/* disable quad wire SPI_IO2 and SPI_IO3 pin output */
void qspi_io23_output_disable(uint32_t spi_periph);
+/* flag & interrupt functions */
+/* enable SPI interrupt */
+void spi_i2s_interrupt_enable(uint32_t spi_periph,uint8_t spi_i2s_int);
+/* disable SPI interrupt */
+void spi_i2s_interrupt_disable(uint32_t spi_periph,uint8_t spi_i2s_int);
+/* get SPI and I2S interrupt status*/
+FlagStatus spi_i2s_interrupt_flag_get(uint32_t spi_periph,uint8_t spi_i2s_int);
+/* get SPI and I2S flag status */
+FlagStatus spi_i2s_flag_get(uint32_t spi_periph,uint32_t spi_i2s_flag);
+/* clear SPI CRC error flag status */
+void spi_crc_error_clear(uint32_t spi_periph);
+
#endif /* GD32F4XX_SPI_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_syscfg.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_syscfg.h
index 42ae5599c7..047910478a 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_syscfg.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_syscfg.h
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_syscfg.h
- \brief definitions for the SYSCFG
+ \file gd32f4xx_syscfg.h
+ \brief definitions for the SYSCFG
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#ifndef GD32F4XX_SYSCFG_H
@@ -85,13 +110,13 @@
#define EXTISS3 ((uint8_t)0x03U) /*!< EXTI source select GPIOx pin 12~15 */
/* EXTI source select mask bits definition */
-#define EXTI_SS_MASK BITS(0,3)
+#define EXTI_SS_MASK BITS(0,3) /*!< EXTI source select mask */
/* EXTI source select jumping step definition */
-#define EXTI_SS_JSTEP ((uint8_t)(0x04U))
+#define EXTI_SS_JSTEP ((uint8_t)(0x04U)) /*!< EXTI source select jumping step */
/* EXTI source select moving step definition */
-#define EXTI_SS_MSTEP(pin) (EXTI_SS_JSTEP*((pin)%EXTI_SS_JSTEP))
+#define EXTI_SS_MSTEP(pin) (EXTI_SS_JSTEP*((pin)%EXTI_SS_JSTEP)) /*!< EXTI source select moving step */
/* EXTI source port definitions */
#define EXTI_SOURCE_GPIOA ((uint8_t)0x00U) /*!< EXTI GPIOA configuration */
@@ -123,35 +148,33 @@
#define EXTI_SOURCE_PIN15 ((uint8_t)0x0FU) /*!< EXTI GPIO pin15 configuration */
/* ethernet PHY selection */
-#define SYSCFG_ENET_PHY_MII ((uint32_t)0x00000000U)
-#define SYSCFG_ENET_PHY_RMII ((uint32_t)0x00800000U)
+#define SYSCFG_ENET_PHY_MII ((uint32_t)0x00000000U) /*!< MII is selected for the Ethernet MAC */
+#define SYSCFG_ENET_PHY_RMII ((uint32_t)0x00800000U) /*!< RMII is selected for the Ethernet MAC */
/* I/O compensation cell enable/disable */
-#define SYSCFG_COMPENSATION_ENABLE ((uint32_t)0x00000001U)
-#define SYSCFG_COMPENSATION_DISABLE ((uint32_t)0x00000000U)
+#define SYSCFG_COMPENSATION_ENABLE ((uint32_t)0x00000001U) /*!< I/O compensation cell enable */
+#define SYSCFG_COMPENSATION_DISABLE ((uint32_t)0x00000000U) /*!< I/O compensation cell disable */
/* function declarations */
+/* initialization functions */
/* deinit syscfg module */
void syscfg_deinit(void);
+/* function configuration */
/* configure the boot mode */
void syscfg_bootmode_config(uint8_t syscfg_bootmode);
-
-/* FMC memory mapping swap */
+/* configure FMC memory mapping swap */
void syscfg_fmc_swap_config(uint32_t syscfg_fmc_swap);
-
/* configure the EXMC swap */
-void syscfg_exmc_swap_config(uint32_t syscfg_exmc_swap);
-
+void syscfg_exmc_swap_config(uint32_t syscfg_exmc_swap);
/* configure the GPIO pin as EXTI Line */
void syscfg_exti_line_config(uint8_t exti_port, uint8_t exti_pin);
-
/* configure the PHY interface for the ethernet MAC */
void syscfg_enet_phy_interface_config(uint32_t syscfg_enet_phy_interface);
-
/* configure the I/O compensation cell */
-void syscfg_compensation_config(uint32_t syscfg_compensation);
+void syscfg_compensation_config(uint32_t syscfg_compensation);
+/* interrupt & flag functions */
/* check the I/O compensation cell is ready or not */
FlagStatus syscfg_flag_get(void);
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_timer.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_timer.h
index e856ec03ac..9da6e12bdd 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_timer.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_timer.h
@@ -1,12 +1,38 @@
/*!
- \file gd32f4xx_timer.h
- \brief definitions for the TIMER
+ \file gd32f4xx_timer.h
+ \brief definitions for the TIMER
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#ifndef GD32F4XX_TIMER_H
@@ -66,8 +92,8 @@
#define TIMER_CTL0_CKDIV BITS(8,9) /*!< clock division */
/* TIMER_CTL1 */
-#define TIMER_CTL1_CCSE BIT(0) /*!< capture/compare control shadow register enable */
-#define TIMER_CTL1_CCUC BIT(2) /*!< capture/compare control shadow register update control */
+#define TIMER_CTL1_CCSE BIT(0) /*!< commutation control shadow enable */
+#define TIMER_CTL1_CCUC BIT(2) /*!< commutation control shadow register update control */
#define TIMER_CTL1_DMAS BIT(3) /*!< DMA request source selection */
#define TIMER_CTL1_MMC BITS(4,6) /*!< master mode control */
#define TIMER_CTL1_TI0S BIT(7) /*!< channel 0 trigger input selection(hall mode selection) */
@@ -87,30 +113,30 @@
#define TIMER_SMCFG_ETPSC BITS(12,13) /*!< external trigger prescaler */
#define TIMER_SMCFG_SMC1 BIT(14) /*!< part of SMC for enable external clock mode 1 */
#define TIMER_SMCFG_ETP BIT(15) /*!< external trigger polarity */
-
+
/* TIMER_DMAINTEN */
#define TIMER_DMAINTEN_UPIE BIT(0) /*!< update interrupt enable */
-#define TIMER_DMAINTEN_CH0IE BIT(1) /*!< channel 0 interrupt enable */
-#define TIMER_DMAINTEN_CH1IE BIT(2) /*!< channel 1 interrupt enable */
-#define TIMER_DMAINTEN_CH2IE BIT(3) /*!< channel 2 interrupt enable */
-#define TIMER_DMAINTEN_CH3IE BIT(4) /*!< channel 3 interrupt enable */
-#define TIMER_DMAINTEN_CMTIE BIT(5) /*!< commutation DMA request enable */
+#define TIMER_DMAINTEN_CH0IE BIT(1) /*!< channel 0 capture/compare interrupt enable */
+#define TIMER_DMAINTEN_CH1IE BIT(2) /*!< channel 1 capture/compare interrupt enable */
+#define TIMER_DMAINTEN_CH2IE BIT(3) /*!< channel 2 capture/compare interrupt enable */
+#define TIMER_DMAINTEN_CH3IE BIT(4) /*!< channel 3 capture/compare interrupt enable */
+#define TIMER_DMAINTEN_CMTIE BIT(5) /*!< commutation interrupt request enable */
#define TIMER_DMAINTEN_TRGIE BIT(6) /*!< trigger interrupt enable */
#define TIMER_DMAINTEN_BRKIE BIT(7) /*!< break interrupt enable */
#define TIMER_DMAINTEN_UPDEN BIT(8) /*!< update DMA request enable */
-#define TIMER_DMAINTEN_CH0DEN BIT(8) /*!< channel 0 DMA request enable */
+#define TIMER_DMAINTEN_CH0DEN BIT(9) /*!< channel 0 DMA request enable */
#define TIMER_DMAINTEN_CH1DEN BIT(10) /*!< channel 1 DMA request enable */
#define TIMER_DMAINTEN_CH2DEN BIT(11) /*!< channel 2 DMA request enable */
#define TIMER_DMAINTEN_CH3DEN BIT(12) /*!< channel 3 DMA request enable */
-#define TIMER_DMAINTEN_CMTDEN BIT(13) /*!< channel control update DMA request enable */
+#define TIMER_DMAINTEN_CMTDEN BIT(13) /*!< commutation DMA request enable */
#define TIMER_DMAINTEN_TRGDEN BIT(14) /*!< trigger DMA request enable */
/* TIMER_INTF */
#define TIMER_INTF_UPIF BIT(0) /*!< update interrupt flag */
-#define TIMER_INTF_CH0IF BIT(1) /*!< channel 0 interrupt flag */
-#define TIMER_INTF_CH1IF BIT(2) /*!< channel 1 interrupt flag */
-#define TIMER_INTF_CH2IF BIT(3) /*!< channel 2 interrupt flag */
-#define TIMER_INTF_CH3IF BIT(4) /*!< channel 3 interrupt flag */
+#define TIMER_INTF_CH0IF BIT(1) /*!< channel 0 capture/compare interrupt flag */
+#define TIMER_INTF_CH1IF BIT(2) /*!< channel 1 capture/compare interrupt flag */
+#define TIMER_INTF_CH2IF BIT(3) /*!< channel 2 capture/compare interrupt flag */
+#define TIMER_INTF_CH3IF BIT(4) /*!< channel 3 capture/compare interrupt flag */
#define TIMER_INTF_CMTIF BIT(5) /*!< channel commutation interrupt flag */
#define TIMER_INTF_TRGIF BIT(6) /*!< trigger interrupt flag */
#define TIMER_INTF_BRKIF BIT(7) /*!< break interrupt flag */
@@ -166,20 +192,20 @@
#define TIMER_CHCTL1_CH3CAPFLT BITS(12,15) /*!< channel 3 input capture filter control */
/* TIMER_CHCTL2 */
-#define TIMER_CHCTL2_CH0EN BIT(0) /*!< channel 0 enable */
-#define TIMER_CHCTL2_CH0P BIT(1) /*!< channel 0 polarity */
+#define TIMER_CHCTL2_CH0EN BIT(0) /*!< channel 0 capture/compare function enable */
+#define TIMER_CHCTL2_CH0P BIT(1) /*!< channel 0 capture/compare function polarity */
#define TIMER_CHCTL2_CH0NEN BIT(2) /*!< channel 0 complementary output enable */
#define TIMER_CHCTL2_CH0NP BIT(3) /*!< channel 0 complementary output polarity */
-#define TIMER_CHCTL2_CH1EN BIT(4) /*!< channel 1 enable */
-#define TIMER_CHCTL2_CH1P BIT(5) /*!< channel 1 polarity */
+#define TIMER_CHCTL2_CH1EN BIT(4) /*!< channel 1 capture/compare function enable */
+#define TIMER_CHCTL2_CH1P BIT(5) /*!< channel 1 capture/compare function polarity */
#define TIMER_CHCTL2_CH1NEN BIT(6) /*!< channel 1 complementary output enable */
#define TIMER_CHCTL2_CH1NP BIT(7) /*!< channel 1 complementary output polarity */
-#define TIMER_CHCTL2_CH2EN BIT(8) /*!< channel 2 enable */
-#define TIMER_CHCTL2_CH2P BIT(9) /*!< channel 2 polarity */
+#define TIMER_CHCTL2_CH2EN BIT(8) /*!< channel 2 capture/compare function enable */
+#define TIMER_CHCTL2_CH2P BIT(9) /*!< channel 2 capture/compare function polarity */
#define TIMER_CHCTL2_CH2NEN BIT(10) /*!< channel 2 complementary output enable */
#define TIMER_CHCTL2_CH2NP BIT(11) /*!< channel 2 complementary output polarity */
-#define TIMER_CHCTL2_CH3EN BIT(12) /*!< channel 3 enable */
-#define TIMER_CHCTL2_CH3P BIT(13) /*!< channel 3 polarity */
+#define TIMER_CHCTL2_CH3EN BIT(12) /*!< channel 3 capture/compare function enable */
+#define TIMER_CHCTL2_CH3P BIT(13) /*!< channel 3 capture/compare function polarity */
/* TIMER_CNT */
#define TIMER_CNT_CNT16 BITS(0,15) /*!< 16 bit timer counter */
@@ -200,16 +226,16 @@
#define TIMER_CH0CV_CH0VAL32 BITS(0,31) /*!< 32 bit(TIMER1,TIMER4) capture/compare value of channel 0 */
/* TIMER_CH1CV */
-#define TIMER_CH1CV_CH0VAL16 BITS(0,15) /*!< 16 bit capture/compare value of channel 1 */
-#define TIMER_CH1CV_CH0VAL32 BITS(0,31) /*!< 32 bit(TIMER1,TIMER4) capture/compare value of channel 1 */
+#define TIMER_CH1CV_CH1VAL16 BITS(0,15) /*!< 16 bit capture/compare value of channel 1 */
+#define TIMER_CH1CV_CH1VAL32 BITS(0,31) /*!< 32 bit(TIMER1,TIMER4) capture/compare value of channel 1 */
/* TIMER_CH2CV */
-#define TIMER_CH2CV_CH0VAL16 BITS(0,15) /*!< 16 bit capture/compare value of channel 2 */
-#define TIMER_CH2CV_CH0VAL32 BITS(0,31) /*!< 32 bit(TIMER1,TIMER4) capture/compare value of channel 2 */
+#define TIMER_CH2CV_CH2VAL16 BITS(0,15) /*!< 16 bit capture/compare value of channel 2 */
+#define TIMER_CH2CV_CH2VAL32 BITS(0,31) /*!< 32 bit(TIMER1,TIMER4) capture/compare value of channel 2 */
/* TIMER_CH3CV */
-#define TIMER_CH3CV_CH0VAL16 BITS(0,15) /*!< 16 bit capture/compare value of channel 3 */
-#define TIMER_CH3CV_CH0VAL32 BITS(0,31) /*!< 32 bit(TIMER1,TIMER4) capture/compare value of channel 3 */
+#define TIMER_CH3CV_CH3VAL16 BITS(0,15) /*!< 16 bit capture/compare value of channel 3 */
+#define TIMER_CH3CV_CH3VAL32 BITS(0,31) /*!< 32 bit(TIMER1,TIMER4) capture/compare value of channel 3 */
/* TIMER_CCHP */
#define TIMER_CCHP_DTCFG BITS(0,7) /*!< dead time configure */
@@ -240,31 +266,31 @@
/* constants definitions */
/* TIMER init parameter struct definitions*/
typedef struct
-{
+{
uint16_t prescaler; /*!< prescaler value */
uint16_t alignedmode; /*!< aligned mode */
uint16_t counterdirection; /*!< counter direction */
- uint32_t period; /*!< period value */
uint16_t clockdivision; /*!< clock division value */
+ uint32_t period; /*!< period value */
uint8_t repetitioncounter; /*!< the counter repetition value */
}timer_parameter_struct;
/* break parameter struct definitions*/
typedef struct
-{
- uint16_t runoffstate; /*!< run mode off-state */
- uint32_t ideloffstate; /*!< idle mode off-state */
- uint16_t deadtime; /*!< delay time between the switching off and on of the outputs */
+{
+ uint16_t runoffstate; /*!< run mode off-state */
+ uint16_t ideloffstate; /*!< idle mode off-state */
+ uint16_t deadtime; /*!< dead time */
uint16_t breakpolarity; /*!< break polarity */
- uint16_t outputautostate; /*!< output automatic enable */
- uint16_t protectmode; /*!< complementary register protect control */
- uint16_t breakstate; /*!< break enable */
+ uint16_t outputautostate; /*!< output automatic enable */
+ uint16_t protectmode; /*!< complementary register protect control */
+ uint16_t breakstate; /*!< break enable */
}timer_break_parameter_struct;
/* channel output parameter struct definitions */
typedef struct
-{
- uint32_t outputstate; /*!< channel output state */
+{
+ uint16_t outputstate; /*!< channel output state */
uint16_t outputnstate; /*!< channel complementary output state */
uint16_t ocpolarity; /*!< channel output polarity */
uint16_t ocnpolarity; /*!< channel complementary output polarity */
@@ -274,47 +300,59 @@ typedef struct
/* channel input parameter struct definitions */
typedef struct
-{
+{
uint16_t icpolarity; /*!< channel input polarity */
uint16_t icselection; /*!< channel input mode selection */
uint16_t icprescaler; /*!< channel input capture prescaler */
uint16_t icfilter; /*!< channel input capture filter control */
}timer_ic_parameter_struct;
-/* TIMER interrupt source */
-#define TIMER_INT_UP ((uint32_t)0x00000001U) /*!< update interrupt */
-#define TIMER_INT_CH0 ((uint32_t)0x00000002U) /*!< channel 0 interrupt */
-#define TIMER_INT_CH1 ((uint32_t)0x00000004U) /*!< channel 1 interrupt */
-#define TIMER_INT_CH2 ((uint32_t)0x00000008U) /*!< channel 2 interrupt */
-#define TIMER_INT_CH3 ((uint32_t)0x00000010U) /*!< channel 3 interrupt */
-#define TIMER_INT_CMT ((uint32_t)0x00000020U) /*!< channel commutation interrupt flag */
-#define TIMER_INT_TRG ((uint32_t)0x00000040U) /*!< trigger interrupt */
-#define TIMER_INT_BRK ((uint32_t)0x00000080U) /*!< break interrupt */
+/* TIMER interrupt enable or disable */
+#define TIMER_INT_UP TIMER_DMAINTEN_UPIE /*!< update interrupt */
+#define TIMER_INT_CH0 TIMER_DMAINTEN_CH0IE /*!< channel 0 interrupt */
+#define TIMER_INT_CH1 TIMER_DMAINTEN_CH1IE /*!< channel 1 interrupt */
+#define TIMER_INT_CH2 TIMER_DMAINTEN_CH2IE /*!< channel 2 interrupt */
+#define TIMER_INT_CH3 TIMER_DMAINTEN_CH3IE /*!< channel 3 interrupt */
+#define TIMER_INT_CMT TIMER_DMAINTEN_CMTIE /*!< channel commutation interrupt flag */
+#define TIMER_INT_TRG TIMER_DMAINTEN_TRGIE /*!< trigger interrupt */
+#define TIMER_INT_BRK TIMER_DMAINTEN_BRKIE /*!< break interrupt */
/* TIMER flag */
-#define TIMER_FLAG_UP ((uint32_t)0x00000001U) /*!< update flag */
-#define TIMER_FLAG_CH0 ((uint32_t)0x00000002U) /*!< channel 0 flag */
-#define TIMER_FLAG_CH1 ((uint32_t)0x00000004U) /*!< channel 1 flag */
-#define TIMER_FLAG_CH2 ((uint32_t)0x00000008U) /*!< channel 2 flag */
-#define TIMER_FLAG_CH3 ((uint32_t)0x00000010U) /*!< channel 3 flag */
-#define TIMER_FLAG_CMT ((uint32_t)0x00000020U) /*!< channel control update flag */
-#define TIMER_FLAG_TRG ((uint32_t)0x00000040U) /*!< trigger flag */
-#define TIMER_FLAG_BRK ((uint32_t)0x00000080U) /*!< break flag */
-#define TIMER_FLAG_CH0OF ((uint32_t)0x00000200U) /*!< channel 0 overcapture flag */
-#define TIMER_FLAG_CH1OF ((uint32_t)0x00000400U) /*!< channel 1 overcapture flag */
-#define TIMER_FLAG_CH2OF ((uint32_t)0x00000800U) /*!< channel 2 overcapture flag */
-#define TIMER_FLAG_CH3OF ((uint32_t)0x00001000U) /*!< channel 3 overcapture flag */
+#define TIMER_FLAG_UP TIMER_INTF_UPIF /*!< update flag */
+#define TIMER_FLAG_CH0 TIMER_INTF_CH0IF /*!< channel 0 flag */
+#define TIMER_FLAG_CH1 TIMER_INTF_CH1IF /*!< channel 1 flag */
+#define TIMER_FLAG_CH2 TIMER_INTF_CH2IF /*!< channel 2 flag */
+#define TIMER_FLAG_CH3 TIMER_INTF_CH3IF /*!< channel 3 flag */
+#define TIMER_FLAG_CMT TIMER_INTF_CMTIF /*!< channel commutation flag */
+#define TIMER_FLAG_TRG TIMER_INTF_TRGIF /*!< trigger flag */
+#define TIMER_FLAG_BRK TIMER_INTF_BRKIF /*!< break flag */
+#define TIMER_FLAG_CH0O TIMER_INTF_CH0OF /*!< channel 0 overcapture flag */
+#define TIMER_FLAG_CH1O TIMER_INTF_CH1OF /*!< channel 1 overcapture flag */
+#define TIMER_FLAG_CH2O TIMER_INTF_CH2OF /*!< channel 2 overcapture flag */
+#define TIMER_FLAG_CH3O TIMER_INTF_CH3OF /*!< channel 3 overcapture flag */
+
+/* TIMER interrupt flag */
+#define TIMER_INT_FLAG_UP TIMER_INTF_UPIF /*!< update interrupt flag */
+#define TIMER_INT_FLAG_CH0 TIMER_INTF_CH0IF /*!< channel 0 interrupt flag */
+#define TIMER_INT_FLAG_CH1 TIMER_INTF_CH1IF /*!< channel 1 interrupt flag */
+#define TIMER_INT_FLAG_CH2 TIMER_INTF_CH2IF /*!< channel 2 interrupt flag */
+#define TIMER_INT_FLAG_CH3 TIMER_INTF_CH3IF /*!< channel 3 interrupt flag */
+#define TIMER_INT_FLAG_CMT TIMER_INTF_CMTIF /*!< channel commutation interrupt flag */
+#define TIMER_INT_FLAG_TRG TIMER_INTF_TRGIF /*!< trigger interrupt flag */
+#define TIMER_INT_FLAG_BRK TIMER_INTF_BRKIF
+
+
/* TIMER DMA source enable */
-#define TIMER_DMA_UPD ((uint16_t)0x0100U) /*!< update DMA enable */
-#define TIMER_DMA_CH0D ((uint16_t)0x0200U) /*!< channel 0 DMA enable */
-#define TIMER_DMA_CH1D ((uint16_t)0x0400U) /*!< channel 1 DMA enable */
-#define TIMER_DMA_CH2D ((uint16_t)0x0800U) /*!< channel 2 DMA enable */
-#define TIMER_DMA_CH3D ((uint16_t)0x1000U) /*!< channel 3 DMA enable */
-#define TIMER_DMA_CMTD ((uint16_t)0x2000U) /*!< commutation DMA request enable */
-#define TIMER_DMA_TRGD ((uint16_t)0x4000U) /*!< trigger DMA enable */
+#define TIMER_DMA_UPD ((uint16_t)TIMER_DMAINTEN_UPDEN) /*!< update DMA enable */
+#define TIMER_DMA_CH0D ((uint16_t)TIMER_DMAINTEN_CH0DEN) /*!< channel 0 DMA enable */
+#define TIMER_DMA_CH1D ((uint16_t)TIMER_DMAINTEN_CH1DEN) /*!< channel 1 DMA enable */
+#define TIMER_DMA_CH2D ((uint16_t)TIMER_DMAINTEN_CH2DEN) /*!< channel 2 DMA enable */
+#define TIMER_DMA_CH3D ((uint16_t)TIMER_DMAINTEN_CH3DEN) /*!< channel 3 DMA enable */
+#define TIMER_DMA_CMTD ((uint16_t)TIMER_DMAINTEN_CMTDEN) /*!< commutation DMA request enable */
+#define TIMER_DMA_TRGD ((uint16_t)TIMER_DMAINTEN_TRGDEN) /*!< trigger DMA enable */
-/* channel DMA request source selection */
+/* channel DMA request source selection */
#define TIMER_DMAREQUEST_UPDATEEVENT ((uint8_t)0x00U) /*!< DMA request of channel y is sent when update event occurs */
#define TIMER_DMAREQUEST_CHANNELEVENT ((uint8_t)0x01U) /*!< DMA request of channel y is sent when channel y event occurs */
@@ -380,12 +418,12 @@ typedef struct
#define TIMER_COUNTER_CENTER_BOTH CTL0_CAM(3) /*!< center-aligned and counting up/down assert mode */
/* TIMER prescaler reload mode */
-#define TIMER_PSC_RELOAD_NOW ((uint8_t)0x00U) /*!< the prescaler is loaded right now */
-#define TIMER_PSC_RELOAD_UPDATE ((uint8_t)0x01U) /*!< the prescaler is loaded at the next update event */
+#define TIMER_PSC_RELOAD_NOW ((uint32_t)0x00000000U) /*!< the prescaler is loaded right now */
+#define TIMER_PSC_RELOAD_UPDATE ((uint32_t)0x00000001U) /*!< the prescaler is loaded at the next update event */
/* count direction */
#define TIMER_COUNTER_UP ((uint16_t)0x0000U) /*!< counter up direction */
-#define TIMER_COUNTER_DOWN ((uint16_t)0x0010U) /*!< counter down direction */
+#define TIMER_COUNTER_DOWN ((uint16_t)TIMER_CTL0_DIR) /*!< counter down direction */
/* specify division ratio between TIMER clock and dead-time and sampling clock */
#define CTL0_CKDIV(regval) ((uint16_t)(BITS(8, 9) & ((uint32_t)(regval) << 8U)))
@@ -394,27 +432,27 @@ typedef struct
#define TIMER_CKDIV_DIV4 CTL0_CKDIV(2) /*!< clock division value is 4, fDTS= fTIMER_CK/4 */
/* single pulse mode */
-#define TIMER_SP_MODE_SINGLE ((uint8_t)0x00U) /*!< single pulse mode */
-#define TIMER_SP_MODE_REPETITIVE ((uint8_t)0x01U) /*!< repetitive pulse mode */
+#define TIMER_SP_MODE_SINGLE ((uint32_t)0x00000000U) /*!< single pulse mode */
+#define TIMER_SP_MODE_REPETITIVE ((uint32_t)0x00000001U) /*!< repetitive pulse mode */
/* update source */
-#define TIMER_UPDATE_SRC_REGULAR ((uint8_t)0x00U) /*!< update generate only by counter overflow/underflow */
-#define TIMER_UPDATE_SRC_GLOBAL ((uint8_t)0x01U) /*!< update generate by setting of UPG bit or the counter overflow/underflow,or the slave mode controller trigger */
+#define TIMER_UPDATE_SRC_REGULAR ((uint32_t)0x00000000U) /*!< update generate only by counter overflow/underflow */
+#define TIMER_UPDATE_SRC_GLOBAL ((uint32_t)0x00000001U) /*!< update generate by setting of UPG bit or the counter overflow/underflow,or the slave mode controller trigger */
/* run mode off-state configure */
-#define TIMER_ROS_STATE_ENABLE ((uint32_t)0x00000800U) /*!< when POEN bit is set, the channel output signals (CHx_O/CHx_ON) are enabled, with relationship to CHxEN/CHxNEN bits */
-#define TIMER_ROS_STATE_DISABLE ((uint32_t)0x00000000U) /*!< when POEN bit is set, the channel output signals (CHx_O/CHx_ON) are disabled */
+#define TIMER_ROS_STATE_ENABLE ((uint16_t)TIMER_CCHP_ROS) /*!< when POEN bit is set, the channel output signals (CHx_O/CHx_ON) are enabled, with relationship to CHxEN/CHxNEN bits */
+#define TIMER_ROS_STATE_DISABLE ((uint16_t)0x0000U) /*!< when POEN bit is set, the channel output signals (CHx_O/CHx_ON) are disabled */
-/* idle mode off-state configure */
-#define TIMER_IOS_STATE_ENABLE ((uint16_t)0x0400U) /*!< when POEN bit is reset, he channel output signals (CHx_O/CHx_ON) are enabled, with relationship to CHxEN/CHxNEN bits */
+/* idle mode off-state configure */
+#define TIMER_IOS_STATE_ENABLE ((uint16_t)TIMER_CCHP_IOS) /*!< when POEN bit is reset, the channel output signals (CHx_O/CHx_ON) are enabled, with relationship to CHxEN/CHxNEN bits */
#define TIMER_IOS_STATE_DISABLE ((uint16_t)0x0000U) /*!< when POEN bit is reset, the channel output signals (CHx_O/CHx_ON) are disabled */
/* break input polarity */
#define TIMER_BREAK_POLARITY_LOW ((uint16_t)0x0000U) /*!< break input polarity is low */
-#define TIMER_BREAK_POLARITY_HIGH ((uint16_t)0x2000U) /*!< break input polarity is high */
+#define TIMER_BREAK_POLARITY_HIGH ((uint16_t)TIMER_CCHP_BRKP) /*!< break input polarity is high */
/* output automatic enable */
-#define TIMER_OUTAUTO_ENABLE ((uint16_t)0x4000U) /*!< output automatic enable */
+#define TIMER_OUTAUTO_ENABLE ((uint16_t)TIMER_CCHP_OAEN) /*!< output automatic enable */
#define TIMER_OUTAUTO_DISABLE ((uint16_t)0x0000U) /*!< output automatic disable */
/* complementary register protect control */
@@ -425,10 +463,10 @@ typedef struct
#define TIMER_CCHP_PROT_2 CCHP_PROT(3) /*!< PROT mode 2 */
/* break input enable */
-#define TIMER_BREAK_ENABLE ((uint16_t)0x1000U) /*!< break input enable */
+#define TIMER_BREAK_ENABLE ((uint16_t)TIMER_CCHP_BRKEN) /*!< break input enable */
#define TIMER_BREAK_DISABLE ((uint16_t)0x0000U) /*!< break input disable */
-/* TIMER channel y(y=0,1,2,3) */
+/* TIMER channel n(n=0,1,2,3) */
#define TIMER_CH_0 ((uint16_t)0x0000U) /*!< TIMER channel 0(TIMERx(x=0..4,7..13)) */
#define TIMER_CH_1 ((uint16_t)0x0001U) /*!< TIMER channel 1(TIMERx(x=0..4,7,8,11)) */
#define TIMER_CH_2 ((uint16_t)0x0002U) /*!< TIMER channel 2(TIMERx(x=0..4,7)) */
@@ -450,11 +488,11 @@ typedef struct
#define TIMER_OCN_POLARITY_HIGH ((uint16_t)0x0000U) /*!< channel complementary output polarity is high */
#define TIMER_OCN_POLARITY_LOW ((uint16_t)0x0008U) /*!< channel complementary output polarity is low */
-/* idle state of channel output */
+/* idle state of channel output */
#define TIMER_OC_IDLE_STATE_HIGH ((uint16_t)0x0100) /*!< idle state of channel output is high */
#define TIMER_OC_IDLE_STATE_LOW ((uint16_t)0x0000) /*!< idle state of channel output is low */
-/* idle state of channel complementary output */
+/* idle state of channel complementary output */
#define TIMER_OCN_IDLE_STATE_HIGH ((uint16_t)0x0200U) /*!< idle state of channel complementary output is high */
#define TIMER_OCN_IDLE_STATE_LOW ((uint16_t)0x0000U) /*!< idle state of channel complementary output is low */
@@ -476,20 +514,20 @@ typedef struct
#define TIMER_OC_FAST_ENABLE ((uint16_t)0x0004) /*!< channel output fast function enable */
#define TIMER_OC_FAST_DISABLE ((uint16_t)0x0000) /*!< channel output fast function disable */
-/* channel output compare clear enable. */
+/* channel output compare clear enable */
#define TIMER_OC_CLEAR_ENABLE ((uint16_t)0x0080U) /*!< channel output clear function enable */
#define TIMER_OC_CLEAR_DISABLE ((uint16_t)0x0000U) /*!< channel output clear function disable */
-/* channel control shadow register update control */
-#define TIMER_UPDATECTL_CCU ((uint8_t)0x00U) /*!< the shadow registers update by when CMTG bit is set */
-#define TIMER_UPDATECTL_CCUTRI ((uint8_t)0x01U) /*!< the shadow registers update by when CMTG bit is set or an rising edge of TRGI occurs */
+/* channel control shadow register update control */
+#define TIMER_UPDATECTL_CCU ((uint32_t)0x00000000U) /*!< the shadow registers are updated when CMTG bit is set */
+#define TIMER_UPDATECTL_CCUTRI ((uint32_t)0x00000001U) /*!< the shadow registers update by when CMTG bit is set or an rising edge of TRGI occurs */
/* channel input capture polarity */
#define TIMER_IC_POLARITY_RISING ((uint16_t)0x0000U) /*!< input capture rising edge */
#define TIMER_IC_POLARITY_FALLING ((uint16_t)0x0002U) /*!< input capture falling edge */
#define TIMER_IC_POLARITY_BOTH_EDGE ((uint16_t)0x000AU) /*!< input capture both edge */
-/* timer input capture selection */
+/* TIMER input capture selection */
#define TIMER_IC_SELECTION_DIRECTTI ((uint16_t)0x0001U) /*!< channel y is configured as input and icy is mapped on CIy */
#define TIMER_IC_SELECTION_INDIRECTTI ((uint16_t)0x0002U) /*!< channel y is configured as input and icy is mapped on opposite input */
#define TIMER_IC_SELECTION_ITS ((uint16_t)0x0003U) /*!< channel y is configured as input and icy is mapped on ITS */
@@ -502,28 +540,28 @@ typedef struct
/* trigger selection */
#define SMCFG_TRGSEL(regval) (BITS(4, 6) & ((uint32_t)(regval) << 4U))
-#define TIMER_SMCFG_TRGSEL_ITI0 SMCFG_TRGSEL(0) /*!< internal trigger 0 */
-#define TIMER_SMCFG_TRGSEL_ITI1 SMCFG_TRGSEL(1) /*!< internal trigger 1 */
-#define TIMER_SMCFG_TRGSEL_ITI2 SMCFG_TRGSEL(2) /*!< internal trigger 2 */
-#define TIMER_SMCFG_TRGSEL_ITI3 SMCFG_TRGSEL(3) /*!< internal trigger 3 */
-#define TIMER_SMCFG_TRGSEL_CI0F_ED SMCFG_TRGSEL(4) /*!< TI0 Edge Detector */
-#define TIMER_SMCFG_TRGSEL_CI0FE0 SMCFG_TRGSEL(5) /*!< filtered TIMER input 0 */
-#define TIMER_SMCFG_TRGSEL_CI1FE1 SMCFG_TRGSEL(6) /*!< filtered TIMER input 1 */
-#define TIMER_SMCFG_TRGSEL_ETIFP SMCFG_TRGSEL(7) /*!< external trigger */
+#define TIMER_SMCFG_TRGSEL_ITI0 SMCFG_TRGSEL(0) /*!< internal trigger 0 */
+#define TIMER_SMCFG_TRGSEL_ITI1 SMCFG_TRGSEL(1) /*!< internal trigger 1 */
+#define TIMER_SMCFG_TRGSEL_ITI2 SMCFG_TRGSEL(2) /*!< internal trigger 2 */
+#define TIMER_SMCFG_TRGSEL_ITI3 SMCFG_TRGSEL(3) /*!< internal trigger 3 */
+#define TIMER_SMCFG_TRGSEL_CI0F_ED SMCFG_TRGSEL(4) /*!< TI0 Edge Detector */
+#define TIMER_SMCFG_TRGSEL_CI0FE0 SMCFG_TRGSEL(5) /*!< filtered TIMER input 0 */
+#define TIMER_SMCFG_TRGSEL_CI1FE1 SMCFG_TRGSEL(6) /*!< filtered TIMER input 1 */
+#define TIMER_SMCFG_TRGSEL_ETIFP SMCFG_TRGSEL(7) /*!< external trigger */
/* master mode control */
#define CTL1_MMC(regval) (BITS(4, 6) & ((uint32_t)(regval) << 4U))
#define TIMER_TRI_OUT_SRC_RESET CTL1_MMC(0) /*!< the UPG bit as trigger output */
#define TIMER_TRI_OUT_SRC_ENABLE CTL1_MMC(1) /*!< the counter enable signal TIMER_CTL0_CEN as trigger output */
#define TIMER_TRI_OUT_SRC_UPDATE CTL1_MMC(2) /*!< update event as trigger output */
-#define TIMER_TRI_OUT_SRC_CC0 CTL1_MMC(3) /*!< a capture or a compare match occurred in channal0 as trigger output TRGO */
+#define TIMER_TRI_OUT_SRC_CH0 CTL1_MMC(3) /*!< a capture or a compare match occurred in channal0 as trigger output TRGO */
#define TIMER_TRI_OUT_SRC_O0CPRE CTL1_MMC(4) /*!< O0CPRE as trigger output */
#define TIMER_TRI_OUT_SRC_O1CPRE CTL1_MMC(5) /*!< O1CPRE as trigger output */
#define TIMER_TRI_OUT_SRC_O2CPRE CTL1_MMC(6) /*!< O2CPRE as trigger output */
#define TIMER_TRI_OUT_SRC_O3CPRE CTL1_MMC(7) /*!< O3CPRE as trigger output */
/* slave mode control */
-#define SMCFG_SMC(regval) (BITS(0, 2) & ((uint32_t)(regval) << 0U))
+#define SMCFG_SMC(regval) (BITS(0, 2) & ((uint32_t)(regval) << 0U))
#define TIMER_SLAVE_MODE_DISABLE SMCFG_SMC(0) /*!< slave mode disable */
#define TIMER_ENCODER_MODE0 SMCFG_SMC(1) /*!< encoder mode 0 */
#define TIMER_ENCODER_MODE1 SMCFG_SMC(2) /*!< encoder mode 1 */
@@ -533,9 +571,9 @@ typedef struct
#define TIMER_SLAVE_MODE_EVENT SMCFG_SMC(6) /*!< event mode */
#define TIMER_SLAVE_MODE_EXTERNAL0 SMCFG_SMC(7) /*!< external clock mode 0 */
-/* master slave mode selection */
-#define TIMER_MASTER_SLAVE_MODE_ENABLE ((uint8_t)0x00U) /*!< master slave mode enable */
-#define TIMER_MASTER_SLAVE_MODE_DISABLE ((uint8_t)0x01U) /*!< master slave mode disable */
+/* master slave mode selection */
+#define TIMER_MASTER_SLAVE_MODE_ENABLE ((uint32_t)0x00000000U) /*!< master slave mode enable */
+#define TIMER_MASTER_SLAVE_MODE_DISABLE ((uint32_t)0x00000001U) /*!< master slave mode disable */
/* external trigger prescaler */
#define SMCFG_ETPSC(regval) (BITS(12, 13) & ((uint32_t)(regval) << 12U))
@@ -548,19 +586,19 @@ typedef struct
#define TIMER_ETP_FALLING TIMER_SMCFG_ETP /*!< active low or falling edge active */
#define TIMER_ETP_RISING ((uint32_t)0x00000000U) /*!< active high or rising edge active */
-/* channel 0 trigger input selection */
-#define TIMER_HALLINTERFACE_ENABLE ((uint8_t)0x00U) /*!< TIMER hall sensor mode enable */
-#define TIMER_HALLINTERFACE_DISABLE ((uint8_t)0x01U) /*!< TIMER hall sensor mode disable */
+/* channel 0 trigger input selection */
+#define TIMER_HALLINTERFACE_ENABLE ((uint32_t)0x00000000U) /*!< TIMER hall sensor mode enable */
+#define TIMER_HALLINTERFACE_DISABLE ((uint32_t)0x00000001U) /*!< TIMER hall sensor mode disable */
/* timer1 internal trigger input1 remap */
-#define TIMER1_IRMP(regval) (BITS(10, 11) & ((uint32_t)(regval) << 10U))
+#define TIMER1_IRMP(regval) (BITS(10, 11) & ((uint32_t)(regval) << 10U))
#define TIMER1_ITI1_RMP_TIMER7_TRGO TIMER1_IRMP(0) /*!< timer1 internal trigger input 1 remap to TIMER7_TRGO */
#define TIMER1_ITI1_RMP_ETHERNET_PTP TIMER1_IRMP(1) /*!< timer1 internal trigger input 1 remap to ethernet PTP */
#define TIMER1_ITI1_RMP_USB_FS_SOF TIMER1_IRMP(2) /*!< timer1 internal trigger input 1 remap to USB FS SOF */
#define TIMER1_ITI1_RMP_USB_HS_SOF TIMER1_IRMP(3) /*!< timer1 internal trigger input 1 remap to USB HS SOF */
/* timer4 channel 3 input remap */
-#define TIMER4_IRMP(regval) (BITS(6, 7) & ((uint32_t)(regval) << 6U))
+#define TIMER4_IRMP(regval) (BITS(6, 7) & ((uint32_t)(regval) << 6U))
#define TIMER4_CI3_RMP_GPIO TIMER4_IRMP(0) /*!< timer4 channel 3 input remap to GPIO pin */
#define TIMER4_CI3_RMP_IRC32K TIMER4_IRMP(1) /*!< timer4 channel 3 input remap to IRC32K */
#define TIMER4_CI3_RMP_LXTAL TIMER4_IRMP(2) /*!< timer4 channel 3 input remap to LXTAL */
@@ -572,19 +610,21 @@ typedef struct
#define TIMER10_ITI1_RMP_RTC_HXTAL_DIV TIMER10_IRMP(2) /*!< timer10 internal trigger input1 remap HXTAL _DIV(clock used for RTC which is HXTAL clock divided by RTCDIV bits in RCU_CFG0 register) */
/* timerx(x=0,1,2,13,14,15,16) write cc register selection */
-#define TIMER_CCSEL_DISABLE ((uint16_t)0x0000U) /*!< write CC register selection disable */
-#define TIMER_CCSEL_ENABLE ((uint16_t)0x0002U) /*!< write CC register selection enable */
+#define TIMER_CHVSEL_ENABLE ((uint16_t)0x0002U) /*!< write CHxVAL register selection enable */
+#define TIMER_CHVSEL_DISABLE ((uint16_t)0x0000U) /*!< write CHxVAL register selection disable */
/* the output value selection */
-#define TIMER_OUTSEL_DISABLE ((uint16_t)0x0000U) /*!< output value selection disable */
#define TIMER_OUTSEL_ENABLE ((uint16_t)0x0001U) /*!< output value selection enable */
+#define TIMER_OUTSEL_DISABLE ((uint16_t)0x0000U) /*!< output value selection disable */
/* function declarations */
/* TIMER timebase*/
/* deinit a TIMER */
void timer_deinit(uint32_t timer_periph);
+/* initialize TIMER init parameter struct */
+void timer_struct_para_init(timer_parameter_struct* initpara);
/* initialize TIMER counter */
-void timer_init(uint32_t timer_periph, timer_parameter_struct* timer_initpara);
+void timer_init(uint32_t timer_periph, timer_parameter_struct* initpara);
/* enable a TIMER */
void timer_enable(uint32_t timer_periph);
/* disable a TIMER */
@@ -598,57 +638,59 @@ void timer_update_event_enable(uint32_t timer_periph);
/* disable the update event */
void timer_update_event_disable(uint32_t timer_periph);
/* set TIMER counter alignment mode */
-void timer_counter_alignment(uint32_t timer_periph,uint16_t timer_aligned);
+void timer_counter_alignment(uint32_t timer_periph, uint16_t aligned);
/* set TIMER counter up direction */
void timer_counter_up_direction(uint32_t timer_periph);
/* set TIMER counter down direction */
void timer_counter_down_direction(uint32_t timer_periph);
/* configure TIMER prescaler */
-void timer_prescaler_config(uint32_t timer_periph,uint16_t timer_prescaler,uint8_t timer_pscreload);
+void timer_prescaler_config(uint32_t timer_periph, uint16_t prescaler, uint8_t pscreload);
/* configure TIMER repetition register value */
-void timer_repetition_value_config(uint32_t timer_periph,uint16_t timer_repetition);
+void timer_repetition_value_config(uint32_t timer_periph, uint16_t repetition);
/* configure TIMER autoreload register value */
-void timer_autoreload_value_config(uint32_t timer_periph,uint32_t timer_autoreload);
+void timer_autoreload_value_config(uint32_t timer_periph,uint32_t autoreload);
/* configure TIMER counter register value */
-void timer_counter_value_config(uint32_t timer_periph , uint32_t timer_counter);
+void timer_counter_value_config(uint32_t timer_periph , uint32_t counter);
/* read TIMER counter value */
uint32_t timer_counter_read(uint32_t timer_periph);
/* read TIMER prescaler value */
uint16_t timer_prescaler_read(uint32_t timer_periph);
/* configure TIMER single pulse mode */
-void timer_single_pulse_mode_config(uint32_t timer_periph,uint8_t timer_spmode);
+void timer_single_pulse_mode_config(uint32_t timer_periph, uint32_t spmode);
/* configure TIMER update source */
-void timer_update_source_config(uint32_t timer_periph,uint8_t timer_update);
+void timer_update_source_config(uint32_t timer_periph, uint32_t update);
/* TIMER interrupt and flag*/
/* enable the TIMER interrupt */
-void timer_interrupt_enable(uint32_t timer_periph,uint32_t timer_interrupt);
+void timer_interrupt_enable(uint32_t timer_periph, uint32_t interrupt);
/* disable the TIMER interrupt */
-void timer_interrupt_disable(uint32_t timer_periph,uint32_t timer_interrupt);
+void timer_interrupt_disable(uint32_t timer_periph, uint32_t interrupt);
/* get timer interrupt flag */
-FlagStatus timer_interrupt_flag_get(uint32_t timer_periph,uint32_t timer_interrupt);
+FlagStatus timer_interrupt_flag_get(uint32_t timer_periph, uint32_t interrupt);
/* clear TIMER interrupt flag */
-void timer_interrupt_flag_clear(uint32_t timer_periph,uint32_t timer_interrupt);
+void timer_interrupt_flag_clear(uint32_t timer_periph, uint32_t interrupt);
/* get TIMER flags */
-FlagStatus timer_flag_get(uint32_t timer_periph , uint32_t timer_flag);
+FlagStatus timer_flag_get(uint32_t timer_periph, uint32_t flag);
/* clear TIMER flags */
-void timer_flag_clear(uint32_t timer_periph , uint32_t timer_flag);
+void timer_flag_clear(uint32_t timer_periph, uint32_t flag);
/* timer DMA and event*/
/* enable the TIMER DMA */
-void timer_dma_enable(uint32_t timer_periph,uint16_t timer_dma);
+void timer_dma_enable(uint32_t timer_periph, uint16_t dma);
/* disable the TIMER DMA */
-void timer_dma_disable(uint32_t timer_periph,uint16_t timer_dma);
+void timer_dma_disable(uint32_t timer_periph, uint16_t dma);
/* channel DMA request source selection */
-void timer_channel_dma_request_source_select(uint32_t timer_periph,uint8_t dma_request);
+void timer_channel_dma_request_source_select(uint32_t timer_periph, uint8_t dma_request);
/* configure the TIMER DMA transfer */
-void timer_dma_transfer_config(uint32_t timer_periph,uint32_t dma_baseaddr,uint32_t dma_lenth);
+void timer_dma_transfer_config(uint32_t timer_periph,uint32_t dma_baseaddr, uint32_t dma_lenth);
/* software generate events */
-void timer_event_software_generate(uint32_t timer_periph,uint16_t timer_event);
+void timer_event_software_generate(uint32_t timer_periph, uint16_t event);
-/* timer channel complementary protection */
+/* TIMER channel complementary protection */
+/* initialize TIMER break parameter struct */
+void timer_break_struct_para_init(timer_break_parameter_struct* breakpara);
/* configure TIMER break function */
-void timer_break_config(uint32_t timer_periph,timer_break_parameter_struct* timer_bkdtpara);
+void timer_break_config(uint32_t timer_periph, timer_break_parameter_struct* breakpara);
/* enable TIMER break function */
void timer_break_enable(uint32_t timer_periph);
/* disable TIMER break function */
@@ -657,79 +699,83 @@ void timer_break_disable(uint32_t timer_periph);
void timer_automatic_output_enable(uint32_t timer_periph);
/* disable TIMER output automatic function */
void timer_automatic_output_disable(uint32_t timer_periph);
-/* configure TIMER primary output function */
-void timer_primary_output_config(uint32_t timer_periph,ControlStatus newvalue);
-/* channel capture/compare control shadow register enable */
-void timer_channel_control_shadow_config(uint32_t timer_periph,ControlStatus newvalue);
+/* enable or disable TIMER primary output function */
+void timer_primary_output_config(uint32_t timer_periph, ControlStatus newvalue);
+/* enable or disable channel capture/compare control shadow register */
+void timer_channel_control_shadow_config(uint32_t timer_periph, ControlStatus newvalue);
/* configure TIMER channel control shadow register update control */
-void timer_channel_control_shadow_update_config(uint32_t timer_periph,uint8_t timer_ccuctl);
+void timer_channel_control_shadow_update_config(uint32_t timer_periph, uint8_t ccuctl);
/* TIMER channel output */
+/* initialize TIMER channel output parameter struct */
+void timer_channel_output_struct_para_init(timer_oc_parameter_struct* ocpara);
/* configure TIMER channel output function */
-void timer_channel_output_config(uint32_t timer_periph,uint16_t timer_channel,timer_oc_parameter_struct* timer_ocpara);
+void timer_channel_output_config(uint32_t timer_periph,uint16_t channel, timer_oc_parameter_struct* ocpara);
/* configure TIMER channel output compare mode */
-void timer_channel_output_mode_config(uint32_t timer_periph,uint16_t timer_channel,uint16_t timer_ocmode);
+void timer_channel_output_mode_config(uint32_t timer_periph, uint16_t channel,uint16_t ocmode);
/* configure TIMER channel output pulse value */
-void timer_channel_output_pulse_value_config(uint32_t timer_periph,uint16_t timer_channel,uint32_t timer_pluse);
+void timer_channel_output_pulse_value_config(uint32_t timer_periph, uint16_t channel, uint32_t pulse);
/* configure TIMER channel output shadow function */
-void timer_channel_output_shadow_config(uint32_t timer_periph,uint16_t timer_channel,uint16_t timer_ocshadow);
+void timer_channel_output_shadow_config(uint32_t timer_periph, uint16_t channel, uint16_t ocshadow);
/* configure TIMER channel output fast function */
-void timer_channel_output_fast_config(uint32_t timer_periph,uint16_t timer_channel,uint16_t timer_ocfast);
+void timer_channel_output_fast_config(uint32_t timer_periph, uint16_t channel, uint16_t ocfast);
/* configure TIMER channel output clear function */
-void timer_channel_output_clear_config(uint32_t timer_periph,uint16_t timer_channel,uint16_t timer_occlear);
+void timer_channel_output_clear_config(uint32_t timer_periph,uint16_t channel,uint16_t occlear);
/* configure TIMER channel output polarity */
-void timer_channel_output_polarity_config(uint32_t timer_periph,uint16_t timer_channel,uint16_t timer_ocpolarity);
+void timer_channel_output_polarity_config(uint32_t timer_periph, uint16_t channel, uint16_t ocpolarity);
/* configure TIMER channel complementary output polarity */
-void timer_channel_complementary_output_polarity_config(uint32_t timer_periph,uint16_t timer_channel,uint16_t timer_ocnpolarity);
+void timer_channel_complementary_output_polarity_config(uint32_t timer_periph, uint16_t channel, uint16_t ocnpolarity);
/* configure TIMER channel enable state */
-void timer_channel_output_state_config(uint32_t timer_periph,uint16_t timer_channel,uint32_t timer_state);
+void timer_channel_output_state_config(uint32_t timer_periph, uint16_t channel, uint32_t state);
/* configure TIMER channel complementary output enable state */
-void timer_channel_complementary_output_state_config(uint32_t timer_periph,uint16_t timer_channel,uint16_t timer_ocnstate);
+void timer_channel_complementary_output_state_config(uint32_t timer_periph, uint16_t channel, uint16_t ocnstate);
/* TIMER channel input */
+/* initialize TIMER channel input parameter struct */
+void timer_channel_input_struct_para_init(timer_ic_parameter_struct* icpara);
/* configure TIMER input capture parameter */
-void timer_input_capture_config(uint32_t timer_periph,uint16_t timer_channel,timer_ic_parameter_struct* timer_icpara);
+void timer_input_capture_config(uint32_t timer_periph, uint16_t channel, timer_ic_parameter_struct* icpara);
/* configure TIMER channel input capture prescaler value */
-void timer_channel_input_capture_prescaler_config(uint32_t timer_periph,uint16_t timer_channel,uint16_t timer_prescaler);
+void timer_channel_input_capture_prescaler_config(uint32_t timer_periph, uint16_t channel, uint16_t prescaler);
/* read TIMER channel capture compare register value */
-uint32_t timer_channel_capture_value_register_read(uint32_t timer_periph,uint16_t timer_channel);
+uint32_t timer_channel_capture_value_register_read(uint32_t timer_periph, uint16_t channel);
/* configure TIMER input pwm capture function */
-void timer_input_pwm_capture_config(uint32_t timer_periph,uint16_t timer_channel,timer_ic_parameter_struct* timer_icpwm);
+void timer_input_pwm_capture_config(uint32_t timer_periph, uint16_t channel, timer_ic_parameter_struct* icpwm);
/* configure TIMER hall sensor mode */
-void timer_hall_mode_config(uint32_t timer_periph,uint8_t timer_hallmode);
+void timer_hall_mode_config(uint32_t timer_periph, uint32_t hallmode);
/* TIMER master and slave */
/* select TIMER input trigger source */
-void timer_input_trigger_source_select(uint32_t timer_periph,uint32_t timer_intrigger);
+void timer_input_trigger_source_select(uint32_t timer_periph, uint32_t intrigger);
/* select TIMER master mode output trigger source */
-void timer_master_output_trigger_source_select(uint32_t timer_periph,uint32_t timer_outrigger);
+void timer_master_output_trigger_source_select(uint32_t timer_periph, uint32_t outrigger);
/* select TIMER slave mode */
-void timer_slave_mode_select(uint32_t timer_periph,uint32_t timer_slavemode);
+void timer_slave_mode_select(uint32_t timer_periph,uint32_t slavemode);
/* configure TIMER master slave mode */
-void timer_master_slave_mode_config(uint32_t timer_periph,uint8_t timer_masterslave);
+void timer_master_slave_mode_config(uint32_t timer_periph, uint32_t masterslave);
/* configure TIMER external trigger input */
-void timer_external_trigger_config(uint32_t timer_periph,uint32_t timer_extprescaler,uint32_t timer_expolarity,uint32_t timer_extfilter);
+void timer_external_trigger_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t extpolarity, uint32_t extfilter);
/* configure TIMER quadrature decoder mode */
-void timer_quadrature_decoder_mode_config(uint32_t timer_periph,uint32_t timer_decomode,uint16_t timer_ic0polarity,uint16_t timer_ic1polarity);
+void timer_quadrature_decoder_mode_config(uint32_t timer_periph, uint32_t decomode, uint16_t ic0polarity, uint16_t ic1polarity);
/* configure TIMER internal clock mode */
void timer_internal_clock_config(uint32_t timer_periph);
/* configure TIMER the internal trigger as external clock input */
-void timer_internal_trigger_as_external_clock_config(uint32_t timer_periph, uint32_t timer_intrigger);
+void timer_internal_trigger_as_external_clock_config(uint32_t timer_periph, uint32_t intrigger);
/* configure TIMER the external trigger as external clock input */
-void timer_external_trigger_as_external_clock_config(uint32_t timer_periph,uint32_t timer_extrigger,uint16_t timer_expolarity,uint32_t timer_extfilter);
+void timer_external_trigger_as_external_clock_config(uint32_t timer_periph, uint32_t extrigger, uint16_t extpolarity,uint32_t extfilter);
/* configure TIMER the external clock mode 0 */
-void timer_external_clock_mode0_config(uint32_t timer_periph,uint32_t timer_extprescaler,uint32_t timer_expolarity,uint32_t timer_extfilter);
+void timer_external_clock_mode0_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t extpolarity, uint32_t extfilter);
/* configure TIMER the external clock mode 1 */
-void timer_external_clock_mode1_config(uint32_t timer_periph,uint32_t timer_extprescaler,uint32_t timer_expolarity,uint32_t timer_extfilter);
+void timer_external_clock_mode1_config(uint32_t timer_periph, uint32_t extprescaler, uint32_t extpolarity, uint32_t extfilter);
/* disable TIMER the external clock mode 1 */
void timer_external_clock_mode1_disable(uint32_t timer_periph);
-/* configure TIMER1 channel 0 remap function */
-void timer_channel_remap_config(uint32_t timer_periph,uint32_t timer_remap);
+/* configure TIMER channel remap function */
+void timer_channel_remap_config(uint32_t timer_periph,uint32_t remap);
/* TIMER configure */
/* configure TIMER write CHxVAL register selection */
-void timer_write_cc_register_config(uint32_t timer_periph, uint16_t timer_ccsel);
+void timer_write_chxval_register_config(uint32_t timer_periph, uint16_t ccsel);
/* configure TIMER output value selection */
-void timer_output_value_selection_config(uint32_t timer_periph, uint16_t timer_outsel);
+void timer_output_value_selection_config(uint32_t timer_periph, uint16_t outsel);
#endif /* GD32F4XX_TIMER_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_tli.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_tli.h
index f2f8f9d71e..8b1232fa17 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_tli.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_tli.h
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_tli.h
- \brief definitions for the TLI
+ \file gd32f4xx_tli.h
+ \brief definitions for the TLI
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.1, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#ifndef GD32F4XX_TLI_H
@@ -17,8 +42,8 @@
/* TLI definitions */
#define TLI TLI_BASE /*!< TLI base address */
/* TLI layer definitions */
-#define LAYER0 TLI_BASE /*!< Layer0 base address */
-#define LAYER1 (TLI_BASE+0x80) /*!< Layer1 base address */
+#define LAYER0 TLI_BASE /*!< TLI layer0 base address */
+#define LAYER1 (TLI_BASE+0x80) /*!< TLI layer1 base address */
/* registers definitions */
#define TLI_SPSZ REG32(TLI + 0x08U) /*!< TLI synchronous pulse size register */
@@ -45,8 +70,7 @@
#define TLI_LxFBADDR(layerx) REG32((layerx) + 0xACU) /*!< TLI layer x frame base address register */
#define TLI_LxFLLEN(layerx) REG32((layerx) + 0xB0U) /*!< TLI layer x frame line length register */
#define TLI_LxFTLN(layerx) REG32((layerx) + 0xB4U) /*!< TLI layer x frame total line number register */
-#define TLI_LxLUT(layerx) REG32((layerx) + 0xC4U) /*!< TLI ayer x Look Up Table register */
-
+#define TLI_LxLUT(layerx) REG32((layerx) + 0xC4U) /*!< TLI layer x look up table register */
/* bits definitions */
/* TLI_SPSZ */
@@ -154,8 +178,8 @@
#define TLI_LxFBADDR_FBADD BITS(0,31) /*!< frame buffer base address */
/* TLI_LxFLLEN */
-#define TLI_LxFLLEN_FLL BITS(0,12) /*!< frame line length */
-#define TLI_LxFLLEN_STDOFF BITS(16,28) /*!< frame buffer stride offset */
+#define TLI_LxFLLEN_FLL BITS(0,13) /*!< frame line length */
+#define TLI_LxFLLEN_STDOFF BITS(16,29) /*!< frame buffer stride offset */
/* TLI_LxFTLN */
#define TLI_LxFTLN_FTLN BITS(0,10) /*!< frame total line number */
@@ -167,14 +191,13 @@
#define TLI_LxLUT_TADD BITS(24,31) /*!< look up table write address */
/* constants definitions */
-
/* TLI parameter struct definitions */
typedef struct
-{
- uint32_t synpsz_vpsz; /*!< size of the vertical synchronous pulse */
- uint32_t synpsz_hpsz; /*!< size of the horizontal synchronous pulse */
- uint32_t backpsz_vbpsz; /*!< size of the vertical back porch plus synchronous pulse */
- uint32_t backpsz_hbpsz; /*!< size of the horizontal back porch plus synchronous pulse */
+{
+ uint16_t synpsz_vpsz; /*!< size of the vertical synchronous pulse */
+ uint16_t synpsz_hpsz; /*!< size of the horizontal synchronous pulse */
+ uint16_t backpsz_vbpsz; /*!< size of the vertical back porch plus synchronous pulse */
+ uint16_t backpsz_hbpsz; /*!< size of the horizontal back porch plus synchronous pulse */
uint32_t activesz_vasz; /*!< size of the vertical active area width plus back porch and synchronous pulse */
uint32_t activesz_hasz; /*!< size of the horizontal active area width plus back porch and synchronous pulse */
uint32_t totalsz_vtsz; /*!< vertical total size of the display */
@@ -186,141 +209,168 @@ typedef struct
uint32_t signalpolarity_vs; /*!< vertical pulse polarity selection */
uint32_t signalpolarity_de; /*!< data enable polarity selection */
uint32_t signalpolarity_pixelck; /*!< pixel clock polarity selection */
-}tli_parameter_struct;
+}tli_parameter_struct;
-/* TLI Layer parameter struct definitions */
+/* TLI layer parameter struct definitions */
typedef struct
-{
- uint32_t layer_window_rightpos; /*!< window right position */
- uint32_t layer_window_leftpos; /*!< window left position */
- uint32_t layer_window_bottompos; /*!< window bottom position */
- uint32_t layer_window_toppos; /*!< window top position */
+{
+ uint16_t layer_window_rightpos; /*!< window right position */
+ uint16_t layer_window_leftpos; /*!< window left position */
+ uint16_t layer_window_bottompos; /*!< window bottom position */
+ uint16_t layer_window_toppos; /*!< window top position */
uint32_t layer_ppf; /*!< packeted pixel format */
- uint32_t layer_sa; /*!< specified alpha */
- uint32_t layer_default_alpha; /*!< the default color alpha */
- uint32_t layer_default_red; /*!< the default color red */
- uint32_t layer_default_green; /*!< the default color green */
- uint32_t layer_default_blue; /*!< the default color blue */
+ uint8_t layer_sa; /*!< specified alpha */
+ uint8_t layer_default_alpha; /*!< the default color alpha */
+ uint8_t layer_default_red; /*!< the default color red */
+ uint8_t layer_default_green; /*!< the default color green */
+ uint8_t layer_default_blue; /*!< the default color blue */
uint32_t layer_acf1; /*!< alpha calculation factor 1 of blending method */
uint32_t layer_acf2; /*!< alpha calculation factor 2 of blending method */
uint32_t layer_frame_bufaddr; /*!< frame buffer base address */
- uint32_t layer_frame_buf_stride_offset; /*!< frame buffer stride offset */
- uint32_t layer_frame_line_length; /*!< frame line length */
- uint32_t layer_frame_total_line_number; /*!< frame total line number */
-}tli_layer_parameter_struct;
+ uint16_t layer_frame_buf_stride_offset; /*!< frame buffer stride offset */
+ uint16_t layer_frame_line_length; /*!< frame line length */
+ uint16_t layer_frame_total_line_number; /*!< frame total line number */
+}tli_layer_parameter_struct;
/* TLI layer LUT parameter struct definitions */
typedef struct
-{
+{
uint32_t layer_table_addr; /*!< look up table write address */
- uint32_t layer_lut_channel_red; /*!< red channel of a LUT entry */
- uint32_t layer_lut_channel_green; /*!< green channel of a LUT entry */
- uint32_t layer_lut_channel_blue; /*!< blue channel of a LUT entry */
-}tli_layer_lut_parameter_struct;
+ uint8_t layer_lut_channel_red; /*!< red channel of a LUT entry */
+ uint8_t layer_lut_channel_green; /*!< green channel of a LUT entry */
+ uint8_t layer_lut_channel_blue; /*!< blue channel of a LUT entry */
+}tli_layer_lut_parameter_struct;
/* packeted pixel format */
-typedef enum
+typedef enum
{
- LAYER_PPF_ARGB8888, /*!< layerx pixel format ARGB8888 */
- LAYER_PPF_RGB888, /*!< layerx pixel format RGB888 */
- LAYER_PPF_RGB565, /*!< layerx pixel format RGB565 */
- LAYER_PPF_ARGB1555, /*!< layerx pixel format ARGB1555 */
- LAYER_PPF_ARGB4444, /*!< layerx pixel format ARGB4444 */
- LAYER_PPF_L8, /*!< layerx pixel format L8 */
- LAYER_PPF_AL44, /*!< layerx pixel format AL44 */
- LAYER_PPF_AL88 /*!< layerx pixel format AL88 */
-} tli_layer_ppf_enum;
+ LAYER_PPF_ARGB8888, /*!< layerx pixel format ARGB8888 */
+ LAYER_PPF_RGB888, /*!< layerx pixel format RGB888 */
+ LAYER_PPF_RGB565, /*!< layerx pixel format RGB565 */
+ LAYER_PPF_ARGB1555, /*!< layerx pixel format ARGB1555 */
+ LAYER_PPF_ARGB4444, /*!< layerx pixel format ARGB4444 */
+ LAYER_PPF_L8, /*!< layerx pixel format L8 */
+ LAYER_PPF_AL44, /*!< layerx pixel format AL44 */
+ LAYER_PPF_AL88 /*!< layerx pixel format AL88 */
+}tli_layer_ppf_enum;
-/* layer reload configure */
-#define TLI_FRAME_BLANK_RELOAD_EN ((uint8_t)0x00U) /*!< the layer configuration will be reloaded at frame blank */
-#define TLI_REQUEST_RELOAD_EN ((uint8_t)0x01U) /*!< the layer configuration will be reloaded after this bit sets */
+/* TLI flags */
+#define TLI_FLAG_VDE TLI_STAT_VDE /*!< current VDE status */
+#define TLI_FLAG_HDE TLI_STAT_HDE /*!< current HDE status */
+#define TLI_FLAG_VS TLI_STAT_VS /*!< current VS status of the TLI */
+#define TLI_FLAG_HS TLI_STAT_HS /*!< current HS status of the TLI */
+#define TLI_FLAG_LM BIT(0) | BIT(31) /*!< line mark interrupt flag */
+#define TLI_FLAG_FE BIT(1) | BIT(31) /*!< FIFO error interrupt flag */
+#define TLI_FLAG_TE BIT(2) | BIT(31) /*!< transaction error interrupt flag */
+#define TLI_FLAG_LCR BIT(3) | BIT(31) /*!< layer configuration reloaded interrupt flag */
-/* dither Function */
-#define TLI_DITHER_DISABLE ((uint8_t)0x00U) /*!< dither function disable */
-#define TLI_DITHER_ENABLE ((uint8_t)0x01U) /*!< dither function enable */
+/* TLI interrupt enable or disable */
+#define TLI_INT_LM BIT(0) /*!< line mark interrupt */
+#define TLI_INT_FE BIT(1) /*!< FIFO error interrupt */
+#define TLI_INT_TE BIT(2) /*!< transaction error interrupt */
+#define TLI_INT_LCR BIT(3) /*!< layer configuration reloaded interrupt */
-/* horizontal pulse polarity selection */
-
-#define TLI_HSYN_ACTLIVE_LOW ((uint32_t)0x00000000U) /*!< horizontal synchronous pulse active low */
-#define TLI_HSYN_ACTLIVE_HIGHT TLI_CTL_HPPS /*!< horizontal synchronous pulse active high */
-
-
-/* vertical pulse polarity selection */
-
-#define TLI_VSYN_ACTLIVE_LOW ((uint32_t)0x00000000U) /*!< vertical synchronous pulse active low */
-#define TLI_VSYN_ACTLIVE_HIGHT TLI_CTL_VPPS /*!< vertical synchronous pulse active high */
+/* TLI interrupt flag */
+#define TLI_INT_FLAG_LM BIT(0) /*!< line mark interrupt flag */
+#define TLI_INT_FLAG_FE BIT(1) /*!< FIFO error interrupt flag */
+#define TLI_INT_FLAG_TE BIT(2) /*!< transaction error interrupt flag */
+#define TLI_INT_FLAG_LCR BIT(3) /*!< layer configuration reloaded interrupt flag */
+/* layer reload configure */
+#define TLI_FRAME_BLANK_RELOAD_EN ((uint8_t)0x00U) /*!< the layer configuration will be reloaded at frame blank */
+#define TLI_REQUEST_RELOAD_EN ((uint8_t)0x01U) /*!< the layer configuration will be reloaded after this bit sets */
-/* pixel Clock Polarity Selection */
+/* dither function */
+#define TLI_DITHER_DISABLE ((uint8_t)0x00U) /*!< dither function disable */
+#define TLI_DITHER_ENABLE ((uint8_t)0x01U) /*!< dither function enable */
-#define TLI_PIXEL_CLOCK_TLI ((uint32_t)0x00000000U) /*!< pixel clock is TLI clock */
-#define TLI_PIXEL_CLOCK_INVERTEDTLI TLI_CTL_CLKPS /*!< pixel clock is inverted TLI clock */
+/* horizontal pulse polarity selection */
+#define TLI_HSYN_ACTLIVE_LOW ((uint32_t)0x00000000U) /*!< horizontal synchronous pulse active low */
+#define TLI_HSYN_ACTLIVE_HIGHT TLI_CTL_HPPS /*!< horizontal synchronous pulse active high */
+/* vertical pulse polarity selection */
+#define TLI_VSYN_ACTLIVE_LOW ((uint32_t)0x00000000U) /*!< vertical synchronous pulse active low */
+#define TLI_VSYN_ACTLIVE_HIGHT TLI_CTL_VPPS /*!< vertical synchronous pulse active high */
-/* data Enable Polarity Selection */
+/* pixel clock polarity selection */
+#define TLI_PIXEL_CLOCK_TLI ((uint32_t)0x00000000U) /*!< pixel clock is TLI clock */
+#define TLI_PIXEL_CLOCK_INVERTEDTLI TLI_CTL_CLKPS /*!< pixel clock is inverted TLI clock */
-#define TLI_DE_ACTLIVE_LOW ((uint32_t)0x00000000U) /*!< data enable active low */
-#define TLI_DE_ACTLIVE_HIGHT TLI_CTL_DEPS /*!< data enable active high */
+/* data enable polarity selection */
+#define TLI_DE_ACTLIVE_LOW ((uint32_t)0x00000000U) /*!< data enable active low */
+#define TLI_DE_ACTLIVE_HIGHT TLI_CTL_DEPS /*!< data enable active high */
/* alpha calculation factor 1 of blending method */
-#define LxBLEND_ACF1(regval) (BITS(8,10) & ((regval)<<8))
-#define LAYER_ACF1_SA LxBLEND_ACF1(4) /*!< normalization specified alpha */
-#define LAYER_ACF1_PASA LxBLEND_ACF1(6) /*!< normalization pixel alpha * normalization specified alpha */
+#define LxBLEND_ACF1(regval) (BITS(8,10) & ((uint32_t)(regval)<<8))
+#define LAYER_ACF1_SA LxBLEND_ACF1(4) /*!< normalization specified alpha */
+#define LAYER_ACF1_PASA LxBLEND_ACF1(6) /*!< normalization pixel alpha * normalization specified alpha */
-/* alpha calculation factor 2 of blending method*/
-#define LxBLEND_ACF2(regval) (BITS(0,2) & ((regval)))
-#define LAYER_ACF2_SA LxBLEND_ACF2(5) /*!< normalization specified alpha */
-#define LAYER_ACF2_PASA LxBLEND_ACF2(7) /*!< normalization pixel alpha x normalization specified alpha */
-/* function declarations */
+/* alpha calculation factor 2 of blending method */
+#define LxBLEND_ACF2(regval) (BITS(0,2) & ((uint32_t)(regval)))
+#define LAYER_ACF2_SA LxBLEND_ACF2(5) /*!< normalization specified alpha */
+#define LAYER_ACF2_PASA LxBLEND_ACF2(7) /*!< normalization pixel alpha * normalization specified alpha */
-/* deinitialize TLI */
+/* function declarations */
+/* initialization functions, TLI enable or disable, TLI reload mode configuration */
+/* deinitialize TLI registers */
void tli_deinit(void);
+/* initialize the parameters of TLI parameter structure with the default values, it is suggested
+ that call this function after a tli_parameter_struct structure is defined */
+void tli_struct_para_init(tli_parameter_struct *tli_struct);
/* initialize TLI */
void tli_init(tli_parameter_struct *tli_struct);
-/* TLI dither function enable */
-void tli_dither_config(uint8_t ditherstat);
+/* configure TLI dither function */
+void tli_dither_config(uint8_t dither_stat);
/* enable TLI */
void tli_enable(void);
/* disable TLI */
void tli_disable(void);
-/* TLI reload mode config*/
-void tli_reload_config(uint8_t reloadmod);
-
-/* TLI interrupt enable */
-void tli_interrupt_enable(uint32_t inttype);
-/* TLI interrupt disable */
-void tli_interrupt_disable(uint32_t inttype);
-/* get TLI interrupt flag */
-FlagStatus tli_interrupt_flag_get(uint32_t intflag);
-/* clear TLI interrupt flag */
-void tli_interrupt_flag_clear(uint32_t intflag);
-
-/* set line mark value */
-void tli_line_mark_set(uint32_t linenum);
-/* get current displayed position */
-uint32_t tli_current_pos_get(void);
-/* get TLI state */
-FlagStatus tli_flag_get(uint32_t state);
+/* configurate TLI reload mode */
+void tli_reload_config(uint8_t reload_mod);
-/* TLI layer enable */
+/* TLI layer configuration functions */
+/* initialize the parameters of TLI layer structure with the default values, it is suggested
+ that call this function after a tli_layer_parameter_struct structure is defined */
+void tli_layer_struct_para_init(tli_layer_parameter_struct *layer_struct);
+/* initialize TLI layer */
+void tli_layer_init(uint32_t layerx,tli_layer_parameter_struct *layer_struct);
+/* reconfigure window position */
+void tli_layer_window_offset_modify(uint32_t layerx,uint16_t offset_x,uint16_t offset_y);
+/* initialize the parameters of TLI layer LUT structure with the default values, it is suggested
+ that call this function after a tli_layer_lut_parameter_struct structure is defined */
+void tli_lut_struct_para_init(tli_layer_lut_parameter_struct *lut_struct);
+/* initialize TLI layer LUT */
+void tli_lut_init(uint32_t layerx,tli_layer_lut_parameter_struct *lut_struct);
+/* initialize TLI layer color key */
+void tli_color_key_init(uint32_t layerx,uint8_t redkey,uint8_t greenkey,uint8_t bluekey);
+/* enable TLI layer */
void tli_layer_enable(uint32_t layerx);
-/* TLI layer disable */
+/* disable TLI layer */
void tli_layer_disable(uint32_t layerx);
-/* TLI layer color keying enable */
+/* enable TLI layer color keying */
void tli_color_key_enable(uint32_t layerx);
-/* TLI layer color keying disable */
+/* disable TLI layer color keying */
void tli_color_key_disable(uint32_t layerx);
-/* TLI layer LUT enable */
+/* enable TLI layer LUT */
void tli_lut_enable(uint32_t layerx);
-/* TLI layer LUT disable */
+/* disable TLI layer LUT */
void tli_lut_disable(uint32_t layerx);
-/* TLI layer initialize */
-void tli_layer_init(uint32_t layerx,tli_layer_parameter_struct *layer_struct);
-/* TLI layer initialize */
-void tli_layer_window_offset_modify(uint32_t layerx,uint32_t offset_x,uint32_t offset_y);
-/* TLI layer lut initialize */
-void tli_lut_init(uint32_t layerx,tli_layer_lut_parameter_struct *lut_struct);
-/* TLI layer key initialize */
-void tli_ckey_init(uint32_t layerx,uint32_t redkey,uint32_t greenkey,uint32_t bluekey);
+
+/* set line mark value */
+void tli_line_mark_set(uint16_t line_num);
+/* get current displayed position */
+uint32_t tli_current_pos_get(void);
+
+/* flag and interrupt functions */
+/* enable TLI interrupt */
+void tli_interrupt_enable(uint32_t int_flag);
+/* disable TLI interrupt */
+void tli_interrupt_disable(uint32_t int_flag);
+/* get TLI interrupt flag */
+FlagStatus tli_interrupt_flag_get(uint32_t int_flag);
+/* clear TLI interrupt flag */
+void tli_interrupt_flag_clear(uint32_t int_flag);
+/* get TLI flag or state in TLI_INTF register or TLI_STAT register */
+FlagStatus tli_flag_get(uint32_t flag);
#endif /* GD32F4XX_TLI_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_trng.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_trng.h
index 7925b91af3..f321b15d28 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_trng.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_trng.h
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_trng.h
- \brief definitions for the TRNG
+ \file gd32f4xx_trng.h
+ \brief definitions for the TRNG
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#ifndef GD32F4XX_TRNG_H
@@ -14,13 +39,13 @@
#include "gd32f4xx.h"
-/* EXTI definitions */
+/* TRNG definitions */
#define TRNG TRNG_BASE
/* registers definitions */
-#define TRNG_CTL REG32(TRNG + 0x00U) /*!< interrupt enable register */
-#define TRNG_STAT REG32(TRNG + 0x04U) /*!< event enable register */
-#define TRNG_DATA REG32(TRNG + 0x08U) /*!< rising edge trigger enable register */
+#define TRNG_CTL REG32(TRNG + 0x00U) /*!< control register */
+#define TRNG_STAT REG32(TRNG + 0x04U) /*!< status register */
+#define TRNG_DATA REG32(TRNG + 0x08U) /*!< data register */
/* bits definitions */
/* TRNG_CTL */
@@ -40,7 +65,7 @@
/* constants definitions */
/* trng status flag */
typedef enum
-{
+{
TRNG_FLAG_DRDY = TRNG_STAT_DRDY, /*!< random Data ready status */
TRNG_FLAG_CECS = TRNG_STAT_CECS, /*!< clock error current status */
TRNG_FLAG_SECS = TRNG_STAT_SECS /*!< seed error current status */
@@ -54,6 +79,7 @@ typedef enum
}trng_int_flag_enum;
/* function declarations */
+/* initialization functions */
/* deinitialize the TRNG */
void trng_deinit(void);
/* enable the TRNG interface */
@@ -62,14 +88,14 @@ void trng_enable(void);
void trng_disable(void);
/* get the true random data */
uint32_t trng_get_true_random_data(void);
-/* get the trng status flags */
-FlagStatus trng_flag_get(trng_flag_enum flag);
-/* clear the trng status flags */
-void trng_flag_clear(trng_flag_enum flag);
-/* the trng interrupt enable */
+
+/* flag & interrupt functions */
+/* trng interrupt enable */
void trng_interrupt_enable(void);
-/* the trng interrupt disable */
+/* trng interrupt disable */
void trng_interrupt_disable(void);
+/* get the trng status flags */
+FlagStatus trng_flag_get(trng_flag_enum flag);
/* get the trng interrupt flags */
FlagStatus trng_interrupt_flag_get(trng_int_flag_enum int_flag);
/* clear the trng interrupt flags */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_usart.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_usart.h
index 5350f5e5b5..3cd49d827f 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_usart.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_usart.h
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_usart.h
- \brief definitions for the USART
+ \file gd32f4xx_usart.h
+ \brief definitions for the USART
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#ifndef GD32F4XX_USART_H
@@ -14,8 +39,8 @@
#include "gd32f4xx.h"
-/* USARTx(x=0,1) definitions */
-#define USART1 USART_BASE
+/* USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7) definitions */
+#define USART1 USART_BASE /*!< USART1 base address */
#define USART2 (USART_BASE+0x00000400U) /*!< USART2 base address */
#define UART3 (USART_BASE+0x00000800U) /*!< UART3 base address */
#define UART4 (USART_BASE+0x00000C00U) /*!< UART4 base address */
@@ -102,7 +127,7 @@
/* USARTx_GP */
#define USART_GP_PSC BITS(0,7) /*!< prescaler value for dividing the system clock */
#define USART_GP_GUAT BITS(8,15) /*!< guard time value in smartcard mode */
-
+
/* USARTx_CTL3 */
#define USART_CTL3_RTEN BIT(0) /*!< receiver timeout enable */
#define USART_CTL3_SCRTNUM BITS(1,3) /*!< smartcard auto-retry number */
@@ -131,59 +156,85 @@
/* constants definitions */
/* define the USART bit position and its register index offset */
#define USART_REGIDX_BIT(regidx, bitpos) (((uint32_t)(regidx) << 6) | (uint32_t)(bitpos))
-#define USART_REG_VAL(usartx, offset) (REG32((usartx) + ((uint32_t)(offset) >> 6)))
+#define USART_REG_VAL(usartx, offset) (REG32((usartx) + (((uint32_t)(offset) & 0xFFFFU) >> 6)))
#define USART_BIT_POS(val) ((uint32_t)(val) & 0x1FU)
+#define USART_REGIDX_BIT2(regidx, bitpos, regidx2, bitpos2) (((uint32_t)(regidx2) << 22) | (uint32_t)((bitpos2) << 16)\
+ | (((uint32_t)(regidx) << 6) | (uint32_t)(bitpos)))
+#define USART_REG_VAL2(usartx, offset) (REG32((usartx) + ((uint32_t)(offset) >> 22)))
+#define USART_BIT_POS2(val) (((uint32_t)(val) & 0x1F0000U) >> 16)
/* register offset */
-#define STAT0_REG_OFFSET 0x00U /*!< STAT0 register offset */
-#define STAT1_REG_OFFSET 0x88U /*!< STAT1 register offset */
-#define CHC_REG_OFFSET 0xC0U /*!< CHC register offset */
-#define CTL0_REG_OFFSET 0x0CU /*!< CTL0 register offset */
-#define CTL1_REG_OFFSET 0x10U /*!< CTL1 register offset */
-#define CTL2_REG_OFFSET 0x14U /*!< CTL2 register offset */
-#define CTL3_REG_OFFSET 0x80U /*!< CTL2 register offset */
+#define USART_STAT0_REG_OFFSET 0x00U /*!< STAT0 register offset */
+#define USART_STAT1_REG_OFFSET 0x88U /*!< STAT1 register offset */
+#define USART_CTL0_REG_OFFSET 0x0CU /*!< CTL0 register offset */
+#define USART_CTL1_REG_OFFSET 0x10U /*!< CTL1 register offset */
+#define USART_CTL2_REG_OFFSET 0x14U /*!< CTL2 register offset */
+#define USART_CTL3_REG_OFFSET 0x80U /*!< CTL3 register offset */
+#define USART_CHC_REG_OFFSET 0xC0U /*!< CHC register offset */
/* USART flags */
typedef enum
{
/* flags in STAT0 register */
- USART_FLAG_CTSF = USART_REGIDX_BIT(STAT0_REG_OFFSET, 9U), /*!< CTS change flag */
- USART_FLAG_LBDF = USART_REGIDX_BIT(STAT0_REG_OFFSET, 8U), /*!< LIN break detected flag */
- USART_FLAG_TBE = USART_REGIDX_BIT(STAT0_REG_OFFSET, 7U), /*!< transmit data buffer empty */
- USART_FLAG_TC = USART_REGIDX_BIT(STAT0_REG_OFFSET, 6U), /*!< transmission complete */
- USART_FLAG_RBNE = USART_REGIDX_BIT(STAT0_REG_OFFSET, 5U), /*!< read data buffer not empty */
- USART_FLAG_IDLEF = USART_REGIDX_BIT(STAT0_REG_OFFSET, 4U), /*!< IDLE frame detected flag */
- USART_FLAG_ORERR = USART_REGIDX_BIT(STAT0_REG_OFFSET, 3U), /*!< overrun error */
- USART_FLAG_NERR = USART_REGIDX_BIT(STAT0_REG_OFFSET, 2U), /*!< noise error flag */
- USART_FLAG_FERR = USART_REGIDX_BIT(STAT0_REG_OFFSET, 1U), /*!< frame error flag */
- USART_FLAG_PERR = USART_REGIDX_BIT(STAT0_REG_OFFSET, 0U), /*!< parity error flag */
+ USART_FLAG_CTS = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 9U), /*!< CTS change flag */
+ USART_FLAG_LBD = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 8U), /*!< LIN break detected flag */
+ USART_FLAG_TBE = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 7U), /*!< transmit data buffer empty */
+ USART_FLAG_TC = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 6U), /*!< transmission complete */
+ USART_FLAG_RBNE = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 5U), /*!< read data buffer not empty */
+ USART_FLAG_IDLE = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 4U), /*!< IDLE frame detected flag */
+ USART_FLAG_ORERR = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 3U), /*!< overrun error */
+ USART_FLAG_NERR = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 2U), /*!< noise error flag */
+ USART_FLAG_FERR = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 1U), /*!< frame error flag */
+ USART_FLAG_PERR = USART_REGIDX_BIT(USART_STAT0_REG_OFFSET, 0U), /*!< parity error flag */
/* flags in STAT1 register */
- USART_FLAG_BSY = USART_REGIDX_BIT(STAT1_REG_OFFSET, 16U), /*!< busy flag */
- USART_FLAG_EBF = USART_REGIDX_BIT(STAT1_REG_OFFSET, 12U), /*!< end of block flag */
- USART_FLAG_RTF = USART_REGIDX_BIT(STAT1_REG_OFFSET, 11U), /*!< receiver timeout flag */
+ USART_FLAG_BSY = USART_REGIDX_BIT(USART_STAT1_REG_OFFSET, 16U), /*!< busy flag */
+ USART_FLAG_EB = USART_REGIDX_BIT(USART_STAT1_REG_OFFSET, 12U), /*!< end of block flag */
+ USART_FLAG_RT = USART_REGIDX_BIT(USART_STAT1_REG_OFFSET, 11U), /*!< receiver timeout flag */
/* flags in CHC register */
- USART_FLAG_EPERR = USART_REGIDX_BIT(CHC_REG_OFFSET, 8U), /*!< early parity error flag */
+ USART_FLAG_EPERR = USART_REGIDX_BIT(USART_CHC_REG_OFFSET, 8U), /*!< early parity error flag */
}usart_flag_enum;
/* USART interrupt flags */
typedef enum
{
/* interrupt flags in CTL0 register */
- USART_INT_PERRIE = USART_REGIDX_BIT(CTL0_REG_OFFSET, 8U), /*!< parity error interrupt */
- USART_INT_TBEIE = USART_REGIDX_BIT(CTL0_REG_OFFSET, 7U), /*!< transmitter buffer empty interrupt */
- USART_INT_TCIE = USART_REGIDX_BIT(CTL0_REG_OFFSET, 6U), /*!< transmission complete interrupt */
- USART_INT_RBNEIE = USART_REGIDX_BIT(CTL0_REG_OFFSET, 5U), /*!< read data buffer not empty interrupt and overrun error interrupt */
- USART_INT_IDLEIE = USART_REGIDX_BIT(CTL0_REG_OFFSET, 4U), /*!< IDLE line detected interrupt */
+ USART_INT_FLAG_PERR = USART_REGIDX_BIT2(USART_CTL0_REG_OFFSET, 8U, USART_STAT0_REG_OFFSET, 0U), /*!< parity error interrupt and flag */
+ USART_INT_FLAG_TBE = USART_REGIDX_BIT2(USART_CTL0_REG_OFFSET, 7U, USART_STAT0_REG_OFFSET, 7U), /*!< transmitter buffer empty interrupt and flag */
+ USART_INT_FLAG_TC = USART_REGIDX_BIT2(USART_CTL0_REG_OFFSET, 6U, USART_STAT0_REG_OFFSET, 6U), /*!< transmission complete interrupt and flag */
+ USART_INT_FLAG_RBNE = USART_REGIDX_BIT2(USART_CTL0_REG_OFFSET, 5U, USART_STAT0_REG_OFFSET, 5U), /*!< read data buffer not empty interrupt and flag */
+ USART_INT_FLAG_RBNE_ORERR = USART_REGIDX_BIT2(USART_CTL0_REG_OFFSET, 5U, USART_STAT0_REG_OFFSET, 3U), /*!< read data buffer not empty interrupt and overrun error flag */
+ USART_INT_FLAG_IDLE = USART_REGIDX_BIT2(USART_CTL0_REG_OFFSET, 4U, USART_STAT0_REG_OFFSET, 4U), /*!< IDLE line detected interrupt and flag */
/* interrupt flags in CTL1 register */
- USART_INT_LBDIE = USART_REGIDX_BIT(CTL1_REG_OFFSET, 6U), /*!< LIN break detected interrupt */
+ USART_INT_FLAG_LBD = USART_REGIDX_BIT2(USART_CTL1_REG_OFFSET, 6U, USART_STAT0_REG_OFFSET, 8U), /*!< LIN break detected interrupt and flag */
/* interrupt flags in CTL2 register */
- USART_INT_CTSIE = USART_REGIDX_BIT(CTL2_REG_OFFSET, 10U), /*!< CTS interrupt */
- USART_INT_ERRIE = USART_REGIDX_BIT(CTL2_REG_OFFSET, 0U), /*!< error interrupt */
+ USART_INT_FLAG_CTS = USART_REGIDX_BIT2(USART_CTL2_REG_OFFSET, 10U, USART_STAT0_REG_OFFSET, 9U), /*!< CTS interrupt and flag */
+ USART_INT_FLAG_ERR_ORERR = USART_REGIDX_BIT2(USART_CTL2_REG_OFFSET, 0U, USART_STAT0_REG_OFFSET, 3U), /*!< error interrupt and overrun error */
+ USART_INT_FLAG_ERR_NERR = USART_REGIDX_BIT2(USART_CTL2_REG_OFFSET, 0U, USART_STAT0_REG_OFFSET, 2U), /*!< error interrupt and noise error flag */
+ USART_INT_FLAG_ERR_FERR = USART_REGIDX_BIT2(USART_CTL2_REG_OFFSET, 0U, USART_STAT0_REG_OFFSET, 1U), /*!< error interrupt and frame error flag */
/* interrupt flags in CTL3 register */
- USART_INT_EBIE = USART_REGIDX_BIT(CTL3_REG_OFFSET, 5U), /*!< interrupt enable bit of end of block event */
- USART_INT_RTIE = USART_REGIDX_BIT(CTL3_REG_OFFSET, 4U), /*!< interrupt enable bit of receive timeout event */
+ USART_INT_FLAG_EB = USART_REGIDX_BIT2(USART_CTL3_REG_OFFSET, 5U, USART_STAT1_REG_OFFSET, 12U), /*!< interrupt enable bit of end of block event and flag */
+ USART_INT_FLAG_RT = USART_REGIDX_BIT2(USART_CTL3_REG_OFFSET, 4U, USART_STAT1_REG_OFFSET, 11U), /*!< interrupt enable bit of receive timeout event and flag */
}usart_interrupt_flag_enum;
+/* USART interrupt flags */
+typedef enum
+{
+ /* interrupt in CTL0 register */
+ USART_INT_PERR = USART_REGIDX_BIT(USART_CTL0_REG_OFFSET, 8U), /*!< parity error interrupt */
+ USART_INT_TBE = USART_REGIDX_BIT(USART_CTL0_REG_OFFSET, 7U), /*!< transmitter buffer empty interrupt */
+ USART_INT_TC = USART_REGIDX_BIT(USART_CTL0_REG_OFFSET, 6U), /*!< transmission complete interrupt */
+ USART_INT_RBNE = USART_REGIDX_BIT(USART_CTL0_REG_OFFSET, 5U), /*!< read data buffer not empty interrupt and overrun error interrupt */
+ USART_INT_IDLE = USART_REGIDX_BIT(USART_CTL0_REG_OFFSET, 4U), /*!< IDLE line detected interrupt */
+ /* interrupt in CTL1 register */
+ USART_INT_LBD = USART_REGIDX_BIT(USART_CTL1_REG_OFFSET, 6U), /*!< LIN break detected interrupt */
+ /* interrupt in CTL2 register */
+ USART_INT_CTS = USART_REGIDX_BIT(USART_CTL2_REG_OFFSET, 10U), /*!< CTS interrupt */
+ USART_INT_ERR = USART_REGIDX_BIT(USART_CTL2_REG_OFFSET, 0U), /*!< error interrupt */
+ /* interrupt in CTL3 register */
+ USART_INT_EB = USART_REGIDX_BIT(USART_CTL3_REG_OFFSET, 5U), /*!< interrupt enable bit of end of block event */
+ USART_INT_RT = USART_REGIDX_BIT(USART_CTL3_REG_OFFSET, 4U), /*!< interrupt enable bit of receive timeout event */
+}usart_interrupt_enum;
+
/* USART invert configure */
typedef enum
{
@@ -211,8 +262,8 @@ typedef enum
/* USART parity bits definitions */
#define CTL0_PM(regval) (BITS(9,10) & ((uint32_t)(regval) << 9))
#define USART_PM_NONE CTL0_PM(0) /*!< no parity */
-#define USART_PM_ODD CTL0_PM(2) /*!< odd parity */
-#define USART_PM_EVEN CTL0_PM(3) /*!< even parity */
+#define USART_PM_EVEN CTL0_PM(2) /*!< even parity */
+#define USART_PM_ODD CTL0_PM(3) /*!< odd parity */
/* USART wakeup method in mute mode */
#define CTL0_WM(regval) (BIT(11) & ((uint32_t)(regval) << 11))
@@ -306,30 +357,6 @@ typedef enum
#define USART_HCM_NONE CHC_HCM(0) /*!< nRTS signal equals to the rxne status register */
#define USART_HCM_EN CHC_HCM(1) /*!< nRTS signal is set when the last data bit has been sampled */
-/* interrupt enable in USART_CTL0 */
-#define USART_INTEN_PERRIE ((uint32_t)0x10000100U) /*!< parity error interrupt */
-#define USART_INTEN_TBEIE ((uint32_t)0x10000080U) /*!< transmitter buffer empty interrupt */
-#define USART_INTEN_TCIE ((uint32_t)0x10000040U) /*!< transmission complete interrupt */
-#define USART_INTEN_RBNEIE ((uint32_t)0x10000020U) /*!< read data buffer not empty interrupt and overrun error interrupt */
-#define USART_INTEN_IDLEIE ((uint32_t)0x10000010U) /*!< IDLE line detected interrupt */
-
-/* interrupt enable flag in USART_CTL1 */
-#define USART_INTEN_LBDIE ((uint32_t)0x20000040U) /*!< LIN break detected interrupt */
-
-/* interrupt enable flag in USART_CTL2 */
-#define USART_INTEN_ERRIE ((uint32_t)0x40000001U) /*!< error interrupt */
-#define USART_INTEN_CTSIE ((uint32_t)0x40000400U) /*!< CTS interrupt*/
-
-/* interrupt enable flag in USART_CTL3 */
-#define USART_INTEN_RTIE ((uint32_t)0x80000010U) /*!< interrupt enable bit of receive timeout event */
-#define USART_INTEN_EBIE ((uint32_t)0x80000020U) /*!< interrupt enable bit of end of block event */
-
-#define USART_INTEN_MASK ((uint32_t)0x00000FFFU) /*!< USART interrupt mask */
-#define USART_INTS_CTL0 ((uint32_t)0x10000000U) /*!< interrupt in USART_CTL0 */
-#define USART_INTS_CTL1 ((uint32_t)0x20000000U) /*!< interrupt in USART_CTL1 */
-#define USART_INTS_CTL2 ((uint32_t)0x40000000U) /*!< interrupt in USART_CTL2 */
-#define USART_INTS_CTL3 ((uint32_t)0x80000000U) /*!< interrupt in USART_CTL3 */
-
/* function declarations */
/* initialization functions */
/* reset USART */
@@ -342,8 +369,6 @@ void usart_parity_config(uint32_t usart_periph, uint32_t paritycfg);
void usart_word_length_set(uint32_t usart_periph, uint32_t wlen);
/* configure usart stop bit length */
void usart_stop_bit_set(uint32_t usart_periph, uint32_t stblen);
-
-/* USART normal mode communication */
/* enable usart */
void usart_enable(uint32_t usart_periph);
/* disable usart */
@@ -352,6 +377,8 @@ void usart_disable(uint32_t usart_periph);
void usart_transmit_config(uint32_t usart_periph, uint32_t txconfig);
/* configure USART receiver */
void usart_receive_config(uint32_t usart_periph, uint32_t rxconfig);
+
+/* USART normal mode communication */
/* data is transmitted/received with the LSB/MSB first */
void usart_data_first_config(uint32_t usart_periph, uint32_t msbf);
/* configure USART inverted */
@@ -382,43 +409,43 @@ void usart_mute_mode_disable(uint32_t usart_periph);
void usart_mute_mode_wakeup_config(uint32_t usart_periph, uint32_t wmehtod);
/* LIN mode communication */
-/* LIN mode enable */
+/* enable LIN mode */
void usart_lin_mode_enable(uint32_t usart_periph);
-/* LIN mode disable */
+/* disable LIN mode */
void usart_lin_mode_disable(uint32_t usart_periph);
/* LIN break detection length */
-void usart_lin_break_dection_length_config(uint32_t usart_periph, uint32_t lblen);
+void usart_lin_break_detection_length_config(uint32_t usart_periph, uint32_t lblen);
/* send break frame */
void usart_send_break(uint32_t usart_periph);
/* half-duplex communication */
-/* half-duplex enable */
+/* enable half-duplex mode */
void usart_halfduplex_enable(uint32_t usart_periph);
-/* half-duplex disable */
+/* disable half-duplex mode */
void usart_halfduplex_disable(uint32_t usart_periph);
/* synchronous communication */
-/* clock enable */
+/* enable CK pin in synchronous mode */
void usart_synchronous_clock_enable(uint32_t usart_periph);
-/* clock disable */
+/* disable CK pin in synchronous mode */
void usart_synchronous_clock_disable(uint32_t usart_periph);
/* configure usart synchronous mode parameters */
void usart_synchronous_clock_config(uint32_t usart_periph, uint32_t clen, uint32_t cph, uint32_t cpl);
/* smartcard communication */
-/* guard time value configure in smartcard mode */
-void usart_guard_time_config(uint32_t usart_periph,uint32_t gaut);
-/* smartcard mode enable */
+/* configure guard time value in smartcard mode */
+void usart_guard_time_config(uint32_t usart_periph, uint32_t guat);
+/* enable smartcard mode */
void usart_smartcard_mode_enable(uint32_t usart_periph);
-/* smartcard mode disable */
+/* disable smartcard mode */
void usart_smartcard_mode_disable(uint32_t usart_periph);
-/* NACK enable in smartcard mode */
+/* enable NACK in smartcard mode */
void usart_smartcard_mode_nack_enable(uint32_t usart_periph);
-/* NACK disable in smartcard mode */
+/* disable NACK in smartcard mode */
void usart_smartcard_mode_nack_disable(uint32_t usart_periph);
-/* smartcard auto-retry number configure */
+/* configure smartcard auto-retry number */
void usart_smartcard_autoretry_config(uint32_t usart_periph, uint32_t scrtnum);
-/* block length configure */
+/* configure block length */
void usart_block_length_config(uint32_t usart_periph, uint32_t bl);
/* IrDA communication */
@@ -427,7 +454,7 @@ void usart_irda_mode_enable(uint32_t usart_periph);
/* disable IrDA mode */
void usart_irda_mode_disable(uint32_t usart_periph);
/* configure the peripheral clock prescaler */
-void usart_prescaler_config(uint32_t usart_periph, uint32_t psc);
+void usart_prescaler_config(uint32_t usart_periph, uint8_t psc);
/* configure IrDA low-power */
void usart_irda_lowpower_config(uint32_t usart_periph, uint32_t irlp);
@@ -445,23 +472,24 @@ void usart_parity_check_coherence_config(uint32_t usart_periph, uint32_t pcm);
/* configure hardware flow control coherence mode */
void usart_hardware_flow_coherence_config(uint32_t usart_periph, uint32_t hcm);
+/* DMA communication */
/* configure USART DMA for reception */
void usart_dma_receive_config(uint32_t usart_periph, uint32_t dmacmd);
/* configure USART DMA for transmission */
void usart_dma_transmit_config(uint32_t usart_periph, uint32_t dmacmd);
-/* flag functions */
-/* get flag in STAT0/STAT1/CHC register */
+/* flag & interrupt functions */
+/* get flag in STAT0/STAT1 register */
FlagStatus usart_flag_get(uint32_t usart_periph, usart_flag_enum flag);
-/* clear flag in STAT0/STAT1/CHC register */
+/* clear flag in STAT0/STAT1 register */
void usart_flag_clear(uint32_t usart_periph, usart_flag_enum flag);
-
-/* interrupt functions */
/* enable USART interrupt */
-void usart_interrupt_enable(uint32_t usart_periph, uint32_t int_flag);
+void usart_interrupt_enable(uint32_t usart_periph, usart_interrupt_enum interrupt);
/* disable USART interrupt */
-void usart_interrupt_disable(uint32_t usart_periph, uint32_t int_flag);
-/* get USART interrupt enable flag */
-FlagStatus usart_interrupt_flag_get(uint32_t usart_periph, uint32_t int_flag);
+void usart_interrupt_disable(uint32_t usart_periph, usart_interrupt_enum interrupt);
+/* get USART interrupt and flag status */
+FlagStatus usart_interrupt_flag_get(uint32_t usart_periph, usart_interrupt_flag_enum int_flag);
+/* clear interrupt flag in STAT0/STAT1 register */
+void usart_interrupt_flag_clear(uint32_t usart_periph, usart_interrupt_flag_enum int_flag);
-#endif /* GD32F4XX_USART_H */
+#endif /* GD32F4XX_USART_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_wwdgt.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_wwdgt.h
index d76cbce32c..525b9a6e5a 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_wwdgt.h
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Include/gd32f4xx_wwdgt.h
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_wwdgt.h
- \brief definitions for the WWDGT
+ \file gd32f4xx_wwdgt.h
+ \brief definitions for the WWDGT
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#ifndef GD32F4XX_WWDGT_H
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_adc.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_adc.c
index 73f89207ba..f249e6c840 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_adc.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_adc.c
@@ -1,24 +1,67 @@
/*!
- \file gd32f4xx_adc.c
- \brief ADC driver
+ \file gd32f4xx_adc.c
+ \brief ADC driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#include "gd32f4xx_adc.h"
-#define REGULAR_CHANNEL_LENGTH_OFFSET ((uint32_t)20U)
-#define INSERTED_CHANNEL_LENGTH_OFFSET ((uint32_t)20U)
-#define REGULAR_DISCONTINUOUS_NUMBER ((uint32_t)13U)
#define REGULAR_TRIGGER_MODE ((uint32_t)28U)
#define INSERTED_TRIGGER_MODE ((uint32_t)20U)
+/* discontinuous mode macro*/
+#define ADC_CHANNEL_LENGTH_SUBTRACT_ONE ((uint8_t)1U)
+
+/* ADC regular channel macro */
+#define ADC_REGULAR_CHANNEL_RANK_SIX ((uint8_t)6U)
+#define ADC_REGULAR_CHANNEL_RANK_TWELVE ((uint8_t)12U)
+#define ADC_REGULAR_CHANNEL_RANK_SIXTEEN ((uint8_t)16U)
+#define ADC_REGULAR_CHANNEL_RANK_LENGTH ((uint8_t)5U)
+
+/* ADC sampling time macro */
+#define ADC_CHANNEL_SAMPLE_TEN ((uint8_t)10U)
+#define ADC_CHANNEL_SAMPLE_EIGHTEEN ((uint8_t)18U)
+#define ADC_CHANNEL_SAMPLE_LENGTH ((uint8_t)3U)
+
+/* ADC inserted channel macro */
+#define ADC_INSERTED_CHANNEL_RANK_LENGTH ((uint8_t)5U)
+#define ADC_INSERTED_CHANNEL_SHIFT_LENGTH ((uint8_t)15U)
+
+/* ADC inserted channel offset macro */
+#define ADC_OFFSET_LENGTH ((uint8_t)3U)
+#define ADC_OFFSET_SHIFT_LENGTH ((uint8_t)4U)
/*!
- \brief ADC reset
+ \brief reset ADC
\param[in] none
\param[out] none
\retval none
@@ -30,53 +73,174 @@ void adc_deinit(void)
}
/*!
+ \brief configure the ADC clock for all the ADCs
+ \param[in] prescaler: configure ADCs prescaler ratio
+ only one parameter can be selected which is shown as below:
+ \arg ADC_ADCCK_PCLK2_DIV2: PCLK2 div2
+ \arg ADC_ADCCK_PCLK2_DIV4: PCLK2 div4
+ \arg ADC_ADCCK_PCLK2_DIV6: PCLK2 div6
+ \arg ADC_ADCCK_PCLK2_DIV8: PCLK2 div8
+ \arg ADC_ADCCK_HCLK_DIV5: HCLK div5
+ \arg ADC_ADCCK_HCLK_DIV6: HCLK div6
+ \arg ADC_ADCCK_HCLK_DIV10: HCLK div10
+ \arg ADC_ADCCK_HCLK_DIV20: HCLK div20
+ \param[out] none
+ \retval none
+*/
+void adc_clock_config(uint32_t prescaler)
+{
+ ADC_SYNCCTL &= ~((uint32_t)ADC_SYNCCTL_ADCCK);
+ ADC_SYNCCTL |= (uint32_t) prescaler;
+}
+
+/*!
+ \brief enable or disable ADC special function
+ \param[in] adc_periph: ADCx,x=0,1,2
+ \param[in] function: the function to config
+ only one parameter can be selected which is shown as below:
+ \arg ADC_SCAN_MODE: scan mode select
+ \arg ADC_INSERTED_CHANNEL_AUTO: inserted channel group convert automatically
+ \arg ADC_CONTINUOUS_MODE: continuous mode select
+ \param[in] newvalue: ENABLE or DISABLE
+ \param[out] none
+ \retval none
+*/
+void adc_special_function_config(uint32_t adc_periph , uint32_t function , ControlStatus newvalue)
+{
+ if(newvalue){
+ if(0U != (function & ADC_SCAN_MODE)){
+ /* enable scan mode */
+ ADC_CTL0(adc_periph) |= ADC_SCAN_MODE;
+ }
+ if(0U != (function & ADC_INSERTED_CHANNEL_AUTO)){
+ /* enable inserted channel group convert automatically */
+ ADC_CTL0(adc_periph) |= ADC_INSERTED_CHANNEL_AUTO;
+ }
+ if(0U != (function & ADC_CONTINUOUS_MODE)){
+ /* enable continuous mode */
+ ADC_CTL1(adc_periph) |= ADC_CONTINUOUS_MODE;
+ }
+ }else{
+ if(0U != (function & ADC_SCAN_MODE)){
+ /* disable scan mode */
+ ADC_CTL0(adc_periph) &= ~ADC_SCAN_MODE;
+ }
+ if(0U != (function & ADC_INSERTED_CHANNEL_AUTO)){
+ /* disable inserted channel group convert automatically */
+ ADC_CTL0(adc_periph) &= ~ADC_INSERTED_CHANNEL_AUTO;
+ }
+ if(0U != (function & ADC_CONTINUOUS_MODE)){
+ /* disable continuous mode */
+ ADC_CTL1(adc_periph) &= ~ADC_CONTINUOUS_MODE;
+ }
+ }
+}
+
+/*!
+ \brief configure ADC data alignment
+ \param[in] adc_periph: ADCx,x=0,1,2
+ \param[in] data_alignment: data alignment select
+ only one parameter can be selected which is shown as below:
+ \arg ADC_DATAALIGN_RIGHT: LSB alignment
+ \arg ADC_DATAALIGN_LEFT: MSB alignment
+ \param[out] none
+ \retval none
+*/
+void adc_data_alignment_config(uint32_t adc_periph , uint32_t data_alignment)
+{
+ if(ADC_DATAALIGN_RIGHT != data_alignment){
+ /* MSB alignment */
+ ADC_CTL1(adc_periph) |= ADC_CTL1_DAL;
+ }else{
+ /* LSB alignment */
+ ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_DAL);
+ }
+}
+
+/*!
\brief enable ADC interface
\param[in] adc_periph: ADCx,x=0,1,2
- \param[in] none
\param[out] none
\retval none
*/
void adc_enable(uint32_t adc_periph)
{
- if(RESET == (ADC_CTL1(adc_periph) & ADC_CTL1_ADCON)){
- ADC_CTL1(adc_periph) |= (uint32_t)ADC_CTL1_ADCON;
- }
+ if(RESET == (ADC_CTL1(adc_periph) & ADC_CTL1_ADCON)){
+ /* enable ADC */
+ ADC_CTL1(adc_periph) |= (uint32_t)ADC_CTL1_ADCON;
+ }
}
/*!
\brief disable ADC interface
\param[in] adc_periph: ADCx,x=0,1,2
- \param[in] none
\param[out] none
\retval none
*/
void adc_disable(uint32_t adc_periph)
{
+ /* disable ADC */
ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_ADCON);
}
/*!
- \brief ADC data alignment config
+ \brief ADC calibration and reset calibration
\param[in] adc_periph: ADCx,x=0,1,2
- \param[in] inserted_channel : insert channel select
- \arg ADC_DATAALIGN_RIGHT: LSB alignment
- \arg ADC_DATAALIGN_LEFT: MSB alignment
\param[out] none
\retval none
*/
-void adc_data_alignment_config(uint32_t adc_periph , uint8_t data_alignment)
+void adc_calibration_enable(uint32_t adc_periph)
{
- if(data_alignment){
- ADC_CTL1(adc_periph) |= ADC_CTL1_DAL;
+ /* reset the selected ADC calibration registers */
+ ADC_CTL1(adc_periph) |= (uint32_t) ADC_CTL1_RSTCLB;
+ /* check the RSTCLB bit state */
+ while(RESET != (ADC_CTL1(adc_periph) & ADC_CTL1_RSTCLB)){
+ }
+ /* enable ADC calibration process */
+ ADC_CTL1(adc_periph) |= ADC_CTL1_CLB;
+ /* check the CLB bit state */
+ while(RESET != (ADC_CTL1(adc_periph) & ADC_CTL1_CLB)){
+ }
+}
+
+/*!
+ \brief configure temperature sensor and internal reference voltage channel or VBAT channel function
+ \param[in] function: temperature sensor and internal reference voltage channel or VBAT channel
+ only one parameter can be selected which is shown as below:
+ \arg ADC_VBAT_CHANNEL_SWITCH: channel 18 (1/4 voltate of external battery) switch of ADC0
+ \arg ADC_TEMP_VREF_CHANNEL_SWITCH: channel 16 (temperature sensor) and 17 (internal reference voltage) switch of ADC0
+ \param[in] newvalue: ENABLE or DISABLE
+\param[out] none
+ \retval none
+*/
+void adc_channel_16_to_18(uint32_t function, ControlStatus newvalue)
+{
+ if(newvalue){
+ if(RESET != (function & ADC_VBAT_CHANNEL_SWITCH)){
+ /* enable ADC0 Vbat channel */
+ ADC_SYNCCTL |= ADC_VBAT_CHANNEL_SWITCH;
+ }
+ if(RESET != (function & ADC_TEMP_VREF_CHANNEL_SWITCH)){
+ /* enable ADC0 Vref and Temperature channel */
+ ADC_SYNCCTL |= ADC_TEMP_VREF_CHANNEL_SWITCH;
+ }
}else{
- ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_DAL);
+ if(RESET != (function & ADC_VBAT_CHANNEL_SWITCH)){
+ /* disable ADC0 Vbat channel */
+ ADC_SYNCCTL &= ~ADC_VBAT_CHANNEL_SWITCH;
+ }
+ if(RESET != (function & ADC_TEMP_VREF_CHANNEL_SWITCH)){
+ /* disable ADC0 Vref and Temperature channel */
+ ADC_SYNCCTL &= ~ADC_TEMP_VREF_CHANNEL_SWITCH;
+ }
}
}
/*!
- \brief ADC resolution config
+ \brief configure ADC resolution
\param[in] adc_periph: ADCx,x=0,1,2
\param[in] resolution: ADC resolution
+ only one parameter can be selected which is shown as below:
\arg ADC_RESOLUTION_12B: 12-bit ADC resolution
\arg ADC_RESOLUTION_10B: 10-bit ADC resolution
\arg ADC_RESOLUTION_8B: 8-bit ADC resolution
@@ -91,206 +255,397 @@ void adc_resolution_config(uint32_t adc_periph , uint32_t resolution)
}
/*!
- \brief ADC calibration and reset calibration
+ \brief configure ADC oversample mode
\param[in] adc_periph: ADCx,x=0,1,2
- \param[in] none
+ \param[in] mode: ADC oversampling mode
+ only one parameter can be selected which is shown as below:
+ \arg ADC_OVERSAMPLING_ALL_CONVERT: all oversampled conversions for a channel are done consecutively after a trigger
+ \arg ADC_OVERSAMPLING_ONE_CONVERT: each oversampled conversion for a channel needs a trigger
+ \param[in] shift: ADC oversampling shift
+ only one parameter can be selected which is shown as below:
+ \arg ADC_OVERSAMPLING_SHIFT_NONE: no oversampling shift
+ \arg ADC_OVERSAMPLING_SHIFT_1B: 1-bit oversampling shift
+ \arg ADC_OVERSAMPLING_SHIFT_2B: 2-bit oversampling shift
+ \arg ADC_OVERSAMPLING_SHIFT_3B: 3-bit oversampling shift
+ \arg ADC_OVERSAMPLING_SHIFT_4B: 3-bit oversampling shift
+ \arg ADC_OVERSAMPLING_SHIFT_5B: 5-bit oversampling shift
+ \arg ADC_OVERSAMPLING_SHIFT_6B: 6-bit oversampling shift
+ \arg ADC_OVERSAMPLING_SHIFT_7B: 7-bit oversampling shift
+ \arg ADC_OVERSAMPLING_SHIFT_8B: 8-bit oversampling shift
+ \param[in] ratio: ADC oversampling ratio
+ only one parameter can be selected which is shown as below:
+ \arg ADC_OVERSAMPLING_RATIO_MUL2: oversampling ratio multiple 2
+ \arg ADC_OVERSAMPLING_RATIO_MUL4: oversampling ratio multiple 4
+ \arg ADC_OVERSAMPLING_RATIO_MUL8: oversampling ratio multiple 8
+ \arg ADC_OVERSAMPLING_RATIO_MUL16: oversampling ratio multiple 16
+ \arg ADC_OVERSAMPLING_RATIO_MUL32: oversampling ratio multiple 32
+ \arg ADC_OVERSAMPLING_RATIO_MUL64: oversampling ratio multiple 64
+ \arg ADC_OVERSAMPLING_RATIO_MUL128: oversampling ratio multiple 128
+ \arg ADC_OVERSAMPLING_RATIO_MUL256: oversampling ratio multiple 256
\param[out] none
\retval none
*/
-void adc_calibration_enable(uint32_t adc_periph)
+void adc_oversample_mode_config(uint32_t adc_periph , uint32_t mode , uint16_t shift , uint8_t ratio)
{
- /* reset the selected ADC1 calibration registers */
- ADC_CTL1(adc_periph) |= (uint32_t) ADC_CTL1_RSTCLB;
- /* check the RSTCLB bit state */
- while((ADC_CTL1(adc_periph) & ADC_CTL1_RSTCLB)){
- }
- /* enable ADC calibration process */
- ADC_CTL1(adc_periph) |= ADC_CTL1_CLB;
- /* check the CLB bit state */
- while((ADC_CTL1(adc_periph) & ADC_CTL1_CLB)){
+ if(ADC_OVERSAMPLING_ONE_CONVERT == mode){
+ ADC_OVSAMPCTL(adc_periph) |= (uint32_t)ADC_OVSAMPCTL_TOVS;
+ }else{
+ ADC_OVSAMPCTL(adc_periph) &= ~((uint32_t)ADC_OVSAMPCTL_TOVS);
}
+ /* config the shift and ratio */
+ ADC_OVSAMPCTL(adc_periph) &= ~((uint32_t)(ADC_OVSAMPCTL_OVSR | ADC_OVSAMPCTL_OVSS));
+ ADC_OVSAMPCTL(adc_periph) |= ((uint32_t)shift | (uint32_t)ratio);
+}
+
+/*!
+ \brief enable ADC oversample mode
+ \param[in] adc_periph: ADCx,x=0,1,2
+ \param[out] none
+ \retval none
+*/
+void adc_oversample_mode_enable(uint32_t adc_periph)
+{
+ ADC_OVSAMPCTL(adc_periph) |= ADC_OVSAMPCTL_OVSEN;
+}
+
+/*!
+ \brief disable ADC oversample mode
+ \param[in] adc_periph: ADCx,x=0,1,2
+ \param[out] none
+ \retval none
+*/
+void adc_oversample_mode_disable(uint32_t adc_periph)
+{
+ ADC_OVSAMPCTL(adc_periph) &= ~((uint32_t)ADC_OVSAMPCTL_OVSEN);
+}
+
+/*!
+ \brief enable DMA request
+ \param[in] adc_periph: ADCx,x=0,1,2
+ \param[out] none
+ \retval none
+*/
+void adc_dma_mode_enable(uint32_t adc_periph)
+{
+ /* enable DMA request */
+ ADC_CTL1(adc_periph) |= (uint32_t)(ADC_CTL1_DMA);
+}
+
+/*!
+ \brief disable DMA request
+ \param[in] adc_periph: ADCx,x=0,1,2
+ \param[out] none
+ \retval none
+*/
+void adc_dma_mode_disable(uint32_t adc_periph)
+{
+ /* disable DMA request */
+ ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_DMA);
+}
+
+/*!
+ \brief when DMA=1, the DMA engine issues a request at end of each regular conversion
+ \param[in] adc_periph: ADCx,x=0,1,2
+ \param[out] none
+ \retval none
+*/
+void adc_dma_request_after_last_enable(uint32_t adc_periph)
+{
+ ADC_CTL1(adc_periph) |= (uint32_t)(ADC_CTL1_DDM);
}
/*!
- \brief ADC discontinuous mode config
+ \brief the DMA engine is disabled after the end of transfer signal from DMA controller is detected
+ \param[in] adc_periph: ADCx,x=0,1,2
+ \param[out] none
+ \retval none
+*/
+void adc_dma_request_after_last_disable(uint32_t adc_periph)
+{
+ ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_DDM);
+}
+
+/*!
+ \brief configure ADC discontinuous mode
\param[in] adc_periph: ADCx,x=0,1,2
\param[in] adc_channel_group: select the channel group
+ only one parameter can be selected which is shown as below:
\arg ADC_REGULAR_CHANNEL: regular channel group
\arg ADC_INSERTED_CHANNEL: inserted channel group
+ \arg ADC_CHANNEL_DISCON_DISABLE: disable discontinuous mode of regular & inserted channel
\param[in] length: number of conversions in discontinuous mode,the number can be 1..8
- for regular channel ,the number is no effect for inserted channel
+ for regular channel ,the number has no effect for inserted channel
\param[out] none
\retval none
*/
void adc_discontinuous_mode_config(uint32_t adc_periph , uint8_t adc_channel_group , uint8_t length)
{
+ /* disable discontinuous mode of regular & inserted channel */
ADC_CTL0(adc_periph) &= ~((uint32_t)( ADC_CTL0_DISRC | ADC_CTL0_DISIC ));
switch(adc_channel_group){
case ADC_REGULAR_CHANNEL:
/* config the number of conversions in discontinuous mode */
ADC_CTL0(adc_periph) &= ~((uint32_t)ADC_CTL0_DISNUM);
if((length <= 8U) && (length >= 1U)){
- ADC_CTL0(adc_periph) |= ((uint32_t)length - 1U) << REGULAR_DISCONTINUOUS_NUMBER;
+ ADC_CTL0(adc_periph) |= CTL0_DISNUM(((uint32_t)length - ADC_CHANNEL_LENGTH_SUBTRACT_ONE));
}
+ /* enable regular channel group discontinuous mode */
ADC_CTL0(adc_periph) |= (uint32_t)ADC_CTL0_DISRC;
break;
case ADC_INSERTED_CHANNEL:
+ /* enable inserted channel group discontinuous mode */
ADC_CTL0(adc_periph) |= (uint32_t)ADC_CTL0_DISIC;
break;
+ case ADC_CHANNEL_DISCON_DISABLE:
+ /* disable discontinuous mode of regular & inserted channel */
default:
break;
}
}
/*!
- \brief config end of conversion mode
+ \brief configure the length of regular channel group or inserted channel group
\param[in] adc_periph: ADCx,x=0,1,2
- \param[in] end_selection: end of conversion mode
- \arg ADC_EOC_SET_SEQUENCE: only at the end of a sequence of regular conversions, the EOC bit is set
- \arg ADC_EOC_SET_CONVERSION: at the end of each regular conversion, the EOC bit is set.
+ \param[in] adc_channel_group: select the channel group
+ only one parameter can be selected which is shown as below:
+ \arg ADC_REGULAR_CHANNEL: regular channel group
+ \arg ADC_INSERTED_CHANNEL: inserted channel group
+ \param[in] length: the length of the channel
+ regular channel 1-16
+ inserted channel 1-4
\param[out] none
\retval none
*/
-void adc_end_of_conversion_config(uint32_t adc_periph , uint8_t end_selection)
+void adc_channel_length_config(uint32_t adc_periph , uint8_t adc_channel_group , uint32_t length)
{
- switch(end_selection){
- case ADC_EOC_SET_SEQUENCE:
- ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_EOCM);
- break;
- case ADC_EOC_SET_CONVERSION:
- ADC_CTL1(adc_periph) |= (uint32_t)(ADC_CTL1_EOCM);
- break;
- default:
- break;
+ switch(adc_channel_group){
+ case ADC_REGULAR_CHANNEL:
+ if((length >= 1U) && (length <= 16U)){
+ ADC_RSQ0(adc_periph) &= ~((uint32_t)ADC_RSQ0_RL);
+ ADC_RSQ0(adc_periph) |= RSQ0_RL((uint32_t)(length-ADC_CHANNEL_LENGTH_SUBTRACT_ONE));
+ }
+ break;
+ case ADC_INSERTED_CHANNEL:
+ if((length >= 1U) && (length <= 4U)){
+ ADC_ISQ(adc_periph) &= ~((uint32_t)ADC_ISQ_IL);
+ ADC_ISQ(adc_periph) |= ISQ_IL((uint32_t)(length-ADC_CHANNEL_LENGTH_SUBTRACT_ONE));
+ }
+ break;
+ default:
+ break;
}
}
/*!
- \brief ADC special function enable or disable
+ \brief configure ADC regular channel
\param[in] adc_periph: ADCx,x=0,1,2
- \param[in] function: select the function to config
- \arg ADC_SCAN_MODE: scan mode select
- \arg ADC_INSERTED_CHANNEL_AUTO: inserted channel group convert automatically
- \arg ADC_CONTINUOUS_MODE: continuous mode select
- \param[in] newvalue: ENABLE or DISABLE
+ \param[in] rank: the regular group sequencer rank,this parameter must be between 0 to 15
+ \param[in] adc_channel: the selected ADC channel
+ only one parameter can be selected which is shown as below:
+ \arg ADC_CHANNEL_x(x=0..18): ADC Channelx
+ \param[in] sample_time: the sample time value
+ only one parameter can be selected which is shown as below:
+ \arg ADC_SAMPLETIME_3: 3 cycles
+ \arg ADC_SAMPLETIME_15: 15 cycles
+ \arg ADC_SAMPLETIME_28: 28 cycles
+ \arg ADC_SAMPLETIME_56: 56 cycles
+ \arg ADC_SAMPLETIME_84: 84 cycles
+ \arg ADC_SAMPLETIME_112: 112 cycles
+ \arg ADC_SAMPLETIME_144: 144 cycles
+ \arg ADC_SAMPLETIME_480: 480 cycles
\param[out] none
\retval none
*/
-void adc_special_function_config(uint32_t adc_periph , uint8_t function , ControlStatus newvalue)
+void adc_regular_channel_config(uint32_t adc_periph , uint8_t rank , uint8_t adc_channel , uint32_t sample_time)
{
- if(newvalue){
- switch(function){
- case ADC_SCAN_MODE:
- ADC_CTL0(adc_periph) |= (uint32_t)ADC_CTL0_SM;
- break;
- case ADC_INSERTED_CHANNEL_AUTO:
- ADC_CTL0(adc_periph) |= (uint32_t)ADC_CTL0_ICA;
- break;
- case ADC_CONTINUOUS_MODE:
- ADC_CTL1(adc_periph) |= (uint32_t)ADC_CTL1_CTN;
- break;
- default:
- break;
- }
+ uint32_t rsq,sampt;
+
+ /* ADC regular sequence config */
+ if(rank < ADC_REGULAR_CHANNEL_RANK_SIX){
+ /* the regular group sequence rank is smaller than six */
+ rsq = ADC_RSQ2(adc_periph);
+ rsq &= ~((uint32_t)(ADC_RSQX_RSQN << (ADC_REGULAR_CHANNEL_RANK_LENGTH*rank)));
+ /* the channel number is written to these bits to select a channel as the nth conversion in the regular channel group */
+ rsq |= ((uint32_t)adc_channel << (ADC_REGULAR_CHANNEL_RANK_LENGTH*rank));
+ ADC_RSQ2(adc_periph) = rsq;
+ }else if(rank < ADC_REGULAR_CHANNEL_RANK_TWELVE){
+ /* the regular group sequence rank is smaller than twelve */
+ rsq = ADC_RSQ1(adc_periph);
+ rsq &= ~((uint32_t)(ADC_RSQX_RSQN << (ADC_REGULAR_CHANNEL_RANK_LENGTH*(rank-ADC_REGULAR_CHANNEL_RANK_SIX))));
+ /* the channel number is written to these bits to select a channel as the nth conversion in the regular channel group */
+ rsq |= ((uint32_t)adc_channel << (ADC_REGULAR_CHANNEL_RANK_LENGTH*(rank-ADC_REGULAR_CHANNEL_RANK_SIX)));
+ ADC_RSQ1(adc_periph) = rsq;
+ }else if(rank < ADC_REGULAR_CHANNEL_RANK_SIXTEEN){
+ /* the regular group sequence rank is smaller than sixteen */
+ rsq = ADC_RSQ0(adc_periph);
+ rsq &= ~((uint32_t)(ADC_RSQX_RSQN << (ADC_REGULAR_CHANNEL_RANK_LENGTH*(rank-ADC_REGULAR_CHANNEL_RANK_TWELVE))));
+ /* the channel number is written to these bits to select a channel as the nth conversion in the regular channel group */
+ rsq |= ((uint32_t)adc_channel << (ADC_REGULAR_CHANNEL_RANK_LENGTH*(rank-ADC_REGULAR_CHANNEL_RANK_TWELVE)));
+ ADC_RSQ0(adc_periph) = rsq;
+ }else{
+ }
+
+ /* ADC sampling time config */
+ if(adc_channel < ADC_CHANNEL_SAMPLE_TEN){
+ /* the regular group sequence rank is smaller than ten */
+ sampt = ADC_SAMPT1(adc_periph);
+ sampt &= ~((uint32_t)(ADC_SAMPTX_SPTN << (ADC_CHANNEL_SAMPLE_LENGTH*adc_channel)));
+ /* channel sample time set*/
+ sampt |= (uint32_t)(sample_time << (ADC_CHANNEL_SAMPLE_LENGTH*adc_channel));
+ ADC_SAMPT1(adc_periph) = sampt;
+ }else if(adc_channel <= ADC_CHANNEL_SAMPLE_EIGHTEEN){
+ /* the regular group sequence rank is smaller than eighteen */
+ sampt = ADC_SAMPT0(adc_periph);
+ sampt &= ~((uint32_t)(ADC_SAMPTX_SPTN << (ADC_CHANNEL_SAMPLE_LENGTH*(adc_channel-ADC_CHANNEL_SAMPLE_TEN))));
+ /* channel sample time set*/
+ sampt |= (uint32_t)(sample_time << (ADC_CHANNEL_SAMPLE_LENGTH*(adc_channel-ADC_CHANNEL_SAMPLE_TEN)));
+ ADC_SAMPT0(adc_periph) = sampt;
}else{
- switch(function){
- case ADC_SCAN_MODE:
- ADC_CTL0(adc_periph) &= ~((uint32_t)ADC_CTL0_SM);
- break;
- case ADC_INSERTED_CHANNEL_AUTO:
- ADC_CTL0(adc_periph) &= ~((uint32_t)ADC_CTL0_ICA);
- break;
- case ADC_CONTINUOUS_MODE:
- ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_CTN);
- break;
- default:
- break;
- }
}
}
/*!
- \brief configure the ADC clock for all the ADCs
- \param[in] prescaler: configure ADCs prescaler ratio
- \arg ADC_ADCCK_PCLK2_DIV2: PCLK2 div2
- \arg ADC_ADCCK_PCLK2_DIV4: PCLK2 div4
- \arg ADC_ADCCK_PCLK2_DIV6: PCLK2 div6
- \arg ADC_ADCCK_PCLK2_DIV8: PCLK2 div8
- \arg ADC_ADCCK_HCLK_DIV5: HCLK div5
- \arg ADC_ADCCK_HCLK_DIV6: HCLK div6
- \arg ADC_ADCCK_HCLK_DIV10: HCLK div10
- \arg ADC_ADCCK_HCLK_DIV20: HCLK div20
+ \brief configure ADC inserted channel
+ \param[in] adc_periph: ADCx,x=0,1,2
+ \param[in] rank: the inserted group sequencer rank,this parameter must be between 0 to 3
+ \param[in] adc_channel: the selected ADC channel
+ only one parameter can be selected which is shown as below:
+ \arg ADC_CHANNEL_x(x=0..18): ADC Channelx
+ \param[in] sample_time: The sample time value
+ only one parameter can be selected which is shown as below:
+ \arg ADC_SAMPLETIME_3: 3 cycles
+ \arg ADC_SAMPLETIME_15: 15 cycles
+ \arg ADC_SAMPLETIME_28: 28 cycles
+ \arg ADC_SAMPLETIME_56: 56 cycles
+ \arg ADC_SAMPLETIME_84: 84 cycles
+ \arg ADC_SAMPLETIME_112: 112 cycles
+ \arg ADC_SAMPLETIME_144: 144 cycles
+ \arg ADC_SAMPLETIME_480: 480 cycles
\param[out] none
\retval none
*/
-void adc_clock_config(uint32_t prescaler)
+void adc_inserted_channel_config(uint32_t adc_periph , uint8_t rank , uint8_t adc_channel , uint32_t sample_time)
{
- ADC_SYNCCTL &= ~((uint32_t)ADC_SYNCCTL_ADCCK);
- ADC_SYNCCTL |= (uint32_t) prescaler;
+ uint8_t inserted_length;
+ uint32_t isq,sampt;
+
+ /* get inserted channel group length */
+ inserted_length = (uint8_t)GET_BITS(ADC_ISQ(adc_periph) , 20U , 21U);
+ /* the channel number is written to these bits to select a channel as the nth conversion in the inserted channel group */
+ if(rank < 4U){
+ isq = ADC_ISQ(adc_periph);
+ isq &= ~((uint32_t)(ADC_ISQ_ISQN << (ADC_INSERTED_CHANNEL_SHIFT_LENGTH-(inserted_length-rank)*ADC_INSERTED_CHANNEL_RANK_LENGTH)));
+ isq |= ((uint32_t)adc_channel << (ADC_INSERTED_CHANNEL_SHIFT_LENGTH-(inserted_length-rank)*ADC_INSERTED_CHANNEL_RANK_LENGTH));
+ ADC_ISQ(adc_periph) = isq;
+ }
+
+ /* ADC sampling time config */
+ if(adc_channel < ADC_CHANNEL_SAMPLE_TEN){
+ /* the inserted group sequence rank is smaller than ten */
+ sampt = ADC_SAMPT1(adc_periph);
+ sampt &= ~((uint32_t)(ADC_SAMPTX_SPTN << (ADC_CHANNEL_SAMPLE_LENGTH*adc_channel)));
+ /* channel sample time set*/
+ sampt |= (uint32_t) sample_time << (ADC_CHANNEL_SAMPLE_LENGTH*adc_channel);
+ ADC_SAMPT1(adc_periph) = sampt;
+ }else if(adc_channel <= ADC_CHANNEL_SAMPLE_EIGHTEEN){
+ /* the inserted group sequence rank is smaller than eighteen */
+ sampt = ADC_SAMPT0(adc_periph);
+ sampt &= ~((uint32_t)(ADC_SAMPTX_SPTN << (ADC_CHANNEL_SAMPLE_LENGTH*(adc_channel - ADC_CHANNEL_SAMPLE_TEN))));
+ /* channel sample time set*/
+ sampt |= ((uint32_t)sample_time << (ADC_CHANNEL_SAMPLE_LENGTH*(adc_channel - ADC_CHANNEL_SAMPLE_TEN)));
+ ADC_SAMPT0(adc_periph) = sampt;
+ }else{
+ }
}
/*!
- \brief configure the ADC clock for all the ADCs
- \param[in] function: temperature sensor and internal reference voltage channel or VBAT channel
- \arg ADC_VBAT_CHANNEL_SWITCH: channel 18 (1/4 voltate of external battery) switch of ADC0
- \arg ADC_TEMP_VREF_CHANNEL_SWITCH: channel 16 (temperature sensor) and 17 (internal reference voltage) switch of ADC0
- \param[in] newvalue: ENABLE or DISABLE
-\param[out] none
+ \brief configure ADC inserted channel offset
+ \param[in] adc_periph: ADCx,x=0,1,2
+ \param[in] inserted_channel : insert channel select
+ only one parameter can be selected which is shown as below:
+ \arg ADC_INSERTED_CHANNEL_0: inserted channel0
+ \arg ADC_INSERTED_CHANNEL_1: inserted channel1
+ \arg ADC_INSERTED_CHANNEL_2: inserted channel2
+ \arg ADC_INSERTED_CHANNEL_3: inserted channel3
+ \param[in] offset : the offset data
+ \param[out] none
\retval none
*/
-void adc_channel_16_to_18(uint8_t function,ControlStatus newvalue)
+void adc_inserted_channel_offset_config(uint32_t adc_periph , uint8_t inserted_channel , uint16_t offset)
{
- if(newvalue){
- switch(function){
- case ADC_VBAT_CHANNEL_SWITCH:
- ADC_SYNCCTL |= (uint32_t)ADC_SYNCCTL_VBATEN;
- break;
- case ADC_TEMP_VREF_CHANNEL_SWITCH:
- ADC_SYNCCTL |= (uint32_t)ADC_SYNCCTL_TSVREN;
- break;
- default:
- break;
- }
- }else{
- switch(function){
- case ADC_VBAT_CHANNEL_SWITCH:
- ADC_SYNCCTL &= ~((uint32_t)ADC_SYNCCTL_VBATEN);
- break;
- case ADC_TEMP_VREF_CHANNEL_SWITCH:
- ADC_SYNCCTL &= ~((uint32_t)ADC_SYNCCTL_TSVREN);
- break;
- default:
- break;
- }
+ uint8_t inserted_length;
+ uint32_t num = 0U;
+
+ inserted_length = (uint8_t)GET_BITS(ADC_ISQ(adc_periph) , 20U , 21U);
+ num = ((uint32_t)ADC_OFFSET_LENGTH - ((uint32_t)inserted_length - (uint32_t)inserted_channel));
+
+ if(num <= ADC_OFFSET_LENGTH){
+ /* calculate the offset of the register */
+ num = num * ADC_OFFSET_SHIFT_LENGTH;
+ /* config the offset of the selected channels */
+ REG32((adc_periph) + 0x14U + num) = IOFFX_IOFF((uint32_t)offset);
}
}
/*!
- \brief config the length of regular channel group or inserted channel group
+ \brief configure ADC external trigger source
\param[in] adc_periph: ADCx,x=0,1,2
\param[in] adc_channel_group: select the channel group
+ only one parameter can be selected which is shown as below:
\arg ADC_REGULAR_CHANNEL: regular channel group
\arg ADC_INSERTED_CHANNEL: inserted channel group
- \param[in] length: the length of the channel
- regular channel 1-16
- inserted channel 1-4
+ \param[in] external_trigger_source: regular or inserted group trigger source
+ for regular channel:
+ only one parameter can be selected which is shown as below:
+ \arg ADC_EXTTRIG_REGULAR_T0_CH0: external trigger timer 0 CC0 event select for regular channel
+ \arg ADC_EXTTRIG_REGULAR_T0_CH1: external trigger timer 0 CC1 event select for regular channel
+ \arg ADC_EXTTRIG_REGULAR_T0_CH2: external trigger timer 0 CC2 event select for regular channel
+ \arg ADC_EXTTRIG_REGULAR_T1_CH1: external trigger timer 1 CC1 event select for regular channel
+ \arg ADC_EXTTRIG_REGULAR_T1_CH2: external trigger timer 1 CC2 event select for regular channel
+ \arg ADC_EXTTRIG_REGULAR_T1_CH3: external trigger timer 1 CC3 event select for regular channel
+ \arg ADC_EXTTRIG_REGULAR_T1_TRGO: external trigger timer 1 TRGO event select for regular channel
+ \arg ADC_EXTTRIG_REGULAR_T2_CH0 : external trigger timer 2 CC0 event select for regular channel
+ \arg ADC_EXTTRIG_REGULAR_T2_TRGO : external trigger timer 2 TRGO event select for regular channel
+ \arg ADC_EXTTRIG_REGULAR_T3_CH3: external trigger timer 3 CC3 event select for regular channel
+ \arg ADC_EXTTRIG_REGULAR_T4_CH0: external trigger timer 4 CC0 event select for regular channel
+ \arg ADC_EXTTRIG_REGULAR_T4_CH1: external trigger timer 4 CC1 event select for regular channel
+ \arg ADC_EXTTRIG_REGULAR_T4_CH2: external trigger timer 4 CC2 event select for regular channel
+ \arg ADC_EXTTRIG_REGULAR_T7_CH0: external trigger timer 7 CC0 event select for regular channel
+ \arg ADC_EXTTRIG_REGULAR_T7_TRGO: external trigger timer 7 TRGO event select for regular channel
+ \arg ADC_EXTTRIG_REGULAR_EXTI_11: external trigger extiline 11 select for regular channel
+ for inserted channel:
+ only one parameter can be selected which is shown as below:
+ \arg ADC_EXTTRIG_INSERTED_T0_CH3: timer0 capture compare 3
+ \arg ADC_EXTTRIG_INSERTED_T0_TRGO: timer0 TRGO event
+ \arg ADC_EXTTRIG_INSERTED_T1_CH0: timer1 capture compare 0
+ \arg ADC_EXTTRIG_INSERTED_T1_TRGO: timer1 TRGO event
+ \arg ADC_EXTTRIG_INSERTED_T2_CH1: timer2 capture compare 1
+ \arg ADC_EXTTRIG_INSERTED_T2_CH3: timer2 capture compare 3
+ \arg ADC_EXTTRIG_INSERTED_T3_CH0: timer3 capture compare 0
+ \arg ADC_EXTTRIG_INSERTED_T3_CH1: timer3 capture compare 1
+ \arg ADC_EXTTRIG_INSERTED_T3_CH2: timer3 capture compare 2
+ \arg ADC_EXTTRIG_INSERTED_T3_TRGO: timer3 capture compare TRGO
+ \arg ADC_EXTTRIG_INSERTED_T4_CH3: timer4 capture compare 3
+ \arg ADC_EXTTRIG_INSERTED_T4_TRGO: timer4 capture compare TRGO
+ \arg ADC_EXTTRIG_INSERTED_T7_CH1: timer7 capture compare 1
+ \arg ADC_EXTTRIG_INSERTED_T7_CH2: timer7 capture compare 2
+ \arg ADC_EXTTRIG_INSERTED_T7_CH3: timer7 capture compare 3
+ \arg ADC_EXTTRIG_INSERTED_EXTI_15: external interrupt line 15
\param[out] none
\retval none
*/
-void adc_channel_length_config(uint32_t adc_periph , uint8_t adc_channel_group , uint32_t length)
+void adc_external_trigger_source_config(uint32_t adc_periph , uint8_t adc_channel_group , uint32_t external_trigger_source)
{
switch(adc_channel_group){
case ADC_REGULAR_CHANNEL:
- if((length >= 1U) && (length <= 16U)){
- ADC_RSQ0(adc_periph) &= ~((uint32_t)ADC_RSQ0_RL);
- ADC_RSQ0(adc_periph) |= (uint32_t)((length-1U) << REGULAR_CHANNEL_LENGTH_OFFSET);
- }
+ /* configure ADC regular group external trigger source */
+ ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_ETSRC);
+ ADC_CTL1(adc_periph) |= (uint32_t)external_trigger_source;
break;
case ADC_INSERTED_CHANNEL:
- if((length >= 1U) && (length <= 4U)){
- ADC_ISQ(adc_periph) &= ~((uint32_t)ADC_ISQ_IL);
- ADC_ISQ(adc_periph) |= (uint32_t)((length-1U) << INSERTED_CHANNEL_LENGTH_OFFSET);
- }
+ /* configure ADC inserted group external trigger source */
+ ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_ETSIC);
+ ADC_CTL1(adc_periph) |= (uint32_t)external_trigger_source;
break;
default:
break;
@@ -298,12 +653,14 @@ void adc_channel_length_config(uint32_t adc_periph , uint8_t adc_channel_group ,
}
/*!
- \brief ADC external trigger enable
+ \brief enable ADC external trigger
\param[in] adc_periph: ADCx,x=0,1,2
\param[in] adc_channel_group: select the channel group
+ only one parameter can be selected which is shown as below:
\arg ADC_REGULAR_CHANNEL: regular channel group
\arg ADC_INSERTED_CHANNEL: inserted channel group
\param[in] trigger_mode: external trigger mode
+ only one parameter can be selected which is shown as below:
\arg EXTERNAL_TRIGGER_DISABLE: external trigger disable
\arg EXTERNAL_TRIGGER_RISING: rising edge of external trigger
\arg EXTERNAL_TRIGGER_FALLING: falling edge of external trigger
@@ -315,10 +672,12 @@ void adc_external_trigger_config(uint32_t adc_periph , uint8_t adc_channel_group
{
switch(adc_channel_group){
case ADC_REGULAR_CHANNEL:
+ /* configure ADC regular channel group external trigger mode */
ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_ETMRC);
ADC_CTL1(adc_periph) |= (uint32_t) (trigger_mode << REGULAR_TRIGGER_MODE);
break;
case ADC_INSERTED_CHANNEL:
+ /* configure ADC inserted channel group external trigger mode */
ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_ETMIC);
ADC_CTL1(adc_periph) |= (uint32_t) (trigger_mode << INSERTED_TRIGGER_MODE);
break;
@@ -328,69 +687,10 @@ void adc_external_trigger_config(uint32_t adc_periph , uint8_t adc_channel_group
}
/*!
- \brief ADC external trigger source config
- \param[in] adc_periph: ADCx,x=0,1,2
- \param[in] adc_channel_group: select the channel group
- \arg ADC_REGULAR_CHANNEL: regular channel group
- \arg ADC_INSERTED_CHANNEL: inserted channel group
- \param[in] external_trigger_source: regular or inserted group trigger source
- for regular channel:
- \arg ADC_EXTTRIG_REGULAR_T0_CH0: external trigger timer 0 CC0 event select for regular channel
- \arg ADC_EXTTRIG_REGULAR_T0_CH1: external trigger timer 0 CC1 event select for regular channel
- \arg ADC_EXTTRIG_REGULAR_T0_CH2: external trigger timer 0 CC2 event select for regular channel
- \arg ADC_EXTTRIG_REGULAR_T1_CH1: external trigger timer 1 CC1 event select for regular channel
- \arg ADC_EXTTRIG_REGULAR_T1_CH2: external trigger timer 1 CC2 event select for regular channel
- \arg ADC_EXTTRIG_REGULAR_T1_CH3: external trigger timer 1 CC3 event select for regular channel
- \arg ADC_EXTTRIG_REGULAR_T1_TRGO: external trigger timer 1 TRGO event select for regular channel
- \arg ADC_EXTTRIG_REGULAR_T2_CH0 : external trigger timer 2 CC0 event select for regular channel
- \arg ADC_EXTTRIG_REGULAR_T2_TRGO : external trigger timer 2 TRGO event select for regular channel
- \arg ADC_EXTTRIG_REGULAR_T3_CH3: external trigger timer 3 CC3 event select for regular channel
- \arg ADC_EXTTRIG_REGULAR_T4_CH0: external trigger timer 4 CC0 event select for regular channel
- \arg ADC_EXTTRIG_REGULAR_T4_CH1: external trigger timer 4 CC1 event select for regular channel
- \arg ADC_EXTTRIG_REGULAR_T4_CH2: external trigger timer 4 CC2 event select for regular channel
- \arg ADC_EXTTRIG_REGULAR_T7_CH0: external trigger timer 7 CC0 event select for regular channel
- \arg ADC_EXTTRIG_REGULAR_T7_TRGO: external trigger timer 7 TRGO event select for regular channel
- \arg ADC_EXTTRIG_REGULAR_EXTI_11: external trigger extiline 11 select for regular channel
- for inserted channel:
- \arg ADC_EXTTRIG_INSERTED_T0_CH3: timer0 capture compare 3
- \arg ADC_EXTTRIG_INSERTED_T0_TRGO: timer0 TRGO event
- \arg ADC_EXTTRIG_INSERTED_T1_CH0: timer1 capture compare 0
- \arg ADC_EXTTRIG_INSERTED_T1_TRGO: timer1 TRGO event
- \arg ADC_EXTTRIG_INSERTED_T2_CH1: timer2 capture compare 1
- \arg ADC_EXTTRIG_INSERTED_T2_CH3: timer2 capture compare 3
- \arg ADC_EXTTRIG_INSERTED_T3_CH0: timer3 capture compare 0
- \arg ADC_EXTTRIG_INSERTED_T3_CH1: timer3 capture compare 1
- \arg ADC_EXTTRIG_INSERTED_T3_CH2: timer3 capture compare 2
- \arg ADC_EXTTRIG_INSERTED_T3_TRGO: timer3 capture compare TRGO
- \arg ADC_EXTTRIG_INSERTED_T4_CH3: timer4 capture compare 3
- \arg ADC_EXTTRIG_INSERTED_T4_TRGO: timer4 capture compare TRGO
- \arg ADC_EXTTRIG_INSERTED_T7_CH1: timer7 capture compare 1
- \arg ADC_EXTTRIG_INSERTED_T7_CH2: timer7 capture compare 2
- \arg ADC_EXTTRIG_INSERTED_T7_CH3: timer7 capture compare 3
- \arg ADC_EXTTRIG_INSERTED_EXTI_15: external interrupt line 15
- \param[out] none
- \retval none
-*/
-void adc_external_trigger_source_config(uint32_t adc_periph , uint8_t adc_channel_group , uint32_t external_trigger_source)
-{
- switch(adc_channel_group){
- case ADC_REGULAR_CHANNEL:
- ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_ETSRC);
- ADC_CTL1(adc_periph) |= (uint32_t)external_trigger_source;
- break;
- case ADC_INSERTED_CHANNEL:
- ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_ETSIC);
- ADC_CTL1(adc_periph) |= (uint32_t)external_trigger_source;
- break;
- default:
- break;
- }
-}
-
-/*!
- \brief ADC software trigger enable
+ \brief enable ADC software trigger
\param[in] adc_periph: ADCx,x=0,1,2
\param[in] adc_channel_group: select the channel group
+ only one parameter can be selected which is shown as below:
\arg ADC_REGULAR_CHANNEL: regular channel group
\arg ADC_INSERTED_CHANNEL: inserted channel group
\param[out] none
@@ -400,9 +700,11 @@ void adc_software_trigger_enable(uint32_t adc_periph , uint8_t adc_channel_group
{
switch(adc_channel_group){
case ADC_REGULAR_CHANNEL:
+ /* enable ADC regular channel group software trigger */
ADC_CTL1(adc_periph) |= (uint32_t)ADC_CTL1_SWRCST;
break;
case ADC_INSERTED_CHANNEL:
+ /* enable ADC inserted channel group software trigger */
ADC_CTL1(adc_periph) |= (uint32_t)ADC_CTL1_SWICST;
break;
default:
@@ -411,173 +713,85 @@ void adc_software_trigger_enable(uint32_t adc_periph , uint8_t adc_channel_group
}
/*!
- \brief get the ADC flag bits
- \param[in] adc_periph: ADCx,x=0,1,2
- \param[in] adc_flag: the adc flag bits
- \arg ADC_FLAG_WDE: analog watchdog event flag
- \arg ADC_FLAG_EOC: end of group conversion flag
- \arg ADC_FLAG_EOIC: end of inserted group conversion flag
- \arg ADC_FLAG_STIC: start flag of inserted channel group
- \arg ADC_FLAG_STRC: start flag of regular channel group
- \arg ADC_FLAG_ROVF: regular data register overflow flag
- \param[out] none
- \retval FlagStatus: SET or RESET
-*/
-FlagStatus adc_flag_get(uint32_t adc_periph , uint32_t adc_flag)
-{
- if(ADC_STAT(adc_periph) & adc_flag){
- return SET;
- }
- return RESET;
-
-}
-
-/*!
- \brief clear the ADC flag bits
+ \brief configure end of conversion mode
\param[in] adc_periph: ADCx,x=0,1,2
- \param[in] adc_flag: the adc flag bits
- \arg ADC_FLAG_WDE: analog watchdog event flag
- \arg ADC_FLAG_EOC: end of group conversion flag
- \arg ADC_FLAG_EOIC: end of inserted group conversion flag
- \arg ADC_FLAG_STIC: start flag of inserted channel group
- \arg ADC_FLAG_STRC: start flag of regular channel group
- \arg ADC_FLAG_ROVF: regular data register overflow flag
+ \param[in] end_selection: end of conversion mode
+ only one parameter can be selected which is shown as below:
+ \arg ADC_EOC_SET_SEQUENCE: only at the end of a sequence of regular conversions, the EOC bit is set.Overflow detection is disabled unless DMA=1.
+ \arg ADC_EOC_SET_CONVERSION: at the end of each regular conversion, the EOC bit is set.Overflow is detected automatically.
\param[out] none
\retval none
*/
-void adc_flag_clear(uint32_t adc_periph , uint32_t adc_flag)
-{
- ADC_STAT(adc_periph) &= ~((uint32_t)adc_flag);
-}
-
-/*!
- \brief get the ADC interrupt bits
- \param[in] adc_periph: ADCx,x=0,1,2
- \param[in] adc_interrupt: the adc interrupt bits
- \arg ADC_INT_WDE: analog watchdog interrupt
- \arg ADC_INT_EOC: end of group conversion interrupt
- \arg ADC_INT_EOIC: end of inserted group conversion interrupt
- \arg ADC_INT_ROVF: regular data register overflow interrupt
- \param[out] none
- \retval FlagStatus: SET or RESET
-*/
-FlagStatus adc_interrupt_flag_get(uint32_t adc_periph , uint32_t adc_interrupt)
+void adc_end_of_conversion_config(uint32_t adc_periph , uint8_t end_selection)
{
- FlagStatus interrupt_flag = RESET;
- uint32_t state;
- /* check the interrupt bits */
- switch(adc_interrupt){
- case ADC_INT_WDE:
- state = ADC_STAT(adc_periph) & ADC_STAT_WDE;
- if((ADC_CTL0(adc_periph) & ADC_CTL0_WDEIE) && state){
- interrupt_flag = SET;
- }
- break;
- case ADC_INT_EOC:
- state = ADC_STAT(adc_periph) & ADC_STAT_EOC;
- if((ADC_CTL0(adc_periph) & ADC_CTL0_EOCIE) && state){
- interrupt_flag = SET;
- }
- break;
- case ADC_INT_EOIC:
- state = ADC_STAT(adc_periph) & ADC_STAT_EOIC;
- if((ADC_CTL0(adc_periph) & ADC_CTL0_EOICIE) && state){
- interrupt_flag = SET;
- }
- break;
- case ADC_INT_ROVF:
- state = ADC_STAT(adc_periph) & ADC_STAT_ROVF;
- if((ADC_CTL0(adc_periph) & ADC_CTL0_ROVFIE) && state){
- interrupt_flag = SET;
- }
- break;
- default:
- break;
+ switch(end_selection){
+ case ADC_EOC_SET_SEQUENCE:
+ /* only at the end of a sequence of regular conversions, the EOC bit is set */
+ ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_EOCM);
+ break;
+ case ADC_EOC_SET_CONVERSION:
+ /* at the end of each regular conversion, the EOC bit is set.Overflow is detected automatically */
+ ADC_CTL1(adc_periph) |= (uint32_t)(ADC_CTL1_EOCM);
+ break;
+ default:
+ break;
}
- return interrupt_flag;
}
/*!
- \brief clear the ADC flag
+ \brief read ADC regular group data register
\param[in] adc_periph: ADCx,x=0,1,2
- \param[in] adc_flag: the adc status flag
- \arg ADC_INT_WDE: analog watchdog interrupt
- \arg ADC_INT_EOC: end of group conversion interrupt
- \arg ADC_INT_EOIC: end of inserted group conversion interrupt
- \arg ADC_INT_ROVF: regular data register overflow interrupt
- \param[out] none
- \retval none
-*/
-void adc_interrupt_flag_clear(uint32_t adc_periph , uint32_t adc_interrupt)
-{
- ADC_STAT(adc_periph) &= ~((uint32_t)adc_interrupt);
-}
-
-/*!
- \brief ADC interrupt enable
- \param[in] adc_periph: ADCx,x=0,1,2
- \param[in] adc_flag: the adc interrupt flag
- \arg ADC_INT_WDE: analog watchdog interrupt flag
- \arg ADC_INT_EOC: end of group conversion interrupt flag
- \arg ADC_INT_EOIC: end of inserted group conversion interrupt flag
- \arg ADC_INT_ROVF: regular data register overflow interrupt flag
+ \param[in] none
\param[out] none
- \retval none
+ \retval the conversion value
*/
-void adc_interrupt_enable(uint32_t adc_periph , uint32_t adc_interrupt)
+uint16_t adc_regular_data_read(uint32_t adc_periph)
{
- switch(adc_interrupt){
- case ADC_INT_WDE:
- ADC_CTL0(adc_periph) |= (uint32_t) ADC_CTL0_WDEIE;
- break;
- case ADC_INT_EOC:
- ADC_CTL0(adc_periph) |= (uint32_t) ADC_CTL0_EOCIE;
- break;
- case ADC_INT_EOIC:
- ADC_CTL0(adc_periph) |= (uint32_t) ADC_CTL0_EOICIE;
- break;
- case ADC_INT_ROVF:
- ADC_CTL0(adc_periph) |= (uint32_t) ADC_CTL0_ROVFIE;
- break;
- default:
- break;
- }
+ return (uint16_t)(ADC_RDATA(adc_periph));
}
/*!
- \brief ADC interrupt disable
+ \brief read ADC inserted group data register
\param[in] adc_periph: ADCx,x=0,1,2
- \param[in] adc_flag: the adc interrupt flag
- \arg ADC_INT_WDE: analog watchdog interrupt flag
- \arg ADC_INT_EOC: end of group conversion interrupt flag
- \arg ADC_INT_EOIC: end of inserted group conversion interrupt flag
- \arg ADC_INT_ROVF: regular data register overflow interrupt flag
+ \param[in] inserted_channel : insert channel select
+ only one parameter can be selected which is shown as below:
+ \arg ADC_INSERTED_CHANNEL_0: inserted Channel0
+ \arg ADC_INSERTED_CHANNEL_1: inserted channel1
+ \arg ADC_INSERTED_CHANNEL_2: inserted Channel2
+ \arg ADC_INSERTED_CHANNEL_3: inserted Channel3
\param[out] none
- \retval none
+ \retval the conversion value
*/
-void adc_interrupt_disable(uint32_t adc_periph , uint32_t adc_interrupt)
+uint16_t adc_inserted_data_read(uint32_t adc_periph , uint8_t inserted_channel)
{
- switch(adc_interrupt){
- /* select the interrupt source */
- case ADC_INT_WDE:
- ADC_CTL0(adc_periph) &= ~((uint32_t)ADC_CTL0_WDEIE);
+ uint32_t idata;
+ /* read the data of the selected channel */
+ switch(inserted_channel){
+ case ADC_INSERTED_CHANNEL_0:
+ /* read the data of channel 0 */
+ idata = ADC_IDATA0(adc_periph);
break;
- case ADC_INT_EOC:
- ADC_CTL0(adc_periph) &= ~((uint32_t)ADC_CTL0_EOCIE);
+ case ADC_INSERTED_CHANNEL_1:
+ /* read the data of channel 1 */
+ idata = ADC_IDATA1(adc_periph);
break;
- case ADC_INT_EOIC:
- ADC_CTL0(adc_periph) &= ~((uint32_t)ADC_CTL0_EOICIE);
+ case ADC_INSERTED_CHANNEL_2:
+ /* read the data of channel 2 */
+ idata = ADC_IDATA2(adc_periph);
break;
- case ADC_INT_ROVF:
- ADC_CTL0(adc_periph) &= ~((uint32_t)ADC_CTL0_ROVFIE);
+ case ADC_INSERTED_CHANNEL_3:
+ /* read the data of channel 3 */
+ idata = ADC_IDATA3(adc_periph);
break;
default:
+ idata = 0U;
break;
}
+ return (uint16_t)idata;
}
/*!
- \brief ADC analog watchdog single channel disable
+ \brief disable ADC analog watchdog single channel
\param[in] adc_periph: ADCx,x=0,1,2
\param[out] none
\retval none
@@ -588,9 +802,10 @@ void adc_watchdog_single_channel_disable(uint32_t adc_periph )
}
/*!
- \brief ADC analog watchdog single channel enable
+ \brief enable ADC analog watchdog single channel
\param[in] adc_periph: ADCx,x=0,1,2
\param[in] adc_channel: the selected ADC channel
+ only one parameter can be selected which is shown as below:
\arg ADC_CHANNEL_x: ADC Channelx(x=0..18)
\param[out] none
\retval none
@@ -599,32 +814,37 @@ void adc_watchdog_single_channel_enable(uint32_t adc_periph , uint8_t adc_channe
{
ADC_CTL0(adc_periph) &= ~((uint32_t)ADC_CTL0_WDCHSEL);
+ /* analog watchdog channel select */
ADC_CTL0(adc_periph) |= (uint32_t)adc_channel;
ADC_CTL0(adc_periph) |= (uint32_t) ADC_CTL0_WDSC;
}
/*!
- \brief adc analog watchdog group channel config
+ \brief configure ADC analog watchdog group channel
\param[in] adc_periph: ADCx,x=0,1,2
- \param[in] adc_channel_group: the channel group use analog watchdog
+ \param[in] adc_channel_group: the channel group use analog watchdog
+ only one parameter can be selected which is shown as below:
\arg ADC_REGULAR_CHANNEL: regular channel group
\arg ADC_INSERTED_CHANNEL: inserted channel group
\arg ADC_REGULAR_INSERTED_CHANNEL: both regular and inserted group
\param[out] none
\retval none
*/
-void adc_watchdog_enable(uint32_t adc_periph , uint8_t adc_channel_group)
+void adc_watchdog_group_channel_enable(uint32_t adc_periph , uint8_t adc_channel_group)
{
ADC_CTL0(adc_periph) &= ~((uint32_t)(ADC_CTL0_RWDEN | ADC_CTL0_IWDEN | ADC_CTL0_WDSC));
/* select the group */
switch(adc_channel_group){
case ADC_REGULAR_CHANNEL:
+ /* regular channel analog watchdog enable */
ADC_CTL0(adc_periph) |= (uint32_t) ADC_CTL0_RWDEN;
break;
case ADC_INSERTED_CHANNEL:
+ /* inserted channel analog watchdog enable */
ADC_CTL0(adc_periph) |= (uint32_t) ADC_CTL0_IWDEN;
break;
case ADC_REGULAR_INSERTED_CHANNEL:
+ /* regular and inserted channel analog watchdog enable */
ADC_CTL0(adc_periph) |= (uint32_t)(ADC_CTL0_RWDEN | ADC_CTL0_IWDEN);
break;
default:
@@ -633,9 +853,10 @@ void adc_watchdog_enable(uint32_t adc_periph , uint8_t adc_channel_group)
}
/*!
- \brief ADC analog watchdog disable
+ \brief disable ADC analog watchdog
\param[in] adc_periph: ADCx,x=0,1,2
- \param[in] adc_channel_group: the channel group use analog watchdog
+ \param[in] adc_channel_group: the channel group use analog watchdog
+ only one parameter can be selected which is shown as below:
\arg ADC_REGULAR_CHANNEL: regular channel group
\arg ADC_INSERTED_CHANNEL: inserted channel group
\arg ADC_REGULAR_INSERTED_CHANNEL: both regular and inserted group
@@ -647,12 +868,15 @@ void adc_watchdog_disable(uint32_t adc_periph , uint8_t adc_channel_group)
/* select the group */
switch(adc_channel_group){
case ADC_REGULAR_CHANNEL:
+ /* disable ADC analog watchdog regular channel group */
ADC_CTL0(adc_periph) &= ~((uint32_t)ADC_CTL0_RWDEN);
break;
case ADC_INSERTED_CHANNEL:
+ /* disable ADC analog watchdog inserted channel group */
ADC_CTL0(adc_periph) &= ~((uint32_t)ADC_CTL0_IWDEN);
break;
case ADC_REGULAR_INSERTED_CHANNEL:
+ /* disable ADC analog watchdog regular and inserted channel group */
ADC_CTL0(adc_periph) &= ~((uint32_t)(ADC_CTL0_RWDEN | ADC_CTL0_IWDEN));
break;
default:
@@ -661,7 +885,7 @@ void adc_watchdog_disable(uint32_t adc_periph , uint8_t adc_channel_group)
}
/*!
- \brief ADC analog watchdog threshold config
+ \brief configure ADC analog watchdog threshold
\param[in] adc_periph: ADCx,x=0,1,2
\param[in] low_threshold: analog watchdog low threshold,0..4095
\param[in] high_threshold: analog watchdog high threshold,0..4095
@@ -670,294 +894,228 @@ void adc_watchdog_disable(uint32_t adc_periph , uint8_t adc_channel_group)
*/
void adc_watchdog_threshold_config(uint32_t adc_periph , uint16_t low_threshold , uint16_t high_threshold)
{
- ADC_WDLT(adc_periph) = (uint32_t)low_threshold;
- ADC_WDHT(adc_periph) = (uint32_t)high_threshold;
+ /* configure ADC analog watchdog low threshold */
+ ADC_WDLT(adc_periph) = (uint32_t)WDLT_WDLT(low_threshold);
+ /* configure ADC analog watchdog high threshold */
+ ADC_WDHT(adc_periph) = (uint32_t)WDHT_WDHT(high_threshold);
}
/*!
- \brief ADC regular channel config
+ \brief get the ADC flag bits
\param[in] adc_periph: ADCx,x=0,1,2
- \param[in] rank: the regular group sequencer rank,this parameter must be between 0 to 15
- \param[in] adc_channel: the selected ADC channel
- \arg ADC_CHANNEL_x(x=0..18): ADC Channelx
- \param[in] sample_time: the sample time value
- \arg ADC_SAMPLETIME_3: 3 cycles
- \arg ADC_SAMPLETIME_15: 15 cycles
- \arg ADC_SAMPLETIME_28: 28 cycles
- \arg ADC_SAMPLETIME_56: 56 cycles
- \arg ADC_SAMPLETIME_84: 84 cycles
- \arg ADC_SAMPLETIME_112: 112 cycles
- \arg ADC_SAMPLETIME_144: 144 cycles
- \arg ADC_SAMPLETIME_480: 480 cycles
+ \param[in] adc_flag: the adc flag bits
+ only one parameter can be selected which is shown as below:
+ \arg ADC_FLAG_WDE: analog watchdog event flag
+ \arg ADC_FLAG_EOC: end of group conversion flag
+ \arg ADC_FLAG_EOIC: end of inserted group conversion flag
+ \arg ADC_FLAG_STIC: start flag of inserted channel group
+ \arg ADC_FLAG_STRC: start flag of regular channel group
+ \arg ADC_FLAG_ROVF: regular data register overflow flag
\param[out] none
- \retval none
+ \retval FlagStatus: SET or RESET
*/
-void adc_regular_channel_config(uint32_t adc_periph , uint8_t rank , uint8_t adc_channel , uint32_t sample_time)
+FlagStatus adc_flag_get(uint32_t adc_periph , uint32_t adc_flag)
{
- uint32_t rsq,sampt;
-
- /* ADC regular sequence config */
- if(rank < 6U){
- rsq = ADC_RSQ2(adc_periph);
- rsq &= ~((uint32_t)(ADC_RSQX_RSQN << (5U*rank)));
- rsq |= ((uint32_t)adc_channel << (5U*rank));
- ADC_RSQ2(adc_periph) = rsq;
- }else if(rank < 12U){
- rsq = ADC_RSQ1(adc_periph);
- rsq &= ~((uint32_t)(ADC_RSQX_RSQN << (5U*(rank-6U))));
- rsq |= ((uint32_t)adc_channel << (5U*(rank-6U)));
- ADC_RSQ1(adc_periph) = rsq;
- }else if(rank < 16U){
- rsq = ADC_RSQ0(adc_periph);
- rsq &= ~((uint32_t)(ADC_RSQX_RSQN << (5U*(rank-12U))));
- rsq |= ((uint32_t)adc_channel << (5U*(rank-12U)));
- ADC_RSQ0(adc_periph) = rsq;
- }else{
- }
-
- /* ADC sampling time config */
- if(adc_channel < 10U){
- sampt = ADC_SAMPT1(adc_periph);
- sampt &= ~((uint32_t)(ADC_SAMPTX_SPTN << (3U*adc_channel)));
- sampt |= (uint32_t)(sample_time << (3U*adc_channel));
- ADC_SAMPT1(adc_periph) = sampt;
- }else if(adc_channel < 19U){
- sampt = ADC_SAMPT0(adc_periph);
- sampt &= ~((uint32_t)(ADC_SAMPTX_SPTN << (3U*(adc_channel-10U))));
- sampt |= (uint32_t)(sample_time << (3U*(adc_channel-10U)));
- ADC_SAMPT0(adc_periph) = sampt;
- }else{
+ FlagStatus reval = RESET;
+ if(ADC_STAT(adc_periph) & adc_flag){
+ reval = SET;
}
+ return reval;
+
}
/*!
- \brief ADC regular group data register read
+ \brief clear the ADC flag bits
\param[in] adc_periph: ADCx,x=0,1,2
- \param[in] none
+ \param[in] adc_flag: the adc flag bits
+ only one parameter can be selected which is shown as below:
+ \arg ADC_FLAG_WDE: analog watchdog event flag
+ \arg ADC_FLAG_EOC: end of group conversion flag
+ \arg ADC_FLAG_EOIC: end of inserted group conversion flag
+ \arg ADC_FLAG_STIC: start flag of inserted channel group
+ \arg ADC_FLAG_STRC: start flag of regular channel group
+ \arg ADC_FLAG_ROVF: regular data register overflow flag
\param[out] none
- \retval the conversion value
+ \retval none
*/
-uint16_t adc_regular_data_read(uint32_t adc_periph)
+void adc_flag_clear(uint32_t adc_periph , uint32_t adc_flag)
{
- return (uint16_t)(ADC_RDATA(adc_periph));
+ ADC_STAT(adc_periph) &= ~((uint32_t)adc_flag);
}
/*!
- \brief ADC inserted channel config
- \param[in] adc_periph: ADCx,x=0,1,2
- \param[in] rank: the inserted group sequencer rank,this parameter must be between 0 to 3
- \param[in] adc_channel: the selected ADC channel
- \arg ADC_CHANNEL_x(x=0..18): ADC Channelx
- \param[in] sample_time: The sample time value
- \arg ADC_SAMPLETIME_3: 3 cycles
- \arg ADC_SAMPLETIME_15: 15 cycles
- \arg ADC_SAMPLETIME_28: 28 cycles
- \arg ADC_SAMPLETIME_56: 56 cycles
- \arg ADC_SAMPLETIME_84: 84 cycles
- \arg ADC_SAMPLETIME_112: 112 cycles
- \arg ADC_SAMPLETIME_144: 144 cycles
- \arg ADC_SAMPLETIME_480: 480 cycles
+ \brief get the bit state of ADCx software start conversion
+ \param[in] adc_periph: ADCx, x=0,1,2 only one among these parameters can be selected
+ \param[in] none
\param[out] none
- \retval none
+ \retval FlagStatus: SET or RESET
*/
-void adc_inserted_channel_config(uint32_t adc_periph , uint8_t rank , uint8_t adc_channel , uint8_t sample_time)
+FlagStatus adc_regular_software_startconv_flag_get(uint32_t adc_periph)
{
- uint8_t inserted_length;
- uint32_t isq,sampt;
-
- inserted_length = (uint8_t)GET_BITS(ADC_ISQ(adc_periph) , 20U , 21U);
- if(rank < 4U){
- isq = ADC_ISQ(adc_periph);
- isq &= ~((uint32_t)(ADC_ISQ_ISQN << (15U-(inserted_length-rank)*5U)));
- isq |= ((uint32_t)adc_channel << (15U-(inserted_length-rank)*5U));
- ADC_ISQ(adc_periph) = isq;
- }
-
- if(adc_channel < 10U){
- sampt = ADC_SAMPT1(adc_periph);
- sampt &= ~((uint32_t)(ADC_SAMPTX_SPTN << (3U*adc_channel)));
- sampt |= (uint32_t) sample_time << (3U*adc_channel);
- ADC_SAMPT1(adc_periph) = sampt;
- }else if(adc_channel < 19U){
- sampt = ADC_SAMPT0(adc_periph);
- sampt &= ~((uint32_t)(ADC_SAMPTX_SPTN << (3U*(adc_channel-10U))));
- sampt |= ((uint32_t)sample_time << (3U*(adc_channel-10U)));
- ADC_SAMPT0(adc_periph) = sampt;
- }else{
+ FlagStatus reval = RESET;
+ if((uint32_t)RESET != (ADC_STAT(adc_periph) & ADC_STAT_STRC)){
+ reval = SET;
}
+ return reval;
}
/*!
- \brief ADC inserted channel offset config
- \param[in] adc_periph: ADCx,x=0,1,2
- \param[in] inserted_channel : insert channel select
- \arg ADC_INSERTED_CHANNEL_0: inserted channel0
- \arg ADC_INSERTED_CHANNEL_1: inserted channel1
- \arg ADC_INSERTED_CHANNEL_2: inserted channel2
- \arg ADC_INSERTED_CHANNEL_3: inserted channel3
- \param[in] offset : the offset data
+ \brief get the bit state of ADCx software inserted channel start conversion
+ \param[in] adc_periph: ADCx, x=0,1,2 only one among these parameters can be selected
+ \param[in] none
\param[out] none
- \retval the conversion value
+ \retval FlagStatus: SET or RESET
*/
-void adc_inserted_channel_offset_config(uint32_t adc_periph , uint8_t inserted_channel , uint16_t offset)
+FlagStatus adc_inserted_software_startconv_flag_get(uint32_t adc_periph)
{
- /* config the offset of the selected channels */
- if(ADC_INSERTED_CHANNEL_0 == inserted_channel){
- ADC_IOFF0(adc_periph) = (uint32_t)offset;
- }else if(ADC_INSERTED_CHANNEL_1 == inserted_channel){
- ADC_IOFF1(adc_periph) = (uint32_t)offset;
- }else if(ADC_INSERTED_CHANNEL_2 == inserted_channel){
- ADC_IOFF2(adc_periph) = (uint32_t)offset;
- }else if(ADC_INSERTED_CHANNEL_3 == inserted_channel){
- ADC_IOFF3(adc_periph) = (uint32_t)offset;
- }else{
- }
+ FlagStatus reval = RESET;
+ if((uint32_t)RESET != (ADC_STAT(adc_periph) & ADC_STAT_STIC)){
+ reval = SET;
+ }
+ return reval;
}
/*!
- \brief ADC inserted group data register read
+ \brief get the ADC interrupt bits
\param[in] adc_periph: ADCx,x=0,1,2
- \param[in] inserted_channel : insert channel select
- \arg ADC_INSERTED_CHANNEL_0: inserted Channel0
- \arg ADC_INSERTED_CHANNEL_1: inserted channel1
- \arg ADC_INSERTED_CHANNEL_2: inserted Channel2
- \arg ADC_INSERTED_CHANNEL_3: inserted Channel3
+ \param[in] adc_interrupt: the adc interrupt bits
+ only one parameter can be selected which is shown as below:
+ \arg ADC_INT_FLAG_WDE: analog watchdog interrupt
+ \arg ADC_INT_FLAG_EOC: end of group conversion interrupt
+ \arg ADC_INT_FLAG_EOIC: end of inserted group conversion interrupt
+ \arg ADC_INT_FLAG_ROVF: regular data register overflow interrupt
\param[out] none
- \retval the conversion value
+ \retval FlagStatus: SET or RESET
*/
-uint16_t adc_inserted_data_read(uint32_t adc_periph , uint8_t inserted_channel)
+FlagStatus adc_interrupt_flag_get(uint32_t adc_periph , uint32_t adc_interrupt)
{
- uint32_t idata;
- /* read the data of the selected channel */
- switch(inserted_channel){
- case ADC_INSERTED_CHANNEL_0:
- idata = ADC_IDATA0(adc_periph);
+ FlagStatus interrupt_flag = RESET;
+ uint32_t state;
+ /* check the interrupt bits */
+ switch(adc_interrupt){
+ case ADC_INT_FLAG_WDE:
+ /* get the ADC analog watchdog interrupt bits */
+ state = ADC_STAT(adc_periph) & ADC_STAT_WDE;
+ if((ADC_CTL0(adc_periph) & ADC_CTL0_WDEIE) && state){
+ interrupt_flag = SET;
+ }
break;
- case ADC_INSERTED_CHANNEL_1:
- idata = ADC_IDATA1(adc_periph);
+ case ADC_INT_FLAG_EOC:
+ /* get the ADC end of group conversion interrupt bits */
+ state = ADC_STAT(adc_periph) & ADC_STAT_EOC;
+ if((ADC_CTL0(adc_periph) & ADC_CTL0_EOCIE) && state){
+ interrupt_flag = SET;
+ }
break;
- case ADC_INSERTED_CHANNEL_2:
- idata = ADC_IDATA2(adc_periph);
+ case ADC_INT_FLAG_EOIC:
+ /* get the ADC end of inserted group conversion interrupt bits */
+ state = ADC_STAT(adc_periph) & ADC_STAT_EOIC;
+ if((ADC_CTL0(adc_periph) & ADC_CTL0_EOICIE) && state){
+ interrupt_flag = SET;
+ }
break;
- case ADC_INSERTED_CHANNEL_3:
- idata = ADC_IDATA3(adc_periph);
+ case ADC_INT_FLAG_ROVF:
+ /* get the ADC regular data register overflow interrupt bits */
+ state = ADC_STAT(adc_periph) & ADC_STAT_ROVF;
+ if((ADC_CTL0(adc_periph) & ADC_CTL0_ROVFIE) && state){
+ interrupt_flag = SET;
+ }
break;
default:
- idata = 0U;
break;
}
- return (uint16_t)idata;
-}
-
-/*!
- \brief DMA request enable
- \param[in] adc_periph: ADCx,x=0,1,2
- \param[out] none
- \retval none
-*/
-void adc_dma_mode_enable(uint32_t adc_periph)
-{
- ADC_CTL1(adc_periph) |= (uint32_t)(ADC_CTL1_DMA);
-}
-
-/*!
- \brief DMA request disable
- \param[in] adc_periph: ADCx,x=0,1,2
- \param[out] none
- \retval none
-*/
-void adc_dma_mode_disable(uint32_t adc_periph)
-{
- ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_DMA);
-}
-
-/*!
- \brief when DMA=1, the DMA engine issues a request at end of each regular conversion
- \param[in] adc_periph: ADCx,x=0,1,2
- \param[out] none
- \retval none
-*/
-void adc_dma_request_after_last_enable(uint32_t adc_periph)
-{
- ADC_CTL1(adc_periph) |= (uint32_t)(ADC_CTL1_DDM);
+ return interrupt_flag;
}
/*!
- \brief the DMA engine is disabled after the end of transfer signal from DMA controller is detected
+ \brief clear the ADC flag
\param[in] adc_periph: ADCx,x=0,1,2
+ \param[in] adc_interrupt: the adc status flag
+ only one parameter can be selected which is shown as below:
+ \arg ADC_INT_FLAG_WDE: analog watchdog interrupt
+ \arg ADC_INT_FLAG_EOC: end of group conversion interrupt
+ \arg ADC_INT_FLAG_EOIC: end of inserted group conversion interrupt
+ \arg ADC_INT_FLAG_ROVF: regular data register overflow interrupt
\param[out] none
\retval none
*/
-void adc_dma_request_after_last_disable(uint32_t adc_periph)
+void adc_interrupt_flag_clear(uint32_t adc_periph , uint32_t adc_interrupt)
{
- ADC_CTL1(adc_periph) &= ~((uint32_t)ADC_CTL1_DDM);
+ ADC_STAT(adc_periph) &= ~((uint32_t)adc_interrupt);
}
/*!
- \brief ADC oversample mode config
+ \brief enable ADC interrupt
\param[in] adc_periph: ADCx,x=0,1,2
- \param[in] mode: ADC oversampling mode
- \arg ADC_OVERSAMPLING_ALL_CONVERT: all oversampled conversions for a channel are done consecutively after a trigger
- \arg ADC_OVERSAMPLING_ONE_CONVERT: each oversampled conversion for a channel needs a trigger
- \param[in] shift: ADC oversampling shift
- \arg ADC_OVERSAMPLING_SHIFT_NONE: no oversampling shift
- \arg ADC_OVERSAMPLING_SHIFT_1B: 1-bit oversampling shift
- \arg ADC_OVERSAMPLING_SHIFT_2B: 2-bit oversampling shift
- \arg ADC_OVERSAMPLING_SHIFT_3B: 3-bit oversampling shift
- \arg ADC_OVERSAMPLING_SHIFT_4B: 3-bit oversampling shift
- \arg ADC_OVERSAMPLING_SHIFT_5B: 5-bit oversampling shift
- \arg ADC_OVERSAMPLING_SHIFT_6B: 6-bit oversampling shift
- \arg ADC_OVERSAMPLING_SHIFT_7B: 7-bit oversampling shift
- \arg ADC_OVERSAMPLING_SHIFT_8B: 8-bit oversampling shift
- \param[in] ratio: ADC oversampling ratio
- \arg ADC_OVERSAMPLING_RATIO_MUL2: oversampling ratio multiple 2
- \arg ADC_OVERSAMPLING_RATIO_MUL4: oversampling ratio multiple 4
- \arg ADC_OVERSAMPLING_RATIO_MUL8: oversampling ratio multiple 8
- \arg ADC_OVERSAMPLING_RATIO_MUL16: oversampling ratio multiple 16
- \arg ADC_OVERSAMPLING_RATIO_MUL32: oversampling ratio multiple 32
- \arg ADC_OVERSAMPLING_RATIO_MUL64: oversampling ratio multiple 64
- \arg ADC_OVERSAMPLING_RATIO_MUL128: oversampling ratio multiple 128
- \arg ADC_OVERSAMPLING_RATIO_MUL256: oversampling ratio multiple 256
+ \param[in] adc_interrupt: the adc interrupt flag
+ only one parameter can be selected which is shown as below:
+ \arg ADC_INT_WDE: analog watchdog interrupt flag
+ \arg ADC_INT_EOC: end of group conversion interrupt flag
+ \arg ADC_INT_EOIC: end of inserted group conversion interrupt flag
+ \arg ADC_INT_ROVF: regular data register overflow interrupt flag
\param[out] none
\retval none
*/
-void adc_oversample_mode_config(uint32_t adc_periph , uint8_t mode , uint16_t shift , uint8_t ratio)
+void adc_interrupt_enable(uint32_t adc_periph , uint32_t adc_interrupt)
{
- if(ADC_OVERSAMPLING_ONE_CONVERT == mode){
- ADC_OVSAMPCTL(adc_periph) |= (uint32_t)ADC_OVSAMPCTL_TOVS;
- }else{
- ADC_OVSAMPCTL(adc_periph) &= ~((uint32_t)ADC_OVSAMPCTL_TOVS);
+ switch(adc_interrupt){
+ case ADC_INT_WDE:
+ /* enable analog watchdog interrupt */
+ ADC_CTL0(adc_periph) |= (uint32_t) ADC_CTL0_WDEIE;
+ break;
+ case ADC_INT_EOC:
+ /* enable end of group conversion interrupt */
+ ADC_CTL0(adc_periph) |= (uint32_t) ADC_CTL0_EOCIE;
+ break;
+ case ADC_INT_EOIC:
+ /* enable end of inserted group conversion interrupt */
+ ADC_CTL0(adc_periph) |= (uint32_t) ADC_CTL0_EOICIE;
+ break;
+ case ADC_INT_ROVF:
+ ADC_CTL0(adc_periph) |= (uint32_t) ADC_CTL0_ROVFIE;
+ break;
+ default:
+ break;
}
- /* config the shift and ratio */
- ADC_OVSAMPCTL(adc_periph) &= ~((uint32_t)(ADC_OVSAMPCTL_OVSR | ADC_OVSAMPCTL_OVSS));
- ADC_OVSAMPCTL(adc_periph) |= ((uint32_t)shift | (uint32_t)ratio);
-}
-
-/*!
- \brief ADC oversample mode enable
- \param[in] adc_periph: ADCx,x=0,1,2
- \param[out] none
- \retval none
-*/
-void adc_oversample_mode_enable(uint32_t adc_periph)
-{
- ADC_OVSAMPCTL(adc_periph) |= ADC_OVSAMPCTL_OVSEN;
}
/*!
- \brief ADC oversample mode disable
+ \brief disable ADC interrupt
\param[in] adc_periph: ADCx,x=0,1,2
+ \param[in] adc_flag: the adc interrupt flag
+ only one parameter can be selected which is shown as below:
+ \arg ADC_INT_WDE: analog watchdog interrupt flag
+ \arg ADC_INT_EOC: end of group conversion interrupt flag
+ \arg ADC_INT_EOIC: end of inserted group conversion interrupt flag
+ \arg ADC_INT_ROVF: regular data register overflow interrupt flag
\param[out] none
\retval none
*/
-void adc_oversample_mode_disable(uint32_t adc_periph)
+void adc_interrupt_disable(uint32_t adc_periph , uint32_t adc_interrupt)
{
- ADC_OVSAMPCTL(adc_periph) &= ~((uint32_t)ADC_OVSAMPCTL_OVSEN);
+ switch(adc_interrupt){
+ /* select the interrupt source */
+ case ADC_INT_WDE:
+ ADC_CTL0(adc_periph) &= ~((uint32_t)ADC_CTL0_WDEIE);
+ break;
+ case ADC_INT_EOC:
+ ADC_CTL0(adc_periph) &= ~((uint32_t)ADC_CTL0_EOCIE);
+ break;
+ case ADC_INT_EOIC:
+ ADC_CTL0(adc_periph) &= ~((uint32_t)ADC_CTL0_EOICIE);
+ break;
+ case ADC_INT_ROVF:
+ ADC_CTL0(adc_periph) &= ~((uint32_t)ADC_CTL0_ROVFIE);
+ break;
+ default:
+ break;
+ }
}
/*!
\brief configure the ADC sync mode
- \param[in] sync_mode: ADC sync mode
+ \param[in] sync_mode: ADC sync mode
+ only one parameter can be selected which is shown as below:
\arg ADC_SYNC_MODE_INDEPENDENT: all the ADCs work independently
\arg ADC_DAUL_REGULAL_PARALLEL_INSERTED_PARALLEL: ADC0 and ADC1 work in combined regular parallel & inserted parallel mode
\arg ADC_DAUL_REGULAL_PARALLEL_INSERTED_ROTATION: ADC0 and ADC1 work in combined regular parallel & trigger rotation mode
@@ -982,7 +1140,8 @@ void adc_sync_mode_config(uint32_t sync_mode)
/*!
\brief configure the delay between 2 sampling phases in ADC sync modes
- \param[in] sample_delay: the delay between 2 sampling phases in ADC sync modes
+ \param[in] sample_delay: the delay between 2 sampling phases in ADC sync modes
+ only one parameter can be selected which is shown as below:
\arg ADC_SYNC_DELAY_xCYCLE: x=5..20,the delay between 2 sampling phases in ADC sync modes is x ADC clock cycles
\param[out] none
\retval none
@@ -996,9 +1155,10 @@ void adc_sync_delay_config(uint32_t sample_delay)
/*!
\brief configure ADC sync DMA mode selection
\param[in] dma_mode: ADC sync DMA mode
+ only one parameter can be selected which is shown as below:
\arg ADC_SYNC_DMA_DISABLE: ADC sync DMA disabled
- \arg ADC_SYNC_DMA_MODE0: ADC sync DMA disabled
- \arg ADC_SYNC_DMA_MODE1: ADC sync DMA disabled
+ \arg ADC_SYNC_DMA_MODE0: ADC sync DMA mode 0
+ \arg ADC_SYNC_DMA_MODE1: ADC sync DMA mode 1
\param[out] none
\retval none
*/
@@ -1031,7 +1191,7 @@ void adc_sync_dma_request_after_last_disable(void)
}
/*!
- \brief ADC sync regular data register read
+ \brief read ADC sync regular data register
\param[in] none
\param[out] none
\retval sync regular data
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_can.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_can.c
index eb03822acf..5eb2974739 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_can.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_can.c
@@ -1,18 +1,47 @@
/*!
- \file gd32f4xx_can.c
- \brief CAN driver
+ \file gd32f4xx_can.c
+ \brief CAN driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2019-11-27, V2.0.1, firmware for GD32F4xx
+ \version 2020-07-14, V2.0.2, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#include "gd32f4xx_can.h"
+#define CAN_ERROR_HANDLE(s) do{}while(1)
+
/*!
- \brief deinitialize CAN
+ \brief deinitialize CAN
\param[in] can_periph
\arg CANx(x=0,1)
\param[out] none
@@ -30,21 +59,100 @@ void can_deinit(uint32_t can_periph)
}
/*!
+ \brief initialize CAN parameter struct with a default value
+ \param[in] type: the type of CAN parameter struct
+ only one parameter can be selected which is shown as below:
+ \arg CAN_INIT_STRUCT: the CAN initial struct
+ \arg CAN_FILTER_STRUCT: the CAN filter struct
+ \arg CAN_TX_MESSAGE_STRUCT: the CAN TX message struct
+ \arg CAN_RX_MESSAGE_STRUCT: the CAN RX message struct
+ \param[in] p_struct: the pointer of the specific struct
+ \param[out] none
+ \retval none
+*/
+void can_struct_para_init(can_struct_type_enum type, void* p_struct)
+{
+ uint8_t i;
+
+ /* get type of the struct */
+ switch(type){
+ /* used for can_init() */
+ case CAN_INIT_STRUCT:
+ ((can_parameter_struct*)p_struct)->auto_bus_off_recovery = DISABLE;
+ ((can_parameter_struct*)p_struct)->no_auto_retrans = DISABLE;
+ ((can_parameter_struct*)p_struct)->auto_wake_up = DISABLE;
+ ((can_parameter_struct*)p_struct)->prescaler = 0x03FFU;
+ ((can_parameter_struct*)p_struct)->rec_fifo_overwrite = DISABLE;
+ ((can_parameter_struct*)p_struct)->resync_jump_width = CAN_BT_SJW_1TQ;
+ ((can_parameter_struct*)p_struct)->time_segment_1 = CAN_BT_BS1_3TQ;
+ ((can_parameter_struct*)p_struct)->time_segment_2 = CAN_BT_BS2_1TQ;
+ ((can_parameter_struct*)p_struct)->time_triggered = DISABLE;
+ ((can_parameter_struct*)p_struct)->trans_fifo_order = DISABLE;
+ ((can_parameter_struct*)p_struct)->working_mode = CAN_NORMAL_MODE;
+
+ break;
+ /* used for can_filter_init() */
+ case CAN_FILTER_STRUCT:
+ ((can_filter_parameter_struct*)p_struct)->filter_bits = CAN_FILTERBITS_32BIT;
+ ((can_filter_parameter_struct*)p_struct)->filter_enable = DISABLE;
+ ((can_filter_parameter_struct*)p_struct)->filter_fifo_number = CAN_FIFO0;
+ ((can_filter_parameter_struct*)p_struct)->filter_list_high = 0x0000U;
+ ((can_filter_parameter_struct*)p_struct)->filter_list_low = 0x0000U;
+ ((can_filter_parameter_struct*)p_struct)->filter_mask_high = 0x0000U;
+ ((can_filter_parameter_struct*)p_struct)->filter_mask_low = 0x0000U;
+ ((can_filter_parameter_struct*)p_struct)->filter_mode = CAN_FILTERMODE_MASK;
+ ((can_filter_parameter_struct*)p_struct)->filter_number = 0U;
+
+ break;
+ /* used for can_message_transmit() */
+ case CAN_TX_MESSAGE_STRUCT:
+ for(i = 0U; i < 8U; i++){
+ ((can_trasnmit_message_struct*)p_struct)->tx_data[i] = 0U;
+ }
+
+ ((can_trasnmit_message_struct*)p_struct)->tx_dlen = 0u;
+ ((can_trasnmit_message_struct*)p_struct)->tx_efid = 0U;
+ ((can_trasnmit_message_struct*)p_struct)->tx_ff = (uint8_t)CAN_FF_STANDARD;
+ ((can_trasnmit_message_struct*)p_struct)->tx_ft = (uint8_t)CAN_FT_DATA;
+ ((can_trasnmit_message_struct*)p_struct)->tx_sfid = 0U;
+
+ break;
+ /* used for can_message_receive() */
+ case CAN_RX_MESSAGE_STRUCT:
+ for(i = 0U; i < 8U; i++){
+ ((can_receive_message_struct*)p_struct)->rx_data[i] = 0U;
+ }
+
+ ((can_receive_message_struct*)p_struct)->rx_dlen = 0U;
+ ((can_receive_message_struct*)p_struct)->rx_efid = 0U;
+ ((can_receive_message_struct*)p_struct)->rx_ff = (uint8_t)CAN_FF_STANDARD;
+ ((can_receive_message_struct*)p_struct)->rx_fi = 0U;
+ ((can_receive_message_struct*)p_struct)->rx_ft = (uint8_t)CAN_FT_DATA;
+ ((can_receive_message_struct*)p_struct)->rx_sfid = 0U;
+
+ break;
+
+ default:
+ CAN_ERROR_HANDLE("parameter is invalid \r\n");
+ }
+}
+
+/*!
\brief initialize CAN
\param[in] can_periph
\arg CANx(x=0,1)
- \param[in] can_parameter_struct: parameters for CAN initializtion
- can_mode: CAN_NORMAL_MODE, CAN_LOOPBACK_MODE, CAN_SILENT_MODE, CAN_SILENT_LOOPBACK_MODE
- can_sjw: CAN_BT_SJW_xTQ(x=1, 2, 3, 4)
- can_bs1: CAN_BT_BS1_xTQ(1..16)
- can_bs2: CAN_BT_BS2_xTQ(1..8)
- can_ttc: ENABLE or DISABLE
- can_abor: ENABLE or DISABLE
- can_awu: ENABLE or DISABLE
- can_ard: ENABLE or DISABLE
- can_rfod: ENABLE or DISABLE
- can_tfo: ENABLE or DISABLE
- can_psc: 0x0001 - 0x03FF
+ \param[in] can_parameter_init: parameters for CAN initializtion
+ \arg working_mode: CAN_NORMAL_MODE, CAN_LOOPBACK_MODE, CAN_SILENT_MODE, CAN_SILENT_LOOPBACK_MODE
+ \arg resync_jump_width: CAN_BT_SJW_xTQ(x=1, 2, 3, 4)
+ \arg time_segment_1: CAN_BT_BS1_xTQ(1..16)
+ \arg time_segment_2: CAN_BT_BS2_xTQ(1..8)
+ \arg time_triggered: ENABLE or DISABLE
+ \arg auto_bus_off_recovery: ENABLE or DISABLE
+ \arg auto_wake_up: ENABLE or DISABLE
+ \arg no_auto_retrans: ENABLE or DISABLE
+ \arg rec_fifo_overwrite: ENABLE or DISABLE
+ \arg trans_fifo_order: ENABLE or DISABLE
+ \arg prescaler: 0x0001 - 0x0400
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
*/
@@ -52,19 +160,19 @@ ErrStatus can_init(uint32_t can_periph, can_parameter_struct* can_parameter_init
{
uint32_t timeout = CAN_TIMEOUT;
ErrStatus flag = ERROR;
-
+
/* disable sleep mode */
CAN_CTL(can_periph) &= ~CAN_CTL_SLPWMOD;
/* enable initialize mode */
CAN_CTL(can_periph) |= CAN_CTL_IWMOD;
/* wait ACK */
- while((CAN_STAT_IWS != (CAN_STAT(can_periph) & CAN_STAT_IWS)) && (timeout)){
+ while((CAN_STAT_IWS != (CAN_STAT(can_periph) & CAN_STAT_IWS)) && (0U != timeout)){
timeout--;
}
/* check initialize working success */
if(CAN_STAT_IWS != (CAN_STAT(can_periph) & CAN_STAT_IWS)){
flag = ERROR;
- } else {
+ }else{
/* set the bit timing register */
CAN_BT(can_periph) = (BT_MODE((uint32_t)can_parameter_init->working_mode) | \
BT_SJW((uint32_t)can_parameter_init->resync_jump_width) | \
@@ -89,64 +197,64 @@ ErrStatus can_init(uint32_t can_periph, can_parameter_struct* can_parameter_init
}else{
CAN_CTL(can_periph) &= ~CAN_CTL_AWU;
}
- /* automatic retransmission mode */
- if(ENABLE == can_parameter_init->auto_retrans){
+ /* automatic retransmission mode disable*/
+ if(ENABLE == can_parameter_init->no_auto_retrans){
CAN_CTL(can_periph) |= CAN_CTL_ARD;
}else{
CAN_CTL(can_periph) &= ~CAN_CTL_ARD;
}
- /* receive fifo overwrite mode */
+ /* receive fifo overwrite mode */
if(ENABLE == can_parameter_init->rec_fifo_overwrite){
CAN_CTL(can_periph) |= CAN_CTL_RFOD;
}else{
CAN_CTL(can_periph) &= ~CAN_CTL_RFOD;
- }
+ }
/* transmit fifo order */
if(ENABLE == can_parameter_init->trans_fifo_order){
CAN_CTL(can_periph) |= CAN_CTL_TFO;
}else{
CAN_CTL(can_periph) &= ~CAN_CTL_TFO;
- }
+ }
/* disable initialize mode */
CAN_CTL(can_periph) &= ~CAN_CTL_IWMOD;
timeout = CAN_TIMEOUT;
/* wait the ACK */
- while((CAN_STAT_IWS == (CAN_STAT(can_periph) & CAN_STAT_IWS)) && (timeout)){
+ while((CAN_STAT_IWS == (CAN_STAT(can_periph) & CAN_STAT_IWS)) && (0U != timeout)){
timeout--;
}
/* check exit initialize mode */
if(CAN_STAT_IWS == (CAN_STAT(can_periph) & CAN_STAT_IWS)){
flag = SUCCESS;
}
- }
+ }
return flag;
}
/*!
- \brief initialize CAN filter
- \param[in] can_filter_parameter_struct: struct for CAN filter initialization
- can_filter_list_high: 0x0000 - 0xFFFF
- can_filter_list_low: 0x0000 - 0xFFFF
- can_filter_mask_high: 0x0000 - 0xFFFF
- can_filter_mask_low: 0x0000 - 0xFFFF
- can_filter_fifo_number: CAN_FIFO0, CAN_FIFO1
- can_filter_number: 0 - 27
- can_filter_mode: CAN_FILTERMODE_MASK, CAN_FILTERMODE_LIST
- can_filter_bits: CAN_FILTERBITS_32BIT, CAN_FILTERBITS_16BIT
- can_filter_enable: ENABLE or DISABLE
+ \brief initialize CAN filter
+ \param[in] can_filter_parameter_init: struct for CAN filter initialization
+ \arg filter_list_high: 0x0000 - 0xFFFF
+ \arg filter_list_low: 0x0000 - 0xFFFF
+ \arg filter_mask_high: 0x0000 - 0xFFFF
+ \arg filter_mask_low: 0x0000 - 0xFFFF
+ \arg filter_fifo_number: CAN_FIFO0, CAN_FIFO1
+ \arg filter_number: 0 - 27
+ \arg filter_mode: CAN_FILTERMODE_MASK, CAN_FILTERMODE_LIST
+ \arg filter_bits: CAN_FILTERBITS_32BIT, CAN_FILTERBITS_16BIT
+ \arg filter_enable: ENABLE or DISABLE
\param[out] none
\retval none
*/
void can_filter_init(can_filter_parameter_struct* can_filter_parameter_init)
{
uint32_t val = 0U;
-
+
val = ((uint32_t)1) << (can_filter_parameter_init->filter_number);
/* filter lock disable */
CAN_FCTL(CAN0) |= CAN_FCTL_FLD;
/* disable filter */
CAN_FW(CAN0) &= ~(uint32_t)val;
-
+
/* filter 16 bits */
if(CAN_FILTERBITS_16BIT == can_filter_parameter_init->filter_bits){
/* set filter 16 bits */
@@ -173,7 +281,7 @@ void can_filter_init(can_filter_parameter_struct* can_filter_parameter_init)
FDATA_MASK_HIGH((can_filter_parameter_init->filter_mask_high) & CAN_FILTER_MASK_16BITS) |
FDATA_MASK_LOW((can_filter_parameter_init->filter_mask_low) & CAN_FILTER_MASK_16BITS);
}
-
+
/* filter mode */
if(CAN_FILTERMODE_MASK == can_filter_parameter_init->filter_mode){
/* mask mode */
@@ -182,24 +290,24 @@ void can_filter_init(can_filter_parameter_struct* can_filter_parameter_init)
/* list mode */
CAN_FMCFG(CAN0) |= (uint32_t)val;
}
-
+
/* filter FIFO */
if(CAN_FIFO0 == (can_filter_parameter_init->filter_fifo_number)){
/* FIFO0 */
CAN_FAFIFO(CAN0) &= ~(uint32_t)val;
}
-
+
if(CAN_FIFO1 == can_filter_parameter_init->filter_fifo_number){
/* FIFO1 */
CAN_FAFIFO(CAN0) |= (uint32_t)val;
}
-
+
/* filter working */
if(ENABLE == can_filter_parameter_init->filter_enable){
-
+
CAN_FW(CAN0) |= (uint32_t)val;
}
-
+
/* filter lock enable */
CAN_FCTL(CAN0) &= ~CAN_FCTL_FLD;
}
@@ -266,11 +374,11 @@ void can_debug_freeze_disable(uint32_t can_periph)
void can_time_trigger_mode_enable(uint32_t can_periph)
{
uint8_t mailbox_number;
-
+
/* enable the tcc mode */
CAN_CTL(can_periph) |= CAN_CTL_TTC;
/* enable time stamp */
- for(mailbox_number=0U; mailbox_number<3U; mailbox_number++){
+ for(mailbox_number = 0U; mailbox_number < 3U; mailbox_number++){
CAN_TMP(can_periph, mailbox_number) |= CAN_TMP_TSEN;
}
}
@@ -284,29 +392,29 @@ void can_time_trigger_mode_enable(uint32_t can_periph)
*/
void can_time_trigger_mode_disable(uint32_t can_periph)
{
- uint8_t mailbox_number;
-
+ uint8_t mailbox_number;
+
/* disable the TCC mode */
CAN_CTL(can_periph) &= ~CAN_CTL_TTC;
/* reset TSEN bits */
- for(mailbox_number=0U; mailbox_number<3U; mailbox_number++){
+ for(mailbox_number = 0U; mailbox_number < 3U; mailbox_number++){
CAN_TMP(can_periph, mailbox_number) &= ~CAN_TMP_TSEN;
}
}
/*!
- \brief CAN transmit message
+ \brief transmit CAN message
\param[in] can_periph
\arg CANx(x=0,1)
- \param[in] can_trasnmit_message_struct: struct for CAN transmit message
- can_rx_sfid: 0x00000000 - 0x000007FF
- can_rx_efid: 0x00000000 - 0x1FFFFFFF
- can_rx_ff: CAN_FF_STANDARD, CAN_FF_EXTENDED
- can_rx_ft: CAN_FT_DATA, CAN_FT_REMOTE
- can_rx_dlenc: 1 - 7
- can_rx_data[]: 0x00 - 0xFF
+ \param[in] transmit_message: struct for CAN transmit message
+ \arg tx_sfid: 0x00000000 - 0x000007FF
+ \arg tx_efid: 0x00000000 - 0x1FFFFFFF
+ \arg tx_ff: CAN_FF_STANDARD, CAN_FF_EXTENDED
+ \arg tx_ft: CAN_FT_DATA, CAN_FT_REMOTE
+ \arg tx_dlen: 0 - 8
+ \arg tx_data[]: 0x00 - 0xFF
\param[out] none
- \retval none
+ \retval mailbox_number
*/
uint8_t can_message_transmit(uint32_t can_periph, can_trasnmit_message_struct* transmit_message)
{
@@ -322,10 +430,11 @@ uint8_t can_message_transmit(uint32_t can_periph, can_trasnmit_message_struct* t
}else{
mailbox_number = CAN_NOMAILBOX;
}
+ /* return no mailbox empty */
if(CAN_NOMAILBOX == mailbox_number){
return CAN_NOMAILBOX;
}
-
+
CAN_TMI(can_periph, mailbox_number) &= CAN_TMI_TEN;
if(CAN_FF_STANDARD == transmit_message->tx_ff){
/* set transmit mailbox standard identifier */
@@ -357,10 +466,11 @@ uint8_t can_message_transmit(uint32_t can_periph, can_trasnmit_message_struct* t
}
/*!
- \brief CAN transmit state
+ \brief get CAN transmit state
\param[in] can_periph
\arg CANx(x=0,1)
\param[in] mailbox_number
+ only one parameter can be selected which is shown as below:
\arg CAN_MAILBOX(x=0,1,2)
\param[out] none
\retval can_transmit_state_enum
@@ -369,14 +479,18 @@ can_transmit_state_enum can_transmit_states(uint32_t can_periph, uint8_t mailbox
{
can_transmit_state_enum state = CAN_TRANSMIT_FAILED;
uint32_t val = 0U;
-
+
+ /* check selected mailbox state */
switch(mailbox_number){
+ /* mailbox0 */
case CAN_MAILBOX0:
val = CAN_TSTAT(can_periph) & (CAN_TSTAT_MTF0 | CAN_TSTAT_MTFNERR0 | CAN_TSTAT_TME0);
break;
+ /* mailbox1 */
case CAN_MAILBOX1:
val = CAN_TSTAT(can_periph) & (CAN_TSTAT_MTF1 | CAN_TSTAT_MTFNERR1 | CAN_TSTAT_TME1);
break;
+ /* mailbox2 */
case CAN_MAILBOX2:
val = CAN_TSTAT(can_periph) & (CAN_TSTAT_MTF2 | CAN_TSTAT_MTFNERR2 | CAN_TSTAT_TME2);
break;
@@ -384,32 +498,36 @@ can_transmit_state_enum can_transmit_states(uint32_t can_periph, uint8_t mailbox
val = CAN_TRANSMIT_FAILED;
break;
}
+
switch(val){
- /* transmit pending */
- case (CAN_STATE_PENDING):
+ /* transmit pending */
+ case (CAN_STATE_PENDING):
state = CAN_TRANSMIT_PENDING;
break;
/* transmit failed */
- case (CAN_TSTAT_MTF0 | CAN_TSTAT_TME0):
+ case (CAN_TSTAT_MTF0 | CAN_TSTAT_TME0):
state = CAN_TRANSMIT_FAILED;
break;
- case (CAN_TSTAT_MTF1 | CAN_TSTAT_TME1):
+ case (CAN_TSTAT_MTF1 | CAN_TSTAT_TME1):
state = CAN_TRANSMIT_FAILED;
break;
- case (CAN_TSTAT_MTF2 | CAN_TSTAT_TME2):
+ case (CAN_TSTAT_MTF2 | CAN_TSTAT_TME2):
state = CAN_TRANSMIT_FAILED;
break;
/* transmit succeeded */
case (CAN_TSTAT_MTF0 | CAN_TSTAT_MTFNERR0 | CAN_TSTAT_TME0):
state = CAN_TRANSMIT_OK;
break;
+ /* mailbox1 transmit succeeded */
case (CAN_TSTAT_MTF1 | CAN_TSTAT_MTFNERR1 | CAN_TSTAT_TME1):
state = CAN_TRANSMIT_OK;
break;
+ /* mailbox2 transmit succeeded */
case (CAN_TSTAT_MTF2 | CAN_TSTAT_MTFNERR2 | CAN_TSTAT_TME2):
state = CAN_TRANSMIT_OK;
break;
- default:
+ /* transmit failed */
+ default:
state = CAN_TRANSMIT_FAILED;
break;
}
@@ -417,10 +535,11 @@ can_transmit_state_enum can_transmit_states(uint32_t can_periph, uint8_t mailbox
}
/*!
- \brief CAN stop transmission
+ \brief stop CAN transmission
\param[in] can_periph
\arg CANx(x=0,1)
\param[in] mailbox_number
+ only one parameter can be selected which is shown as below:
\arg CAN_MAILBOXx(x=0,1,2)
\param[out] none
\retval none
@@ -429,12 +548,18 @@ void can_transmission_stop(uint32_t can_periph, uint8_t mailbox_number)
{
if(CAN_MAILBOX0 == mailbox_number){
CAN_TSTAT(can_periph) |= CAN_TSTAT_MST0;
+ while(CAN_TSTAT_MST0 == (CAN_TSTAT(can_periph) & CAN_TSTAT_MST0)){
+ }
}else if(CAN_MAILBOX1 == mailbox_number){
CAN_TSTAT(can_periph) |= CAN_TSTAT_MST1;
+ while(CAN_TSTAT_MST1 == (CAN_TSTAT(can_periph) & CAN_TSTAT_MST1)){
+ }
}else if(CAN_MAILBOX2 == mailbox_number){
CAN_TSTAT(can_periph) |= CAN_TSTAT_MST2;
+ while(CAN_TSTAT_MST2 == (CAN_TSTAT(can_periph) & CAN_TSTAT_MST2)){
+ }
}else{
- /* illegal parameter*/
+ /* illegal parameters */
}
}
@@ -443,15 +568,15 @@ void can_transmission_stop(uint32_t can_periph, uint8_t mailbox_number)
\param[in] can_periph
\arg CANx(x=0,1)
\param[in] fifo_number
- \arg CAN_FIFO0x(x=0,1)
- \param[out] can_receive_message_struct: struct for CAN receive message
- can_rx_sfid: 0x00000000 - 0x000007FF
- can_rx_efid: 0x00000000 - 0x1FFFFFFF
- can_rx_ff: CAN_FF_STANDARD, CAN_FF_EXTENDED
- can_rx_ft: CAN_FT_DATA, CAN_FT_REMOTE
- can_rx_dlenc: 1 - 7
- can_rx_data[]: 0x00 - 0xFF
- can_rx_fi: 0 - 27
+ \arg CAN_FIFOx(x=0,1)
+ \param[out] receive_message: struct for CAN receive message
+ \arg rx_sfid: 0x00000000 - 0x000007FF
+ \arg rx_efid: 0x00000000 - 0x1FFFFFFF
+ \arg rx_ff: CAN_FF_STANDARD, CAN_FF_EXTENDED
+ \arg rx_ft: CAN_FT_DATA, CAN_FT_REMOTE
+ \arg rx_dlen: 0 - 8
+ \arg rx_data[]: 0x00 - 0xFF
+ \arg rx_fi: 0 - 27
\retval none
*/
void can_message_receive(uint32_t can_periph, uint8_t fifo_number, can_receive_message_struct* receive_message)
@@ -460,29 +585,29 @@ void can_message_receive(uint32_t can_periph, uint8_t fifo_number, can_receive_m
receive_message->rx_ff = (uint8_t)(CAN_RFIFOMI_FF & CAN_RFIFOMI(can_periph, fifo_number));
if(CAN_FF_STANDARD == receive_message->rx_ff){
/* get standard identifier */
- receive_message -> rx_sfid = (uint32_t)(RFIFOMI_SFID(CAN_RFIFOMI(can_periph, fifo_number)));
+ receive_message->rx_sfid = (uint32_t)(GET_RFIFOMI_SFID(CAN_RFIFOMI(can_periph, fifo_number)));
}else{
/* get extended identifier */
- receive_message -> rx_efid = (uint32_t)(RFIFOMI_EFID(CAN_RFIFOMI(can_periph, fifo_number)));
+ receive_message->rx_efid = (uint32_t)(GET_RFIFOMI_EFID(CAN_RFIFOMI(can_periph, fifo_number)));
}
-
+
/* get frame type */
- receive_message -> rx_ft = (uint8_t)(CAN_RFIFOMI_FT & CAN_RFIFOMI(can_periph, fifo_number));
- /* get recevie data length */
- receive_message -> rx_dlen = (uint8_t)(RFIFOMP_DLENC(CAN_RFIFOMP(can_periph, fifo_number)));
+ receive_message->rx_ft = (uint8_t)(CAN_RFIFOMI_FT & CAN_RFIFOMI(can_periph, fifo_number));
/* filtering index */
- receive_message -> rx_fi = (uint8_t)(RFIFOMP_FI(CAN_RFIFOMP(can_periph, fifo_number)));
-
+ receive_message->rx_fi = (uint8_t)(GET_RFIFOMP_FI(CAN_RFIFOMP(can_periph, fifo_number)));
+ /* get recevie data length */
+ receive_message->rx_dlen = (uint8_t)(GET_RFIFOMP_DLENC(CAN_RFIFOMP(can_periph, fifo_number)));
+
/* receive data */
- receive_message -> rx_data[0] = (uint8_t)(RFIFOMDATA0_DB0(CAN_RFIFOMDATA0(can_periph, fifo_number)));
- receive_message -> rx_data[1] = (uint8_t)(RFIFOMDATA0_DB1(CAN_RFIFOMDATA0(can_periph, fifo_number)));
- receive_message -> rx_data[2] = (uint8_t)(RFIFOMDATA0_DB2(CAN_RFIFOMDATA0(can_periph, fifo_number)));
- receive_message -> rx_data[3] = (uint8_t)(RFIFOMDATA0_DB3(CAN_RFIFOMDATA0(can_periph, fifo_number)));
- receive_message -> rx_data[4] = (uint8_t)(RFIFOMDATA1_DB4(CAN_RFIFOMDATA1(can_periph, fifo_number)));
- receive_message -> rx_data[5] = (uint8_t)(RFIFOMDATA1_DB5(CAN_RFIFOMDATA1(can_periph, fifo_number)));
- receive_message -> rx_data[6] = (uint8_t)(RFIFOMDATA1_DB6(CAN_RFIFOMDATA1(can_periph, fifo_number)));
- receive_message -> rx_data[7] = (uint8_t)(RFIFOMDATA1_DB7(CAN_RFIFOMDATA1(can_periph, fifo_number)));
-
+ receive_message -> rx_data[0] = (uint8_t)(GET_RFIFOMDATA0_DB0(CAN_RFIFOMDATA0(can_periph, fifo_number)));
+ receive_message -> rx_data[1] = (uint8_t)(GET_RFIFOMDATA0_DB1(CAN_RFIFOMDATA0(can_periph, fifo_number)));
+ receive_message -> rx_data[2] = (uint8_t)(GET_RFIFOMDATA0_DB2(CAN_RFIFOMDATA0(can_periph, fifo_number)));
+ receive_message -> rx_data[3] = (uint8_t)(GET_RFIFOMDATA0_DB3(CAN_RFIFOMDATA0(can_periph, fifo_number)));
+ receive_message -> rx_data[4] = (uint8_t)(GET_RFIFOMDATA1_DB4(CAN_RFIFOMDATA1(can_periph, fifo_number)));
+ receive_message -> rx_data[5] = (uint8_t)(GET_RFIFOMDATA1_DB5(CAN_RFIFOMDATA1(can_periph, fifo_number)));
+ receive_message -> rx_data[6] = (uint8_t)(GET_RFIFOMDATA1_DB6(CAN_RFIFOMDATA1(can_periph, fifo_number)));
+ receive_message -> rx_data[7] = (uint8_t)(GET_RFIFOMDATA1_DB7(CAN_RFIFOMDATA1(can_periph, fifo_number)));
+
/* release FIFO */
if(CAN_FIFO0 == fifo_number){
CAN_RFIFO0(can_periph) |= CAN_RFIFO0_RFD0;
@@ -495,7 +620,9 @@ void can_message_receive(uint32_t can_periph, uint8_t fifo_number, can_receive_m
\brief release FIFO0
\param[in] can_periph
\arg CANx(x=0,1)
- \arg CAN_FIFO0x(x=0,1)
+ \param[in] fifo_number
+ only one parameter can be selected which is shown as below:
+ \arg CAN_FIFOx(x=0,1)
\param[out] none
\retval none
*/
@@ -506,7 +633,8 @@ void can_fifo_release(uint32_t can_periph, uint8_t fifo_number)
}else if(CAN_FIFO1 == fifo_number){
CAN_RFIFO1(can_periph) |= CAN_RFIFO1_RFD1;
}else{
- /* illegal parameter */
+ /* illegal parameters */
+ CAN_ERROR_HANDLE("CAN FIFO NUM is invalid \r\n");
}
}
@@ -514,20 +642,24 @@ void can_fifo_release(uint32_t can_periph, uint8_t fifo_number)
\brief CAN receive message length
\param[in] can_periph
\arg CANx(x=0,1)
- \arg CAN_FIFO0x(x=0,1)
+ \param[in] fifo_number
+ only one parameter can be selected which is shown as below:
+ \arg CAN_FIFOx(x=0,1)
\param[out] none
\retval message length
*/
-uint8_t can_receive_message_length(uint32_t can_periph, uint8_t fifo_number)
+uint8_t can_receive_message_length_get(uint32_t can_periph, uint8_t fifo_number)
{
uint8_t val = 0U;
-
+
if(CAN_FIFO0 == fifo_number){
- val = (uint8_t)(CAN_RFIFO0(can_periph) & CAN_RFIFO_RFL0_MASK);
- }else if(CAN_FIFO0 == fifo_number){
- val = (uint8_t)(CAN_RFIFO1(can_periph) & CAN_RFIFO_RFL0_MASK);
+ /* FIFO0 */
+ val = (uint8_t)(CAN_RFIFO0(can_periph) & CAN_RFIF_RFL_MASK);
+ }else if(CAN_FIFO1 == fifo_number){
+ /* FIFO1 */
+ val = (uint8_t)(CAN_RFIFO1(can_periph) & CAN_RFIF_RFL_MASK);
}else{
- /* illegal parameter */
+ /* illegal parameters */
}
return val;
}
@@ -537,25 +669,26 @@ uint8_t can_receive_message_length(uint32_t can_periph, uint8_t fifo_number)
\param[in] can_periph
\arg CANx(x=0,1)
\param[in] can_working_mode
- \arg CAN_INITIALIZE_MODE
- \arg CAN_NORMAL_MODE
- \arg CAN_SLEEP_MODE
+ only one parameter can be selected which is shown as below:
+ \arg CAN_MODE_INITIALIZE
+ \arg CAN_MODE_NORMAL
+ \arg CAN_MODE_SLEEP
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
*/
ErrStatus can_working_mode_set(uint32_t can_periph, uint8_t working_mode)
{
ErrStatus flag = ERROR;
- /* timeout for IWS or also for SLPWS bits*/
- uint32_t timeout = CAN_TIMEOUT;
-
+ /* timeout for IWS or also for SLPWS bits */
+ uint32_t timeout = CAN_TIMEOUT;
+
if(CAN_MODE_INITIALIZE == working_mode){
/* disable sleep mode */
CAN_CTL(can_periph) &= (~(uint32_t)CAN_CTL_SLPWMOD);
/* set initialize mode */
CAN_CTL(can_periph) |= (uint8_t)CAN_CTL_IWMOD;
/* wait the acknowledge */
- while((CAN_STAT_IWS != (CAN_STAT(can_periph) & CAN_STAT_IWS)) && (timeout != 0U)){
+ while((CAN_STAT_IWS != (CAN_STAT(can_periph) & CAN_STAT_IWS)) && (0U != timeout)){
timeout--;
}
if(CAN_STAT_IWS != (CAN_STAT(can_periph) & CAN_STAT_IWS)){
@@ -567,7 +700,7 @@ ErrStatus can_working_mode_set(uint32_t can_periph, uint8_t working_mode)
/* enter normal mode */
CAN_CTL(can_periph) &= ~(uint32_t)(CAN_CTL_SLPWMOD | CAN_CTL_IWMOD);
/* wait the acknowledge */
- while((0U != (CAN_STAT(can_periph) & (CAN_STAT_IWS | CAN_STAT_SLPWS))) && (timeout != 0U)){
+ while((0U != (CAN_STAT(can_periph) & (CAN_STAT_IWS | CAN_STAT_SLPWS))) && (0U != timeout)){
timeout--;
}
if(0U != (CAN_STAT(can_periph) & (CAN_STAT_IWS | CAN_STAT_SLPWS))){
@@ -581,10 +714,10 @@ ErrStatus can_working_mode_set(uint32_t can_periph, uint8_t working_mode)
/* set sleep mode */
CAN_CTL(can_periph) |= (uint8_t)CAN_CTL_SLPWMOD;
/* wait the acknowledge */
- while((CAN_STAT_SLPWS != (CAN_STAT(can_periph) & CAN_STAT_SLPWS)) && (timeout != 0U)){
+ while((CAN_STAT_SLPWS != (CAN_STAT(can_periph) & CAN_STAT_SLPWS)) && (0U != timeout)){
timeout--;
}
- if (CAN_STAT_SLPWS != (CAN_STAT(can_periph) & CAN_STAT_SLPWS)){
+ if(CAN_STAT_SLPWS != (CAN_STAT(can_periph) & CAN_STAT_SLPWS)){
flag = ERROR;
}else{
flag = SUCCESS;
@@ -592,7 +725,7 @@ ErrStatus can_working_mode_set(uint32_t can_periph, uint8_t working_mode)
}else{
flag = ERROR;
}
- return flag;
+ return flag;
}
/*!
@@ -606,13 +739,14 @@ ErrStatus can_wakeup(uint32_t can_periph)
{
ErrStatus flag = ERROR;
uint32_t timeout = CAN_TIMEOUT;
-
+
/* wakeup */
CAN_CTL(can_periph) &= ~CAN_CTL_SLPWMOD;
-
- while((0U != (CAN_STAT(can_periph) & CAN_STAT_SLPWS)) && (timeout != 0x00U)){
+
+ while((0U != (CAN_STAT(can_periph) & CAN_STAT_SLPWS)) && (0x00U != timeout)){
timeout--;
}
+ /* check state */
if(0U != (CAN_STAT(can_periph) & CAN_STAT_SLPWS)){
flag = ERROR;
}else{
@@ -627,66 +761,76 @@ ErrStatus can_wakeup(uint32_t can_periph)
\arg CANx(x=0,1)
\param[out] none
\retval can_error_enum
+ \arg CAN_ERROR_NONE: no error
+ \arg CAN_ERROR_FILL: fill error
+ \arg CAN_ERROR_FORMATE: format error
+ \arg CAN_ERROR_ACK: ACK error
+ \arg CAN_ERROR_BITRECESSIVE: bit recessive
+ \arg CAN_ERROR_BITDOMINANTER: bit dominant error
+ \arg CAN_ERROR_CRC: CRC error
+ \arg CAN_ERROR_SOFTWARECFG: software configure
*/
can_error_enum can_error_get(uint32_t can_periph)
{
can_error_enum error;
error = CAN_ERROR_NONE;
-
+
/* get error type */
- error = (can_error_enum)((CAN_ERR(can_periph) & CAN_ERR_ERRN) >> 4U);
+ error = (can_error_enum)(GET_ERR_ERRN(CAN_ERR(can_periph)));
return error;
}
/*!
- \brief CAN receive error number
+ \brief get CAN receive error number
\param[in] can_periph
\arg CANx(x=0,1)
\param[out] none
\retval error number
*/
-uint8_t can_receive_error_number(uint32_t can_periph)
+uint8_t can_receive_error_number_get(uint32_t can_periph)
{
uint8_t val;
-
- val = (uint8_t)((CAN_ERR(can_periph) & CAN_ERR_RECNT) >> 24U);
+
+ /* get error count */
+ val = (uint8_t)(GET_ERR_RECNT(CAN_ERR(can_periph)));
return val;
}
/*!
- \brief CAN transmit error number
+ \brief get CAN transmit error number
\param[in] can_periph
\arg CANx(x=0,1)
\param[out] none
\retval error number
*/
-uint8_t can_transmit_error_number(uint32_t can_periph)
+uint8_t can_transmit_error_number_get(uint32_t can_periph)
{
uint8_t val;
-
- val = (uint8_t)((CAN_ERR(can_periph) & CAN_ERR_TECNT) >> 16U);
+
+ val = (uint8_t)(GET_ERR_TECNT(CAN_ERR(can_periph)));
return val;
}
/*!
- \brief enable CAN interrupt
+ \brief enable CAN interrupt
\param[in] can_periph
\arg CANx(x=0,1)
- \param[in] interrupt
- \arg CAN_INTEN_TMEIE
- \arg CAN_INTEN_RFNEIE0
- \arg CAN_INTEN_RFFIE0
- \arg CAN_INTEN_RFOIE0
- \arg CAN_INTEN_RFNEIE1
- \arg CAN_INTEN_RFFIE1
- \arg CAN_INTEN_RFOIE1
- \arg CAN_INTEN_WERRIE
- \arg CAN_INTEN_PERRIE
- \arg CAN_INTEN_BOIE
- \arg CAN_INTEN_ERRNIE
- \arg CAN_INTEN_ERRIE
- \arg CAN_INTEN_WUIE
- \arg CAN_INTEN_SLPWIE
+ \param[in] interrupt
+ one or more parameters can be selected which are shown as below:
+ \arg CAN_INT_TME: transmit mailbox empty interrupt enable
+ \arg CAN_INT_RFNE0: receive FIFO0 not empty interrupt enable
+ \arg CAN_INT_RFF0: receive FIFO0 full interrupt enable
+ \arg CAN_INT_RFO0: receive FIFO0 overfull interrupt enable
+ \arg CAN_INT_RFNE1: receive FIFO1 not empty interrupt enable
+ \arg CAN_INT_RFF1: receive FIFO1 full interrupt enable
+ \arg CAN_INT_RFO1: receive FIFO1 overfull interrupt enable
+ \arg CAN_INT_WERR: warning error interrupt enable
+ \arg CAN_INT_PERR: passive error interrupt enable
+ \arg CAN_INT_BO: bus-off interrupt enable
+ \arg CAN_INT_ERRN: error number interrupt enable
+ \arg CAN_INT_ERR: error interrupt enable
+ \arg CAN_INT_WU: wakeup interrupt enable
+ \arg CAN_INT_SLPW: sleep working interrupt enable
\param[out] none
\retval none
*/
@@ -696,24 +840,25 @@ void can_interrupt_enable(uint32_t can_periph, uint32_t interrupt)
}
/*!
- \brief disable CAN interrupt
+ \brief disable CAN interrupt
\param[in] can_periph
\arg CANx(x=0,1)
\param[in] interrupt
- \arg CAN_INTEN_TMEIE
- \arg CAN_INTEN_RFNEIE0
- \arg CAN_INTEN_RFFIE0
- \arg CAN_INTEN_RFOIE0
- \arg CAN_INTEN_RFNEIE1
- \arg CAN_INTEN_RFFIE1
- \arg CAN_INTEN_RFOIE1
- \arg CAN_INTEN_WERRIE
- \arg CAN_INTEN_PERRIE
- \arg CAN_INTEN_BOIE
- \arg CAN_INTEN_ERRNIE
- \arg CAN_INTEN_ERRIE
- \arg CAN_INTEN_WUIE
- \arg CAN_INTEN_SLPWIE
+ one or more parameters can be selected which are shown as below:
+ \arg CAN_INT_TME: transmit mailbox empty interrupt enable
+ \arg CAN_INT_RFNE0: receive FIFO0 not empty interrupt enable
+ \arg CAN_INT_RFF0: receive FIFO0 full interrupt enable
+ \arg CAN_INT_RFO0: receive FIFO0 overfull interrupt enable
+ \arg CAN_INT_RFNE1: receive FIFO1 not empty interrupt enable
+ \arg CAN_INT_RFF1: receive FIFO1 full interrupt enable
+ \arg CAN_INT_RFO1: receive FIFO1 overfull interrupt enable
+ \arg CAN_INT_WERR: warning error interrupt enable
+ \arg CAN_INT_PERR: passive error interrupt enable
+ \arg CAN_INT_BO: bus-off interrupt enable
+ \arg CAN_INT_ERRN: error number interrupt enable
+ \arg CAN_INT_ERR: error interrupt enable
+ \arg CAN_INT_WU: wakeup interrupt enable
+ \arg CAN_INT_SLPW: sleep working interrupt enable
\param[out] none
\retval none
*/
@@ -728,24 +873,46 @@ void can_interrupt_disable(uint32_t can_periph, uint32_t interrupt)
\arg CANx(x=0,1)
\param[in] flag: CAN flags, refer to can_flag_enum
only one parameter can be selected which is shown as below:
- \arg CAN_FLAG_MTE2
- \arg CAN_FLAG_MTE1
- \arg CAN_FLAG_MTE0
- \arg CAN_FLAG_MTF2
- \arg CAN_FLAG_MTF1
- \arg CAN_FLAG_MTF0
- \arg CAN_FLAG_RFO0
- \arg CAN_FLAG_RFF0
- \arg CAN_FLAG_RFO1
- \arg CAN_FLAG_RFF1
- \arg CAN_FLAG_BOERR
- \arg CAN_FLAG_PERR
- \arg CAN_FLAG_WERR
+ \arg CAN_FLAG_RXL: RX level
+ \arg CAN_FLAG_LASTRX: last sample value of RX pin
+ \arg CAN_FLAG_RS: receiving state
+ \arg CAN_FLAG_TS: transmitting state
+ \arg CAN_FLAG_SLPIF: status change flag of entering sleep working mode
+ \arg CAN_FLAG_WUIF: status change flag of wakeup from sleep working mode
+ \arg CAN_FLAG_ERRIF: error flag
+ \arg CAN_FLAG_SLPWS: sleep working state
+ \arg CAN_FLAG_IWS: initial working state
+ \arg CAN_FLAG_TMLS2: transmit mailbox 2 last sending in Tx FIFO
+ \arg CAN_FLAG_TMLS1: transmit mailbox 1 last sending in Tx FIFO
+ \arg CAN_FLAG_TMLS0: transmit mailbox 0 last sending in Tx FIFO
+ \arg CAN_FLAG_TME2: transmit mailbox 2 empty
+ \arg CAN_FLAG_TME1: transmit mailbox 1 empty
+ \arg CAN_FLAG_TME0: transmit mailbox 0 empty
+ \arg CAN_FLAG_MTE2: mailbox 2 transmit error
+ \arg CAN_FLAG_MTE1: mailbox 1 transmit error
+ \arg CAN_FLAG_MTE0: mailbox 0 transmit error
+ \arg CAN_FLAG_MAL2: mailbox 2 arbitration lost
+ \arg CAN_FLAG_MAL1: mailbox 1 arbitration lost
+ \arg CAN_FLAG_MAL0: mailbox 0 arbitration lost
+ \arg CAN_FLAG_MTFNERR2: mailbox 2 transmit finished with no error
+ \arg CAN_FLAG_MTFNERR1: mailbox 1 transmit finished with no error
+ \arg CAN_FLAG_MTFNERR0: mailbox 0 transmit finished with no error
+ \arg CAN_FLAG_MTF2: mailbox 2 transmit finished
+ \arg CAN_FLAG_MTF1: mailbox 1 transmit finished
+ \arg CAN_FLAG_MTF0: mailbox 0 transmit finished
+ \arg CAN_FLAG_RFO0: receive FIFO0 overfull
+ \arg CAN_FLAG_RFF0: receive FIFO0 full
+ \arg CAN_FLAG_RFO1: receive FIFO1 overfull
+ \arg CAN_FLAG_RFF1: receive FIFO1 full
+ \arg CAN_FLAG_BOERR: bus-off error
+ \arg CAN_FLAG_PERR: passive error
+ \arg CAN_FLAG_WERR: warning error
\param[out] none
\retval FlagStatus: SET or RESET
*/
FlagStatus can_flag_get(uint32_t can_periph, can_flag_enum flag)
-{
+{
+ /* get flag and interrupt enable state */
if(RESET != (CAN_REG_VAL(can_periph, flag) & BIT(CAN_BIT_POS(flag)))){
return SET;
}else{
@@ -755,26 +922,35 @@ FlagStatus can_flag_get(uint32_t can_periph, can_flag_enum flag)
/*!
\brief clear CAN flag state
- \param[in] can_periph
+ \param[in] can_periph
\arg CANx(x=0,1)
\param[in] flag: CAN flags, refer to can_flag_enum
only one parameter can be selected which is shown as below:
- \arg CAN_FLAG_MTE2
- \arg CAN_FLAG_MTE1
- \arg CAN_FLAG_MTE0
- \arg CAN_FLAG_MTF2
- \arg CAN_FLAG_MTF1
- \arg CAN_FLAG_MTF0
- \arg CAN_FLAG_RFO0
- \arg CAN_FLAG_RFF0
- \arg CAN_FLAG_RFO1
- \arg CAN_FLAG_RFF1
+ \arg CAN_FLAG_SLPIF: status change flag of entering sleep working mode
+ \arg CAN_FLAG_WUIF: status change flag of wakeup from sleep working mode
+ \arg CAN_FLAG_ERRIF: error flag
+ \arg CAN_FLAG_MTE2: mailbox 2 transmit error
+ \arg CAN_FLAG_MTE1: mailbox 1 transmit error
+ \arg CAN_FLAG_MTE0: mailbox 0 transmit error
+ \arg CAN_FLAG_MAL2: mailbox 2 arbitration lost
+ \arg CAN_FLAG_MAL1: mailbox 1 arbitration lost
+ \arg CAN_FLAG_MAL0: mailbox 0 arbitration lost
+ \arg CAN_FLAG_MTFNERR2: mailbox 2 transmit finished with no error
+ \arg CAN_FLAG_MTFNERR1: mailbox 1 transmit finished with no error
+ \arg CAN_FLAG_MTFNERR0: mailbox 0 transmit finished with no error
+ \arg CAN_FLAG_MTF2: mailbox 2 transmit finished
+ \arg CAN_FLAG_MTF1: mailbox 1 transmit finished
+ \arg CAN_FLAG_MTF0: mailbox 0 transmit finished
+ \arg CAN_FLAG_RFO0: receive FIFO0 overfull
+ \arg CAN_FLAG_RFF0: receive FIFO0 full
+ \arg CAN_FLAG_RFO1: receive FIFO1 overfull
+ \arg CAN_FLAG_RFF1: receive FIFO1 full
\param[out] none
\retval none
*/
void can_flag_clear(uint32_t can_periph, can_flag_enum flag)
{
- CAN_REG_VAL(can_periph, flag) |= BIT(CAN_BIT_POS(flag));
+ CAN_REG_VAL(can_periph, flag) = BIT(CAN_BIT_POS(flag));
}
/*!
@@ -783,62 +959,43 @@ void can_flag_clear(uint32_t can_periph, can_flag_enum flag)
\arg CANx(x=0,1)
\param[in] flag: CAN interrupt flags, refer to can_interrupt_flag_enum
only one parameter can be selected which is shown as below:
- \arg CAN_INT_SLPIF
- \arg CAN_INT_WUIF
- \arg CAN_INT_ERRIF
+ \arg CAN_INT_FLAG_SLPIF: status change interrupt flag of sleep working mode entering
+ \arg CAN_INT_FLAG_WUIF: status change interrupt flag of wakeup from sleep working mode
+ \arg CAN_INT_FLAG_ERRIF: error interrupt flag
+ \arg CAN_INT_FLAG_MTF2: mailbox 2 transmit finished interrupt flag
+ \arg CAN_INT_FLAG_MTF1: mailbox 1 transmit finished interrupt flag
+ \arg CAN_INT_FLAG_MTF0: mailbox 0 transmit finished interrupt flag
+ \arg CAN_INT_FLAG_RFO0: receive FIFO0 overfull interrupt flag
+ \arg CAN_INT_FLAG_RFF0: receive FIFO0 full interrupt flag
+ \arg CAN_INT_FLAG_RFL0: receive FIFO0 not empty interrupt flag
+ \arg CAN_INT_FLAG_RFO1: receive FIFO1 overfull interrupt flag
+ \arg CAN_INT_FLAG_RFF1: receive FIFO1 full interrupt flag
+ \arg CAN_INT_FLAG_RFL1: receive FIFO1 not empty interrupt flag
+ \arg CAN_INT_FLAG_ERRN: error number interrupt flag
+ \arg CAN_INT_FLAG_BOERR: bus-off error interrupt flag
+ \arg CAN_INT_FLAG_PERR: passive error interrupt flag
+ \arg CAN_INT_FLAG_WERR: warning error interrupt flag
\param[out] none
\retval FlagStatus: SET or RESET
*/
FlagStatus can_interrupt_flag_get(uint32_t can_periph, can_interrupt_flag_enum flag)
-{
- FlagStatus inten = RESET;
- FlagStatus temp = RESET;
- FlagStatus status1 = RESET;
- FlagStatus status2 = RESET;
-
- switch(flag){
- /* get the status of sleep working interrupt enable bit */
- case CAN_INT_SLPIF:
- inten = (FlagStatus)(CAN_INTEN(can_periph) & CAN_INTEN_SLPWIE);
- break;
- /* get the status of wakeup interrupt enable bit */
- case CAN_INT_WUIF:
- inten = (FlagStatus)(CAN_INTEN(can_periph) & CAN_INTEN_WUIE);
- break;
- /* get the status of error falgs and its enable bit */
- case CAN_INT_ERRIF:
- /* check if the BOERR bit in CAN_ERR register and BOIE bit in CAN_INTEN register are set */
- status1 = (FlagStatus)(CAN_INTEN(can_periph) & CAN_INTEN_BOIE);
- status2 = (FlagStatus)(CAN_ERR(can_periph) & CAN_ERR_BOERR);
- if((RESET != status1) && (RESET != status2)){
- inten = SET;
- }
- /* check if the WERR bit in CAN_ERR register and WERRIE bit in CAN_INTEN register are set */
- status1 = (FlagStatus)(CAN_INTEN(can_periph) & CAN_INTEN_WERRIE);
- status2 = (FlagStatus)(CAN_ERR(can_periph) & CAN_ERR_WERR);
- if((RESET != status1) && (RESET != status2)){
- inten = SET;
- }
- /* check if the PERR bit in CAN_ERR register and PERRIE bit in CAN_INTEN register are set */
- status1 = (FlagStatus)(CAN_INTEN(can_periph) & CAN_INTEN_PERRIE);
- status2 = (FlagStatus)(CAN_ERR(can_periph) & CAN_ERR_PERR);
- if((RESET != status1) && (RESET != status2)){
- inten = SET;
- }
- /* check if the ERRN bit in CAN_ERR register and ERRNIE bit in CAN_INTEN register are set */
- status1 = (FlagStatus)(CAN_INTEN(can_periph) & CAN_INTEN_ERRNIE);
- status2 = (FlagStatus)(CAN_ERR(can_periph) & CAN_ERR_ERRN);
- if((RESET != status1) && (RESET != status2)){
- inten = SET;
- }
- break;
- default:
- break;
+{
+ uint32_t ret1 = RESET;
+ uint32_t ret2 = RESET;
+
+ /* get the staus of interrupt flag */
+ if (flag == CAN_INT_FLAG_RFF0) {
+ ret1 = can_receive_message_length_get(can_periph, CAN_FIFO0);
+ } else if (flag == CAN_INT_FLAG_RFF1) {
+ ret1 = can_receive_message_length_get(can_periph, CAN_FIFO1);
+ } else if (flag == CAN_INT_FLAG_ERRN) {
+ ret1 = can_error_get(can_periph);
+ } else {
+ ret1 = CAN_REG_VALS(can_periph, flag) & BIT(CAN_BIT_POS0(flag));
}
- /* get the interrupt flag */
- temp = (FlagStatus)(CAN_REG_VAL(can_periph, flag) & BIT(CAN_BIT_POS(flag)));
- /* check the interrupt enable bit and corresponding flag bit are set */
- if((RESET != inten) && (RESET != temp)){
+ /* get the staus of interrupt enale bit */
+ ret2 = CAN_INTEN(can_periph) & BIT(CAN_BIT_POS1(flag));
+ if(ret1 && ret2){
return SET;
}else{
return RESET;
@@ -851,13 +1008,20 @@ FlagStatus can_interrupt_flag_get(uint32_t can_periph, can_interrupt_flag_enum f
\arg CANx(x=0,1)
\param[in] flag: CAN interrupt flags, refer to can_interrupt_flag_enum
only one parameter can be selected which is shown as below:
- \arg CAN_INT_SLPIF
- \arg CAN_INT_WUIF
- \arg CAN_INT_ERRIF
+ \arg CAN_INT_FLAG_SLPIF: status change interrupt flag of sleep working mode entering
+ \arg CAN_INT_FLAG_WUIF: status change interrupt flag of wakeup from sleep working mode
+ \arg CAN_INT_FLAG_ERRIF: error interrupt flag
+ \arg CAN_INT_FLAG_MTF2: mailbox 2 transmit finished interrupt flag
+ \arg CAN_INT_FLAG_MTF1: mailbox 1 transmit finished interrupt flag
+ \arg CAN_INT_FLAG_MTF0: mailbox 0 transmit finished interrupt flag
+ \arg CAN_INT_FLAG_RFO0: receive FIFO0 overfull interrupt flag
+ \arg CAN_INT_FLAG_RFF0: receive FIFO0 full interrupt flag
+ \arg CAN_INT_FLAG_RFO1: receive FIFO1 overfull interrupt flag
+ \arg CAN_INT_FLAG_RFF1: receive FIFO1 full interrupt flag
\param[out] none
\retval none
*/
void can_interrupt_flag_clear(uint32_t can_periph, can_interrupt_flag_enum flag)
{
- CAN_REG_VAL(can_periph, flag) |= BIT(CAN_BIT_POS(flag));
+ CAN_REG_VALS(can_periph, flag) = BIT(CAN_BIT_POS0(flag));
}
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_crc.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_crc.c
index e51d8dc483..bfe79cb9aa 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_crc.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_crc.c
@@ -1,16 +1,43 @@
/*!
- \file gd32f4xx_crc.c
- \brief CRC driver
+ \file gd32f4xx_crc.c
+ \brief CRC driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#include "gd32f4xx_crc.h"
+#define CRC_DATA_RESET_VALUE ((uint32_t)0xFFFFFFFFU)
+#define CRC_FDATA_RESET_VALUE ((uint32_t)0x00000000U)
/*!
\brief deinit CRC calculation unit
\param[in] none
@@ -19,13 +46,13 @@
*/
void crc_deinit(void)
{
- CRC_DATA = (uint32_t)0xFFFFFFFFU;
- CRC_FDATA = (uint32_t)0x00000000U;
- CRC_CTL = CRC_CTL_RST;
+ CRC_DATA = CRC_DATA_RESET_VALUE;
+ CRC_FDATA = CRC_FDATA_RESET_VALUE;
+ CRC_CTL = (uint32_t)CRC_CTL_RST;
}
/*!
- \brief reset data register to the value of initializaiton data register
+ \brief reset data register(CRC_DATA) to the value of 0xFFFFFFFF
\param[in] none
\param[out] none
\retval none
@@ -36,7 +63,7 @@ void crc_data_register_reset(void)
}
/*!
- \brief read the data register
+ \brief read the value of the data register
\param[in] none
\param[out] none
\retval 32-bit value of the data register
@@ -49,7 +76,7 @@ uint32_t crc_data_register_read(void)
}
/*!
- \brief read the free data register
+ \brief read the value of the free data register
\param[in] none
\param[out] none
\retval 8-bit value of the free data register
@@ -62,8 +89,8 @@ uint8_t crc_free_data_register_read(void)
}
/*!
- \brief write the free data register
- \param[in] free_data: specify 8-bit data
+ \brief write data to the free data register
+ \param[in] free_data: specified 8-bit data
\param[out] none
\retval none
*/
@@ -73,10 +100,10 @@ void crc_free_data_register_write(uint8_t free_data)
}
/*!
- \brief CRC calculate a 32-bit data
- \param[in] sdata: specify 32-bit data
+ \brief calculate the CRC value of a 32-bit data
+ \param[in] sdata: specified 32-bit data
\param[out] none
- \retval 32-bit CRC calculate value
+ \retval 32-bit value calculated by CRC
*/
uint32_t crc_single_data_calculate(uint32_t sdata)
{
@@ -85,11 +112,11 @@ uint32_t crc_single_data_calculate(uint32_t sdata)
}
/*!
- \brief CRC calculate a 32-bit data array
- \param[in] array: pointer to an array of 32 bit data words
+ \brief calculate the CRC value of an array of 32-bit values
+ \param[in] array: pointer to an array of 32-bit values
\param[in] size: size of the array
\param[out] none
- \retval 32-bit CRC calculate value
+ \retval 32-bit value calculated by CRC
*/
uint32_t crc_block_data_calculate(uint32_t array[], uint32_t size)
{
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_ctc.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_ctc.c
index 34431164a3..ab67c4ad73 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_ctc.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_ctc.c
@@ -1,18 +1,49 @@
/*!
- \file gd32f4xx_ctc.c
- \brief CTC driver
+ \file gd32f4xx_ctc.c
+ \brief CTC driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#include "gd32f4xx_ctc.h"
#define CTC_FLAG_MASK ((uint32_t)0x00000700U)
+/* CTC register bit offset */
+#define CTC_TRIMVALUE_OFFSET ((uint32_t)8U)
+#define CTC_TRIM_VALUE_OFFSET ((uint32_t)8U)
+#define CTC_REFCAP_OFFSET ((uint32_t)16U)
+#define CTC_LIMIT_VALUE_OFFSET ((uint32_t)16U)
+
/*!
\brief reset CTC clock trim controller
\param[in] none
@@ -27,112 +58,117 @@ void ctc_deinit(void)
}
/*!
- \brief configure the IRC48M trim value
- \param[in] ctc_trim_value: 8-bit IRC48M trim value
+ \brief enable CTC trim counter
+ \param[in] none
\param[out] none
\retval none
*/
-void ctc_irc48m_trim_value_config(uint8_t ctc_trim_value)
+void ctc_counter_enable(void)
{
- /* clear TRIMVALUE bits */
- CTC_CTL0 &= (~(uint32_t)CTC_CTL0_TRIMVALUE);
- /* set TRIMVALUE bits */
- CTC_CTL0 |= ((uint32_t)ctc_trim_value << 8);
+ CTC_CTL0 |= (uint32_t)CTC_CTL0_CNTEN;
}
/*!
- \brief generate software reference source sync pulse
+ \brief disable CTC trim counter
\param[in] none
\param[out] none
\retval none
*/
-void ctc_software_refsource_pulse_generate(void)
+void ctc_counter_disable(void)
{
- CTC_CTL0 |= (uint32_t)CTC_CTL0_SWREFPUL;
+ CTC_CTL0 &= (uint32_t)(~CTC_CTL0_CNTEN);
}
/*!
- \brief configure hardware automatically trim mode
- \param[in] ctc_hardmode:
- \arg CTC_HARDWARE_TRIM_MODE_ENABLE: hardware automatically trim mode enable
- \arg CTC_HARDWARE_TRIM_MODE_DISABLE: hardware automatically trim mode disable
+ \brief configure the IRC48M trim value
+ \param[in] ctc_trim_value: 8-bit IRC48M trim value
+ \arg 0x00 - 0x3F
\param[out] none
\retval none
*/
-void ctc_hardware_trim_mode_config(uint32_t ctc_hardmode)
+void ctc_irc48m_trim_value_config(uint8_t trim_value)
{
- CTC_CTL0 &= (uint32_t)(~CTC_CTL0_AUTOTRIM);
- CTC_CTL0 |= (uint32_t)ctc_hardmode;
+ /* clear TRIMVALUE bits */
+ CTC_CTL0 &= (~(uint32_t)CTC_CTL0_TRIMVALUE);
+ /* set TRIMVALUE bits */
+ CTC_CTL0 |= ((uint32_t)trim_value << CTC_TRIM_VALUE_OFFSET);
}
/*!
- \brief enable CTC counter
+ \brief generate software reference source sync pulse
\param[in] none
\param[out] none
\retval none
*/
-void ctc_counter_enable(void)
+void ctc_software_refsource_pulse_generate(void)
{
- CTC_CTL0 |= (uint32_t)CTC_CTL0_CNTEN;
+ CTC_CTL0 |= (uint32_t)CTC_CTL0_SWREFPUL;
}
/*!
- \brief disable CTC counter
- \param[in] none
+ \brief configure hardware automatically trim mode
+ \param[in] hardmode:
+ only one parameter can be selected which is shown as below:
+ \arg CTC_HARDWARE_TRIM_MODE_ENABLE: hardware automatically trim mode enable
+ \arg CTC_HARDWARE_TRIM_MODE_DISABLE: hardware automatically trim mode disable
\param[out] none
\retval none
*/
-void ctc_counter_disable(void)
+void ctc_hardware_trim_mode_config(uint32_t hardmode)
{
- CTC_CTL0 &= (uint32_t)(~CTC_CTL0_CNTEN);
+ CTC_CTL0 &= (uint32_t)(~CTC_CTL0_AUTOTRIM);
+ CTC_CTL0 |= (uint32_t)hardmode;
}
/*!
\brief configure reference signal source polarity
- \param[in] ctc_polarity:
+ \param[in] polarity:
+ only one parameter can be selected which is shown as below:
\arg CTC_REFSOURCE_POLARITY_FALLING: reference signal source polarity is falling edge
\arg CTC_REFSOURCE_POLARITY_RISING: reference signal source polarity is rising edge
\param[out] none
\retval none
*/
-void ctc_refsource_polarity_config(uint32_t ctc_polarity)
+void ctc_refsource_polarity_config(uint32_t polarity)
{
CTC_CTL1 &= (uint32_t)(~CTC_CTL1_REFPOL);
- CTC_CTL1 |= (uint32_t)ctc_polarity;
+ CTC_CTL1 |= (uint32_t)polarity;
}
/*!
\brief select USBFS or USBHS SOF signal
- \param[in] ctc_usbsof:
+ \param[in] usbsof:
\arg CTC_USBSOFSEL_USBHS: USBHS SOF signal is selected
\arg CTC_USBSOFSEL_USBFS: USBFS SOF signal is selected
\param[out] none
\retval none
*/
-void ctc_usbsof_signal_select(uint32_t ctc_usbsof)
+void ctc_usbsof_signal_select(uint32_t usbsof)
{
CTC_CTL1 &= (uint32_t)(~CTC_CTL1_USBSOFSEL);
- CTC_CTL1 |= (uint32_t)ctc_usbsof;
+ CTC_CTL1 |= (uint32_t)usbsof;
}
/*!
\brief select reference signal source
- \param[in] ctc_refs:
+ \param[in] refs:
+ only one parameter can be selected which is shown as below:
\arg CTC_REFSOURCE_GPIO: GPIO is selected
- \arg CTC_REFSOURCE_LXTAL: LXTAL is clock selected
+ \arg CTC_REFSOURCE_LXTAL: LXTAL is selected
\arg CTC_REFSOURCE_USBSOF: USBSOF is selected
\param[out] none
\retval none
*/
-void ctc_refsource_signal_select(uint32_t ctc_refs)
+void ctc_refsource_signal_select(uint32_t refs)
{
CTC_CTL1 &= (uint32_t)(~CTC_CTL1_REFSEL);
- CTC_CTL1 |= (uint32_t)ctc_refs;
+ CTC_CTL1 |= (uint32_t)refs;
}
/*!
\brief configure reference signal source prescaler
- \param[in] ctc_prescaler:
+ \param[in] prescaler:
+ only one parameter can be selected which is shown as below:
\arg CTC_REFSOURCE_PSC_OFF: reference signal not divided
\arg CTC_REFSOURCE_PSC_DIV2: reference signal divided by 2
\arg CTC_REFSOURCE_PSC_DIV4: reference signal divided by 4
@@ -144,34 +180,36 @@ void ctc_refsource_signal_select(uint32_t ctc_refs)
\param[out] none
\retval none
*/
-void ctc_refsource_prescaler_config(uint32_t ctc_prescaler)
+void ctc_refsource_prescaler_config(uint32_t prescaler)
{
CTC_CTL1 &= (uint32_t)(~CTC_CTL1_REFPSC);
- CTC_CTL1 |= (uint32_t)ctc_prescaler;
+ CTC_CTL1 |= (uint32_t)prescaler;
}
/*!
\brief configure clock trim base limit value
- \param[in] ctc_limit_value: 8-bit clock trim base limit value
+ \param[in] limit_value: 8-bit clock trim base limit value
+ \arg 0x00 - 0xFF
\param[out] none
\retval none
*/
-void ctc_clock_limit_value_config(uint8_t ctc_limit_value)
+void ctc_clock_limit_value_config(uint8_t limit_value)
{
CTC_CTL1 &= (uint32_t)(~CTC_CTL1_CKLIM);
- CTC_CTL1 |= (uint32_t)((uint32_t)ctc_limit_value << 16);
+ CTC_CTL1 |= (uint32_t)((uint32_t)limit_value << CTC_LIMIT_VALUE_OFFSET);
}
/*!
\brief configure CTC counter reload value
- \param[in] ctc_reload_value: 16-bit CTC counter reload value
+ \param[in] reload_value: 16-bit CTC counter reload value
+ \arg 0x0000 - 0xFFFF
\param[out] none
\retval none
*/
-void ctc_counter_reload_value_config(uint16_t ctc_reload_value)
+void ctc_counter_reload_value_config(uint16_t reload_value)
{
CTC_CTL1 &= (uint32_t)(~CTC_CTL1_RLVALUE);
- CTC_CTL1 |= (uint32_t)ctc_reload_value;
+ CTC_CTL1 |= (uint32_t)reload_value;
}
/*!
@@ -183,7 +221,7 @@ void ctc_counter_reload_value_config(uint16_t ctc_reload_value)
uint16_t ctc_counter_capture_value_read(void)
{
uint16_t capture_value = 0U;
- capture_value = (uint16_t)((CTC_STAT & CTC_STAT_REFCAP)>> 16);
+ capture_value = (uint16_t)((CTC_STAT & CTC_STAT_REFCAP)>> CTC_REFCAP_OFFSET);
return (capture_value);
}
@@ -226,65 +264,71 @@ uint16_t ctc_counter_reload_value_read(void)
uint8_t ctc_irc48m_trim_value_read(void)
{
uint8_t trim_value = 0U;
- trim_value = (uint8_t)((CTC_CTL0 & CTC_CTL0_TRIMVALUE) >> 8);
+ trim_value = (uint8_t)((CTC_CTL0 & CTC_CTL0_TRIMVALUE) >> CTC_TRIMVALUE_OFFSET);
return (trim_value);
}
/*!
\brief enable the CTC interrupt
- \param[in] ctc_interrupt: CTC interrupt enable
- \arg CTC_INT_CKOKIE: clock trim OK interrupt enable
- \arg CTC_INT_CKWARNIE: clock trim warning interrupt enable
- \arg CTC_INT_ERRIE: error interrupt enable
- \arg CTC_INT_EREFIE: expect reference interrupt enable
+ \param[in] interrupt: CTC interrupt enable
+ one or more parameters can be selected which are shown as below:
+ \arg CTC_INT_CKOK: clock trim OK interrupt enable
+ \arg CTC_INT_CKWARN: clock trim warning interrupt enable
+ \arg CTC_INT_ERR: error interrupt enable
+ \arg CTC_INT_EREF: expect reference interrupt enable
\param[out] none
\retval none
*/
-void ctc_interrupt_enable(uint32_t ctc_interrupt)
+void ctc_interrupt_enable(uint32_t interrupt)
{
- CTC_CTL0 |= (uint32_t)ctc_interrupt;
+ CTC_CTL0 |= (uint32_t)interrupt;
}
/*!
\brief disable the CTC interrupt
- \param[in] ctc_interrupt: CTC interrupt enable source
- \arg CTC_INT_CKOKIE: clock trim OK interrupt enable
- \arg CTC_INT_CKWARNIE: clock trim warning interrupt enable
- \arg CTC_INT_ERRIE: error interrupt enable
- \arg CTC_INT_EREFIE: expect reference interrupt enable
+ \param[in] interrupt: CTC interrupt enable source
+ one or more parameters can be selected which are shown as below:
+ \arg CTC_INT_CKOK: clock trim OK interrupt enable
+ \arg CTC_INT_CKWARN: clock trim warning interrupt enable
+ \arg CTC_INT_ERR: error interrupt enable
+ \arg CTC_INT_EREF: expect reference interrupt enable
\param[out] none
\retval none
*/
-void ctc_interrupt_disable(uint32_t ctc_interrupt)
+void ctc_interrupt_disable(uint32_t interrupt)
{
- CTC_CTL0 &= (uint32_t)(~ctc_interrupt);
+ CTC_CTL0 &= (uint32_t)(~interrupt);
}
/*!
\brief get CTC interrupt flag
- \param[in] ctc_interrupt: the CTC interrupt flag
- \arg CTC_INT_CKOK: clock trim OK interrupt
- \arg CTC_INT_CKWARN: clock trim warning interrupt
- \arg CTC_INT_ERR: error interrupt
- \arg CTC_INT_EREF: expect reference interrupt
- \arg CTC_INT_CKERR: clock trim error bit interrupt
- \arg CTC_INT_REFMISS: reference sync pulse miss interrupt
- \arg CTC_INT_TRIMERR: trim value error interrupt
+ \param[in] int_flag: the CTC interrupt flag
+ only one parameter can be selected which is shown as below:
+ \arg CTC_INT_FLAG_CKOK: clock trim OK interrupt
+ \arg CTC_INT_FLAG_CKWARN: clock trim warning interrupt
+ \arg CTC_INT_FLAG_ERR: error interrupt
+ \arg CTC_INT_FLAG_EREF: expect reference interrupt
+ \arg CTC_INT_FLAG_CKERR: clock trim error bit interrupt
+ \arg CTC_INT_FLAG_REFMISS: reference sync pulse miss interrupt
+ \arg CTC_INT_FLAG_TRIMERR: trim value error interrupt
\param[out] none
\retval FlagStatus: SET or RESET
*/
-FlagStatus ctc_interrupt_flag_get(uint32_t ctc_interrupt)
+FlagStatus ctc_interrupt_flag_get(uint32_t int_flag)
{
- uint32_t interrupt = 0U, intenable = 0U;
+ uint32_t interrupt_flag = 0U, intenable = 0U;
- if(ctc_interrupt & CTC_FLAG_MASK){
- intenable = CTC_CTL0 & CTC_INT_ERRIE;
+ /* check whether the interrupt is enabled */
+ if(RESET != (int_flag & CTC_FLAG_MASK)){
+ intenable = CTC_CTL0 & CTC_CTL0_ERRIE;
}else{
- intenable = CTC_CTL0 & ctc_interrupt;
+ intenable = CTC_CTL0 & int_flag;
}
- interrupt = CTC_STAT & ctc_interrupt;
- if(interrupt && intenable){
+ /* get interrupt flag status */
+ interrupt_flag = CTC_STAT & int_flag;
+
+ if(interrupt_flag && intenable){
return SET;
}else{
return RESET;
@@ -293,32 +337,34 @@ FlagStatus ctc_interrupt_flag_get(uint32_t ctc_interrupt)
/*!
\brief clear CTC interrupt flag
- \param[in] ctc_interrupt: the CTC interrupt flag
- \arg CTC_INT_CKOK: clock trim OK interrupt
- \arg CTC_INT_CKWARN: clock trim warning interrupt
- \arg CTC_INT_ERR: error interrupt
- \arg CTC_INT_EREF: expect reference interrupt
- \arg CTC_INT_CKERR: clock trim error bit interrupt
- \arg CTC_INT_REFMISS: reference sync pulse miss interrupt
- \arg CTC_INT_TRIMERR: trim value error interrupt
+ \param[in] int_flag: the CTC interrupt flag
+ only one parameter can be selected which is shown as below:
+ \arg CTC_INT_FLAG_CKOK: clock trim OK interrupt
+ \arg CTC_INT_FLAG_CKWARN: clock trim warning interrupt
+ \arg CTC_INT_FLAG_ERR: error interrupt
+ \arg CTC_INT_FLAG_EREF: expect reference interrupt
+ \arg CTC_INT_FLAG_CKERR: clock trim error bit interrupt
+ \arg CTC_INT_FLAG_REFMISS: reference sync pulse miss interrupt
+ \arg CTC_INT_FLAG_TRIMERR: trim value error interrupt
\param[out] none
\retval none
-*/
-void ctc_interrupt_flag_clear(uint32_t ctc_interrupt)
+*/
+void ctc_interrupt_flag_clear(uint32_t int_flag)
{
- if(ctc_interrupt & CTC_FLAG_MASK){
+ if(RESET != (int_flag & CTC_FLAG_MASK)){
CTC_INTC |= CTC_INTC_ERRIC;
}else{
- CTC_INTC |= ctc_interrupt;
+ CTC_INTC |= int_flag;
}
}
/*!
\brief get CTC flag
- \param[in] ctc_flag: the CTC flag
+ \param[in] flag: the CTC flag
+ only one parameter can be selected which is shown as below:
\arg CTC_FLAG_CKOK: clock trim OK flag
- \arg CTC_FLAG_CKWARN: clock trim warning flag
- \arg CTC_FLAG_ERR: error flag
+ \arg CTC_FLAG_CKWARN: clock trim warning flag
+ \arg CTC_FLAG_ERR: error flag
\arg CTC_FLAG_EREF: expect reference flag
\arg CTC_FLAG_CKERR: clock trim error bit
\arg CTC_FLAG_REFMISS: reference sync pulse miss
@@ -326,9 +372,9 @@ void ctc_interrupt_flag_clear(uint32_t ctc_interrupt)
\param[out] none
\retval FlagStatus: SET or RESET
*/
-FlagStatus ctc_flag_get(uint32_t ctc_flag)
+FlagStatus ctc_flag_get(uint32_t flag)
{
- if(RESET != (CTC_STAT & ctc_flag)){
+ if(RESET != (CTC_STAT & flag)){
return SET;
}else{
return RESET;
@@ -337,10 +383,11 @@ FlagStatus ctc_flag_get(uint32_t ctc_flag)
/*!
\brief clear CTC flag
- \param[in] ctc_flag: the CTC flag
+ \param[in] flag: the CTC flag
+ only one parameter can be selected which is shown as below:
\arg CTC_FLAG_CKOK: clock trim OK flag
- \arg CTC_FLAG_CKWARN: clock trim warning flag
- \arg CTC_FLAG_ERR: error flag
+ \arg CTC_FLAG_CKWARN: clock trim warning flag
+ \arg CTC_FLAG_ERR: error flag
\arg CTC_FLAG_EREF: expect reference flag
\arg CTC_FLAG_CKERR: clock trim error bit
\arg CTC_FLAG_REFMISS: reference sync pulse miss
@@ -348,11 +395,11 @@ FlagStatus ctc_flag_get(uint32_t ctc_flag)
\param[out] none
\retval none
*/
-void ctc_flag_clear(uint32_t ctc_flag)
+void ctc_flag_clear(uint32_t flag)
{
- if(ctc_flag & CTC_FLAG_MASK){
+ if(RESET != (flag & CTC_FLAG_MASK)){
CTC_INTC |= CTC_INTC_ERRIC;
}else{
- CTC_INTC |= ctc_flag;
+ CTC_INTC |= flag;
}
}
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_dac.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_dac.c
index 2204d08c21..3a5dd52cdd 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_dac.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_dac.c
@@ -1,16 +1,46 @@
/*!
- \file gd32f4xx_dac.c
- \brief DAC driver
+ \file gd32f4xx_dac.c
+ \brief DAC driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#include "gd32f4xx_dac.h"
+/* DAC register bit offset */
+#define DAC1_REG_OFFSET ((uint32_t)16U)
+#define DH_12BIT_OFFSET ((uint32_t)16U)
+#define DH_8BIT_OFFSET ((uint32_t)8U)
+
/*!
\brief deinitialize DAC
\param[in] none
@@ -25,8 +55,7 @@ void dac_deinit(void)
/*!
\brief enable DAC
- \param[in] dac_periph
- \arg DACx(x =0,1)
+ \param[in] dac_periph: DACx(x = 0,1)
\param[out] none
\retval none
*/
@@ -37,12 +66,11 @@ void dac_enable(uint32_t dac_periph)
}else{
DAC_CTL |= DAC_CTL_DEN1;
}
-}
+}
/*!
\brief disable DAC
- \param[in] dac_periph
- \arg DACx(x =0,1)
+ \param[in] dac_periph: DACx(x = 0,1)
\param[out] none
\retval none
*/
@@ -57,8 +85,7 @@ void dac_disable(uint32_t dac_periph)
/*!
\brief enable DAC DMA function
- \param[in] dac_periph
- \arg DACx(x=0,1)
+ \param[in] dac_periph: DACx(x = 0,1)
\param[out] none
\retval none
*/
@@ -73,8 +100,7 @@ void dac_dma_enable(uint32_t dac_periph)
/*!
\brief disable DAC DMA function
- \param[in] dac_periph
- \arg DACx(x=0,1)
+ \param[in] dac_periph: DACx(x = 0,1)
\param[out] none
\retval none
*/
@@ -89,8 +115,7 @@ void dac_dma_disable(uint32_t dac_periph)
/*!
\brief enable DAC output buffer
- \param[in] dac_periph
- \arg DACx(x =0,1)
+ \param[in] dac_periph: DACx(x = 0,1)
\param[out] none
\retval none
*/
@@ -105,8 +130,7 @@ void dac_output_buffer_enable(uint32_t dac_periph)
/*!
\brief disable DAC output buffer
- \param[in] dac_periph
- \arg DACx(x =0,1)
+ \param[in] dac_periph: DACx(x = 0,1)
\param[out] none
\retval none
*/
@@ -120,132 +144,168 @@ void dac_output_buffer_disable(uint32_t dac_periph)
}
/*!
- \brief enable DAC trigger
- \param[in] dac_periph
- \arg DACx(x =0,1)
+ \brief get DAC output value
+ \param[in] dac_periph: DACx(x = 0,1)
\param[out] none
- \retval none
+ \retval DAC output data
*/
-void dac_trigger_enable(uint32_t dac_periph)
+uint16_t dac_output_value_get(uint32_t dac_periph)
{
+ uint16_t data = 0U;
if(DAC0 == dac_periph){
- DAC_CTL |= DAC_CTL_DTEN0;
+ /* store the DAC0 output value */
+ data = (uint16_t)DAC0_DO;
}else{
- DAC_CTL |= DAC_CTL_DTEN1;
+ /* store the DAC1 output value */
+ data = (uint16_t)DAC1_DO;
}
+ return data;
}
/*!
- \brief disable DAC trigger
- \param[in] dac_periph
- \arg DACx(x =0,1)
+ \brief set the DAC specified data holding register value
+ \param[in] dac_periph: DACx(x = 0,1)
+ \param[in] dac_align: data alignment
+ only one parameter can be selected which is shown as below:
+ \arg DAC_ALIGN_8B_R: data right 8 bit alignment
+ \arg DAC_ALIGN_12B_R: data right 12 bit alignment
+ \arg DAC_ALIGN_12B_L: data left 12 bit alignment
+ \param[in] data: data to be loaded
\param[out] none
\retval none
*/
-void dac_trigger_disable(uint32_t dac_periph)
+void dac_data_set(uint32_t dac_periph, uint32_t dac_align, uint16_t data)
{
if(DAC0 == dac_periph){
- DAC_CTL &= ~DAC_CTL_DTEN0;
+ switch(dac_align){
+ /* data right 12 bit alignment */
+ case DAC_ALIGN_12B_R:
+ DAC0_R12DH = data;
+ break;
+ /* data left 12 bit alignment */
+ case DAC_ALIGN_12B_L:
+ DAC0_L12DH = data;
+ break;
+ /* data right 8 bit alignment */
+ case DAC_ALIGN_8B_R:
+ DAC0_R8DH = data;
+ break;
+ default:
+ break;
+ }
}else{
- DAC_CTL &= ~DAC_CTL_DTEN1;
+ switch(dac_align){
+ /* data right 12 bit alignment */
+ case DAC_ALIGN_12B_R:
+ DAC1_R12DH = data;
+ break;
+ /* data left 12 bit alignment */
+ case DAC_ALIGN_12B_L:
+ DAC1_L12DH = data;
+ break;
+ /* data right 8 bit alignment */
+ case DAC_ALIGN_8B_R:
+ DAC1_R8DH = data;
+ break;
+ default:
+ break;
+ }
}
}
/*!
- \brief enable DAC software trigger
- \param[in] dac_periph
- \arg DACx(x =0,1)
+ \brief enable DAC trigger
+ \param[in] dac_periph: DACx(x = 0,1)
+ \param[out] none
\retval none
*/
-void dac_software_trigger_enable(uint32_t dac_periph)
+void dac_trigger_enable(uint32_t dac_periph)
{
if(DAC0 == dac_periph){
- DAC_SWT |= DAC_SWT_SWTR0;
+ DAC_CTL |= DAC_CTL_DTEN0;
}else{
- DAC_SWT |= DAC_SWT_SWTR1;
+ DAC_CTL |= DAC_CTL_DTEN1;
}
}
/*!
- \brief disable DAC software trigger
- \param[in] dac_periph
- \arg DACx(x =0,1)
+ \brief disable DAC trigger
+ \param[in] dac_periph: DACx(x = 0,1)
\param[out] none
\retval none
*/
-void dac_software_trigger_disable(uint32_t dac_periph)
+void dac_trigger_disable(uint32_t dac_periph)
{
if(DAC0 == dac_periph){
- DAC_SWT &= ~DAC_SWT_SWTR0;
+ DAC_CTL &= ~DAC_CTL_DTEN0;
}else{
- DAC_SWT &= ~DAC_SWT_SWTR1;
+ DAC_CTL &= ~DAC_CTL_DTEN1;
}
}
/*!
- \brief enable DAC interrupt(DAC0 DMA underrun interrupt)
- \param[in] dac_periph
- \arg DACx(x=0,1)
+ \brief set DAC trigger source
+ \param[in] dac_periph: DACx(x = 0,1)
+ \param[in] triggersource: external triggers of DAC
+ only one parameter can be selected which is shown as below:
+ \arg DAC_TRIGGER_T1_TRGO: TIMER1 TRGO
+ \arg DAC_TRIGGER_T3_TRGO: TIMER3 TRGO
+ \arg DAC_TRIGGER_T4_TRGO: TIMER4 TRGO
+ \arg DAC_TRIGGER_T5_TRGO: TIMER5 TRGO
+ \arg DAC_TRIGGER_T6_TRGO: TIMER6 TRGO
+ \arg DAC_TRIGGER_T7_TRGO: TIMER7 TRGO
+ \arg DAC_TRIGGER_EXTI_9: EXTI interrupt line9 event
+ \arg DAC_TRIGGER_SOFTWARE: software trigger
\param[out] none
\retval none
*/
-void dac_interrupt_enable(uint32_t dac_periph)
+void dac_trigger_source_config(uint32_t dac_periph,uint32_t triggersource)
{
if(DAC0 == dac_periph){
- DAC_CTL |= DAC_CTL_DDUDRIE0;
+ /* configure DAC0 trigger source */
+ DAC_CTL &= ~DAC_CTL_DTSEL0;
+ DAC_CTL |= triggersource;
}else{
- DAC_CTL |= DAC_CTL_DDUDRIE1;
+ /* configure DAC1 trigger source */
+ DAC_CTL &= ~DAC_CTL_DTSEL1;
+ DAC_CTL |= (triggersource << DAC1_REG_OFFSET);
}
}
/*!
- \brief disable DAC interrupt(DAC0 DMA underrun interrupt)
- \param[in] dac_periph
- \arg DACx(x=0,1)
- \param[out] none
+ \brief enable DAC software trigger
+ \param[in] dac_periph: DACx(x = 0,1)
\retval none
*/
-void dac_interrupt_disable(uint32_t dac_periph)
+void dac_software_trigger_enable(uint32_t dac_periph)
{
if(DAC0 == dac_periph){
- DAC_CTL &= ~DAC_CTL_DDUDRIE0;
+ DAC_SWT |= DAC_SWT_SWTR0;
}else{
- DAC_CTL &= ~DAC_CTL_DDUDRIE1;
+ DAC_SWT |= DAC_SWT_SWTR1;
}
}
/*!
- \brief set DAC trigger source
- \param[in] dac_periph
- \arg DACx(x =0,1)
- \param[in] triggersource: external triggers of DAC
- \arg DAC_TRIGGER_T1_TRGO: TIMER1 TRGO
- \arg DAC_TRIGGER_T3_TRGO: TIMER3 TRGO
- \arg DAC_TRIGGER_T4_TRGO: TIMER4 TRGO
- \arg DAC_TRIGGER_T5_TRGO: TIMER5 TRGO
- \arg DAC_TRIGGER_T6_TRGO: TIMER6 TRGO
- \arg DAC_TRIGGER_T7_TRGO: TIMER7 TRGO
- \arg DAC_TRIGGER_EXTI_9: EXTI interrupt line9 event
- \arg DAC_TRIGGER_SOFTWARE: software trigger
+ \brief disable DAC software trigger
+ \param[in] dac_periph: DACx(x = 0,1)
\param[out] none
\retval none
*/
-void dac_trigger_source_config(uint32_t dac_periph,uint32_t triggersource)
+void dac_software_trigger_disable(uint32_t dac_periph)
{
if(DAC0 == dac_periph){
- DAC_CTL &= ~DAC_CTL_DTSEL0;
- DAC_CTL |= triggersource;
+ DAC_SWT &= ~DAC_SWT_SWTR0;
}else{
- DAC_CTL &= ~DAC_CTL_DTSEL1;
- DAC_CTL |= (triggersource << 16);
+ DAC_SWT &= ~DAC_SWT_SWTR1;
}
}
/*!
\brief configure DAC wave mode
- \param[in] dac_periph
- \arg DACx(x=0,1)
- \param[in] wave_mode
+ \param[in] dac_periph: DACx(x = 0,1)
+ \param[in] wave_mode: noise wave mode
+ only one parameter can be selected which is shown as below:
\arg DAC_WAVE_DISABLE: wave disable
\arg DAC_WAVE_MODE_LFSR: LFSR noise mode
\arg DAC_WAVE_MODE_TRIANGLE: triangle noise mode
@@ -255,19 +315,21 @@ void dac_trigger_source_config(uint32_t dac_periph,uint32_t triggersource)
void dac_wave_mode_config(uint32_t dac_periph, uint32_t wave_mode)
{
if(DAC0 == dac_periph){
+ /* configure DAC0 wave mode */
DAC_CTL &= ~DAC_CTL_DWM0;
DAC_CTL |= wave_mode;
}else{
+ /* configure DAC1 wave mode */
DAC_CTL &= ~DAC_CTL_DWM1;
- DAC_CTL |= wave_mode << 16;
+ DAC_CTL |= (wave_mode << DAC1_REG_OFFSET);
}
}
/*!
\brief configure DAC wave bit width
- \param[in] dac_periph
- \arg DACx(x=0,1)
- \param[in] bit_width
+ \param[in] dac_periph: DACx(x = 0,1)
+ \param[in] bit_width: noise wave bit width
+ only one parameter can be selected which is shown as below:
\arg DAC_WAVE_BIT_WIDTH_1: bit width of the wave signal is 1
\arg DAC_WAVE_BIT_WIDTH_2: bit width of the wave signal is 2
\arg DAC_WAVE_BIT_WIDTH_3: bit width of the wave signal is 3
@@ -286,19 +348,21 @@ void dac_wave_mode_config(uint32_t dac_periph, uint32_t wave_mode)
void dac_wave_bit_width_config(uint32_t dac_periph, uint32_t bit_width)
{
if(DAC0 == dac_periph){
+ /* configure DAC0 wave bit width */
DAC_CTL &= ~DAC_CTL_DWBW0;
DAC_CTL |= bit_width;
}else{
+ /* configure DAC1 wave bit width */
DAC_CTL &= ~DAC_CTL_DWBW1;
- DAC_CTL |= bit_width << 16;
+ DAC_CTL |= (bit_width << DAC1_REG_OFFSET);
}
}
/*!
\brief configure DAC LFSR noise mode
- \param[in] dac_periph
- \arg DACx(x=0,1)
- \param[in] unmask_bits
+ \param[in] dac_periph: DACx(x = 0,1)
+ \param[in] unmask_bits: unmask LFSR bits in DAC LFSR noise mode
+ only one parameter can be selected which is shown as below:
\arg DAC_LFSR_BIT0: unmask the LFSR bit0
\arg DAC_LFSR_BITS1_0: unmask the LFSR bits[1:0]
\arg DAC_LFSR_BITS2_0: unmask the LFSR bits[2:0]
@@ -317,19 +381,21 @@ void dac_wave_bit_width_config(uint32_t dac_periph, uint32_t bit_width)
void dac_lfsr_noise_config(uint32_t dac_periph, uint32_t unmask_bits)
{
if(DAC0 == dac_periph){
+ /* configure DAC0 LFSR noise mode */
DAC_CTL &= ~DAC_CTL_DWBW0;
DAC_CTL |= unmask_bits;
}else{
+ /* configure DAC1 LFSR noise mode */
DAC_CTL &= ~DAC_CTL_DWBW1;
- DAC_CTL |= unmask_bits << 16;
+ DAC_CTL |= (unmask_bits << DAC1_REG_OFFSET);
}
}
/*!
\brief configure DAC triangle noise mode
- \param[in] dac_periph
- \arg DACx(x=0,1)
- \param[in] amplitude
+ \param[in] dac_periph: DACx(x = 0,1)
+ \param[in] amplitude: triangle amplitude in DAC triangle noise mode
+ only one parameter can be selected which is shown as below:
\arg DAC_TRIANGLE_AMPLITUDE_1: triangle amplitude is 1
\arg DAC_TRIANGLE_AMPLITUDE_3: triangle amplitude is 3
\arg DAC_TRIANGLE_AMPLITUDE_7: triangle amplitude is 7
@@ -348,33 +414,17 @@ void dac_lfsr_noise_config(uint32_t dac_periph, uint32_t unmask_bits)
void dac_triangle_noise_config(uint32_t dac_periph, uint32_t amplitude)
{
if(DAC0 == dac_periph){
+ /* configure DAC0 triangle noise mode */
DAC_CTL &= ~DAC_CTL_DWBW0;
DAC_CTL |= amplitude;
}else{
+ /* configure DAC1 triangle noise mode */
DAC_CTL &= ~DAC_CTL_DWBW1;
- DAC_CTL |= amplitude << 16;
+ DAC_CTL |= (amplitude << DAC1_REG_OFFSET);
}
}
/*!
- \brief get DAC output value
- \param[in] dac_periph
- \arg DACx(x=0,1)
- \param[out] none
- \retval DAC output data
-*/
-uint16_t dac_output_value_get(uint32_t dac_periph)
-{
- uint16_t data = 0U;
- if(DAC0 == dac_periph){
- data = (uint16_t)DAC0_DO;
- }else{
- data = (uint16_t)DAC1_DO;
- }
- return data;
-}
-
-/*!
\brief enable DAC concurrent mode
\param[in] none
\param[out] none
@@ -410,7 +460,7 @@ void dac_concurrent_software_trigger_enable(void)
{
uint32_t swt = 0U;
swt = DAC_SWT_SWTR0 | DAC_SWT_SWTR1;
- DAC_SWT |= (swt);
+ DAC_SWT |= (swt);
}
/*!
@@ -453,6 +503,42 @@ void dac_concurrent_output_buffer_disable(void)
}
/*!
+ \brief set DAC concurrent mode data holding register value
+ \param[in] dac_align: data alignment
+ only one parameter can be selected which is shown as below:
+ \arg DAC_ALIGN_8B_R: data right 8b alignment
+ \arg DAC_ALIGN_12B_R: data right 12b alignment
+ \arg DAC_ALIGN_12B_L: data left 12b alignment
+ \param[in] data0: data to be loaded
+ \param[in] data1: data to be loaded
+ \param[out] none
+ \retval none
+*/
+void dac_concurrent_data_set(uint32_t dac_align, uint16_t data0, uint16_t data1)
+{
+ uint32_t data = 0U;
+ switch(dac_align){
+ /* data right 12b alignment */
+ case DAC_ALIGN_12B_R:
+ data = ((uint32_t)data1 << DH_12BIT_OFFSET) | data0;
+ DACC_R12DH = data;
+ break;
+ /* data left 12b alignment */
+ case DAC_ALIGN_12B_L:
+ data = ((uint32_t)data1 << DH_12BIT_OFFSET) | data0;
+ DACC_L12DH = data;
+ break;
+ /* data right 8b alignment */
+ case DAC_ALIGN_8B_R:
+ data = ((uint32_t)data1 << DH_8BIT_OFFSET) | data0;
+ DACC_R8DH = data;
+ break;
+ default:
+ break;
+ }
+}
+
+/*!
\brief enable DAC concurrent interrupt funcution
\param[in] none
\param[out] none
@@ -479,97 +565,40 @@ void dac_concurrent_interrupt_disable(void)
}
/*!
- \brief set the DAC specified data holding register value
- \param[in] dac_periph
- \arg DACx(x=0,1)
- \param[in] dac_align
- \arg DAC_ALIGN_8B_R: data right 8b alignment
- \arg DAC_ALIGN_12B_R: data right 12b alignment
- \arg DAC_ALIGN_12B_L: data left 12b alignment
- \param[in] data: data to be loaded
+ \brief enable DAC interrupt(DAC DMA underrun interrupt)
+ \param[in] dac_periph: DACx(x = 0,1)
\param[out] none
\retval none
*/
-void dac_data_set(uint32_t dac_periph, uint32_t dac_align, uint16_t data)
+void dac_interrupt_enable(uint32_t dac_periph)
{
if(DAC0 == dac_periph){
- switch(dac_align){
- /* data right 12b alignment */
- case DAC_ALIGN_12B_R:
- DAC0_R12DH = data;
- break;
- /* data left 12b alignment */
- case DAC_ALIGN_12B_L:
- DAC0_L12DH = data;
- break;
- /* data right 8b alignment */
- case DAC_ALIGN_8B_R:
- DAC0_R8DH = data;
- break;
- default:
- break;
- }
+ DAC_CTL |= DAC_CTL_DDUDRIE0;
}else{
- switch(dac_align){
- /* data right 12b alignment */
- case DAC_ALIGN_12B_R:
- DAC1_R12DH = data;
- break;
- /* data left 12b alignment */
- case DAC_ALIGN_12B_L:
- DAC1_L12DH = data;
- break;
- /* data right 8b alignment */
- case DAC_ALIGN_8B_R:
- DAC1_R8DH = data;
- break;
- default:
- break;
- }
+ DAC_CTL |= DAC_CTL_DDUDRIE1;
}
}
/*!
- \brief set DAC concurrent mode data holding register value
- \param[in] dac_align
- \arg DAC_ALIGN_8B_R: data right 8b alignment
- \arg DAC_ALIGN_12B_R: data right 12b alignment
- \arg DAC_ALIGN_12B_L: data left 12b alignment
- \param[in] data0: data to be loaded
- \param[in] data1: data to be loaded
+ \brief disable DAC interrupt(DAC DMA underrun interrupt)
+ \param[in] dac_periph: DACx(x = 0,1)
\param[out] none
\retval none
*/
-void dac_concurrent_data_set(uint32_t dac_align, uint16_t data0, uint16_t data1)
+void dac_interrupt_disable(uint32_t dac_periph)
{
- uint32_t data = 0U;
- switch(dac_align){
- /* data right 12b alignment */
- case DAC_ALIGN_12B_R:
- data = ((uint32_t)data1 << 16) | data0;
- DACC_R12DH = data;
- break;
- /* data left 12b alignment */
- case DAC_ALIGN_12B_L:
- data = ((uint32_t)data1 << 16) | data0;
- DACC_L12DH = data;
- break;
- /* data right 8b alignment */
- case DAC_ALIGN_8B_R:
- data = ((uint32_t)data1 << 8) | data0;
- DACC_R8DH = data;
- break;
- default:
- break;
+ if(DAC0 == dac_periph){
+ DAC_CTL &= ~DAC_CTL_DDUDRIE0;
+ }else{
+ DAC_CTL &= ~DAC_CTL_DDUDRIE1;
}
}
/*!
- \brief get the specified DAC flag(DAC DMA underrun flag)
- \param[in] dac_periph
- \arg DACx(x=0,1)
+ \brief get the specified DAC flag (DAC DMA underrun flag)
+ \param[in] dac_periph: DACx(x = 0,1)
\param[out] none
- \retval the state of dac bit(SET or RESET)
+ \retval FlagStatus: SET or RESET
*/
FlagStatus dac_flag_get(uint32_t dac_periph)
{
@@ -589,9 +618,8 @@ FlagStatus dac_flag_get(uint32_t dac_periph)
}
/*!
- \brief clear the specified DAC flag(DAC DMA underrun flag)
- \param[in] dac_periph
- \arg DACx(x=0,1)
+ \brief clear the specified DAC flag (DAC DMA underrun flag)
+ \param[in] dac_periph: DACx(x = 0,1)
\param[out] none
\retval none
*/
@@ -605,16 +633,16 @@ void dac_flag_clear(uint32_t dac_periph)
}
/*!
- \brief get the specified DAC interrupt flag(DAC DMA underrun interrupt flag)
- \param[in] dac_periph
- \arg DACx(x=0,1)
+ \brief get the specified DAC interrupt flag (DAC DMA underrun interrupt flag)
+ \param[in] dac_periph: DACx(x = 0,1)
\param[out] none
- \retval the state of DAC interrupt flag(SET or RESET)
+ \retval FlagStatus: SET or RESET
*/
FlagStatus dac_interrupt_flag_get(uint32_t dac_periph)
{
FlagStatus temp_flag = RESET;
uint32_t ddudr_flag = 0U, ddudrie_flag = 0U;
+
if(DAC0 == dac_periph){
/* check the DMA underrun flag and DAC DMA underrun interrupt enable flag */
ddudr_flag = DAC_STAT & DAC_STAT_DDUDR0;
@@ -634,9 +662,8 @@ FlagStatus dac_interrupt_flag_get(uint32_t dac_periph)
}
/*!
- \brief clear the specified DAC interrupt flag(DAC DMA underrun interrupt flag)
- \param[in] dac_periph
- \arg DACx(x=0,1)
+ \brief clear the specified DAC interrupt flag (DAC DMA underrun interrupt flag)
+ \param[in] dac_periph: DACx(x = 0,1)
\param[out] none
\retval none
*/
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_dbg.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_dbg.c
index a017c7e3e5..a408136ea4 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_dbg.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_dbg.c
@@ -1,16 +1,55 @@
/*!
- \file gd32f4xx_dbg.c
- \brief DBG driver
+ \file gd32f4xx_dbg.c
+ \brief DBG driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#include "gd32f4xx_dbg.h"
+#define DBG_RESET_VAL 0x00000000U
+
+/*!
+ \brief deinitialize the DBG
+ \param[in] none
+ \param[out] none
+ \retval none
+*/
+void dbg_deinit(void)
+{
+ DBG_CTL0 = DBG_RESET_VAL;
+ DBG_CTL1 = DBG_RESET_VAL;
+}
+
/*!
\brief read DBG_ID code register
\param[in] none
@@ -55,32 +94,69 @@ void dbg_low_power_disable(uint32_t dbg_low_power)
/*!
\brief enable peripheral behavior when the mcu is in debug mode
\param[in] dbg_periph: dbg_periph_enum
- \param[out] none
+ only one parameter can be selected which is shown as below:
+ \arg DBG_TIMER1_HOLD: hold TIMER1 counter when core is halted
+ \arg DBG_TIMER2_HOLD: hold TIMER2 counter when core is halted
+ \arg DBG_TIMER3_HOLD: hold TIMER3 counter when core is halted
+ \arg DBG_TIMER4_HOLD: hold TIMER4 counter when core is halted
+ \arg DBG_TIMER5_HOLD: hold TIMER5 counter when core is halted
+ \arg DBG_TIMER6_HOLD: hold TIMER6 counter when core is halted
+ \arg DBG_TIMER11_HOLD: hold TIMER11 counter when core is halted
+ \arg DBG_TIMER12_HOLD: hold TIMER12 counter when core is halted
+ \arg DBG_TIMER13_HOLD: hold TIMER13 counter when core is halted
+ \arg DBG_RTC_HOLD: hold RTC calendar and wakeup counter when core is halted
+ \arg DBG_WWDGT_HOLD: debug WWDGT kept when core is halted
+ \arg DBG_FWDGT_HOLD: debug FWDGT kept when core is halted
+ \arg DBG_I2C0_HOLD: hold I2C0 smbus when core is halted
+ \arg DBG_I2C1_HOLD: hold I2C1 smbus when core is halted
+ \arg DBG_I2C2_HOLD: hold I2C2 smbus when core is halted
+ \arg DBG_CAN0_HOLD: debug CAN0 kept when core is halted
+ \arg DBG_CAN1_HOLD: debug CAN1 kept when core is halted
+ \arg DBG_TIMER0_HOLD: hold TIMER0 counter when core is halted
+ \arg DBG_TIMER7_HOLD: hold TIMER7 counter when core is halted
+ \arg DBG_TIMER8_HOLD: hold TIMER8 counter when core is halted
+ \arg DBG_TIMER9_HOLD: hold TIMER9 counter when core is halted
+ \arg DBG_TIMER10_HOLD: hold TIMER10 counter when core is halted
+ \arg \param[out] none
\retval none
*/
void dbg_periph_enable(dbg_periph_enum dbg_periph)
{
- if(RESET == ((uint32_t)dbg_periph & BIT(30))){
- DBG_CTL1 |= (uint32_t)dbg_periph;
- }else{
- DBG_CTL2 |= ((uint32_t)dbg_periph & (~BIT(30)));
- }
-
+ DBG_REG_VAL(dbg_periph) |= BIT(DBG_BIT_POS(dbg_periph));
}
/*!
\brief disable peripheral behavior when the mcu is in debug mode
\param[in] dbg_periph: dbg_periph_enum
+ only one parameter can be selected which is shown as below:
+ \arg DBG_TIMER1_HOLD: hold TIMER1 counter when core is halted
+ \arg DBG_TIMER2_HOLD: hold TIMER2 counter when core is halted
+ \arg DBG_TIMER3_HOLD: hold TIMER3 counter when core is halted
+ \arg DBG_TIMER4_HOLD: hold TIMER4 counter when core is halted
+ \arg DBG_TIMER5_HOLD: hold TIMER5 counter when core is halted
+ \arg DBG_TIMER6_HOLD: hold TIMER6 counter when core is halted
+ \arg DBG_TIMER11_HOLD: hold TIMER11 counter when core is halted
+ \arg DBG_TIMER12_HOLD: hold TIMER12 counter when core is halted
+ \arg DBG_TIMER13_HOLD: hold TIMER13 counter when core is halted
+ \arg DBG_RTC_HOLD: hold RTC calendar and wakeup counter when core is halted
+ \arg DBG_WWDGT_HOLD: debug WWDGT kept when core is halted
+ \arg DBG_FWDGT_HOLD: debug FWDGT kept when core is halted
+ \arg DBG_I2C0_HOLD: hold I2C0 smbus when core is halted
+ \arg DBG_I2C1_HOLD: hold I2C1 smbus when core is halted
+ \arg DBG_I2C2_HOLD: hold I2C2 smbus when core is halted
+ \arg DBG_CAN0_HOLD: debug CAN0 kept when core is halted
+ \arg DBG_CAN1_HOLD: debug CAN1 kept when core is halted
+ \arg DBG_TIMER0_HOLD: hold TIMER0 counter when core is halted
+ \arg DBG_TIMER7_HOLD: hold TIMER7 counter when core is halted
+ \arg DBG_TIMER8_HOLD: hold TIMER8 counter when core is halted
+ \arg DBG_TIMER9_HOLD: hold TIMER9 counter when core is halted
+ \arg DBG_TIMER10_HOLD: hold TIMER10 counter when core is halted
\param[out] none
\retval none
*/
void dbg_periph_disable(dbg_periph_enum dbg_periph)
{
- if(RESET == ((uint32_t)dbg_periph & BIT(30))){
- DBG_CTL1 &= ~(uint32_t)dbg_periph;
- }else{
- DBG_CTL2 &= ~((uint32_t)dbg_periph & (~BIT(30)));
- }
+ DBG_REG_VAL(dbg_periph) &= ~BIT(DBG_BIT_POS(dbg_periph));
}
/*!
@@ -106,9 +182,9 @@ void dbg_trace_pin_disable(void)
}
/*!
- \brief trace pin mode selection
+ \brief trace pin mode selection
\param[in] trace_mode:
- \arg TRACE_MODE_ASYNC: trace pin used for async mode
+ \arg TRACE_MODE_ASYNC: trace pin used for async mode
\arg TRACE_MODE_SYNC_DATASIZE_1: trace pin used for sync mode and data size is 1
\arg TRACE_MODE_SYNC_DATASIZE_2: trace pin used for sync mode and data size is 2
\arg TRACE_MODE_SYNC_DATASIZE_4: trace pin used for sync mode and data size is 4
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_dci.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_dci.c
index 2984ff11f7..a1ddcab384 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_dci.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_dci.c
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_dci.c
- \brief DCI driver
+ \file gd32f4xx_dci.c
+ \brief DCI driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#include "gd32f4xx_dci.h"
@@ -25,11 +50,11 @@ void dci_deinit(void)
/*!
\brief initialize DCI registers
- \param[in] dci_struct: DCI parameter initialization stuct
+ \param[in] dci_struct: DCI parameter initialization structure
members of the structure and the member values are shown as below:
capture_mode : DCI_CAPTURE_MODE_CONTINUOUS, DCI_CAPTURE_MODE_SNAPSHOT
colck_polarity : DCI_CK_POLARITY_FALLING, DCI_CK_POLARITY_RISING
- hsync_polarity : DCI_HSYNC_POLARITY_LOW, DCI_HSYNC_POLARITY_HIGH
+ hsync_polarity : DCI_HSYNC_POLARITY_LOW, DCI_HSYNC_POLARITY_HIGH
vsync_polarity : DCI_VSYNC_POLARITY_LOW, DCI_VSYNC_POLARITY_HIGH
frame_rate : DCI_FRAME_RATE_ALL, DCI_FRAME_RATE_1_2, DCI_FRAME_RATE_1_4
interface_format: DCI_INTERFACE_FORMAT_8BITS, DCI_INTERFACE_FORMAT_10BITS,
@@ -39,10 +64,10 @@ void dci_deinit(void)
*/
void dci_init(dci_parameter_struct* dci_struct)
{
- uint32_t reg =0U;
+ uint32_t reg = 0U;
/* disable capture function and DCI */
DCI_CTL &= ~(DCI_CTL_CAP | DCI_CTL_DCIEN);
- /* config DCI parameter */
+ /* configure DCI parameter */
reg |= dci_struct->capture_mode;
reg |= dci_struct->clock_polarity;
reg |= dci_struct->hsync_polarity;
@@ -54,18 +79,18 @@ void dci_init(dci_parameter_struct* dci_struct)
}
/*!
- \brief enable DCI function
+ \brief enable DCI function
\param[in] none
\param[out] none
\retval none
*/
void dci_enable(void)
{
- DCI_CTL |= DCI_CTL_DCIEN;
+ DCI_CTL |= DCI_CTL_DCIEN;
}
/*!
- \brief disable DCI function
+ \brief disable DCI function
\param[in] none
\param[out] none
\retval none
@@ -76,7 +101,7 @@ void dci_disable(void)
}
/*!
- \brief enable DCI capture
+ \brief enable DCI capture
\param[in] none
\param[out] none
\retval none
@@ -87,7 +112,7 @@ void dci_capture_enable(void)
}
/*!
- \brief disable DCI capture
+ \brief disable DCI capture
\param[in] none
\param[out] none
\retval none
@@ -98,7 +123,7 @@ void dci_capture_disable(void)
}
/*!
- \brief enable DCI jpeg mode
+ \brief enable DCI jpeg mode
\param[in] none
\param[out] none
\retval none
@@ -109,7 +134,7 @@ void dci_jpeg_enable(void)
}
/*!
- \brief disable DCI jpeg mode
+ \brief disable DCI jpeg mode
\param[in] none
\param[out] none
\retval none
@@ -142,11 +167,11 @@ void dci_crop_window_disable(void)
}
/*!
- \brief config DCI cropping window
+ \brief configure DCI cropping window
\param[in] start_x: window horizontal start position
\param[in] start_y: window vertical start position
- \param[in] size_height: window horizontal size
- \param[in] size_width: window vertical size
+ \param[in] size_width: window horizontal size
+ \param[in] size_height: window vertical size
\param[out] none
\retval none
*/
@@ -157,28 +182,28 @@ void dci_crop_window_config(uint16_t start_x, uint16_t start_y, uint16_t size_wi
}
/*!
- \brief enable sync codes function
+ \brief enable embedded synchronous mode
\param[in] none
\param[out] none
\retval none
*/
-void dci_sync_codes_enable(void)
+void dci_embedded_sync_enable(void)
{
DCI_CTL |= DCI_CTL_ESM;
}
/*!
- \brief disable sync codes function
+ \brief disble embedded synchronous mode
\param[in] none
\param[out] none
\retval none
*/
-void dci_sync_codes_disable(void)
+void dci_embedded_sync_disable(void)
{
DCI_CTL &= ~DCI_CTL_ESM;
}
/*!
- \brief config sync codes
+ \brief config synchronous codes in embedded synchronous mode
\param[in] frame_start: frame start code in embedded synchronous mode
\param[in] line_start: line start code in embedded synchronous mode
\param[in] line_end: line end code in embedded synchronous mode
@@ -192,7 +217,7 @@ void dci_sync_codes_config(uint8_t frame_start, uint8_t line_start, uint8_t line
}
/*!
- \brief config sync codes unmask
+ \brief config synchronous codes unmask in embedded synchronous mode
\param[in] frame_start: frame start code unmask bits in embedded synchronous mode
\param[in] line_start: line start code unmask bits in embedded synchronous mode
\param[in] line_end: line end code unmask bits in embedded synchronous mode
@@ -202,7 +227,7 @@ void dci_sync_codes_config(uint8_t frame_start, uint8_t line_start, uint8_t line
*/
void dci_sync_codes_unmask_config(uint8_t frame_start, uint8_t line_start, uint8_t line_end, uint8_t frame_end)
{
- DCI_SCUMSK = ((uint32_t)frame_start | ((uint32_t)line_start<<8) | ((uint32_t)line_end<<16) | ((uint32_t)frame_end<<24));
+ DCI_SCUMSK = ((uint32_t)frame_start | ((uint32_t)line_start<<8) | ((uint32_t)line_end<<16) | ((uint32_t)frame_end<<24));
}
/*!
@@ -217,12 +242,45 @@ uint32_t dci_data_read(void)
}
/*!
+ \brief get specified flag
+ \param[in] flag:
+ \arg DCI_FLAG_HS: HS line status
+ \arg DCI_FLAG_VS: VS line status
+ \arg DCI_FLAG_FV:FIFO valid
+ \arg DCI_FLAG_EF: end of frame flag
+ \arg DCI_FLAG_OVR: FIFO overrun flag
+ \arg DCI_FLAG_ESE: embedded synchronous error flag
+ \arg DCI_FLAG_VSYNC: vsync flag
+ \arg DCI_FLAG_EL: end of line flag
+ \param[out] none
+ \retval FlagStatus: SET or RESET
+*/
+FlagStatus dci_flag_get(uint32_t flag)
+{
+ uint32_t stat = 0U;
+
+ if(flag >> 31){
+ /* get flag status from DCI_STAT1 register */
+ stat = DCI_STAT1;
+ }else{
+ /* get flag status from DCI_STAT0 register */
+ stat = DCI_STAT0;
+ }
+
+ if(flag & stat){
+ return SET;
+ }else{
+ return RESET;
+ }
+}
+
+/*!
\brief enable specified DCI interrupt
\param[in] interrupt:
\arg DCI_INT_EF: end of frame interrupt
\arg DCI_INT_OVR: FIFO overrun interrupt
- \arg DCI_INT_ESE: embedded synchronous error interrupt
- \arg DCI_INT_VS: vsync interrupt
+ \arg DCI_INT_ESE: embedded synchronous error interrupt
+ \arg DCI_INT_VSYNC: vsync interrupt
\arg DCI_INT_EL: end of line interrupt
\param[out] none
\retval none
@@ -237,8 +295,8 @@ void dci_interrupt_enable(uint32_t interrupt)
\param[in] interrupt:
\arg DCI_INT_EF: end of frame interrupt
\arg DCI_INT_OVR: FIFO overrun interrupt
- \arg DCI_INT_ESE: embedded synchronous error interrupt
- \arg DCI_INT_VS: vsync interrupt
+ \arg DCI_INT_ESE: embedded synchronous error interrupt
+ \arg DCI_INT_VSYNC: vsync interrupt
\arg DCI_INT_EL: end of line interrupt
\param[out] none
\retval none
@@ -249,93 +307,39 @@ void dci_interrupt_disable(uint32_t interrupt)
}
/*!
- \brief clear specified interrupt
- \param[in] interrupt:
+ \brief clear specified interrupt flag
+ \param[in] int_flag:
\arg DCI_INT_EF: end of frame interrupt
\arg DCI_INT_OVR: FIFO overrun interrupt
- \arg DCI_INT_ESE: embedded synchronous error interrupt
- \arg DCI_INT_VS: vsync interrupt
+ \arg DCI_INT_ESE: embedded synchronous error interrupt
+ \arg DCI_INT_VSYNC: vsync interrupt
\arg DCI_INT_EL: end of line interrupt
\param[out] none
\retval none
*/
-void dci_interrupt_clear(uint32_t interrupt)
+void dci_interrupt_flag_clear(uint32_t int_flag)
{
- DCI_INTC |= interrupt;
-}
-
-/*!
- \brief get specified flag
- \param[in] flag:
- \arg DCI_FLAG_HS: HS line status
- \arg DCI_FLAG_VS: VS line status
- \arg DCI_FLAG_FV:FIFO valid
- \arg DCI_FLAG_EFF: end of frame flag
- \arg DCI_FLAG_OVRF: FIFO overrun flag
- \arg DCI_FLAG_ESEF: embedded synchronous error flag
- \arg DCI_FLAG_VSF: vsync flag
- \arg DCI_FLAG_ELF: end of line flag
- \param[out] none
- \retval FlagStatus: SET or RESET
-*/
-FlagStatus dci_flag_get(uint32_t flag)
-{
- uint32_t ret = 0U;
-
- switch(flag){
- /* get flag status from DCI_STAT0 register */
- case DCI_FLAG_HS:
- ret = (DCI_STAT0 & DCI_STAT0_HS);
- break;
- case DCI_FLAG_VS:
- ret = (DCI_STAT0 & DCI_STAT0_VS);
- break;
- case DCI_FLAG_FV:
- ret = (DCI_STAT0 & DCI_STAT0_FV);
- break;
- /* get flag status from DCI_STAT1 register */
- case DCI_FLAG_EFF:
- ret = (DCI_STAT1 & DCI_STAT1_EFF);
- break;
- case DCI_FLAG_OVRF:
- ret = (DCI_STAT1 & DCI_STAT1_OVRF);
- break;
- case DCI_FLAG_ESEF:
- ret = (DCI_STAT1 & DCI_STAT1_ESEF);
- break;
- case DCI_FLAG_VSF:
- ret = (DCI_STAT1 & DCI_STAT1_VSF);
- break;
- case DCI_FLAG_ELF:
- ret = (DCI_STAT1 & DCI_STAT1_ELF);
- break;
- default :
- break;
- }
-
- if(RESET == ret){
- return RESET;
- }else{
- return SET;
- }
+ DCI_INTC |= int_flag;
}
/*!
\brief get specified interrupt flag
- \param[in] interrupt:
- \arg DCI_INT_EF: end of frame interrupt
- \arg DCI_INT_OVR: FIFO overrun interrupt
- \arg DCI_INT_ESE: embedded synchronous error interrupt
- \arg DCI_INT_VS: vsync interrupt
- \arg DCI_INT_EL: end of line interrupt
+ \param[in] int_flag:
+ \arg DCI_INT_FLAG_EF: end of frame interrupt flag
+ \arg DCI_INT_FLAG_OVR: FIFO overrun interrupt flag
+ \arg DCI_INT_FLAG_ESE: embedded synchronous error interrupt flag
+ \arg DCI_INT_FLAG_VSYNC: vsync interrupt flag
+ \arg DCI_INT_FLAG_EL: end of line interrupt flag
\param[out] none
\retval FlagStatus: SET or RESET
*/
-FlagStatus dci_interrupt_flag_get(uint32_t interrupt)
+FlagStatus dci_interrupt_flag_get(uint32_t int_flag)
{
- if(RESET == (DCI_INTF & interrupt)){
+ if(RESET == (DCI_INTF & int_flag)){
return RESET;
}else{
return SET;
}
}
+
+
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_dma.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_dma.c
index c7f5ce9a70..d8bd7be2d7 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_dma.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_dma.c
@@ -1,14 +1,40 @@
/*!
- \file gd32f4xx_dma.c
- \brief DMA driver
+ \file gd32f4xx_dma.c
+ \brief DMA driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
+
#include "gd32f4xx_dma.h"
/* DMA register bit offset */
@@ -23,7 +49,7 @@
\param[out] none
\retval none
*/
-void dma_deinit(uint32_t dma_periph,dma_channel_enum channelx)
+void dma_deinit(uint32_t dma_periph, dma_channel_enum channelx)
{
/* disable DMA a channel */
DMA_CHCTL(dma_periph,channelx) &= ~DMA_CHXCTL_CHEN;
@@ -37,11 +63,55 @@ void dma_deinit(uint32_t dma_periph,dma_channel_enum channelx)
if(channelx < DMA_CH4){
DMA_INTC0(dma_periph) |= DMA_FLAG_ADD(DMA_CHINTF_RESET_VALUE,channelx);
}else{
+ channelx -= (dma_channel_enum)4;
DMA_INTC1(dma_periph) |= DMA_FLAG_ADD(DMA_CHINTF_RESET_VALUE,channelx);
}
}
/*!
+ \brief initialize the DMA single data mode parameters struct with the default values
+ \param[in] init_struct: the initialization data needed to initialize DMA channel
+ \param[out] none
+ \retval none
+*/
+void dma_single_data_para_struct_init(dma_single_data_parameter_struct* init_struct)
+{
+ /* set the DMA struct with the default values */
+ init_struct->periph_addr = 0U;
+ init_struct->periph_inc = DMA_PERIPH_INCREASE_DISABLE;
+ init_struct->memory0_addr = 0U;
+ init_struct->memory_inc = DMA_MEMORY_INCREASE_DISABLE;
+ init_struct->periph_memory_width = 0U;
+ init_struct->circular_mode = DMA_CIRCULAR_MODE_DISABLE;
+ init_struct->direction = DMA_PERIPH_TO_MEMORY;
+ init_struct->number = 0U;
+ init_struct->priority = DMA_PRIORITY_LOW;
+}
+
+/*!
+ \brief initialize the DMA multi data mode parameters struct with the default values
+ \param[in] init_struct: the initialization data needed to initialize DMA channel
+ \param[out] none
+ \retval none
+*/
+void dma_multi_data_para_struct_init(dma_multi_data_parameter_struct* init_struct)
+{
+ /* set the DMA struct with the default values */
+ init_struct->periph_addr = 0U;
+ init_struct->periph_width = 0U;
+ init_struct->periph_inc = DMA_PERIPH_INCREASE_DISABLE;
+ init_struct->memory0_addr = 0U;
+ init_struct->memory_width = 0U;
+ init_struct->memory_inc = DMA_MEMORY_INCREASE_DISABLE;
+ init_struct->memory_burst_width = 0U;
+ init_struct->periph_burst_width = 0U;
+ init_struct->circular_mode = DMA_CIRCULAR_MODE_DISABLE;
+ init_struct->direction = DMA_PERIPH_TO_MEMORY;
+ init_struct->number = 0U;
+ init_struct->priority = DMA_PRIORITY_LOW;
+}
+
+/*!
\brief initialize DMA single data mode
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
@@ -49,57 +119,57 @@ void dma_deinit(uint32_t dma_periph,dma_channel_enum channelx)
\arg DMA_CHx(x=0..7)
\param[in] init_struct: the data needed to initialize DMA single data mode
periph_addr: peripheral base address
- periph_memory_width: DMA_PERIPH_WIDTH_8BIT,DMA_PERIPH_WIDTH_16BIT,DMA_PERIPH_WIDTH_32BIT
- periph_inc: DMA_PERIPH_INCREASE_ENABLE,DMA_PERIPH_INCREASE_DISABLE,DMA_PERIPH_INCREASE_FIX
+ periph_inc: DMA_PERIPH_INCREASE_ENABLE,DMA_PERIPH_INCREASE_DISABLE,DMA_PERIPH_INCREASE_FIX
memory0_addr: memory base address
memory_inc: DMA_MEMORY_INCREASE_ENABLE,DMA_MEMORY_INCREASE_DISABLE
+ periph_memory_width: DMA_PERIPH_WIDTH_8BIT,DMA_PERIPH_WIDTH_16BIT,DMA_PERIPH_WIDTH_32BIT
+ circular_mode: DMA_CIRCULAR_MODE_ENABLE,DMA_CIRCULAR_MODE_DISABLE
direction: DMA_PERIPH_TO_MEMORY,DMA_MEMORY_TO_PERIPH,DMA_MEMORY_TO_MEMORY
number: the number of remaining data to be transferred by the DMA
priority: DMA_PRIORITY_LOW,DMA_PRIORITY_MEDIUM,DMA_PRIORITY_HIGH,DMA_PRIORITY_ULTRA_HIGH
- circular_mode: DMA_CIRCULAR_MODE_ENABLE,DMA_CIRCULAR_MODE_DISABLE
\param[out] none
\retval none
*/
-void dma_single_data_mode_init(uint32_t dma_periph,dma_channel_enum channelx,dma_single_data_parameter_struct init_struct)
+void dma_single_data_mode_init(uint32_t dma_periph, dma_channel_enum channelx, dma_single_data_parameter_struct* init_struct)
{
uint32_t ctl;
-
+
/* select single data mode */
DMA_CHFCTL(dma_periph,channelx) &= ~DMA_CHXFCTL_MDMEN;
-
+
/* configure peripheral base address */
- DMA_CHPADDR(dma_periph,channelx) = init_struct.periph_addr;
-
+ DMA_CHPADDR(dma_periph,channelx) = init_struct->periph_addr;
+
/* configure memory base address */
- DMA_CHM0ADDR(dma_periph,channelx) = init_struct.memory0_addr;
-
+ DMA_CHM0ADDR(dma_periph,channelx) = init_struct->memory0_addr;
+
/* configure the number of remaining data to be transferred */
- DMA_CHCNT(dma_periph,channelx) = init_struct.number;
-
+ DMA_CHCNT(dma_periph,channelx) = init_struct->number;
+
/* configure peripheral and memory transfer width,channel priotity,transfer mode */
ctl = DMA_CHCTL(dma_periph,channelx);
ctl &= ~(DMA_CHXCTL_PWIDTH | DMA_CHXCTL_MWIDTH | DMA_CHXCTL_PRIO | DMA_CHXCTL_TM);
- ctl |= (init_struct.periph_memory_width | (init_struct.periph_memory_width << 2) | init_struct.priority | init_struct.direction);
+ ctl |= (init_struct->periph_memory_width | (init_struct->periph_memory_width << 2) | init_struct->priority | init_struct->direction);
DMA_CHCTL(dma_periph,channelx) = ctl;
/* configure peripheral increasing mode */
- if(DMA_PERIPH_INCREASE_ENABLE == init_struct.periph_inc){
+ if(DMA_PERIPH_INCREASE_ENABLE == init_struct->periph_inc){
DMA_CHCTL(dma_periph,channelx) |= DMA_CHXCTL_PNAGA;
- }else if(DMA_PERIPH_INCREASE_DISABLE == init_struct.periph_inc){
+ }else if(DMA_PERIPH_INCREASE_DISABLE == init_struct->periph_inc){
DMA_CHCTL(dma_periph,channelx) &= ~DMA_CHXCTL_PNAGA;
}else{
DMA_CHCTL(dma_periph,channelx) |= DMA_CHXCTL_PAIF;
}
/* configure memory increasing mode */
- if(DMA_MEMORY_INCREASE_ENABLE == init_struct.memory_inc){
+ if(DMA_MEMORY_INCREASE_ENABLE == init_struct->memory_inc){
DMA_CHCTL(dma_periph,channelx) |= DMA_CHXCTL_MNAGA;
}else{
DMA_CHCTL(dma_periph,channelx) &= ~DMA_CHXCTL_MNAGA;
}
/* configure DMA circular mode */
- if(DMA_CIRCULAR_MODE_ENABLE == init_struct.circular_mode){
+ if(DMA_CIRCULAR_MODE_ENABLE == init_struct->circular_mode){
DMA_CHCTL(dma_periph,channelx) |= DMA_CHXCTL_CMEN;
}else{
DMA_CHCTL(dma_periph,channelx) &= ~DMA_CHXCTL_CMEN;
@@ -115,60 +185,60 @@ void dma_single_data_mode_init(uint32_t dma_periph,dma_channel_enum channelx,dma
\param[in] dma_multi_data_parameter_struct: the data needed to initialize DMA multi data mode
periph_addr: peripheral base address
periph_width: DMA_PERIPH_WIDTH_8BIT,DMA_PERIPH_WIDTH_16BIT,DMA_PERIPH_WIDTH_32BIT
- periph_inc: DMA_PERIPH_INCREASE_ENABLE,DMA_PERIPH_INCREASE_DISABLE,DMA_PERIPH_INCREASE_FIX
+ periph_inc: DMA_PERIPH_INCREASE_ENABLE,DMA_PERIPH_INCREASE_DISABLE,DMA_PERIPH_INCREASE_FIX
memory0_addr: memory0 base address
memory_width: DMA_MEMORY_WIDTH_8BIT,DMA_MEMORY_WIDTH_16BIT,DMA_MEMORY_WIDTH_32BIT
memory_inc: DMA_MEMORY_INCREASE_ENABLE,DMA_MEMORY_INCREASE_DISABLE
- direction: DMA_PERIPH_TO_MEMORY,DMA_MEMORY_TO_PERIPH,DMA_MEMORY_TO_MEMORY
- number: the number of remaining data to be transferred by the DMA
- priority: DMA_PRIORITY_LOW,DMA_PRIORITY_MEDIUM,DMA_PRIORITY_HIGH,DMA_PRIORITY_ULTRA_HIGH
- circular_mode: DMA_CIRCULAR_MODE_ENABLE,DMA_CIRCULAR_MODE_DISABLE
memory_burst_width: DMA_MEMORY_BURST_SINGLE,DMA_MEMORY_BURST_4_BEAT,DMA_MEMORY_BURST_8_BEAT,DMA_MEMORY_BURST_16_BEAT
periph_burst_width: DMA_PERIPH_BURST_SINGLE,DMA_PERIPH_BURST_4_BEAT,DMA_PERIPH_BURST_8_BEAT,DMA_PERIPH_BURST_16_BEAT
critical_value: DMA_FIFO_1_WORD,DMA_FIFO_2_WORD,DMA_FIFO_3_WORD,DMA_FIFO_4_WORD
+ circular_mode: DMA_CIRCULAR_MODE_ENABLE,DMA_CIRCULAR_MODE_DISABLE
+ direction: DMA_PERIPH_TO_MEMORY,DMA_MEMORY_TO_PERIPH,DMA_MEMORY_TO_MEMORY
+ number: the number of remaining data to be transferred by the DMA
+ priority: DMA_PRIORITY_LOW,DMA_PRIORITY_MEDIUM,DMA_PRIORITY_HIGH,DMA_PRIORITY_ULTRA_HIGH
\param[out] none
\retval none
*/
-void dma_multi_data_mode_init(uint32_t dma_periph,dma_channel_enum channelx,dma_multi_data_parameter_struct init_struct)
+void dma_multi_data_mode_init(uint32_t dma_periph, dma_channel_enum channelx, dma_multi_data_parameter_struct* init_struct)
{
uint32_t ctl;
-
+
/* select multi data mode and configure FIFO critical value */
- DMA_CHFCTL(dma_periph,channelx) |= (DMA_CHXFCTL_MDMEN | init_struct.critical_value);
-
+ DMA_CHFCTL(dma_periph,channelx) |= (DMA_CHXFCTL_MDMEN | init_struct->critical_value);
+
/* configure peripheral base address */
- DMA_CHPADDR(dma_periph,channelx) = init_struct.periph_addr;
-
+ DMA_CHPADDR(dma_periph,channelx) = init_struct->periph_addr;
+
/* configure memory base address */
- DMA_CHM0ADDR(dma_periph,channelx) = init_struct.memory0_addr;
-
+ DMA_CHM0ADDR(dma_periph,channelx) = init_struct->memory0_addr;
+
/* configure the number of remaining data to be transferred */
- DMA_CHCNT(dma_periph,channelx) = init_struct.number;
-
+ DMA_CHCNT(dma_periph,channelx) = init_struct->number;
+
/* configure peripheral and memory transfer width,channel priotity,transfer mode,peripheral and memory burst transfer width */
ctl = DMA_CHCTL(dma_periph,channelx);
ctl &= ~(DMA_CHXCTL_PWIDTH | DMA_CHXCTL_MWIDTH | DMA_CHXCTL_PRIO | DMA_CHXCTL_TM | DMA_CHXCTL_PBURST | DMA_CHXCTL_MBURST);
- ctl |= (init_struct.periph_width | (init_struct.memory_width ) | init_struct.priority | init_struct.direction | init_struct.memory_burst_width | init_struct.periph_burst_width);
+ ctl |= (init_struct->periph_width | (init_struct->memory_width ) | init_struct->priority | init_struct->direction | init_struct->memory_burst_width | init_struct->periph_burst_width);
DMA_CHCTL(dma_periph,channelx) = ctl;
/* configure peripheral increasing mode */
- if(DMA_PERIPH_INCREASE_ENABLE == init_struct.periph_inc){
+ if(DMA_PERIPH_INCREASE_ENABLE == init_struct->periph_inc){
DMA_CHCTL(dma_periph,channelx) |= DMA_CHXCTL_PNAGA;
- }else if(DMA_PERIPH_INCREASE_DISABLE == init_struct.periph_inc){
+ }else if(DMA_PERIPH_INCREASE_DISABLE == init_struct->periph_inc){
DMA_CHCTL(dma_periph,channelx) &= ~DMA_CHXCTL_PNAGA;
}else{
DMA_CHCTL(dma_periph,channelx) |= DMA_CHXCTL_PAIF;
}
/* configure memory increasing mode */
- if(DMA_MEMORY_INCREASE_ENABLE == init_struct.memory_inc){
+ if(DMA_MEMORY_INCREASE_ENABLE == init_struct->memory_inc){
DMA_CHCTL(dma_periph,channelx) |= DMA_CHXCTL_MNAGA;
}else{
DMA_CHCTL(dma_periph,channelx) &= ~DMA_CHXCTL_MNAGA;
}
/* configure DMA circular mode */
- if(DMA_CIRCULAR_MODE_ENABLE == init_struct.circular_mode){
+ if(DMA_CIRCULAR_MODE_ENABLE == init_struct->circular_mode){
DMA_CHCTL(dma_periph,channelx) |= DMA_CHXCTL_CMEN;
}else{
DMA_CHCTL(dma_periph,channelx) &= ~DMA_CHXCTL_CMEN;
@@ -176,216 +246,6 @@ void dma_multi_data_mode_init(uint32_t dma_periph,dma_channel_enum channelx,dma_
}
/*!
- \brief get DMA flag is set or not
- \param[in] dma_periph: DMAx(x=0,1)
- \arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel to get flag
- \arg DMA_CHx(x=0..7)
- \param[in] flag: specify get which flag
- \arg DMA_INTF_FEEIF: FIFO error and exception flag
- \arg DMA_INTF_SDEIF: single data mode exception flag
- \arg DMA_INTF_TAEIF: transfer access error flag
- \arg DMA_INTF_HTFIF: half transfer finish flag
- \arg DMA_INTF_FTFIF: full transger finish flag
- \param[out] none
- \retval FlagStatus: SET or RESET
-*/
-FlagStatus dma_flag_get(uint32_t dma_periph,dma_channel_enum channelx,uint32_t flag)
-{
- if(channelx < DMA_CH4){
- if(DMA_INTF0(dma_periph) & DMA_FLAG_ADD(flag,channelx)){
- return SET;
- }else{
- return RESET;
- }
- }else{
- channelx -= (dma_channel_enum)4;
- if(DMA_INTF1(dma_periph) & DMA_FLAG_ADD(flag,channelx)){
- return SET;
- }else{
- return RESET;
- }
- }
-}
-
-/*!
- \brief clear DMA a channel flag
- \param[in] dma_periph: DMAx(x=0,1)
- \arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel to get flag
- \arg DMA_CHx(x=0..7)
- \param[in] flag: specify get which flag
- \arg DMA_INTF_FEEIF: FIFO error and exception flag
- \arg DMA_INTF_SDEIF: single data mode exception flag
- \arg DMA_INTF_TAEIF: transfer access error flag
- \arg DMA_INTF_HTFIF: half transfer finish flag
- \arg DMA_INTF_FTFIF: full transger finish flag
- \param[out] none
- \retval none
-*/
-void dma_flag_clear(uint32_t dma_periph,dma_channel_enum channelx,uint32_t flag)
-{
- if(channelx < DMA_CH4){
- DMA_INTC0(dma_periph) |= DMA_FLAG_ADD(flag,channelx);
- }else{
- channelx -= (dma_channel_enum)4;
- DMA_INTC1(dma_periph) |= DMA_FLAG_ADD(flag,channelx);
- }
-}
-
-/*!
- \brief get DMA interrupt flag is set or not
- \param[in] dma_periph: DMAx(x=0,1)
- \arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel to get interrupt flag
- \arg DMA_CHx(x=0..7)
- \param[in] interrupt: specify get which flag
- \arg DMA_INTF_FEEIF: FIFO error and exception flag
- \arg DMA_INTF_SDEIF: single data mode exception flag
- \arg DMA_INTF_TAEIF: transfer access error flag
- \arg DMA_INTF_HTFIF: half transfer finish flag
- \arg DMA_INTF_FTFIF: full transger finish flag
- \param[out] none
- \retval FlagStatus: SET or RESET
-*/
-FlagStatus dma_interrupt_flag_get(uint32_t dma_periph,dma_channel_enum channelx,uint32_t interrupt)
-{
- uint32_t interrupt_enable = 0U,interrupt_flag = 0U;
- dma_channel_enum channel_flag_offset = channelx;
- if(channelx < DMA_CH4){
- switch(interrupt){
- case DMA_INTF_FEEIF:
- interrupt_flag = DMA_INTF0(dma_periph) & DMA_FLAG_ADD(interrupt,channelx);
- interrupt_enable = DMA_CHFCTL(dma_periph,channelx) & DMA_CHXFCTL_FEEIE;
- break;
- case DMA_INTF_SDEIF:
- interrupt_flag = DMA_INTF0(dma_periph) & DMA_FLAG_ADD(interrupt,channelx);
- interrupt_enable = DMA_CHCTL(dma_periph,channelx) & DMA_CHXCTL_SDEIE;
- break;
- case DMA_INTF_TAEIF:
- interrupt_flag = DMA_INTF0(dma_periph) & DMA_FLAG_ADD(interrupt,channelx);
- interrupt_enable = DMA_CHCTL(dma_periph,channelx) & DMA_CHXCTL_TAEIE;
- break;
- case DMA_INTF_HTFIF:
- interrupt_flag = DMA_INTF0(dma_periph) & DMA_FLAG_ADD(interrupt,channelx);
- interrupt_enable = DMA_CHCTL(dma_periph,channelx) & DMA_CHXCTL_HTFIE;
- break;
- case DMA_INTF_FTFIF:
- interrupt_flag = (DMA_INTF0(dma_periph) & DMA_FLAG_ADD(interrupt,channelx));
- interrupt_enable = (DMA_CHCTL(dma_periph,channelx) & DMA_CHXCTL_FTFIE);
- break;
- default:
- break;
- }
- }else{
- channel_flag_offset -= (dma_channel_enum)4;
- switch(interrupt){
- case DMA_INTF_FEEIF:
- interrupt_flag = DMA_INTF1(dma_periph) & DMA_FLAG_ADD(interrupt,channel_flag_offset);
- interrupt_enable = DMA_CHFCTL(dma_periph,channelx) & DMA_CHXFCTL_FEEIE;
- break;
- case DMA_INTF_SDEIF:
- interrupt_flag = DMA_INTF1(dma_periph) & DMA_FLAG_ADD(interrupt,channel_flag_offset);
- interrupt_enable = DMA_CHCTL(dma_periph,channelx) & DMA_CHXCTL_SDEIE;
- break;
- case DMA_INTF_TAEIF:
- interrupt_flag = DMA_INTF1(dma_periph) & DMA_FLAG_ADD(interrupt,channel_flag_offset);
- interrupt_enable = DMA_CHCTL(dma_periph,channelx) & DMA_CHXCTL_TAEIE;
- break;
- case DMA_INTF_HTFIF:
- interrupt_flag = DMA_INTF1(dma_periph) & DMA_FLAG_ADD(interrupt,channel_flag_offset);
- interrupt_enable = DMA_CHCTL(dma_periph,channelx) & DMA_CHXCTL_HTFIE;
- break;
- case DMA_INTF_FTFIF:
- interrupt_flag = DMA_INTF1(dma_periph) & DMA_FLAG_ADD(interrupt,channel_flag_offset);
- interrupt_enable = DMA_CHCTL(dma_periph,channelx) & DMA_CHXCTL_FTFIE;
- break;
- default:
- break;
- }
- }
-
- if(interrupt_flag && interrupt_enable){
- return SET;
- }else{
- return RESET;
- }
-}
-
-/*!
- \brief clear DMA a channel interrupt flag
- \param[in] dma_periph: DMAx(x=0,1)
- \arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel to clear interrupt flag
- \arg DMA_CHx(x=0..7)
- \param[in] interrupt: specify get which flag
- \arg DMA_INTC_FEEIFC: clear FIFO error and exception flag
- \arg DMA_INTC_SDEIFC: clear single data mode exception flag
- \arg DMA_INTC_TAEIFC: clear transfer access error flag
- \arg DMA_INTC_HTFIFC: clear half transfer finish flag
- \arg DMA_INTC_FTFIFC: clear full transger finish flag
- \param[out] none
- \retval none
-*/
-void dma_interrupt_flag_clear(uint32_t dma_periph,dma_channel_enum channelx,uint32_t interrupt)
-{
- if(channelx < DMA_CH4){
- DMA_INTC0(dma_periph) |= DMA_FLAG_ADD(interrupt,channelx);
- }else{
- channelx -= (dma_channel_enum)4;
- DMA_INTC1(dma_periph) |= DMA_FLAG_ADD(interrupt,channelx);
- }
-}
-
-/*!
- \brief enable DMA interrupt
- \param[in] dma_periph: DMAx(x=0,1)
- \arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
- \arg DMA_CHx(x=0..7)
- \param[in] source: specify which interrupt to enbale
- \arg DMA_CHXCTL_SDEIE: single data mode exception interrupt enable
- \arg DMA_CHXCTL_TAEIE: tranfer access error interrupt enable
- \arg DMA_CHXCTL_HTFIE: half transfer finish interrupt enable
- \arg DMA_CHXCTL_FTFIE: full transfer finish interrupt enable
- \arg DMA_CHXFCTL_FEEIE: FIFO exception interrupt enable
- \param[out] none
- \retval none
-*/
-void dma_interrupt_enable(uint32_t dma_periph,dma_channel_enum channelx,uint32_t source)
-{
- if(DMA_CHXFCTL_FEEIE != source){
- DMA_CHCTL(dma_periph,channelx) |= source;
- }else{
- DMA_CHFCTL(dma_periph,channelx) |= source;
- }
-}
-
-/*!
- \brief disable DMA interrupt
- \param[in] dma_periph: DMAx(x=0,1)
- \arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
- \arg DMA_CHx(x=0..7)
- \param[in] source: specify which interrupt to disbale
- \arg DMA_CHXCTL_SDEIE: single data mode exception interrupt enable
- \arg DMA_CHXCTL_TAEIE: tranfer access error interrupt enable
- \arg DMA_CHXCTL_HTFIE: half transfer finish interrupt enable
- \arg DMA_CHXCTL_FTFIE: full transfer finish interrupt enable
- \arg DMA_CHXFCTL_FEEIE: FIFO exception interrupt enable
- \param[out] none
- \retval none
-*/
-void dma_interrupt_disable(uint32_t dma_periph,dma_channel_enum channelx,uint32_t source)
-{
- if(DMA_CHXFCTL_FEEIE != source){
- DMA_CHCTL(dma_periph,channelx) &= ~source;
- }else{
- DMA_CHFCTL(dma_periph,channelx) &= ~source;
- }
-}
-
-/*!
\brief set DMA peripheral base address
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
@@ -395,7 +255,7 @@ void dma_interrupt_disable(uint32_t dma_periph,dma_channel_enum channelx,uint32_
\param[out] none
\retval none
*/
-void dma_periph_address_config(uint32_t dma_periph,dma_channel_enum channelx,uint32_t address)
+void dma_periph_address_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t address)
{
DMA_CHPADDR(dma_periph,channelx) = address;
}
@@ -404,14 +264,14 @@ void dma_periph_address_config(uint32_t dma_periph,dma_channel_enum channelx,uin
\brief set DMA Memory0 base address
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel to set Memory base address
+ \param[in] channelx: specify which DMA channel to set Memory base address
\arg DMA_CHx(x=0..7)
\param[in] memory_flag: DMA_MEMORY_x(x=0,1)
\param[in] address: Memory base address
\param[out] none
\retval none
*/
-void dma_memory_address_config(uint32_t dma_periph,dma_channel_enum channelx,uint8_t memory_flag,uint32_t address)
+void dma_memory_address_config(uint32_t dma_periph, dma_channel_enum channelx, uint8_t memory_flag, uint32_t address)
{
if(memory_flag){
DMA_CHM1ADDR(dma_periph,channelx) = address;
@@ -430,7 +290,7 @@ void dma_memory_address_config(uint32_t dma_periph,dma_channel_enum channelx,uin
\param[out] none
\retval none
*/
-void dma_transfer_number_config(uint32_t dma_periph,dma_channel_enum channelx,uint32_t number)
+void dma_transfer_number_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t number)
{
DMA_CHCNT(dma_periph,channelx) = number;
}
@@ -439,12 +299,12 @@ void dma_transfer_number_config(uint32_t dma_periph,dma_channel_enum channelx,ui
\brief get the number of remaining data to be transferred by the DMA
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel to set number
+ \param[in] channelx: specify which DMA channel to set number
\arg DMA_CHx(x=0..7)
\param[out] none
- \retval uint32_t: the number of remaining data to be transferred by the DMA
+ \retval uint32_t: the number of remaining data to be transferred by the DMA
*/
-uint32_t dma_transfer_number_get(uint32_t dma_periph,dma_channel_enum channelx)
+uint32_t dma_transfer_number_get(uint32_t dma_periph, dma_channel_enum channelx)
{
return (uint32_t)DMA_CHCNT(dma_periph,channelx);
}
@@ -456,14 +316,15 @@ uint32_t dma_transfer_number_get(uint32_t dma_periph,dma_channel_enum channelx)
\param[in] channelx: specify which DMA channel
\arg DMA_CHx(x=0..7)
\param[in] priority: priority Level of this channel
+ only one parameter can be selected which is shown as below:
\arg DMA_PRIORITY_LOW: low priority
\arg DMA_PRIORITY_MEDIUM: medium priority
\arg DMA_PRIORITY_HIGH: high priority
\arg DMA_PRIORITY_ULTRA_HIGH: ultra high priority
\param[out] none
- \retval none
+ \retval none
*/
-void dma_priority_config(uint32_t dma_periph,dma_channel_enum channelx,uint32_t priority)
+void dma_priority_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t priority)
{
uint32_t ctl;
/* acquire DMA_CHxCTL register */
@@ -488,7 +349,7 @@ void dma_priority_config(uint32_t dma_periph,dma_channel_enum channelx,uint32_t
\param[out] none
\retval none
*/
-void dma_memory_burst_beats_config (uint32_t dma_periph,dma_channel_enum channelx,uint32_t mbeat)
+void dma_memory_burst_beats_config (uint32_t dma_periph, dma_channel_enum channelx, uint32_t mbeat)
{
uint32_t ctl;
/* acquire DMA_CHxCTL register */
@@ -506,6 +367,7 @@ void dma_memory_burst_beats_config (uint32_t dma_periph,dma_channel_enum channel
\param[in] channelx: specify which DMA channel
\arg DMA_CHx(x=0..7)
\param[in] pbeat: transfer burst beats
+ only one parameter can be selected which is shown as below:
\arg DMA_PERIPH_BURST_SINGLE: peripheral transfer single burst
\arg DMA_PERIPH_BURST_4_BEAT: peripheral transfer 4-beat burst
\arg DMA_PERIPH_BURST_8_BEAT: peripheral transfer 8-beat burst
@@ -513,7 +375,7 @@ void dma_memory_burst_beats_config (uint32_t dma_periph,dma_channel_enum channel
\param[out] none
\retval none
*/
-void dma_periph_burst_beats_config (uint32_t dma_periph,dma_channel_enum channelx,uint32_t pbeat)
+void dma_periph_burst_beats_config (uint32_t dma_periph, dma_channel_enum channelx, uint32_t pbeat)
{
uint32_t ctl;
/* acquire DMA_CHxCTL register */
@@ -531,13 +393,14 @@ void dma_periph_burst_beats_config (uint32_t dma_periph,dma_channel_enum channel
\param[in] channelx: specify which DMA channel
\arg DMA_CHx(x=0..7)
\param[in] msize: transfer data size of memory
+ only one parameter can be selected which is shown as below:
\arg DMA_MEMORY_WIDTH_8BIT: transfer data size of memory is 8-bit
\arg DMA_MEMORY_WIDTH_16BIT: transfer data size of memory is 16-bit
\arg DMA_MEMORY_WIDTH_32BIT: transfer data size of memory is 32-bit
\param[out] none
\retval none
*/
-void dma_memory_width_config(uint32_t dma_periph,dma_channel_enum channelx,uint32_t msize)
+void dma_memory_width_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t msize)
{
uint32_t ctl;
/* acquire DMA_CHxCTL register */
@@ -549,19 +412,20 @@ void dma_memory_width_config(uint32_t dma_periph,dma_channel_enum channelx,uint3
}
/*!
- \brief configure transfer data size of peripheral
+ \brief configure transfer data size of peripheral
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
\arg DMA_CHx(x=0..7)
\param[in] msize: transfer data size of peripheral
+ only one parameter can be selected which is shown as below:
\arg DMA_PERIPHERAL_WIDTH_8BIT: transfer data size of peripheral is 8-bit
\arg DMA_PERIPHERAL_WIDTH_16BIT: transfer data size of peripheral is 16-bit
\arg DMA_PERIPHERAL_WIDTH_32BIT: transfer data size of peripheral is 32-bit
\param[out] none
\retval none
*/
-void dma_periph_width_config (uint32_t dma_periph,dma_channel_enum channelx,uint32_t psize)
+void dma_periph_width_config (uint32_t dma_periph, dma_channel_enum channelx, uint32_t psize)
{
uint32_t ctl;
/* acquire DMA_CHxCTL register */
@@ -576,15 +440,16 @@ void dma_periph_width_config (uint32_t dma_periph,dma_channel_enum channelx,uint
\brief configure memory address generation generation_algorithm
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
\arg DMA_CHx(x=0..7)
\param[in] generation_algorithm: the address generation algorithm
+ only one parameter can be selected which is shown as below:
\arg DMA_MEMORY_INCREASE_ENABLE: next address of memory is increasing address mode
\arg DMA_MEMORY_INCREASE_DISABLE: next address of memory is fixed address mode
\param[out] none
\retval none
*/
-void dma_memory_address_generation_config(uint32_t dma_periph,dma_channel_enum channelx,uint8_t generation_algorithm)
+void dma_memory_address_generation_config(uint32_t dma_periph, dma_channel_enum channelx, uint8_t generation_algorithm)
{
if(DMA_MEMORY_INCREASE_ENABLE == generation_algorithm){
DMA_CHCTL(dma_periph,channelx) |= DMA_CHXCTL_MNAGA;
@@ -594,19 +459,20 @@ void dma_memory_address_generation_config(uint32_t dma_periph,dma_channel_enum c
}
/*!
- \brief configure peripheral address generation generation_algorithm
+ \brief configure peripheral address generation_algorithm
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
\arg DMA_CHx(x=0..7)
\param[in] generation_algorithm: the address generation algorithm
+ only one parameter can be selected which is shown as below:
\arg DMA_PERIPH_INCREASE_ENABLE: next address of peripheral is increasing address mode
\arg DMA_PERIPH_INCREASE_DISABLE: next address of peripheral is fixed address mode
\arg DMA_PERIPH_INCREASE_FIX: increasing steps of peripheral address is fixed
\param[out] none
\retval none
*/
-void dma_peripheral_address_generation_config(uint32_t dma_periph,dma_channel_enum channelx,uint8_t generation_algorithm)
+void dma_peripheral_address_generation_config(uint32_t dma_periph, dma_channel_enum channelx, uint8_t generation_algorithm)
{
if(DMA_PERIPH_INCREASE_ENABLE == generation_algorithm){
DMA_CHCTL(dma_periph,channelx) |= DMA_CHXCTL_PNAGA;
@@ -622,12 +488,12 @@ void dma_peripheral_address_generation_config(uint32_t dma_periph,dma_channel_en
\brief enable DMA circulation mode
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
\arg DMA_CHx(x=0..7)
\param[out] none
- \retval none
+ \retval none
*/
-void dma_circulation_enable(uint32_t dma_periph,dma_channel_enum channelx)
+void dma_circulation_enable(uint32_t dma_periph, dma_channel_enum channelx)
{
DMA_CHCTL(dma_periph,channelx) |= DMA_CHXCTL_CMEN;
}
@@ -636,30 +502,59 @@ void dma_circulation_enable(uint32_t dma_periph,dma_channel_enum channelx)
\brief disable DMA circulation mode
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
\arg DMA_CHx(x=0..7)
\param[out] none
- \retval none
+ \retval none
*/
-void dma_circulation_disable(uint32_t dma_periph,dma_channel_enum channelx)
+void dma_circulation_disable(uint32_t dma_periph, dma_channel_enum channelx)
{
DMA_CHCTL(dma_periph,channelx) &= ~DMA_CHXCTL_CMEN;
}
/*!
+ \brief enable DMA channel
+ \param[in] dma_periph: DMAx(x=0,1)
+ \arg DMAx(x=0,1)
+ \param[in] channelx: specify which DMA channel
+ \arg DMA_CHx(x=0..7)
+ \param[out] none
+ \retval none
+*/
+void dma_channel_enable(uint32_t dma_periph, dma_channel_enum channelx)
+{
+ DMA_CHCTL(dma_periph,channelx) |= DMA_CHXCTL_CHEN;
+}
+
+/*!
+ \brief disable DMA channel
+ \param[in] dma_periph: DMAx(x=0,1)
+ \arg DMAx(x=0,1)
+ \param[in] channelx: specify which DMA channel
+ \arg DMA_CHx(x=0..7)
+ \param[out] none
+ \retval none
+*/
+void dma_channel_disable(uint32_t dma_periph, dma_channel_enum channelx)
+{
+ DMA_CHCTL(dma_periph,channelx) &= ~DMA_CHXCTL_CHEN;
+}
+
+/*!
\brief configure the direction of data transfer on the channel
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
\arg DMA_CHx(x=0..7)
\param[in] direction: specify the direction of data transfer
+ only one parameter can be selected which is shown as below:
\arg DMA_PERIPH_TO_MEMORY: read from peripheral and write to memory
\arg DMA_MEMORY_TO_PERIPH: read from memory and write to peripheral
\arg DMA_MEMORY_TO_MEMORY: read from memory and write to memory
\param[out] none
\retval none
*/
-void dma_transfer_direction_config(uint32_t dma_periph,dma_channel_enum channelx,uint8_t direction)
+void dma_transfer_direction_config(uint32_t dma_periph, dma_channel_enum channelx, uint8_t direction)
{
uint32_t ctl;
/* acquire DMA_CHxCTL register */
@@ -667,50 +562,63 @@ void dma_transfer_direction_config(uint32_t dma_periph,dma_channel_enum channelx
/* assign regiser */
ctl &= ~DMA_CHXCTL_TM;
ctl |= direction;
-
+
DMA_CHCTL(dma_periph,channelx) = ctl;
}
/*!
- \brief enable DMA channel
+ \brief DMA switch buffer mode config
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
\arg DMA_CHx(x=0..7)
+ \param[in] memory1_addr: memory1 base address
+ \param[in] memory_select: DMA_MEMORY_0 or DMA_MEMORY_1
\param[out] none
- \retval none
+ \retval none
*/
-void dma_channel_enable(uint32_t dma_periph,dma_channel_enum channelx)
+void dma_switch_buffer_mode_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t memory1_addr, uint32_t memory_select)
{
- DMA_CHCTL(dma_periph,channelx) |= DMA_CHXCTL_CHEN;
+ /* configure memory1 base address */
+ DMA_CHM1ADDR(dma_periph,channelx) = memory1_addr;
+
+ if(DMA_MEMORY_0 == memory_select){
+ DMA_CHCTL(dma_periph,channelx) &= ~DMA_CHXCTL_MBS;
+ }else{
+ DMA_CHCTL(dma_periph,channelx) |= DMA_CHXCTL_MBS;
+ }
}
/*!
- \brief disable DMA channel
+ \brief DMA using memory get
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
\arg DMA_CHx(x=0..7)
\param[out] none
- \retval none
+ \retval the using memory
*/
-void dma_channel_disable(uint32_t dma_periph,dma_channel_enum channelx)
+uint32_t dma_using_memory_get(uint32_t dma_periph, dma_channel_enum channelx)
{
- DMA_CHCTL(dma_periph,channelx) &= ~DMA_CHXCTL_CHEN;
+ if((DMA_CHCTL(dma_periph,channelx)) & DMA_CHXCTL_MBS){
+ return DMA_MEMORY_1;
+ }else{
+ return DMA_MEMORY_0;
+ }
}
/*!
\brief DMA channel peripheral select
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
\arg DMA_CHx(x=0..7)
\param[in] sub_periph: specify DMA channel peripheral
\arg DMA_SUBPERIx(x=0..7)
\param[out] none
- \retval none
+ \retval none
*/
-void dma_channel_subperipheral_select(uint32_t dma_periph,dma_channel_enum channelx,dma_subperipheral_enum sub_periph)
+void dma_channel_subperipheral_select(uint32_t dma_periph, dma_channel_enum channelx, dma_subperipheral_enum sub_periph)
{
uint32_t ctl;
/* acquire DMA_CHxCTL register */
@@ -718,30 +626,29 @@ void dma_channel_subperipheral_select(uint32_t dma_periph,dma_channel_enum chann
/* assign regiser */
ctl &= ~DMA_CHXCTL_PERIEN;
ctl |= ((uint32_t)sub_periph << CHXCTL_PERIEN_OFFSET);
-
+
DMA_CHCTL(dma_periph,channelx) = ctl;
}
/*!
- \brief DMA switch buffer mode config
+ \brief DMA flow controller configure
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
\arg DMA_CHx(x=0..7)
- \param[in] memory1_addr: memory1 base address
- \param[in] memory_select: DMA_MEMORY_0 or DMA_MEMORY_1
+ \param[in] controller: specify DMA flow controler
+ only one parameter can be selected which is shown as below:
+ \arg DMA_FLOW_CONTROLLER_DMA: DMA is the flow controller
+ \arg DMA_FLOW_CONTROLLER_PERI: peripheral is the flow controller
\param[out] none
- \retval none
+ \retval none
*/
-void dma_switch_buffer_mode_config(uint32_t dma_periph,dma_channel_enum channelx,uint32_t memory1_addr,uint32_t memory_select)
+void dma_flow_controller_config(uint32_t dma_periph, dma_channel_enum channelx, uint32_t controller)
{
- /* configure memory1 base address */
- DMA_CHM1ADDR(dma_periph,channelx) = memory1_addr;
-
- if(DMA_MEMORY_0 == memory_select){
- DMA_CHCTL(dma_periph,channelx) &= ~DMA_CHXCTL_MBS;
+ if(DMA_FLOW_CONTROLLER_DMA == controller){
+ DMA_CHCTL(dma_periph,channelx) &= ~DMA_CHXCTL_TFCS;
}else{
- DMA_CHCTL(dma_periph,channelx) |= DMA_CHXCTL_MBS;
+ DMA_CHCTL(dma_periph,channelx) |= DMA_CHXCTL_TFCS;
}
}
@@ -749,13 +656,13 @@ void dma_switch_buffer_mode_config(uint32_t dma_periph,dma_channel_enum channelx
\brief DMA switch buffer mode enable
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
\arg DMA_CHx(x=0..7)
\param[in] newvalue: ENABLE or DISABLE
\param[out] none
- \retval none
+ \retval none
*/
-void dma_switch_buffer_mode_enable(uint32_t dma_periph,dma_channel_enum channelx,ControlStatus newvalue)
+void dma_switch_buffer_mode_enable(uint32_t dma_periph, dma_channel_enum channelx, ControlStatus newvalue)
{
if(ENABLE == newvalue){
/* switch buffer mode enable */
@@ -767,54 +674,232 @@ void dma_switch_buffer_mode_enable(uint32_t dma_periph,dma_channel_enum channelx
}
/*!
- \brief DMA using memory get
+ \brief DMA FIFO status get
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel
\arg DMA_CHx(x=0..7)
\param[out] none
- \retval the using memory
+ \retval the using memory
*/
-uint32_t dma_using_memory_get(uint32_t dma_periph,dma_channel_enum channelx)
+uint32_t dma_fifo_status_get(uint32_t dma_periph, dma_channel_enum channelx)
{
- if((DMA_CHCTL(dma_periph,channelx)) & DMA_CHXCTL_MBS){
- return DMA_MEMORY_1;
+ return (DMA_CHFCTL(dma_periph,channelx) & DMA_CHXFCTL_FCNT);
+}
+
+/*!
+ \brief get DMA flag is set or not
+ \param[in] dma_periph: DMAx(x=0,1)
+ \arg DMAx(x=0,1)
+ \param[in] channelx: specify which DMA channel to get flag
+ \arg DMA_CHx(x=0..7)
+ \param[in] flag: specify get which flag
+ only one parameter can be selected which is shown as below:
+ \arg DMA_FLAG_FEE: FIFO error and exception flag
+ \arg DMA_FLAG_SDE: single data mode exception flag
+ \arg DMA_FLAG_TAE: transfer access error flag
+ \arg DMA_FLAG_HTF: half transfer finish flag
+ \arg DMA_FLAG_FTF: full transger finish flag
+ \param[out] none
+ \retval FlagStatus: SET or RESET
+*/
+FlagStatus dma_flag_get(uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag)
+{
+ if(channelx < DMA_CH4){
+ if(DMA_INTF0(dma_periph) & DMA_FLAG_ADD(flag,channelx)){
+ return SET;
+ }else{
+ return RESET;
+ }
}else{
- return DMA_MEMORY_0;
+ channelx -= (dma_channel_enum)4;
+ if(DMA_INTF1(dma_periph) & DMA_FLAG_ADD(flag,channelx)){
+ return SET;
+ }else{
+ return RESET;
+ }
}
}
/*!
- \brief DMA flow controller configure
+ \brief clear DMA a channel flag
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel to get flag
\arg DMA_CHx(x=0..7)
- \param[in] controller: specify DMA flow controler
- \arg DMA_FLOW_CONTROLLER_DMA: DMA is the flow controller
- \arg DMA_FLOW_CONTROLLER_PERI: peripheral is the flow controller
+ \param[in] flag: specify get which flag
+ only one parameter can be selected which is shown as below:
+ \arg DMA_FLAG_FEE: FIFO error and exception flag
+ \arg DMA_FLAG_SDE: single data mode exception flag
+ \arg DMA_FLAG_TAE: transfer access error flag
+ \arg DMA_FLAG_HTF: half transfer finish flag
+ \arg DMA_FLAG_FTF: full transger finish flag
\param[out] none
\retval none
*/
-void dma_flow_controller_config(uint32_t dma_periph,dma_channel_enum channelx,uint32_t controller)
+void dma_flag_clear(uint32_t dma_periph, dma_channel_enum channelx, uint32_t flag)
{
- if(DMA_FLOW_CONTROLLER_DMA == controller){
- DMA_CHCTL(dma_periph,channelx) &= ~DMA_CHXCTL_TFCS;
+ if(channelx < DMA_CH4){
+ DMA_INTC0(dma_periph) |= DMA_FLAG_ADD(flag,channelx);
}else{
- DMA_CHCTL(dma_periph,channelx) |= DMA_CHXCTL_TFCS;
+ channelx -= (dma_channel_enum)4;
+ DMA_INTC1(dma_periph) |= DMA_FLAG_ADD(flag,channelx);
}
}
/*!
- \brief DMA FIFO status get
+ \brief get DMA interrupt flag is set or not
\param[in] dma_periph: DMAx(x=0,1)
\arg DMAx(x=0,1)
- \param[in] channelx: specify which DMA channel
+ \param[in] channelx: specify which DMA channel to get interrupt flag
\arg DMA_CHx(x=0..7)
+ \param[in] interrupt: specify get which flag
+ only one parameter can be selected which is shown as below:
+ \arg DMA_INT_FLAG_FEE: FIFO error and exception flag
+ \arg DMA_INT_FLAG_SDE: single data mode exception flag
+ \arg DMA_INT_FLAG_TAE: transfer access error flag
+ \arg DMA_INT_FLAG_HTF: half transfer finish flag
+ \arg DMA_INT_FLAG_FTF: full transger finish flag
\param[out] none
- \retval the using memory
+ \retval FlagStatus: SET or RESET
*/
-uint32_t dma_fifo_status_get(uint32_t dma_periph,dma_channel_enum channelx)
+FlagStatus dma_interrupt_flag_get(uint32_t dma_periph, dma_channel_enum channelx, uint32_t interrupt)
{
- return (DMA_CHFCTL(dma_periph,channelx) & DMA_CHXFCTL_FCNT);
+ uint32_t interrupt_enable = 0U,interrupt_flag = 0U;
+ dma_channel_enum channel_flag_offset = channelx;
+ if(channelx < DMA_CH4){
+ switch(interrupt){
+ case DMA_INTF_FEEIF:
+ interrupt_flag = DMA_INTF0(dma_periph) & DMA_FLAG_ADD(interrupt,channelx);
+ interrupt_enable = DMA_CHFCTL(dma_periph,channelx) & DMA_CHXFCTL_FEEIE;
+ break;
+ case DMA_INTF_SDEIF:
+ interrupt_flag = DMA_INTF0(dma_periph) & DMA_FLAG_ADD(interrupt,channelx);
+ interrupt_enable = DMA_CHCTL(dma_periph,channelx) & DMA_CHXCTL_SDEIE;
+ break;
+ case DMA_INTF_TAEIF:
+ interrupt_flag = DMA_INTF0(dma_periph) & DMA_FLAG_ADD(interrupt,channelx);
+ interrupt_enable = DMA_CHCTL(dma_periph,channelx) & DMA_CHXCTL_TAEIE;
+ break;
+ case DMA_INTF_HTFIF:
+ interrupt_flag = DMA_INTF0(dma_periph) & DMA_FLAG_ADD(interrupt,channelx);
+ interrupt_enable = DMA_CHCTL(dma_periph,channelx) & DMA_CHXCTL_HTFIE;
+ break;
+ case DMA_INTF_FTFIF:
+ interrupt_flag = (DMA_INTF0(dma_periph) & DMA_FLAG_ADD(interrupt,channelx));
+ interrupt_enable = (DMA_CHCTL(dma_periph,channelx) & DMA_CHXCTL_FTFIE);
+ break;
+ default:
+ break;
+ }
+ }else{
+ channel_flag_offset -= (dma_channel_enum)4;
+ switch(interrupt){
+ case DMA_INTF_FEEIF:
+ interrupt_flag = DMA_INTF1(dma_periph) & DMA_FLAG_ADD(interrupt,channel_flag_offset);
+ interrupt_enable = DMA_CHFCTL(dma_periph,channelx) & DMA_CHXFCTL_FEEIE;
+ break;
+ case DMA_INTF_SDEIF:
+ interrupt_flag = DMA_INTF1(dma_periph) & DMA_FLAG_ADD(interrupt,channel_flag_offset);
+ interrupt_enable = DMA_CHCTL(dma_periph,channelx) & DMA_CHXCTL_SDEIE;
+ break;
+ case DMA_INTF_TAEIF:
+ interrupt_flag = DMA_INTF1(dma_periph) & DMA_FLAG_ADD(interrupt,channel_flag_offset);
+ interrupt_enable = DMA_CHCTL(dma_periph,channelx) & DMA_CHXCTL_TAEIE;
+ break;
+ case DMA_INTF_HTFIF:
+ interrupt_flag = DMA_INTF1(dma_periph) & DMA_FLAG_ADD(interrupt,channel_flag_offset);
+ interrupt_enable = DMA_CHCTL(dma_periph,channelx) & DMA_CHXCTL_HTFIE;
+ break;
+ case DMA_INTF_FTFIF:
+ interrupt_flag = DMA_INTF1(dma_periph) & DMA_FLAG_ADD(interrupt,channel_flag_offset);
+ interrupt_enable = DMA_CHCTL(dma_periph,channelx) & DMA_CHXCTL_FTFIE;
+ break;
+ default:
+ break;
+ }
+ }
+
+ if(interrupt_flag && interrupt_enable){
+ return SET;
+ }else{
+ return RESET;
+ }
}
+
+/*!
+ \brief clear DMA a channel interrupt flag
+ \param[in] dma_periph: DMAx(x=0,1)
+ \arg DMAx(x=0,1)
+ \param[in] channelx: specify which DMA channel to clear interrupt flag
+ \arg DMA_CHx(x=0..7)
+ \param[in] interrupt: specify get which flag
+ only one parameter can be selected which is shown as below:
+ \arg DMA_INT_FLAG_FEE: FIFO error and exception flag
+ \arg DMA_INT_FLAG_SDE: single data mode exception flag
+ \arg DMA_INT_FLAG_TAE: transfer access error flag
+ \arg DMA_INT_FLAG_HTF: half transfer finish flag
+ \arg DMA_INT_FLAG_FTF: full transger finish flag
+ \param[out] none
+ \retval none
+*/
+void dma_interrupt_flag_clear(uint32_t dma_periph, dma_channel_enum channelx, uint32_t interrupt)
+{
+ if(channelx < DMA_CH4){
+ DMA_INTC0(dma_periph) |= DMA_FLAG_ADD(interrupt,channelx);
+ }else{
+ channelx -= (dma_channel_enum)4;
+ DMA_INTC1(dma_periph) |= DMA_FLAG_ADD(interrupt,channelx);
+ }
+}
+
+/*!
+ \brief enable DMA interrupt
+ \param[in] dma_periph: DMAx(x=0,1)
+ \arg DMAx(x=0,1)
+ \param[in] channelx: specify which DMA channel
+ \arg DMA_CHx(x=0..7)
+ \param[in] source: specify which interrupt to enbale
+ one or more parameters can be selected which are shown as below:
+ \arg DMA_CHXCTL_SDEIE: single data mode exception interrupt enable
+ \arg DMA_CHXCTL_TAEIE: tranfer access error interrupt enable
+ \arg DMA_CHXCTL_HTFIE: half transfer finish interrupt enable
+ \arg DMA_CHXCTL_FTFIE: full transfer finish interrupt enable
+ \arg DMA_CHXFCTL_FEEIE: FIFO exception interrupt enable
+ \param[out] none
+ \retval none
+*/
+void dma_interrupt_enable(uint32_t dma_periph, dma_channel_enum channelx, uint32_t source)
+{
+ if(DMA_CHXFCTL_FEEIE != source){
+ DMA_CHCTL(dma_periph,channelx) |= source;
+ }else{
+ DMA_CHFCTL(dma_periph,channelx) |= source;
+ }
+}
+
+/*!
+ \brief disable DMA interrupt
+ \param[in] dma_periph: DMAx(x=0,1)
+ \arg DMAx(x=0,1)
+ \param[in] channelx: specify which DMA channel
+ \arg DMA_CHx(x=0..7)
+ \param[in] source: specify which interrupt to disbale
+ one or more parameters can be selected which are shown as below:
+ \arg DMA_CHXCTL_SDEIE: single data mode exception interrupt enable
+ \arg DMA_CHXCTL_TAEIE: tranfer access error interrupt enable
+ \arg DMA_CHXCTL_HTFIE: half transfer finish interrupt enable
+ \arg DMA_CHXCTL_FTFIE: full transfer finish interrupt enable
+ \arg DMA_CHXFCTL_FEEIE: FIFO exception interrupt enable
+ \param[out] none
+ \retval none
+*/
+void dma_interrupt_disable(uint32_t dma_periph, dma_channel_enum channelx, uint32_t source)
+{
+ if(DMA_CHXFCTL_FEEIE != source){
+ DMA_CHCTL(dma_periph,channelx) &= ~source;
+ }else{
+ DMA_CHFCTL(dma_periph,channelx) &= ~source;
+ }
+}
+
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_enet.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_enet.c
index 55ed8a9145..456e476fd8 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_enet.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_enet.c
@@ -1,24 +1,49 @@
/*!
- \file gd32f4xx_enet.c
- \brief ENET driver
+ \file gd32f4xx_enet.c
+ \brief ENET driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.1, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#include "gd32f4xx_enet.h"
#if defined (__CC_ARM) /*!< ARM compiler */
-__align(4)
+__align(4)
enet_descriptors_struct rxdesc_tab[ENET_RXBUF_NUM]; /*!< ENET RxDMA descriptor */
-__align(4)
+__align(4)
enet_descriptors_struct txdesc_tab[ENET_TXBUF_NUM]; /*!< ENET TxDMA descriptor */
-__align(4)
+__align(4)
uint8_t rx_buff[ENET_RXBUF_NUM][ENET_RXBUF_SIZE]; /*!< ENET receive buffer */
-__align(4)
+__align(4)
uint8_t tx_buff[ENET_TXBUF_NUM][ENET_TXBUF_SIZE]; /*!< ENET transmit buffer */
#elif defined ( __ICCARM__ ) /*!< IAR compiler */
@@ -31,15 +56,11 @@ uint8_t rx_buff[ENET_RXBUF_NUM][ENET_RXBUF_SIZE]; /*!< ENET receive bu
#pragma data_alignment=4
uint8_t tx_buff[ENET_TXBUF_NUM][ENET_TXBUF_SIZE]; /*!< ENET transmit buffer */
-#elif defined ( __GNUC__ )
-__attribute__((aligned(4)))
-enet_descriptors_struct rxdesc_tab[ENET_RXBUF_NUM]; /*!< ENET RxDMA descriptor */
-__attribute__((aligned(4)))
-enet_descriptors_struct txdesc_tab[ENET_TXBUF_NUM]; /*!< ENET TxDMA descriptor */
-__attribute__((aligned(4)))
-uint8_t rx_buff[ENET_RXBUF_NUM][ENET_RXBUF_SIZE]; /*!< ENET receive buffer */
-__attribute__((aligned(4)))
-uint8_t tx_buff[ENET_TXBUF_NUM][ENET_TXBUF_SIZE]; /*!< ENET transmit buffer */
+#elif defined (__GNUC__) /* GNU Compiler */
+enet_descriptors_struct rxdesc_tab[ENET_RXBUF_NUM] __attribute__ ((aligned (4))); /*!< ENET RxDMA descriptor */
+enet_descriptors_struct txdesc_tab[ENET_TXBUF_NUM] __attribute__ ((aligned (4))); /*!< ENET TxDMA descriptor */
+uint8_t rx_buff[ENET_RXBUF_NUM][ENET_RXBUF_SIZE] __attribute__ ((aligned (4))); /*!< ENET receive buffer */
+uint8_t tx_buff[ENET_TXBUF_NUM][ENET_TXBUF_SIZE] __attribute__ ((aligned (4))); /*!< ENET transmit buffer */
#endif /* __CC_ARM */
@@ -53,19 +74,31 @@ enet_descriptors_struct *dma_current_ptp_rxdesc = NULL;
/* init structure parameters for ENET initialization */
static enet_initpara_struct enet_initpara ={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
-
+static uint32_t enet_unknow_err = 0U;
/* array of register offset for debug information get */
static const uint16_t enet_reg_tab[] = {
0x0000, 0x0004, 0x0008, 0x000C, 0x0010, 0x0014, 0x0018, 0x001C, 0x0028, 0x002C, 0x0034,
0x0038, 0x003C, 0x0040, 0x0044, 0x0048, 0x004C, 0x0050, 0x0054, 0x0058, 0x005C, 0x1080,
-
-0x0100, 0x0104, 0x0108, 0x010C, 0x0110, 0x014C, 0x0150, 0x0168, 0x0194, 0x0198, 0x01C4,
-
-0x0700, 0x0704,0x0708, 0x070C, 0x0710, 0x0714, 0x0718, 0x071C, 0x0720, 0x0728, 0x072C,
-
+
+0x0100, 0x0104, 0x0108, 0x010C, 0x0110, 0x014C, 0x0150, 0x0168, 0x0194, 0x0198, 0x01C4,
+
+0x0700, 0x0704,0x0708, 0x070C, 0x0710, 0x0714, 0x0718, 0x071C, 0x0720, 0x0728, 0x072C,
+
0x1000, 0x1004, 0x1008, 0x100C, 0x1010, 0x1014, 0x1018, 0x101C, 0x1020, 0x1024, 0x1048,
0x104C, 0x1050, 0x1054};
+/* initialize ENET peripheral with generally concerned parameters, call it by enet_init() */
+static void enet_default_init(void);
+#ifdef USE_DELAY
+/* user can provide more timing precise _ENET_DELAY_ function */
+#define _ENET_DELAY_ delay_ms
+#else
+/* insert a delay time */
+static void enet_delay(uint32_t ncount);
+/* default _ENET_DELAY_ function with less precise timing */
+#define _ENET_DELAY_ enet_delay
+#endif
+
/*!
\brief deinitialize the ENET, and reset structure parameters for ENET initialization
@@ -82,16 +115,16 @@ void enet_deinit(void)
/*!
\brief configure the parameters which are usually less cared for initialization
- note -- this function must be called before enet_init(), otherwise
+ note -- this function must be called before enet_init(), otherwise
configuration will be no effect
- \param[in] option: different function option, which is related to several parameters,
- only one parameter can be selected which is shown as below, refer to enet_option_enum
+ \param[in] option: different function option, which is related to several parameters, refer to enet_option_enum
+ only one parameter can be selected which is shown as below
\arg FORWARD_OPTION: choose to configure the frame forward related parameters
\arg DMABUS_OPTION: choose to configure the DMA bus mode related parameters
\arg DMA_MAXBURST_OPTION: choose to configure the DMA max burst related parameters
\arg DMA_ARBITRATION_OPTION: choose to configure the DMA arbitration related parameters
\arg STORE_OPTION: choose to configure the store forward mode related parameters
- \arg DMA_OPTION: choose to configure the DMA descriptor related parameters
+ \arg DMA_OPTION: choose to configure the DMA descriptor related parameters
\arg VLAN_OPTION: choose to configure vlan related parameters
\arg FLOWCTL_OPTION: choose to configure flow control related parameters
\arg HASHH_OPTION: choose to configure hash high
@@ -100,8 +133,8 @@ void enet_deinit(void)
\arg HALFDUPLEX_OPTION: choose to configure halfduplex mode related parameters
\arg TIMER_OPTION: choose to configure time counter related parameters
\arg INTERFRAMEGAP_OPTION: choose to configure the inter frame gap related parameters
- \param[in] para: the related parameters according to the option
- all the related parameters should be configured which are shown as below
+ \param[in] para: the related parameters according to the option
+ all the related parameters should be configured which are shown as below
FORWARD_OPTION related parameters:
- ENET_AUTO_PADCRC_DROP_ENABLE/ ENET_AUTO_PADCRC_DROP_DISABLE ;
- ENET_TYPEFRAME_CRC_DROP_ENABLE/ ENET_TYPEFRAME_CRC_DROP_DISABLE ;
@@ -110,7 +143,7 @@ void enet_deinit(void)
DMABUS_OPTION related parameters:
- ENET_ADDRESS_ALIGN_ENABLE/ ENET_ADDRESS_ALIGN_DISABLE ;
- ENET_FIXED_BURST_ENABLE/ ENET_FIXED_BURST_DISABLE ;
- - ENET_MIXED_BURST_ENABLE/ ENET_MIXED_BURST_DISABLE ;
+ - ENET_MIXED_BURST_ENABLE/ ENET_MIXED_BURST_DISABLE ;
DMA_MAXBURST_OPTION related parameters:
- ENET_RXDP_1BEAT/ ENET_RXDP_2BEAT/ ENET_RXDP_4BEAT/
ENET_RXDP_8BEAT/ ENET_RXDP_16BEAT/ ENET_RXDP_32BEAT/
@@ -146,7 +179,7 @@ void enet_deinit(void)
FLOWCTL_OPTION related parameters:
- MAC_FCTL_PTM(regval) ;
- ENET_ZERO_QUANTA_PAUSE_ENABLE/ ENET_ZERO_QUANTA_PAUSE_DISABLE ;
- - ENET_PAUSETIME_MINUS4/ ENET_PAUSETIME_MINUS28/
+ - ENET_PAUSETIME_MINUS4/ ENET_PAUSETIME_MINUS28/
ENET_PAUSETIME_MINUS144/ENET_PAUSETIME_MINUS256 ;
- ENET_MAC0_AND_UNIQUE_ADDRESS_PAUSEDETECT/ ENET_UNIQUE_PAUSEDETECT ;
- ENET_RX_FLOWCONTROL_ENABLE/ ENET_RX_FLOWCONTROL_DISABLE ;
@@ -180,7 +213,7 @@ void enet_deinit(void)
ENET_INTERFRAMEGAP_80BIT/ ENET_INTERFRAMEGAP_72BIT/
ENET_INTERFRAMEGAP_64BIT/ ENET_INTERFRAMEGAP_56BIT/
ENET_INTERFRAMEGAP_48BIT/ ENET_INTERFRAMEGAP_40BIT .
- \param[out] none
+ \param[out] none
\retval none
*/
void enet_initpara_config(enet_option_enum option, uint32_t para)
@@ -214,11 +247,11 @@ void enet_initpara_config(enet_option_enum option, uint32_t para)
case DMA_OPTION:
/* choose to configure dma_function, and save the configuration parameters */
enet_initpara.option_enable |= (uint32_t)DMA_OPTION;
-
+
#ifndef SELECT_DESCRIPTORS_ENHANCED_MODE
para &= ~ENET_ENHANCED_DESCRIPTOR;
-#endif /* SELECT_DESCRIPTORS_ENHANCED_MODE */
-
+#endif /* SELECT_DESCRIPTORS_ENHANCED_MODE */
+
enet_initpara.dma_function = para;
break;
case VLAN_OPTION:
@@ -254,7 +287,7 @@ void enet_initpara_config(enet_option_enum option, uint32_t para)
case TIMER_OPTION:
/* choose to configure timer_config, and save the configuration parameters */
enet_initpara.option_enable |= (uint32_t)TIMER_OPTION;
- enet_initpara.timer_config = para;
+ enet_initpara.timer_config = para;
break;
case INTERFRAMEGAP_OPTION:
/* choose to configure interframegap, and save the configuration parameters */
@@ -262,34 +295,34 @@ void enet_initpara_config(enet_option_enum option, uint32_t para)
enet_initpara.interframegap = para;
break;
default:
- break;
- }
-}
+ break;
+ }
+}
/*!
- \brief initialize ENET peripheral with generally concerned parameters and the less cared
+ \brief initialize ENET peripheral with generally concerned parameters and the less cared
parameters
- \param[in] mediamode: PHY mode and mac loopback configurations, only one parameter can be selected
- which is shown as below, refer to enet_mediamode_enum
+ \param[in] mediamode: PHY mode and mac loopback configurations, refer to enet_mediamode_enum
+ only one parameter can be selected which is shown as below
\arg ENET_AUTO_NEGOTIATION: PHY auto negotiation
\arg ENET_100M_FULLDUPLEX: 100Mbit/s, full-duplex
\arg ENET_100M_HALFDUPLEX: 100Mbit/s, half-duplex
\arg ENET_10M_FULLDUPLEX: 10Mbit/s, full-duplex
\arg ENET_10M_HALFDUPLEX: 10Mbit/s, half-duplex
\arg ENET_LOOPBACKMODE: MAC in loopback mode at the MII
- \param[in] checksum: IP frame checksum offload function, only one parameter can be selected
- which is shown as below, refer to enet_mediamode_enum
+ \param[in] checksum: IP frame checksum offload function, refer to enet_mediamode_enum
+ only one parameter can be selected which is shown as below
\arg ENET_NO_AUTOCHECKSUM: disable IP frame checksum function
\arg ENET_AUTOCHECKSUM_DROP_FAILFRAMES: enable IP frame checksum function
\arg ENET_AUTOCHECKSUM_ACCEPT_FAILFRAMES: enable IP frame checksum function, and the received frame
with only payload error but no other errors will not be dropped
- \param[in] recept: frame filter function, only one parameter can be selected
- which is shown as below, refer to enet_frmrecept_enum
+ \param[in] recept: frame filter function, refer to enet_frmrecept_enum
+ only one parameter can be selected which is shown as below
\arg ENET_PROMISCUOUS_MODE: promiscuous mode enabled
\arg ENET_RECEIVEALL: all received frame are forwarded to application
\arg ENET_BROADCAST_FRAMES_PASS: the address filters pass all received broadcast frames
\arg ENET_BROADCAST_FRAMES_DROP: the address filters filter all incoming broadcast frames
- \param[out] none
+ \param[out] none
\retval ErrStatus: ERROR or SUCCESS
*/
ErrStatus enet_init(enet_mediamode_enum mediamode, enet_chksumconf_enum checksum, enet_frmrecept_enum recept)
@@ -297,19 +330,19 @@ ErrStatus enet_init(enet_mediamode_enum mediamode, enet_chksumconf_enum checksum
uint32_t reg_value=0U, reg_temp = 0U, temp = 0U;
uint32_t media_temp = 0U;
uint32_t timeout = 0U;
- uint16_t phy_value = 0U;
+ uint16_t phy_value = 0U;
ErrStatus phy_state= ERROR, enet_state = ERROR;
-
+
/* PHY interface configuration, configure SMI clock and reset PHY chip */
if(ERROR == enet_phy_config()){
_ENET_DELAY_(PHY_RESETDELAY);
if(ERROR == enet_phy_config()){
return enet_state;
- }
+ }
}
/* initialize ENET peripheral with generally concerned parameters */
enet_default_init();
-
+
/* 1st, configure mediamode */
media_temp = (uint32_t)mediamode;
/* if is PHY auto negotiation */
@@ -317,7 +350,7 @@ ErrStatus enet_init(enet_mediamode_enum mediamode, enet_chksumconf_enum checksum
/* wait for PHY_LINKED_STATUS bit be set */
do{
enet_phy_write_read(ENET_PHY_READ, PHY_ADDRESS, PHY_REG_BSR, &phy_value);
- phy_value &= PHY_LINKED_STATUS;
+ phy_value &= PHY_LINKED_STATUS;
timeout++;
}while((RESET == phy_value) && (timeout < PHY_READ_TO));
/* return ERROR due to timeout */
@@ -326,7 +359,7 @@ ErrStatus enet_init(enet_mediamode_enum mediamode, enet_chksumconf_enum checksum
}
/* reset timeout counter */
timeout = 0U;
-
+
/* enable auto-negotiation */
phy_value = PHY_AUTONEGOTIATION;
phy_state = enet_phy_write_read(ENET_PHY_WRITE, PHY_ADDRESS, PHY_REG_BCR, &phy_value);
@@ -334,22 +367,22 @@ ErrStatus enet_init(enet_mediamode_enum mediamode, enet_chksumconf_enum checksum
/* return ERROR due to write timeout */
return enet_state;
}
-
+
/* wait for the PHY_AUTONEGO_COMPLETE bit be set */
do{
enet_phy_write_read(ENET_PHY_READ, PHY_ADDRESS, PHY_REG_BSR, &phy_value);
phy_value &= PHY_AUTONEGO_COMPLETE;
timeout++;
- }while((RESET == phy_value) && (timeout < (uint32_t)PHY_READ_TO));
+ }while((RESET == phy_value) && (timeout < (uint32_t)PHY_READ_TO));
/* return ERROR due to timeout */
if(PHY_READ_TO == timeout){
return enet_state;
}
/* reset timeout counter */
timeout = 0U;
-
+
/* read the result of the auto-negotiation */
- enet_phy_write_read(ENET_PHY_READ, PHY_ADDRESS, PHY_SR, &phy_value);
+ enet_phy_write_read(ENET_PHY_READ, PHY_ADDRESS, PHY_SR, &phy_value);
/* configure the duplex mode of MAC following the auto-negotiation result */
if((uint16_t)RESET != (phy_value & PHY_DUPLEX_STATUS)){
media_temp = ENET_MODE_FULLDUPLEX;
@@ -361,7 +394,7 @@ ErrStatus enet_init(enet_mediamode_enum mediamode, enet_chksumconf_enum checksum
media_temp |= ENET_SPEEDMODE_10M;
}else{
media_temp |= ENET_SPEEDMODE_100M;
- }
+ }
}else{
phy_value = (uint16_t)((media_temp & ENET_MAC_CFG_DPM) >> 3);
phy_value |= (uint16_t)((media_temp & ENET_MAC_CFG_SPD) >> 1);
@@ -371,7 +404,7 @@ ErrStatus enet_init(enet_mediamode_enum mediamode, enet_chksumconf_enum checksum
return enet_state;
}
/* PHY configuration need some time */
- _ENET_DELAY_(PHY_CONFIGDELAY);
+ _ENET_DELAY_(PHY_CONFIGDELAY);
}
/* after configuring the PHY, use mediamode to configure registers */
reg_value = ENET_MAC_CFG;
@@ -379,27 +412,27 @@ ErrStatus enet_init(enet_mediamode_enum mediamode, enet_chksumconf_enum checksum
reg_value &= (~(ENET_MAC_CFG_SPD |ENET_MAC_CFG_DPM |ENET_MAC_CFG_LBM));
reg_value |= media_temp;
ENET_MAC_CFG = reg_value;
-
-
+
+
/* 2st, configure checksum */
if(RESET != ((uint32_t)checksum & ENET_CHECKSUMOFFLOAD_ENABLE)){
ENET_MAC_CFG |= ENET_CHECKSUMOFFLOAD_ENABLE;
-
+
reg_value = ENET_DMA_CTL;
/* configure ENET_DMA_CTL register */
reg_value &= ~ENET_DMA_CTL_DTCERFD;
reg_value |= ((uint32_t)checksum & ENET_DMA_CTL_DTCERFD);
ENET_DMA_CTL = reg_value;
}
-
+
/* 3rd, configure recept */
ENET_MAC_FRMF |= (uint32_t)recept;
-
+
/* 4th, configure different function options */
/* configure forward_frame related registers */
if(RESET != (enet_initpara.option_enable & (uint32_t)FORWARD_OPTION)){
reg_temp = enet_initpara.forward_frame;
-
+
reg_value = ENET_MAC_CFG;
temp = reg_temp;
/* configure ENET_MAC_CFG register */
@@ -407,7 +440,7 @@ ErrStatus enet_init(enet_mediamode_enum mediamode, enet_chksumconf_enum checksum
temp &= (ENET_MAC_CFG_TFCD | ENET_MAC_CFG_APCD);
reg_value |= temp;
ENET_MAC_CFG = reg_value;
-
+
reg_value = ENET_DMA_CTL;
temp = reg_temp;
/* configure ENET_DMA_CTL register */
@@ -420,7 +453,7 @@ ErrStatus enet_init(enet_mediamode_enum mediamode, enet_chksumconf_enum checksum
/* configure dmabus_mode related registers */
if(RESET != (enet_initpara.option_enable & (uint32_t)DMABUS_OPTION)){
temp = enet_initpara.dmabus_mode;
-
+
reg_value = ENET_DMA_BCTL;
/* configure ENET_DMA_BCTL register */
reg_value &= ~(ENET_DMA_BCTL_AA | ENET_DMA_BCTL_FB \
@@ -430,31 +463,31 @@ ErrStatus enet_init(enet_mediamode_enum mediamode, enet_chksumconf_enum checksum
}
/* configure dma_maxburst related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)DMA_MAXBURST_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)DMA_MAXBURST_OPTION)){
temp = enet_initpara.dma_maxburst;
-
+
reg_value = ENET_DMA_BCTL;
/* configure ENET_DMA_BCTL register */
- reg_value &= ~(ENET_DMA_BCTL_RXDP| ENET_DMA_BCTL_PGBL | ENET_DMA_BCTL_UIP);
+ reg_value &= ~(ENET_DMA_BCTL_RXDP| ENET_DMA_BCTL_PGBL | ENET_DMA_BCTL_UIP);
reg_value |= temp;
ENET_DMA_BCTL = reg_value;
}
/* configure dma_arbitration related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)DMA_ARBITRATION_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)DMA_ARBITRATION_OPTION)){
temp = enet_initpara.dma_arbitration;
-
+
reg_value = ENET_DMA_BCTL;
/* configure ENET_DMA_BCTL register */
reg_value &= ~(ENET_DMA_BCTL_RTPR | ENET_DMA_BCTL_DAB);
reg_value |= temp;
ENET_DMA_BCTL = reg_value;
}
-
+
/* configure store_forward_mode related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)STORE_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)STORE_OPTION)){
temp = enet_initpara.store_forward_mode;
-
+
reg_value = ENET_DMA_CTL;
/* configure ENET_DMA_CTL register */
reg_value &= ~(ENET_DMA_CTL_RSFD | ENET_DMA_CTL_TSFD| ENET_DMA_CTL_RTHC| ENET_DMA_CTL_TTHC);
@@ -463,9 +496,9 @@ ErrStatus enet_init(enet_mediamode_enum mediamode, enet_chksumconf_enum checksum
}
/* configure dma_function related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)DMA_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)DMA_OPTION)){
reg_temp = enet_initpara.dma_function;
-
+
reg_value = ENET_DMA_CTL;
temp = reg_temp;
/* configure ENET_DMA_CTL register */
@@ -473,7 +506,7 @@ ErrStatus enet_init(enet_mediamode_enum mediamode, enet_chksumconf_enum checksum
temp &= (ENET_DMA_CTL_DAFRF | ENET_DMA_CTL_OSF);
reg_value |= temp;
ENET_DMA_CTL = reg_value;
-
+
reg_value = ENET_DMA_BCTL;
temp = reg_temp;
/* configure ENET_DMA_BCTL register */
@@ -484,9 +517,9 @@ ErrStatus enet_init(enet_mediamode_enum mediamode, enet_chksumconf_enum checksum
}
/* configure vlan_config related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)VLAN_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)VLAN_OPTION)){
reg_temp = enet_initpara.vlan_config;
-
+
reg_value = ENET_MAC_VLT;
/* configure ENET_MAC_VLT register */
reg_value &= ~(ENET_MAC_VLT_VLTI | ENET_MAC_VLT_VLTC);
@@ -495,9 +528,9 @@ ErrStatus enet_init(enet_mediamode_enum mediamode, enet_chksumconf_enum checksum
}
/* configure flow_control related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)FLOWCTL_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)FLOWCTL_OPTION)){
reg_temp = enet_initpara.flow_control;
-
+
reg_value = ENET_MAC_FCTL;
temp = reg_temp;
/* configure ENET_MAC_FCTL register */
@@ -507,7 +540,7 @@ ErrStatus enet_init(enet_mediamode_enum mediamode, enet_chksumconf_enum checksum
| ENET_MAC_FCTL_UPFDT |ENET_MAC_FCTL_RFCEN |ENET_MAC_FCTL_TFCEN);
reg_value |= temp;
ENET_MAC_FCTL = reg_value;
-
+
reg_value = ENET_MAC_FCTH;
temp = reg_temp;
/* configure ENET_MAC_FCTH register */
@@ -515,22 +548,22 @@ ErrStatus enet_init(enet_mediamode_enum mediamode, enet_chksumconf_enum checksum
temp &= ((ENET_MAC_FCTH_RFA | ENET_MAC_FCTH_RFD )<<8);
reg_value |= (temp >> 8);
ENET_MAC_FCTH = reg_value;
- }
-
+ }
+
/* configure hashtable_high related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)HASHH_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)HASHH_OPTION)){
ENET_MAC_HLH = enet_initpara.hashtable_high;
- }
+ }
/* configure hashtable_low related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)HASHL_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)HASHL_OPTION)){
ENET_MAC_HLL = enet_initpara.hashtable_low;
- }
+ }
/* configure framesfilter_mode related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)FILTER_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)FILTER_OPTION)){
reg_temp = enet_initpara.framesfilter_mode;
-
+
reg_value = ENET_MAC_FRMF;
/* configure ENET_MAC_FRMF register */
reg_value &= ~(ENET_MAC_FRMF_SAFLT | ENET_MAC_FRMF_SAIFLT | ENET_MAC_FRMF_DAIFLT \
@@ -538,41 +571,41 @@ ErrStatus enet_init(enet_mediamode_enum mediamode, enet_chksumconf_enum checksum
| ENET_MAC_FRMF_HUF | ENET_MAC_FRMF_PCFRM);
reg_value |= reg_temp;
ENET_MAC_FRMF = reg_value;
- }
+ }
/* configure halfduplex_param related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)HALFDUPLEX_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)HALFDUPLEX_OPTION)){
reg_temp = enet_initpara.halfduplex_param;
-
+
reg_value = ENET_MAC_CFG;
/* configure ENET_MAC_CFG register */
reg_value &= ~(ENET_MAC_CFG_CSD | ENET_MAC_CFG_ROD | ENET_MAC_CFG_RTD \
| ENET_MAC_CFG_BOL | ENET_MAC_CFG_DFC);
reg_value |= reg_temp;
ENET_MAC_CFG = reg_value;
- }
+ }
/* configure timer_config related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)TIMER_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)TIMER_OPTION)){
reg_temp = enet_initpara.timer_config;
-
+
reg_value = ENET_MAC_CFG;
/* configure ENET_MAC_CFG register */
reg_value &= ~(ENET_MAC_CFG_WDD | ENET_MAC_CFG_JBD);
reg_value |= reg_temp;
ENET_MAC_CFG = reg_value;
- }
-
+ }
+
/* configure interframegap related registers */
- if(RESET != (enet_initpara.option_enable & (uint32_t)INTERFRAMEGAP_OPTION)){
+ if(RESET != (enet_initpara.option_enable & (uint32_t)INTERFRAMEGAP_OPTION)){
reg_temp = enet_initpara.interframegap;
-
+
reg_value = ENET_MAC_CFG;
/* configure ENET_MAC_CFG register */
reg_value &= ~ENET_MAC_CFG_IGBS;
reg_value |= reg_temp;
ENET_MAC_CFG = reg_value;
- }
+ }
enet_state = SUCCESS;
return enet_state;
@@ -589,21 +622,21 @@ ErrStatus enet_software_reset(void)
uint32_t timeout = 0U;
ErrStatus enet_state = ERROR;
uint32_t dma_flag;
-
+
/* reset all core internal registers located in CLK_TX and CLK_RX */
ENET_DMA_BCTL |= ENET_DMA_BCTL_SWR;
-
+
/* wait for reset operation complete */
do{
dma_flag = (ENET_DMA_BCTL & ENET_DMA_BCTL_SWR);
timeout++;
}while((RESET != dma_flag) && (ENET_DELAY_TO != timeout));
- /* reset operation complete */
+ /* reset operation complete */
if(RESET == (ENET_DMA_BCTL & ENET_DMA_BCTL_SWR)){
enet_state = SUCCESS;
}
-
+
return enet_state;
}
@@ -617,15 +650,15 @@ uint32_t enet_rxframe_size_get(void)
{
uint32_t size = 0U;
uint32_t status;
-
+
/* get rdes0 information of current RxDMA descriptor */
status = dma_current_rxdesc->status;
-
+
/* if the desciptor is owned by DMA */
if((uint32_t)RESET != (status & ENET_RDES0_DAV)){
return 0U;
}
-
+
/* if has any error, or the frame uses two or more descriptors */
if((((uint32_t)RESET) != (status & ENET_RDES0_ERRS)) ||
(((uint32_t)RESET) == (status & ENET_RDES0_LDES)) ||
@@ -633,7 +666,7 @@ uint32_t enet_rxframe_size_get(void)
/* drop current receive frame */
enet_rxframe_drop();
- return 0U;
+ return 1U;
}
#ifdef SELECT_DESCRIPTORS_ENHANCED_MODE
/* if is an ethernet-type frame, and IP frame payload error occurred */
@@ -642,18 +675,18 @@ uint32_t enet_rxframe_size_get(void)
/* drop current receive frame */
enet_rxframe_drop();
- return 0U;
+ return 1U;
}
-#else
+#else
/* if is an ethernet-type frame, and IP frame payload error occurred */
if((((uint32_t)RESET) != (status & ENET_RDES0_FRMT)) &&
(((uint32_t)RESET) != (status & ENET_RDES0_PCERR))){
/* drop current receive frame */
enet_rxframe_drop();
- return 0U;
- }
-#endif
+ return 1U;
+ }
+#endif
/* if CPU owns current descriptor, no error occured, the frame uses only one descriptor */
if((((uint32_t)RESET) == (status & ENET_RDES0_DAV)) &&
(((uint32_t)RESET) == (status & ENET_RDES0_ERRS)) &&
@@ -661,22 +694,27 @@ uint32_t enet_rxframe_size_get(void)
(((uint32_t)RESET) != (status & ENET_RDES0_FDES))){
/* get the size of the received data including CRC */
size = GET_RDES0_FRML(status);
- /* substract the CRC size */
+ /* substract the CRC size */
size = size - 4U;
-
- /* if is a type frame, and CRC is not included in forwarding frame */
+
+ /* if is a type frame, and CRC is not included in forwarding frame */
if((RESET != (ENET_MAC_CFG & ENET_MAC_CFG_TFCD)) && (RESET != (status & ENET_RDES0_FRMT))){
size = size + 4U;
}
+ }else{
+ enet_unknow_err++;
+ enet_rxframe_drop();
+
+ return 1U;
}
-
- /* return packet size */
+
+ /* return packet size */
return size;
}
/*!
\brief initialize the DMA Tx/Rx descriptors's parameters in chain mode
- \param[in] direction: the descriptors which users want to init, refer to enet_dmadirection_enum,
+ \param[in] direction: the descriptors which users want to init, refer to enet_dmadirection_enum
only one parameter can be selected which is shown as below
\arg ENET_DMA_TX: DMA Tx descriptors
\arg ENET_DMA_RX: DMA Rx descriptors
@@ -688,7 +726,7 @@ void enet_descriptors_chain_init(enet_dmadirection_enum direction)
uint32_t num = 0U, count = 0U, maxsize = 0U;
uint32_t desc_status = 0U, desc_bufsize = 0U;
enet_descriptors_struct *desc, *desc_tab;
- uint8_t *buf;
+ uint8_t *buf;
/* if want to initialize DMA Tx descriptors */
if (ENET_DMA_TX == direction){
@@ -697,58 +735,58 @@ void enet_descriptors_chain_init(enet_dmadirection_enum direction)
buf = &tx_buff[0][0];
count = ENET_TXBUF_NUM;
maxsize = ENET_TXBUF_SIZE;
-
+
/* select chain mode */
desc_status = ENET_TDES0_TCHM;
-
+
/* configure DMA Tx descriptor table address register */
ENET_DMA_TDTADDR = (uint32_t)desc_tab;
dma_current_txdesc = desc_tab;
- }else{
+ }else{
/* if want to initialize DMA Rx descriptors */
/* save a copy of the DMA Rx descriptors */
desc_tab = rxdesc_tab;
buf = &rx_buff[0][0];
count = ENET_RXBUF_NUM;
maxsize = ENET_RXBUF_SIZE;
-
+
/* enable receiving */
desc_status = ENET_RDES0_DAV;
/* select receive chained mode and set buffer1 size */
desc_bufsize = ENET_RDES1_RCHM | (uint32_t)ENET_RXBUF_SIZE;
-
+
/* configure DMA Rx descriptor table address register */
ENET_DMA_RDTADDR = (uint32_t)desc_tab;
- dma_current_rxdesc = desc_tab;
+ dma_current_rxdesc = desc_tab;
}
dma_current_ptp_rxdesc = NULL;
dma_current_ptp_txdesc = NULL;
-
- /* configure each descriptor */
+
+ /* configure each descriptor */
for(num=0U; num < count; num++){
/* get the pointer to the next descriptor of the descriptor table */
desc = desc_tab + num;
/* configure descriptors */
- desc->status = desc_status;
+ desc->status = desc_status;
desc->control_buffer_size = desc_bufsize;
desc->buffer1_addr = (uint32_t)(&buf[num * maxsize]);
-
+
/* if is not the last descriptor */
if(num < (count - 1U)){
/* configure the next descriptor address */
desc->buffer2_next_desc_addr = (uint32_t)(desc_tab + num + 1U);
}else{
- /* when it is the last descriptor, the next descriptor address
- equals to first descriptor address in descriptor table */
- desc->buffer2_next_desc_addr = (uint32_t) desc_tab;
+ /* when it is the last descriptor, the next descriptor address
+ equals to first descriptor address in descriptor table */
+ desc->buffer2_next_desc_addr = (uint32_t) desc_tab;
}
- }
+ }
}
/*!
\brief initialize the DMA Tx/Rx descriptors's parameters in ring mode
- \param[in] direction: the descriptors which users want to init, refer to enet_dmadirection_enum,
+ \param[in] direction: the descriptors which users want to init, refer to enet_dmadirection_enum
only one parameter can be selected which is shown as below
\arg ENET_DMA_TX: DMA Tx descriptors
\arg ENET_DMA_RX: DMA Rx descriptors
@@ -761,20 +799,20 @@ void enet_descriptors_ring_init(enet_dmadirection_enum direction)
uint32_t desc_status = 0U, desc_bufsize = 0U;
enet_descriptors_struct *desc;
enet_descriptors_struct *desc_tab;
- uint8_t *buf;
-
+ uint8_t *buf;
+
/* configure descriptor skip length */
ENET_DMA_BCTL &= ~ENET_DMA_BCTL_DPSL;
ENET_DMA_BCTL |= DMA_BCTL_DPSL(0);
-
+
/* if want to initialize DMA Tx descriptors */
if (ENET_DMA_TX == direction){
/* save a copy of the DMA Tx descriptors */
desc_tab = txdesc_tab;
buf = &tx_buff[0][0];
count = ENET_TXBUF_NUM;
- maxsize = ENET_TXBUF_SIZE;
-
+ maxsize = ENET_TXBUF_SIZE;
+
/* configure DMA Tx descriptor table address register */
ENET_DMA_TDTADDR = (uint32_t)desc_tab;
dma_current_txdesc = desc_tab;
@@ -784,41 +822,41 @@ void enet_descriptors_ring_init(enet_dmadirection_enum direction)
desc_tab = rxdesc_tab;
buf = &rx_buff[0][0];
count = ENET_RXBUF_NUM;
- maxsize = ENET_RXBUF_SIZE;
-
+ maxsize = ENET_RXBUF_SIZE;
+
/* enable receiving */
desc_status = ENET_RDES0_DAV;
/* set buffer1 size */
desc_bufsize = ENET_RXBUF_SIZE;
-
+
/* configure DMA Rx descriptor table address register */
ENET_DMA_RDTADDR = (uint32_t)desc_tab;
- dma_current_rxdesc = desc_tab;
+ dma_current_rxdesc = desc_tab;
}
dma_current_ptp_rxdesc = NULL;
dma_current_ptp_txdesc = NULL;
-
- /* configure each descriptor */
+
+ /* configure each descriptor */
for(num=0U; num < count; num++){
/* get the pointer to the next descriptor of the descriptor table */
desc = desc_tab + num;
/* configure descriptors */
- desc->status = desc_status;
- desc->control_buffer_size = desc_bufsize;
- desc->buffer1_addr = (uint32_t)(&buf[num * maxsize]);
-
+ desc->status = desc_status;
+ desc->control_buffer_size = desc_bufsize;
+ desc->buffer1_addr = (uint32_t)(&buf[num * maxsize]);
+
/* when it is the last descriptor */
if(num == (count - 1U)){
if (ENET_DMA_TX == direction){
- /* configure transmit end of ring mode */
+ /* configure transmit end of ring mode */
desc->status |= ENET_TDES0_TERM;
}else{
/* configure receive end of ring mode */
desc->control_buffer_size |= ENET_RDES1_RERM;
}
}
- }
+ }
}
/*!
@@ -831,46 +869,46 @@ void enet_descriptors_ring_init(enet_dmadirection_enum direction)
ErrStatus enet_frame_receive(uint8_t *buffer, uint32_t bufsize)
{
uint32_t offset = 0U, size = 0U;
-
+
/* the descriptor is busy due to own by the DMA */
if((uint32_t)RESET != (dma_current_rxdesc->status & ENET_RDES0_DAV)){
- return ERROR;
+ return ERROR;
}
-
+
/* if buffer pointer is null, indicates that users has copied data in application */
if(NULL != buffer){
/* if no error occurs, and the frame uses only one descriptor */
- if((((uint32_t)RESET) == (dma_current_rxdesc->status & ENET_RDES0_ERRS)) &&
- (((uint32_t)RESET) != (dma_current_rxdesc->status & ENET_RDES0_LDES)) &&
- (((uint32_t)RESET) != (dma_current_rxdesc->status & ENET_RDES0_FDES))){
+ if((((uint32_t)RESET) == (dma_current_rxdesc->status & ENET_RDES0_ERRS)) &&
+ (((uint32_t)RESET) != (dma_current_rxdesc->status & ENET_RDES0_LDES)) &&
+ (((uint32_t)RESET) != (dma_current_rxdesc->status & ENET_RDES0_FDES))){
/* get the frame length except CRC */
size = GET_RDES0_FRML(dma_current_rxdesc->status);
size = size - 4U;
-
- /* if is a type frame, and CRC is not included in forwarding frame */
+
+ /* if is a type frame, and CRC is not included in forwarding frame */
if((RESET != (ENET_MAC_CFG & ENET_MAC_CFG_TFCD)) && (RESET != (dma_current_rxdesc->status & ENET_RDES0_FRMT))){
size = size + 4U;
}
-
+
/* to avoid situation that the frame size exceeds the buffer length */
if(size > bufsize){
return ERROR;
}
-
+
/* copy data from Rx buffer to application buffer */
for(offset = 0U; offset<size; offset++){
(*(buffer + offset)) = (*(__IO uint8_t *) (uint32_t)((dma_current_rxdesc->buffer1_addr) + offset));
}
-
+
}else{
/* return ERROR */
return ERROR;
}
}
/* enable reception, descriptor is owned by DMA */
- dma_current_rxdesc->status = ENET_RDES0_DAV;
-
+ dma_current_rxdesc->status = ENET_RDES0_DAV;
+
/* check Rx buffer unavailable flag status */
if ((uint32_t)RESET != (ENET_DMA_STAT & ENET_DMA_STAT_RBU)){
/* clear RBU flag */
@@ -878,22 +916,22 @@ ErrStatus enet_frame_receive(uint8_t *buffer, uint32_t bufsize)
/* resume DMA reception by writing to the RPEN register*/
ENET_DMA_RPEN = 0U;
}
-
- /* update the current RxDMA descriptor pointer to the next decriptor in RxDMA decriptor table */
+
+ /* update the current RxDMA descriptor pointer to the next decriptor in RxDMA decriptor table */
/* chained mode */
- if((uint32_t)RESET != (dma_current_rxdesc->control_buffer_size & ENET_RDES1_RCHM)){
- dma_current_rxdesc = (enet_descriptors_struct*) (dma_current_rxdesc->buffer2_next_desc_addr);
- }else{
+ if((uint32_t)RESET != (dma_current_rxdesc->control_buffer_size & ENET_RDES1_RCHM)){
+ dma_current_rxdesc = (enet_descriptors_struct*) (dma_current_rxdesc->buffer2_next_desc_addr);
+ }else{
/* ring mode */
if((uint32_t)RESET != (dma_current_rxdesc->control_buffer_size & ENET_RDES1_RERM)){
/* if is the last descriptor in table, the next descriptor is the table header */
- dma_current_rxdesc = (enet_descriptors_struct*) (ENET_DMA_RDTADDR);
- }else{
+ dma_current_rxdesc = (enet_descriptors_struct*) (ENET_DMA_RDTADDR);
+ }else{
/* the next descriptor is the current address, add the descriptor size, and descriptor skip length */
- dma_current_rxdesc = (enet_descriptors_struct*) (uint32_t)((uint32_t)dma_current_rxdesc + ETH_DMARXDESC_SIZE + (GET_DMA_BCTL_DPSL(ENET_DMA_BCTL)));
+ dma_current_rxdesc = (enet_descriptors_struct*) (uint32_t)((uint32_t)dma_current_rxdesc + ETH_DMARXDESC_SIZE + (GET_DMA_BCTL_DPSL(ENET_DMA_BCTL)));
}
}
-
+
return SUCCESS;
}
@@ -909,52 +947,52 @@ ErrStatus enet_frame_transmit(uint8_t *buffer, uint32_t length)
{
uint32_t offset = 0U;
uint32_t dma_tbu_flag, dma_tu_flag;
-
+
/* the descriptor is busy due to own by the DMA */
if((uint32_t)RESET != (dma_current_txdesc->status & ENET_TDES0_DAV)){
return ERROR;
}
-
+
/* only frame length no more than ENET_MAX_FRAME_SIZE is allowed */
if(length > ENET_MAX_FRAME_SIZE){
return ERROR;
- }
-
+ }
+
/* if buffer pointer is null, indicates that users has handled data in application */
- if(NULL != buffer){
+ if(NULL != buffer){
/* copy frame data from application buffer to Tx buffer */
for(offset = 0U; offset < length; offset++){
(*(__IO uint8_t *) (uint32_t)((dma_current_txdesc->buffer1_addr) + offset)) = (*(buffer + offset));
}
}
-
+
/* set the frame length */
dma_current_txdesc->control_buffer_size = length;
- /* set the segment of frame, frame is transmitted in one descriptor */
+ /* set the segment of frame, frame is transmitted in one descriptor */
dma_current_txdesc->status |= ENET_TDES0_LSG | ENET_TDES0_FSG;
/* enable the DMA transmission */
dma_current_txdesc->status |= ENET_TDES0_DAV;
-
+
/* check Tx buffer unavailable flag status */
- dma_tbu_flag = (ENET_DMA_STAT & ENET_DMA_STAT_TBU);
+ dma_tbu_flag = (ENET_DMA_STAT & ENET_DMA_STAT_TBU);
dma_tu_flag = (ENET_DMA_STAT & ENET_DMA_STAT_TU);
-
+
if ((RESET != dma_tbu_flag) || (RESET != dma_tu_flag)){
/* clear TBU and TU flag */
ENET_DMA_STAT = (dma_tbu_flag | dma_tu_flag);
/* resume DMA transmission by writing to the TPEN register*/
ENET_DMA_TPEN = 0U;
}
-
- /* update the current TxDMA descriptor pointer to the next decriptor in TxDMA decriptor table*/
+
+ /* update the current TxDMA descriptor pointer to the next decriptor in TxDMA decriptor table*/
/* chained mode */
- if((uint32_t)RESET != (dma_current_txdesc->status & ENET_TDES0_TCHM)){
- dma_current_txdesc = (enet_descriptors_struct*) (dma_current_txdesc->buffer2_next_desc_addr);
- }else{
+ if((uint32_t)RESET != (dma_current_txdesc->status & ENET_TDES0_TCHM)){
+ dma_current_txdesc = (enet_descriptors_struct*) (dma_current_txdesc->buffer2_next_desc_addr);
+ }else{
/* ring mode */
if((uint32_t)RESET != (dma_current_txdesc->status & ENET_TDES0_TERM)){
/* if is the last descriptor in table, the next descriptor is the table header */
- dma_current_txdesc = (enet_descriptors_struct*) (ENET_DMA_TDTADDR);
+ dma_current_txdesc = (enet_descriptors_struct*) (ENET_DMA_TDTADDR);
}else{
/* the next descriptor is the current address, add the descriptor size, and descriptor skip length */
dma_current_txdesc = (enet_descriptors_struct*) (uint32_t)((uint32_t)dma_current_txdesc + ETH_DMATXDESC_SIZE + (GET_DMA_BCTL_DPSL(ENET_DMA_BCTL)));
@@ -966,7 +1004,7 @@ ErrStatus enet_frame_transmit(uint8_t *buffer, uint32_t length)
/*!
\brief configure the transmit IP frame checksum offload calculation and insertion
- \param[in] desc: the descriptor pointer which users want to configure
+ \param[in] desc: the descriptor pointer which users want to configure, refer to enet_descriptors_struct
\param[in] checksum: IP frame checksum configuration
only one parameter can be selected which is shown as below
\arg ENET_CHECKSUM_DISABLE: checksum insertion disabled
@@ -1007,18 +1045,18 @@ void enet_disable(void)
}
/*!
- \brief configure MAC address
- \param[in] mac_addr: select which MAC address will be set,
- only one parameter can be selected which is shown as below
+ \brief configure MAC address
+ \param[in] mac_addr: select which MAC address will be set, refer to enet_macaddress_enum
+ only one parameter can be selected which is shown as below
\arg ENET_MAC_ADDRESS0: set MAC address 0 filter
\arg ENET_MAC_ADDRESS1: set MAC address 1 filter
\arg ENET_MAC_ADDRESS2: set MAC address 2 filter
\arg ENET_MAC_ADDRESS3: set MAC address 3 filter
\param[in] paddr: the buffer pointer which stores the MAC address
- (little-ending store, such as MAC address is aa:bb:cc:dd:ee:22, the buffer is {22, ee, dd, cc, bb, aa})
+ (little-ending store, such as MAC address is aa:bb:cc:dd:ee:22, the buffer is {22, ee, dd, cc, bb, aa})
\param[out] none
\retval none
-*/
+*/
void enet_mac_address_set(enet_macaddress_enum mac_addr, uint8_t paddr[])
{
REG32(ENET_ADDRH_BASE + (uint32_t)mac_addr) = ENET_SET_MACADDRH(paddr);
@@ -1026,17 +1064,17 @@ void enet_mac_address_set(enet_macaddress_enum mac_addr, uint8_t paddr[])
}
/*!
- \brief get MAC address
- \param[in] mac_addr: select which MAC address will be get,
+ \brief get MAC address
+ \param[in] mac_addr: select which MAC address will be get, refer to enet_macaddress_enum
only one parameter can be selected which is shown as below
\arg ENET_MAC_ADDRESS0: get MAC address 0 filter
\arg ENET_MAC_ADDRESS1: get MAC address 1 filter
\arg ENET_MAC_ADDRESS2: get MAC address 2 filter
\arg ENET_MAC_ADDRESS3: get MAC address 3 filter
\param[out] paddr: the buffer pointer which is stored the MAC address
- (little-ending store, such as mac address is aa:bb:cc:dd:ee:22, the buffer is {22, ee, dd, cc, bb, aa})
+ (little-ending store, such as mac address is aa:bb:cc:dd:ee:22, the buffer is {22, ee, dd, cc, bb, aa})
\retval none
-*/
+*/
void enet_mac_address_get(enet_macaddress_enum mac_addr, uint8_t paddr[])
{
paddr[0] = ENET_GET_MACADDR(mac_addr, 0U);
@@ -1048,12 +1086,12 @@ void enet_mac_address_get(enet_macaddress_enum mac_addr, uint8_t paddr[])
}
/*!
- \brief get the ENET MAC/MSC/PTP/DMA status flag
+ \brief get the ENET MAC/MSC/PTP/DMA status flag
\param[in] enet_flag: ENET status flag, refer to enet_flag_enum,
only one parameter can be selected which is shown as below
- \arg ENET_MAC_FLAG_MPKR: magic packet received flag
+ \arg ENET_MAC_FLAG_MPKR: magic packet received flag
\arg ENET_MAC_FLAG_WUFR: wakeup frame received flag
- \arg ENET_MAC_FLAG_FLOWCONTROL: flow control status flag
+ \arg ENET_MAC_FLAG_FLOWCONTROL: flow control status flag
\arg ENET_MAC_FLAG_WUM: WUM status flag
\arg ENET_MAC_FLAG_MSC: MSC status flag
\arg ENET_MAC_FLAG_MSCR: MSC receive status flag
@@ -1101,7 +1139,7 @@ FlagStatus enet_flag_get(enet_flag_enum enet_flag)
}
/*!
- \brief clear the ENET DMA status flag
+ \brief clear the ENET DMA status flag
\param[in] enet_flag: ENET DMA flag clear, refer to enet_flag_clear_enum
only one parameter can be selected which is shown as below
\arg ENET_DMA_FLAG_TS_CLR: transmit status flag clear
@@ -1129,8 +1167,8 @@ void enet_flag_clear(enet_flag_clear_enum enet_flag)
}
/*!
- \brief enable ENET MAC/MSC/DMA interrupt
- \param[in] enet_int: ENET interrupt,
+ \brief enable ENET MAC/MSC/DMA interrupt
+ \param[in] enet_int: ENET interrupt,, refer to enet_int_enum
only one parameter can be selected which is shown as below
\arg ENET_MAC_INT_WUMIM: WUM interrupt mask
\arg ENET_MAC_INT_TMSTIM: timestamp trigger interrupt mask
@@ -1170,8 +1208,8 @@ void enet_interrupt_enable(enet_int_enum enet_int)
}
/*!
- \brief disable ENET MAC/MSC/DMA interrupt
- \param[in] enet_int: ENET interrupt,
+ \brief disable ENET MAC/MSC/DMA interrupt
+ \param[in] enet_int: ENET interrupt, refer to enet_int_enum
only one parameter can be selected which is shown as below
\arg ENET_MAC_INT_WUMIM: WUM interrupt mask
\arg ENET_MAC_INT_TMSTIM: timestamp trigger interrupt mask
@@ -1211,8 +1249,8 @@ void enet_interrupt_disable(enet_int_enum enet_int)
}
/*!
- \brief get ENET MAC/MSC/DMA interrupt flag
- \param[in] int_flag: ENET interrupt flag,
+ \brief get ENET MAC/MSC/DMA interrupt flag
+ \param[in] int_flag: ENET interrupt flag, refer to enet_int_flag_enum
only one parameter can be selected which is shown as below
\arg ENET_MAC_INT_FLAG_WUM: WUM status flag
\arg ENET_MAC_INT_FLAG_MSC: MSC status flag
@@ -1256,8 +1294,8 @@ FlagStatus enet_interrupt_flag_get(enet_int_flag_enum int_flag)
}
/*!
- \brief clear ENET DMA interrupt flag
- \param[in] int_flag_clear: clear ENET interrupt flag,
+ \brief clear ENET DMA interrupt flag
+ \param[in] int_flag_clear: clear ENET interrupt flag, refer to enet_int_flag_clear_enum
only one parameter can be selected which is shown as below
\arg ENET_DMA_INT_FLAG_TS_CLR: transmit status flag
\arg ENET_DMA_INT_FLAG_TPS_CLR: transmit process stopped status flag
@@ -1303,7 +1341,7 @@ void enet_tx_enable(void)
\retval none
*/
void enet_tx_disable(void)
-{
+{
ENET_DMA_CTL &= ~ENET_DMA_CTL_STE;
enet_txfifo_flush();
ENET_MAC_CFG &= ~ENET_MAC_CFG_TEN;
@@ -1334,10 +1372,10 @@ void enet_rx_disable(void)
}
/*!
- \brief put registers value into the application buffer
+ \brief put registers value into the application buffer
\param[in] type: register type which will be get, refer to enet_registers_type_enum,
only one parameter can be selected which is shown as below
- \arg ALL_MAC_REG: get the registers within the offset scope between ENET_MAC_CFG and ENET_MAC_FCTH
+ \arg ALL_MAC_REG: get the registers within the offset scope between ENET_MAC_CFG and ENET_MAC_FCTH
\arg ALL_MSC_REG: get the registers within the offset scope between ENET_MSC_CTL and ENET_MSC_RGUFCNT
\arg ALL_PTP_REG: get the registers within the offset scope between ENET_PTP_TSCTL and ENET_PTP_PPSCTL
\arg ALL_DMA_REG: get the registers within the offset scope between ENET_DMA_BCTL and ENET_DMA_CRBADDR
@@ -1348,37 +1386,37 @@ void enet_rx_disable(void)
void enet_registers_get(enet_registers_type_enum type, uint32_t *preg, uint32_t num)
{
uint32_t offset = 0U, max = 0U, limit = 0U;
-
+
offset = (uint32_t)type;
max = (uint32_t)type + num;
limit = sizeof(enet_reg_tab)/sizeof(uint16_t);
-
+
/* prevent element in this array is out of range */
- if(max > limit){
+ if(max > limit){
max = limit;
}
-
+
for(; offset < max; offset++){
/* get value of the corresponding register */
- *preg = REG32((ENET) + enet_reg_tab[offset]);
+ *preg = REG32((ENET) + enet_reg_tab[offset]);
preg++;
}
-}
+}
/*!
\brief get the enet debug status from the debug register
- \param[in] mac_debug: enet debug status,
+ \param[in] mac_debug: enet debug status
only one parameter can be selected which is shown as below
\arg ENET_MAC_RECEIVER_NOT_IDLE: MAC receiver is not in idle state
\arg ENET_RX_ASYNCHRONOUS_FIFO_STATE: Rx asynchronous FIFO status
- \arg ENET_RXFIFO_NOT_WRITING: RxFIFO is not doing write operation
+ \arg ENET_RXFIFO_WRITING: RxFIFO is doing write operation
\arg ENET_RXFIFO_READ_STATUS: RxFIFO read operation status
\arg ENET_RXFIFO_STATE: RxFIFO state
\arg ENET_MAC_TRANSMITTER_NOT_IDLE: MAC transmitter is not in idle state
\arg ENET_MAC_TRANSMITTER_STATUS: status of MAC transmitter
\arg ENET_PAUSE_CONDITION_STATUS: pause condition status
\arg ENET_TXFIFO_READ_STATUS: TxFIFO read operation status
- \arg ENET_TXFIFO_NOT_WRITING: TxFIFO is not doing write operation
+ \arg ENET_TXFIFO_WRITING: TxFIFO is doing write operation
\arg ENET_TXFIFO_NOT_EMPTY: TxFIFO is not empty
\arg ENET_TXFIFO_FULL: TxFIFO is full
\param[out] none
@@ -1387,7 +1425,7 @@ void enet_registers_get(enet_registers_type_enum type, uint32_t *preg, uint32_t
uint32_t enet_debug_status_get(uint32_t mac_debug)
{
uint32_t temp_state = 0U;
-
+
switch(mac_debug){
case ENET_RX_ASYNCHRONOUS_FIFO_STATE:
temp_state = GET_MAC_DBG_RXAFS(ENET_MAC_DBG);
@@ -1408,14 +1446,14 @@ uint32_t enet_debug_status_get(uint32_t mac_debug)
if(RESET != (ENET_MAC_DBG & mac_debug)){
temp_state = 0x1U;
}
- break;
+ break;
}
return temp_state;
}
/*!
- \brief enable the MAC address filter
- \param[in] mac_addr: select which MAC address will be enable
+ \brief enable the MAC address filter
+ \param[in] mac_addr: select which MAC address will be enable, refer to enet_macaddress_enum
\arg ENET_MAC_ADDRESS1: enable MAC address 1 filter
\arg ENET_MAC_ADDRESS2: enable MAC address 2 filter
\arg ENET_MAC_ADDRESS3: enable MAC address 3 filter
@@ -1428,8 +1466,8 @@ void enet_address_filter_enable(enet_macaddress_enum mac_addr)
}
/*!
- \brief disable the MAC address filter
- \param[in] mac_addr: select which MAC address will be disable,
+ \brief disable the MAC address filter
+ \param[in] mac_addr: select which MAC address will be disable, refer to enet_macaddress_enum
only one parameter can be selected which is shown as below
\arg ENET_MAC_ADDRESS1: disable MAC address 1 filter
\arg ENET_MAC_ADDRESS2: disable MAC address 2 filter
@@ -1443,21 +1481,21 @@ void enet_address_filter_disable(enet_macaddress_enum mac_addr)
}
/*!
- \brief configure the MAC address filter
- \param[in] mac_addr: select which MAC address will be configured,
+ \brief configure the MAC address filter
+ \param[in] mac_addr: select which MAC address will be configured, refer to enet_macaddress_enum
only one parameter can be selected which is shown as below
\arg ENET_MAC_ADDRESS1: configure MAC address 1 filter
\arg ENET_MAC_ADDRESS2: configure MAC address 2 filter
\arg ENET_MAC_ADDRESS3: configure MAC address 3 filter
- \param[in] addr_mask: select which MAC address bytes will be mask,
+ \param[in] addr_mask: select which MAC address bytes will be mask
one or more parameters can be selected which are shown as below
\arg ENET_ADDRESS_MASK_BYTE0: mask ENET_MAC_ADDR1L[7:0] bits
- \arg ENET_ADDRESS_MASK_BYTE1: mask ENET_MAC_ADDR1L[15:8] bits
+ \arg ENET_ADDRESS_MASK_BYTE1: mask ENET_MAC_ADDR1L[15:8] bits
\arg ENET_ADDRESS_MASK_BYTE2: mask ENET_MAC_ADDR1L[23:16] bits
\arg ENET_ADDRESS_MASK_BYTE3: mask ENET_MAC_ADDR1L [31:24] bits
\arg ENET_ADDRESS_MASK_BYTE4: mask ENET_MAC_ADDR1H [7:0] bits
\arg ENET_ADDRESS_MASK_BYTE5: mask ENET_MAC_ADDR1H [15:8] bits
- \param[in] filter_type: select which MAC address filter type will be selected,
+ \param[in] filter_type: select which MAC address filter type will be selected
only one parameter can be selected which is shown as below
\arg ENET_ADDRESS_FILTER_SA: The MAC address is used to compared with the SA field of the received frame
\arg ENET_ADDRESS_FILTER_DA: The MAC address is used to compared with the DA field of the received frame
@@ -1467,7 +1505,7 @@ void enet_address_filter_disable(enet_macaddress_enum mac_addr)
void enet_address_filter_config(enet_macaddress_enum mac_addr, uint32_t addr_mask, uint32_t filter_type)
{
uint32_t reg;
-
+
/* get the address filter register value which is to be configured */
reg = REG32(ENET_ADDRH_BASE + mac_addr);
@@ -1482,21 +1520,21 @@ void enet_address_filter_config(enet_macaddress_enum mac_addr, uint32_t addr_mas
\param[in] none
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
-*/
+*/
ErrStatus enet_phy_config(void)
{
uint32_t ahbclk;
uint32_t reg;
uint16_t phy_value;
ErrStatus enet_state = ERROR;
-
+
/* clear the previous MDC clock */
reg = ENET_MAC_PHY_CTL;
reg &= ~ENET_MAC_PHY_CTL_CLR;
/* get the HCLK frequency */
ahbclk = rcu_clock_freq_get(CK_AHB);
-
+
/* configure MDC clock according to HCLK frequency range */
if(ENET_RANGE(ahbclk, 20000000U, 35000000U)){
reg |= ENET_MDC_HCLK_DIV16;
@@ -1507,7 +1545,7 @@ ErrStatus enet_phy_config(void)
}else if(ENET_RANGE(ahbclk, 100000000U, 150000000U)){
reg |= ENET_MDC_HCLK_DIV62;
}else if((ENET_RANGE(ahbclk, 150000000U, 200000000U))||(200000000U == ahbclk)){
- reg |= ENET_MDC_HCLK_DIV102;
+ reg |= ENET_MDC_HCLK_DIV102;
}else{
return enet_state;
}
@@ -1518,9 +1556,9 @@ ErrStatus enet_phy_config(void)
if(ERROR == (enet_phy_write_read(ENET_PHY_WRITE, PHY_ADDRESS, PHY_REG_BCR, &phy_value))){
return enet_state;
}
- /* PHY reset need some time */
+ /* PHY reset need some time */
_ENET_DELAY_(ENET_DELAY_TO);
-
+
/* check whether PHY reset is complete */
if(ERROR == (enet_phy_write_read(ENET_PHY_READ, PHY_ADDRESS, PHY_REG_BCR, &phy_value))){
return enet_state;
@@ -1530,18 +1568,18 @@ ErrStatus enet_phy_config(void)
if(RESET == (phy_value & PHY_RESET)){
enet_state = SUCCESS;
}
-
+
return enet_state;
}
/*!
\brief write to / read from a PHY register
- \param[in] direction: only one parameter can be selected which is shown as below
+ \param[in] direction: only one parameter can be selected which is shown as below, refer to enet_phydirection_enum
\arg ENET_PHY_WRITE: write data to phy register
\arg ENET_PHY_READ: read data from phy register
- \param[in] phy_address: 0x0 - 0x1F
- \param[in] phy_reg: 0x0 - 0x1F
- \param[in] pvalue: the value will be written to the PHY register in ENET_PHY_WRITE direction
+ \param[in] phy_address: 0x0000 - 0x001F
+ \param[in] phy_reg: 0x0000 - 0x001F
+ \param[in] pvalue: the value will be written to the PHY register in ENET_PHY_WRITE direction
\param[out] pvalue: the value will be read from the PHY register in ENET_PHY_READ direction
\retval ErrStatus: SUCCESS or ERROR
*/
@@ -1551,16 +1589,16 @@ ErrStatus enet_phy_write_read(enet_phydirection_enum direction, uint16_t phy_add
uint32_t timeout = 0U;
ErrStatus enet_state = ERROR;
- /* configure ENET_MAC_PHY_CTL with write/read operation */
+ /* configure ENET_MAC_PHY_CTL with write/read operation */
reg = ENET_MAC_PHY_CTL;
reg &= ~(ENET_MAC_PHY_CTL_PB | ENET_MAC_PHY_CTL_PW | ENET_MAC_PHY_CTL_PR | ENET_MAC_PHY_CTL_PA);
- reg |= (direction | MAC_PHY_CTL_PR(phy_reg) | MAC_PHY_CTL_PA(phy_address) | ENET_MAC_PHY_CTL_PB);
+ reg |= (direction | MAC_PHY_CTL_PR(phy_reg) | MAC_PHY_CTL_PA(phy_address) | ENET_MAC_PHY_CTL_PB);
/* if do the write operation, write value to the register */
if(ENET_PHY_WRITE == direction){
- ENET_MAC_PHY_DATA = *pvalue;
+ ENET_MAC_PHY_DATA = *pvalue;
}
-
+
/* do PHY write/read operation, and wait the operation complete */
ENET_MAC_PHY_CTL = reg;
do{
@@ -1569,16 +1607,16 @@ ErrStatus enet_phy_write_read(enet_phydirection_enum direction, uint16_t phy_add
}
while((RESET != phy_flag) && (ENET_DELAY_TO != timeout));
- /* write/read operation complete */
+ /* write/read operation complete */
if(RESET == (ENET_MAC_PHY_CTL & ENET_MAC_PHY_CTL_PB)){
enet_state = SUCCESS;
}
- /* if do the read operation, get value from the register */
+ /* if do the read operation, get value from the register */
if(ENET_PHY_READ == direction){
- *pvalue = (uint16_t)ENET_MAC_PHY_DATA;
+ *pvalue = (uint16_t)ENET_MAC_PHY_DATA;
}
-
+
return enet_state;
}
@@ -1594,7 +1632,7 @@ ErrStatus enet_phyloopback_enable(void)
ErrStatus phy_state = ERROR;
/* get the PHY configuration to update it */
- enet_phy_write_read(ENET_PHY_READ, PHY_ADDRESS, PHY_REG_BCR, &temp_phy);
+ enet_phy_write_read(ENET_PHY_READ, PHY_ADDRESS, PHY_REG_BCR, &temp_phy);
/* enable the PHY loopback mode */
temp_phy |= PHY_LOOPBACK;
@@ -1617,7 +1655,7 @@ ErrStatus enet_phyloopback_disable(void)
ErrStatus phy_state = ERROR;
/* get the PHY configuration to update it */
- enet_phy_write_read(ENET_PHY_READ, PHY_ADDRESS, PHY_REG_BCR, &temp_phy);
+ enet_phy_write_read(ENET_PHY_READ, PHY_ADDRESS, PHY_REG_BCR, &temp_phy);
/* disable the PHY loopback mode */
temp_phy &= (uint16_t)~PHY_LOOPBACK;
@@ -1630,7 +1668,7 @@ ErrStatus enet_phyloopback_disable(void)
/*!
\brief enable ENET forward feature
- \param[in] feature: the feature of ENET forward mode,
+ \param[in] feature: the feature of ENET forward mode
one or more parameters can be selected which are shown as below
\arg ENET_AUTO_PADCRC_DROP: the function of the MAC strips the Pad/FCS field on received frames
\arg ENET_TYPEFRAME_CRC_DROP: the function that FCS field(last 4 bytes) of frame will be dropped before forwarding
@@ -1642,17 +1680,17 @@ ErrStatus enet_phyloopback_disable(void)
void enet_forward_feature_enable(uint32_t feature)
{
uint32_t mask;
-
+
mask = (feature & (~(ENET_FORWARD_ERRFRAMES | ENET_FORWARD_UNDERSZ_GOODFRAMES)));
ENET_MAC_CFG |= mask;
-
+
mask = (feature & (~(ENET_AUTO_PADCRC_DROP | ENET_TYPEFRAME_CRC_DROP)));
ENET_DMA_CTL |= (mask >> 2);
}
/*!
\brief disable ENET forward feature
- \param[in] feature: the feature of ENET forward mode,
+ \param[in] feature: the feature of ENET forward mode
one or more parameters can be selected which are shown as below
\arg ENET_AUTO_PADCRC_DROP: the automatic zero-quanta generation function
\arg ENET_TYPEFRAME_CRC_DROP: the flow control operation in the MAC
@@ -1664,17 +1702,17 @@ void enet_forward_feature_enable(uint32_t feature)
void enet_forward_feature_disable(uint32_t feature)
{
uint32_t mask;
-
+
mask = (feature & (~(ENET_FORWARD_ERRFRAMES | ENET_FORWARD_UNDERSZ_GOODFRAMES)));
ENET_MAC_CFG &= ~mask;
-
+
mask = (feature & (~(ENET_AUTO_PADCRC_DROP | ENET_TYPEFRAME_CRC_DROP)));
ENET_DMA_CTL &= ~(mask >> 2);
}
-
-/*!
+
+/*!
\brief enable ENET fliter feature
- \param[in] feature: the feature of ENET fliter mode,
+ \param[in] feature: the feature of ENET fliter mode
one or more parameters can be selected which are shown as below
\arg ENET_SRC_FILTER: filter source address function
\arg ENET_SRC_FILTER_INVERSE: inverse source address filtering result function
@@ -1693,7 +1731,7 @@ void enet_fliter_feature_enable(uint32_t feature)
/*!
\brief disable ENET fliter feature
- \param[in] feature: the feature of ENET fliter mode,
+ \param[in] feature: the feature of ENET fliter mode
one or more parameters can be selected which are shown as below
\arg ENET_SRC_FILTER: filter source address function
\arg ENET_SRC_FILTER_INVERSE: inverse source address filtering result function
@@ -1717,8 +1755,8 @@ void enet_fliter_feature_disable(uint32_t feature)
\param[out] none
\retval ErrStatus: ERROR or SUCCESS
*/
-ErrStatus enet_pauseframe_generate(void)
-{
+ErrStatus enet_pauseframe_generate(void)
+{
ErrStatus enet_state =ERROR;
uint32_t temp = 0U;
@@ -1728,16 +1766,16 @@ ErrStatus enet_pauseframe_generate(void)
ENET_MAC_FCTL |= ENET_MAC_FCTL_FLCBBKPA;
enet_state = SUCCESS;
}
- return enet_state;
+ return enet_state;
}
/*!
\brief configure the pause frame detect type
- \param[in] detect: pause frame detect type,
+ \param[in] detect: pause frame detect type
only one parameter can be selected which is shown as below
\arg ENET_MAC0_AND_UNIQUE_ADDRESS_PAUSEDETECT: besides the unique multicast address, MAC can also
use the MAC0 address to detecting pause frame
- \arg ENET_UNIQUE_PAUSEDETECT: only the unique multicast address for pause frame which is specified
+ \arg ENET_UNIQUE_PAUSEDETECT: only the unique multicast address for pause frame which is specified
in IEEE802.3 can be detected
\param[out] none
\retval none
@@ -1751,9 +1789,9 @@ void enet_pauseframe_detect_config(uint32_t detect)
/*!
\brief configure the pause frame parameters
\param[in] pausetime: pause time in transmit pause control frame
- \param[in] pause_threshold: the threshold of the pause timer for retransmitting frames automatically,
- this value must make sure to be less than configured pause time, only one parameter can be
- selected which is shown as below
+ \param[in] pause_threshold: the threshold of the pause timer for retransmitting frames automatically
+ this value must make sure to be less than configured pause time
+ only one parameter can be selected which is shown as below
\arg ENET_PAUSETIME_MINUS4: pause time minus 4 slot times
\arg ENET_PAUSETIME_MINUS28: pause time minus 28 slot times
\arg ENET_PAUSETIME_MINUS144: pause time minus 144 slot times
@@ -1769,9 +1807,9 @@ void enet_pauseframe_config(uint32_t pausetime, uint32_t pause_threshold)
/*!
\brief configure the threshold of the flow control(deactive and active threshold)
- \param[in] deactive: the threshold of the deactive flow control, this value
- should always be less than active flow control value, only one
- parameter can be selected which is shown as below
+ \param[in] deactive: the threshold of the deactive flow control
+ this value should always be less than active flow control value
+ only one parameter can be selected which is shown as below
\arg ENET_DEACTIVE_THRESHOLD_256BYTES: threshold level is 256 bytes
\arg ENET_DEACTIVE_THRESHOLD_512BYTES: threshold level is 512 bytes
\arg ENET_DEACTIVE_THRESHOLD_768BYTES: threshold level is 768 bytes
@@ -1779,8 +1817,8 @@ void enet_pauseframe_config(uint32_t pausetime, uint32_t pause_threshold)
\arg ENET_DEACTIVE_THRESHOLD_1280BYTES: threshold level is 1280 bytes
\arg ENET_DEACTIVE_THRESHOLD_1536BYTES: threshold level is 1536 bytes
\arg ENET_DEACTIVE_THRESHOLD_1792BYTES: threshold level is 1792 bytes
- \param[in] active: the threshold of the active flow control, only one parameter
- can be selected which is shown as below
+ \param[in] active: the threshold of the active flow control
+ only one parameter can be selected which is shown as below
\arg ENET_ACTIVE_THRESHOLD_256BYTES: threshold level is 256 bytes
\arg ENET_ACTIVE_THRESHOLD_512BYTES: threshold level is 512 bytes
\arg ENET_ACTIVE_THRESHOLD_768BYTES: threshold level is 768 bytes
@@ -1793,7 +1831,7 @@ void enet_pauseframe_config(uint32_t pausetime, uint32_t pause_threshold)
*/
void enet_flowcontrol_threshold_config(uint32_t deactive, uint32_t active)
{
- ENET_MAC_FCTH = ((deactive | active) >> 8);
+ ENET_MAC_FCTH = ((deactive | active) >> 8);
}
/*!
@@ -1838,8 +1876,8 @@ void enet_flowcontrol_feature_disable(uint32_t feature)
/*!
\brief get the dma transmit/receive process state
- \param[in] direction: choose the direction of dma process which users want to check,
- refer to enet_dmadirection_enum, only one parameter can be selected which is shown as below
+ \param[in] direction: choose the direction of dma process which users want to check, refer to enet_dmadirection_enum
+ only one parameter can be selected which is shown as below
\arg ENET_DMA_TX: dma transmit process
\arg ENET_DMA_RX: dma receive process
\param[out] none
@@ -1857,10 +1895,10 @@ uint32_t enet_dmaprocess_state_get(enet_dmadirection_enum direction)
}
/*!
- \brief poll the DMA transmission/reception enable by writing any value to the
+ \brief poll the DMA transmission/reception enable by writing any value to the
ENET_DMA_TPEN/ENET_DMA_RPEN register, this will make the DMA to resume transmission/reception
- \param[in] direction: choose the direction of DMA process which users want to resume,
- refer to enet_dmadirection_enum, only one parameter can be selected which is shown as below
+ \param[in] direction: choose the direction of DMA process which users want to resume, refer to enet_dmadirection_enum
+ only one parameter can be selected which is shown as below
\arg ENET_DMA_TX: DMA transmit process
\arg ENET_DMA_RX: DMA receive process
\param[out] none
@@ -1876,7 +1914,7 @@ void enet_dmaprocess_resume(enet_dmadirection_enum direction)
}
/*!
- \brief check and recover the Rx process
+ \brief check and recover the Rx process
\param[in] none
\param[out] none
\retval none
@@ -1885,11 +1923,11 @@ void enet_rxprocess_check_recovery(void)
{
uint32_t status;
- /* get DAV information of current RxDMA descriptor */
+ /* get DAV information of current RxDMA descriptor */
status = dma_current_rxdesc->status;
status &= ENET_RDES0_DAV;
-
- /* if current descriptor is owned by DMA, but the descriptor address mismatches with
+
+ /* if current descriptor is owned by DMA, but the descriptor address mismatches with
receive descriptor address pointer updated by RxDMA controller */
if((ENET_DMA_CRDADDR != ((uint32_t)dma_current_rxdesc)) &&
(ENET_RDES0_DAV == status)){
@@ -1908,25 +1946,25 @@ ErrStatus enet_txfifo_flush(void)
uint32_t flush_state;
uint32_t timeout = 0U;
ErrStatus enet_state = ERROR;
-
+
/* set the FTF bit for flushing transmit FIFO */
- ENET_DMA_CTL |= ENET_DMA_CTL_FTF;
+ ENET_DMA_CTL |= ENET_DMA_CTL_FTF;
/* wait until the flush operation completes */
do{
- flush_state = ENET_DMA_CTL & ENET_DMA_CTL_FTF;
+ flush_state = ENET_DMA_CTL & ENET_DMA_CTL_FTF;
timeout++;
}while((RESET != flush_state) && (timeout < ENET_DELAY_TO));
/* return ERROR due to timeout */
if(RESET == flush_state){
enet_state = SUCCESS;
}
-
+
return enet_state;
}
/*!
\brief get the transmit/receive address of current descriptor, or current buffer, or descriptor table
- \param[in] addr_get: choose the address which users want to get, refer to enet_desc_reg_enum,
+ \param[in] addr_get: choose the address which users want to get, refer to enet_desc_reg_enum
only one parameter can be selected which is shown as below
\arg ENET_RX_DESC_TABLE: the start address of the receive descriptor table
\arg ENET_RX_CURRENT_DESC: the start descriptor address of the current receive descriptor read by
@@ -1936,7 +1974,7 @@ ErrStatus enet_txfifo_flush(void)
\arg ENET_TX_CURRENT_DESC: the start descriptor address of the current transmit descriptor read by
the TxDMA controller
\arg ENET_TX_CURRENT_BUFFER: the current transmit buffer address being read by the TxDMA controller
- \param[out] none
+ \param[out] none
\retval address value
*/
uint32_t enet_current_desc_address_get(enet_desc_reg_enum addr_get)
@@ -1950,7 +1988,7 @@ uint32_t enet_current_desc_address_get(enet_desc_reg_enum addr_get)
/*!
\brief get the Tx or Rx descriptor information
\param[in] desc: the descriptor pointer which users want to get information
- \param[in] info_get: the descriptor information type which is selected,
+ \param[in] info_get: the descriptor information type which is selected, refer to enet_descstate_enum
only one parameter can be selected which is shown as below
\arg RXDESC_BUFFER_1_SIZE: receive buffer 1 size
\arg RXDESC_BUFFER_2_SIZE: receive buffer 2 size
@@ -1971,25 +2009,30 @@ uint32_t enet_desc_information_get(enet_descriptors_struct *desc, enet_descstate
break;
case RXDESC_BUFFER_2_SIZE:
reval = GET_RDES1_RB2S(desc->control_buffer_size);
- break;
- case RXDESC_FRAME_LENGTH:
+ break;
+ case RXDESC_FRAME_LENGTH:
reval = GET_RDES0_FRML(desc->status);
- reval = reval - 4U;
-
- /* if is a type frame, and CRC is not included in forwarding frame */
- if((RESET != (ENET_MAC_CFG & ENET_MAC_CFG_TFCD)) && (RESET != (desc->status & ENET_RDES0_FRMT))){
- reval = reval + 4U;
- }
+ if(reval > 4U){
+ reval = reval - 4U;
+
+ /* if is a type frame, and CRC is not included in forwarding frame */
+ if((RESET != (ENET_MAC_CFG & ENET_MAC_CFG_TFCD)) && (RESET != (desc->status & ENET_RDES0_FRMT))){
+ reval = reval + 4U;
+ }
+ }else{
+ reval = 0U;
+ }
+
break;
- case RXDESC_BUFFER_1_ADDR:
- reval = desc->buffer1_addr;
+ case RXDESC_BUFFER_1_ADDR:
+ reval = desc->buffer1_addr;
break;
- case TXDESC_BUFFER_1_ADDR:
- reval = desc->buffer1_addr;
+ case TXDESC_BUFFER_1_ADDR:
+ reval = desc->buffer1_addr;
break;
- case TXDESC_COLLISION_COUNT:
+ case TXDESC_COLLISION_COUNT:
reval = GET_TDES0_COCNT(desc->status);
- break;
+ break;
default:
break;
}
@@ -2006,7 +2049,7 @@ uint32_t enet_desc_information_get(enet_descriptors_struct *desc, enet_descstate
void enet_missed_frame_counter_get(uint32_t *rxfifo_drop, uint32_t *rxdma_drop)
{
uint32_t temp_counter = 0U;
-
+
temp_counter = ENET_DMA_MFBOCNT;
*rxfifo_drop = GET_DMA_MFBOCNT_MSFA(temp_counter);
*rxdma_drop = GET_DMA_MFBOCNT_MSFC(temp_counter);
@@ -2015,9 +2058,9 @@ void enet_missed_frame_counter_get(uint32_t *rxfifo_drop, uint32_t *rxdma_drop)
/*!
\brief get the bit flag of ENET DMA descriptor
\param[in] desc: the descriptor pointer which users want to get flag
- \param[in] desc_flag: the bit flag of ENET DMA descriptor,
+ \param[in] desc_flag: the bit flag of ENET DMA descriptor
only one parameter can be selected which is shown as below
- \arg ENET_TDES0_DB: deferred
+ \arg ENET_TDES0_DB: deferred
\arg ENET_TDES0_UFE: underflow error
\arg ENET_TDES0_EXD: excessive deferral
\arg ENET_TDES0_VFRM: VLAN frame
@@ -2030,18 +2073,18 @@ void enet_missed_frame_counter_get(uint32_t *rxfifo_drop, uint32_t *rxdma_drop)
\arg ENET_TDES0_JT: jabber timeout
\arg ENET_TDES0_ES: error summary
\arg ENET_TDES0_IPHE: IP header error
- \arg ENET_TDES0_TTMSS: transmit timestamp status
+ \arg ENET_TDES0_TTMSS: transmit timestamp status
\arg ENET_TDES0_TCHM: the second address chained mode
\arg ENET_TDES0_TERM: transmit end of ring mode
\arg ENET_TDES0_TTSEN: transmit timestamp function enable
- \arg ENET_TDES0_DPAD: disable adding pad
+ \arg ENET_TDES0_DPAD: disable adding pad
\arg ENET_TDES0_DCRC: disable CRC
\arg ENET_TDES0_FSG: first segment
\arg ENET_TDES0_LSG: last segment
\arg ENET_TDES0_INTC: interrupt on completion
\arg ENET_TDES0_DAV: DAV bit
-
- \arg ENET_RDES0_PCERR: payload checksum error
+
+ \arg ENET_RDES0_PCERR: payload checksum error
\arg ENET_RDES0_EXSV: extended status valid
\arg ENET_RDES0_CERR: CRC error
\arg ENET_RDES0_DBERR: dribble bit error
@@ -2054,11 +2097,11 @@ void enet_missed_frame_counter_get(uint32_t *rxfifo_drop, uint32_t *rxdma_drop)
\arg ENET_RDES0_LDES: last descriptor
\arg ENET_RDES0_FDES: first descriptor
\arg ENET_RDES0_VTAG: VLAN tag
- \arg ENET_RDES0_OERR: overflow error
+ \arg ENET_RDES0_OERR: overflow error
\arg ENET_RDES0_LERR: length error
\arg ENET_RDES0_SAFF: SA filter fail
\arg ENET_RDES0_DERR: descriptor error
- \arg ENET_RDES0_ERRS: error summary
+ \arg ENET_RDES0_ERRS: error summary
\arg ENET_RDES0_DAFF: destination address filter fail
\arg ENET_RDES0_DAV: descriptor available
\param[out] none
@@ -2067,7 +2110,7 @@ void enet_missed_frame_counter_get(uint32_t *rxfifo_drop, uint32_t *rxdma_drop)
FlagStatus enet_desc_flag_get(enet_descriptors_struct *desc, uint32_t desc_flag)
{
FlagStatus enet_flag = RESET;
-
+
if ((uint32_t)RESET != (desc->status & desc_flag)){
enet_flag = SET;
}
@@ -2078,20 +2121,20 @@ FlagStatus enet_desc_flag_get(enet_descriptors_struct *desc, uint32_t desc_flag)
/*!
\brief set the bit flag of ENET DMA descriptor
\param[in] desc: the descriptor pointer which users want to set flag
- \param[in] desc_flag: the bit flag of ENET DMA descriptor,
+ \param[in] desc_flag: the bit flag of ENET DMA descriptor
only one parameter can be selected which is shown as below
\arg ENET_TDES0_VFRM: VLAN frame
\arg ENET_TDES0_FRMF: frame flushed
\arg ENET_TDES0_TCHM: the second address chained mode
\arg ENET_TDES0_TERM: transmit end of ring mode
\arg ENET_TDES0_TTSEN: transmit timestamp function enable
- \arg ENET_TDES0_DPAD: disable adding pad
+ \arg ENET_TDES0_DPAD: disable adding pad
\arg ENET_TDES0_DCRC: disable CRC
\arg ENET_TDES0_FSG: first segment
\arg ENET_TDES0_LSG: last segment
\arg ENET_TDES0_INTC: interrupt on completion
\arg ENET_TDES0_DAV: DAV bit
- \arg ENET_RDES0_DAV: descriptor available
+ \arg ENET_RDES0_DAV: descriptor available
\param[out] none
\retval none
*/
@@ -2103,20 +2146,20 @@ void enet_desc_flag_set(enet_descriptors_struct *desc, uint32_t desc_flag)
/*!
\brief clear the bit flag of ENET DMA descriptor
\param[in] desc: the descriptor pointer which users want to clear flag
- \param[in] desc_flag: the bit flag of ENET DMA descriptor,
+ \param[in] desc_flag: the bit flag of ENET DMA descriptor
only one parameter can be selected which is shown as below
\arg ENET_TDES0_VFRM: VLAN frame
\arg ENET_TDES0_FRMF: frame flushed
\arg ENET_TDES0_TCHM: the second address chained mode
\arg ENET_TDES0_TERM: transmit end of ring mode
\arg ENET_TDES0_TTSEN: transmit timestamp function enable
- \arg ENET_TDES0_DPAD: disable adding pad
+ \arg ENET_TDES0_DPAD: disable adding pad
\arg ENET_TDES0_DCRC: disable CRC
\arg ENET_TDES0_FSG: first segment
\arg ENET_TDES0_LSG: last segment
\arg ENET_TDES0_INTC: interrupt on completion
\arg ENET_TDES0_DAV: DAV bit
- \arg ENET_RDES0_DAV: descriptor available
+ \arg ENET_RDES0_DAV: descriptor available
\param[out] none
\retval none
*/
@@ -2126,7 +2169,7 @@ void enet_desc_flag_clear(enet_descriptors_struct *desc, uint32_t desc_flag)
}
/*!
- \brief when receiving completed, set RS bit in ENET_DMA_STAT register will immediately set
+ \brief when receiving completed, set RS bit in ENET_DMA_STAT register will immediately set
\param[in] desc: the descriptor pointer which users want to configure
\param[out] none
\retval none
@@ -2137,9 +2180,9 @@ void enet_rx_desc_immediate_receive_complete_interrupt(enet_descriptors_struct *
}
/*!
- \brief when receiving completed, set RS bit in ENET_DMA_STAT register will is set after a configurable delay time
+ \brief when receiving completed, set RS bit in ENET_DMA_STAT register will is set after a configurable delay time
\param[in] desc: the descriptor pointer which users want to configure
- \param[in] delay_time: delay a time of 256*delay_time HCLK, this value must be between 0 and 0xFF
+ \param[in] delay_time: delay a time of 256*delay_time HCLK(0x00000000 - 0x000000FF)
\param[out] none
\retval none
*/
@@ -2158,10 +2201,10 @@ void enet_rx_desc_delay_receive_complete_interrupt(enet_descriptors_struct *desc
void enet_rxframe_drop(void)
{
/* enable reception, descriptor is owned by DMA */
- dma_current_rxdesc->status = ENET_RDES0_DAV;
-
+ dma_current_rxdesc->status = ENET_RDES0_DAV;
+
/* chained mode */
- if((uint32_t)RESET != (dma_current_rxdesc->control_buffer_size & ENET_RDES1_RCHM)){
+ if((uint32_t)RESET != (dma_current_rxdesc->control_buffer_size & ENET_RDES1_RCHM)){
if(NULL != dma_current_ptp_rxdesc){
dma_current_rxdesc = (enet_descriptors_struct*) (dma_current_ptp_rxdesc->buffer2_next_desc_addr);
/* if it is the last ptp descriptor */
@@ -2175,9 +2218,9 @@ void enet_rxframe_drop(void)
}else{
dma_current_rxdesc = (enet_descriptors_struct*) (dma_current_rxdesc->buffer2_next_desc_addr);
}
-
+
}else{
- /* ring mode */
+ /* ring mode */
if((uint32_t)RESET != (dma_current_rxdesc->control_buffer_size & ENET_RDES1_RERM)){
/* if is the last descriptor in table, the next descriptor is the table header */
dma_current_rxdesc = (enet_descriptors_struct*) (ENET_DMA_RDTADDR);
@@ -2196,9 +2239,9 @@ void enet_rxframe_drop(void)
/*!
\brief enable DMA feature
- \param[in] feature: the feature of DMA mode,
+ \param[in] feature: the feature of DMA mode
one or more parameters can be selected which are shown as below
- \arg ENET_FLUSH_RXFRAME: RxDMA flushes frames function
+ \arg ENET_NO_FLUSH_RXFRAME: RxDMA does not flushes frames function
\arg ENET_SECONDFRAME_OPT: TxDMA controller operate on second frame function
\param[out] none
\retval none
@@ -2210,9 +2253,9 @@ void enet_dma_feature_enable(uint32_t feature)
/*!
\brief disable DMA feature
- \param[in] feature: the feature of DMA mode,
+ \param[in] feature: the feature of DMA mode
one or more parameters can be selected which are shown as below
- \arg ENET_FLUSH_RXFRAME: RxDMA flushes frames function
+ \arg ENET_NO_FLUSH_RXFRAME: RxDMA does not flushes frames function
\arg ENET_SECONDFRAME_OPT: TxDMA controller operate on second frame function
\param[out] none
\retval none
@@ -2226,7 +2269,7 @@ void enet_dma_feature_disable(uint32_t feature)
/*!
\brief get the bit of extended status flag in ENET DMA descriptor
\param[in] desc: the descriptor pointer which users want to get the extended status flag
- \param[in] desc_status: the extended status want to get,
+ \param[in] desc_status: the extended status want to get
only one parameter can be selected which is shown as below
\arg ENET_RDES4_IPPLDT: IP frame payload type
\arg ENET_RDES4_IPHERR: IP frame header error
@@ -2243,7 +2286,7 @@ void enet_dma_feature_disable(uint32_t feature)
uint32_t enet_rx_desc_enhanced_status_get(enet_descriptors_struct *desc, uint32_t desc_status)
{
uint32_t reval = 0xFFFFFFFFU;
-
+
switch (desc_status){
case ENET_RDES4_IPPLDT:
reval = GET_RDES4_IPPLDT(desc->extended_status);
@@ -2256,9 +2299,9 @@ uint32_t enet_rx_desc_enhanced_status_get(enet_descriptors_struct *desc, uint32_
reval = 1U;
}else{
reval = 0U;
- }
+ }
}
-
+
return reval;
}
@@ -2275,7 +2318,7 @@ void enet_desc_select_enhanced_mode(void)
/*!
\brief initialize the DMA Tx/Rx descriptors's parameters in enhanced chain mode with ptp function
- \param[in] direction: the descriptors which users want to init, refer to enet_dmadirection_enum,
+ \param[in] direction: the descriptors which users want to init, refer to enet_dmadirection_enum
only one parameter can be selected which is shown as below
\arg ENET_DMA_TX: DMA Tx descriptors
\arg ENET_DMA_RX: DMA Rx descriptors
@@ -2288,18 +2331,18 @@ void enet_ptp_enhanced_descriptors_chain_init(enet_dmadirection_enum direction)
uint32_t desc_status = 0U, desc_bufsize = 0U;
enet_descriptors_struct *desc, *desc_tab;
uint8_t *buf;
-
+
/* if want to initialize DMA Tx descriptors */
if (ENET_DMA_TX == direction){
/* save a copy of the DMA Tx descriptors */
desc_tab = txdesc_tab;
buf = &tx_buff[0][0];
count = ENET_TXBUF_NUM;
- maxsize = ENET_TXBUF_SIZE;
-
+ maxsize = ENET_TXBUF_SIZE;
+
/* select chain mode, and enable transmit timestamp function */
desc_status = ENET_TDES0_TCHM | ENET_TDES0_TTSEN;
-
+
/* configure DMA Tx descriptor table address register */
ENET_DMA_TDTADDR = (uint32_t)desc_tab;
dma_current_txdesc = desc_tab;
@@ -2309,43 +2352,43 @@ void enet_ptp_enhanced_descriptors_chain_init(enet_dmadirection_enum direction)
desc_tab = rxdesc_tab;
buf = &rx_buff[0][0];
count = ENET_RXBUF_NUM;
- maxsize = ENET_RXBUF_SIZE;
-
+ maxsize = ENET_RXBUF_SIZE;
+
/* enable receiving */
desc_status = ENET_RDES0_DAV;
/* select receive chained mode and set buffer1 size */
desc_bufsize = ENET_RDES1_RCHM | (uint32_t)ENET_RXBUF_SIZE;
-
+
/* configure DMA Rx descriptor table address register */
ENET_DMA_RDTADDR = (uint32_t)desc_tab;
- dma_current_rxdesc = desc_tab;
+ dma_current_rxdesc = desc_tab;
}
-
- /* configuration each descriptor */
+
+ /* configuration each descriptor */
for(num = 0U; num < count; num++){
/* get the pointer to the next descriptor of the descriptor table */
desc = desc_tab + num;
/* configure descriptors */
- desc->status = desc_status;
+ desc->status = desc_status;
desc->control_buffer_size = desc_bufsize;
desc->buffer1_addr = (uint32_t)(&buf[num * maxsize]);
-
+
/* if is not the last descriptor */
if(num < (count - 1U)){
/* configure the next descriptor address */
desc->buffer2_next_desc_addr = (uint32_t)(desc_tab + num + 1U);
}else{
- /* when it is the last descriptor, the next descriptor address
- equals to first descriptor address in descriptor table */
- desc->buffer2_next_desc_addr = (uint32_t)desc_tab;
+ /* when it is the last descriptor, the next descriptor address
+ equals to first descriptor address in descriptor table */
+ desc->buffer2_next_desc_addr = (uint32_t)desc_tab;
}
- }
+ }
}
/*!
\brief initialize the DMA Tx/Rx descriptors's parameters in enhanced ring mode with ptp function
- \param[in] direction: the descriptors which users want to init, refer to enet_dmadirection_enum,
+ \param[in] direction: the descriptors which users want to init, refer to enet_dmadirection_enum
only one parameter can be selected which is shown as below
\arg ENET_DMA_TX: DMA Tx descriptors
\arg ENET_DMA_RX: DMA Rx descriptors
@@ -2358,23 +2401,23 @@ void enet_ptp_enhanced_descriptors_ring_init(enet_dmadirection_enum direction)
uint32_t desc_status = 0U, desc_bufsize = 0U;
enet_descriptors_struct *desc;
enet_descriptors_struct *desc_tab;
- uint8_t *buf;
-
+ uint8_t *buf;
+
/* configure descriptor skip length */
ENET_DMA_BCTL &= ~ENET_DMA_BCTL_DPSL;
ENET_DMA_BCTL |= DMA_BCTL_DPSL(0);
-
+
/* if want to initialize DMA Tx descriptors */
if (ENET_DMA_TX == direction){
/* save a copy of the DMA Tx descriptors */
desc_tab = txdesc_tab;
buf = &tx_buff[0][0];
count = ENET_TXBUF_NUM;
- maxsize = ENET_TXBUF_SIZE;
+ maxsize = ENET_TXBUF_SIZE;
/* select ring mode, and enable transmit timestamp function */
desc_status = ENET_TDES0_TTSEN;
-
+
/* configure DMA Tx descriptor table address register */
ENET_DMA_TDTADDR = (uint32_t)desc_tab;
dma_current_txdesc = desc_tab;
@@ -2384,43 +2427,43 @@ void enet_ptp_enhanced_descriptors_ring_init(enet_dmadirection_enum direction)
desc_tab = rxdesc_tab;
buf = &rx_buff[0][0];
count = ENET_RXBUF_NUM;
- maxsize = ENET_RXBUF_SIZE;
-
+ maxsize = ENET_RXBUF_SIZE;
+
/* enable receiving */
desc_status = ENET_RDES0_DAV;
/* set buffer1 size */
desc_bufsize = ENET_RXBUF_SIZE;
-
+
/* configure DMA Rx descriptor table address register */
ENET_DMA_RDTADDR = (uint32_t)desc_tab;
- dma_current_rxdesc = desc_tab;
+ dma_current_rxdesc = desc_tab;
}
-
- /* configure each descriptor */
+
+ /* configure each descriptor */
for(num=0U; num < count; num++){
/* get the pointer to the next descriptor of the descriptor table */
desc = desc_tab + num;
/* configure descriptors */
- desc->status = desc_status;
- desc->control_buffer_size = desc_bufsize;
- desc->buffer1_addr = (uint32_t)(&buf[num * maxsize]);
-
+ desc->status = desc_status;
+ desc->control_buffer_size = desc_bufsize;
+ desc->buffer1_addr = (uint32_t)(&buf[num * maxsize]);
+
/* when it is the last descriptor */
if(num == (count - 1U)){
if (ENET_DMA_TX == direction){
- /* configure transmit end of ring mode */
+ /* configure transmit end of ring mode */
desc->status |= ENET_TDES0_TERM;
}else{
/* configure receive end of ring mode */
desc->control_buffer_size |= ENET_RDES1_RERM;
}
}
- }
+ }
}
/*!
- \brief receive a packet data with timestamp values to application buffer, when the DMA is in enhanced mode
+ \brief receive a packet data with timestamp values to application buffer, when the DMA is in enhanced mode
\param[in] bufsize: the size of buffer which is the parameter in function
\param[out] buffer: pointer to the application buffer
note -- if the input is NULL, user should copy data in application by himself
@@ -2433,26 +2476,26 @@ ErrStatus enet_ptpframe_receive_enhanced_mode(uint8_t *buffer, uint32_t bufsize,
uint32_t offset = 0U, size = 0U;
uint32_t timeout = 0U;
uint32_t rdes0_tsv_flag;
-
+
/* the descriptor is busy due to own by the DMA */
if((uint32_t)RESET != (dma_current_rxdesc->status & ENET_RDES0_DAV)){
- return ERROR;
+ return ERROR;
}
-
+
/* if buffer pointer is null, indicates that users has copied data in application */
if(NULL != buffer){
- /* if no error occurs, and the frame uses only one descriptor */
- if(((uint32_t)RESET == (dma_current_rxdesc->status & ENET_RDES0_ERRS)) &&
- ((uint32_t)RESET != (dma_current_rxdesc->status & ENET_RDES0_LDES)) &&
- ((uint32_t)RESET != (dma_current_rxdesc->status & ENET_RDES0_FDES))){
+ /* if no error occurs, and the frame uses only one descriptor */
+ if(((uint32_t)RESET == (dma_current_rxdesc->status & ENET_RDES0_ERRS)) &&
+ ((uint32_t)RESET != (dma_current_rxdesc->status & ENET_RDES0_LDES)) &&
+ ((uint32_t)RESET != (dma_current_rxdesc->status & ENET_RDES0_FDES))){
/* get the frame length except CRC */
size = GET_RDES0_FRML(dma_current_rxdesc->status) - 4U;
- /* if is a type frame, and CRC is not included in forwarding frame */
+ /* if is a type frame, and CRC is not included in forwarding frame */
if((RESET != (ENET_MAC_CFG & ENET_MAC_CFG_TFCD)) && (RESET != (dma_current_rxdesc->status & ENET_RDES0_FRMT))){
size = size + 4U;
}
-
+
/* to avoid situation that the frame size exceeds the buffer length */
if(size > bufsize){
return ERROR;
@@ -2465,22 +2508,22 @@ ErrStatus enet_ptpframe_receive_enhanced_mode(uint8_t *buffer, uint32_t bufsize,
}else{
return ERROR;
}
- }
-
+ }
+
/* if timestamp pointer is null, indicates that users don't care timestamp in application */
if(NULL != timestamp){
/* wait for ENET_RDES0_TSV flag to be set, the timestamp value is taken and
write to the RDES6 and RDES7 */
- do{
+ do{
rdes0_tsv_flag = (dma_current_rxdesc->status & ENET_RDES0_TSV);
timeout++;
}while ((RESET == rdes0_tsv_flag) && (timeout < ENET_DELAY_TO));
-
+
/* return ERROR due to timeout */
if(ENET_DELAY_TO == timeout){
return ERROR;
}
-
+
/* clear the ENET_RDES0_TSV flag */
dma_current_rxdesc->status &= ~ENET_RDES0_TSV;
/* get the timestamp value of the received frame */
@@ -2490,7 +2533,7 @@ ErrStatus enet_ptpframe_receive_enhanced_mode(uint8_t *buffer, uint32_t bufsize,
/* enable reception, descriptor is owned by DMA */
dma_current_rxdesc->status = ENET_RDES0_DAV;
-
+
/* check Rx buffer unavailable flag status */
if ((uint32_t)RESET != (ENET_DMA_STAT & ENET_DMA_STAT_RBU)){
/* Clear RBU flag */
@@ -2498,33 +2541,32 @@ ErrStatus enet_ptpframe_receive_enhanced_mode(uint8_t *buffer, uint32_t bufsize,
/* resume DMA reception by writing to the RPEN register*/
ENET_DMA_RPEN = 0;
}
-
- /* update the current RxDMA descriptor pointer to the next decriptor in RxDMA decriptor table */
+
+ /* update the current RxDMA descriptor pointer to the next decriptor in RxDMA decriptor table */
/* chained mode */
- if((uint32_t)RESET != (dma_current_rxdesc->control_buffer_size & ENET_RDES1_RCHM)){
- dma_current_rxdesc = (enet_descriptors_struct*) (dma_current_rxdesc->buffer2_next_desc_addr);
- }else{
- /* ring mode */
+ if((uint32_t)RESET != (dma_current_rxdesc->control_buffer_size & ENET_RDES1_RCHM)){
+ dma_current_rxdesc = (enet_descriptors_struct*) (dma_current_rxdesc->buffer2_next_desc_addr);
+ }else{
+ /* ring mode */
if((uint32_t)RESET != (dma_current_rxdesc->control_buffer_size & ENET_RDES1_RERM)){
/* if is the last descriptor in table, the next descriptor is the table header */
- dma_current_rxdesc = (enet_descriptors_struct*) (ENET_DMA_RDTADDR);
- }else{
+ dma_current_rxdesc = (enet_descriptors_struct*) (ENET_DMA_RDTADDR);
+ }else{
/* the next descriptor is the current address, add the descriptor size, and descriptor skip length */
- dma_current_rxdesc = (enet_descriptors_struct*) ((uint32_t)dma_current_rxdesc + ETH_DMARXDESC_SIZE + GET_DMA_BCTL_DPSL(ENET_DMA_BCTL));
+ dma_current_rxdesc = (enet_descriptors_struct*) ((uint32_t)dma_current_rxdesc + ETH_DMARXDESC_SIZE + GET_DMA_BCTL_DPSL(ENET_DMA_BCTL));
}
}
-
+
return SUCCESS;
}
/*!
- \brief send data with timestamp values in application buffer as a transmit packet, when the DMA is in enhanced mode
+ \brief send data with timestamp values in application buffer as a transmit packet, when the DMA is in enhanced mode
\param[in] buffer: pointer on the application buffer
note -- if the input is NULL, user should copy data in application by himself
\param[in] length: the length of frame data to be transmitted
\param[out] timestamp: pointer to the table which stores the timestamp high and low
note -- if the input is NULL, timestamp is ignored
- \param[out] none
\retval ErrStatus: SUCCESS or ERROR
*/
ErrStatus enet_ptpframe_transmit_enhanced_mode(uint8_t *buffer, uint32_t length, uint32_t timestamp[])
@@ -2532,17 +2574,17 @@ ErrStatus enet_ptpframe_transmit_enhanced_mode(uint8_t *buffer, uint32_t length,
uint32_t offset = 0;
uint32_t dma_tbu_flag, dma_tu_flag;
uint32_t tdes0_ttmss_flag;
- uint32_t timeout = 0;
-
+ uint32_t timeout = 0;
+
/* the descriptor is busy due to own by the DMA */
if((uint32_t)RESET != (dma_current_txdesc->status & ENET_TDES0_DAV)){
return ERROR;
}
-
+
/* only frame length no more than ENET_MAX_FRAME_SIZE is allowed */
if(length > ENET_MAX_FRAME_SIZE){
return ERROR;
- }
+ }
/* if buffer pointer is null, indicates that users has handled data in application */
if(NULL != buffer){
@@ -2553,22 +2595,22 @@ ErrStatus enet_ptpframe_transmit_enhanced_mode(uint8_t *buffer, uint32_t length,
}
/* set the frame length */
dma_current_txdesc->control_buffer_size = length;
- /* set the segment of frame, frame is transmitted in one descriptor */
+ /* set the segment of frame, frame is transmitted in one descriptor */
dma_current_txdesc->status |= ENET_TDES0_LSG | ENET_TDES0_FSG;
/* enable the DMA transmission */
dma_current_txdesc->status |= ENET_TDES0_DAV;
/* check Tx buffer unavailable flag status */
- dma_tbu_flag = (ENET_DMA_STAT & ENET_DMA_STAT_TBU);
+ dma_tbu_flag = (ENET_DMA_STAT & ENET_DMA_STAT_TBU);
dma_tu_flag = (ENET_DMA_STAT & ENET_DMA_STAT_TU);
-
+
if ((RESET != dma_tbu_flag) || (RESET != dma_tu_flag)){
/* Clear TBU and TU flag */
ENET_DMA_STAT = (dma_tbu_flag | dma_tu_flag);
/* resume DMA transmission by writing to the TPEN register*/
ENET_DMA_TPEN = 0;
}
-
+
/* if timestamp pointer is null, indicates that users don't care timestamp in application */
if(NULL != timestamp){
/* wait for ENET_TDES0_TTMSS flag to be set, a timestamp was captured */
@@ -2576,12 +2618,12 @@ ErrStatus enet_ptpframe_transmit_enhanced_mode(uint8_t *buffer, uint32_t length,
tdes0_ttmss_flag = (dma_current_txdesc->status & ENET_TDES0_TTMSS);
timeout++;
}while((RESET == tdes0_ttmss_flag) && (timeout < ENET_DELAY_TO));
-
+
/* return ERROR due to timeout */
if(ENET_DELAY_TO == timeout){
return ERROR;
}
-
+
/* clear the ENET_TDES0_TTMSS flag */
dma_current_txdesc->status &= ~ENET_TDES0_TTMSS;
/* get the timestamp value of the transmit frame */
@@ -2589,16 +2631,16 @@ ErrStatus enet_ptpframe_transmit_enhanced_mode(uint8_t *buffer, uint32_t length,
timestamp[1] = dma_current_txdesc->timestamp_high;
}
- /* update the current TxDMA descriptor pointer to the next decriptor in TxDMA decriptor table*/
+ /* update the current TxDMA descriptor pointer to the next decriptor in TxDMA decriptor table*/
/* chained mode */
- if((uint32_t)RESET != (dma_current_txdesc->status & ENET_TDES0_TCHM)){
- dma_current_txdesc = (enet_descriptors_struct*) (dma_current_txdesc->buffer2_next_desc_addr);
+ if((uint32_t)RESET != (dma_current_txdesc->status & ENET_TDES0_TCHM)){
+ dma_current_txdesc = (enet_descriptors_struct*) (dma_current_txdesc->buffer2_next_desc_addr);
}else{
- /* ring mode */
+ /* ring mode */
if((uint32_t)RESET != (dma_current_txdesc->status & ENET_TDES0_TERM)){
/* if is the last descriptor in table, the next descriptor is the table header */
- dma_current_txdesc = (enet_descriptors_struct*) (ENET_DMA_TDTADDR);
- }else{
+ dma_current_txdesc = (enet_descriptors_struct*) (ENET_DMA_TDTADDR);
+ }else{
/* the next descriptor is the current address, add the descriptor size, and descriptor skip length */
dma_current_txdesc = (enet_descriptors_struct*) ((uint32_t)dma_current_txdesc + ETH_DMATXDESC_SIZE + GET_DMA_BCTL_DPSL(ENET_DMA_BCTL));
}
@@ -2622,7 +2664,7 @@ void enet_desc_select_normal_mode(void)
/*!
\brief initialize the DMA Tx/Rx descriptors's parameters in normal chain mode with PTP function
- \param[in] direction: the descriptors which users want to init, refer to enet_dmadirection_enum,
+ \param[in] direction: the descriptors which users want to init, refer to enet_dmadirection_enum
only one parameter can be selected which is shown as below
\arg ENET_DMA_TX: DMA Tx descriptors
\arg ENET_DMA_RX: DMA Rx descriptors
@@ -2636,18 +2678,18 @@ void enet_ptp_normal_descriptors_chain_init(enet_dmadirection_enum direction, en
uint32_t desc_status = 0U, desc_bufsize = 0U;
enet_descriptors_struct *desc, *desc_tab;
uint8_t *buf;
-
+
/* if want to initialize DMA Tx descriptors */
if (ENET_DMA_TX == direction){
/* save a copy of the DMA Tx descriptors */
desc_tab = txdesc_tab;
buf = &tx_buff[0][0];
count = ENET_TXBUF_NUM;
- maxsize = ENET_TXBUF_SIZE;
-
+ maxsize = ENET_TXBUF_SIZE;
+
/* select chain mode, and enable transmit timestamp function */
desc_status = ENET_TDES0_TCHM | ENET_TDES0_TTSEN;
-
+
/* configure DMA Tx descriptor table address register */
ENET_DMA_TDTADDR = (uint32_t)desc_tab;
dma_current_txdesc = desc_tab;
@@ -2658,50 +2700,50 @@ void enet_ptp_normal_descriptors_chain_init(enet_dmadirection_enum direction, en
desc_tab = rxdesc_tab;
buf = &rx_buff[0][0];
count = ENET_RXBUF_NUM;
- maxsize = ENET_RXBUF_SIZE;
-
+ maxsize = ENET_RXBUF_SIZE;
+
/* enable receiving */
desc_status = ENET_RDES0_DAV;
/* select receive chained mode and set buffer1 size */
desc_bufsize = ENET_RDES1_RCHM | (uint32_t)ENET_RXBUF_SIZE;
-
+
/* configure DMA Rx descriptor table address register */
ENET_DMA_RDTADDR = (uint32_t)desc_tab;
dma_current_rxdesc = desc_tab;
- dma_current_ptp_rxdesc = desc_ptptab;
+ dma_current_ptp_rxdesc = desc_ptptab;
}
-
- /* configure each descriptor */
+
+ /* configure each descriptor */
for(num = 0U; num < count; num++){
/* get the pointer to the next descriptor of the descriptor table */
desc = desc_tab + num;
/* configure descriptors */
- desc->status = desc_status;
+ desc->status = desc_status;
desc->control_buffer_size = desc_bufsize;
desc->buffer1_addr = (uint32_t)(&buf[num * maxsize]);
-
+
/* if is not the last descriptor */
if(num < (count - 1U)){
/* configure the next descriptor address */
desc->buffer2_next_desc_addr = (uint32_t)(desc_tab + num + 1U);
}else{
- /* when it is the last descriptor, the next descriptor address
- equals to first descriptor address in descriptor table */
- desc->buffer2_next_desc_addr = (uint32_t)desc_tab;
+ /* when it is the last descriptor, the next descriptor address
+ equals to first descriptor address in descriptor table */
+ desc->buffer2_next_desc_addr = (uint32_t)desc_tab;
}
/* set desc_ptptab equal to desc_tab */
(&desc_ptptab[num])->buffer1_addr = desc->buffer1_addr;
(&desc_ptptab[num])->buffer2_next_desc_addr = desc->buffer2_next_desc_addr;
- }
- /* when it is the last ptp descriptor, preserve the first descriptor
+ }
+ /* when it is the last ptp descriptor, preserve the first descriptor
address of desc_ptptab in ptp descriptor status */
(&desc_ptptab[num-1U])->status = (uint32_t)desc_ptptab;
}
/*!
\brief initialize the DMA Tx/Rx descriptors's parameters in normal ring mode with PTP function
- \param[in] direction: the descriptors which users want to init, refer to enet_dmadirection_enum,
+ \param[in] direction: the descriptors which users want to init, refer to enet_dmadirection_enum
only one parameter can be selected which is shown as below
\arg ENET_DMA_TX: DMA Tx descriptors
\arg ENET_DMA_RX: DMA Rx descriptors
@@ -2719,18 +2761,18 @@ void enet_ptp_normal_descriptors_ring_init(enet_dmadirection_enum direction, ene
/* configure descriptor skip length */
ENET_DMA_BCTL &= ~ENET_DMA_BCTL_DPSL;
ENET_DMA_BCTL |= DMA_BCTL_DPSL(0);
-
+
/* if want to initialize DMA Tx descriptors */
if (ENET_DMA_TX == direction){
/* save a copy of the DMA Tx descriptors */
desc_tab = txdesc_tab;
buf = &tx_buff[0][0];
count = ENET_TXBUF_NUM;
- maxsize = ENET_TXBUF_SIZE;
-
+ maxsize = ENET_TXBUF_SIZE;
+
/* select ring mode, and enable transmit timestamp function */
desc_status = ENET_TDES0_TTSEN;
-
+
/* configure DMA Tx descriptor table address register */
ENET_DMA_TDTADDR = (uint32_t)desc_tab;
dma_current_txdesc = desc_tab;
@@ -2741,33 +2783,33 @@ void enet_ptp_normal_descriptors_ring_init(enet_dmadirection_enum direction, ene
desc_tab = rxdesc_tab;
buf = &rx_buff[0][0];
count = ENET_RXBUF_NUM;
- maxsize = ENET_RXBUF_SIZE;
-
+ maxsize = ENET_RXBUF_SIZE;
+
/* enable receiving */
desc_status = ENET_RDES0_DAV;
/* select receive ring mode and set buffer1 size */
desc_bufsize = (uint32_t)ENET_RXBUF_SIZE;
-
+
/* configure DMA Rx descriptor table address register */
ENET_DMA_RDTADDR = (uint32_t)desc_tab;
dma_current_rxdesc = desc_tab;
- dma_current_ptp_rxdesc = desc_ptptab;
+ dma_current_ptp_rxdesc = desc_ptptab;
}
-
- /* configure each descriptor */
+
+ /* configure each descriptor */
for(num = 0U; num < count; num++){
/* get the pointer to the next descriptor of the descriptor table */
desc = desc_tab + num;
/* configure descriptors */
- desc->status = desc_status;
+ desc->status = desc_status;
desc->control_buffer_size = desc_bufsize;
desc->buffer1_addr = (uint32_t)(&buf[num * maxsize]);
-
+
/* when it is the last descriptor */
if(num == (count - 1U)){
if (ENET_DMA_TX == direction){
- /* configure transmit end of ring mode */
+ /* configure transmit end of ring mode */
desc->status |= ENET_TDES0_TERM;
}else{
/* configure receive end of ring mode */
@@ -2777,43 +2819,43 @@ void enet_ptp_normal_descriptors_ring_init(enet_dmadirection_enum direction, ene
/* set desc_ptptab equal to desc_tab */
(&desc_ptptab[num])->buffer1_addr = desc->buffer1_addr;
(&desc_ptptab[num])->buffer2_next_desc_addr = desc->buffer2_next_desc_addr;
- }
- /* when it is the last ptp descriptor, preserve the first descriptor
+ }
+ /* when it is the last ptp descriptor, preserve the first descriptor
address of desc_ptptab in ptp descriptor status */
(&desc_ptptab[num-1U])->status = (uint32_t)desc_ptptab;
}
/*!
- \brief receive a packet data with timestamp values to application buffer, when the DMA is in normal mode
+ \brief receive a packet data with timestamp values to application buffer, when the DMA is in normal mode
\param[in] bufsize: the size of buffer which is the parameter in function
- \param[out] timestamp: pointer to the table which stores the timestamp high and low
\param[out] buffer: pointer to the application buffer
note -- if the input is NULL, user should copy data in application by himself
+ \param[out] timestamp: pointer to the table which stores the timestamp high and low
\retval ErrStatus: SUCCESS or ERROR
*/
ErrStatus enet_ptpframe_receive_normal_mode(uint8_t *buffer, uint32_t bufsize, uint32_t timestamp[])
{
uint32_t offset = 0U, size = 0U;
-
+
/* the descriptor is busy due to own by the DMA */
if((uint32_t)RESET != (dma_current_rxdesc->status & ENET_RDES0_DAV)){
return ERROR;
}
-
+
/* if buffer pointer is null, indicates that users has copied data in application */
if(NULL != buffer){
/* if no error occurs, and the frame uses only one descriptor */
if(((uint32_t)RESET == (dma_current_rxdesc->status & ENET_RDES0_ERRS)) &&
((uint32_t)RESET != (dma_current_rxdesc->status & ENET_RDES0_LDES)) &&
((uint32_t)RESET != (dma_current_rxdesc->status & ENET_RDES0_FDES))){
-
+
/* get the frame length except CRC */
size = GET_RDES0_FRML(dma_current_rxdesc->status) - 4U;
/* if is a type frame, and CRC is not included in forwarding frame */
if((RESET != (ENET_MAC_CFG & ENET_MAC_CFG_TFCD)) && (RESET != (dma_current_rxdesc->status & ENET_RDES0_FRMT))){
size = size + 4U;
}
-
+
/* to avoid situation that the frame size exceeds the buffer length */
if(size > bufsize){
return ERROR;
@@ -2823,7 +2865,7 @@ ErrStatus enet_ptpframe_receive_normal_mode(uint8_t *buffer, uint32_t bufsize, u
for(offset = 0U; offset < size; offset++){
(*(buffer + offset)) = (*(__IO uint8_t *)(uint32_t)((dma_current_ptp_rxdesc->buffer1_addr) + offset));
}
-
+
}else{
return ERROR;
}
@@ -2834,10 +2876,10 @@ ErrStatus enet_ptpframe_receive_normal_mode(uint8_t *buffer, uint32_t bufsize, u
dma_current_rxdesc->buffer1_addr = dma_current_ptp_rxdesc ->buffer1_addr ;
dma_current_rxdesc->buffer2_next_desc_addr = dma_current_ptp_rxdesc ->buffer2_next_desc_addr;
-
+
/* enable reception, descriptor is owned by DMA */
dma_current_rxdesc->status = ENET_RDES0_DAV;
-
+
/* check Rx buffer unavailable flag status */
if ((uint32_t)RESET != (ENET_DMA_STAT & ENET_DMA_STAT_RBU)){
/* clear RBU flag */
@@ -2845,9 +2887,9 @@ ErrStatus enet_ptpframe_receive_normal_mode(uint8_t *buffer, uint32_t bufsize, u
/* resume DMA reception by writing to the RPEN register*/
ENET_DMA_RPEN = 0U;
}
-
- /* update the current RxDMA descriptor pointer to the next decriptor in RxDMA decriptor table */
+
+ /* update the current RxDMA descriptor pointer to the next decriptor in RxDMA decriptor table */
/* chained mode */
if((uint32_t)RESET != (dma_current_rxdesc->control_buffer_size & ENET_RDES1_RCHM)){
dma_current_rxdesc = (enet_descriptors_struct*) (dma_current_ptp_rxdesc->buffer2_next_desc_addr);
@@ -2860,16 +2902,16 @@ ErrStatus enet_ptpframe_receive_normal_mode(uint8_t *buffer, uint32_t bufsize, u
dma_current_ptp_rxdesc++;
}
}else{
- /* ring mode */
+ /* ring mode */
if((uint32_t)RESET != (dma_current_rxdesc->control_buffer_size & ENET_RDES1_RERM)){
/* if is the last descriptor in table, the next descriptor is the table header */
dma_current_rxdesc = (enet_descriptors_struct*) (ENET_DMA_RDTADDR);
/* RDES2 and RDES3 will not be covered by buffer address, so do not need to preserve a new table,
use the same table with RxDMA descriptor */
- dma_current_ptp_rxdesc = (enet_descriptors_struct*) (dma_current_ptp_rxdesc->status);
+ dma_current_ptp_rxdesc = (enet_descriptors_struct*) (dma_current_ptp_rxdesc->status);
}else{
/* the next descriptor is the current address, add the descriptor size, and descriptor skip length */
- dma_current_rxdesc = (enet_descriptors_struct*) (uint32_t)((uint32_t)dma_current_rxdesc + ETH_DMARXDESC_SIZE + GET_DMA_BCTL_DPSL(ENET_DMA_BCTL));
+ dma_current_rxdesc = (enet_descriptors_struct*) (uint32_t)((uint32_t)dma_current_rxdesc + ETH_DMARXDESC_SIZE + GET_DMA_BCTL_DPSL(ENET_DMA_BCTL));
dma_current_ptp_rxdesc ++;
}
}
@@ -2878,7 +2920,7 @@ ErrStatus enet_ptpframe_receive_normal_mode(uint8_t *buffer, uint32_t bufsize, u
}
/*!
- \brief send data with timestamp values in application buffer as a transmit packet, when the DMA is in normal mode
+ \brief send data with timestamp values in application buffer as a transmit packet, when the DMA is in normal mode
\param[in] buffer: pointer on the application buffer
note -- if the input is NULL, user should copy data in application by himself
\param[in] length: the length of frame data to be transmitted
@@ -2889,8 +2931,8 @@ ErrStatus enet_ptpframe_receive_normal_mode(uint8_t *buffer, uint32_t bufsize, u
ErrStatus enet_ptpframe_transmit_normal_mode(uint8_t *buffer, uint32_t length, uint32_t timestamp[])
{
uint32_t offset = 0U, timeout = 0U;
- uint32_t dma_tbu_flag, dma_tu_flag, tdes0_ttmss_flag;
-
+ uint32_t dma_tbu_flag, dma_tu_flag, tdes0_ttmss_flag;
+
/* the descriptor is busy due to own by the DMA */
if((uint32_t)RESET != (dma_current_txdesc->status & ENET_TDES0_DAV)){
return ERROR;
@@ -2900,7 +2942,7 @@ ErrStatus enet_ptpframe_transmit_normal_mode(uint8_t *buffer, uint32_t length, u
if(length > ENET_MAX_FRAME_SIZE){
return ERROR;
}
-
+
/* if buffer pointer is null, indicates that users has handled data in application */
if(NULL != buffer){
/* copy frame data from application buffer to Tx buffer */
@@ -2914,31 +2956,31 @@ ErrStatus enet_ptpframe_transmit_normal_mode(uint8_t *buffer, uint32_t length, u
dma_current_txdesc->status |= ENET_TDES0_LSG | ENET_TDES0_FSG;
/* enable the DMA transmission */
dma_current_txdesc->status |= ENET_TDES0_DAV;
-
+
/* check Tx buffer unavailable flag status */
- dma_tbu_flag = (ENET_DMA_STAT & ENET_DMA_STAT_TBU);
+ dma_tbu_flag = (ENET_DMA_STAT & ENET_DMA_STAT_TBU);
dma_tu_flag = (ENET_DMA_STAT & ENET_DMA_STAT_TU);
-
+
if((RESET != dma_tbu_flag) || (RESET != dma_tu_flag)){
/* clear TBU and TU flag */
ENET_DMA_STAT = (dma_tbu_flag | dma_tu_flag);
/* resume DMA transmission by writing to the TPEN register*/
ENET_DMA_TPEN = 0U;
}
-
+
/* if timestamp pointer is null, indicates that users don't care timestamp in application */
if(NULL != timestamp){
/* wait for ENET_TDES0_TTMSS flag to be set, a timestamp was captured */
- do{
+ do{
tdes0_ttmss_flag = (dma_current_txdesc->status & ENET_TDES0_TTMSS);
timeout++;
}while((RESET == tdes0_ttmss_flag) && (timeout < ENET_DELAY_TO));
-
+
/* return ERROR due to timeout */
if(ENET_DELAY_TO == timeout){
return ERROR;
- }
-
+ }
+
/* clear the ENET_TDES0_TTMSS flag */
dma_current_txdesc->status &= ~ENET_TDES0_TTMSS;
/* get the timestamp value of the transmit frame */
@@ -2948,12 +2990,12 @@ ErrStatus enet_ptpframe_transmit_normal_mode(uint8_t *buffer, uint32_t length, u
dma_current_txdesc->buffer1_addr = dma_current_ptp_txdesc ->buffer1_addr ;
dma_current_txdesc->buffer2_next_desc_addr = dma_current_ptp_txdesc ->buffer2_next_desc_addr;
- /* update the current TxDMA descriptor pointer to the next decriptor in TxDMA decriptor table */
+ /* update the current TxDMA descriptor pointer to the next decriptor in TxDMA decriptor table */
/* chained mode */
- if((uint32_t)RESET != (dma_current_txdesc->status & ENET_TDES0_TCHM)){
+ if((uint32_t)RESET != (dma_current_txdesc->status & ENET_TDES0_TCHM)){
dma_current_txdesc = (enet_descriptors_struct*) (dma_current_ptp_txdesc->buffer2_next_desc_addr);
/* if it is the last ptp descriptor */
- if(0U != dma_current_ptp_txdesc->status){
+ if(0U != dma_current_ptp_txdesc->status){
/* pointer back to the first ptp descriptor address in the desc_ptptab list address */
dma_current_ptp_txdesc = (enet_descriptors_struct*) (dma_current_ptp_txdesc->status);
}else{
@@ -2961,17 +3003,17 @@ ErrStatus enet_ptpframe_transmit_normal_mode(uint8_t *buffer, uint32_t length, u
dma_current_ptp_txdesc++;
}
}else{
- /* ring mode */
+ /* ring mode */
if((uint32_t)RESET != (dma_current_txdesc->status & ENET_TDES0_TERM)){
/* if is the last descriptor in table, the next descriptor is the table header */
- dma_current_txdesc = (enet_descriptors_struct*) (ENET_DMA_TDTADDR);
+ dma_current_txdesc = (enet_descriptors_struct*) (ENET_DMA_TDTADDR);
/* TDES2 and TDES3 will not be covered by buffer address, so do not need to preserve a new table,
use the same table with TxDMA descriptor */
dma_current_ptp_txdesc = (enet_descriptors_struct*) (dma_current_ptp_txdesc->status);
}else{
/* the next descriptor is the current address, add the descriptor size, and descriptor skip length */
- dma_current_txdesc = (enet_descriptors_struct*) (uint32_t)((uint32_t)dma_current_txdesc + ETH_DMATXDESC_SIZE + GET_DMA_BCTL_DPSL(ENET_DMA_BCTL));
- dma_current_ptp_txdesc ++;
+ dma_current_txdesc = (enet_descriptors_struct*) (uint32_t)((uint32_t)dma_current_txdesc + ETH_DMATXDESC_SIZE + GET_DMA_BCTL_DPSL(ENET_DMA_BCTL));
+ dma_current_ptp_txdesc ++;
}
}
return SUCCESS;
@@ -2980,7 +3022,7 @@ ErrStatus enet_ptpframe_transmit_normal_mode(uint8_t *buffer, uint32_t length, u
#endif /* SELECT_DESCRIPTORS_ENHANCED_MODE */
/*!
- \brief wakeup frame filter register pointer reset
+ \brief wakeup frame filter register pointer reset
\param[in] none
\param[out] none
\retval none
@@ -2991,7 +3033,7 @@ void enet_wum_filter_register_pointer_reset(void)
}
/*!
- \brief set the remote wakeup frame registers
+ \brief set the remote wakeup frame registers
\param[in] pdata: pointer to buffer data which is written to remote wakeup frame registers (8 words total)
\param[out] none
\retval none
@@ -2999,7 +3041,7 @@ void enet_wum_filter_register_pointer_reset(void)
void enet_wum_filter_config(uint32_t pdata[])
{
uint32_t num = 0U;
-
+
/* configure ENET_MAC_RWFF register */
for(num = 0U; num < ETH_WAKEUP_REGISTER_LENGTH; num++){
ENET_MAC_RWFF = pdata[num];
@@ -3007,8 +3049,9 @@ void enet_wum_filter_config(uint32_t pdata[])
}
/*!
- \brief enable wakeup management features
- \param[in] feature: one or more parameters can be selected which are shown as below
+ \brief enable wakeup management features
+ \param[in] feature: the wake up type which is selected
+ one or more parameters can be selected which are shown as below
\arg ENET_WUM_POWER_DOWN: power down mode
\arg ENET_WUM_MAGIC_PACKET_FRAME: enable a wakeup event due to magic packet reception
\arg ENET_WUM_WAKE_UP_FRAME: enable a wakeup event due to wakeup frame reception
@@ -3022,8 +3065,9 @@ void enet_wum_feature_enable(uint32_t feature)
}
/*!
- \brief disable wakeup management features
- \param[in] feature: one or more parameters can be selected which are shown as below
+ \brief disable wakeup management features
+ \param[in] feature: the wake up type which is selected
+ one or more parameters can be selected which are shown as below
\arg ENET_WUM_MAGIC_PACKET_FRAME: enable a wakeup event due to magic packet reception
\arg ENET_WUM_WAKE_UP_FRAME: enable a wakeup event due to wakeup frame reception
\arg ENET_WUM_GLOBAL_UNICAST: any received unicast frame passed filter is considered to be a wakeup frame
@@ -3036,8 +3080,8 @@ void enet_wum_feature_disable(uint32_t feature)
}
/*!
- \brief reset the MAC statistics counters
- \param[in] none
+ \brief reset the MAC statistics counters
+ \param[in] none
\param[out] none
\retval none
*/
@@ -3049,7 +3093,8 @@ void enet_msc_counters_reset(void)
/*!
\brief enable the MAC statistics counter features
- \param[in] feature: one or more parameters can be selected which are shown as below
+ \param[in] feature: the feature of MAC statistics counter
+ one or more parameters can be selected which are shown as below
\arg ENET_MSC_COUNTER_STOP_ROLLOVER: counter stop rollover
\arg ENET_MSC_RESET_ON_READ: reset on read
\arg ENET_MSC_COUNTERS_FREEZE: MSC counter freeze
@@ -3063,7 +3108,8 @@ void enet_msc_feature_enable(uint32_t feature)
/*!
\brief disable the MAC statistics counter features
- \param[in] feature: one or more parameters can be selected which are shown as below
+ \param[in] feature: the feature of MAC statistics counter
+ one or more parameters can be selected which are shown as below
\arg ENET_MSC_COUNTER_STOP_ROLLOVER: counter stop rollover
\arg ENET_MSC_RESET_ON_READ: reset on read
\arg ENET_MSC_COUNTERS_FREEZE: MSC counter freeze
@@ -3076,8 +3122,8 @@ void enet_msc_feature_disable(uint32_t feature)
}
/*!
- \brief configure MAC statistics counters preset mode
- \param[in] mode: MSC counters preset mode, refer to enet_msc_preset_enum,
+ \brief configure MAC statistics counters preset mode
+ \param[in] mode: MSC counters preset mode, refer to enet_msc_preset_enum
only one parameter can be selected which is shown as below
\arg ENET_MSC_PRESET_NONE: do not preset MSC counter
\arg ENET_MSC_PRESET_HALF: preset all MSC counters to almost-half(0x7FFF FFF0) value
@@ -3092,8 +3138,8 @@ void enet_msc_counters_preset_config(enet_msc_preset_enum mode)
}
/*!
- \brief get MAC statistics counter
- \param[in] counter: MSC counters which is selected, refer to enet_msc_counter_enum,
+ \brief get MAC statistics counter
+ \param[in] counter: MSC counters which is selected, refer to enet_msc_counter_enum
only one parameter can be selected which is shown as below
\arg ENET_MSC_TX_SCCNT: MSC transmitted good frames after a single collision counter
\arg ENET_MSC_TX_MSCCNT: MSC transmitted good frames after more than a single collision counter
@@ -3107,9 +3153,9 @@ void enet_msc_counters_preset_config(enet_msc_preset_enum mode)
uint32_t enet_msc_counters_get(enet_msc_counter_enum counter)
{
uint32_t reval;
-
+
reval = REG32((ENET + (uint32_t)counter));
-
+
return reval;
}
@@ -3153,7 +3199,8 @@ void enet_ptp_feature_disable(uint32_t feature)
/*!
\brief configure the PTP timestamp function
- \param[in] func: only one parameter can be selected which is shown as below
+ \param[in] func: the function of PTP timestamp
+ only one parameter can be selected which is shown as below
\arg ENET_CKNT_ORDINARY: type of ordinary clock node type for timestamp
\arg ENET_CKNT_BOUNDARY: type of boundary clock node type for timestamp
\arg ENET_CKNT_END_TO_END: type of end-to-end transparent clock node type for timestamp
@@ -3168,7 +3215,7 @@ void enet_ptp_feature_disable(uint32_t feature)
\arg ENET_SNOOPING_PTP_VERSION_2: version 2
\arg ENET_SNOOPING_PTP_VERSION_1: version 1
\arg ENET_EVENT_TYPE_MESSAGES_SNAPSHOT: only event type messages are taken snapshot
- \arg ENET_ALL_TYPE_MESSAGES_SNAPSHOT: all type messages are taken snapshot except announce,
+ \arg ENET_ALL_TYPE_MESSAGES_SNAPSHOT: all type messages are taken snapshot except announce,
management and signaling message
\arg ENET_MASTER_NODE_MESSAGE_SNAPSHOT: snapshot is only take for master node message
\arg ENET_SLAVE_NODE_MESSAGE_SNAPSHOT: snapshot is only taken for slave node message
@@ -3189,10 +3236,10 @@ ErrStatus enet_ptp_timestamp_function_config(enet_ptp_function_enum func)
ENET_PTP_TSCTL &= ~ENET_PTP_TSCTL_CKNT;
ENET_PTP_TSCTL |= (uint32_t)func;
break;
- case ENET_PTP_ADDEND_UPDATE:
+ case ENET_PTP_ADDEND_UPDATE:
/* this bit must be read as zero before application set it */
do{
- temp_state = ENET_PTP_TSCTL & ENET_PTP_TSCTL_TMSARU;
+ temp_state = ENET_PTP_TSCTL & ENET_PTP_TSCTL_TMSARU;
timeout++;
}while((RESET != temp_state) && (timeout < ENET_DELAY_TO));
/* return ERROR due to timeout */
@@ -3200,12 +3247,12 @@ ErrStatus enet_ptp_timestamp_function_config(enet_ptp_function_enum func)
enet_state = ERROR;
}else{
ENET_PTP_TSCTL |= ENET_PTP_TSCTL_TMSARU;
- }
+ }
break;
case ENET_PTP_SYSTIME_UPDATE:
/* both the TMSSTU and TMSSTI bits must be read as zero before application set this bit */
do{
- temp_state = ENET_PTP_TSCTL & (ENET_PTP_TSCTL_TMSSTU | ENET_PTP_TSCTL_TMSSTI);
+ temp_state = ENET_PTP_TSCTL & (ENET_PTP_TSCTL_TMSSTU | ENET_PTP_TSCTL_TMSSTI);
timeout++;
}while((RESET != temp_state) && (timeout < ENET_DELAY_TO));
/* return ERROR due to timeout */
@@ -3213,12 +3260,12 @@ ErrStatus enet_ptp_timestamp_function_config(enet_ptp_function_enum func)
enet_state = ERROR;
}else{
ENET_PTP_TSCTL |= ENET_PTP_TSCTL_TMSSTU;
- }
- break;
+ }
+ break;
case ENET_PTP_SYSTIME_INIT:
/* this bit must be read as zero before application set it */
do{
- temp_state = ENET_PTP_TSCTL & ENET_PTP_TSCTL_TMSSTI;
+ temp_state = ENET_PTP_TSCTL & ENET_PTP_TSCTL_TMSSTI;
timeout++;
}while((RESET != temp_state) && (timeout < ENET_DELAY_TO));
/* return ERROR due to timeout */
@@ -3226,16 +3273,16 @@ ErrStatus enet_ptp_timestamp_function_config(enet_ptp_function_enum func)
enet_state = ERROR;
}else{
ENET_PTP_TSCTL |= ENET_PTP_TSCTL_TMSSTI;
- }
- break;
+ }
+ break;
default:
- temp_config = (uint32_t)func & (~BIT(31));
+ temp_config = (uint32_t)func & (~BIT(31));
if(RESET != ((uint32_t)func & BIT(31))){
- ENET_PTP_TSCTL |= temp_config;
+ ENET_PTP_TSCTL |= temp_config;
}else{
- ENET_PTP_TSCTL &= ~temp_config;
+ ENET_PTP_TSCTL &= ~temp_config;
}
- break;
+ break;
}
return enet_state;
@@ -3243,8 +3290,7 @@ ErrStatus enet_ptp_timestamp_function_config(enet_ptp_function_enum func)
/*!
\brief configure system time subsecond increment value
- \param[in] subsecond: the value will be added to the subsecond value of system time,
- this value must be between 0 and 0xFF
+ \param[in] subsecond: the value will be added to the subsecond value of system time(0x00000000 - 0x000000FF)
\param[out] none
\retval none
*/
@@ -3266,12 +3312,12 @@ void enet_ptp_timestamp_addend_config(uint32_t add)
/*!
\brief initialize or add/subtract to second of the system time
- \param[in] sign: timestamp update positive or negative sign,
+ \param[in] sign: timestamp update positive or negative sign
only one parameter can be selected which is shown as below
\arg ENET_PTP_ADD_TO_TIME: timestamp update value is added to system time
\arg ENET_PTP_SUBSTRACT_FROM_TIME: timestamp update value is subtracted from system time
\param[in] second: initializing or adding/subtracting to second of the system time
- \param[in] subsecond: the current subsecond of the system time
+ \param[in] subsecond: the current subsecond of the system time
with 0.46 ns accuracy if required accuracy is 20 ns
\param[out] none
\retval none
@@ -3279,7 +3325,7 @@ void enet_ptp_timestamp_addend_config(uint32_t add)
void enet_ptp_timestamp_update_config(uint32_t sign, uint32_t second, uint32_t subsecond)
{
ENET_PTP_TSUH = second;
- ENET_PTP_TSUL = sign | PTP_TSUL_TMSUSS(subsecond);
+ ENET_PTP_TSUL = sign | PTP_TSUL_TMSUSS(subsecond);
}
/*!
@@ -3298,7 +3344,7 @@ void enet_ptp_expected_time_config(uint32_t second, uint32_t nanosecond)
/*!
\brief get the current system time
\param[in] none
- \param[out] systime_struct: pointer to a enet_ptp_systime_struct structure which contains
+ \param[out] systime_struct: pointer to a enet_ptp_systime_struct structure which contains
parameters of PTP system time
members of the structure and the member values are shown as below:
second: 0x0 - 0xFFFF FFFF
@@ -3311,9 +3357,9 @@ void enet_ptp_system_time_get(enet_ptp_systime_struct *systime_struct)
uint32_t temp_sec = 0U, temp_subs = 0U;
/* get the value of sysytem time registers */
- temp_sec = (uint32_t)ENET_PTP_TSH;
+ temp_sec = (uint32_t)ENET_PTP_TSH;
temp_subs = (uint32_t)ENET_PTP_TSL;
-
+
/* get sysytem time and construct the enet_ptp_systime_struct structure */
systime_struct->second = temp_sec;
systime_struct->subsecond = GET_PTP_TSL_STMSS(temp_subs);
@@ -3322,18 +3368,18 @@ void enet_ptp_system_time_get(enet_ptp_systime_struct *systime_struct)
/*!
\brief configure the PPS output frequency
- \param[in] freq: PPS output frequency,
+ \param[in] freq: PPS output frequency
only one parameter can be selected which is shown as below
\arg ENET_PPSOFC_1HZ: PPS output 1Hz frequency
- \arg ENET_PPSOFC_2HZ: PPS output 2Hz frequency
- \arg ENET_PPSOFC_4HZ: PPS output 4Hz frequency
- \arg ENET_PPSOFC_8HZ: PPS output 8Hz frequency
- \arg ENET_PPSOFC_16HZ: PPS output 16Hz frequency
- \arg ENET_PPSOFC_32HZ: PPS output 32Hz frequency
+ \arg ENET_PPSOFC_2HZ: PPS output 2Hz frequency
+ \arg ENET_PPSOFC_4HZ: PPS output 4Hz frequency
+ \arg ENET_PPSOFC_8HZ: PPS output 8Hz frequency
+ \arg ENET_PPSOFC_16HZ: PPS output 16Hz frequency
+ \arg ENET_PPSOFC_32HZ: PPS output 32Hz frequency
\arg ENET_PPSOFC_64HZ: PPS output 64Hz frequency
\arg ENET_PPSOFC_128HZ: PPS output 128Hz frequency
\arg ENET_PPSOFC_256HZ: PPS output 256Hz frequency
- \arg ENET_PPSOFC_512HZ: PPS output 512Hz frequency
+ \arg ENET_PPSOFC_512HZ: PPS output 512Hz frequency
\arg ENET_PPSOFC_1024HZ: PPS output 1024Hz frequency
\arg ENET_PPSOFC_2048HZ: PPS output 2048Hz frequency
\arg ENET_PPSOFC_4096HZ: PPS output 4096Hz frequency
@@ -3362,7 +3408,7 @@ void enet_initpara_reset(void)
enet_initpara.dma_maxburst = 0U;
enet_initpara.dma_arbitration = 0U;
enet_initpara.store_forward_mode = 0U;
- enet_initpara.dma_function = 0U;
+ enet_initpara.dma_function = 0U;
enet_initpara.vlan_config = 0U;
enet_initpara.flow_control = 0U;
enet_initpara.hashtable_high = 0U;
@@ -3371,10 +3417,10 @@ void enet_initpara_reset(void)
enet_initpara.halfduplex_param = 0U;
enet_initpara.timer_config = 0U;
enet_initpara.interframegap = 0U;
-}
+}
/*!
- \brief initialize ENET peripheral with generally concerned parameters, call it by enet_init()
+ \brief initialize ENET peripheral with generally concerned parameters, call it by enet_init()
\param[in] none
\param[out] none
\retval none
@@ -3396,7 +3442,7 @@ static void enet_default_init(void)
| ENET_AUTO_PADCRC_DROP_DISABLE \
| ENET_CHECKSUMOFFLOAD_DISABLE;
ENET_MAC_CFG = reg_value;
-
+
/* configure ENET_MAC_FRMF register */
ENET_MAC_FRMF = ENET_SRC_FILTER_DISABLE |ENET_DEST_FILTER_INVERSE_DISABLE \
|ENET_MULTICAST_FILTER_PERFECT |ENET_UNICAST_FILTER_PERFECT \
@@ -3405,7 +3451,7 @@ static void enet_default_init(void)
/* configure ENET_MAC_HLH, ENET_MAC_HLL register */
ENET_MAC_HLH = 0x0U;
-
+
ENET_MAC_HLL = 0x0U;
/* configure ENET_MAC_FCTL, ENET_MAC_FCTH register */
@@ -3414,13 +3460,13 @@ static void enet_default_init(void)
reg_value |= MAC_FCTL_PTM(0) |ENET_ZERO_QUANTA_PAUSE_DISABLE \
|ENET_PAUSETIME_MINUS4 |ENET_UNIQUE_PAUSEDETECT \
|ENET_RX_FLOWCONTROL_DISABLE |ENET_TX_FLOWCONTROL_DISABLE;
- ENET_MAC_FCTL = reg_value;
-
+ ENET_MAC_FCTL = reg_value;
+
ENET_MAC_FCTH = ENET_DEACTIVE_THRESHOLD_512BYTES |ENET_ACTIVE_THRESHOLD_1536BYTES;
-
+
/* configure ENET_MAC_VLT register */
ENET_MAC_VLT = ENET_VLANTAGCOMPARISON_16BIT |MAC_VLT_VLTI(0);
-
+
/* DMA */
/* configure ENET_DMA_CTL register */
reg_value = ENET_DMA_CTL;
@@ -3429,8 +3475,8 @@ static void enet_default_init(void)
|ENET_FLUSH_RXFRAME_ENABLE |ENET_TX_MODE_STOREFORWARD \
|ENET_TX_THRESHOLD_64BYTES |ENET_RX_THRESHOLD_64BYTES \
|ENET_FORWARD_ERRFRAMES_DISABLE |ENET_FORWARD_UNDERSZ_GOODFRAMES_DISABLE \
- |ENET_SECONDFRAME_OPT_DISABLE;
- ENET_DMA_CTL = reg_value;
+ |ENET_SECONDFRAME_OPT_DISABLE;
+ ENET_DMA_CTL = reg_value;
/* configure ENET_DMA_BCTL register */
reg_value = ENET_DMA_BCTL;
@@ -3439,7 +3485,7 @@ static void enet_default_init(void)
|ENET_RXDP_32BEAT |ENET_PGBL_32BEAT |ENET_RXTX_DIFFERENT_PGBL \
|ENET_FIXED_BURST_ENABLE |ENET_MIXED_BURST_DISABLE \
|ENET_NORMAL_DESCRIPTOR;
- ENET_DMA_BCTL = reg_value;
+ ENET_DMA_BCTL = reg_value;
}
#ifndef USE_DELAY
@@ -3451,8 +3497,8 @@ static void enet_default_init(void)
*/
static void enet_delay(uint32_t ncount)
{
- uint32_t delay_time = 0U;
-
+ __IO uint32_t delay_time = 0U;
+
for(delay_time = ncount; delay_time != 0U; delay_time--){
}
}
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_exmc.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_exmc.c
index a3049a7448..e225258eb5 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_exmc.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_exmc.c
@@ -1,33 +1,58 @@
/*!
- \file gd32f4xx_exmc.c
- \brief EXMC driver
+ \file gd32f4xx_exmc.c
+ \brief EXMC driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#include "gd32f4xx_exmc.h"
/* EXMC bank0 register reset value */
-#define BANK0_SNCTL_REGION_RESET ((uint32_t)0x000030DAU)
+#define BANK0_SNCTL_RESET ((uint32_t)0x000030DAU)
#define BANK0_SNTCFG_RESET ((uint32_t)0x0FFFFFFFU)
#define BANK0_SNWTCFG_RESET ((uint32_t)0x0FFFFFFFU)
-/* EXMC bank1/2 register reset mask*/
-#define BANK1_2_NPCTL_RESET ((uint32_t)0x00000018U)
-#define BANK1_2_NPINTEN_RESET ((uint32_t)0x00000040U)
-#define BANK1_2_NPCTCFG_RESET ((uint32_t)0xFCFCFCFCU)
-#define BANK1_2_NPATCFG_RESET ((uint32_t)0xFCFCFCFCU)
+/* EXMC bank1/2 register reset mask */
+#define BANK1_2_NPCTL_RESET ((uint32_t)0x00000008U)
+#define BANK1_2_NPINTEN_RESET ((uint32_t)0x00000042U)
+#define BANK1_2_NPCTCFG_RESET ((uint32_t)0xFFFFFFFFU)
+#define BANK1_2_NPATCFG_RESET ((uint32_t)0xFFFFFFFFU)
-/* EXMC bank3 register reset mask*/
-#define BANK3_NPCTL_RESET ((uint32_t)0x00000018U)
-#define BANK3_NPINTEN_RESET ((uint32_t)0x00000000U)
-#define BANK3_NPCTCFG_RESET ((uint32_t)0xFCFCFCFCU)
-#define BANK3_NPATCFG_RESET ((uint32_t)0xFCFCFCFCU)
-#define BANK3_PIOTCFG3_RESET ((uint32_t)0xFCFCFCFCU)
+/* EXMC bank3 register reset mask */
+#define BANK3_NPCTL_RESET ((uint32_t)0x00000008U)
+#define BANK3_NPINTEN_RESET ((uint32_t)0x00000040U)
+#define BANK3_NPCTCFG_RESET ((uint32_t)0xFFFFFFFFU)
+#define BANK3_NPATCFG_RESET ((uint32_t)0xFFFFFFFFU)
+#define BANK3_PIOTCFG3_RESET ((uint32_t)0xFFFFFFFFU)
/* EXMC SDRAM device register reset mask */
#define SDRAM_DEVICE_SDCTL_RESET ((uint32_t)0x000002D0U)
@@ -64,13 +89,13 @@
#define NPCTCFG_COMHLD_OFFSET ((uint32_t)16U)
#define NPCTCFG_COMHIZ_OFFSET ((uint32_t)24U)
-#define NPATCFG_COMWAIT_OFFSET ((uint32_t)8U)
-#define NPATCFG_COMHLD_OFFSET ((uint32_t)16U)
-#define NPATCFG_COMHIZ_OFFSET ((uint32_t)24U)
+#define NPATCFG_ATTWAIT_OFFSET ((uint32_t)8U)
+#define NPATCFG_ATTHLD_OFFSET ((uint32_t)16U)
+#define NPATCFG_ATTHIZ_OFFSET ((uint32_t)24U)
-#define PIOTCFG_COMWAIT_OFFSET ((uint32_t)8U)
-#define PIOTCFG_COMHLD_OFFSET ((uint32_t)16U)
-#define PIOTCFG_COMHIZ_OFFSET ((uint32_t)24U)
+#define PIOTCFG_IOWAIT_OFFSET ((uint32_t)8U)
+#define PIOTCFG_IOHLD_OFFSET ((uint32_t)16U)
+#define PIOTCFG_IOHIZ_OFFSET ((uint32_t)24U)
#define SDCTL_WPEN_OFFSET ((uint32_t)9U)
#define SDCTL_BRSTRD_OFFSET ((uint32_t)12U)
@@ -96,11 +121,12 @@
#define SRCMD_RWAITCYCLE_OFFSET ((uint32_t)16U)
#define SWCMD_WWAITCYCLE_OFFSET ((uint32_t)16U)
-#define INTEN_INTEN_OFFSET ((uint32_t)3U)
+#define INTEN_INTS_OFFSET ((uint32_t)3U)
/*!
\brief deinitialize EXMC NOR/SRAM region
\param[in] exmc_norsram_region: select the region of bank0
+ only one parameter can be selected which is shown as below:
\arg EXMC_BANK0_NORSRAM_REGIONx(x=0..3)
\param[out] none
\retval none
@@ -108,29 +134,83 @@
void exmc_norsram_deinit(uint32_t exmc_norsram_region)
{
/* reset the registers */
- EXMC_SNCTL(exmc_norsram_region) = BANK0_SNCTL_REGION_RESET;
+ EXMC_SNCTL(exmc_norsram_region) = BANK0_SNCTL_RESET;
EXMC_SNTCFG(exmc_norsram_region) = BANK0_SNTCFG_RESET;
EXMC_SNWTCFG(exmc_norsram_region) = BANK0_SNWTCFG_RESET;
}
/*!
+ \brief initialize exmc_norsram_parameter_struct with the default values
+ \param[in] none
+ \param[out] exmc_norsram_init_struct: the initialized struct exmc_norsram_parameter_struct pointer
+ \retval none
+*/
+void exmc_norsram_struct_para_init(exmc_norsram_parameter_struct* exmc_norsram_init_struct)
+{
+ /* configure the structure with default values */
+ exmc_norsram_init_struct->norsram_region = EXMC_BANK0_NORSRAM_REGION0;
+ exmc_norsram_init_struct->address_data_mux = ENABLE;
+ exmc_norsram_init_struct->memory_type = EXMC_MEMORY_TYPE_SRAM;
+ exmc_norsram_init_struct->databus_width = EXMC_NOR_DATABUS_WIDTH_8B;
+ exmc_norsram_init_struct->burst_mode = DISABLE;
+ exmc_norsram_init_struct->nwait_polarity = EXMC_NWAIT_POLARITY_LOW;
+ exmc_norsram_init_struct->wrap_burst_mode = DISABLE;
+ exmc_norsram_init_struct->nwait_config = EXMC_NWAIT_CONFIG_BEFORE;
+ exmc_norsram_init_struct->memory_write = ENABLE;
+ exmc_norsram_init_struct->nwait_signal = ENABLE;
+ exmc_norsram_init_struct->extended_mode = DISABLE;
+ exmc_norsram_init_struct->asyn_wait = DISABLE;
+ exmc_norsram_init_struct->write_mode = EXMC_ASYN_WRITE;
+
+ /* configure read/write timing */
+ exmc_norsram_init_struct->read_write_timing->asyn_address_setuptime = 0xFU;
+ exmc_norsram_init_struct->read_write_timing->asyn_address_holdtime = 0xFU;
+ exmc_norsram_init_struct->read_write_timing->asyn_data_setuptime = 0xFFU;
+ exmc_norsram_init_struct->read_write_timing->bus_latency = 0xFU;
+ exmc_norsram_init_struct->read_write_timing->syn_clk_division = EXMC_SYN_CLOCK_RATIO_16_CLK;
+ exmc_norsram_init_struct->read_write_timing->syn_data_latency = EXMC_DATALAT_17_CLK;
+ exmc_norsram_init_struct->read_write_timing->asyn_access_mode = EXMC_ACCESS_MODE_A;
+
+ /* write timing configure, when extended mode is used */
+ exmc_norsram_init_struct->write_timing->asyn_address_setuptime = 0xFU;
+ exmc_norsram_init_struct->write_timing->asyn_address_holdtime = 0xFU;
+ exmc_norsram_init_struct->write_timing->asyn_data_setuptime = 0xFFU;
+ exmc_norsram_init_struct->write_timing->bus_latency = 0xFU;
+ exmc_norsram_init_struct->write_timing->asyn_access_mode = EXMC_ACCESS_MODE_A;
+}
+
+/*!
\brief initialize EXMC NOR/SRAM region
\param[in] exmc_norsram_parameter_struct: configure the EXMC NOR/SRAM parameter
- norsram_region: EXMC_BANK0_NORSRAM_REGIONx,x=0..3
- write_mode: EXMC_ASYN_WRITE,EXMC_SYN_WRITE
- extended_mode: ENABLE or DISABLE
+ norsram_region: EXMC_BANK0_NORSRAM_REGIONx, x=0..3
+ write_mode: EXMC_ASYN_WRITE, EXMC_SYN_WRITE
+ extended_mode: ENABLE or DISABLE
asyn_wait: ENABLE or DISABLE
nwait_signal: ENABLE or DISABLE
memory_write: ENABLE or DISABLE
- nwait_config: EXMC_NWAIT_CONFIG_BEFORE,EXMC_NWAIT_CONFIG_DURING
+ nwait_config: EXMC_NWAIT_CONFIG_BEFORE, EXMC_NWAIT_CONFIG_DURING
wrap_burst_mode: ENABLE or DISABLE
- nwait_polarity: EXMC_NWAIT_POLARITY_LOW,EXMC_NWAIT_POLARITY_HIGH
+ nwait_polarity: EXMC_NWAIT_POLARITY_LOW, EXMC_NWAIT_POLARITY_HIGH
burst_mode: ENABLE or DISABLE
- databus_width: EXMC_NOR_DATABUS_WIDTH_8B,EXMC_NOR_DATABUS_WIDTH_16B
- memory_type: EXMC_MEMORY_TYPE_SRAM,EXMC_MEMORY_TYPE_PSRAM,EXMC_MEMORY_TYPE_NOR
+ databus_width: EXMC_NOR_DATABUS_WIDTH_8B, EXMC_NOR_DATABUS_WIDTH_16B
+ memory_type: EXMC_MEMORY_TYPE_SRAM, EXMC_MEMORY_TYPE_PSRAM, EXMC_MEMORY_TYPE_NOR
address_data_mux: ENABLE or DISABLE
read_write_timing: struct exmc_norsram_timing_parameter_struct set the time
+ asyn_access_mode: EXMC_ACCESS_MODE_A, EXMC_ACCESS_MODE_B, EXMC_ACCESS_MODE_C, EXMC_ACCESS_MODE_D
+ syn_data_latency: EXMC_DATALAT_x_CLK, x=2..17
+ syn_clk_division: EXMC_SYN_CLOCK_RATIO_x_CLK, x=2..16
+ bus_latency: 0x0U~0xFU
+ asyn_data_setuptime: 0x01U~0xFFU
+ asyn_address_holdtime: 0x1U~0xFU
+ asyn_address_setuptime: 0x0U~0xFU
write_timing: struct exmc_norsram_timing_parameter_struct set the time
+ asyn_access_mode: EXMC_ACCESS_MODE_A, EXMC_ACCESS_MODE_B, EXMC_ACCESS_MODE_C, EXMC_ACCESS_MODE_D
+ syn_data_latency: EXMC_DATALAT_x_CLK, x=2..17
+ syn_clk_division: EXMC_SYN_CLOCK_RATIO_x_CLK, x=2..16
+ bus_latency: 0x0U~0xFU
+ asyn_data_setuptime: 0x01U~0xFFU
+ asyn_address_holdtime: 0x1U~0xFU
+ asyn_address_setuptime: 0x0U~0xFU
\param[out] none
\retval none
*/
@@ -142,23 +222,23 @@ void exmc_norsram_init(exmc_norsram_parameter_struct* exmc_norsram_init_struct)
snctl = EXMC_SNCTL(exmc_norsram_init_struct->norsram_region);
/* clear relative bits */
- snctl &= ((uint32_t)~(EXMC_SNCTL_EXMODEN | EXMC_SNCTL_NRTP | EXMC_SNCTL_NRW | EXMC_SNCTL_SBRSTEN |
- EXMC_SNCTL_NRWTPOL | EXMC_SNCTL_WRAPEN | EXMC_SNCTL_NRWTCFG | EXMC_SNCTL_WREN |
- EXMC_SNCTL_NRWTEN | EXMC_SNCTL_EXMODEN | EXMC_SNCTL_ASYNCWAIT | EXMC_SNCTL_SYNCWR |
- EXMC_SNCTL_NRBKEN));
+ snctl &= ((uint32_t)~(EXMC_SNCTL_NREN | EXMC_SNCTL_NRTP | EXMC_SNCTL_NRW | EXMC_SNCTL_SBRSTEN |
+ EXMC_SNCTL_NRWTPOL | EXMC_SNCTL_WRAPEN | EXMC_SNCTL_NRWTCFG | EXMC_SNCTL_WREN |
+ EXMC_SNCTL_NRWTEN | EXMC_SNCTL_EXMODEN | EXMC_SNCTL_ASYNCWAIT | EXMC_SNCTL_SYNCWR |
+ EXMC_SNCTL_NRMUX ));
- snctl = (uint32_t)(exmc_norsram_init_struct->address_data_mux << SNCTL_NRMUX_OFFSET) |
- exmc_norsram_init_struct->memory_type |
- exmc_norsram_init_struct->databus_width |
- (exmc_norsram_init_struct->burst_mode << SNCTL_SBRSTEN_OFFSET) |
- exmc_norsram_init_struct->nwait_polarity |
- (exmc_norsram_init_struct->wrap_burst_mode << SNCTL_WRAPEN_OFFSET) |
- exmc_norsram_init_struct->nwait_config |
- (exmc_norsram_init_struct->memory_write << SNCTL_WREN_OFFSET) |
- (exmc_norsram_init_struct->nwait_signal << SNCTL_NRWTEN_OFFSET) |
- (exmc_norsram_init_struct->extended_mode << SNCTL_EXMODEN_OFFSET) |
- (exmc_norsram_init_struct->asyn_wait << SNCTL_ASYNCWAIT_OFFSET) |
- exmc_norsram_init_struct->write_mode;
+ snctl |= (uint32_t)(exmc_norsram_init_struct->address_data_mux << SNCTL_NRMUX_OFFSET) |
+ exmc_norsram_init_struct->memory_type |
+ exmc_norsram_init_struct->databus_width |
+ (exmc_norsram_init_struct->burst_mode << SNCTL_SBRSTEN_OFFSET) |
+ exmc_norsram_init_struct->nwait_polarity |
+ (exmc_norsram_init_struct->wrap_burst_mode << SNCTL_WRAPEN_OFFSET) |
+ exmc_norsram_init_struct->nwait_config |
+ (exmc_norsram_init_struct->memory_write << SNCTL_WREN_OFFSET) |
+ (exmc_norsram_init_struct->nwait_signal << SNCTL_NRWTEN_OFFSET) |
+ (exmc_norsram_init_struct->extended_mode << SNCTL_EXMODEN_OFFSET) |
+ (exmc_norsram_init_struct->asyn_wait << SNCTL_ASYNCWAIT_OFFSET) |
+ exmc_norsram_init_struct->write_mode;
sntcfg = (uint32_t)exmc_norsram_init_struct->read_write_timing->asyn_address_setuptime |
(exmc_norsram_init_struct->read_write_timing->asyn_address_holdtime << SNTCFG_AHLD_OFFSET) |
@@ -169,22 +249,18 @@ void exmc_norsram_init(exmc_norsram_parameter_struct* exmc_norsram_init_struct)
exmc_norsram_init_struct->read_write_timing->asyn_access_mode;
/* nor flash access enable */
- if(EXMC_MEMORY_TYPE_NOR == exmc_norsram_init_struct->memory_type)
- {
+ if(EXMC_MEMORY_TYPE_NOR == exmc_norsram_init_struct->memory_type){
snctl |= (uint32_t)EXMC_SNCTL_NREN;
}
/* extended mode configure */
- if(ENABLE == exmc_norsram_init_struct->extended_mode)
- {
+ if(ENABLE == exmc_norsram_init_struct->extended_mode){
snwtcfg = (uint32_t)exmc_norsram_init_struct->write_timing->asyn_address_setuptime |
(exmc_norsram_init_struct->write_timing->asyn_address_holdtime << SNTCFG_AHLD_OFFSET )|
(exmc_norsram_init_struct->write_timing->asyn_data_setuptime << SNTCFG_DSET_OFFSET) |
(exmc_norsram_init_struct->write_timing->bus_latency << SNTCFG_BUSLAT_OFFSET) |
exmc_norsram_init_struct->write_timing->asyn_access_mode;
- }
- else
- {
+ }else{
snwtcfg = BANK0_SNWTCFG_RESET;
}
@@ -195,85 +271,9 @@ void exmc_norsram_init(exmc_norsram_parameter_struct* exmc_norsram_init_struct)
}
/*!
- \brief initialize the struct exmc_norsram_parameter_struct
- \param[in] none
- \param[out] exmc_norsram_init_struct: the initialized struct exmc_norsram_parameter_struct pointer
- \retval none
-*/
-void exmc_norsram_parameter_init(exmc_norsram_parameter_struct* exmc_norsram_init_struct)
-{
- /* configure the structure with default value */
- exmc_norsram_init_struct->norsram_region = EXMC_BANK0_NORSRAM_REGION0;
- exmc_norsram_init_struct->address_data_mux = ENABLE;
- exmc_norsram_init_struct->memory_type = EXMC_MEMORY_TYPE_SRAM;
- exmc_norsram_init_struct->databus_width = EXMC_NOR_DATABUS_WIDTH_8B;
- exmc_norsram_init_struct->burst_mode = DISABLE;
- exmc_norsram_init_struct->nwait_polarity = EXMC_NWAIT_POLARITY_LOW;
- exmc_norsram_init_struct->wrap_burst_mode = DISABLE;
- exmc_norsram_init_struct->nwait_config = EXMC_NWAIT_CONFIG_BEFORE;
- exmc_norsram_init_struct->memory_write = ENABLE;
- exmc_norsram_init_struct->nwait_signal = ENABLE;
- exmc_norsram_init_struct->extended_mode = DISABLE;
- exmc_norsram_init_struct->asyn_wait = DISABLE;
- exmc_norsram_init_struct->write_mode = EXMC_ASYN_WRITE;
-
- /* read/write timing configure */
- exmc_norsram_init_struct->read_write_timing->asyn_address_setuptime = 0xFU;
- exmc_norsram_init_struct->read_write_timing->asyn_address_holdtime = 0xFU;
- exmc_norsram_init_struct->read_write_timing->asyn_data_setuptime = 0xFFU;
- exmc_norsram_init_struct->read_write_timing->bus_latency = 0xFU;
- exmc_norsram_init_struct->read_write_timing->syn_clk_division = EXMC_SYN_CLOCK_RATIO_16_CLK;
- exmc_norsram_init_struct->read_write_timing->syn_data_latency = EXMC_DATALAT_17_CLK;
- exmc_norsram_init_struct->read_write_timing->asyn_access_mode = EXMC_ACCESS_MODE_A;
-
- /* write timing configure, when extended mode is used */
- exmc_norsram_init_struct->write_timing->asyn_address_setuptime = 0xFU;
- exmc_norsram_init_struct->write_timing->asyn_address_holdtime = 0xFU;
- exmc_norsram_init_struct->write_timing->asyn_data_setuptime = 0xFFU;
- exmc_norsram_init_struct->write_timing->bus_latency = 0xFU;
- exmc_norsram_init_struct->write_timing->asyn_access_mode = EXMC_ACCESS_MODE_A;
-}
-
-/*!
- \brief consecutive clock configure
- \param[in] clock_mode: specifie when the clock is generated
- \arg EXMC_CLOCK_SYN_MODE: the clock is generated only during synchronous access
- \arg EXMC_CLOCK_UNCONDITIONALLY: the clock is generated unconditionally
- \param[out] none
- \retval none
-*/
-void exmc_norsram_consecutive_clock_config(uint32_t clock_mode)
-{
- if (EXMC_CLOCK_UNCONDITIONALLY == clock_mode){
- EXMC_SNCTL(EXMC_BANK0_NORSRAM_REGION0) |= EXMC_CLOCK_UNCONDITIONALLY;
- }else{
- EXMC_SNCTL(EXMC_BANK0_NORSRAM_REGION0) &= ~EXMC_CLOCK_UNCONDITIONALLY;
- }
-}
-
-/*!
- \brief CRAM page size configure
- \param[in] page_size: CRAM page size
- \arg EXMC_CRAM_AUTO_SPLIT: the clock is generated only during synchronous access
- \arg EXMC_CRAM_PAGE_SIZE_128_BYTES: page size is 128 bytes
- \arg EXMC_CRAM_PAGE_SIZE_256_BYTES: page size is 256 bytes
- \arg EXMC_CRAM_PAGE_SIZE_512_BYTES: page size is 512 bytes
- \arg EXMC_CRAM_PAGE_SIZE_1024_BYTES: page size is 1024 bytes
- \param[out] none
- \retval none
-*/
-void exmc_norsram_page_size_config(uint32_t page_size)
-{
- /* reset the bits */
- EXMC_SNCTL(EXMC_BANK0_NORSRAM_REGION0) &= ~EXMC_SNCTL_CPS;
-
- /* set the CPS bits */
- EXMC_SNCTL(EXMC_BANK0_NORSRAM_REGION0) |= page_size;
-}
-
-/*!
\brief enable EXMC NOR/PSRAM bank region
\param[in] exmc_norsram_region: specifie the region of NOR/PSRAM bank
+ only one parameter can be selected which is shown as below:
\arg EXMC_BANK0_NORSRAM_REGIONx(x=0..3)
\param[out] none
\retval none
@@ -286,6 +286,7 @@ void exmc_norsram_enable(uint32_t exmc_norsram_region)
/*!
\brief disable EXMC NOR/PSRAM bank region
\param[in] exmc_norsram_region: specifie the region of NOR/PSRAM Bank
+ only one parameter can be selected which is shown as below:
\arg EXMC_BANK0_NORSRAM_REGIONx(x=0..3)
\param[out] none
\retval none
@@ -298,6 +299,7 @@ void exmc_norsram_disable(uint32_t exmc_norsram_region)
/*!
\brief deinitialize EXMC NAND bank
\param[in] exmc_nand_bank: select the bank of NAND
+ only one parameter can be selected which is shown as below:
\arg EXMC_BANKx_NAND(x=1..2)
\param[out] none
\retval none
@@ -312,6 +314,32 @@ void exmc_nand_deinit(uint32_t exmc_nand_bank)
}
/*!
+ \brief initialize exmc_norsram_parameter_struct with the default values
+ \param[in] none
+ \param[out] the initialized struct exmc_norsram_parameter_struct pointer
+ \retval none
+*/
+void exmc_nand_struct_para_init(exmc_nand_parameter_struct* exmc_nand_init_struct)
+{
+ /* configure the structure with default values */
+ exmc_nand_init_struct->nand_bank = EXMC_BANK1_NAND;
+ exmc_nand_init_struct->wait_feature = DISABLE;
+ exmc_nand_init_struct->databus_width = EXMC_NAND_DATABUS_WIDTH_8B;
+ exmc_nand_init_struct->ecc_logic = DISABLE;
+ exmc_nand_init_struct->ecc_size = EXMC_ECC_SIZE_256BYTES;
+ exmc_nand_init_struct->ctr_latency = 0x0U;
+ exmc_nand_init_struct->atr_latency = 0x0U;
+ exmc_nand_init_struct->common_space_timing->setuptime = 0xFCU;
+ exmc_nand_init_struct->common_space_timing->waittime = 0xFCU;
+ exmc_nand_init_struct->common_space_timing->holdtime = 0xFCU;
+ exmc_nand_init_struct->common_space_timing->databus_hiztime = 0xFCU;
+ exmc_nand_init_struct->attribute_space_timing->setuptime = 0xFCU;
+ exmc_nand_init_struct->attribute_space_timing->waittime = 0xFCU;
+ exmc_nand_init_struct->attribute_space_timing->holdtime = 0xFCU;
+ exmc_nand_init_struct->attribute_space_timing->databus_hiztime = 0xFCU;
+}
+
+/*!
\brief initialize EXMC NAND bank
\param[in] exmc_nand_parameter_struct: configure the EXMC NAND parameter
nand_bank: EXMC_BANK1_NAND,EXMC_BANK2_NAND
@@ -322,14 +350,22 @@ void exmc_nand_deinit(uint32_t exmc_nand_bank)
databus_width: EXMC_NAND_DATABUS_WIDTH_8B,EXMC_NAND_DATABUS_WIDTH_16B
wait_feature: ENABLE or DISABLE
common_space_timing: struct exmc_nand_pccard_timing_parameter_struct set the time
+ databus_hiztime: 0x01U~0xFFU
+ holdtime: 0x01U~0xFEU
+ waittime: 0x02U~0xFFU
+ setuptime: 0x01U~0xFFU
attribute_space_timing: struct exmc_nand_pccard_timing_parameter_struct set the time
+ databus_hiztime: 0x00U~0xFEU
+ holdtime: 0x01U~0xFEU
+ waittime: 0x02U~0xFFU
+ setuptime: 0x01U~0xFFU
\param[out] none
\retval none
*/
void exmc_nand_init(exmc_nand_parameter_struct* exmc_nand_init_struct)
{
uint32_t npctl = 0x00000000U, npctcfg = 0x00000000U, npatcfg = 0x00000000U;
-
+
npctl = (uint32_t)(exmc_nand_init_struct->wait_feature << NPCTL_NDWTEN_OFFSET)|
EXMC_NPCTL_NDTP |
exmc_nand_init_struct->databus_width |
@@ -338,15 +374,15 @@ void exmc_nand_init(exmc_nand_parameter_struct* exmc_nand_init_struct)
exmc_nand_init_struct->ctr_latency |
exmc_nand_init_struct->atr_latency;
- npctcfg = (uint32_t)(exmc_nand_init_struct->common_space_timing->setuptime - 1U) |
- ((exmc_nand_init_struct->common_space_timing->waittime - 1U) << NPCTCFG_COMWAIT_OFFSET) |
- (exmc_nand_init_struct->common_space_timing->holdtime << NPCTCFG_COMHLD_OFFSET)|
- ((exmc_nand_init_struct->common_space_timing->databus_hiztime - 1U) << NPCTCFG_COMHIZ_OFFSET);
+ npctcfg = (uint32_t)((exmc_nand_init_struct->common_space_timing->setuptime - 1U) & EXMC_NPCTCFG_COMSET ) |
+ (((exmc_nand_init_struct->common_space_timing->waittime - 1U) << NPCTCFG_COMWAIT_OFFSET) & EXMC_NPCTCFG_COMWAIT ) |
+ ((exmc_nand_init_struct->common_space_timing->holdtime << NPCTCFG_COMHLD_OFFSET) & EXMC_NPCTCFG_COMHLD ) |
+ (((exmc_nand_init_struct->common_space_timing->databus_hiztime - 1U) << NPCTCFG_COMHIZ_OFFSET) & EXMC_NPCTCFG_COMHIZ );
- npatcfg = (uint32_t)(exmc_nand_init_struct->attribute_space_timing->setuptime - 1U) |
- ((exmc_nand_init_struct->attribute_space_timing->waittime - 1U) << NPATCFG_COMWAIT_OFFSET) |
- (exmc_nand_init_struct->attribute_space_timing->holdtime << NPATCFG_COMHLD_OFFSET)|
- (exmc_nand_init_struct->attribute_space_timing->databus_hiztime << NPATCFG_COMHIZ_OFFSET);
+ npatcfg = (uint32_t)((exmc_nand_init_struct->attribute_space_timing->setuptime - 1U) & EXMC_NPATCFG_ATTSET ) |
+ (((exmc_nand_init_struct->attribute_space_timing->waittime - 1U) << NPATCFG_ATTWAIT_OFFSET) & EXMC_NPATCFG_ATTWAIT ) |
+ ((exmc_nand_init_struct->attribute_space_timing->holdtime << NPATCFG_ATTHLD_OFFSET) & EXMC_NPATCFG_ATTHLD ) |
+ ((exmc_nand_init_struct->attribute_space_timing->databus_hiztime << NPATCFG_ATTHIZ_OFFSET) & EXMC_NPATCFG_ATTHIZ );
/* EXMC_BANK1_NAND or EXMC_BANK2_NAND initialize */
EXMC_NPCTL(exmc_nand_init_struct->nand_bank) = npctl;
@@ -355,34 +391,9 @@ void exmc_nand_init(exmc_nand_parameter_struct* exmc_nand_init_struct)
}
/*!
- \brief initialize the struct exmc_norsram_parameter_struct
- \param[in] none
- \param[out] the initialized struct exmc_norsram_parameter_struct pointer
- \retval none
-*/
-void exmc_nand_parameter_init(exmc_nand_parameter_struct* exmc_nand_init_struct)
-{
- /* configure the structure with default value */
- exmc_nand_init_struct->nand_bank = EXMC_BANK1_NAND;
- exmc_nand_init_struct->wait_feature = DISABLE;
- exmc_nand_init_struct->databus_width = EXMC_NAND_DATABUS_WIDTH_8B;
- exmc_nand_init_struct->ecc_logic = DISABLE;
- exmc_nand_init_struct->ecc_size = EXMC_ECC_SIZE_256BYTES;
- exmc_nand_init_struct->ctr_latency = 0x0U;
- exmc_nand_init_struct->atr_latency = 0x0U;
- exmc_nand_init_struct->common_space_timing->setuptime = 0xfcU;
- exmc_nand_init_struct->common_space_timing->waittime = 0xfcU;
- exmc_nand_init_struct->common_space_timing->holdtime = 0xfcU;
- exmc_nand_init_struct->common_space_timing->databus_hiztime = 0xfcU;
- exmc_nand_init_struct->attribute_space_timing->setuptime = 0xfcU;
- exmc_nand_init_struct->attribute_space_timing->waittime = 0xfcU;
- exmc_nand_init_struct->attribute_space_timing->holdtime = 0xfcU;
- exmc_nand_init_struct->attribute_space_timing->databus_hiztime = 0xfcU;
-}
-
-/*!
\brief enable NAND bank
\param[in] exmc_nand_bank: specifie the NAND bank
+ only one parameter can be selected which is shown as below:
\arg EXMC_BANKx_NAND(x=1,2)
\param[out] none
\retval none
@@ -395,6 +406,7 @@ void exmc_nand_enable(uint32_t exmc_nand_bank)
/*!
\brief disable NAND bank
\param[in] exmc_nand_bank: specifie the NAND bank
+ only one parameter can be selected which is shown as below:
\arg EXMC_BANKx_NAND(x=1,2)
\param[out] none
\retval none
@@ -405,40 +417,6 @@ void exmc_nand_disable(uint32_t exmc_nand_bank)
}
/*!
- \brief enable or disable the EXMC NAND ECC function
- \param[in] exmc_nand_bank: specifie the NAND bank
- \arg EXMC_BANKx_NAND(x=1,2)
- \param[in] newvalue: ENABLE or DISABLE
- \param[out] none
- \retval none
-*/
-void exmc_nand_ecc_config(uint32_t exmc_nand_bank, ControlStatus newvalue)
-{
- if (ENABLE == newvalue)
- {
- /* enable the selected NAND bank ECC function */
- EXMC_NPCTL(exmc_nand_bank) |= EXMC_NPCTL_ECCEN;
- }
- else
- {
- /* disable the selected NAND bank ECC function */
- EXMC_NPCTL(exmc_nand_bank) &= ~EXMC_NPCTL_ECCEN;
- }
-}
-
-/*!
- \brief get the EXMC ECC value
- \param[in] exmc_nand_bank: specifie the NAND bank
- \arg EXMC_BANKx_NAND(x=1,2)
- \param[out] none
- \retval the error correction code(ECC) value
-*/
-uint32_t exmc_ecc_get(uint32_t exmc_nand_bank)
-{
- return(EXMC_NECC(exmc_nand_bank));
-}
-
-/*!
\brief deinitialize EXMC PC card bank
\param[in] none
\param[out] none
@@ -455,14 +433,52 @@ void exmc_pccard_deinit(void)
}
/*!
+ \brief initialize exmc_pccard_parameter_struct with the default values
+ \param[in] none
+ \param[out] the initialized struct exmc_pccard_parameter_struct pointer
+ \retval none
+*/
+void exmc_pccard_struct_para_init(exmc_pccard_parameter_struct* exmc_pccard_init_struct)
+{
+ /* configure the structure with default values */
+ exmc_pccard_init_struct->wait_feature = DISABLE;
+ exmc_pccard_init_struct->ctr_latency = 0x0U;
+ exmc_pccard_init_struct->atr_latency = 0x0U;
+ exmc_pccard_init_struct->common_space_timing->setuptime = 0xFCU;
+ exmc_pccard_init_struct->common_space_timing->waittime = 0xFCU;
+ exmc_pccard_init_struct->common_space_timing->holdtime = 0xFCU;
+ exmc_pccard_init_struct->common_space_timing->databus_hiztime = 0xFCU;
+ exmc_pccard_init_struct->attribute_space_timing->setuptime = 0xFCU;
+ exmc_pccard_init_struct->attribute_space_timing->waittime = 0xFCU;
+ exmc_pccard_init_struct->attribute_space_timing->holdtime = 0xFCU;
+ exmc_pccard_init_struct->attribute_space_timing->databus_hiztime = 0xFCU;
+ exmc_pccard_init_struct->io_space_timing->setuptime = 0xFCU;
+ exmc_pccard_init_struct->io_space_timing->waittime = 0xFCU;
+ exmc_pccard_init_struct->io_space_timing->holdtime = 0xFCU;
+ exmc_pccard_init_struct->io_space_timing->databus_hiztime = 0xFCU;
+}
+
+/*!
\brief initialize EXMC PC card bank
\param[in] exmc_pccard_parameter_struct: configure the EXMC NAND parameter
atr_latency: EXMC_ALE_RE_DELAY_x_HCLK,x=1..16
ctr_latency: EXMC_CLE_RE_DELAY_x_HCLK,x=1..16
wait_feature: ENABLE or DISABLE
common_space_timing: struct exmc_nand_pccard_timing_parameter_struct set the time
+ databus_hiztime: 0x01U~0xFFU
+ holdtime: 0x01U~0xFEU
+ waittime: 0x02U~0xFFU
+ setuptime: 0x01U~0xFFU
attribute_space_timing: struct exmc_nand_pccard_timing_parameter_struct set the time
+ databus_hiztime: 0x00U~0xFEU
+ holdtime: 0x01U~0xFEU
+ waittime: 0x02U~0xFFU
+ setuptime: 0x01U~0xFFU
io_space_timing: exmc_nand_pccard_timing_parameter_struct set the time
+ databus_hiztime: 0x00U~0xFFU
+ holdtime: 0x01U~0xFFU
+ waittime: 0x02U~0x100U
+ setuptime: 0x01U~0x100U
\param[out] none
\retval none
*/
@@ -470,53 +486,27 @@ void exmc_pccard_init(exmc_pccard_parameter_struct* exmc_pccard_init_struct)
{
/* configure the EXMC bank3 PC card control register */
EXMC_NPCTL3 = (uint32_t)(exmc_pccard_init_struct->wait_feature << NPCTL_NDWTEN_OFFSET) |
- EXMC_NAND_DATABUS_WIDTH_16B |
+ EXMC_NAND_DATABUS_WIDTH_16B |
exmc_pccard_init_struct->ctr_latency |
exmc_pccard_init_struct->atr_latency ;
-
+
/* configure the EXMC bank3 PC card common space timing configuration register */
- EXMC_NPCTCFG3 = (uint32_t)(exmc_pccard_init_struct->common_space_timing->setuptime - 1U) |
- ((exmc_pccard_init_struct->common_space_timing->waittime - 1U) << NPCTCFG_COMWAIT_OFFSET) |
- (exmc_pccard_init_struct->common_space_timing->holdtime << NPCTCFG_COMHLD_OFFSET)|
- ((exmc_pccard_init_struct->common_space_timing->databus_hiztime - 1U) << NPCTCFG_COMHIZ_OFFSET);
+ EXMC_NPCTCFG3 = (uint32_t)((exmc_pccard_init_struct->common_space_timing->setuptime - 1U) & EXMC_NPCTCFG_COMSET ) |
+ (((exmc_pccard_init_struct->common_space_timing->waittime - 1U) << NPCTCFG_COMWAIT_OFFSET) & EXMC_NPCTCFG_COMWAIT ) |
+ ((exmc_pccard_init_struct->common_space_timing->holdtime << NPCTCFG_COMHLD_OFFSET) & EXMC_NPCTCFG_COMHLD ) |
+ (((exmc_pccard_init_struct->common_space_timing->databus_hiztime - 1U) << NPCTCFG_COMHIZ_OFFSET) & EXMC_NPCTCFG_COMHIZ );
/* configure the EXMC bank3 PC card attribute space timing configuration register */
- EXMC_NPATCFG3 = (uint32_t)(exmc_pccard_init_struct->attribute_space_timing->setuptime - 1U) |
- ((exmc_pccard_init_struct->attribute_space_timing->waittime - 1U) << NPATCFG_COMWAIT_OFFSET) |
- (exmc_pccard_init_struct->attribute_space_timing->holdtime << NPATCFG_COMHLD_OFFSET)|
- (exmc_pccard_init_struct->attribute_space_timing->databus_hiztime << NPATCFG_COMHIZ_OFFSET);
+ EXMC_NPATCFG3 = (uint32_t)((exmc_pccard_init_struct->attribute_space_timing->setuptime - 1U) & EXMC_NPATCFG_ATTSET ) |
+ (((exmc_pccard_init_struct->attribute_space_timing->waittime - 1U) << NPATCFG_ATTWAIT_OFFSET) & EXMC_NPATCFG_ATTWAIT ) |
+ ((exmc_pccard_init_struct->attribute_space_timing->holdtime << NPATCFG_ATTHLD_OFFSET) & EXMC_NPATCFG_ATTHLD ) |
+ ((exmc_pccard_init_struct->attribute_space_timing->databus_hiztime << NPATCFG_ATTHIZ_OFFSET) & EXMC_NPATCFG_ATTHIZ);
/* configure the EXMC bank3 PC card io space timing configuration register */
- EXMC_PIOTCFG3 = (uint32_t)(exmc_pccard_init_struct->io_space_timing->setuptime - 1U) |
- ((exmc_pccard_init_struct->io_space_timing->waittime - 1U) << PIOTCFG_COMWAIT_OFFSET) |
- (exmc_pccard_init_struct->io_space_timing->holdtime << PIOTCFG_COMHLD_OFFSET)|
- (exmc_pccard_init_struct->io_space_timing->databus_hiztime << PIOTCFG_COMHIZ_OFFSET);
-}
-
-/*!
- \brief initialize the struct exmc_pccard_parameter_struct
- \param[in] none
- \param[out] the initialized struct exmc_pccard_parameter_struct pointer
- \retval none
-*/
-void exmc_pccard_parameter_init(exmc_pccard_parameter_struct* exmc_pccard_init_struct)
-{
- /* configure the structure with default value */
- exmc_pccard_init_struct->wait_feature = DISABLE;
- exmc_pccard_init_struct->ctr_latency = 0x0U;
- exmc_pccard_init_struct->atr_latency = 0x0U;
- exmc_pccard_init_struct->common_space_timing->setuptime = 0xFCU;
- exmc_pccard_init_struct->common_space_timing->waittime = 0xFCU;
- exmc_pccard_init_struct->common_space_timing->holdtime = 0xFCU;
- exmc_pccard_init_struct->common_space_timing->databus_hiztime = 0xFCU;
- exmc_pccard_init_struct->attribute_space_timing->setuptime = 0xFCU;
- exmc_pccard_init_struct->attribute_space_timing->waittime = 0xFCU;
- exmc_pccard_init_struct->attribute_space_timing->holdtime = 0xFCU;
- exmc_pccard_init_struct->attribute_space_timing->databus_hiztime = 0xFCU;
- exmc_pccard_init_struct->io_space_timing->setuptime = 0xFCU;
- exmc_pccard_init_struct->io_space_timing->waittime = 0xFCU;
- exmc_pccard_init_struct->io_space_timing->holdtime = 0xFCU;
- exmc_pccard_init_struct->io_space_timing->databus_hiztime = 0xFCU;
+ EXMC_PIOTCFG3 = (uint32_t)((exmc_pccard_init_struct->io_space_timing->setuptime - 1U) & EXMC_PIOTCFG3_IOSET ) |
+ (((exmc_pccard_init_struct->io_space_timing->waittime - 1U) << PIOTCFG_IOWAIT_OFFSET) & EXMC_PIOTCFG3_IOWAIT ) |
+ ((exmc_pccard_init_struct->io_space_timing->holdtime << PIOTCFG_IOHLD_OFFSET) & EXMC_PIOTCFG3_IOHLD ) |
+ ((exmc_pccard_init_struct->io_space_timing->databus_hiztime << PIOTCFG_IOHIZ_OFFSET) & EXMC_PIOTCFG3_IOHIZ );
}
/*!
@@ -543,6 +533,9 @@ void exmc_pccard_disable(void)
/*!
\brief deinitialize EXMC SDRAM device
+ \param[in] exmc_sdram_device: select the SRAM device
+ only one parameter can be selected which is shown as below:
+ \arg EXMC_SDRAM_DEVICEx(x=0, 1)
\param[in] none
\param[out] none
\retval none
@@ -558,6 +551,35 @@ void exmc_sdram_deinit(uint32_t exmc_sdram_device)
}
/*!
+ \brief initialize exmc_sdram_parameter_struct with the default values
+ \param[in] none
+ \param[out] the initialized struct exmc_pccard_parameter_struct pointer
+ \retval none
+*/
+void exmc_sdram_struct_para_init(exmc_sdram_parameter_struct* exmc_sdram_init_struct)
+{
+ /* configure the structure with default values */
+ exmc_sdram_init_struct->sdram_device = EXMC_SDRAM_DEVICE0;
+ exmc_sdram_init_struct->column_address_width = EXMC_SDRAM_COW_ADDRESS_8;
+ exmc_sdram_init_struct->row_address_width = EXMC_SDRAM_ROW_ADDRESS_11;
+ exmc_sdram_init_struct->data_width = EXMC_SDRAM_DATABUS_WIDTH_16B;
+ exmc_sdram_init_struct->internal_bank_number = EXMC_SDRAM_4_INTER_BANK;
+ exmc_sdram_init_struct->cas_latency = EXMC_CAS_LATENCY_1_SDCLK;
+ exmc_sdram_init_struct->write_protection = ENABLE;
+ exmc_sdram_init_struct->sdclock_config = EXMC_SDCLK_DISABLE;
+ exmc_sdram_init_struct->brust_read_switch = DISABLE;
+ exmc_sdram_init_struct->pipeline_read_delay = EXMC_PIPELINE_DELAY_0_HCLK;
+
+ exmc_sdram_init_struct->timing->load_mode_register_delay = 16U;
+ exmc_sdram_init_struct->timing->exit_selfrefresh_delay = 16U;
+ exmc_sdram_init_struct->timing->row_address_select_delay = 16U;
+ exmc_sdram_init_struct->timing->auto_refresh_delay = 16U;
+ exmc_sdram_init_struct->timing->write_recovery_delay = 16U;
+ exmc_sdram_init_struct->timing->row_precharge_delay = 16U;
+ exmc_sdram_init_struct->timing->row_to_column_delay = 16U;
+}
+
+/*!
\brief initialize EXMC SDRAM device
\param[in] exmc_sdram_parameter_struct: configure the EXMC SDRAM parameter
sdram_device: EXMC_SDRAM_DEVICE0,EXMC_SDRAM_DEVICE1
@@ -571,6 +593,13 @@ void exmc_sdram_deinit(uint32_t exmc_sdram_device)
row_address_width: EXMC_SDRAM_ROW_ADDRESS_x,x=11..13
column_address_width: EXMC_SDRAM_COW_ADDRESS_x,x=8..11
timing: exmc_sdram_timing_parameter_struct set the time
+ row_to_column_delay: 1U~16U
+ row_precharge_delay: 1U~16U
+ write_recovery_delay: 1U~16U
+ auto_refresh_delay: 1U~16U
+ row_address_select_delay: 1U~16U
+ exit_selfrefresh_delay: 1U~16U
+ load_mode_register_delay: 1U~16U
\param[out] none
\retval none
*/
@@ -578,7 +607,7 @@ void exmc_sdram_init(exmc_sdram_parameter_struct* exmc_sdram_init_struct)
{
uint32_t sdctl0, sdctl1, sdtcfg0, sdtcfg1;
- /* configuration EXMC_SDCTL0 or EXMC_SDCTL1 */
+ /* configuration EXMC_SDCTL0 or EXMC_SDCTL1 */
if(EXMC_SDRAM_DEVICE0 == exmc_sdram_init_struct->sdram_device){
/* configuration EXMC_SDCTL0 */
EXMC_SDCTL(EXMC_SDRAM_DEVICE0) = (uint32_t)exmc_sdram_init_struct->column_address_width |
@@ -588,9 +617,9 @@ void exmc_sdram_init(exmc_sdram_parameter_struct* exmc_sdram_init_struct)
exmc_sdram_init_struct->cas_latency |
(exmc_sdram_init_struct->write_protection << SDCTL_WPEN_OFFSET)|
exmc_sdram_init_struct->sdclock_config |
- (exmc_sdram_init_struct->brust_read_switch << SDCTL_BRSTRD_OFFSET)|
+ (exmc_sdram_init_struct->brust_read_switch << SDCTL_BRSTRD_OFFSET)|
exmc_sdram_init_struct->pipeline_read_delay;
-
+
/* configuration EXMC_SDTCFG0 */
EXMC_SDTCFG(EXMC_SDRAM_DEVICE0) = (uint32_t)((exmc_sdram_init_struct->timing->load_mode_register_delay)-1U) |
(((exmc_sdram_init_struct->timing->exit_selfrefresh_delay)-1U) << SDTCFG_XSRD_OFFSET) |
@@ -603,11 +632,11 @@ void exmc_sdram_init(exmc_sdram_parameter_struct* exmc_sdram_init_struct)
/* configuration EXMC_SDCTL0 and EXMC_SDCTL1 */
/* some bits in the EXMC_SDCTL1 register are reserved */
sdctl0 = EXMC_SDCTL(EXMC_SDRAM_DEVICE0) & (~( EXMC_SDCTL_PIPED | EXMC_SDCTL_BRSTRD | EXMC_SDCTL_SDCLK ));
-
+
sdctl0 |= (uint32_t)exmc_sdram_init_struct->sdclock_config |
- exmc_sdram_init_struct->brust_read_switch |
+ exmc_sdram_init_struct->brust_read_switch |
exmc_sdram_init_struct->pipeline_read_delay;
-
+
sdctl1 = (uint32_t)exmc_sdram_init_struct->column_address_width |
exmc_sdram_init_struct->row_address_width |
exmc_sdram_init_struct->data_width |
@@ -617,7 +646,7 @@ void exmc_sdram_init(exmc_sdram_parameter_struct* exmc_sdram_init_struct)
EXMC_SDCTL(EXMC_SDRAM_DEVICE0) = sdctl0;
EXMC_SDCTL(EXMC_SDRAM_DEVICE1) = sdctl1;
-
+
/* configuration EXMC_SDTCFG0 and EXMC_SDTCFG1 */
/* some bits in the EXMC_SDTCFG1 register are reserved */
sdtcfg0 = EXMC_SDTCFG(EXMC_SDRAM_DEVICE0) & (~(EXMC_SDTCFG_RPD | EXMC_SDTCFG_WRD | EXMC_SDTCFG_ARFD));
@@ -629,7 +658,7 @@ void exmc_sdram_init(exmc_sdram_parameter_struct* exmc_sdram_init_struct)
sdtcfg1 = (uint32_t)((exmc_sdram_init_struct->timing->load_mode_register_delay)-1U) |
(((exmc_sdram_init_struct->timing->exit_selfrefresh_delay)-1U) << SDTCFG_XSRD_OFFSET) |
(((exmc_sdram_init_struct->timing->row_address_select_delay)-1U) << SDTCFG_RASD_OFFSET) |
- (((exmc_sdram_init_struct->timing->row_to_column_delay)-1U) << SDTCFG_RCD_OFFSET);
+ (((exmc_sdram_init_struct->timing->row_to_column_delay)-1U) << SDTCFG_RCD_OFFSET);
EXMC_SDTCFG(EXMC_SDRAM_DEVICE0) = sdtcfg0;
EXMC_SDTCFG(EXMC_SDRAM_DEVICE1) = sdtcfg1;
@@ -637,121 +666,152 @@ void exmc_sdram_init(exmc_sdram_parameter_struct* exmc_sdram_init_struct)
}
/*!
- \brief initialize the struct exmc_pccard_parameter_struct
+ \brief deinitialize exmc SQPIPSRAM
\param[in] none
- \param[out] the initialized struct exmc_pccard_parameter_struct pointer
+ \param[out] none
\retval none
*/
-void exmc_sdram_parameter_init(exmc_sdram_parameter_struct* exmc_sdram_init_struct)
+void exmc_sqpipsram_deinit(void)
{
- /* configure the structure with default value */
- exmc_sdram_init_struct->sdram_device = EXMC_SDRAM_DEVICE0;
- exmc_sdram_init_struct->column_address_width = EXMC_SDRAM_COW_ADDRESS_8;
- exmc_sdram_init_struct->row_address_width = EXMC_SDRAM_ROW_ADDRESS_11;
- exmc_sdram_init_struct->data_width = EXMC_SDRAM_DATABUS_WIDTH_16B;
- exmc_sdram_init_struct->internal_bank_number = EXMC_SDRAM_4_INTER_BANK;
- exmc_sdram_init_struct->cas_latency = EXMC_CAS_LATENCY_1_SDCLK;
- exmc_sdram_init_struct->write_protection = ENABLE;
- exmc_sdram_init_struct->sdclock_config = EXMC_SDCLK_DISABLE;
- exmc_sdram_init_struct->brust_read_switch = DISABLE;
- exmc_sdram_init_struct->pipeline_read_delay = EXMC_PIPELINE_DELAY_0_HCLK;
+ /* reset the registers */
+ EXMC_SINIT = BANK0_SQPI_SINIT_RESET;
+ EXMC_SRCMD = BANK0_SQPI_SRCMD_RESET;
+ EXMC_SWCMD = BANK0_SQPI_SWCMD_RESET;
+ EXMC_SIDL = BANK0_SQPI_SIDL_RESET;
+ EXMC_SIDH = BANK0_SQPI_SIDH_RESET;
+}
- exmc_sdram_init_struct->timing->load_mode_register_delay = 16U;
- exmc_sdram_init_struct->timing->exit_selfrefresh_delay = 16U;
- exmc_sdram_init_struct->timing->row_address_select_delay = 16U;
- exmc_sdram_init_struct->timing->auto_refresh_delay = 16U;
- exmc_sdram_init_struct->timing->write_recovery_delay = 16U;
- exmc_sdram_init_struct->timing->row_precharge_delay = 16U;
- exmc_sdram_init_struct->timing->row_to_column_delay = 16U;
+/*!
+ \brief initialize exmc_sqpipsram_parameter_struct with the default values
+ \param[in] the struct exmc_sqpipsram_parameter_struct pointer
+ \param[out] none
+ \retval none
+*/
+void exmc_sqpipsram_struct_para_init(exmc_sqpipsram_parameter_struct* exmc_sqpipsram_init_struct)
+{
+ /* configure the structure with default values */
+ exmc_sqpipsram_init_struct->sample_polarity = EXMC_SQPIPSRAM_SAMPLE_RISING_EDGE;
+ exmc_sqpipsram_init_struct->id_length = EXMC_SQPIPSRAM_ID_LENGTH_64B;
+ exmc_sqpipsram_init_struct->address_bits = EXMC_SQPIPSRAM_ADDR_LENGTH_24B;
+ exmc_sqpipsram_init_struct->command_bits = EXMC_SQPIPSRAM_COMMAND_LENGTH_8B;
}
/*!
- \brief configure the SDRAM memory command
- \param[in] the struct exmc_sdram_command_parameter_struct pointer
+ \brief initialize EXMC SQPIPSRAM
+ \param[in] exmc_sqpipsram_parameter_struct: configure the EXMC SQPIPSRAM parameter
+ sample_polarity: EXMC_SQPIPSRAM_SAMPLE_RISING_EDGE,EXMC_SQPIPSRAM_SAMPLE_FALLING_EDGE
+ id_length: EXMC_SQPIPSRAM_ID_LENGTH_xB,x=8,16,32,64
+ address_bits: EXMC_SQPIPSRAM_ADDR_LENGTH_xB,x=1..26
+ command_bits: EXMC_SQPIPSRAM_COMMAND_LENGTH_xB,x=4,8,16
\param[out] none
\retval none
*/
-void exmc_sdram_command_config(exmc_sdram_command_parameter_struct* exmc_sdram_command_init_struct)
+void exmc_sqpipsram_init(exmc_sqpipsram_parameter_struct* exmc_sqpipsram_init_struct)
{
- /* configure command register */
- EXMC_SDCMD = (uint32_t)((exmc_sdram_command_init_struct->command) |
- (exmc_sdram_command_init_struct->bank_select) |
- ((exmc_sdram_command_init_struct->auto_refresh_number)) |
- ((exmc_sdram_command_init_struct->mode_register_content)<<SDCMD_MRC_OFFSET) );
+ /* initialize SQPI controller */
+ EXMC_SINIT = (uint32_t)exmc_sqpipsram_init_struct->sample_polarity |
+ exmc_sqpipsram_init_struct->id_length |
+ exmc_sqpipsram_init_struct->address_bits |
+ exmc_sqpipsram_init_struct->command_bits;
}
/*!
- \brief set auto-refresh interval
- \param[in] exmc_count: the number SDRAM clock cycles unit between two successive auto-refresh commands
+ \brief configure consecutive clock
+ \param[in] clock_mode: specifie when the clock is generated
+ only one parameter can be selected which is shown as below:
+ \arg EXMC_CLOCK_SYN_MODE: the clock is generated only during synchronous access
+ \arg EXMC_CLOCK_UNCONDITIONALLY: the clock is generated unconditionally
\param[out] none
\retval none
*/
-void exmc_sdram_refresh_count_set(uint32_t exmc_count)
+void exmc_norsram_consecutive_clock_config(uint32_t clock_mode)
{
- uint32_t sdari;
- sdari = EXMC_SDARI & (~EXMC_SDARI_ARINTV);
- EXMC_SDARI = sdari | (uint32_t)((exmc_count << SDARI_ARINTV_OFFSET) & EXMC_SDARI_ARINTV);
+ if (EXMC_CLOCK_UNCONDITIONALLY == clock_mode){
+ EXMC_SNCTL(EXMC_BANK0_NORSRAM_REGION0) |= EXMC_CLOCK_UNCONDITIONALLY;
+ }else{
+ EXMC_SNCTL(EXMC_BANK0_NORSRAM_REGION0) &= ~EXMC_CLOCK_UNCONDITIONALLY;
+ }
}
/*!
- \brief set the number of successive auto-refresh command
- \param[in] exmc_number: the number SDRAM clock cycles unit between two successive auto-refresh commands
+ \brief configure CRAM page size
+ \param[in] exmc_norsram_region: select the region of bank0
+ only one parameter can be selected which is shown as below:
+ \arg EXMC_BANK0_NORSRAM_REGIONx(x=0..3)
+ \param[in] page_size: CRAM page size
+ only one parameter can be selected which is shown as below:
+ \arg EXMC_CRAM_AUTO_SPLIT: the clock is generated only during synchronous access
+ \arg EXMC_CRAM_PAGE_SIZE_128_BYTES: page size is 128 bytes
+ \arg EXMC_CRAM_PAGE_SIZE_256_BYTES: page size is 256 bytes
+ \arg EXMC_CRAM_PAGE_SIZE_512_BYTES: page size is 512 bytes
+ \arg EXMC_CRAM_PAGE_SIZE_1024_BYTES: page size is 1024 bytes
\param[out] none
\retval none
*/
-void exmc_sdram_autorefresh_number_set(uint32_t exmc_number)
+void exmc_norsram_page_size_config(uint32_t exmc_norsram_region, uint32_t page_size)
{
- uint32_t sdcmd;
- sdcmd = EXMC_SDCMD & (~EXMC_SDCMD_NARF);
- EXMC_SDCMD = sdcmd | (uint32_t)((exmc_number << SDCMD_NARF_OFFSET) & EXMC_SDCMD_NARF) ;
+ /* reset the bits */
+ EXMC_SNCTL(exmc_norsram_region) &= ~EXMC_SNCTL_CPS;
+
+ /* set the CPS bits */
+ EXMC_SNCTL(exmc_norsram_region) |= page_size;
}
/*!
- \brief config the write protection function
- \param[in] exmc_sdram_device: specifie the SDRAM device
- \arg EXMC_SDRAM_DEVICEx(x=0,1)
+ \brief enable or disable the EXMC NAND ECC function
+ \param[in] exmc_nand_bank: specifie the NAND bank
+ only one parameter can be selected which is shown as below:
+ \arg EXMC_BANKx_NAND(x=1,2)
\param[in] newvalue: ENABLE or DISABLE
\param[out] none
\retval none
*/
-void exmc_sdram_write_protection_config(uint32_t exmc_sdram_device, ControlStatus newvalue)
+void exmc_nand_ecc_config(uint32_t exmc_nand_bank, ControlStatus newvalue)
{
if (ENABLE == newvalue){
- EXMC_SDCTL(exmc_sdram_device) |= (uint32_t)EXMC_SDCTL_WPEN;
+ /* enable the selected NAND bank ECC function */
+ EXMC_NPCTL(exmc_nand_bank) |= EXMC_NPCTL_ECCEN;
}else{
- EXMC_SDCTL(exmc_sdram_device) &= ~((uint32_t)EXMC_SDCTL_WPEN);
+ /* disable the selected NAND bank ECC function */
+ EXMC_NPCTL(exmc_nand_bank) &= ~EXMC_NPCTL_ECCEN;
}
-
}
/*!
- \brief get the status of SDRAM device0 or device1
- \param[in] exmc_sdram_device: specifie the SDRAM device
- \arg EXMC_SDRAM_DEVICEx(x=0,1)
+ \brief get the EXMC ECC value
+ \param[in] exmc_nand_bank: specifie the NAND bank
+ only one parameter can be selected which is shown as below:
+ \arg EXMC_BANKx_NAND(x=1,2)
\param[out] none
- \retval the status of SDRAM device
+ \retval the error correction code(ECC) value
*/
-uint32_t exmc_sdram_bankstatus_get(uint32_t exmc_sdram_device)
+uint32_t exmc_ecc_get(uint32_t exmc_nand_bank)
{
- uint32_t sdstat = 0U;
+ return(EXMC_NECC(exmc_nand_bank));
+}
- if(EXMC_SDRAM_DEVICE0 == exmc_sdram_device)
- {
- sdstat = ((uint32_t)(EXMC_SDSTAT & EXMC_SDSDAT_STA0) >> SDSTAT_STA0_OFFSET);
- }
- else
- {
- sdstat = ((uint32_t)(EXMC_SDSTAT & EXMC_SDSDAT_STA1) >> SDSTAT_STA1_OFFSET);
+/*!
+ \brief enable or disable read sample
+ \param[in] newvalue: ENABLE or DISABLE
+ \param[out] none
+ \retval none
+*/
+void exmc_sdram_readsample_enable(ControlStatus newvalue)
+{
+ if (ENABLE == newvalue){
+ EXMC_SDRSCTL |= EXMC_SDRSCTL_RSEN;
+ }else{
+ EXMC_SDRSCTL &= (uint32_t)(~EXMC_SDRSCTL_RSEN);
}
-
- return sdstat;
}
/*!
\brief configure the delayed sample clock of read data
\param[in] delay_cell: SDRAM the delayed sample clock of read data
+ only one parameter can be selected which is shown as below:
\arg EXMC_SDRAM_x_DELAY_CELL(x=0..15)
\param[in] extra_hclk: sample cycle of read data
+ only one parameter can be selected which is shown as below:
\arg EXMC_SDRAM_READSAMPLE_x_EXTRAHCLK(x=0,1)
\param[out] none
\retval none
@@ -759,81 +819,106 @@ uint32_t exmc_sdram_bankstatus_get(uint32_t exmc_sdram_device)
void exmc_sdram_readsample_config(uint32_t delay_cell, uint32_t extra_hclk)
{
uint32_t sdrsctl = 0U;
-
+
+ /* reset the bits */
sdrsctl = EXMC_SDRSCTL & (~(EXMC_SDRSCTL_SDSC | EXMC_SDRSCTL_SSCR));
+ /* set the bits */
sdrsctl |= (uint32_t)(delay_cell & EXMC_SDRSCTL_SDSC) |
((extra_hclk << SDRSCTL_SSCR_OFFSET) & EXMC_SDRSCTL_SSCR);
EXMC_SDRSCTL = sdrsctl;
}
/*!
- \brief enable or disable read sample
- \param[in] newvalue: ENABLE or DISABLE
+ \brief configure the SDRAM memory command
+ \param[in] exmc_sdram_command_init_struct: initialize EXMC SDRAM command
+ mode_register_content:
+ auto_refresh_number: EXMC_SDRAM_AUTO_REFLESH_x_SDCLK, x=1..15
+ bank_select: EXMC_SDRAM_DEVICE0_SELECT, EXMC_SDRAM_DEVICE1_SELECT, EXMC_SDRAM_DEVICE0_1_SELECT
+ command: EXMC_SDRAM_NORMAL_OPERATION, EXMC_SDRAM_CLOCK_ENABLE, EXMC_SDRAM_PRECHARGE_ALL,
+ EXMC_SDRAM_AUTO_REFRESH, EXMC_SDRAM_LOAD_MODE_REGISTER, EXMC_SDRAM_SELF_REFRESH,
+ EXMC_SDRAM_POWERDOWN_ENTRY
\param[out] none
\retval none
*/
-void exmc_sdram_readsample_enable(ControlStatus newvalue)
+void exmc_sdram_command_config(exmc_sdram_command_parameter_struct* exmc_sdram_command_init_struct)
{
- if (ENABLE == newvalue){
- EXMC_SDRSCTL |= EXMC_SDRSCTL_RSEN;
- }else{
- EXMC_SDRSCTL &= (uint32_t)(~EXMC_SDRSCTL_RSEN);
- }
+ /* configure command register */
+ EXMC_SDCMD = (uint32_t)((exmc_sdram_command_init_struct->command) |
+ (exmc_sdram_command_init_struct->bank_select) |
+ ((exmc_sdram_command_init_struct->auto_refresh_number)) |
+ ((exmc_sdram_command_init_struct->mode_register_content)<<SDCMD_MRC_OFFSET) );
}
/*!
- \brief deinitialize exmc SQPIPSRAM
- \param[in] none
+ \brief set auto-refresh interval
+ \param[in] exmc_count: the number SDRAM clock cycles unit between two successive auto-refresh commands, 0x0000~0x1FFF
\param[out] none
\retval none
*/
-void exmc_sqpipsram_deinit(void)
+void exmc_sdram_refresh_count_set(uint32_t exmc_count)
{
- /* reset the registers */
- EXMC_SINIT = BANK0_SQPI_SINIT_RESET;
- EXMC_SRCMD = BANK0_SQPI_SRCMD_RESET;
- EXMC_SWCMD = BANK0_SQPI_SWCMD_RESET;
- EXMC_SIDL = BANK0_SQPI_SIDL_RESET;
- EXMC_SIDH = BANK0_SQPI_SIDH_RESET;
+ uint32_t sdari;
+ sdari = EXMC_SDARI & (~EXMC_SDARI_ARINTV);
+ EXMC_SDARI = sdari | (uint32_t)((exmc_count << SDARI_ARINTV_OFFSET) & EXMC_SDARI_ARINTV);
}
/*!
- \brief initialize EXMC SQPIPSRAM
- \param[in] exmc_sqpipsram_parameter_struct: configure the EXMC SQPIPSRAM parameter
- sample_polarity: EXMC_SDRAM_SAMPLE_RISING_EDGE,EXMC_SDRAM_SAMPLE_FALLING_EDGE
- id_length: EXMC_SQPIPSRAM_ID_LENGTH_xB,x=8,16,32,64
- address_bits: EXMC_SQPIPSRAM_ADDR_LENGTH_xB,x=1..26
- command_bits: EXMC_SQPIPSRAM_COMMAND_LENGTH_xB,x=4,8,16
+ \brief set the number of successive auto-refresh command
+ \param[in] exmc_number: the number of successive Auto-refresh cycles will be send, 1~15
\param[out] none
\retval none
*/
-void exmc_sqpipsram_init(exmc_sqpipsram_parameter_struct* exmc_sqpipsram_init_struct)
+void exmc_sdram_autorefresh_number_set(uint32_t exmc_number)
{
- /* initialize SQPI controller */
- EXMC_SINIT = (uint32_t)exmc_sqpipsram_init_struct->sample_polarity |
- exmc_sqpipsram_init_struct->id_length |
- exmc_sqpipsram_init_struct->address_bits |
- exmc_sqpipsram_init_struct->command_bits;
+ uint32_t sdcmd;
+ sdcmd = EXMC_SDCMD & (~EXMC_SDCMD_NARF);
+ EXMC_SDCMD = sdcmd | (uint32_t)((exmc_number << SDCMD_NARF_OFFSET) & EXMC_SDCMD_NARF) ;
}
/*!
- \brief initialize the struct exmc_sqpipsram_parameter_struct
- \param[in] the struct exmc_sqpipsram_parameter_struct pointer
+ \brief config the write protection function
+ \param[in] exmc_sdram_device: specifie the SDRAM device
+ only one parameter can be selected which is shown as below:
+ \arg EXMC_SDRAM_DEVICEx(x=0,1)
+ \param[in] newvalue: ENABLE or DISABLE
\param[out] none
\retval none
*/
-void exmc_sqpipsram_parameter_init(exmc_sqpipsram_parameter_struct* exmc_sqpipsram_init_struct)
+void exmc_sdram_write_protection_config(uint32_t exmc_sdram_device, ControlStatus newvalue)
{
- /* configure the structure with default value */
- exmc_sqpipsram_init_struct->sample_polarity = EXMC_SDRAM_SAMPLE_RISING_EDGE;
- exmc_sqpipsram_init_struct->id_length = EXMC_SQPIPSRAM_ID_LENGTH_64B;
- exmc_sqpipsram_init_struct->address_bits = EXMC_SQPIPSRAM_ADDR_LENGTH_24B;
- exmc_sqpipsram_init_struct->command_bits = EXMC_SQPIPSRAM_COMMAND_LENGTH_8B;
+ if (ENABLE == newvalue){
+ EXMC_SDCTL(exmc_sdram_device) |= (uint32_t)EXMC_SDCTL_WPEN;
+ }else{
+ EXMC_SDCTL(exmc_sdram_device) &= ~((uint32_t)EXMC_SDCTL_WPEN);
+ }
+
+}
+
+/*!
+ \brief get the status of SDRAM device0 or device1
+ \param[in] exmc_sdram_device: specifie the SDRAM device
+ only one parameter can be selected which is shown as below:
+ \arg EXMC_SDRAM_DEVICEx(x=0,1)
+ \param[out] none
+ \retval the status of SDRAM device
+*/
+uint32_t exmc_sdram_bankstatus_get(uint32_t exmc_sdram_device)
+{
+ uint32_t sdstat = 0U;
+
+ if(EXMC_SDRAM_DEVICE0 == exmc_sdram_device){
+ sdstat = ((uint32_t)(EXMC_SDSTAT & EXMC_SDSDAT_STA0) >> SDSTAT_STA0_OFFSET);
+ }else{
+ sdstat = ((uint32_t)(EXMC_SDSTAT & EXMC_SDSDAT_STA1) >> SDSTAT_STA1_OFFSET);
+ }
+
+ return sdstat;
}
/*!
\brief set the read command
\param[in] read_command_mode: configure SPI PSRAM read command mode
+ only one parameter can be selected which is shown as below:
\arg EXMC_SQPIPSRAM_READ_MODE_DISABLE: not SPI mode
\arg EXMC_SQPIPSRAM_READ_MODE_SPI: SPI mode
\arg EXMC_SQPIPSRAM_READ_MODE_SQPI: SQPI mode
@@ -843,10 +928,10 @@ void exmc_sqpipsram_parameter_init(exmc_sqpipsram_parameter_struct* exmc_sqpipsr
\param[out] none
\retval none
*/
-void exmc_sqpipsram_read_command_set(uint32_t read_command_mode,uint32_t read_wait_cycle,uint32_t read_command_code)
+void exmc_sqpipsram_read_command_set(uint32_t read_command_mode,uint32_t read_wait_cycle, uint32_t read_command_code)
{
uint32_t srcmd;
-
+
srcmd = (uint32_t) read_command_mode |
((read_wait_cycle << SRCMD_RWAITCYCLE_OFFSET) & EXMC_SRCMD_RWAITCYCLE) |
((read_command_code & EXMC_SRCMD_RCMD));
@@ -856,6 +941,7 @@ void exmc_sqpipsram_read_command_set(uint32_t read_command_mode,uint32_t read_wa
/*!
\brief set the write command
\param[in] write_command_mode: configure SPI PSRAM write command mode
+ only one parameter can be selected which is shown as below:
\arg EXMC_SQPIPSRAM_WRITE_MODE_DISABLE: not SPI mode
\arg EXMC_SQPIPSRAM_WRITE_MODE_SPI: SPI mode
\arg EXMC_SQPIPSRAM_WRITE_MODE_SQPI: SQPI mode
@@ -865,10 +951,10 @@ void exmc_sqpipsram_read_command_set(uint32_t read_command_mode,uint32_t read_wa
\param[out] none
\retval none
*/
-void exmc_sqpipsram_write_command_set(uint32_t write_command_mode,uint32_t write_wait_cycle,uint32_t write_command_code)
+void exmc_sqpipsram_write_command_set(uint32_t write_command_mode,uint32_t write_wait_cycle, uint32_t write_command_code)
{
uint32_t swcmd;
-
+
swcmd = (uint32_t) write_command_mode |
((write_wait_cycle << SWCMD_WWAITCYCLE_OFFSET) & EXMC_SWCMD_WWAITCYCLE) |
((write_command_code & EXMC_SWCMD_WCMD));
@@ -922,6 +1008,7 @@ uint32_t exmc_sqpipsram_high_id_get(void)
/*!
\brief get the bit value of EXMC send write command bit or read ID command
\param[in] send_command_flag: the send command flag
+ only one parameter can be selected which is shown as below:
\arg EXMC_SEND_COMMAND_FLAG_RDID: EXMC_SRCMD_RDID flag bit
\arg EXMC_SEND_COMMAND_FLAG_SC: EXMC_SWCMD_SC flag bit
\param[out] none
@@ -930,14 +1017,14 @@ uint32_t exmc_sqpipsram_high_id_get(void)
FlagStatus exmc_sqpipsram_send_command_state_get(uint32_t send_command_flag)
{
uint32_t flag = 0x00000000U;
-
+
if(EXMC_SEND_COMMAND_FLAG_RDID == send_command_flag){
flag = EXMC_SRCMD;
}else if(EXMC_SEND_COMMAND_FLAG_SC == send_command_flag){
flag = EXMC_SWCMD;
}else{
}
-
+
if (flag & send_command_flag){
/* flag is set */
return SET;
@@ -948,14 +1035,74 @@ FlagStatus exmc_sqpipsram_send_command_state_get(uint32_t send_command_flag)
}
/*!
- \brief check EXMC flag is set or not
+ \brief enable EXMC interrupt
+ \param[in] exmc_bank: specifies the NAND bank,PC card bank or SDRAM device
+ only one parameter can be selected which is shown as below:
+ \arg EXMC_BANK1_NAND: the NAND bank1
+ \arg EXMC_BANK2_NAND: the NAND bank2
+ \arg EXMC_BANK3_PCCARD: the PC card bank
+ \arg EXMC_SDRAM_DEVICE0: the SDRAM device0
+ \arg EXMC_SDRAM_DEVICE1: the SDRAM device1
+ \param[in] interrupt: specify get which interrupt flag
+ only one parameter can be selected which is shown as below:
+ \arg EXMC_NAND_PCCARD_INT_FLAG_RISE: rising edge interrupt and flag
+ \arg EXMC_NAND_PCCARD_INT_FLAG_LEVEL: high-level interrupt and flag
+ \arg EXMC_NAND_PCCARD_INT_FLAG_FALL: falling edge interrupt and flag
+ \arg EXMC_SDRAM_INT_FLAG_REFRESH: refresh error interrupt and flag
+ \param[out] none
+ \retval none
+*/
+void exmc_interrupt_enable(uint32_t exmc_bank, uint32_t interrupt)
+{
+ if((EXMC_BANK1_NAND == exmc_bank) || (EXMC_BANK2_NAND == exmc_bank) || (EXMC_BANK3_PCCARD == exmc_bank)){
+ /* NAND bank1,bank2 or PC card bank3 */
+ EXMC_NPINTEN(exmc_bank) |= interrupt;
+ }else{
+ /* SDRAM device0 or device1 */
+ EXMC_SDARI |= EXMC_SDARI_REIE;
+ }
+}
+
+/*!
+ \brief disable EXMC interrupt
+ \param[in] exmc_bank: specifies the NAND bank , PC card bank or SDRAM device
+ only one parameter can be selected which is shown as below:
+ \arg EXMC_BANK1_NAND: the NAND bank1
+ \arg EXMC_BANK2_NAND: the NAND bank2
+ \arg EXMC_BANK3_PCCARD: the PC card bank
+ \arg EXMC_SDRAM_DEVICE0: the SDRAM device0
+ \arg EXMC_SDRAM_DEVICE1: the SDRAM device1
+ \param[in] interrupt: specify get which interrupt flag
+ only one parameter can be selected which is shown as below:
+ \arg EXMC_NAND_PCCARD_INT_FLAG_RISE: rising edge interrupt and flag
+ \arg EXMC_NAND_PCCARD_INT_FLAG_LEVEL: high-level interrupt and flag
+ \arg EXMC_NAND_PCCARD_INT_FLAG_FALL: falling edge interrupt and flag
+ \arg EXMC_SDRAM_INT_FLAG_REFRESH: refresh error interrupt and flag
+ \param[out] none
+ \retval none
+*/
+void exmc_interrupt_disable(uint32_t exmc_bank, uint32_t interrupt)
+{
+ if((EXMC_BANK1_NAND == exmc_bank) || (EXMC_BANK2_NAND == exmc_bank) || (EXMC_BANK3_PCCARD == exmc_bank)){
+ /* NAND bank1,bank2 or PC card bank3 */
+ EXMC_NPINTEN(exmc_bank) &= ~interrupt;
+ }else{
+ /* SDRAM device0 or device1 */
+ EXMC_SDARI &= ~EXMC_SDARI_REIE;
+ }
+}
+
+/*!
+ \brief get EXMC flag status
\param[in] exmc_bank: specifies the NAND bank , PC card bank or SDRAM device
+ only one parameter can be selected which is shown as below:
\arg EXMC_BANK1_NAND: the NAND bank1
\arg EXMC_BANK2_NAND: the NAND bank2
\arg EXMC_BANK3_PCCARD: the PC Card bank
\arg EXMC_SDRAM_DEVICE0: the SDRAM device0
\arg EXMC_SDRAM_DEVICE1: the SDRAM device1
- \param[in] flag: specify get which flag
+ \param[in] flag: EXMC status and flag
+ only one parameter can be selected which is shown as below:
\arg EXMC_NAND_PCCARD_FLAG_RISE: interrupt rising edge status
\arg EXMC_NAND_PCCARD_FLAG_LEVEL: interrupt high-level status
\arg EXMC_NAND_PCCARD_FLAG_FALL: interrupt falling edge status
@@ -976,7 +1123,7 @@ FlagStatus exmc_flag_get(uint32_t exmc_bank,uint32_t flag)
/* SDRAM device0 or device1 */
status = EXMC_SDSTAT;
}
-
+
if ((status & flag) != (uint32_t)flag ){
/* flag is reset */
return RESET;
@@ -987,14 +1134,16 @@ FlagStatus exmc_flag_get(uint32_t exmc_bank,uint32_t flag)
}
/*!
- \brief clear EXMC a channel flag
+ \brief clear EXMC flag status
\param[in] exmc_bank: specifie the NAND bank , PCCARD bank or SDRAM device
+ only one parameter can be selected which is shown as below:
\arg EXMC_BANK1_NAND: the NAND bank1
\arg EXMC_BANK2_NAND: the NAND bank2
\arg EXMC_BANK3_PCCARD: the PC card bank
\arg EXMC_SDRAM_DEVICE0: the SDRAM device0
\arg EXMC_SDRAM_DEVICE1: the SDRAM device1
- \param[in] flag: specify get which flag
+ \param[in] flag: EXMC status and flag
+ only one parameter can be selected which is shown as below:
\arg EXMC_NAND_PCCARD_FLAG_RISE: interrupt rising edge status
\arg EXMC_NAND_PCCARD_FLAG_LEVEL: interrupt high-level status
\arg EXMC_NAND_PCCARD_FLAG_FALL: interrupt falling edge status
@@ -1004,7 +1153,7 @@ FlagStatus exmc_flag_get(uint32_t exmc_bank,uint32_t flag)
\param[out] none
\retval none
*/
-void exmc_flag_clear(uint32_t exmc_bank,uint32_t flag)
+void exmc_flag_clear(uint32_t exmc_bank, uint32_t flag)
{
if((EXMC_BANK1_NAND == exmc_bank) || (EXMC_BANK2_NAND == exmc_bank) || (EXMC_BANK3_PCCARD == exmc_bank)){
/* NAND bank1,bank2 or PC card bank3 */
@@ -1012,40 +1161,42 @@ void exmc_flag_clear(uint32_t exmc_bank,uint32_t flag)
}else{
/* SDRAM device0 or device1 */
EXMC_SDSTAT &= ~flag;
- }
+ }
}
/*!
- \brief check EXMC interrupt flag is set or not
+ \brief get EXMC interrupt flag
\param[in] exmc_bank: specifies the NAND bank , PC card bank or SDRAM device
+ only one parameter can be selected which is shown as below:
\arg EXMC_BANK1_NAND: the NAND bank1
\arg EXMC_BANK2_NAND: the NAND bank2
\arg EXMC_BANK3_PCCARD: the PC card bank
\arg EXMC_SDRAM_DEVICE0: the SDRAM device0
\arg EXMC_SDRAM_DEVICE1: the SDRAM device1
- \param[in] interrupt_source: specify get which interrupt flag
- \arg EXMC_NAND_PCCARD_INT_RISE: interrupt source of rising edge
- \arg EXMC_NAND_PCCARD_INT_LEVEL: interrupt source of high-level
- \arg EXMC_NAND_PCCARD_INT_FALL: interrupt source of falling edge
- \arg EXMC_SDRAM_INT_REFRESH: interrupt source of refresh error
+ \param[in] interrupt: EXMC interrupt flag
+ only one parameter can be selected which is shown as below:
+ \arg EXMC_NAND_PCCARD_INT_FLAG_RISE: rising edge interrupt and flag
+ \arg EXMC_NAND_PCCARD_INT_FLAG_LEVEL: high-level interrupt and flag
+ \arg EXMC_NAND_PCCARD_INT_FLAG_FALL: falling edge interrupt and flag
+ \arg EXMC_SDRAM_INT_FLAG_REFRESH: refresh error interrupt and flag
\param[out] none
\retval FlagStatus: SET or RESET
*/
-FlagStatus exmc_interrupt_flag_get(uint32_t exmc_bank,uint32_t interrupt_source)
+FlagStatus exmc_interrupt_flag_get(uint32_t exmc_bank, uint32_t interrupt)
{
uint32_t status = 0x00000000U,interrupt_enable = 0x00000000U,interrupt_state = 0x00000000U;
if((EXMC_BANK1_NAND == exmc_bank) || (EXMC_BANK2_NAND == exmc_bank) || (EXMC_BANK3_PCCARD == exmc_bank)){
/* NAND bank1,bank2 or PC card bank3 */
status = EXMC_NPINTEN(exmc_bank);
- interrupt_enable = (status & (interrupt_source >> INTEN_INTEN_OFFSET));
+ interrupt_state = (status & (interrupt >> INTEN_INTS_OFFSET));
}else{
/* SDRAM device0 or device1 */
status = EXMC_SDARI;
- interrupt_enable = (EXMC_SDSTAT & EXMC_SDSDAT_REIF);
+ interrupt_state = (EXMC_SDSTAT & EXMC_SDSDAT_REIF);
}
- interrupt_state = (status & interrupt_source);
+ interrupt_enable = (status & interrupt);
if ((interrupt_enable) && (interrupt_state)){
/* interrupt flag is set */
@@ -1057,82 +1208,30 @@ FlagStatus exmc_interrupt_flag_get(uint32_t exmc_bank,uint32_t interrupt_source)
}
/*!
- \brief clear EXMC one channel interrupt flag
+ \brief clear EXMC interrupt flag
\param[in] exmc_bank: specifies the NAND bank , PC card bank or SDRAM device
+ only one parameter can be selected which is shown as below:
\arg EXMC_BANK1_NAND: the NAND bank1
\arg EXMC_BANK2_NAND: the NAND bank2
\arg EXMC_BANK3_PCCARD: the PC card bank
\arg EXMC_SDRAM_DEVICE0: the SDRAM device0
\arg EXMC_SDRAM_DEVICE1: the SDRAM device1
- \param[in] interrupt_source: specify get which interrupt flag
- \arg EXMC_NAND_PCCARD_INT_RISE: interrupt source of rising edge
- \arg EXMC_NAND_PCCARD_INT_LEVEL: interrupt source of high-level
- \arg EXMC_NAND_PCCARD_INT_FALL: interrupt source of falling edge
- \arg EXMC_SDRAM_INT_REFRESH: interrupt source of refresh error
+ \param[in] interrupt: EXMC interrupt flag
+ only one parameter can be selected which is shown as below:
+ \arg EXMC_NAND_PCCARD_INT_FLAG_RISE: rising edge interrupt and flag
+ \arg EXMC_NAND_PCCARD_INT_FLAG_LEVEL: high-level interrupt and flag
+ \arg EXMC_NAND_PCCARD_INT_FLAG_FALL: falling edge interrupt and flag
+ \arg EXMC_SDRAM_INT_FLAG_REFRESH: refresh error interrupt and flag
\param[out] none
\retval none
*/
-void exmc_interrupt_flag_clear(uint32_t exmc_bank,uint32_t interrupt_source)
+void exmc_interrupt_flag_clear(uint32_t exmc_bank, uint32_t interrupt)
{
if((EXMC_BANK1_NAND == exmc_bank) || (EXMC_BANK2_NAND == exmc_bank) || (EXMC_BANK3_PCCARD == exmc_bank)){
/* NAND bank1,bank2 or PC card bank3 */
- EXMC_NPINTEN(exmc_bank) &= ~(interrupt_source >> INTEN_INTEN_OFFSET);
+ EXMC_NPINTEN(exmc_bank) &= ~(interrupt >> INTEN_INTS_OFFSET);
}else{
/* SDRAM device0 or device1 */
EXMC_SDARI |= EXMC_SDARI_REC;
}
}
-
-/*!
- \brief enable EXMC interrupt
- \param[in] exmc_bank: specifies the NAND bank,PC card bank or SDRAM device
- \arg EXMC_BANK1_NAND: the NAND bank1
- \arg EXMC_BANK2_NAND: the NAND bank2
- \arg EXMC_BANK3_PCCARD: the PC card bank
- \arg EXMC_SDRAM_DEVICE0: the SDRAM device0
- \arg EXMC_SDRAM_DEVICE1: the SDRAM device1
- \param[in] interrupt_source: specify get which interrupt flag
- \arg EXMC_NAND_PCCARD_INT_RISE: interrupt source of rising edge
- \arg EXMC_NAND_PCCARD_INT_LEVEL: interrupt source of high-level
- \arg EXMC_NAND_PCCARD_INT_FALL: interrupt source of falling edge
- \arg EXMC_SDRAM_INT_REFRESH: interrupt source of refresh error
- \param[out] none
- \retval none
-*/
-void exmc_interrupt_enable(uint32_t exmc_bank,uint32_t interrupt_source)
-{
- if((EXMC_BANK1_NAND == exmc_bank) || (EXMC_BANK2_NAND == exmc_bank) || (EXMC_BANK3_PCCARD == exmc_bank)){
- /* NAND bank1,bank2 or PC card bank3 */
- EXMC_NPINTEN(exmc_bank) |= interrupt_source;
- }else{
- /* SDRAM device0 or device1 */
- EXMC_SDARI |= EXMC_SDARI_REIE;
- }
-}
-
-/*!
- \brief disable EXMC interrupt
- \param[in] exmc_bank: specifies the NAND bank , PC card bank or SDRAM device
- \arg EXMC_BANK1_NAND: the NAND bank1
- \arg EXMC_BANK2_NAND: the NAND bank2
- \arg EXMC_BANK3_PCCARD: the PC card bank
- \arg EXMC_SDRAM_DEVICE0: the SDRAM device0
- \arg EXMC_SDRAM_DEVICE1: the SDRAM device1
- \param[in] interrupt_source: specify get which interrupt flag
- \arg EXMC_NAND_PCCARD_INT_RISE: interrupt source of rising edge
- \arg EXMC_NAND_PCCARD_INT_LEVEL: interrupt source of high-level
- \arg EXMC_NAND_PCCARD_INT_FALL: interrupt source of falling edge
- \arg EXMC_SDRAM_INT_REFRESH: interrupt source of refresh error
- \param[out] none
- \retval none
-*/
-void exmc_interrupt_disable(uint32_t exmc_bank,uint32_t interrupt_source)
-{
- if((EXMC_BANK1_NAND == exmc_bank) || (EXMC_BANK2_NAND == exmc_bank) || (EXMC_BANK3_PCCARD == exmc_bank)){
- /* NAND bank1,bank2 or PC card bank3 */
- EXMC_NPINTEN(exmc_bank) &= ~interrupt_source;
- }else{
- /* SDRAM device0 or device1 */
- EXMC_SDARI &= ~EXMC_SDARI_REIE;
- }
-}
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_exti.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_exti.c
index 24bffea316..a3eacb0202 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_exti.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_exti.c
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_exti.c
- \brief EXTI driver
+ \file gd32f4xx_exti.c
+ \brief EXTI driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.1, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#include "gd32f4xx_exti.h"
@@ -41,6 +66,7 @@ void exti_deinit(void)
\arg EXTI_TRIG_RISING: rising edge trigger
\arg EXTI_TRIG_FALLING: falling trigger
\arg EXTI_TRIG_BOTH: rising and falling trigger
+ \arg EXTI_TRIG_NONE: without rising edge or falling edge trigger
\param[out] none
\retval none
*/
@@ -53,7 +79,7 @@ void exti_init(exti_line_enum linex, \
EXTI_EVEN &= ~(uint32_t)linex;
EXTI_RTEN &= ~(uint32_t)linex;
EXTI_FTEN &= ~(uint32_t)linex;
-
+
/* set the EXTI mode and enable the interrupts or events from EXTI line x */
switch(mode){
case EXTI_INTERRUPT:
@@ -65,7 +91,7 @@ void exti_init(exti_line_enum linex, \
default:
break;
}
-
+
/* set the EXTI trigger type */
switch(trig_type){
case EXTI_TRIG_RISING:
@@ -80,6 +106,7 @@ void exti_init(exti_line_enum linex, \
EXTI_RTEN |= (uint32_t)linex;
EXTI_FTEN |= (uint32_t)linex;
break;
+ case EXTI_TRIG_NONE:
default:
break;
}
@@ -99,29 +126,29 @@ void exti_interrupt_enable(exti_line_enum linex)
}
/*!
- \brief enable the events from EXTI line x
+ \brief disable the interrupt from EXTI line x
\param[in] linex: EXTI line number, refer to exti_line_enum
only one parameter can be selected which is shown as below:
\arg EXTI_x (x=0..22): EXTI line x
\param[out] none
\retval none
*/
-void exti_event_enable(exti_line_enum linex)
+void exti_interrupt_disable(exti_line_enum linex)
{
- EXTI_EVEN |= (uint32_t)linex;
+ EXTI_INTEN &= ~(uint32_t)linex;
}
/*!
- \brief disable the interrupt from EXTI line x
+ \brief enable the events from EXTI line x
\param[in] linex: EXTI line number, refer to exti_line_enum
only one parameter can be selected which is shown as below:
\arg EXTI_x (x=0..22): EXTI line x
\param[out] none
\retval none
*/
-void exti_interrupt_disable(exti_line_enum linex)
+void exti_event_enable(exti_line_enum linex)
{
- EXTI_INTEN &= ~(uint32_t)linex;
+ EXTI_EVEN |= (uint32_t)linex;
}
/*!
@@ -138,51 +165,42 @@ void exti_event_disable(exti_line_enum linex)
}
/*!
- \brief get EXTI lines flag
+ \brief enable EXTI software interrupt event
\param[in] linex: EXTI line number, refer to exti_line_enum
only one parameter can be selected which is shown as below:
\arg EXTI_x (x=0..22): EXTI line x
\param[out] none
- \retval FlagStatus: status of flag (RESET or SET)
+ \retval none
*/
-FlagStatus exti_flag_get(exti_line_enum linex)
+void exti_software_interrupt_enable(exti_line_enum linex)
{
- if(RESET != (EXTI_PD & (uint32_t)linex)){
- return SET;
- }else{
- return RESET;
- }
+ EXTI_SWIEV |= (uint32_t)linex;
}
/*!
- \brief clear EXTI lines pending flag
+ \brief disable EXTI software interrupt event
\param[in] linex: EXTI line number, refer to exti_line_enum
only one parameter can be selected which is shown as below:
\arg EXTI_x (x=0..22): EXTI line x
\param[out] none
\retval none
*/
-void exti_flag_clear(exti_line_enum linex)
+void exti_software_interrupt_disable(exti_line_enum linex)
{
- EXTI_PD = (uint32_t)linex;
+ EXTI_SWIEV &= ~(uint32_t)linex;
}
/*!
- \brief get EXTI lines flag when the interrupt flag is set
+ \brief get EXTI lines flag
\param[in] linex: EXTI line number, refer to exti_line_enum
only one parameter can be selected which is shown as below:
\arg EXTI_x (x=0..22): EXTI line x
\param[out] none
\retval FlagStatus: status of flag (RESET or SET)
*/
-FlagStatus exti_interrupt_flag_get(exti_line_enum linex)
+FlagStatus exti_flag_get(exti_line_enum linex)
{
- uint32_t flag_left, flag_right;
-
- flag_left = EXTI_PD & (uint32_t)linex;
- flag_right = EXTI_INTEN & (uint32_t)linex;
-
- if((RESET != flag_left) && (RESET != flag_right)){
+ if(RESET != (EXTI_PD & (uint32_t)linex)){
return SET;
}else{
return RESET;
@@ -197,33 +215,43 @@ FlagStatus exti_interrupt_flag_get(exti_line_enum linex)
\param[out] none
\retval none
*/
-void exti_interrupt_flag_clear(exti_line_enum linex)
+void exti_flag_clear(exti_line_enum linex)
{
EXTI_PD = (uint32_t)linex;
}
/*!
- \brief enable EXTI software interrupt event
+ \brief get EXTI lines flag when the interrupt flag is set
\param[in] linex: EXTI line number, refer to exti_line_enum
only one parameter can be selected which is shown as below:
\arg EXTI_x (x=0..22): EXTI line x
\param[out] none
- \retval none
+ \retval FlagStatus: status of flag (RESET or SET)
*/
-void exti_software_interrupt_enable(exti_line_enum linex)
+FlagStatus exti_interrupt_flag_get(exti_line_enum linex)
{
- EXTI_SWIEV |= (uint32_t)linex;
+ uint32_t flag_left, flag_right;
+
+ flag_left = EXTI_PD & (uint32_t)linex;
+ flag_right = EXTI_INTEN & (uint32_t)linex;
+
+ if((RESET != flag_left) && (RESET != flag_right)){
+ return SET;
+ }else{
+ return RESET;
+ }
}
/*!
- \brief disable EXTI software interrupt event
+ \brief clear EXTI lines pending flag
\param[in] linex: EXTI line number, refer to exti_line_enum
only one parameter can be selected which is shown as below:
\arg EXTI_x (x=0..22): EXTI line x
\param[out] none
\retval none
*/
-void exti_software_interrupt_disable(exti_line_enum linex)
+void exti_interrupt_flag_clear(exti_line_enum linex)
{
- EXTI_SWIEV &= ~(uint32_t)linex;
+ EXTI_PD = (uint32_t)linex;
}
+
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_fmc.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_fmc.c
index 2bfc2f1caa..4e2b0db9a5 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_fmc.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_fmc.c
@@ -1,19 +1,46 @@
/*!
- \file gd32f4xx_fmc.c
- \brief FMC driver
+ \file gd32f4xx_fmc.c
+ \brief FMC driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
+
#include "gd32f4xx_fmc.h"
/*!
\brief set the wait state counter value
- \param[in] wscnt��wait state counter value
+ \param[in] wscnt: wait state counter value
+ only one parameter can be selected which is shown as below:
\arg WS_WSCNT_0: FMC 0 wait
\arg WS_WSCNT_1: FMC 1 wait
\arg WS_WSCNT_2: FMC 2 wait
@@ -36,7 +63,7 @@
void fmc_wscnt_set(uint32_t wscnt)
{
uint32_t reg;
-
+
reg = FMC_WS;
/* set the wait state counter value */
reg &= ~FMC_WC_WSCNT;
@@ -73,58 +100,64 @@ void fmc_lock(void)
/*!
\brief erase sector
\param[in] fmc_sector: select the sector to erase
- \arg CTL_SECTOR_NUMBER_0: sector 0
- \arg CTL_SECTOR_NUMBER_1: sector 1
- \arg CTL_SECTOR_NUMBER_2: sector 2
- \arg CTL_SECTOR_NUMBER_3: sector 3
- \arg CTL_SECTOR_NUMBER_4: sector 4
- \arg CTL_SECTOR_NUMBER_5: sector 5
- \arg CTL_SECTOR_NUMBER_6: sector 6
- \arg CTL_SECTOR_NUMBER_7: sector 7
- \arg CTL_SECTOR_NUMBER_8: sector 8
- \arg CTL_SECTOR_NUMBER_9: sector 9
- \arg CTL_SECTOR_NUMBER_10: sector 10
- \arg CTL_SECTOR_NUMBER_11: sector 11
- \arg CTL_SECTOR_NUMBER_12: sector 12
- \arg CTL_SECTOR_NUMBER_13: sector 13
- \arg CTL_SECTOR_NUMBER_14: sector 14
- \arg CTL_SECTOR_NUMBER_15: sector 15
- \arg CTL_SECTOR_NUMBER_16: sector 16
- \arg CTL_SECTOR_NUMBER_17: sector 17
- \arg CTL_SECTOR_NUMBER_18: sector 18
- \arg CTL_SECTOR_NUMBER_19: sector 19
- \arg CTL_SECTOR_NUMBER_20: sector 20
- \arg CTL_SECTOR_NUMBER_21: sector 21
- \arg CTL_SECTOR_NUMBER_22: sector 22
- \arg CTL_SECTOR_NUMBER_23: sector 23
- \arg CTL_SECTOR_NUMBER_24: sector 24
- \arg CTL_SECTOR_NUMBER_25: sector 25
- \arg CTL_SECTOR_NUMBER_26: sector 26
- \arg CTL_SECTOR_NUMBER_27: sector 27
- \arg CTL_SECTOR_NUMBER_28: sector 28
- \arg CTL_SECTOR_NUMBER_29: sector 29
- \arg CTL_SECTOR_NUMBER_30: sector 30
+ only one parameter can be selected which is shown as below:
+ \arg CTL_SECTOR_NUMBER_0: sector 0
+ \arg CTL_SECTOR_NUMBER_1: sector 1
+ \arg CTL_SECTOR_NUMBER_2: sector 2
+ \arg CTL_SECTOR_NUMBER_3: sector 3
+ \arg CTL_SECTOR_NUMBER_4: sector 4
+ \arg CTL_SECTOR_NUMBER_5: sector 5
+ \arg CTL_SECTOR_NUMBER_6: sector 6
+ \arg CTL_SECTOR_NUMBER_7: sector 7
+ \arg CTL_SECTOR_NUMBER_8: sector 8
+ \arg CTL_SECTOR_NUMBER_9: sector 9
+ \arg CTL_SECTOR_NUMBER_10: sector 10
+ \arg CTL_SECTOR_NUMBER_11: sector 11
+ \arg CTL_SECTOR_NUMBER_12: sector 12
+ \arg CTL_SECTOR_NUMBER_13: sector 13
+ \arg CTL_SECTOR_NUMBER_14: sector 14
+ \arg CTL_SECTOR_NUMBER_15: sector 15
+ \arg CTL_SECTOR_NUMBER_16: sector 16
+ \arg CTL_SECTOR_NUMBER_17: sector 17
+ \arg CTL_SECTOR_NUMBER_18: sector 18
+ \arg CTL_SECTOR_NUMBER_19: sector 19
+ \arg CTL_SECTOR_NUMBER_20: sector 20
+ \arg CTL_SECTOR_NUMBER_21: sector 21
+ \arg CTL_SECTOR_NUMBER_22: sector 22
+ \arg CTL_SECTOR_NUMBER_23: sector 23
+ \arg CTL_SECTOR_NUMBER_24: sector 24
+ \arg CTL_SECTOR_NUMBER_25: sector 25
+ \arg CTL_SECTOR_NUMBER_26: sector 26
+ \arg CTL_SECTOR_NUMBER_27: sector 27
\param[out] none
- \retval fmc_state_enum
+ \retval state of FMC
+ \arg FMC_READY: the operation has been completed
+ \arg FMC_BUSY: the operation is in progress
+ \arg FMC_RDDERR: read D-bus protection error
+ \arg FMC_PGSERR: program sequence error
+ \arg FMC_PGMERR: program size not match error
+ \arg FMC_WPERR: erase/program protection error
+ \arg FMC_OPERR: operation error
+ \arg FMC_PGERR: program error
*/
fmc_state_enum fmc_sector_erase(uint32_t fmc_sector)
{
fmc_state_enum fmc_state = FMC_READY;
/* wait for the FMC ready */
- fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
-
- if(FMC_READY == fmc_state){
+ fmc_state = fmc_ready_wait();
+
+ if(FMC_READY == fmc_state){
/* start sector erase */
FMC_CTL &= ~FMC_CTL_SN;
FMC_CTL |= (FMC_CTL_SER | fmc_sector);
FMC_CTL |= FMC_CTL_START;
/* wait for the FMC ready */
- fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
-
+ fmc_state = fmc_ready_wait();
+
/* reset the SER bit */
FMC_CTL &= (~FMC_CTL_SER);
- FMC_CTL &= ~FMC_CTL_SN;
+ FMC_CTL &= ~FMC_CTL_SN;
}
/* return the FMC state */
@@ -135,21 +168,29 @@ fmc_state_enum fmc_sector_erase(uint32_t fmc_sector)
\brief erase whole chip
\param[in] none
\param[out] none
- \retval fmc_state_enum
+ \retval state of FMC
+ \arg FMC_READY: the operation has been completed
+ \arg FMC_BUSY: the operation is in progress
+ \arg FMC_RDDERR: read D-bus protection error
+ \arg FMC_PGSERR: program sequence error
+ \arg FMC_PGMERR: program size not match error
+ \arg FMC_WPERR: erase/program protection error
+ \arg FMC_OPERR: operation error
+ \arg FMC_PGERR: program error
*/
fmc_state_enum fmc_mass_erase(void)
{
fmc_state_enum fmc_state = FMC_READY;
/* wait for the FMC ready */
- fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
+ fmc_state = fmc_ready_wait();
- if(FMC_READY == fmc_state){
- /* start whole chip erase */
+ if(FMC_READY == fmc_state){
+ /* start whole chip erase */
FMC_CTL |= (FMC_CTL_MER0 | FMC_CTL_MER1);
FMC_CTL |= FMC_CTL_START;
-
+
/* wait for the FMC ready */
- fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
+ fmc_state = fmc_ready_wait();
/* reset the MER bits */
FMC_CTL &= ~(FMC_CTL_MER0 | FMC_CTL_MER1);
@@ -163,21 +204,29 @@ fmc_state_enum fmc_mass_erase(void)
\brief erase all FMC sectors in bank0
\param[in] none
\param[out] none
- \retval fmc_state_enum
+ \retval state of FMC
+ \arg FMC_READY: the operation has been completed
+ \arg FMC_BUSY: the operation is in progress
+ \arg FMC_RDDERR: read D-bus protection error
+ \arg FMC_PGSERR: program sequence error
+ \arg FMC_PGMERR: program size not match error
+ \arg FMC_WPERR: erase/program protection error
+ \arg FMC_OPERR: operation error
+ \arg FMC_PGERR: program error
*/
fmc_state_enum fmc_bank0_erase(void)
{
fmc_state_enum fmc_state = FMC_READY;
/* wait for the FMC ready */
- fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
+ fmc_state = fmc_ready_wait();
if(FMC_READY == fmc_state){
/* start FMC bank0 erase */
FMC_CTL |= FMC_CTL_MER0;
FMC_CTL |= FMC_CTL_START;
-
+
/* wait for the FMC ready */
- fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
+ fmc_state = fmc_ready_wait();
/* reset the MER0 bit */
FMC_CTL &= (~FMC_CTL_MER0);
@@ -191,21 +240,29 @@ fmc_state_enum fmc_bank0_erase(void)
\brief erase all FMC sectors in bank1
\param[in] none
\param[out] none
- \retval fmc_state_enum
+ \retval state of FMC
+ \arg FMC_READY: the operation has been completed
+ \arg FMC_BUSY: the operation is in progress
+ \arg FMC_RDDERR: read D-bus protection error
+ \arg FMC_PGSERR: program sequence error
+ \arg FMC_PGMERR: program size not match error
+ \arg FMC_WPERR: erase/program protection error
+ \arg FMC_OPERR: operation error
+ \arg FMC_PGERR: program error
*/
fmc_state_enum fmc_bank1_erase(void)
{
fmc_state_enum fmc_state = FMC_READY;
/* wait for the FMC ready */
- fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
-
+ fmc_state = fmc_ready_wait();
+
if(FMC_READY == fmc_state){
/* start FMC bank1 erase */
FMC_CTL |= FMC_CTL_MER1;
FMC_CTL |= FMC_CTL_START;
-
+
/* wait for the FMC ready */
- fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
+ fmc_state = fmc_ready_wait();
/* reset the MER1 bit */
FMC_CTL &= (~FMC_CTL_MER1);
@@ -218,31 +275,39 @@ fmc_state_enum fmc_bank1_erase(void)
/*!
\brief program a word at the corresponding address
\param[in] address: address to program
- \param[in] data: word to program
+ \param[in] data: word to program(0x00000000 - 0xFFFFFFFF)
\param[out] none
- \retval fmc_state_enum
+ \retval state of FMC
+ \arg FMC_READY: the operation has been completed
+ \arg FMC_BUSY: the operation is in progress
+ \arg FMC_RDDERR: read D-bus protection error
+ \arg FMC_PGSERR: program sequence error
+ \arg FMC_PGMERR: program size not match error
+ \arg FMC_WPERR: erase/program protection error
+ \arg FMC_OPERR: operation error
+ \arg FMC_PGERR: program error
*/
fmc_state_enum fmc_word_program(uint32_t address, uint32_t data)
{
fmc_state_enum fmc_state = FMC_READY;
/* wait for the FMC ready */
- fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
-
+ fmc_state = fmc_ready_wait();
+
if(FMC_READY == fmc_state){
/* set the PG bit to start program */
FMC_CTL &= ~FMC_CTL_PSZ;
FMC_CTL |= CTL_PSZ_WORD;
- FMC_CTL |= FMC_CTL_PG;
-
+ FMC_CTL |= FMC_CTL_PG;
+
REG32(address) = data;
/* wait for the FMC ready */
- fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
-
+ fmc_state = fmc_ready_wait();
+
/* reset the PG bit */
- FMC_CTL &= ~FMC_CTL_PG;
- }
-
+ FMC_CTL &= ~FMC_CTL_PG;
+ }
+
/* return the FMC state */
return fmc_state;
}
@@ -250,31 +315,39 @@ fmc_state_enum fmc_word_program(uint32_t address, uint32_t data)
/*!
\brief program a half word at the corresponding address
\param[in] address: address to program
- \param[in] data: halfword to program
+ \param[in] data: halfword to program(0x0000 - 0xFFFF)
\param[out] none
- \retval fmc_state_enum
+ \retval state of FMC
+ \arg FMC_READY: the operation has been completed
+ \arg FMC_BUSY: the operation is in progress
+ \arg FMC_RDDERR: read D-bus protection error
+ \arg FMC_PGSERR: program sequence error
+ \arg FMC_PGMERR: program size not match error
+ \arg FMC_WPERR: erase/program protection error
+ \arg FMC_OPERR: operation error
+ \arg FMC_PGERR: program error
*/
fmc_state_enum fmc_halfword_program(uint32_t address, uint16_t data)
{
fmc_state_enum fmc_state = FMC_READY;
/* wait for the FMC ready */
- fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
-
- if(FMC_READY == fmc_state){
+ fmc_state = fmc_ready_wait();
+
+ if(FMC_READY == fmc_state){
/* set the PG bit to start program */
FMC_CTL &= ~FMC_CTL_PSZ;
FMC_CTL |= CTL_PSZ_HALF_WORD;
- FMC_CTL |= FMC_CTL_PG;
-
+ FMC_CTL |= FMC_CTL_PG;
+
REG16(address) = data;
/* wait for the FMC ready */
- fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
-
+ fmc_state = fmc_ready_wait();
+
/* reset the PG bit */
- FMC_CTL &= ~FMC_CTL_PG;
- }
-
+ FMC_CTL &= ~FMC_CTL_PG;
+ }
+
/* return the FMC state */
return fmc_state;
}
@@ -282,31 +355,39 @@ fmc_state_enum fmc_halfword_program(uint32_t address, uint16_t data)
/*!
\brief program a byte at the corresponding address
\param[in] address: address to program
- \param[in] data: byte to program
+ \param[in] data: byte to program(0x00 - 0xFF)
\param[out] none
- \retval fmc_state_enum
+ \retval state of FMC
+ \arg FMC_READY: the operation has been completed
+ \arg FMC_BUSY: the operation is in progress
+ \arg FMC_RDDERR: read D-bus protection error
+ \arg FMC_PGSERR: program sequence error
+ \arg FMC_PGMERR: program size not match error
+ \arg FMC_WPERR: erase/program protection error
+ \arg FMC_OPERR: operation error
+ \arg FMC_PGERR: program error
*/
fmc_state_enum fmc_byte_program(uint32_t address, uint8_t data)
{
fmc_state_enum fmc_state = FMC_READY;
/* wait for the FMC ready */
- fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
-
+ fmc_state = fmc_ready_wait();
+
if(FMC_READY == fmc_state){
/* set the PG bit to start program */
FMC_CTL &= ~FMC_CTL_PSZ;
FMC_CTL |= CTL_PSZ_BYTE;
FMC_CTL |= FMC_CTL_PG;
-
+
REG8(address) = data;
/* wait for the FMC ready */
- fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
-
+ fmc_state = fmc_ready_wait();
+
/* reset the PG bit */
- FMC_CTL &= ~FMC_CTL_PG;
- }
-
+ FMC_CTL &= ~FMC_CTL_PG;
+ }
+
/* return the FMC state */
return fmc_state;
}
@@ -335,7 +416,7 @@ void ob_unlock(void)
void ob_lock(void)
{
/* reset the OB_LK bit */
- FMC_OBCTL0 &= ~FMC_OBCTL0_OB_LK;
+ FMC_OBCTL0 |= FMC_OBCTL0_OB_LK;
}
/*!
@@ -346,178 +427,183 @@ void ob_lock(void)
*/
void ob_start(void)
{
+ fmc_state_enum fmc_state = FMC_READY;
/* set the OB_START bit in OBCTL0 register */
FMC_OBCTL0 |= FMC_OBCTL0_OB_START;
+ fmc_state = fmc_ready_wait();
+ if(FMC_READY != fmc_state){
+ while(1){
+ }
+ }
}
/*!
- \brief enable write protection
- \param[in] ob_wp: specify sector to be write protected
- \arg OB_WPx(x=0..11): write protect specify sector
- \arg OB_WP_ALL: write protect all sector
+ \brief erase option byte
+ \param[in] none
\param[out] none
\retval none
*/
-void ob_write_protection0_enable(uint32_t ob_wp)
+void ob_erase(void)
{
+ uint32_t reg, reg1;
fmc_state_enum fmc_state = FMC_READY;
/* wait for the FMC ready */
- fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
+ fmc_state = fmc_ready_wait();
if(FMC_READY == fmc_state){
- FMC_OBCTL0 &= (~((uint32_t)ob_wp << 16));
- }
-}
+ reg = FMC_OBCTL0;
+ reg1 = FMC_OBCTL1;
-/*!
- \brief disable write protection
- \param[in] ob_wp: specify sector to be write protected
- \arg OB_WPx(x=0..11): write protect specify sector
- \arg OB_WP_ALL: write protect all sector
- \param[out] none
- \retval none
-*/
-void ob_write_protection0_disable(uint32_t ob_wp)
-{
- fmc_state_enum fmc_state = FMC_READY;
- /* wait for the FMC ready */
- fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
+ /* reset the OB_FWDGT, OB_DEEPSLEEP and OB_STDBY, set according to ob_fwdgt ,ob_deepsleep and ob_stdby */
+ reg |= (FMC_OBCTL0_NWDG_HW | FMC_OBCTL0_NRST_DPSLP | FMC_OBCTL0_NRST_STDBY);
+ /* reset the BOR level */
+ reg |= FMC_OBCTL0_BOR_TH;
+ /* reset option byte boot bank value */
+ reg &= ~FMC_OBCTL0_BB;
+ /* reset option byte dbs value */
+ reg &= ~FMC_OBCTL0_DBS;
- if(FMC_READY == fmc_state){
- FMC_OBCTL0 |= ((uint32_t)ob_wp << 16);
+ /* reset drp and wp value */
+ reg |= FMC_OBCTL0_WP0;
+ reg &= (~FMC_OBCTL0_DRP);
+ FMC_OBCTL0 = reg;
+
+ reg1 |= FMC_OBCTL1_WP1;
+ FMC_OBCTL1 = reg1;
+
+ FMC_OBCTL0 = reg;
}
}
/*!
\brief enable write protection
\param[in] ob_wp: specify sector to be write protected
- \arg OB_WPx(x=12..30): write protect specify sector
- \arg OB_WP_ALL: write protect all sector
+ one or more parameters can be selected which are shown as below:
+ \arg OB_WP_x(x=0..22):sector x(x = 0,1,2...22)
+ \arg OB_WP_23_27: sector23~27
+ \arg OB_WP_ALL: all sector
\param[out] none
\retval none
*/
-void ob_write_protection1_enable(uint32_t ob_wp)
+void ob_write_protection_enable(uint32_t ob_wp)
{
+ uint32_t reg0 = FMC_OBCTL0;
+ uint32_t reg1 = FMC_OBCTL1;
fmc_state_enum fmc_state = FMC_READY;
+ if(RESET != (FMC_OBCTL0 & FMC_OBCTL0_DRP)){
+ while(1){
+ }
+ }
/* wait for the FMC ready */
- fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
+ fmc_state = fmc_ready_wait();
if(FMC_READY == fmc_state){
- FMC_OBCTL1 &= (~((uint32_t)ob_wp << 16));
+ reg0 &= (~((uint32_t)ob_wp << 16));
+ reg1 &= (~(ob_wp & 0xFFFF0000U));
+ FMC_OBCTL0 = reg0;
+ FMC_OBCTL1 = reg1;
}
}
/*!
\brief disable write protection
\param[in] ob_wp: specify sector to be write protected
- \arg OB_WPx(x=12..30): write protect specify sector
- \arg OB_WP_ALL: write protect all sector
- \param[out] none
- \retval none
-*/
-void ob_write_protection1_disable(uint32_t ob_wp)
-{
- fmc_state_enum fmc_state = FMC_READY;
- /* wait for the FMC ready */
- fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
-
- if(FMC_READY == fmc_state){
- FMC_OBCTL1 |= ((uint32_t)ob_wp << 16);
- }
-}
-/*!
- \brief configure the protection mode
- \param[in] ob_drp: configure the protection mode of WPx bits
- \arg OB_DRP_DISABLE: the WPx bits used as erase/program protection of each sector
- \arg OB_DRP_ENABLE: the WPx bits used as erase/program protection and D-bus read protection of each sector
+ one or more parameters can be selected which are shown as below:
+ \arg OB_WP_x(x=0..22):sector x(x = 0,1,2...22)
+ \arg OB_WP_23_27: sector23~27
+ \arg OB_WP_ALL: all sector
\param[out] none
\retval none
*/
-void ob_drp_config(uint32_t ob_drp)
-{
- FMC_OBCTL0 &= ~FMC_OBCTL0_DRP;
- FMC_OBCTL0 |= ob_drp;
-}
-
-/*!
- \brief enable erase/program protection and D-bus read protection
- \param[in] ob_drp: enable the WPx bits used as erase/program protection and D-bus read protection of each sector
- \arg OB_DRPx(x=0..11): erase/program protection and D-bus read protection of specify sector
- \arg OB_DRP_ALL: erase/program protection and D-bus read protection of all sector
- \param[out] none
- \retval none
-*/
-void ob_drp0_enable(uint32_t ob_drp)
+void ob_write_protection_disable(uint32_t ob_wp)
{
+ uint32_t reg0 = FMC_OBCTL0;
+ uint32_t reg1 = FMC_OBCTL1;
fmc_state_enum fmc_state = FMC_READY;
- /* wait for the FMC ready */
- fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
-
- if(FMC_READY == fmc_state){
- FMC_OBCTL0 |= ((uint32_t)ob_drp << 16);
+ if(RESET != (FMC_OBCTL0 & FMC_OBCTL0_DRP)){
+ while(1){
+ }
}
-}
-
-/*!
- \brief disable erase/program protection and D-bus read protection
- \param[in] ob_drp: disable the WPx bits used as erase/program protection and D-bus read protection of each sector
- \arg OB_DRPx(x=0..11): erase/program protection and D-bus read protection of specify sector
- \arg OB_DRP_ALL: erase/program protection and D-bus read protection of all sector
- \param[out] none
- \retval none
-*/
-void ob_drp0_disable(uint32_t ob_drp)
-{
- fmc_state_enum fmc_state = FMC_READY;
/* wait for the FMC ready */
- fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
+ fmc_state = fmc_ready_wait();
if(FMC_READY == fmc_state){
- FMC_OBCTL0 &= (~((uint32_t)ob_drp << 16));
+ reg0 |= ((uint32_t)ob_wp << 16);
+ reg1 |= (ob_wp & 0xFFFF0000U);
+ FMC_OBCTL0 = reg0;
+ FMC_OBCTL1 = reg1;
}
}
/*!
\brief enable erase/program protection and D-bus read protection
- \param[in] ob_drp: enable the WPx bits used as erase/program protection and D-bus read protection of each sector
- \arg OB_DRPx(x=12..30): erase/program protection and D-bus read protection of specify sector
- \arg OB_DRP_ALL: erase/program protection and D-bus read protection of all sector
+ \param[in] ob_drp: enable the WPx bits used as erase/program protection and D-bus read protection of each sector
+ one or more parameters can be selected which are shown as below:
+ \arg OB_DRP_x(x=0..22): sector x(x = 0,1,2...22)
+ \arg OB_DRP_23_27: sector23~27
+ \arg OB_DRP_ALL: all sector
\param[out] none
\retval none
*/
-void ob_drp1_enable(uint32_t ob_drp)
+void ob_drp_enable(uint32_t ob_drp)
{
+ uint32_t reg0 = FMC_OBCTL0;
+ uint32_t reg1 = FMC_OBCTL1;
fmc_state_enum fmc_state = FMC_READY;
+ uint32_t drp_state = FMC_OBCTL0 & FMC_OBCTL0_DRP;
+ uint32_t wp0_state = FMC_OBCTL0 & FMC_OBCTL0_WP0;
+ uint32_t wp1_state = FMC_OBCTL1 & FMC_OBCTL1_WP1;
+ /*disable write protection before enable D-bus read protection*/
+ if((RESET != drp_state) && ((FMC_OBCTL0_WP0 != wp0_state) && (FMC_OBCTL1_WP1 != wp1_state))){
+ while(1){
+ }
+ }
/* wait for the FMC ready */
- fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
+ fmc_state = fmc_ready_wait();
if(FMC_READY == fmc_state){
- FMC_OBCTL1 |= ((uint32_t)ob_drp << 16);
+ reg0 &= ~FMC_OBCTL0_WP0;
+ reg1 &= ~FMC_OBCTL1_WP1;
+ reg0 |= ((uint32_t)ob_drp << 16);
+ reg1 |= ((uint32_t)ob_drp & 0xFFFF0000U);
+ FMC_OBCTL0 = reg0;
+ FMC_OBCTL1 = reg1;
+ FMC_OBCTL0 |= FMC_OBCTL0_DRP;
}
}
/*!
\brief disable erase/program protection and D-bus read protection
\param[in] ob_drp: disable the WPx bits used as erase/program protection and D-bus read protection of each sector
- \arg OB_DRPx(x=12..30): erase/program protection and D-bus read protection of specify sector
- \arg OB_DRP_ALL: erase/program protection and D-bus read protection of all sector
+ one or more parameters can be selected which are shown as below:
+ \arg OB_DRP_x(x=0..22): sector x(x = 0,1,2...22)
+ \arg OB_DRP_23_27: sector23~27
+ \arg OB_DRP_ALL: all sector
\param[out] none
\retval none
*/
-void ob_drp1_disable(uint32_t ob_drp)
+void ob_drp_disable(uint32_t ob_drp)
{
+ uint32_t reg0 = FMC_OBCTL0;
+ uint32_t reg1 = FMC_OBCTL1;
fmc_state_enum fmc_state = FMC_READY;
/* wait for the FMC ready */
- fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
+ fmc_state = fmc_ready_wait();
if(FMC_READY == fmc_state){
- FMC_OBCTL1 &= (~((uint32_t)ob_drp << 16));
+ reg0 |= FMC_OBCTL0_WP0;
+ reg0 &= (~FMC_OBCTL0_DRP);
+ FMC_OBCTL0 = reg0;
+
+ reg1 |= FMC_OBCTL1_WP1;
+ FMC_OBCTL1 = reg1;
}
}
/*!
\brief configure security protection level
\param[in] ob_spc: specify security protection level
+ only one parameter can be selected which is shown as below:
\arg FMC_NSPC: no security protection
\arg FMC_LSPC: low security protection
\arg FMC_HSPC: high security protection
@@ -528,29 +614,33 @@ void ob_security_protection_config(uint8_t ob_spc)
{
fmc_state_enum fmc_state = FMC_READY;
/* wait for the FMC ready */
- fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
+ fmc_state = fmc_ready_wait();
if(FMC_READY == fmc_state){
uint32_t reg;
-
+
reg = FMC_OBCTL0;
/* reset the OBCTL0_SPC, set according to ob_spc */
reg &= ~FMC_OBCTL0_SPC;
- FMC_OBCTL0 |= ((uint32_t)ob_spc << 8);
+ reg |= ((uint32_t)ob_spc << 8);
+ FMC_OBCTL0 = reg;
}
}
/*!
- \brief program the FMC user option byte
+ \brief program the FMC user option byte
\param[in] ob_fwdgt: option byte watchdog value
+ only one parameter can be selected which is shown as below:
\arg OB_FWDGT_SW: software free watchdog
\arg OB_FWDGT_HW: hardware free watchdog
\param[in] ob_deepsleep: option byte deepsleep reset value
+ only one parameter can be selected which is shown as below:
\arg OB_DEEPSLEEP_NRST: no reset when entering deepsleep mode
- \arg OB_DEEPSLEEP_RST: generate a reset instead of entering deepsleep mode
+ \arg OB_DEEPSLEEP_RST: generate a reset instead of entering deepsleep mode
\param[in] ob_stdby:option byte standby reset value
+ only one parameter can be selected which is shown as below:
\arg OB_STDBY_NRST: no reset when entering standby mode
- \arg OB_STDBY_RST: generate a reset instead of entering standby mode
+ \arg OB_STDBY_RST: generate a reset instead of entering standby mode
\param[out] none
\retval none
*/
@@ -559,11 +649,11 @@ void ob_user_write(uint32_t ob_fwdgt, uint32_t ob_deepsleep, uint32_t ob_stdby)
fmc_state_enum fmc_state = FMC_READY;
/* wait for the FMC ready */
- fmc_state = fmc_ready_wait(FMC_TIMEOUT_COUNT);
-
+ fmc_state = fmc_ready_wait();
+
if(FMC_READY == fmc_state){
uint32_t reg;
-
+
reg = FMC_OBCTL0;
/* reset the OB_FWDGT, OB_DEEPSLEEP and OB_STDBY, set according to ob_fwdgt ,ob_deepsleep and ob_stdby */
reg &= ~(FMC_OBCTL0_NWDG_HW | FMC_OBCTL0_NRST_DPSLP | FMC_OBCTL0_NRST_STDBY);
@@ -574,17 +664,18 @@ void ob_user_write(uint32_t ob_fwdgt, uint32_t ob_deepsleep, uint32_t ob_stdby)
/*!
\brief program the option byte BOR threshold value
\param[in] ob_bor_th: user option byte
+ only one parameter can be selected which is shown as below:
\arg OB_BOR_TH_VALUE3: BOR threshold value 3
\arg OB_BOR_TH_VALUE2: BOR threshold value 2
\arg OB_BOR_TH_VALUE1: BOR threshold value 1
- \arg OB_BOR_TH_OFF: no BOR function.
+ \arg OB_BOR_TH_OFF: no BOR function
\param[out] none
\retval none
*/
void ob_user_bor_threshold(uint32_t ob_bor_th)
{
uint32_t reg;
-
+
reg = FMC_OBCTL0;
/* set the BOR level */
reg &= ~FMC_OBCTL0_BOR_TH;
@@ -594,6 +685,7 @@ void ob_user_bor_threshold(uint32_t ob_bor_th)
/*!
\brief configure the option byte boot bank value
\param[in] boot_mode: specifies the option byte boot bank value
+ only one parameter can be selected which is shown as below:
\arg OB_BB_DISABLE: boot from bank0
\arg OB_BB_ENABLE: boot from bank1 or bank0 if bank1 is void
\param[out] none
@@ -602,7 +694,7 @@ void ob_user_bor_threshold(uint32_t ob_bor_th)
void ob_boot_mode_config(uint32_t boot_mode)
{
uint32_t reg;
-
+
reg = FMC_OBCTL0;
/* set option byte boot bank value */
reg &= ~FMC_OBCTL0_BB;
@@ -613,7 +705,7 @@ void ob_boot_mode_config(uint32_t boot_mode)
\brief get the FMC user option byte
\param[in] none
\param[out] none
- \retval the FMC user option byte values: ob_fwdgt(Bit0), ob_deepsleep(Bit1), ob_stdby(Bit2).
+ \retval the FMC user option byte values: ob_fwdgt(Bit0), ob_deepsleep(Bit1), ob_stdby(Bit2)
*/
uint8_t ob_user_get(void)
{
@@ -677,7 +769,7 @@ uint16_t ob_drp1_get(void)
FlagStatus ob_spc_get(void)
{
FlagStatus spc_state = RESET;
-
+
if (((uint8_t)(FMC_OBCTL0 >> 8)) != (uint8_t)FMC_NSPC){
spc_state = SET;
}else{
@@ -700,9 +792,10 @@ uint8_t ob_user_bor_threshold_get(void)
/*!
\brief enable FMC interrupt
- \param[in] the FMC interrupt source
- \arg FMC_INTEN_END: enable FMC end of program interrupt
- \arg FMC_INTEN_ERR: enable FMC error interrupt
+ \param[in] fmc_int: the FMC interrupt source
+ only one parameter can be selected which is shown as below:
+ \arg FMC_INT_END: enable FMC end of program interrupt
+ \arg FMC_INT_ERR: enable FMC error interrupt
\param[out] none
\retval none
*/
@@ -713,9 +806,10 @@ void fmc_interrupt_enable(uint32_t fmc_int)
/*!
\brief disable FMC interrupt
- \param[in] the FMC interrupt source
- \arg FMC_INTEN_END: disable FMC end of program interrupt
- \arg FMC_INTEN_ERR: disable FMC error interrupt
+ \param[in] fmc_int: the FMC interrupt source
+ only one parameter can be selected which is shown as below:
+ \arg FMC_INT_END: disable FMC end of program interrupt
+ \arg FMC_INT_ERR: disable FMC error interrupt
\param[out] none
\retval none
*/
@@ -727,12 +821,13 @@ void fmc_interrupt_disable(uint32_t fmc_int)
/*!
\brief get flag set or reset
\param[in] fmc_flag: check FMC flag
- \arg FMC_FLAG_BUSY: FMC busy flag
+ only one parameter can be selected which is shown as below:
+ \arg FMC_FLAG_BUSY: FMC busy flag bit
\arg FMC_FLAG_RDDERR: FMC read D-bus protection error flag bit
\arg FMC_FLAG_PGSERR: FMC program sequence error flag bit
\arg FMC_FLAG_PGMERR: FMC program size not match error flag bit
\arg FMC_FLAG_WPERR: FMC Erase/Program protection error flag bit
- \arg FMC_FLAG_OPERR: FMC operation error flag bit
+ \arg FMC_FLAG_OPERR: FMC operation error flag bit
\arg FMC_FLAG_END: FMC end of operation flag bit
\param[out] none
\retval FlagStatus: SET or RESET
@@ -743,17 +838,18 @@ FlagStatus fmc_flag_get(uint32_t fmc_flag)
return SET;
}
/* return the state of corresponding FMC flag */
- return RESET;
+ return RESET;
}
/*!
\brief clear the FMC pending flag
\param[in] FMC_flag: clear FMC flag
+ only one parameter can be selected which is shown as below:
\arg FMC_FLAG_RDDERR: FMC read D-bus protection error flag bit
\arg FMC_FLAG_PGSERR: FMC program sequence error flag bit
\arg FMC_FLAG_PGMERR: FMC program size not match error flag bit
\arg FMC_FLAG_WPERR: FMC erase/program protection error flag bit
- \arg FMC_FLAG_OPERR: FMC operation error flag bit
+ \arg FMC_FLAG_OPERR: FMC operation error flag bit
\arg FMC_FLAG_END: FMC end of operation flag bit
\param[out] none
\retval none
@@ -768,23 +864,31 @@ void fmc_flag_clear(uint32_t fmc_flag)
\brief get the FMC state
\param[in] none
\param[out] none
- \retval fmc_state_enum
+ \retval state of FMC
+ \arg FMC_READY: the operation has been completed
+ \arg FMC_BUSY: the operation is in progress
+ \arg FMC_RDDERR: read D-bus protection error
+ \arg FMC_PGSERR: program sequence error
+ \arg FMC_PGMERR: program size not match error
+ \arg FMC_WPERR: erase/program protection error
+ \arg FMC_OPERR: operation error
+ \arg FMC_PGERR: program error
*/
fmc_state_enum fmc_state_get(void)
{
fmc_state_enum fmc_state = FMC_READY;
-
+
if((FMC_STAT & FMC_FLAG_BUSY) == FMC_FLAG_BUSY){
fmc_state = FMC_BUSY;
}else{
- if((FMC_STAT & FMC_FLAG_WPERR) != (uint32_t)0x00){
+ if((FMC_STAT & FMC_FLAG_WPERR) != (uint32_t)0x00){
fmc_state = FMC_WPERR;
}else{
- if((FMC_STAT & FMC_FLAG_RDDERR) != (uint32_t)0x00){
+ if((FMC_STAT & FMC_FLAG_RDDERR) != (uint32_t)0x00){
fmc_state = FMC_RDDERR;
}else{
if((FMC_STAT & (uint32_t)0xEF) != (uint32_t)0x00){
- fmc_state = FMC_PGERR;
+ fmc_state = FMC_PGERR;
}else{
if((FMC_STAT & FMC_FLAG_OPERR) != (uint32_t)0x00){
fmc_state = FMC_OPERR;
@@ -801,24 +905,28 @@ fmc_state_enum fmc_state_get(void)
/*!
\brief check whether FMC is ready or not
- \param[in] count: FMC_TIMEOUT_COUNT
+ \param[in] none
\param[out] none
- \retval fmc_state_enum
+ \retval state of FMC
+ \arg FMC_READY: the operation has been completed
+ \arg FMC_BUSY: the operation is in progress
+ \arg FMC_RDDERR: read D-bus protection error
+ \arg FMC_PGSERR: program sequence error
+ \arg FMC_PGMERR: program size not match error
+ \arg FMC_WPERR: erase/program protection error
+ \arg FMC_OPERR: operation error
+ \arg FMC_PGERR: program error
*/
-fmc_state_enum fmc_ready_wait(uint32_t count)
+fmc_state_enum fmc_ready_wait(void)
{
fmc_state_enum fmc_state = FMC_BUSY;
-
+
/* wait for FMC ready */
do{
/* get FMC state */
fmc_state = fmc_state_get();
- count--;
- }while((FMC_BUSY == fmc_state) && ((uint32_t)RESET != count));
-
- if(FMC_BUSY == fmc_state){
- fmc_state = FMC_TOERR;
- }
+ }while(FMC_BUSY == fmc_state);
+
/* return the FMC state */
return fmc_state;
}
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_fwdgt.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_fwdgt.c
index 4762344417..04e2c5b99d 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_fwdgt.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_fwdgt.c
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_fwdgt.c
- \brief FWDGT driver
+ \file gd32f4xx_fwdgt.c
+ \brief FWDGT driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#include "gd32f4xx_fwdgt.h"
@@ -17,25 +42,25 @@
#define RLD_RLD(regval) (BITS(0,11) & ((uint32_t)(regval) << 0))
/*!
- \brief disable write access to FWDGT_PSC and FWDGT_RLD
+ \brief enable write access to FWDGT_PSC and FWDGT_RLD
\param[in] none
\param[out] none
\retval none
*/
-void fwdgt_write_disable(void)
+void fwdgt_write_enable(void)
{
- FWDGT_CTL = FWDGT_WRITEACCESS_DISABLE;
+ FWDGT_CTL = FWDGT_WRITEACCESS_ENABLE;
}
/*!
- \brief reload the counter of FWDGT
+ \brief disable write access to FWDGT_PSC and FWDGT_RLD
\param[in] none
\param[out] none
\retval none
*/
-void fwdgt_counter_reload(void)
+void fwdgt_write_disable(void)
{
- FWDGT_CTL = FWDGT_KEY_RELOAD;
+ FWDGT_CTL = FWDGT_WRITEACCESS_DISABLE;
}
/*!
@@ -49,11 +74,22 @@ void fwdgt_enable(void)
FWDGT_CTL = FWDGT_KEY_ENABLE;
}
+/*!
+ \brief reload the counter of FWDGT
+ \param[in] none
+ \param[out] none
+ \retval none
+*/
+void fwdgt_counter_reload(void)
+{
+ FWDGT_CTL = FWDGT_KEY_RELOAD;
+}
/*!
\brief configure counter reload value, and prescaler divider value
\param[in] reload_value: specify reload value(0x0000 - 0x0FFF)
\param[in] prescaler_div: FWDGT prescaler value
+ only one parameter can be selected which is shown as below:
\arg FWDGT_PSC_DIV4: FWDGT prescaler set to 4
\arg FWDGT_PSC_DIV8: FWDGT prescaler set to 8
\arg FWDGT_PSC_DIV16: FWDGT prescaler set to 16
@@ -68,15 +104,15 @@ ErrStatus fwdgt_config(uint16_t reload_value, uint8_t prescaler_div)
{
uint32_t timeout = FWDGT_PSC_TIMEOUT;
uint32_t flag_status = RESET;
-
+
/* enable write access to FWDGT_PSC,and FWDGT_RLD */
FWDGT_CTL = FWDGT_WRITEACCESS_ENABLE;
-
+
/* wait until the PUD flag to be reset */
do{
flag_status = FWDGT_STAT & FWDGT_STAT_PUD;
}while((--timeout > 0U) && ((uint32_t)RESET != flag_status));
-
+
if ((uint32_t)RESET != flag_status){
return ERROR;
}
@@ -89,13 +125,13 @@ ErrStatus fwdgt_config(uint16_t reload_value, uint8_t prescaler_div)
do{
flag_status = FWDGT_STAT & FWDGT_STAT_RUD;
}while((--timeout > 0U) && ((uint32_t)RESET != flag_status));
-
+
if ((uint32_t)RESET != flag_status){
return ERROR;
}
-
+
FWDGT_RLD = RLD_RLD(reload_value);
-
+
/* reload the counter */
FWDGT_CTL = FWDGT_KEY_RELOAD;
@@ -104,7 +140,8 @@ ErrStatus fwdgt_config(uint16_t reload_value, uint8_t prescaler_div)
/*!
\brief get flag state of FWDGT
- \param[in] flag: flag to get
+ \param[in] flag: flag to get
+ only one parameter can be selected which is shown as below:
\arg FWDGT_STAT_PUD: a write operation to FWDGT_PSC register is on going
\arg FWDGT_STAT_RUD: a write operation to FWDGT_RLD register is on going
\param[out] none
@@ -112,7 +149,7 @@ ErrStatus fwdgt_config(uint16_t reload_value, uint8_t prescaler_div)
*/
FlagStatus fwdgt_flag_get(uint16_t flag)
{
- if(FWDGT_STAT & flag){
+ if(RESET != (FWDGT_STAT & flag)){
return SET;
}
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_gpio.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_gpio.c
index ccce538926..d3693abb17 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_gpio.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_gpio.c
@@ -1,19 +1,46 @@
/*!
- \file gd32f4xx_gpio.c
- \brief GPIO driver
+ \file gd32f4xx_gpio.c
+ \brief GPIO driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#include "gd32f4xx_gpio.h"
/*!
\brief reset GPIO port
- \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G,H,I)
+ \param[in] gpio_periph: GPIO port
+ only one parameter can be selected which is shown as below:
+ \arg GPIOx(x = A,B,C,D,E,F,G,H,I)
\param[out] none
\retval none
*/
@@ -71,22 +98,26 @@ void gpio_deinit(uint32_t gpio_periph)
}
/*!
- \brief set GPIO output mode
- \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G,H,I)
- \param[in] mode: gpio pin mode
+ \brief set GPIO mode
+ \param[in] gpio_periph: GPIO port
+ only one parameter can be selected which is shown as below:
+ \arg GPIOx(x = A,B,C,D,E,F,G,H,I)
+ \param[in] mode: GPIO pin mode
\arg GPIO_MODE_INPUT: input mode
\arg GPIO_MODE_OUTPUT: output mode
\arg GPIO_MODE_AF: alternate function mode
\arg GPIO_MODE_ANALOG: analog mode
- \param[in] pull_up_down: gpio pin with pull-up or pull-down resistor
- \arg GPIO_PUPD_NONE: without weak pull-up and pull-down resistors
- \arg GPIO_PUPD_PULLUP: with weak pull-up resistor
- \arg GPIO_PUPD_PULLDOWN:with weak pull-down resistor
- \param[in] pin: GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
+ \param[in] pull_up_down: GPIO pin with pull-up or pull-down resistor
+ \arg GPIO_PUPD_NONE: floating mode, no pull-up and pull-down resistors
+ \arg GPIO_PUPD_PULLUP: with pull-up resistor
+ \arg GPIO_PUPD_PULLDOWN:with pull-down resistor
+ \param[in] pin: GPIO pin
+ one or more parameters can be selected which are shown as below:
+ \arg GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
\param[out] none
\retval none
*/
-void gpio_mode_set(uint32_t gpio_periph,uint32_t mode,uint32_t pull_up_down,uint32_t pin)
+void gpio_mode_set(uint32_t gpio_periph, uint32_t mode, uint32_t pull_up_down, uint32_t pin)
{
uint16_t i;
uint32_t ctl, pupd;
@@ -114,25 +145,29 @@ void gpio_mode_set(uint32_t gpio_periph,uint32_t mode,uint32_t pull_up_down,uint
/*!
\brief set GPIO output type and speed
- \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G,H,I)
- \param[in] otype: gpio pin output mode
+ \param[in] gpio_periph: GPIO port
+ only one parameter can be selected which is shown as below:
+ \arg GPIOx(x = A,B,C,D,E,F,G,H,I)
+ \param[in] otype: GPIO pin output mode
\arg GPIO_OTYPE_PP: push pull mode
\arg GPIO_OTYPE_OD: open drain mode
- \param[in] speed: gpio pin output max speed
- \arg GPIO_OSPEED_2MHZ: output max speed 2M
- \arg GPIO_OSPEED_25MHZ: output max speed 25M
- \arg GPIO_OSPEED_50MHZ: output max speed 50M
- \arg GPIO_OSPEED_200MHZ: output max speed 200M
- \param[in] pin: GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
+ \param[in] speed: GPIO pin output max speed
+ \arg GPIO_OSPEED_2MHZ: output max speed 2MHz
+ \arg GPIO_OSPEED_25MHZ: output max speed 25MHz
+ \arg GPIO_OSPEED_50MHZ: output max speed 50MHz
+ \arg GPIO_OSPEED_200MHZ: output max speed 200MHz
+ \param[in] pin: GPIO pin
+ one or more parameters can be selected which are shown as below:
+ \arg GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
\param[out] none
\retval none
*/
-void gpio_output_options_set(uint32_t gpio_periph,uint8_t otype,uint32_t speed,uint32_t pin)
+void gpio_output_options_set(uint32_t gpio_periph, uint8_t otype, uint32_t speed, uint32_t pin)
{
uint16_t i;
uint32_t ospeedr;
- if(0x1U == otype){
+ if(GPIO_OTYPE_OD == otype){
GPIO_OMODE(gpio_periph) |= (uint32_t)pin;
}else{
GPIO_OMODE(gpio_periph) &= (uint32_t)(~pin);
@@ -153,40 +188,52 @@ void gpio_output_options_set(uint32_t gpio_periph,uint8_t otype,uint32_t speed,u
}
/*!
- \brief set GPIO pin
- \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G,H,I)
- \param[in] pin: GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
+ \brief set GPIO pin bit
+ \param[in] gpio_periph: GPIO port
+ only one parameter can be selected which is shown as below:
+ \arg GPIOx(x = A,B,C,D,E,F,G,H,I)
+ \param[in] pin: GPIO pin
+ one or more parameters can be selected which are shown as below:
+ \arg GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
\param[out] none
\retval none
*/
-void gpio_bit_set(uint32_t gpio_periph,uint32_t pin)
+void gpio_bit_set(uint32_t gpio_periph, uint32_t pin)
{
GPIO_BOP(gpio_periph) = (uint32_t)pin;
}
/*!
- \brief reset GPIO pin
- \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G,H,I)
- \param[in] pin: GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
+ \brief reset GPIO pin bit
+ \param[in] gpio_periph: GPIO port
+ only one parameter can be selected which is shown as below:
+ \arg GPIOx(x = A,B,C,D,E,F,G,H,I)
+ \param[in] pin: GPIO pin
+ one or more parameters can be selected which are shown as below:
+ \arg GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
\param[out] none
\retval none
*/
-void gpio_bit_reset(uint32_t gpio_periph,uint32_t pin)
+void gpio_bit_reset(uint32_t gpio_periph, uint32_t pin)
{
GPIO_BC(gpio_periph) = (uint32_t)pin;
}
/*!
\brief write data to the specified GPIO pin
- \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G,H,I)
- \param[in] pin: GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
- \param[in] bitvalue: SET or RESET
+ \param[in] gpio_periph: GPIO port
+ only one parameter can be selected which is shown as below:
+ \arg GPIOx(x = A,B,C,D,E,F,G,H,I)
+ \param[in] pin: GPIO pin
+ one or more parameters can be selected which are shown as below:
+ \arg GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
+ \param[in] bit_value: SET or RESET
\arg RESET: clear the port pin
\arg SET: set the port pin
\param[out] none
\retval none
*/
-void gpio_bit_write(uint32_t gpio_periph,uint32_t pin,bit_status bit_value)
+void gpio_bit_write(uint32_t gpio_periph, uint32_t pin, bit_status bit_value)
{
if(RESET != bit_value){
GPIO_BOP(gpio_periph) = (uint32_t)pin;
@@ -197,27 +244,33 @@ void gpio_bit_write(uint32_t gpio_periph,uint32_t pin,bit_status bit_value)
/*!
\brief write data to the specified GPIO port
- \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G,H,I)
- \param[in] data: specify the value to be written to the port output data register
+ \param[in] gpio_periph: GPIO port
+ only one parameter can be selected which is shown as below:
+ \arg GPIOx(x = A,B,C,D,E,F,G,H,I)
+ \param[in] data: specify the value to be written to the port output control register
\param[out] none
\retval none
*/
-void gpio_port_write(uint32_t gpio_periph,uint16_t data)
+void gpio_port_write(uint32_t gpio_periph, uint16_t data)
{
GPIO_OCTL(gpio_periph) = (uint32_t)data;
}
/*!
\brief get GPIO pin input status
- \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G,H,I)
- \param[in] pin: GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
+ \param[in] gpio_periph: GPIO port
+ only one parameter can be selected which is shown as below:
+ \arg GPIOx(x = A,B,C,D,E,F,G,H,I)
+ \param[in] pin: GPIO pin
+ one or more parameters can be selected which are shown as below:
+ \arg GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
\param[out] none
- \retval input state of gpio pin: SET or RESET
+ \retval input status of GPIO pin: SET or RESET
*/
-FlagStatus gpio_input_bit_get(uint32_t gpio_periph,uint32_t pin)
+FlagStatus gpio_input_bit_get(uint32_t gpio_periph, uint32_t pin)
{
if((uint32_t)RESET != (GPIO_ISTAT(gpio_periph)&(pin))){
- return SET;
+ return SET;
}else{
return RESET;
}
@@ -225,23 +278,29 @@ FlagStatus gpio_input_bit_get(uint32_t gpio_periph,uint32_t pin)
/*!
\brief get GPIO all pins input status
- \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G,H,I)
+ \param[in] gpio_periph: GPIO port
+ only one parameter can be selected which is shown as below:
+ \arg GPIOx(x = A,B,C,D,E,F,G,H,I)
\param[out] none
- \retval input state of gpio all pins
+ \retval input status of GPIO all pins
*/
uint16_t gpio_input_port_get(uint32_t gpio_periph)
{
- return (uint16_t)(GPIO_ISTAT(gpio_periph));
+ return ((uint16_t)GPIO_ISTAT(gpio_periph));
}
/*!
\brief get GPIO pin output status
- \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G,H,I)
- \param[in] pin: GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
+ \param[in] gpio_periph: GPIO port
+ only one parameter can be selected which is shown as below:
+ \arg GPIOx(x = A,B,C,D,E,F,G,H,I)
+ \param[in] pin: GPIO pin
+ one or more parameters can be selected which are shown as below:
+ \arg GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
\param[out] none
- \retval output state of gpio pin: SET or RESET
+ \retval output status of GPIO pin: SET or RESET
*/
-FlagStatus gpio_output_bit_get(uint32_t gpio_periph,uint32_t pin)
+FlagStatus gpio_output_bit_get(uint32_t gpio_periph, uint32_t pin)
{
if((uint32_t)RESET !=(GPIO_OCTL(gpio_periph)&(pin))){
return SET;
@@ -252,9 +311,11 @@ FlagStatus gpio_output_bit_get(uint32_t gpio_periph,uint32_t pin)
/*!
\brief get GPIO all pins output status
- \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G,H,I)
+ \param[in] gpio_periph: GPIO port
+ only one parameter can be selected which is shown as below:
+ \arg GPIOx(x = A,B,C,D,E,F,G,H,I)
\param[out] none
- \retval output state of gpio all pins
+ \retval output status of GPIO all pins
*/
uint16_t gpio_output_port_get(uint32_t gpio_periph)
{
@@ -263,29 +324,33 @@ uint16_t gpio_output_port_get(uint32_t gpio_periph)
/*!
\brief set GPIO alternate function
- \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G,H,I)
- \param[in] alt_func_num: gpio pin af function
+ \param[in] gpio_periph: GPIO port
+ only one parameter can be selected which is shown as below:
+ \arg GPIOx(x = A,B,C,D,E,F,G,H,I)
+ \param[in] alt_func_num: GPIO pin af function
\arg GPIO_AF_0: SYSTEM
\arg GPIO_AF_1: TIMER0, TIMER1
\arg GPIO_AF_2: TIMER2, TIMER3, TIMER4
\arg GPIO_AF_3: TIMER7, TIMER8, TIMER9, TIMER10
\arg GPIO_AF_4: I2C0, I2C1, I2C2
\arg GPIO_AF_5: SPI0, SPI1, SPI2, SPI3, SPI4, SPI5
- \arg GPIO_AF_6: SPI1, SPI2, SAI0
+ \arg GPIO_AF_6: SPI1, SPI2, SAI0
\arg GPIO_AF_7: USART0, USART1, USART2
\arg GPIO_AF_8: UART3, UART4, USART5, UART6, UART7
- \arg GPIO_AF_9: CAN0,CAN1, TLI, TIMER11, TIMER12, TIMER13
+ \arg GPIO_AF_9: CAN0, CAN1, TLI, TIMER11, TIMER12, TIMER13
\arg GPIO_AF_10: USB_FS, USB_HS
\arg GPIO_AF_11: ENET
- \arg GPIO_AF_12: FMC, SDIO, USB_HS
+ \arg GPIO_AF_12: EXMC, SDIO, USB_HS
\arg GPIO_AF_13: DCI
\arg GPIO_AF_14: TLI
\arg GPIO_AF_15: EVENTOUT
- \param[in] pin: GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
+ \param[in] pin: GPIO pin
+ one or more parameters can be selected which are shown as below:
+ \arg GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
\param[out] none
\retval none
*/
-void gpio_af_set(uint32_t gpio_periph,uint32_t alt_func_num,uint32_t pin)
+void gpio_af_set(uint32_t gpio_periph, uint32_t alt_func_num, uint32_t pin)
{
uint16_t i;
uint32_t afrl, afrh;
@@ -314,18 +379,22 @@ void gpio_af_set(uint32_t gpio_periph,uint32_t alt_func_num,uint32_t pin)
}
/*!
- \brief lock GPIO pin
- \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G,H,I)
- \param[in] pin: GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
+ \brief lock GPIO pin bit
+ \param[in] gpio_periph: GPIO port
+ only one parameter can be selected which is shown as below:
+ \arg GPIOx(x = A,B,C,D,E,F,G,H,I)
+ \param[in] pin: GPIO pin
+ one or more parameters can be selected which are shown as below:
+ \arg GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
\param[out] none
\retval none
*/
-void gpio_pin_lock(uint32_t gpio_periph,uint32_t pin)
+void gpio_pin_lock(uint32_t gpio_periph, uint32_t pin)
{
uint32_t lock = 0x00010000U;
lock |= pin;
- /* lock key writing sequence: write 1->write 0->write 1-> read 0-> read 1 */
+ /* lock key writing sequence: write 1->write 0->write 1->read 0->read 1 */
GPIO_LOCK(gpio_periph) = (uint32_t)lock;
GPIO_LOCK(gpio_periph) = (uint32_t)pin;
GPIO_LOCK(gpio_periph) = (uint32_t)lock;
@@ -334,20 +403,27 @@ void gpio_pin_lock(uint32_t gpio_periph,uint32_t pin)
}
/*!
- \brief toggle GPIO pin
- \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G,H,I)
- \param[in] pin: GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
+ \brief toggle GPIO pin status
+ \param[in] gpio_periph: GPIO port
+ only one parameter can be selected which is shown as below:
+ \arg GPIOx(x = A,B,C,D,E,F,G,H,I)
+ \param[in] pin: GPIO pin
+ one or more parameters can be selected which are shown as below:
+ \arg GPIO_PIN_x(x=0..15), GPIO_PIN_ALL
\param[out] none
\retval none
*/
-void gpio_bit_toggle(uint32_t gpio_periph,uint32_t pin)
+void gpio_bit_toggle(uint32_t gpio_periph, uint32_t pin)
{
GPIO_TG(gpio_periph) = (uint32_t)pin;
}
/*!
- \brief toggle GPIO port
- \param[in] gpio_periph: GPIOx(x = A,B,C,D,E,F,G,H,I)
+ \brief toggle GPIO port status
+ \param[in] gpio_periph: GPIO port
+ only one parameter can be selected which is shown as below:
+ \arg GPIOx(x = A,B,C,D,E,F,G,H,I)
+
\param[out] none
\retval none
*/
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_i2c.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_i2c.c
index 79480b63e5..c3ac50c178 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_i2c.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_i2c.c
@@ -1,19 +1,51 @@
/*!
- \file gd32f4xx_i2c.c
- \brief I2C driver
+ \file gd32f4xx_i2c.c
+ \brief I2C driver
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2019-04-16, V2.0.2, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#include "gd32f4xx_i2c.h"
-#define I2CCLK_MAX 0x3fU /*!< i2cclk max value */
-#define I2C_STATE_MASK 0x0000FFFFU /*!< i2c state mask */
+/* I2C register bit mask */
+#define I2CCLK_MAX ((uint32_t)0x00000032U) /*!< i2cclk maximum value */
+#define I2CCLK_MIN ((uint32_t)0x00000002U) /*!< i2cclk minimum value */
+#define I2C_FLAG_MASK ((uint32_t)0x0000FFFFU) /*!< i2c flag mask */
+#define I2C_ADDRESS_MASK ((uint32_t)0x000003FFU) /*!< i2c address mask */
+#define I2C_ADDRESS2_MASK ((uint32_t)0x000000FEU) /*!< the second i2c address mask */
+
+/* I2C register bit offset */
+#define STAT1_PECV_OFFSET ((uint32_t)8U) /* bit offset of PECV in I2C_STAT1 */
/*!
\brief reset I2C
@@ -25,202 +57,229 @@ void i2c_deinit(uint32_t i2c_periph)
{
switch(i2c_periph){
case I2C0:
+ /* reset I2C0 */
rcu_periph_reset_enable(RCU_I2C0RST);
rcu_periph_reset_disable(RCU_I2C0RST);
break;
case I2C1:
+ /* reset I2C1 */
rcu_periph_reset_enable(RCU_I2C1RST);
rcu_periph_reset_disable(RCU_I2C1RST);
break;
case I2C2:
+ /* reset I2C2 */
rcu_periph_reset_enable(RCU_I2C2RST);
rcu_periph_reset_disable(RCU_I2C2RST);
break;
default:
break;
-
}
}
/*!
- \brief I2C clock configure
+ \brief configure I2C clock
\param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] clkspeed: i2c clock speed
+ \param[in] clkspeed: I2C clock speed, supports standard mode (up to 100 kHz), fast mode (up to 400 kHz)
\param[in] dutycyc: duty cycle in fast mode
- \arg I2C_DTCY_2: T_low/T_high=2
+ only one parameter can be selected which is shown as below:
+ \arg I2C_DTCY_2: T_low/T_high=2
\arg I2C_DTCY_16_9: T_low/T_high=16/9
\param[out] none
\retval none
*/
-void i2c_clock_config(uint32_t i2c_periph,uint32_t clkspeed,uint32_t dutycyc)
+void i2c_clock_config(uint32_t i2c_periph, uint32_t clkspeed, uint32_t dutycyc)
{
- uint32_t pclk1,clkc,i2cclk,risetime;
+ uint32_t pclk1, clkc, freq, risetime;
+ uint32_t temp;
+
pclk1 = rcu_clock_freq_get(CK_APB1);
- /* I2C Peripheral clock frequency */
- i2cclk=((pclk1)/(uint32_t)(1000000));
- if(i2cclk >= I2CCLK_MAX){
- i2cclk = I2CCLK_MAX;
+ /* I2C peripheral clock frequency */
+ freq = (uint32_t)(pclk1/1000000U);
+ if(freq >= I2CCLK_MAX){
+ freq = I2CCLK_MAX;
}
-
- I2C_CTL1(i2c_periph) |= (I2C_CTL1_I2CCLK & i2cclk) ;
-
+ temp = I2C_CTL1(i2c_periph);
+ temp &= ~I2C_CTL1_I2CCLK;
+ temp |= freq;
+
+ I2C_CTL1(i2c_periph) = temp;
+
if(100000U >= clkspeed){
- /* standard mode the maximum SCL rise time in standard mode is 1000ns */
+ /* the maximum SCL rise time is 1000ns in standard mode */
risetime = (uint32_t)((pclk1/1000000U)+1U);
if(risetime >= I2CCLK_MAX){
- I2C_RT(i2c_periph) |= I2CCLK_MAX;
+ I2C_RT(i2c_periph) = I2CCLK_MAX;
}else{
- I2C_RT(i2c_periph) |= (uint32_t)((pclk1/1000000U)+1U);
+ I2C_RT(i2c_periph) = risetime;
}
clkc = (uint32_t)(pclk1/(clkspeed*2U));
if(clkc < 0x04U){
- /* The CLKC in standard mode minmum value is 4*/
+ /* the CLKC in standard mode minmum value is 4 */
clkc = 0x04U;
}
- I2C_CKCFG(i2c_periph) |= (I2C_CKCFG_CLKC & clkc);
- }else{
- /* fast mode the maximum SCL rise time in standard mode is 300ns */
- I2C_RT(i2c_periph) |= (uint16_t)(((i2cclk*(uint16_t)300)/(uint16_t)1000)+(uint16_t)1);
+ I2C_CKCFG(i2c_periph) |= (I2C_CKCFG_CLKC & clkc);
+
+ }else if(400000U >= clkspeed){
+ /* the maximum SCL rise time is 300ns in fast mode */
+ I2C_RT(i2c_periph) = (uint32_t)(((freq*(uint32_t)300U)/(uint32_t)1000U)+(uint32_t)1U);
if(I2C_DTCY_2 == dutycyc){
- /* I2C_DutyCycle == 2 */
- clkc = (uint16_t)(pclk1/(clkspeed*3U));
- } else{
- /* I2C_DutyCycle == 16/9 */
- clkc = (uint16_t)(pclk1/(clkspeed*25U));
+ /* I2C duty cycle is 2 */
+ clkc = (uint32_t)(pclk1/(clkspeed*3U));
+ I2C_CKCFG(i2c_periph) &= ~I2C_CKCFG_DTCY;
+ }else{
+ /* I2C duty cycle is 16/9 */
+ clkc = (uint32_t)(pclk1/(clkspeed*25U));
I2C_CKCFG(i2c_periph) |= I2C_CKCFG_DTCY;
}
- if((clkc & I2C_CKCFG_CLKC) == 0U){
- /* The CLKC in standard mode minmum value is 1*/
- clkc |= (uint16_t)0x0001;
+ if(0U == (clkc & I2C_CKCFG_CLKC)){
+ /* the CLKC in fast mode minmum value is 1 */
+ clkc |= 0x0001U;
}
+ I2C_CKCFG(i2c_periph) |= I2C_CKCFG_FAST;
I2C_CKCFG(i2c_periph) |= clkc;
+ }else{
}
}
/*!
- \brief I2C address configure
+ \brief configure I2C address
\param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] i2cmod:
- \arg I2C_I2CMODE_ENABLE: I2C mode
+ \param[in] mode:
+ only one parameter can be selected which is shown as below:
+ \arg I2C_I2CMODE_ENABLE: I2C mode
\arg I2C_SMBUSMODE_ENABLE: SMBus mode
\param[in] addformat: 7bits or 10bits
- \arg I2C_ADDFORMAT_7BITS: 7bits
+ only one parameter can be selected which is shown as below:
+ \arg I2C_ADDFORMAT_7BITS: 7bits
\arg I2C_ADDFORMAT_10BITS: 10bits
\param[in] addr: I2C address
\param[out] none
\retval none
*/
-void i2c_mode_addr_config(uint32_t i2c_periph,uint32_t i2cmod,uint32_t addformat,uint32_t addr)
+void i2c_mode_addr_config(uint32_t i2c_periph, uint32_t mode, uint32_t addformat, uint32_t addr)
{
/* SMBus/I2C mode selected */
uint32_t ctl = 0U;
+
ctl = I2C_CTL0(i2c_periph);
- ctl &= ~(I2C_CTL0_SMBEN);
- ctl |= i2cmod;
+ ctl &= ~(I2C_CTL0_SMBEN);
+ ctl |= mode;
I2C_CTL0(i2c_periph) = ctl;
/* configure address */
- I2C_SADDR0(i2c_periph) = (addformat|addr);
-
+ addr = addr & I2C_ADDRESS_MASK;
+ I2C_SADDR0(i2c_periph) = (addformat | addr);
}
/*!
\brief SMBus type selection
\param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] ack:
+ \param[in] type:
+ only one parameter can be selected which is shown as below:
\arg I2C_SMBUS_DEVICE: device
\arg I2C_SMBUS_HOST: host
\param[out] none
\retval none
*/
-void i2c_smbus_type_config(uint32_t i2c_periph,uint32_t type)
+void i2c_smbus_type_config(uint32_t i2c_periph, uint32_t type)
{
if(I2C_SMBUS_HOST == type){
- I2C_CTL0(i2c_periph) |= I2C_CTL0_SMBSEL;
+ I2C_CTL0(i2c_periph) |= I2C_CTL0_SMBSEL;
}else{
- I2C_CTL0(i2c_periph) &= ~(I2C_CTL0_SMBSEL);
- }
+ I2C_CTL0(i2c_periph) &= ~(I2C_CTL0_SMBSEL);
+ }
}
/*!
\brief whether or not to send an ACK
\param[in] i2c_periph: I2Cx(x=0,1,2)
\param[in] ack:
- \arg I2C_ACK_ENABLE: ACK will be sent
- \arg I2C_ACK_DISABLE: ACK will not be sent
+ only one parameter can be selected which is shown as below:
+ \arg I2C_ACK_ENABLE: ACK will be sent
+ \arg I2C_ACK_DISABLE: ACK will not be sent
\param[out] none
\retval none
*/
-void i2c_ack_config(uint32_t i2c_periph,uint8_t ack)
+void i2c_ack_config(uint32_t i2c_periph, uint32_t ack)
{
if(I2C_ACK_ENABLE == ack){
- I2C_CTL0(i2c_periph) |= I2C_CTL0_ACKEN;
+ I2C_CTL0(i2c_periph) |= I2C_CTL0_ACKEN;
}else{
- I2C_CTL0(i2c_periph) &= ~(I2C_CTL0_ACKEN);
- }
+ I2C_CTL0(i2c_periph) &= ~(I2C_CTL0_ACKEN);
+ }
}
/*!
- \brief I2C POAP position configure
+ \brief configure I2C POAP position
\param[in] i2c_periph: I2Cx(x=0,1,2)
\param[in] pos:
- \arg I2C_ACK_ENABLE: ACK will be sent
- \arg I2C_ACK_DISABLE: ACK will not be sent
+ only one parameter can be selected which is shown as below:
+ \arg I2C_ACKPOS_CURRENT: whether to send ACK or not for the current
+ \arg I2C_ACKPOS_NEXT: whether to send ACK or not for the next byte
\param[out] none
\retval none
*/
-void i2c_ackpos_config(uint32_t i2c_periph,uint8_t pos)
+void i2c_ackpos_config(uint32_t i2c_periph, uint32_t pos)
{
- /* configure i2c POAP position */
+ /* configure I2C POAP position */
if(I2C_ACKPOS_NEXT == pos){
- I2C_CTL0(i2c_periph) |= I2C_CTL0_POAP;
+ I2C_CTL0(i2c_periph) |= I2C_CTL0_POAP;
}else{
- I2C_CTL0(i2c_periph) &= ~(I2C_CTL0_POAP);
- }
-
+ I2C_CTL0(i2c_periph) &= ~(I2C_CTL0_POAP);
+ }
}
/*!
- \brief master send slave address
+ \brief master sends slave address
\param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] addr: slave address
+ \param[in] addr: slave address
\param[in] trandirection: transmitter or receiver
- \arg I2C_TRANSMITTER: transmitter
- \arg I2C_RECEIVER: receiver
+ only one parameter can be selected which is shown as below:
+ \arg I2C_TRANSMITTER: transmitter
+ \arg I2C_RECEIVER: receiver
\param[out] none
\retval none
*/
-void i2c_master_addressing(uint32_t i2c_periph,uint8_t addr,uint32_t trandirection)
+void i2c_master_addressing(uint32_t i2c_periph, uint32_t addr, uint32_t trandirection)
{
- if(I2C_TRANSMITTER==trandirection){
- addr = (uint8_t)((uint32_t)addr & I2C_TRANSMITTER);
+ /* master is a transmitter or a receiver */
+ if(I2C_TRANSMITTER == trandirection){
+ addr = addr & I2C_TRANSMITTER;
}else{
- addr = (uint8_t)((uint32_t)addr|I2C_RECEIVER);
+ addr = addr | I2C_RECEIVER;
}
+ /* send slave address */
I2C_DATA(i2c_periph) = addr;
}
/*!
- \brief dual-address mode switch
+ \brief enable dual-address mode
\param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] dualaddr:
- \arg I2C_DUADEN_DISABLE: dual-address mode disabled
- \arg I2C_DUADEN_ENABLE: dual-address mode enabled
+ \param[in] addr: the second address in dual-address mode
\param[out] none
\retval none
*/
-void i2c_dualaddr_enable(uint32_t i2c_periph,uint8_t dualaddr)
+void i2c_dualaddr_enable(uint32_t i2c_periph, uint32_t addr)
{
- if(I2C_DUADEN_ENABLE == dualaddr){
- I2C_SADDR1(i2c_periph) |= I2C_SADDR1_DUADEN;
- }else{
- I2C_SADDR1(i2c_periph) &= ~(I2C_SADDR1_DUADEN);
- }
+ /* configure address */
+ addr = addr & I2C_ADDRESS2_MASK;
+ I2C_SADDR1(i2c_periph) = (I2C_SADDR1_DUADEN | addr);
}
/*!
- \brief enable i2c
- \param[in] i2c_periph: I2Cx(x=0,1,2)
+ \brief disable dual-address mode
+ \param[in] i2c_periph: I2Cx(x=0,1,2)
+ \param[out] none
+ \retval none
+*/
+void i2c_dualaddr_disable(uint32_t i2c_periph)
+{
+ I2C_SADDR1(i2c_periph) &= ~(I2C_SADDR1_DUADEN);
+}
+
+/*!
+ \brief enable I2C
+ \param[in] i2c_periph: I2Cx(x=0,1,2)
\param[out] none
\retval none
*/
@@ -230,15 +289,14 @@ void i2c_enable(uint32_t i2c_periph)
}
/*!
- \brief disable i2c
- \param[in] i2c_periph: I2Cx(x=0,1,2)
+ \brief disable I2C
+ \param[in] i2c_periph: I2Cx(x=0,1,2)
\param[out] none
\retval none
*/
void i2c_disable(uint32_t i2c_periph)
{
I2C_CTL0(i2c_periph) &= ~(I2C_CTL0_I2CEN);
-
}
/*!
@@ -264,91 +322,96 @@ void i2c_stop_on_bus(uint32_t i2c_periph)
}
/*!
- \brief i2c transmit data function
+ \brief I2C transmit data function
\param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] data: data of transmission
+ \param[in] data: data of transmission
\param[out] none
\retval none
*/
-void i2c_transmit_data(uint32_t i2c_periph,uint8_t data)
+void i2c_data_transmit(uint32_t i2c_periph, uint8_t data)
{
- I2C_DATA(i2c_periph) = data;
+ I2C_DATA(i2c_periph) = DATA_TRANS(data);
}
/*!
- \brief i2c receive data function
+ \brief I2C receive data function
\param[in] i2c_periph: I2Cx(x=0,1,2)
\param[out] none
\retval data of received
*/
-uint8_t i2c_receive_data(uint32_t i2c_periph)
+uint8_t i2c_data_receive(uint32_t i2c_periph)
{
- return (uint8_t)I2C_DATA(i2c_periph);
+ return (uint8_t)DATA_RECV(I2C_DATA(i2c_periph));
}
/*!
- \brief I2C DMA mode enable
+ \brief enable I2C DMA mode
\param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] dmastste:
- \arg I2C_DMA_ON: DMA mode enabled
- \arg I2C_DMA_OFF: DMA mode disabled
+ \param[in] dmastate:
+ only one parameter can be selected which is shown as below:
+ \arg I2C_DMA_ON: DMA mode enable
+ \arg I2C_DMA_OFF: DMA mode disable
\param[out] none
\retval none
*/
-void i2c_dma_enable(uint32_t i2c_periph,uint32_t dmastste)
+void i2c_dma_enable(uint32_t i2c_periph, uint32_t dmastate)
{
- /* configure i2c DMA function */
+ /* configure I2C DMA function */
uint32_t ctl = 0U;
+
ctl = I2C_CTL1(i2c_periph);
- ctl &= ~(I2C_CTL1_DMAON);
- ctl |= dmastste;
+ ctl &= ~(I2C_CTL1_DMAON);
+ ctl |= dmastate;
I2C_CTL1(i2c_periph) = ctl;
-
}
/*!
- \brief flag indicating DMA last transfer
+ \brief configure whether next DMA EOT is DMA last transfer or not
\param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] dmastste:
+ \param[in] dmalast:
+ only one parameter can be selected which is shown as below:
\arg I2C_DMALST_ON: next DMA EOT is the last transfer
\arg I2C_DMALST_OFF: next DMA EOT is not the last transfer
\param[out] none
\retval none
*/
-void i2c_dma_last_transfer_enable(uint32_t i2c_periph,uint32_t dmalast)
+void i2c_dma_last_transfer_config(uint32_t i2c_periph, uint32_t dmalast)
{
/* configure DMA last transfer */
uint32_t ctl = 0U;
+
ctl = I2C_CTL1(i2c_periph);
- ctl &= ~(I2C_CTL1_DMALST);
+ ctl &= ~(I2C_CTL1_DMALST);
ctl |= dmalast;
I2C_CTL1(i2c_periph) = ctl;
-
}
/*!
- \brief whether to stretch SCL low when data is not ready in slave mode
+ \brief whether to stretch SCL low when data is not ready in slave mode
\param[in] i2c_periph: I2Cx(x=0,1,2)
\param[in] stretchpara:
+ only one parameter can be selected which is shown as below:
\arg I2C_SCLSTRETCH_ENABLE: SCL stretching is enabled
\arg I2C_SCLSTRETCH_DISABLE: SCL stretching is disabled
\param[out] none
\retval none
*/
-void i2c_stretch_scl_low_config(uint32_t i2c_periph,uint32_t stretchpara)
+void i2c_stretch_scl_low_config(uint32_t i2c_periph, uint32_t stretchpara)
{
/* configure I2C SCL strerching enable or disable */
uint32_t ctl = 0U;
+
ctl = I2C_CTL0(i2c_periph);
- ctl &= ~(I2C_CTL0_DISSTRC);
+ ctl &= ~(I2C_CTL0_SS);
ctl |= stretchpara;
I2C_CTL0(i2c_periph) = ctl;
}
/*!
- \brief whether or not to response to a general Cal
+ \brief whether or not to response to a general call
\param[in] i2c_periph: I2Cx(x=0,1,2)
\param[in] gcallpara:
+ only one parameter can be selected which is shown as below:
\arg I2C_GCEN_ENABLE: slave will response to a general call
\arg I2C_GCEN_DISABLE: slave will not response to a general call
\param[out] none
@@ -358,16 +421,18 @@ void i2c_slave_response_to_gcall_config(uint32_t i2c_periph, uint32_t gcallpara)
{
/* configure slave response to a general call enable or disable */
uint32_t ctl = 0U;
+
ctl = I2C_CTL0(i2c_periph);
- ctl &= ~(I2C_CTL0_GCEN);
+ ctl &= ~(I2C_CTL0_GCEN);
ctl |= gcallpara;
I2C_CTL0(i2c_periph) = ctl;
}
/*!
- \brief software reset I2C
+ \brief software reset I2C
\param[in] i2c_periph: I2Cx(x=0,1,2)
\param[in] sreset:
+ only one parameter can be selected which is shown as below:
\arg I2C_SRESET_SET: I2C is under reset
\arg I2C_SRESET_RESET: I2C is not under reset
\param[out] none
@@ -377,134 +442,30 @@ void i2c_software_reset_config(uint32_t i2c_periph, uint32_t sreset)
{
/* modify CTL0 and configure software reset I2C state */
uint32_t ctl = 0U;
+
ctl = I2C_CTL0(i2c_periph);
- ctl &= ~(I2C_CTL0_SRESET);
+ ctl &= ~(I2C_CTL0_SRESET);
ctl |= sreset;
I2C_CTL0(i2c_periph) = ctl;
}
/*!
- \brief check i2c state
- \param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] state:
- \arg I2C_SBSEND: start condition send out
- \arg I2C_ADDSEND: address is sent in master mode or received and matches in slave mode
- \arg I2C_BTC: byte transmission finishes
- \arg I2C_ADD10SEND: header of 10-bit address is sent in master mode
- \arg I2C_STPDET: etop condition detected in slave mode
- \arg I2C_RBNE: I2C_DATA is not Empty during receiving
- \arg I2C_TBE: I2C_DATA is empty during transmitting
- \arg I2C_BERR: a bus error occurs indication a unexpected start or stop condition on I2C bus
- \arg I2C_LOSTARB: arbitration lost in master mode
- \arg I2C_AERR: acknowledge error
- \arg I2C_OUERR: over-run or under-run situation occurs in slave mode
- \arg I2C_PECERR: PEC error when receiving data
- \arg I2C_SMBTO: timeout signal in SMBus mode
- \arg I2C_SMBALT: SMBus alert status
- \arg I2C_MASTER: a flag indicating whether I2C block is in master or slave mode
- \arg I2C_I2CBSY: busy flag
- \arg I2C_TRS: whether the I2C is a transmitter or a receiver
- \arg I2C_RXGC: general call address (00h) received
- \arg I2C_DEFSMB: default address of SMBus device
- \arg I2C_HSTSMB: SMBus host header detected in slave mode
- \arg I2C_DUMODF: dual flag in slave mode indicating which address is matched in dual-address mode
- \param[out] none
- \retval state of i2c
-*/
-FlagStatus i2c_flag_get(uint32_t i2c_periph,uint32_t state )
-{
- uint32_t reg = 0U;
- FlagStatus regstate = RESET;
- /* get the state in which register */
- reg = (BIT(31) & state);
- if((BIT(31) == reg)){
- if((I2C_STAT1(i2c_periph)&(state & I2C_STATE_MASK))){
- regstate = SET;
- }else{
- regstate = RESET;
- }
- }else{
- if((I2C_STAT0(i2c_periph)&(state & I2C_STATE_MASK))){
- regstate = SET;
- }else{
- regstate = RESET;
- }
- }
- /* return the state */
- return regstate;
-}
-
-/*!
- \brief clear i2c state
- \param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] state: state type
- \@arg I2C_STAT0_SMBALT: SMBus Alert status
- \@arg I2C_STAT0_SMBTO: timeout signal in SMBus mode
- \@arg I2C_STAT0_PECERR: PEC error when receiving data
- \@arg I2C_STAT0_OUERR: over-run or under-run situation occurs in slave mode
- \@arg I2C_STAT0_AERR: acknowledge error
- \@arg I2C_STAT0_LOSTARB: arbitration lost in master mode
- \@arg I2C_STAT0_BERR: a bus error
- \@arg I2C_STAT0_ADDSEND: cleared by reading I2C_STAT0 and reading I2C_STAT1
- \param[out] none
- \retval none
-*/
-void i2c_flag_clear(uint32_t i2c_periph,uint32_t state)
-{
- if(I2C_STAT0_ADDSEND == state){
- /* read I2C_STAT0 and then read I2C_STAT1 to clear ADDSEND */
- I2C_STAT0(i2c_periph);
- I2C_STAT1(i2c_periph);
- }else{
- I2C_STAT0(i2c_periph) &= ~(state);
- }
-}
-
-/*!
- \brief enable i2c interrupt
- \param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] inttype: interrupt type
- \arg I2C_CTL1_ERRIE: error interrupt enable
- \arg I2C_CTL1_EVIE: event interrupt enable
- \arg I2C_CTL1_BUFIE: buffer interrupt enable
- \param[out] none
- \retval none
-*/
-void i2c_interrupt_enable(uint32_t i2c_periph,uint32_t inttype)
-{
- I2C_CTL1(i2c_periph) |= (inttype);
-}
-
-/*!
- \brief disable i2c interrupt
- \param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] inttype: interrupt type
- \arg I2C_CTL1_ERRIE: error interrupt enable
- \arg I2C_CTL1_EVIE: event interrupt enable
- \arg I2C_CTL1_BUFIE: buffer interrupt enable
- \param[out] none
- \retval none
-*/
-void i2c_interrupt_disable(uint32_t i2c_periph,uint32_t inttype)
-{
- I2C_CTL1(i2c_periph) &= ~(inttype);
-}
-
-/*!
\brief I2C PEC calculation on or off
\param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] pecpara:
- \arg I2C_PEC_ENABLE: PEC calculation on
- \arg I2C_PEC_DISABLE: PEC calculation off
+ \param[in] pecstate:
+ only one parameter can be selected which is shown as below:
+ \arg I2C_PEC_ENABLE: PEC calculation on
+ \arg I2C_PEC_DISABLE: PEC calculation off
\param[out] none
\retval none
*/
-void i2c_pec_enable(uint32_t i2c_periph,uint32_t pecstate)
+void i2c_pec_enable(uint32_t i2c_periph, uint32_t pecstate)
{
/* on/off PEC calculation */
uint32_t ctl = 0U;
+
ctl = I2C_CTL0(i2c_periph);
- ctl &= ~(I2C_CTL0_PECEN);
+ ctl &= ~(I2C_CTL0_PECEN);
ctl |= pecstate;
I2C_CTL0(i2c_periph) = ctl;
}
@@ -513,66 +474,72 @@ void i2c_pec_enable(uint32_t i2c_periph,uint32_t pecstate)
\brief I2C whether to transfer PEC value
\param[in] i2c_periph: I2Cx(x=0,1,2)
\param[in] pecpara:
- \arg I2C_PECTRANS_ENABLE: transfer PEC
- \arg I2C_PECTRANS_DISABLE: not transfer PEC
+ only one parameter can be selected which is shown as below:
+ \arg I2C_PECTRANS_ENABLE: transfer PEC
+ \arg I2C_PECTRANS_DISABLE: not transfer PEC
\param[out] none
\retval none
*/
-void i2c_pec_transfer_enable(uint32_t i2c_periph,uint32_t pecpara)
+void i2c_pec_transfer_enable(uint32_t i2c_periph, uint32_t pecpara)
{
/* whether to transfer PEC */
uint32_t ctl = 0U;
+
ctl = I2C_CTL0(i2c_periph);
- ctl &= ~(I2C_CTL0_PECTRANS);
+ ctl &= ~(I2C_CTL0_PECTRANS);
ctl |= pecpara;
I2C_CTL0(i2c_periph) = ctl;
}
/*!
- \brief packet error checking value
+ \brief get packet error checking value
\param[in] i2c_periph: I2Cx(x=0,1,2)
\param[out] none
\retval PEC value
*/
-uint8_t i2c_pec_value(uint32_t i2c_periph)
+uint8_t i2c_pec_value_get(uint32_t i2c_periph)
{
- return (uint8_t)((I2C_STAT1(i2c_periph) &I2C_STAT1_ECV)>>8);
+ return (uint8_t)((I2C_STAT1(i2c_periph) & I2C_STAT1_PECV)>>STAT1_PECV_OFFSET);
}
/*!
- \brief I2C issue alert through SMBA pin
+ \brief I2C issue alert through SMBA pin
\param[in] i2c_periph: I2Cx(x=0,1,2)
\param[in] smbuspara:
- \arg I2C_SALTSEND_ENABLE: issue alert through SMBA pin
- \arg I2C_SALTSEND_DISABLE: not issue alert through SMBA pin
+ only one parameter can be selected which is shown as below:
+ \arg I2C_SALTSEND_ENABLE: issue alert through SMBA pin
+ \arg I2C_SALTSEND_DISABLE: not issue alert through SMBA pin
\param[out] none
\retval none
*/
-void i2c_smbus_alert_issue(uint32_t i2c_periph,uint32_t smbuspara)
+void i2c_smbus_issue_alert(uint32_t i2c_periph, uint32_t smbuspara)
{
/* issue alert through SMBA pin configure*/
uint32_t ctl = 0U;
+
ctl = I2C_CTL0(i2c_periph);
- ctl &= ~(I2C_CTL0_SALT);
+ ctl &= ~(I2C_CTL0_SALT);
ctl |= smbuspara;
I2C_CTL0(i2c_periph) = ctl;
}
/*!
- \brief I2C ARP protocol in SMBus switch enable or disable
+ \brief enable or disable I2C ARP protocol in SMBus switch
\param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] smbuspara:
- \arg I2C_ARP_ENABLE: ARP is enabled
- \arg I2C_ARP_DISABLE: ARP is disabled
+ \param[in] arpstate:
+ only one parameter can be selected which is shown as below:
+ \arg I2C_ARP_ENABLE: enable ARP
+ \arg I2C_ARP_DISABLE: disable ARP
\param[out] none
\retval none
*/
-void i2c_smbus_arp_enable(uint32_t i2c_periph,uint32_t arpstate)
+void i2c_smbus_arp_enable(uint32_t i2c_periph, uint32_t arpstate)
{
/* enable or disable I2C ARP protocol*/
uint32_t ctl = 0U;
+
ctl = I2C_CTL0(i2c_periph);
- ctl &= ~(I2C_CTL0_ARPEN);
+ ctl &= ~(I2C_CTL0_ARPEN);
ctl |= arpstate;
I2C_CTL0(i2c_periph) = ctl;
}
@@ -585,7 +552,7 @@ void i2c_smbus_arp_enable(uint32_t i2c_periph,uint32_t arpstate)
*/
void i2c_analog_noise_filter_disable(uint32_t i2c_periph)
{
- I2C_FCTL(i2c_periph) |= I2C_FCTL_AFD;
+ I2C_FCTL(i2c_periph) |= I2C_FCTL_AFD;
}
/*!
@@ -596,19 +563,19 @@ void i2c_analog_noise_filter_disable(uint32_t i2c_periph)
*/
void i2c_analog_noise_filter_enable(uint32_t i2c_periph)
{
- I2C_FCTL(i2c_periph) &= ~(I2C_FCTL_AFD);
+ I2C_FCTL(i2c_periph) &= ~(I2C_FCTL_AFD);
}
/*!
\brief digital noise filter configuration
\param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] dfilterpara: refer to enum i2c_gcall_config_enum
+ \param[in] dfilterpara: refer to enum i2c_digital_filter_enum
\param[out] none
\retval none
*/
void i2c_digital_noise_filter_config(uint32_t i2c_periph,i2c_digital_filter_enum dfilterpara)
{
- I2C_FCTL(i2c_periph) |= dfilterpara;
+ I2C_FCTL(i2c_periph) |= dfilterpara;
}
/*!
@@ -619,7 +586,7 @@ void i2c_digital_noise_filter_config(uint32_t i2c_periph,i2c_digital_filter_enum
*/
void i2c_sam_enable(uint32_t i2c_periph)
{
- I2C_SAMCS(i2c_periph) |= I2C_SAMCS_SAMEN;
+ I2C_SAMCS(i2c_periph) |= I2C_SAMCS_SAMEN;
}
/*!
@@ -630,7 +597,7 @@ void i2c_sam_enable(uint32_t i2c_periph)
*/
void i2c_sam_disable(uint32_t i2c_periph)
{
- I2C_SAMCS(i2c_periph) &= ~(I2C_SAMCS_SAMEN);
+ I2C_SAMCS(i2c_periph) &= ~(I2C_SAMCS_SAMEN);
}
/*!
@@ -641,7 +608,7 @@ void i2c_sam_disable(uint32_t i2c_periph)
*/
void i2c_sam_timeout_enable(uint32_t i2c_periph)
{
- I2C_SAMCS(i2c_periph) |= I2C_SAMCS_STOEN;
+ I2C_SAMCS(i2c_periph) |= I2C_SAMCS_STOEN;
}
/*!
@@ -652,79 +619,201 @@ void i2c_sam_timeout_enable(uint32_t i2c_periph)
*/
void i2c_sam_timeout_disable(uint32_t i2c_periph)
{
- I2C_SAMCS(i2c_periph) &= ~(I2C_SAMCS_STOEN);
+ I2C_SAMCS(i2c_periph) &= ~(I2C_SAMCS_STOEN);
+}
+
+/*!
+ \brief check I2C flag is set or not
+ \param[in] i2c_periph: I2Cx(x=0,1,2)
+ \param[in] flag: I2C flags, refer to i2c_flag_enum
+ only one parameter can be selected which is shown as below:
+ \arg I2C_FLAG_SBSEND: start condition send out
+ \arg I2C_FLAG_ADDSEND: address is sent in master mode or received and matches in slave mode
+ \arg I2C_FLAG_BTC: byte transmission finishes
+ \arg I2C_FLAG_ADD10SEND: header of 10-bit address is sent in master mode
+ \arg I2C_FLAG_STPDET: stop condition detected in slave mode
+ \arg I2C_FLAG_RBNE: I2C_DATA is not Empty during receiving
+ \arg I2C_FLAG_TBE: I2C_DATA is empty during transmitting
+ \arg I2C_FLAG_BERR: a bus error occurs indication a unexpected start or stop condition on I2C bus
+ \arg I2C_FLAG_LOSTARB: arbitration lost in master mode
+ \arg I2C_FLAG_AERR: acknowledge error
+ \arg I2C_FLAG_OUERR: overrun or underrun situation occurs in slave mode
+ \arg I2C_FLAG_PECERR: PEC error when receiving data
+ \arg I2C_FLAG_SMBTO: timeout signal in SMBus mode
+ \arg I2C_FLAG_SMBALT: SMBus alert status
+ \arg I2C_FLAG_MASTER: a flag indicating whether I2C block is in master or slave mode
+ \arg I2C_FLAG_I2CBSY: busy flag
+ \arg I2C_FLAG_TRS: whether the I2C is a transmitter or a receiver
+ \arg I2C_FLAG_RXGC: general call address (00h) received
+ \arg I2C_FLAG_DEFSMB: default address of SMBus device
+ \arg I2C_FLAG_HSTSMB: SMBus host header detected in slave mode
+ \arg I2C_FLAG_DUMOD: dual flag in slave mode indicating which address is matched in dual-address mode
+ \arg I2C_FLAG_TFF: txframe fall flag
+ \arg I2C_FLAG_TFR: txframe rise flag
+ \arg I2C_FLAG_RFF: rxframe fall flag
+ \arg I2C_FLAG_RFR: rxframe rise flag
+ \param[out] none
+ \retval FlagStatus: SET or RESET
+*/
+FlagStatus i2c_flag_get(uint32_t i2c_periph, i2c_flag_enum flag)
+{
+ if(RESET != (I2C_REG_VAL(i2c_periph, flag) & BIT(I2C_BIT_POS(flag)))){
+ return SET;
+ }else{
+ return RESET;
+ }
+}
+
+/*!
+ \brief clear I2C flag
+ \param[in] i2c_periph: I2Cx(x=0,1,2)
+ \param[in] flag: I2C flags, refer to i2c_flag_enum
+ only one parameter can be selected which is shown as below:
+ \arg I2C_FLAG_SMBALT: SMBus Alert status
+ \arg I2C_FLAG_SMBTO: timeout signal in SMBus mode
+ \arg I2C_FLAG_PECERR: PEC error when receiving data
+ \arg I2C_FLAG_OUERR: over-run or under-run situation occurs in slave mode
+ \arg I2C_FLAG_AERR: acknowledge error
+ \arg I2C_FLAG_LOSTARB: arbitration lost in master mode
+ \arg I2C_FLAG_BERR: a bus error
+ \arg I2C_FLAG_ADDSEND: cleared by reading I2C_STAT0 and reading I2C_STAT1
+ \arg I2C_FLAG_TFF: txframe fall flag
+ \arg I2C_FLAG_TFR: txframe rise flag
+ \arg I2C_FLAG_RFF: rxframe fall flag
+ \arg I2C_FLAG_RFR: rxframe rise flag
+ \param[out] none
+ \retval none
+*/
+void i2c_flag_clear(uint32_t i2c_periph, i2c_flag_enum flag)
+{
+ if(I2C_FLAG_ADDSEND == flag){
+ /* read I2C_STAT0 and then read I2C_STAT1 to clear ADDSEND */
+ I2C_STAT0(i2c_periph);
+ I2C_STAT1(i2c_periph);
+ }else{
+ I2C_REG_VAL(i2c_periph, flag) &= ~BIT(I2C_BIT_POS(flag));
+ }
}
/*!
- \brief enable the specified I2C SAM interrupt
+ \brief enable I2C interrupt
\param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] inttype: interrupt type
- \@arg I2C_SAMCS_TFFIE: txframe fall interrupt
- \@arg I2C_SAMCS_TFRIE: txframe rise interrupt
- \@arg I2C_SAMCS_RFFIE: rxframe fall interrupt
- \@arg I2C_SAMCS_RFRIE: rxframe rise interrupt
- \param[out] none
- \retval none
+ \param[in] interrupt: I2C interrupts, refer to i2c_interrupt_enum
+ only one parameter can be selected which is shown as below:
+ \arg I2C_INT_ERR: error interrupt enable
+ \arg I2C_INT_EV: event interrupt enable
+ \arg I2C_INT_BUF: buffer interrupt enable
+ \arg I2C_INT_TFF: txframe fall interrupt enable
+ \arg I2C_INT_TFR: txframe rise interrupt enable
+ \arg I2C_INT_RFF: rxframe fall interrupt enable
+ \arg I2C_INT_RFR: rxframe rise interrupt enable
+ \param[out] none
+ \retval none
*/
-void i2c_sam_interrupt_enable(uint32_t i2c_periph,uint32_t inttype)
+void i2c_interrupt_enable(uint32_t i2c_periph, i2c_interrupt_enum interrupt)
{
- I2C_SAMCS(i2c_periph) |= (inttype);
+ I2C_REG_VAL(i2c_periph, interrupt) |= BIT(I2C_BIT_POS(interrupt));
}
/*!
- \brief disable i2c interrupt
+ \brief disable I2C interrupt
\param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] inttype: interrupt type
- \@arg I2C_SAMCS_TFFIE: txframe fall interrupt
- \@arg I2C_SAMCS_TFRIE: txframe rise interrupt
- \@arg I2C_SAMCS_RFFIE: rxframe fall interrupt
- \@arg I2C_SAMCS_RFRIE: rxframe rise interrupt
+ \param[in] interrupt: I2C interrupts, refer to i2c_flag_enum
+ only one parameter can be selected which is shown as below:
+ \arg I2C_INT_ERR: error interrupt enable
+ \arg I2C_INT_EV: event interrupt enable
+ \arg I2C_INT_BUF: buffer interrupt enable
+ \arg I2C_INT_TFF: txframe fall interrupt enable
+ \arg I2C_INT_TFR: txframe rise interrupt enable
+ \arg I2C_INT_RFF: rxframe fall interrupt enable
+ \arg I2C_INT_RFR: rxframe rise interrupt enable
\param[out] none
\retval none
*/
-void i2c_sam_interrupt_disable(uint32_t i2c_periph,uint32_t inttype)
+void i2c_interrupt_disable(uint32_t i2c_periph, i2c_interrupt_enum interrupt)
{
- I2C_SAMCS(i2c_periph) &= ~(inttype);
+ I2C_REG_VAL(i2c_periph, interrupt) &= ~BIT(I2C_BIT_POS(interrupt));
}
/*!
- \brief check i2c SAM state
+ \brief check I2C interrupt flag
\param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] samstate: state type
- \@arg I2C_SAMCS_TXF: level of txframe signal
- \@arg I2C_SAMCS_RXF: level of rxframe signal
- \@arg I2C_SAMCS_TFF: txframe fall flag
- \@arg I2C_SAMCS_TFR: txframe rise flag
- \@arg I2C_SAMCS_RFF: rxframe fall flag
- \@arg I2C_SAMCS_RFR: rxframe rise flag
+ \param[in] int_flag: I2C interrupt flags, refer to i2c_interrupt_flag_enum
+ only one parameter can be selected which is shown as below:
+ \arg I2C_INT_FLAG_SBSEND: start condition sent out in master mode interrupt flag
+ \arg I2C_INT_FLAG_ADDSEND: address is sent in master mode or received and matches in slave mode interrupt flag
+ \arg I2C_INT_FLAG_BTC: byte transmission finishes
+ \arg I2C_INT_FLAG_ADD10SEND: header of 10-bit address is sent in master mode interrupt flag
+ \arg I2C_INT_FLAG_STPDET: etop condition detected in slave mode interrupt flag
+ \arg I2C_INT_FLAG_RBNE: I2C_DATA is not Empty during receiving interrupt flag
+ \arg I2C_INT_FLAG_TBE: I2C_DATA is empty during transmitting interrupt flag
+ \arg I2C_INT_FLAG_BERR: a bus error occurs indication a unexpected start or stop condition on I2C bus interrupt flag
+ \arg I2C_INT_FLAG_LOSTARB: arbitration lost in master mode interrupt flag
+ \arg I2C_INT_FLAG_AERR: acknowledge error interrupt flag
+ \arg I2C_INT_FLAG_OUERR: over-run or under-run situation occurs in slave mode interrupt flag
+ \arg I2C_INT_FLAG_PECERR: PEC error when receiving data interrupt flag
+ \arg I2C_INT_FLAG_SMBTO: timeout signal in SMBus mode interrupt flag
+ \arg I2C_INT_FLAG_SMBALT: SMBus Alert status interrupt flag
+ \arg I2C_INT_FLAG_TFF: txframe fall interrupt flag
+ \arg I2C_INT_FLAG_TFR: txframe rise interrupt flag
+ \arg I2C_INT_FLAG_RFF: rxframe fall interrupt flag
+ \arg I2C_INT_FLAG_RFR: rxframe rise interrupt flag
\param[out] none
- \retval state of i2c SAM
+ \retval FlagStatus: SET or RESET
*/
-FlagStatus i2c_sam_flag_get(uint32_t i2c_periph,uint32_t samstate)
+FlagStatus i2c_interrupt_flag_get(uint32_t i2c_periph, i2c_interrupt_flag_enum int_flag)
{
- FlagStatus reg = RESET;
- if(I2C_SAMCS(i2c_periph)&samstate){
- reg =SET;
+ uint32_t intenable = 0U, flagstatus = 0U, bufie;
+
+ /* check BUFIE */
+ bufie = I2C_CTL1(i2c_periph)&I2C_CTL1_BUFIE;
+
+ /* get the interrupt enable bit status */
+ intenable = (I2C_REG_VAL(i2c_periph, int_flag) & BIT(I2C_BIT_POS(int_flag)));
+ /* get the corresponding flag bit status */
+ flagstatus = (I2C_REG_VAL2(i2c_periph, int_flag) & BIT(I2C_BIT_POS2(int_flag)));
+
+ if((I2C_INT_FLAG_RBNE == int_flag) || (I2C_INT_FLAG_TBE == int_flag)){
+ if(intenable && bufie){
+ intenable = 1U;
+ }else{
+ intenable = 0U;
+ }
+ }
+ if((0U != flagstatus) && (0U != intenable)){
+ return SET;
}else{
- reg =RESET;
+ return RESET;
}
- return reg;
}
/*!
- \brief clear i2c SAM state
+ \brief clear I2C interrupt flag
\param[in] i2c_periph: I2Cx(x=0,1,2)
- \param[in] samstate: state type
- \@arg I2C_SAMCS_TFF: txframe fall flag
- \@arg I2C_SAMCS_TFR: txframe rise flag
- \@arg I2C_SAMCS_RFF: rxframe fall flag
- \@arg I2C_SAMCS_RFR: rxframe rise flag
+ \param[in] int_flag: I2C interrupt flags, refer to i2c_interrupt_flag_enum
+ only one parameter can be selected which is shown as below:
+ \arg I2C_INT_FLAG_ADDSEND: address is sent in master mode or received and matches in slave mode interrupt flag
+ \arg I2C_INT_FLAG_BERR: a bus error occurs indication a unexpected start or stop condition on I2C bus interrupt flag
+ \arg I2C_INT_FLAG_LOSTARB: arbitration lost in master mode interrupt flag
+ \arg I2C_INT_FLAG_AERR: acknowledge error interrupt flag
+ \arg I2C_INT_FLAG_OUERR: over-run or under-run situation occurs in slave mode interrupt flag
+ \arg I2C_INT_FLAG_PECERR: PEC error when receiving data interrupt flag
+ \arg I2C_INT_FLAG_SMBTO: timeout signal in SMBus mode interrupt flag
+ \arg I2C_INT_FLAG_SMBALT: SMBus Alert status interrupt flag
+ \arg I2C_INT_FLAG_TFF: txframe fall interrupt flag
+ \arg I2C_INT_FLAG_TFR: txframe rise interrupt flag
+ \arg I2C_INT_FLAG_RFF: rxframe fall interrupt flag
+ \arg I2C_INT_FLAG_RFR: rxframe rise interrupt flag
\param[out] none
\retval none
*/
-void i2c_sam_flag_clear(uint32_t i2c_periph,uint32_t samstate)
+void i2c_interrupt_flag_clear(uint32_t i2c_periph, i2c_interrupt_flag_enum int_flag)
{
- I2C_SAMCS(i2c_periph) &= ~(samstate);
-
+ if(I2C_INT_FLAG_ADDSEND == int_flag){
+ /* read I2C_STAT0 and then read I2C_STAT1 to clear ADDSEND */
+ I2C_STAT0(i2c_periph);
+ I2C_STAT1(i2c_periph);
+ }else{
+ I2C_REG_VAL2(i2c_periph, int_flag) &= ~BIT(I2C_BIT_POS2(int_flag));
+ }
}
-
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_ipa.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_ipa.c
index d50b473ab9..5afcc48e0d 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_ipa.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_ipa.c
@@ -1,30 +1,57 @@
/*!
- \file gd32f4xx_ipa.c
- \brief IPA driver
+ \file gd32f4xx_ipa.c
+ \brief IPA driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#include "gd32f4xx_ipa.h"
+#define IPA_DEFAULT_VALUE 0x00000000U
+
/*!
- \brief deinitialize IPA registers
+ \brief deinitialize IPA registers
\param[in] none
\param[out] none
\retval none
*/
void ipa_deinit(void)
{
- rcu_periph_reset_enable(RCU_IPAENRST);
- rcu_periph_reset_disable(RCU_IPAENRST);
+ rcu_periph_reset_enable(RCU_IPARST);
+ rcu_periph_reset_disable(RCU_IPARST);
}
/*!
- \brief IPA transfer enable
+ \brief enable IPA transfer
\param[in] none
\param[out] none
\retval none
@@ -35,8 +62,8 @@ void ipa_transfer_enable(void)
}
/*!
- \brief IPA transfer hang up enable
- \param[in] none.
+ \brief enable IPA transfer hang up
+ \param[in] none
\param[out] none
\retval none
*/
@@ -46,8 +73,8 @@ void ipa_transfer_hangup_enable(void)
}
/*!
- \brief IPA transfer hang up disable
- \param[in] none.
+ \brief disable IPA transfer hang up
+ \param[in] none
\param[out] none
\retval none
*/
@@ -57,8 +84,8 @@ void ipa_transfer_hangup_disable(void)
}
/*!
- \brief IPA transfer stop enable
- \param[in] none.
+ \brief enable IPA transfer stop
+ \param[in] none
\param[out] none
\retval none
*/
@@ -68,8 +95,8 @@ void ipa_transfer_stop_enable(void)
}
/*!
- \brief IPA transfer stop disable
- \param[in] none.
+ \brief disable IPA transfer stop
+ \param[in] none
\param[out] none
\retval none
*/
@@ -78,8 +105,8 @@ void ipa_transfer_stop_disable(void)
IPA_CTL &= ~(IPA_CTL_TST);
}
/*!
- \brief IPA foreground LUT loading enable
- \param[in] none.
+ \brief enable IPA foreground LUT loading
+ \param[in] none
\param[out] none
\retval none
*/
@@ -89,8 +116,8 @@ void ipa_foreground_lut_loading_enable(void)
}
/*!
- \brief IPA background LUT loading enable
- \param[in] none.
+ \brief enable IPA background LUT loading
+ \param[in] none
\param[out] none
\retval none
*/
@@ -100,94 +127,217 @@ void ipa_background_lut_loading_enable(void)
}
/*!
- \brief Pixel format convert mode
- \param[in] pfcm:
- \arg IPA_FGTODE: foreground memory to destination memory without pixel format convert
- \arg IPA_FGTODE_PF_CONVERT: foreground memory to destination memory with pixel format convert
- \arg IPA_FGBGTODE: blending foreground and background memory to destination memory
- \arg IPA_FILL_UP_DE: fill up destination memory with specific color
+ \brief set pixel format convert mode, the function is invalid when the IPA transfer is enabled
+ \param[in] pfcm: pixel format convert mode
+ only one parameter can be selected which is shown as below:
+ \arg IPA_FGTODE: foreground memory to destination memory without pixel format convert
+ \arg IPA_FGTODE_PF_CONVERT: foreground memory to destination memory with pixel format convert
+ \arg IPA_FGBGTODE: blending foreground and background memory to destination memory
+ \arg IPA_FILL_UP_DE: fill up destination memory with specific color
\param[out] none
\retval none
*/
-void ipa_pixel_format_convert_mod(uint32_t pfcm)
+void ipa_pixel_format_convert_mode_set(uint32_t pfcm)
{
IPA_CTL |= pfcm;
}
/*!
- \brief initialize foreground parameters
- \param[in] foreground_struct: the data needed to initialize fore.
+ \brief initialize the structure of IPA foreground parameter struct with the default values, it is
+ suggested that call this function after an ipa_foreground_parameter_struct structure is defined
+ \param[in] none
+ \param[out] foreground_struct: the data needed to initialize foreground
+ foreground_memaddr: foreground memory base address
+ foreground_lineoff: foreground line offset
+ foreground_prealpha: foreground pre-defined alpha value
+ foreground_alpha_algorithm: IPA_FG_ALPHA_MODE_0,IPA_FG_ALPHA_MODE_1,IPA_FG_ALPHA_MODE_2
+ foreground_pf: foreground pixel format(FOREGROUND_PPF_ARGB8888,FOREGROUND_PPF_RGB888,FOREGROUND_PPF_RGB565,
+ FOREGROUND_PPF_ARG1555,FOREGROUND_PPF_ARGB4444,FOREGROUND_PPF_L8,FOREGROUND_PPF_AL44,
+ FOREGROUND_PPF_AL88,FOREGROUND_PPF_L4,FOREGROUND_PPF_A8,FOREGROUND_PPF_A4)
+ foreground_prered: foreground pre-defined red value
+ foreground_pregreen: foreground pre-defined green value
+ foreground_preblue: foreground pre-defined blue value
+ \retval none
+*/
+void ipa_foreground_struct_para_init(ipa_foreground_parameter_struct* foreground_struct)
+{
+ /* initialize the struct parameters with default values */
+ foreground_struct->foreground_memaddr = IPA_DEFAULT_VALUE;
+ foreground_struct->foreground_lineoff = IPA_DEFAULT_VALUE;
+ foreground_struct->foreground_prealpha = IPA_DEFAULT_VALUE;
+ foreground_struct->foreground_alpha_algorithm = IPA_FG_ALPHA_MODE_0;
+ foreground_struct->foreground_pf = FOREGROUND_PPF_ARGB8888;
+ foreground_struct->foreground_prered = IPA_DEFAULT_VALUE;
+ foreground_struct->foreground_pregreen = IPA_DEFAULT_VALUE;
+ foreground_struct->foreground_preblue = IPA_DEFAULT_VALUE;
+}
+
+/*!
+ \brief initialize foreground parameters
+ \param[in] foreground_struct: the data needed to initialize foreground
foreground_memaddr: foreground memory base address
foreground_lineoff: foreground line offset
- foreground_prealpha: foreground pre-defined alpha value
+ foreground_prealpha: foreground pre-defined alpha value
foreground_alpha_algorithm: IPA_FG_ALPHA_MODE_0,IPA_FG_ALPHA_MODE_1,IPA_FG_ALPHA_MODE_2
- foreground_pf: foreground pixel format
+ foreground_pf: foreground pixel format(FOREGROUND_PPF_ARGB8888,FOREGROUND_PPF_RGB888,FOREGROUND_PPF_RGB565,
+ FOREGROUND_PPF_ARG1555,FOREGROUND_PPF_ARGB4444,FOREGROUND_PPF_L8,FOREGROUND_PPF_AL44,
+ FOREGROUND_PPF_AL88,FOREGROUND_PPF_L4,FOREGROUND_PPF_A8,FOREGROUND_PPF_A4)
foreground_prered: foreground pre-defined red value
- foreground_pregreen: foreground pre-defined green value
+ foreground_pregreen: foreground pre-defined green value
foreground_preblue: foreground pre-defined blue value
\param[out] none
\retval none
*/
void ipa_foreground_init(ipa_foreground_parameter_struct* foreground_struct)
{
+ FlagStatus tempflag = RESET;
+ if(RESET != (IPA_CTL & IPA_CTL_TEN)){
+ tempflag = SET;
+ /* reset the TEN in order to configure the following bits */
+ IPA_CTL &= ~IPA_CTL_TEN;
+ }
+
/* foreground memory base address configuration */
IPA_FMADDR &= ~(IPA_FMADDR_FMADDR);
IPA_FMADDR = foreground_struct->foreground_memaddr;
/* foreground line offset configuration */
IPA_FLOFF &= ~(IPA_FLOFF_FLOFF);
IPA_FLOFF = foreground_struct->foreground_lineoff;
- /* foreground pixel format pre-defined alpha, alpha calculation algorithm configuration */
- IPA_FPCTL &= ~(IPA_FPCTL_FAVCA|IPA_FPCTL_FAVCA|IPA_FPCTL_FPF);
+ /* foreground pixel format pre-defined alpha, alpha calculation algorithm configuration */
+ IPA_FPCTL &= ~(IPA_FPCTL_FPDAV|IPA_FPCTL_FAVCA|IPA_FPCTL_FPF);
IPA_FPCTL |= (foreground_struct->foreground_prealpha<<24U);
IPA_FPCTL |= foreground_struct->foreground_alpha_algorithm;
IPA_FPCTL |= foreground_struct->foreground_pf;
- /* foreground pre-defined red green blue configuration */
+ /* foreground pre-defined red green blue configuration */
IPA_FPV &= ~(IPA_FPV_FPDRV|IPA_FPV_FPDGV|IPA_FPV_FPDBV);
- IPA_FPV |= ((foreground_struct->foreground_prered<<16U)|(foreground_struct->foreground_pregreen<<8U)|(foreground_struct->foreground_preblue));
+ IPA_FPV |= ((foreground_struct->foreground_prered<<16U)|(foreground_struct->foreground_pregreen<<8U)
+ |(foreground_struct->foreground_preblue));
+
+ if(SET == tempflag){
+ /* restore the state of TEN */
+ IPA_CTL |= IPA_CTL_TEN;
+ }
+}
+
+/*!
+ \brief initialize the structure of IPA background parameter struct with the default values, it is
+ suggested that call this function after an ipa_background_parameter_struct structure is defined
+ \param[in] none
+ \param[out] background_struct: the data needed to initialize background
+ background_memaddr: background memory base address
+ background_lineoff: background line offset
+ background_prealpha: background pre-defined alpha value
+ background_alpha_algorithm: IPA_BG_ALPHA_MODE_0,IPA_BG_ALPHA_MODE_1,IPA_BG_ALPHA_MODE_2
+ background_pf: background pixel format(BACKGROUND_PPF_ARGB8888,BACKGROUND_PPF_RGB888,BACKGROUND_PPF_RGB565,
+ BACKGROUND_PPF_ARG1555,BACKGROUND_PPF_ARGB4444,BACKGROUND_PPF_L8,BACKGROUND_PPF_AL44,
+ BACKGROUND_PPF_AL88,BACKGROUND_PPF_L4,BACKGROUND_PPF_A8,BACKGROUND_PPF_A4)
+ background_prered: background pre-defined red value
+ background_pregreen: background pre-defined green value
+ background_preblue: background pre-defined blue value
+ \retval none
+*/
+void ipa_background_struct_para_init(ipa_background_parameter_struct* background_struct)
+{
+ /* initialize the struct parameters with default values */
+ background_struct->background_memaddr = IPA_DEFAULT_VALUE;
+ background_struct->background_lineoff = IPA_DEFAULT_VALUE;
+ background_struct->background_prealpha = IPA_DEFAULT_VALUE;
+ background_struct->background_alpha_algorithm = IPA_BG_ALPHA_MODE_0;
+ background_struct->background_pf = BACKGROUND_PPF_ARGB8888;
+ background_struct->background_prered = IPA_DEFAULT_VALUE;
+ background_struct->background_pregreen = IPA_DEFAULT_VALUE;
+ background_struct->background_preblue = IPA_DEFAULT_VALUE;
}
/*!
- \brief initialize background parameters
- \param[in] background_struct: the data needed to initialize fore.
+ \brief initialize background parameters
+ \param[in] background_struct: the data needed to initialize background
background_memaddr: background memory base address
background_lineoff: background line offset
- background_prealpha: background pre-defined alpha value
+ background_prealpha: background pre-defined alpha value
background_alpha_algorithm: IPA_BG_ALPHA_MODE_0,IPA_FG_ALPHA_MODE_1,IPA_FG_ALPHA_MODE_2
- background_pf: background pixel format
+ background_pf: background pixel format(BACKGROUND_PPF_ARGB8888,BACKGROUND_PPF_RGB888,BACKGROUND_PPF_RGB565,
+ BACKGROUND_PPF_ARG1555,BACKGROUND_PPF_ARGB4444,BACKGROUND_PPF_L8,BACKGROUND_PPF_AL44,
+ BACKGROUND_PPF_AL88,BACKGROUND_PPF_L4,BACKGROUND_PPF_A8,BACKGROUND_PPF_A4)
background_prered: background pre-defined red value
- background_pregreen: background pre-defined green value
+ background_pregreen: background pre-defined green value
background_preblue: background pre-defined blue value
\param[out] none
\retval none
*/
void ipa_background_init(ipa_background_parameter_struct* background_struct)
{
+ FlagStatus tempflag = RESET;
+ if(RESET != (IPA_CTL & IPA_CTL_TEN)){
+ tempflag = SET;
+ /* reset the TEN in order to configure the following bits */
+ IPA_CTL &= ~IPA_CTL_TEN;
+ }
+
/* background memory base address configuration */
IPA_BMADDR &= ~(IPA_BMADDR_BMADDR);
IPA_BMADDR = background_struct->background_memaddr;
/* background line offset configuration */
IPA_BLOFF &= ~(IPA_BLOFF_BLOFF);
- IPA_BLOFF =background_struct->background_lineoff;
- /* background pixel format pre-defined alpha, alpha calculation algorithm configuration */
- IPA_BPCTL &= ~(IPA_BPCTL_BAVCA|IPA_BPCTL_BAVCA|IPA_BPCTL_BPF);
+ IPA_BLOFF = background_struct->background_lineoff;
+ /* background pixel format pre-defined alpha, alpha calculation algorithm configuration */
+ IPA_BPCTL &= ~(IPA_BPCTL_BPDAV|IPA_BPCTL_BAVCA|IPA_BPCTL_BPF);
IPA_BPCTL |= (background_struct->background_prealpha<<24U);
IPA_BPCTL |= background_struct->background_alpha_algorithm;
- IPA_BPCTL |= background_struct->background_pf;
- /* background pre-defined red green blue configuration */
+ IPA_BPCTL |= background_struct->background_pf;
+ /* background pre-defined red green blue configuration */
IPA_BPV &= ~(IPA_BPV_BPDRV|IPA_BPV_BPDGV|IPA_BPV_BPDBV);
- IPA_BPV |= ((background_struct->background_prered<<16U)|(background_struct->background_pregreen<<8U)|(background_struct->background_preblue));
+ IPA_BPV |= ((background_struct->background_prered<<16U)|(background_struct->background_pregreen<<8U)
+ |(background_struct->background_preblue));
+
+ if(SET == tempflag){
+ /* restore the state of TEN */
+ IPA_CTL |= IPA_CTL_TEN;
+ }
+}
+
+/*!
+ \brief initialize the structure of IPA destination parameter struct with the default values, it is
+ suggested that call this function after an ipa_destination_parameter_struct structure is defined
+ \param[in] none
+ \param[out] destination_struct: the data needed to initialize destination parameter
+ destination_pf: IPA_DPF_ARGB8888,IPA_DPF_RGB888,IPA_DPF_RGB565,IPA_DPF_ARGB1555,
+ IPA_DPF_ARGB4444,refer to ipa_dpf_enum
+ destination_lineoff: destination line offset
+ destination_prealpha: destination pre-defined alpha value
+ destination_prered: destination pre-defined red value
+ destination_pregreen: destination pre-defined green value
+ destination_preblue: destination pre-defined blue value
+ destination_memaddr: destination memory base address
+ image_width: width of the image to be processed
+ image_height: height of the image to be processed
+ \retval none
+*/
+void ipa_destination_struct_para_init(ipa_destination_parameter_struct* destination_struct)
+{
+ /* initialize the struct parameters with default values */
+ destination_struct->destination_pf = IPA_DPF_ARGB8888;
+ destination_struct->destination_lineoff = IPA_DEFAULT_VALUE;
+ destination_struct->destination_prealpha = IPA_DEFAULT_VALUE;
+ destination_struct->destination_prered = IPA_DEFAULT_VALUE;
+ destination_struct->destination_pregreen = IPA_DEFAULT_VALUE;
+ destination_struct->destination_preblue = IPA_DEFAULT_VALUE;
+ destination_struct->destination_memaddr = IPA_DEFAULT_VALUE;
+ destination_struct->image_width = IPA_DEFAULT_VALUE;
+ destination_struct->image_height = IPA_DEFAULT_VALUE;
}
/*!
- \brief initialize destination parameters
- \param[in] destination_struct: the data needed to initialize tli.
- destination_pf: refer to ipa_dpf_enum
+ \brief initialize destination parameters
+ \param[in] destination_struct: the data needed to initialize destination parameters
+ destination_pf: IPA_DPF_ARGB8888,IPA_DPF_RGB888,IPA_DPF_RGB565,IPA_DPF_ARGB1555,
+ IPA_DPF_ARGB4444,refer to ipa_dpf_enum
destination_lineoff: destination line offset
- destination_prealpha: destination pre-defined alpha value
+ destination_prealpha: destination pre-defined alpha value
destination_prered: destination pre-defined red value
destination_pregreen: destination pre-defined green value
destination_preblue: destination pre-defined blue value
- destination_memaddr: destination memory base address
+ destination_memaddr: destination memory base address
image_width: width of the image to be processed
image_height: height of the image to be processed
\param[out] none
@@ -196,6 +346,13 @@ void ipa_background_init(ipa_background_parameter_struct* background_struct)
void ipa_destination_init(ipa_destination_parameter_struct* destination_struct)
{
uint32_t destination_pixelformat;
+ FlagStatus tempflag = RESET;
+ if(RESET != (IPA_CTL & IPA_CTL_TEN)){
+ tempflag = SET;
+ /* reset the TEN in order to configure the following bits */
+ IPA_CTL &= ~IPA_CTL_TEN;
+ }
+
/* destination pixel format configuration */
IPA_DPCTL &= ~(IPA_DPCTL_DPF);
IPA_DPCTL = destination_struct->destination_pf;
@@ -230,36 +387,48 @@ void ipa_destination_init(ipa_destination_parameter_struct* destination_struct)
/* destination pixel format ARGB4444 */
case IPA_DPF_ARGB4444:
IPA_DPV &= ~(IPA_DPV_DPDBV_4|(IPA_DPV_DPDGV_4)|(IPA_DPV_DPDRV_4)|(IPA_DPV_DPDAV_4));
- IPA_DPV = (destination_struct->destination_preblue|(destination_struct->destination_pregreen<<5U)
- |(destination_struct->destination_prered<<10U)
- |(destination_struct->destination_prealpha<<15U));
+ IPA_DPV = (destination_struct->destination_preblue|(destination_struct->destination_pregreen<<4U)
+ |(destination_struct->destination_prered<<8U)
+ |(destination_struct->destination_prealpha<<12U));
break;
default:
break;
}
/* destination memory base address configuration */
IPA_DMADDR &= ~(IPA_DMADDR_DMADDR);
- IPA_DMADDR =destination_struct->destination_memaddr;
- /* destination line offset configuration */
+ IPA_DMADDR = destination_struct->destination_memaddr;
+ /* destination line offset configuration */
IPA_DLOFF &= ~(IPA_DLOFF_DLOFF);
IPA_DLOFF =destination_struct->destination_lineoff;
- /* image size configuration */
+ /* image size configuration */
IPA_IMS &= ~(IPA_IMS_HEIGHT|IPA_IMS_WIDTH);
- IPA_IMS |= ((destination_struct->image_width<<16)|(destination_struct->image_height));
+ IPA_IMS |= ((destination_struct->image_width<<16U)|(destination_struct->image_height));
+
+ if(SET == tempflag){
+ /* restore the state of TEN */
+ IPA_CTL |= IPA_CTL_TEN;
+ }
}
/*!
- \brief initialize IPA foreground LUT parameters
- \param[in] fg_lut_num: foreground LUT number of pixel.
- \param[in] fg_lut_pf: foreground LUT pixel format,IPA_LUT_PF_ARGB8888,IPA_LUT_PF_RGB888.
- \param[in] fg_lut_addr: foreground LUT memory base address.
+ \brief initialize IPA foreground LUT parameters
+ \param[in] fg_lut_num: foreground LUT number of pixel
+ \param[in] fg_lut_pf: foreground LUT pixel format(IPA_LUT_PF_ARGB8888, IPA_LUT_PF_RGB888)
+ \param[in] fg_lut_addr: foreground LUT memory base address
\param[out] none
\retval none
*/
-void ipa_foreground_lut_init(uint32_t fg_lut_num,uint8_t fg_lut_pf, uint32_t fg_lut_addr)
+void ipa_foreground_lut_init(uint8_t fg_lut_num, uint8_t fg_lut_pf, uint32_t fg_lut_addr)
{
+ FlagStatus tempflag = RESET;
+ if(RESET != (IPA_FPCTL & IPA_FPCTL_FLLEN)){
+ tempflag = SET;
+ /* reset the FLLEN in order to configure the following bits */
+ IPA_FPCTL &= ~IPA_FPCTL_FLLEN;
+ }
+
/* foreground LUT number of pixel configuration */
- IPA_FPCTL |= (fg_lut_num<<8U);
+ IPA_FPCTL |= ((uint32_t)fg_lut_num<<8U);
/* foreground LUT pixel format configuration */
if(IPA_LUT_PF_RGB888 == fg_lut_pf){
IPA_FPCTL |= IPA_FPCTL_FLPF;
@@ -269,20 +438,32 @@ void ipa_foreground_lut_init(uint32_t fg_lut_num,uint8_t fg_lut_pf, uint32_t fg_
/* foreground LUT memory base address configuration */
IPA_FLMADDR &= ~(IPA_FLMADDR_FLMADDR);
IPA_FLMADDR = fg_lut_addr;
+
+ if(SET == tempflag){
+ /* restore the state of FLLEN */
+ IPA_FPCTL |= IPA_FPCTL_FLLEN;
+ }
}
/*!
- \brief initialize IPA background LUT parameters
- \param[in] bg_lut_num: background LUT number of pixel.
- \param[in] bg_lut_pf: background LUT pixel format, IPA_LUT_PF_ARGB8888,IPA_LUT_PF_RGB888.
- \param[in] bg_lut_addr: background LUT memory base address.
+ \brief initialize IPA background LUT parameters
+ \param[in] bg_lut_num: background LUT number of pixel
+ \param[in] bg_lut_pf: background LUT pixel format(IPA_LUT_PF_ARGB8888, IPA_LUT_PF_RGB888)
+ \param[in] bg_lut_addr: background LUT memory base address
\param[out] none
\retval none
*/
-void ipa_background_lut_init(uint32_t bg_lut_num,uint8_t bg_lut_pf, uint32_t bg_lut_addr)
+void ipa_background_lut_init(uint8_t bg_lut_num, uint8_t bg_lut_pf, uint32_t bg_lut_addr)
{
+ FlagStatus tempflag = RESET;
+ if(RESET != (IPA_BPCTL & IPA_BPCTL_BLLEN)){
+ tempflag = SET;
+ /* reset the BLLEN in order to configure the following bits */
+ IPA_BPCTL &= ~IPA_BPCTL_BLLEN;
+ }
+
/* background LUT number of pixel configuration */
- IPA_BPCTL|=(bg_lut_num<<8U);
+ IPA_BPCTL |= ((uint32_t)bg_lut_num<<8U);
/* background LUT pixel format configuration */
if(IPA_LUT_PF_RGB888 == bg_lut_pf){
IPA_BPCTL |= IPA_BPCTL_BLPF;
@@ -292,29 +473,34 @@ void ipa_background_lut_init(uint32_t bg_lut_num,uint8_t bg_lut_pf, uint32_t bg_
/* background LUT memory base address configuration */
IPA_BLMADDR &= ~(IPA_BLMADDR_BLMADDR);
IPA_BLMADDR = bg_lut_addr;
+
+ if(SET == tempflag){
+ /* restore the state of BLLEN */
+ IPA_BPCTL |= IPA_BPCTL_BLLEN;
+ }
}
/*!
- \brief configure line mark
- \param[in] linenum: line number.
+ \brief configure IPA line mark
+ \param[in] line_num: line number
\param[out] none
\retval none
*/
-void ipa_line_mark_config(uint32_t linenum)
+void ipa_line_mark_config(uint16_t line_num)
{
IPA_LM &= ~(IPA_LM_LM);
- IPA_LM = linenum;
+ IPA_LM = line_num;
}
/*!
- \brief Inter-timer enable or disable
- \param[in] timercfg: IPA_INTER_TIMER_ENABLE,IPA_INTER_TIMER_DISABLE
+ \brief inter-timer enable or disable
+ \param[in] timer_cfg: IPA_INTER_TIMER_ENABLE,IPA_INTER_TIMER_DISABLE
\param[out] none
\retval none
*/
-void ipa_inter_timer_config(uint8_t timercfg)
+void ipa_inter_timer_config(uint8_t timer_cfg)
{
- if(IPA_INTER_TIMER_ENABLE == timercfg){
+ if(IPA_INTER_TIMER_ENABLE == timer_cfg){
IPA_ITCTL |= IPA_ITCTL_ITEN;
}else{
IPA_ITCTL &= ~(IPA_ITCTL_ITEN);
@@ -322,68 +508,110 @@ void ipa_inter_timer_config(uint8_t timercfg)
}
/*!
- \brief number of clock cycles interval set
- \param[in] clk_num: the number of clock cycles.
+ \brief configure the number of clock cycles interval
+ \param[in] clk_num: the number of clock cycles
\param[out] none
\retval none
*/
-void ipa_interval_clock_num_config(uint32_t clk_num )
+void ipa_interval_clock_num_config(uint8_t clk_num)
{
+ /* NCCI[7:0] bits have no meaning if ITEN is '0' */
IPA_ITCTL &= ~(IPA_ITCTL_NCCI);
- IPA_ITCTL |= (clk_num<<8U);
+ IPA_ITCTL |= ((uint32_t)clk_num<<8U);
+}
+
+/*!
+ \brief get IPA flag status in IPA_INTF register
+ \param[in] flag: IPA flags
+ one or more parameters can be selected which are shown as below:
+ \arg IPA_FLAG_TAE: transfer access error interrupt flag
+ \arg IPA_FLAG_FTF: full transfer finish interrupt flag
+ \arg IPA_FLAG_TLM: transfer line mark interrupt flag
+ \arg IPA_FLAG_LAC: LUT access conflict interrupt flag
+ \arg IPA_FLAG_LLF: LUT loading finish interrupt flag
+ \arg IPA_FLAG_WCF: wrong configuration interrupt flag
+ \param[out] none
+ \retval none
+*/
+FlagStatus ipa_flag_get(uint32_t flag)
+{
+ if(RESET != (IPA_INTF & flag)){
+ return SET;
+ }else{
+ return RESET;
+ }
}
/*!
- \brief IPA interrupt enable
- \param[in] inttype: IPA interrupt bits.
- \arg IPA_CTL_TAEIE: transfer access error interrupt
- \arg IPA_CTL_FTFIE: full transfer finish interrupt
- \arg IPA_CTL_TLMIE: transfer line mark interrupt
- \arg IPA_CTL_LACIE: LUT access conflict interrupt
- \arg IPA_CTL_LLFIE: LUT loading finish interrupt
- \arg IPA_CTL_WCFIE: wrong configuration interrupt
+ \brief clear IPA flag in IPA_INTF register
+ \param[in] flag: IPA flags
+ one or more parameters can be selected which are shown as below:
+ \arg IPA_FLAG_TAE: transfer access error interrupt flag
+ \arg IPA_FLAG_FTF: full transfer finish interrupt flag
+ \arg IPA_FLAG_TLM: transfer line mark interrupt flag
+ \arg IPA_FLAG_LAC: LUT access conflict interrupt flag
+ \arg IPA_FLAG_LLF: LUT loading finish interrupt flag
+ \arg IPA_FLAG_WCF: wrong configuration interrupt flag
\param[out] none
\retval none
*/
-void ipa_interrupt_enable(uint32_t inttype)
+void ipa_flag_clear(uint32_t flag)
{
- IPA_CTL |= (inttype);
+ IPA_INTC |= (flag);
}
/*!
- \brief IPA interrupt disable
- \param[in] inttype: IPA interrupt bits.
- \arg IPA_CTL_TAEIE: transfer access error interrupt
- \arg IPA_CTL_FTFIE: full transfer finish interrupt
- \arg IPA_CTL_TLMIE: transfer line mark interrupt
- \arg IPA_CTL_LACIE: LUT access conflict interrupt
- \arg IPA_CTL_LLFIE: LUT loading finish interrupt
- \arg IPA_CTL_WCFIE: wrong configuration interrupt
+ \brief enable IPA interrupt
+ \param[in] int_flag: IPA interrupt flags
+ one or more parameters can be selected which are shown as below:
+ \arg IPA_INT_TAE: transfer access error interrupt
+ \arg IPA_INT_FTF: full transfer finish interrupt
+ \arg IPA_INT_TLM: transfer line mark interrupt
+ \arg IPA_INT_LAC: LUT access conflict interrupt
+ \arg IPA_INT_LLF: LUT loading finish interrupt
+ \arg IPA_INT_WCF: wrong configuration interrupt
\param[out] none
\retval none
*/
-void ipa_interrupt_disable(uint32_t inttype)
+void ipa_interrupt_enable(uint32_t int_flag)
{
- IPA_CTL &= ~(inttype);
+ IPA_CTL |= (int_flag);
}
/*!
- \brief get IPA interrupt flag
- \param[in] intflag: tli interrupt flag bits.
- \arg IPA_INTF_TAEIF: transfer access error interrupt flag
- \arg IPA_INTF_FTFIF: full transfer finish interrupt flag
- \arg IPA_INTF_TLMIF: transfer line mark interrupt flag
- \arg IPA_INTF_LACIF: LUT access conflict interrupt flag
- \arg IPA_INTF_LLFIF: LUT loading finish interrupt flag
- \arg IPA_INTF_WCFIF: wrong configuration interrupt flag
+ \brief disable IPA interrupt
+ \param[in] int_flag: IPA interrupt flags
+ one or more parameters can be selected which are shown as below:
+ \arg IPA_INT_TAE: transfer access error interrupt
+ \arg IPA_INT_FTF: full transfer finish interrupt
+ \arg IPA_INT_TLM: transfer line mark interrupt
+ \arg IPA_INT_LAC: LUT access conflict interrupt
+ \arg IPA_INT_LLF: LUT loading finish interrupt
+ \arg IPA_INT_WCF: wrong configuration interrupt
\param[out] none
\retval none
*/
-FlagStatus ipa_interrupt_flag_get(uint32_t intflag)
+void ipa_interrupt_disable(uint32_t int_flag)
{
- uint32_t state;
- state = IPA_INTF;
- if(state & intflag){
+ IPA_CTL &= ~(int_flag);
+}
+
+/*!
+ \brief get IPA interrupt flag
+ \param[in] int_flag: IPA interrupt flag flags
+ one or more parameters can be selected which are shown as below:
+ \arg IPA_INT_FLAG_TAE: transfer access error interrupt flag
+ \arg IPA_INT_FLAG_FTF: full transfer finish interrupt flag
+ \arg IPA_INT_FLAG_TLM: transfer line mark interrupt flag
+ \arg IPA_INT_FLAG_LAC: LUT access conflict interrupt flag
+ \arg IPA_INT_FLAG_LLF: LUT loading finish interrupt flag
+ \arg IPA_INT_FLAG_WCF: wrong configuration interrupt flag
+ \param[out] none
+ \retval none
+*/
+FlagStatus ipa_interrupt_flag_get(uint32_t int_flag)
+{
+ if(0U != (IPA_INTF & int_flag)){
return SET;
}else{
return RESET;
@@ -391,19 +619,19 @@ FlagStatus ipa_interrupt_flag_get(uint32_t intflag)
}
/*!
- \brief clear IPA interrupt flag
- \param[in] intflag: tli interrupt flag bits.
- \arg IPA_INTC_TAEIFC: transfer access error interrupt flag
- \arg IPA_INTC_FTFIFC: full transfer finish interrupt flag
- \arg IPA_INTC_TLMIFC: transfer line mark interrupt flag
- \arg IPA_INTC_LACIFC: LUT access conflict interrupt flag
- \arg IPA_INTC_LLFIFC: LUT loading finish interrupt flag
- \arg IPA_INTC_WCFIFC: wrong configuration interrupt flag
+ \brief clear IPA interrupt flag
+ \param[in] int_flag: IPA interrupt flag flags
+ one or more parameters can be selected which are shown as below:
+ \arg IPA_INT_FLAG_TAE: transfer access error interrupt flag
+ \arg IPA_INT_FLAG_FTF: full transfer finish interrupt flag
+ \arg IPA_INT_FLAG_TLM: transfer line mark interrupt flag
+ \arg IPA_INT_FLAG_LAC: LUT access conflict interrupt flag
+ \arg IPA_INT_FLAG_LLF: LUT loading finish interrupt flag
+ \arg IPA_INT_FLAG_WCF: wrong configuration interrupt flag
\param[out] none
\retval none
*/
-void ipa_interrupt_flag_clear(uint32_t intflag)
+void ipa_interrupt_flag_clear(uint32_t int_flag)
{
- IPA_INTC |= (intflag);
+ IPA_INTC |= (int_flag);
}
-
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_iref.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_iref.c
index 237fc2ee75..218a070ef4 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_iref.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_iref.c
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_iref.c
- \brief IREF driver
+ \file gd32f4xx_iref.c
+ \brief IREF driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#include "gd32f4xx_iref.h"
@@ -87,7 +112,7 @@ void iref_sink_set(uint32_t sinkmode)
}
/*!
- \brief set IREF step data
+ \brief set IREF step data
\param[in] stepdata
\arg IREF_CUR_STEP_DATA_X:(x=0..63): step*x
\param[out] none
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_misc.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_misc.c
index 1649929a4b..c826722f13 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_misc.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_misc.c
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_misc.c
- \brief MISC driver
+ \file gd32f4xx_misc.c
+ \brief MISC driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#include "gd32f4xx_misc.h"
@@ -36,7 +61,7 @@ void nvic_priority_group_set(uint32_t nvic_prigroup)
\param[out] none
\retval none
*/
-void nvic_irq_enable(uint8_t nvic_irq, uint8_t nvic_irq_pre_priority,
+void nvic_irq_enable(uint8_t nvic_irq, uint8_t nvic_irq_pre_priority,
uint8_t nvic_irq_sub_priority)
{
uint32_t temp_priority = 0x00U, temp_pre = 0x00U, temp_sub = 0x00U;
@@ -57,6 +82,9 @@ void nvic_irq_enable(uint8_t nvic_irq, uint8_t nvic_irq_pre_priority,
temp_pre=4U;
temp_sub=0x0U;
}else{
+ nvic_priority_group_set(NVIC_PRIGROUP_PRE2_SUB2);
+ temp_pre=2U;
+ temp_sub=0x2U;
}
/* get the temp_priority to fill the NVIC->IP register */
temp_priority = (uint32_t)nvic_irq_pre_priority << (0x4U - temp_pre);
@@ -96,10 +124,10 @@ void nvic_vector_table_set(uint32_t nvic_vict_tab, uint32_t offset)
/*!
\brief set the state of the low power mode
\param[in] lowpower_mode: the low power mode state
- \arg SCB_LPM_SLEEP_EXIT_ISR: if chose this para, the system always enter low power
+ \arg SCB_LPM_SLEEP_EXIT_ISR: if chose this para, the system always enter low power
mode by exiting from ISR
\arg SCB_LPM_DEEPSLEEP: if chose this para, the system will enter the DEEPSLEEP mode
- \arg SCB_LPM_WAKE_BY_ALL_INT: if chose this para, the lowpower mode can be woke up
+ \arg SCB_LPM_WAKE_BY_ALL_INT: if chose this para, the lowpower mode can be woke up
by all the enable and disable interrupts
\param[out] none
\retval none
@@ -112,10 +140,10 @@ void system_lowpower_set(uint8_t lowpower_mode)
/*!
\brief reset the state of the low power mode
\param[in] lowpower_mode: the low power mode state
- \arg SCB_LPM_SLEEP_EXIT_ISR: if chose this para, the system will exit low power
+ \arg SCB_LPM_SLEEP_EXIT_ISR: if chose this para, the system will exit low power
mode by exiting from ISR
\arg SCB_LPM_DEEPSLEEP: if chose this para, the system will enter the SLEEP mode
- \arg SCB_LPM_WAKE_BY_ALL_INT: if chose this para, the lowpower mode only can be
+ \arg SCB_LPM_WAKE_BY_ALL_INT: if chose this para, the lowpower mode only can be
woke up by the enable interrupts
\param[out] none
\retval none
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_pmu.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_pmu.c
index 267e4c32fd..05f4cd7c3a 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_pmu.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_pmu.c
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_pmu.c
- \brief PMU driver
+ \file gd32f4xx_pmu.c
+ \brief PMU driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#include "gd32f4xx_pmu.h"
@@ -26,37 +51,37 @@ void pmu_deinit(void)
/*!
\brief select low voltage detector threshold
- \param[in] pmu_lvdt_n:
- \arg PMU_LVDT_0: voltage threshold is 2.2V
+ \param[in] lvdt_n:
+ \arg PMU_LVDT_0: voltage threshold is 2.1V
\arg PMU_LVDT_1: voltage threshold is 2.3V
\arg PMU_LVDT_2: voltage threshold is 2.4V
- \arg PMU_LVDT_3: voltage threshold is 2.5V
- \arg PMU_LVDT_4: voltage threshold is 2.6V
- \arg PMU_LVDT_5: voltage threshold is 2.7V
- \arg PMU_LVDT_6: voltage threshold is 2.8V
- \arg PMU_LVDT_7: voltage threshold is 2.9V
+ \arg PMU_LVDT_3: voltage threshold is 2.6V
+ \arg PMU_LVDT_4: voltage threshold is 2.7V
+ \arg PMU_LVDT_5: voltage threshold is 2.9V
+ \arg PMU_LVDT_6: voltage threshold is 3.0V
+ \arg PMU_LVDT_7: voltage threshold is 3.1V
\param[out] none
\retval none
*/
-void pmu_lvd_select(uint32_t pmu_lvdt_n)
+void pmu_lvd_select(uint32_t lvdt_n)
{
/* disable LVD */
PMU_CTL &= ~PMU_CTL_LVDEN;
/* clear LVDT bits */
PMU_CTL &= ~PMU_CTL_LVDT;
/* set LVDT bits according to pmu_lvdt_n */
- PMU_CTL |= pmu_lvdt_n;
+ PMU_CTL |= lvdt_n;
/* enable LVD */
PMU_CTL |= PMU_CTL_LVDEN;
}
/*!
- \brief LDO output voltage select
+ \brief select LDO output voltage
this bit set by software when the main PLL closed, before closing PLL, change the system clock to IRC16M or HXTAL
\param[in] ldo_output:
\arg PMU_LDOVS_LOW: low-driver mode enable in deep-sleep mode
- \arg PMU_LDOVS_MID: low-driver mode disable in deep-sleep mode
- \arg PMU_LDOVS_HIGH: low-driver mode disable in deep-sleep mode
+ \arg PMU_LDOVS_MID: mid-driver mode disable in deep-sleep mode
+ \arg PMU_LDOVS_HIGH: high-driver mode disable in deep-sleep mode
\param[out] none
\retval none
*/
@@ -67,10 +92,10 @@ void pmu_ldo_output_select(uint32_t ldo_output)
}
/*!
- \brief low-driver mode enable in deep-sleep mode
+ \brief enable low-driver mode in deep-sleep mode
\param[in] lowdr_mode:
- \arg PMU_LOWDRIVER_ENABLE: low-driver mode enable in deep-sleep mode
- \arg PMU_LOWDRIVER_DISABLE: low-driver mode disable in deep-sleep mode
+ \arg PMU_LOWDRIVER_ENABLE: enable low-driver mode in deep-sleep mode
+ \arg PMU_LOWDRIVER_DISABLE: disable low-driver mode in deep-sleep mode
\param[out] none
\retval none
*/
@@ -81,11 +106,11 @@ void pmu_low_driver_mode_enable(uint32_t lowdr_mode)
}
/*!
- \brief high-driver mode switch
+ \brief switch high-driver mode
this bit set by software only when IRC16M or HXTAL used as system clock
\param[in] highdr_switch:
- \arg PMU_HIGHDR_SWITCH_NONE: no high-driver mode switch
- \arg PMU_HIGHDR_SWITCH_EN: high-driver mode switch
+ \arg PMU_HIGHDR_SWITCH_NONE: disable high-driver mode switch
+ \arg PMU_HIGHDR_SWITCH_EN: enable high-driver mode switch
\param[out] none
\retval none
*/
@@ -150,8 +175,8 @@ void pmu_lowdriver_lowpower_config(uint32_t mode)
/*!
\brief low-driver mode when use normal power LDO
\param[in] mode:
- \arg PMU_NORMALDR_NORMALPWR: normal driver when use low power LDO
- \arg PMU_LOWDR_NORMALPWR: low-driver mode enabled when LDEN is 11 and use low power LDO
+ \arg PMU_NORMALDR_NORMALPWR: normal driver when use normal power LDO
+ \arg PMU_LOWDR_NORMALPWR: low-driver mode enabled when LDEN is 11 and use normal power LDO
\param[out] none
\retval none
*/
@@ -173,7 +198,7 @@ void pmu_to_sleepmode(uint8_t sleepmodecmd)
{
/* clear sleepdeep bit of Cortex-M4 system control register */
SCB->SCR &= ~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
-
+
/* select WFI or WFE command to enter sleep mode */
if(WFI_CMD == sleepmodecmd){
__WFI();
@@ -184,26 +209,37 @@ void pmu_to_sleepmode(uint8_t sleepmodecmd)
/*!
\brief PMU work at deepsleep mode
- \param[in] pmu_ldo
+ \param[in] ldo
\arg PMU_LDO_NORMAL: LDO normal work when pmu enter deepsleep mode
\arg PMU_LDO_LOWPOWER: LDO work at low power mode when pmu enter deepsleep mode
- \param[in] deepsleepmodecmd:
+ \param[in] deepsleepmodecmd:
\arg WFI_CMD: use WFI command
\arg WFE_CMD: use WFE command
\param[out] none
\retval none
*/
-void pmu_to_deepsleepmode(uint32_t pmu_ldo,uint8_t deepsleepmodecmd)
+void pmu_to_deepsleepmode(uint32_t ldo,uint8_t deepsleepmodecmd)
{
+ static uint32_t reg_snap[ 4 ];
/* clear stbmod and ldolp bits */
PMU_CTL &= ~((uint32_t)(PMU_CTL_STBMOD | PMU_CTL_LDOLP));
-
+
/* set ldolp bit according to pmu_ldo */
- PMU_CTL |= pmu_ldo;
-
+ PMU_CTL |= ldo;
+
/* set sleepdeep bit of Cortex-M4 system control register */
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
-
+
+ reg_snap[ 0 ] = REG32( 0xE000E010U );
+ reg_snap[ 1 ] = REG32( 0xE000E100U );
+ reg_snap[ 2 ] = REG32( 0xE000E104U );
+ reg_snap[ 3 ] = REG32( 0xE000E108U );
+
+ REG32( 0xE000E010U ) &= 0x00010004U;
+ REG32( 0xE000E180U ) = 0XFF7FF831U;
+ REG32( 0xE000E184U ) = 0XBFFFF8FFU;
+ REG32( 0xE000E188U ) = 0xFFFFEFFFU;
+
/* select WFI or WFE command to enter deepsleep mode */
if(WFI_CMD == deepsleepmodecmd){
__WFI();
@@ -212,6 +248,12 @@ void pmu_to_deepsleepmode(uint32_t pmu_ldo,uint8_t deepsleepmodecmd)
__WFE();
__WFE();
}
+
+ REG32( 0xE000E010U ) = reg_snap[ 0 ] ;
+ REG32( 0xE000E100U ) = reg_snap[ 1 ] ;
+ REG32( 0xE000E104U ) = reg_snap[ 2 ] ;
+ REG32( 0xE000E108U ) = reg_snap[ 3 ] ;
+
/* reset sleepdeep bit of Cortex-M4 system control register */
SCB->SCR &= ~((uint32_t)SCB_SCR_SLEEPDEEP_Msk);
}
@@ -231,10 +273,10 @@ void pmu_to_standbymode(uint8_t standbymodecmd)
/* set stbmod bit */
PMU_CTL |= PMU_CTL_STBMOD;
-
+
/* reset wakeup flag */
PMU_CTL |= PMU_CTL_WURST;
-
+
/* select WFI or WFE command to enter standby mode */
if(WFI_CMD == standbymodecmd){
__WFI();
@@ -282,25 +324,26 @@ void pmu_flag_reset(uint32_t flag_reset)
}
/*!
- \brief get flag status
+ \brief get flag state
\param[in] pmu_flag:
- \arg PMU_FLAG_WAKEUP: wakeup flag status
- \arg PMU_FLAG_STANDBY: standby flag status
- \arg PMU_FLAG_LVD: lvd flag status
+ \arg PMU_FLAG_WAKEUP: wakeup flag
+ \arg PMU_FLAG_STANDBY: standby flag
+ \arg PMU_FLAG_LVD: lvd flag
\arg PMU_FLAG_BLDORF: backup SRAM LDO ready flag
\arg PMU_FLAG_LDOVSRF: LDO voltage select ready flag
\arg PMU_FLAG_HDRF: high-driver ready flag
\arg PMU_FLAG_HDSRF: high-driver switch ready flag
- \arg PMU_FLAG_LDRF: low-driver mode ready flag
+ \arg PMU_FLAG_LDRF: low-driver mode ready flag
\param[out] none
- \retval FlagStatus SET or RESET
+ \retval FlagStatus: SET or RESET
*/
-FlagStatus pmu_flag_get(uint32_t pmu_flag )
+FlagStatus pmu_flag_get(uint32_t pmu_flag)
{
if(PMU_CS & pmu_flag){
return SET;
+ }else{
+ return RESET;
}
- return RESET;
}
/*!
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_rcu.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_rcu.c
index e37b9f9808..aecc895a09 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_rcu.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_rcu.c
@@ -1,21 +1,52 @@
/*!
- \file gd32f4xx_rcu.c
- \brief RCU driver
+ \file gd32f4xx_rcu.c
+ \brief RCU driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.1, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#include "gd32f4xx_rcu.h"
-#define SEL_IRC16M 0U
-#define SEL_HXTAL 1U
-#define SEL_PLLP 2U
-#define OSC_STARTUP_TIMEOUT ((uint16_t)0xfffffU)
-#define LXTAL_STARTUP_TIMEOUT ((uint16_t)0x3ffffffU)
+/* define clock source */
+#define SEL_IRC16M ((uint16_t)0U) /* IRC16M is selected as CK_SYS */
+#define SEL_HXTAL ((uint16_t)1U) /* HXTAL is selected as CK_SYS */
+#define SEL_PLLP ((uint16_t)2U) /* PLLP is selected as CK_SYS */
+/* define startup timeout count */
+#define OSC_STARTUP_TIMEOUT ((uint32_t)0x000fffffU)
+#define LXTAL_STARTUP_TIMEOUT ((uint32_t)0x0fffffffU)
+
+/* RCU IRC16M adjust value mask and offset*/
+#define RCU_IRC16M_ADJUST_MASK ((uint8_t)0x1FU)
+#define RCU_IRC16M_ADJUST_OFFSET ((uint32_t)3U)
/*!
\brief deinitialize the RCU
@@ -33,8 +64,9 @@ void rcu_deinit(void)
RCU_CFG0_RTCDIV | RCU_CFG0_CKOUT0SEL | RCU_CFG0_I2SSEL | RCU_CFG0_CKOUT0DIV |
RCU_CFG0_CKOUT1DIV | RCU_CFG0_CKOUT1SEL);
/* reset CTL register */
- RCU_CTL &= ~(RCU_CTL_HXTALEN | RCU_CTL_CKMEN | RCU_CTL_PLLEN | RCU_CTL_PLLI2SEN |
- RCU_CTL_PLLSAIEN | RCU_CTL_HXTALBPS);
+ RCU_CTL &= ~(RCU_CTL_HXTALEN | RCU_CTL_CKMEN | RCU_CTL_PLLEN | RCU_CTL_PLLI2SEN
+ | RCU_CTL_PLLSAIEN);
+ RCU_CTL &= ~(RCU_CTL_HXTALBPS);
/* reset PLL register */
RCU_PLL = 0x24003010U;
/* reset PLLI2S register */
@@ -44,7 +76,7 @@ void rcu_deinit(void)
/* reset INT register */
RCU_INT = 0x00000000U;
/* reset CFG1 register */
- RCU_CFG1 &= ~(RCU_CFG1_PLLSAIRDIV | RCU_CFG1_TIMERSEL);
+ RCU_CFG1 &= ~(RCU_CFG1_PLLSAIRDIV | RCU_CFG1_TIMERSEL);
}
/*!
@@ -236,7 +268,7 @@ void rcu_periph_clock_sleep_disable(rcu_periph_sleep_enum periph)
\arg RCU_GPIOxRST (x=A,B,C,D,E,F,G,H,I): reset GPIO ports
\arg RCU_CRCRST: reset CRC
\arg RCU_DMAxRST (x=0,1): reset DMA
- \arg RCU_IPAENRST: reset IPA
+ \arg RCU_IPARST: reset IPA
\arg RCU_ENETRST: reset ENET
\arg RCU_USBHSRST: reset USBHS
\arg RCU_DCIRST: reset DCI
@@ -273,7 +305,7 @@ void rcu_periph_reset_enable(rcu_periph_reset_enum periph_reset)
\arg RCU_GPIOxRST (x=A,B,C,D,E,F,G,H,I): reset GPIO ports
\arg RCU_CRCRST: reset CRC
\arg RCU_DMAxRST (x=0,1): reset DMA
- \arg RCU_IPAENRST: reset IPA
+ \arg RCU_IPARST: reset IPA
\arg RCU_ENETRST: reset ENET
\arg RCU_USBHSRST: reset USBHS
\arg RCU_DCIRST: reset DCI
@@ -338,7 +370,7 @@ void rcu_bkp_reset_disable(void)
void rcu_system_clock_source_config(uint32_t ck_sys)
{
uint32_t reg;
-
+
reg = RCU_CFG0;
/* reset the SCS bits and set according to ck_sys */
reg &= ~RCU_CFG0_SCS;
@@ -370,9 +402,9 @@ uint32_t rcu_system_clock_source_get(void)
void rcu_ahb_clock_config(uint32_t ck_ahb)
{
uint32_t reg;
-
+
reg = RCU_CFG0;
- /* reset the AHBPS bits and set according to ck_ahb */
+ /* reset the AHBPSC bits and set according to ck_ahb */
reg &= ~RCU_CFG0_AHBPSC;
RCU_CFG0 = (reg | ck_ahb);
}
@@ -392,9 +424,9 @@ void rcu_ahb_clock_config(uint32_t ck_ahb)
void rcu_apb1_clock_config(uint32_t ck_apb1)
{
uint32_t reg;
-
+
reg = RCU_CFG0;
- /* reset the APB1PS and set according to ck_apb1 */
+ /* reset the APB1PSC and set according to ck_apb1 */
reg &= ~RCU_CFG0_APB1PSC;
RCU_CFG0 = (reg | ck_apb1);
}
@@ -414,9 +446,9 @@ void rcu_apb1_clock_config(uint32_t ck_apb1)
void rcu_apb2_clock_config(uint32_t ck_apb2)
{
uint32_t reg;
-
+
reg = RCU_CFG0;
- /* reset the APB2PS and set according to ck_apb2 */
+ /* reset the APB2PSC and set according to ck_apb2 */
reg &= ~RCU_CFG0_APB2PSC;
RCU_CFG0 = (reg | ck_apb2);
}
@@ -429,7 +461,7 @@ void rcu_apb2_clock_config(uint32_t ck_apb2)
\arg RCU_CKOUT0SRC_LXTAL: LXTAL selected
\arg RCU_CKOUT0SRC_HXTAL: HXTAL selected
\arg RCU_CKOUT0SRC_PLLP: PLLP selected
- \param[in] ckout0_div: CK_OUT0 divider
+ \param[in] ckout0_div: CK_OUT0 divider
\arg RCU_CKOUT0_DIVx(x=1,2,3,4,5): CK_OUT0 is divided by x
\param[out] none
\retval none
@@ -437,7 +469,7 @@ void rcu_apb2_clock_config(uint32_t ck_apb2)
void rcu_ckout0_config(uint32_t ckout0_src, uint32_t ckout0_div)
{
uint32_t reg;
-
+
reg = RCU_CFG0;
/* reset the CKOUT0SRC, CKOUT0DIV and set according to ckout0_src and ckout0_div */
reg &= ~(RCU_CFG0_CKOUT0SEL | RCU_CFG0_CKOUT0DIV );
@@ -451,8 +483,8 @@ void rcu_ckout0_config(uint32_t ckout0_src, uint32_t ckout0_div)
\arg RCU_CKOUT1SRC_SYSTEMCLOCK: system clock selected
\arg RCU_CKOUT1SRC_PLLI2SR: PLLI2SR selected
\arg RCU_CKOUT1SRC_HXTAL: HXTAL selected
- \arg RCU_CKOUT1SRC_PLLP: PLLP selected
- \param[in] ckout1_div: CK_OUT1 divider
+ \arg RCU_CKOUT1SRC_PLLP: PLLP selected
+ \param[in] ckout1_div: CK_OUT1 divider
\arg RCU_CKOUT1_DIVx(x=1,2,3,4,5): CK_OUT1 is divided by x
\param[out] none
\retval none
@@ -460,7 +492,7 @@ void rcu_ckout0_config(uint32_t ckout0_src, uint32_t ckout0_div)
void rcu_ckout1_config(uint32_t ckout1_src, uint32_t ckout1_div)
{
uint32_t reg;
-
+
reg = RCU_CFG0;
/* reset the CKOUT1SRC, CKOUT1DIV and set according to ckout1_src and ckout1_div */
reg &= ~(RCU_CFG0_CKOUT1SEL | RCU_CFG0_CKOUT1DIV);
@@ -468,7 +500,7 @@ void rcu_ckout1_config(uint32_t ckout1_src, uint32_t ckout1_div)
}
/*!
- \brief configure the main PLL clock
+ \brief configure the main PLL clock
\param[in] pll_src: PLL clock source selection
\arg RCU_PLLSRC_IRC16M: select IRC16M as PLL source clock
\arg RCU_PLLSRC_HXTAL: select HXTAL as PLL source clock
@@ -487,7 +519,7 @@ ErrStatus rcu_pll_config(uint32_t pll_src, uint32_t pll_psc, uint32_t pll_n, uin
{
uint32_t ss_modulation_inc;
uint32_t ss_modulation_reg;
-
+
ss_modulation_inc = 0U;
ss_modulation_reg = RCU_PLLSSCTL;
@@ -499,9 +531,9 @@ ErrStatus rcu_pll_config(uint32_t pll_src, uint32_t pll_psc, uint32_t pll_n, uin
ss_modulation_inc += RCU_SS_MODULATION_CENTER_INC;
}
}
-
+
/* check the function parameter */
- if(CHECK_PLL_PSC_VALID(pll_psc) && CHECK_PLL_N_VALID(pll_n,ss_modulation_inc) &&
+ if(CHECK_PLL_PSC_VALID(pll_psc) && CHECK_PLL_N_VALID(pll_n,ss_modulation_inc) &&
CHECK_PLL_P_VALID(pll_p) && CHECK_PLL_Q_VALID(pll_q)){
RCU_PLL = pll_psc | (pll_n << 6) | (((pll_p >> 1) - 1U) << 16) |
(pll_src) | (pll_q << 24);
@@ -509,60 +541,55 @@ ErrStatus rcu_pll_config(uint32_t pll_src, uint32_t pll_psc, uint32_t pll_n, uin
/* return status */
return ERROR;
}
-
+
/* return status */
return SUCCESS;
}
/*!
- \brief configure the PLLI2S clock
+ \brief configure the PLLI2S clock
\param[in] plli2s_n: the PLLI2S VCO clock multi factor
\arg this parameter should be selected between 50 and 500
- \param[in] plli2s_q: the PLLI2S Q output frequency division factor from PLLI2S VCO clock
- \arg this parameter should be selected between 2 and 15
\param[in] plli2s_r: the PLLI2S R output frequency division factor from PLLI2S VCO clock
\arg this parameter should be selected between 2 and 7
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
*/
-ErrStatus rcu_plli2s_config(uint32_t plli2s_n, uint32_t plli2s_q, uint32_t plli2s_r)
+ErrStatus rcu_plli2s_config(uint32_t plli2s_n, uint32_t plli2s_r)
{
/* check the function parameter */
- if(CHECK_PLLI2S_N_VALID(plli2s_n) && CHECK_PLLI2S_Q_VALID(plli2s_q) && CHECK_PLLI2S_R_VALID(plli2s_r)){
- RCU_PLLI2S = (plli2s_n << 6) | (plli2s_q << 24) | (plli2s_r << 28);
+ if(CHECK_PLLI2S_N_VALID(plli2s_n) && CHECK_PLLI2S_R_VALID(plli2s_r)){
+ RCU_PLLI2S = (plli2s_n << 6) | (plli2s_r << 28);
}else{
/* return status */
return ERROR;
}
-
+
/* return status */
- return SUCCESS;
+ return SUCCESS;
}
/*!
- \brief configure the PLLSAI clock
+ \brief configure the PLLSAI clock
\param[in] pllsai_n: the PLLSAI VCO clock multi factor
\arg this parameter should be selected between 50 and 500
\param[in] pllsai_p: the PLLSAI P output frequency division factor from PLL VCO clock
\arg this parameter should be selected 2,4,6,8
- \param[in] pllsai_q: the PLLSAI Q output frequency division factor from PLL VCO clock
- \arg this parameter should be selected between 2 and 15
\param[in] pllsai_r: the PLLSAI R output frequency division factor from PLL VCO clock
\arg this parameter should be selected between 2 and 7
\param[out] none
\retval ErrStatus: SUCCESS or ERROR
*/
-ErrStatus rcu_pllsai_config(uint32_t pllsai_n, uint32_t pllsai_p, uint32_t pllsai_q, uint32_t pllsai_r)
+ErrStatus rcu_pllsai_config(uint32_t pllsai_n, uint32_t pllsai_p, uint32_t pllsai_r)
{
/* check the function parameter */
- if(CHECK_PLLSAI_N_VALID(pllsai_n) && CHECK_PLLSAI_P_VALID(pllsai_p) &&
- CHECK_PLLSAI_Q_VALID(pllsai_q) && CHECK_PLLSAI_R_VALID(pllsai_r)){
- RCU_PLLSAI = (pllsai_n << 6U) | (((pllsai_p >> 1U) - 1U) << 16U) | (pllsai_q << 24U) | (pllsai_r << 28U);
+ if(CHECK_PLLSAI_N_VALID(pllsai_n) && CHECK_PLLSAI_P_VALID(pllsai_p) && CHECK_PLLSAI_R_VALID(pllsai_r)){
+ RCU_PLLSAI = (pllsai_n << 6U) | (((pllsai_p >> 1U) - 1U) << 16U) | (pllsai_r << 28U);
}else{
/* return status */
return ERROR;
}
-
+
/* return status */
return SUCCESS;
}
@@ -581,14 +608,34 @@ ErrStatus rcu_pllsai_config(uint32_t pllsai_n, uint32_t pllsai_p, uint32_t pllsa
void rcu_rtc_clock_config(uint32_t rtc_clock_source)
{
uint32_t reg;
-
- reg = RCU_BDCTL;
+
+ reg = RCU_BDCTL;
/* reset the RTCSRC bits and set according to rtc_clock_source */
reg &= ~RCU_BDCTL_RTCSRC;
RCU_BDCTL = (reg | rtc_clock_source);
}
/*!
+ \brief configure the frequency division of RTC clock when HXTAL was selected as its clock source
+ \param[in] rtc_div: RTC clock frequency division
+ only one parameter can be selected which is shown as below:
+ \arg RCU_RTC_HXTAL_NONE: no clock for RTC
+ \arg RCU_RTC_HXTAL_DIVx: RTCDIV clock select CK_HXTAL/x, x = 2....31
+ \param[out] none
+ \retval none
+*/
+void rcu_rtc_div_config(uint32_t rtc_div)
+{
+ uint32_t reg;
+
+ reg = RCU_CFG0;
+ /* reset the RTCDIV bits and set according to rtc_div value */
+ reg &= ~RCU_CFG0_RTCDIV;
+ RCU_CFG0 = (reg | rtc_div);
+}
+
+
+/*!
\brief configure the I2S clock source selection
\param[in] i2s_clock_source: I2S clock source selection
only one parameter can be selected which is shown as below:
@@ -600,8 +647,8 @@ void rcu_rtc_clock_config(uint32_t rtc_clock_source)
void rcu_i2s_clock_config(uint32_t i2s_clock_source)
{
uint32_t reg;
-
- reg = RCU_CFG0;
+
+ reg = RCU_CFG0;
/* reset the I2SSEL bit and set according to i2s_clock_source */
reg &= ~RCU_CFG0_I2SSEL;
RCU_CFG0 = (reg | i2s_clock_source);
@@ -619,9 +666,9 @@ void rcu_i2s_clock_config(uint32_t i2s_clock_source)
void rcu_ck48m_clock_config(uint32_t ck48m_clock_source)
{
uint32_t reg;
-
+
reg = RCU_ADDCTL;
- /* reset the I2SSEL bit and set according to i2s_clock_source */
+ /* reset the CK48MSEL bit and set according to i2s_clock_source */
reg &= ~RCU_ADDCTL_CK48MSEL;
RCU_ADDCTL = (reg | ck48m_clock_source);
}
@@ -638,7 +685,7 @@ void rcu_ck48m_clock_config(uint32_t ck48m_clock_source)
void rcu_pll48m_clock_config(uint32_t pll48m_clock_source)
{
uint32_t reg;
-
+
reg = RCU_ADDCTL;
/* reset the PLL48MSEL bit and set according to pll48m_clock_source */
reg &= ~RCU_ADDCTL_PLL48MSEL;
@@ -649,13 +696,13 @@ void rcu_pll48m_clock_config(uint32_t pll48m_clock_source)
\brief configure the TIMER clock prescaler selection
\param[in] timer_clock_prescaler: TIMER clock selection
only one parameter can be selected which is shown as below:
- \arg RCU_TIMER_PSC_MUL2: if APB1PSC/APB2PSC in RCU_CFG0 register is 0b0xx(CK_APBx = CK_AHB)
+ \arg RCU_TIMER_PSC_MUL2: if APB1PSC/APB2PSC in RCU_CFG0 register is 0b0xx(CK_APBx = CK_AHB)
or 0b100(CK_APBx = CK_AHB/2), the TIMER clock is equal to CK_AHB(CK_TIMERx = CK_AHB).
- or else, the TIMER clock is twice the corresponding APB clock (TIMER in APB1 domain: CK_TIMERx = 2 x CK_APB1;
+ or else, the TIMER clock is twice the corresponding APB clock (TIMER in APB1 domain: CK_TIMERx = 2 x CK_APB1;
TIMER in APB2 domain: CK_TIMERx = 2 x CK_APB2)
- \arg RCU_TIMER_PSC_MUL4: if APB1PSC/APB2PSC in RCU_CFG0 register is 0b0xx(CK_APBx = CK_AHB),
- 0b100(CK_APBx = CK_AHB/2), or 0b101(CK_APBx = CK_AHB/4), the TIMER clock is equal to CK_AHB(CK_TIMERx = CK_AHB).
- or else, the TIMER clock is four timers the corresponding APB clock (TIMER in APB1 domain: CK_TIMERx = 4 x CK_APB1;
+ \arg RCU_TIMER_PSC_MUL4: if APB1PSC/APB2PSC in RCU_CFG0 register is 0b0xx(CK_APBx = CK_AHB),
+ 0b100(CK_APBx = CK_AHB/2), or 0b101(CK_APBx = CK_AHB/4), the TIMER clock is equal to CK_AHB(CK_TIMERx = CK_AHB).
+ or else, the TIMER clock is four timers the corresponding APB clock (TIMER in APB1 domain: CK_TIMERx = 4 x CK_APB1;
TIMER in APB2 domain: CK_TIMERx = 4 x CK_APB2)
\param[out] none
\retval none
@@ -681,7 +728,7 @@ void rcu_timer_clock_prescaler_config(uint32_t timer_clock_prescaler)
void rcu_tli_clock_div_config(uint32_t pllsai_r_div)
{
uint32_t reg;
-
+
reg = RCU_CFG1;
/* reset the PLLSAIRDIV bit and set according to pllsai_r_div */
reg &= ~RCU_CFG1_PLLSAIRDIV;
@@ -735,9 +782,9 @@ void rcu_all_reset_flag_clear(void)
\brief get the clock stabilization interrupt and ckm flags
\param[in] int_flag: interrupt and ckm flags, refer to rcu_int_flag_enum
only one parameter can be selected which is shown as below:
- \arg RCU_INT_FLAG_IRC32KSTB: IRC40K stabilization interrupt flag
+ \arg RCU_INT_FLAG_IRC32KSTB: IRC32K stabilization interrupt flag
\arg RCU_INT_FLAG_LXTALSTB: LXTAL stabilization interrupt flag
- \arg RCU_INT_FLAG_IRC8MSTB: IRC8M stabilization interrupt flag
+ \arg RCU_INT_FLAG_IRC16MSTB: IRC16M stabilization interrupt flag
\arg RCU_INT_FLAG_HXTALSTB: HXTAL stabilization interrupt flag
\arg RCU_INT_FLAG_PLLSTB: PLL stabilization interrupt flag
\arg RCU_INT_FLAG_PLLI2SSTB: PLLI2S stabilization interrupt flag
@@ -759,7 +806,7 @@ FlagStatus rcu_interrupt_flag_get(rcu_int_flag_enum int_flag)
/*!
\brief clear the interrupt flags
- \param[in] int_flag_clear: clock stabilization and stuck interrupt flags clear, refer to rcu_int_flag_clear_enum
+ \param[in] int_flag: clock stabilization and stuck interrupt flags clear, refer to rcu_int_flag_clear_enum
only one parameter can be selected which is shown as below:
\arg RCU_INT_FLAG_IRC32KSTB_CLR: IRC32K stabilization interrupt flag clear
\arg RCU_INT_FLAG_LXTALSTB_CLR: LXTAL stabilization interrupt flag clear
@@ -773,14 +820,14 @@ FlagStatus rcu_interrupt_flag_get(rcu_int_flag_enum int_flag)
\param[out] none
\retval none
*/
-void rcu_interrupt_flag_clear(rcu_int_flag_clear_enum int_flag_clear)
+void rcu_interrupt_flag_clear(rcu_int_flag_clear_enum int_flag)
{
- RCU_REG_VAL(int_flag_clear) |= BIT(RCU_BIT_POS(int_flag_clear));
+ RCU_REG_VAL(int_flag) |= BIT(RCU_BIT_POS(int_flag));
}
/*!
\brief enable the stabilization interrupt
- \param[in] stab_int: clock stabilization interrupt, refer to rcu_int_enum
+ \param[in] interrupt: clock stabilization interrupt, refer to rcu_int_enum
Only one parameter can be selected which is shown as below:
\arg RCU_INT_IRC32KSTB: IRC32K stabilization interrupt enable
\arg RCU_INT_LXTALSTB: LXTAL stabilization interrupt enable
@@ -793,15 +840,15 @@ void rcu_interrupt_flag_clear(rcu_int_flag_clear_enum int_flag_clear)
\param[out] none
\retval none
*/
-void rcu_interrupt_enable(rcu_int_enum stab_int)
+void rcu_interrupt_enable(rcu_int_enum interrupt)
{
- RCU_REG_VAL(stab_int) |= BIT(RCU_BIT_POS(stab_int));
+ RCU_REG_VAL(interrupt) |= BIT(RCU_BIT_POS(interrupt));
}
/*!
\brief disable the stabilization interrupt
- \param[in] stab_int: clock stabilization interrupt, refer to rcu_int_enum
+ \param[in] interrupt: clock stabilization interrupt, refer to rcu_int_enum
only one parameter can be selected which is shown as below:
\arg RCU_INT_IRC32KSTB: IRC32K stabilization interrupt disable
\arg RCU_INT_LXTALSTB: LXTAL stabilization interrupt disable
@@ -814,9 +861,9 @@ void rcu_interrupt_enable(rcu_int_enum stab_int)
\param[out] none
\retval none
*/
-void rcu_interrupt_disable(rcu_int_enum stab_int)
+void rcu_interrupt_disable(rcu_int_enum interrupt)
{
- RCU_REG_VAL(stab_int) &= ~BIT(RCU_BIT_POS(stab_int));
+ RCU_REG_VAL(interrupt) &= ~BIT(RCU_BIT_POS(interrupt));
}
/*!
@@ -831,9 +878,9 @@ void rcu_interrupt_disable(rcu_int_enum stab_int)
void rcu_lxtal_drive_capability_config(uint32_t lxtal_dricap)
{
uint32_t reg;
-
+
reg = RCU_BDCTL;
-
+
/* reset the LXTALDRI bits and set according to lxtal_dricap */
reg &= ~RCU_BDCTL_LXTALDRI;
RCU_BDCTL = (reg | lxtal_dricap);
@@ -859,7 +906,7 @@ ErrStatus rcu_osci_stab_wait(rcu_osci_type_enum osci)
uint32_t stb_cnt = 0U;
ErrStatus reval = ERROR;
FlagStatus osci_stat = RESET;
-
+
switch(osci){
/* wait HXTAL stable */
case RCU_HXTAL:
@@ -867,7 +914,7 @@ ErrStatus rcu_osci_stab_wait(rcu_osci_type_enum osci)
osci_stat = rcu_flag_get(RCU_FLAG_HXTALSTB);
stb_cnt++;
}
-
+
/* check whether flag is set */
if(RESET != rcu_flag_get(RCU_FLAG_HXTALSTB)){
reval = SUCCESS;
@@ -879,31 +926,31 @@ ErrStatus rcu_osci_stab_wait(rcu_osci_type_enum osci)
osci_stat = rcu_flag_get(RCU_FLAG_LXTALSTB);
stb_cnt++;
}
-
+
/* check whether flag is set */
if(RESET != rcu_flag_get(RCU_FLAG_LXTALSTB)){
reval = SUCCESS;
}
break;
- /* wait IRC16M stable */
+ /* wait IRC16M stable */
case RCU_IRC16M:
while((RESET == osci_stat) && (IRC16M_STARTUP_TIMEOUT != stb_cnt)){
osci_stat = rcu_flag_get(RCU_FLAG_IRC16MSTB);
stb_cnt++;
}
-
+
/* check whether flag is set */
if(RESET != rcu_flag_get(RCU_FLAG_IRC16MSTB)){
reval = SUCCESS;
}
break;
- /* wait IRC48M stable */
+ /* wait IRC48M stable */
case RCU_IRC48M:
while((RESET == osci_stat) && (OSC_STARTUP_TIMEOUT != stb_cnt)){
osci_stat = rcu_flag_get(RCU_FLAG_IRC48MSTB);
stb_cnt++;
}
-
+
/* check whether flag is set */
if (RESET != rcu_flag_get(RCU_FLAG_IRC48MSTB)){
reval = SUCCESS;
@@ -915,19 +962,19 @@ ErrStatus rcu_osci_stab_wait(rcu_osci_type_enum osci)
osci_stat = rcu_flag_get(RCU_FLAG_IRC32KSTB);
stb_cnt++;
}
-
+
/* check whether flag is set */
if(RESET != rcu_flag_get(RCU_FLAG_IRC32KSTB)){
reval = SUCCESS;
}
break;
- /* wait PLL stable */
+ /* wait PLL stable */
case RCU_PLL_CK:
while((RESET == osci_stat) && (OSC_STARTUP_TIMEOUT != stb_cnt)){
osci_stat = rcu_flag_get(RCU_FLAG_PLLSTB);
stb_cnt++;
}
-
+
/* check whether flag is set */
if(RESET != rcu_flag_get(RCU_FLAG_PLLSTB)){
reval = SUCCESS;
@@ -939,29 +986,29 @@ ErrStatus rcu_osci_stab_wait(rcu_osci_type_enum osci)
osci_stat = rcu_flag_get(RCU_FLAG_PLLI2SSTB);
stb_cnt++;
}
-
+
/* check whether flag is set */
if(RESET != rcu_flag_get(RCU_FLAG_PLLI2SSTB)){
reval = SUCCESS;
}
break;
- /* wait PLLSAI stable */
+ /* wait PLLSAI stable */
case RCU_PLLSAI_CK:
while((RESET == osci_stat) && (OSC_STARTUP_TIMEOUT != stb_cnt)){
osci_stat = rcu_flag_get(RCU_FLAG_PLLSAISTB);
stb_cnt++;
}
-
+
/* check whether flag is set */
if(RESET != rcu_flag_get(RCU_FLAG_PLLSAISTB)){
reval = SUCCESS;
}
break;
-
+
default:
break;
}
-
+
/* return value */
return reval;
}
@@ -1010,8 +1057,8 @@ void rcu_osci_off(rcu_osci_type_enum osci)
\brief enable the oscillator bypass mode, HXTALEN or LXTALEN must be reset before it
\param[in] osci: oscillator types, refer to rcu_osci_type_enum
only one parameter can be selected which is shown as below:
- \arg RCU_HXTAL: HXTAL
- \arg RCU_LXTAL: LXTAL
+ \arg RCU_HXTAL: high speed crystal oscillator(HXTAL)
+ \arg RCU_LXTAL: low speed crystal oscillator(LXTAL)
\param[out] none
\retval none
*/
@@ -1020,7 +1067,7 @@ void rcu_osci_bypass_mode_enable(rcu_osci_type_enum osci)
uint32_t reg;
switch(osci){
- /* enable HXTAL to bypass mode */
+ /* enable HXTAL to bypass mode */
case RCU_HXTAL:
reg = RCU_CTL;
RCU_CTL &= ~RCU_CTL_HXTALEN;
@@ -1037,7 +1084,7 @@ void rcu_osci_bypass_mode_enable(rcu_osci_type_enum osci)
case RCU_IRC32K:
case RCU_PLL_CK:
case RCU_PLLI2S_CK:
- case RCU_PLLSAI_CK:
+ case RCU_PLLSAI_CK:
break;
default:
break;
@@ -1048,17 +1095,17 @@ void rcu_osci_bypass_mode_enable(rcu_osci_type_enum osci)
\brief disable the oscillator bypass mode, HXTALEN or LXTALEN must be reset before it
\param[in] osci: oscillator types, refer to rcu_osci_type_enum
only one parameter can be selected which is shown as below:
- \arg RCU_HXTAL: HXTAL
- \arg RCU_LXTAL: LXTAL
+ \arg RCU_HXTAL: high speed crystal oscillator(HXTAL)
+ \arg RCU_LXTAL: low speed crystal oscillator(LXTAL)
\param[out] none
\retval none
*/
void rcu_osci_bypass_mode_disable(rcu_osci_type_enum osci)
{
uint32_t reg;
-
+
switch(osci){
- /* disable HXTAL to bypass mode */
+ /* disable HXTAL to bypass mode */
case RCU_HXTAL:
reg = RCU_CTL;
RCU_CTL &= ~RCU_CTL_HXTALEN;
@@ -1075,7 +1122,7 @@ void rcu_osci_bypass_mode_disable(rcu_osci_type_enum osci)
case RCU_IRC32K:
case RCU_PLL_CK:
case RCU_PLLI2S_CK:
- case RCU_PLLSAI_CK:
+ case RCU_PLLSAI_CK:
break;
default:
break;
@@ -1108,17 +1155,18 @@ void rcu_hxtal_clock_monitor_disable(void)
/*!
\brief set the IRC16M adjust value
\param[in] irc16m_adjval: IRC16M adjust value, must be between 0 and 0x1F
+ \arg 0x00 - 0x1F
\param[out] none
\retval none
*/
void rcu_irc16m_adjust_value_set(uint32_t irc16m_adjval)
{
uint32_t reg;
-
+
reg = RCU_CTL;
/* reset the IRC16MADJ bits and set according to irc16m_adjval */
reg &= ~RCU_CTL_IRC16MADJ;
- RCU_CTL = (reg | ((irc16m_adjval & 0x1FU) << 3));
+ RCU_CTL = (reg | ((irc16m_adjval & RCU_IRC16M_ADJUST_MASK) << RCU_IRC16M_ADJUST_OFFSET));
}
/*!
@@ -1144,7 +1192,7 @@ void rcu_voltage_key_unlock(void)
\retval none
*/
void rcu_deepsleep_voltage_set(uint32_t dsvol)
-{
+{
dsvol &= RCU_DSV_DSLPVS;
RCU_DSV = dsvol;
}
@@ -1155,16 +1203,16 @@ void rcu_deepsleep_voltage_set(uint32_t dsvol)
\arg RCU_SS_TYPE_CENTER: center spread type is selected
\arg RCU_SS_TYPE_DOWN: down spread type is selected
\param[in] modstep: configure PLL spread spectrum modulation profile amplitude and frequency
- \arg This parameter should be selected between 0 and 7FFF.The following criteria must be met: MODSTEP*MODCNT=215-1
+ \arg This parameter should be selected between 0 and 7FFF.The following criteria must be met: MODSTEP*MODCNT <=2^15-1
\param[in] modcnt: configure PLL spread spectrum modulation profile amplitude and frequency
- \arg This parameter should be selected between 0 and 1FFF.The following criteria must be met: MODSTEP*MODCNT=215-1
+ \arg This parameter should be selected between 0 and 1FFF.The following criteria must be met: MODSTEP*MODCNT <=2^15-1
\param[out] none
\retval none
*/
void rcu_spread_spectrum_config(uint32_t spread_spectrum_type, uint32_t modstep, uint32_t modcnt)
{
uint32_t reg;
-
+
reg = RCU_PLLSSCTL;
/* reset the RCU_PLLSSCTL register bits */
reg &= ~(RCU_PLLSSCTL_MODCNT | RCU_PLLSSCTL_MODSTEP | RCU_PLLSSCTL_SS_TYPE);
@@ -1209,7 +1257,7 @@ uint32_t rcu_clock_freq_get(rcu_clock_freq_enum clock)
uint32_t sws, ck_freq = 0U;
uint32_t cksys_freq, ahb_freq, apb1_freq, apb2_freq;
uint32_t pllpsc, plln, pllsel, pllp, ck_src, idx, clk_exp;
-
+
/* exponent of AHB, APB1 and APB2 clock divider */
const uint8_t ahb_exp[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};
const uint8_t apb1_exp[8] = {0, 0, 0, 0, 1, 2, 3, 4};
@@ -1231,7 +1279,7 @@ uint32_t rcu_clock_freq_get(rcu_clock_freq_enum clock)
pllpsc = GET_BITS(RCU_PLL, 0U, 5U);
plln = GET_BITS(RCU_PLL, 6U, 14U);
pllp = (GET_BITS(RCU_PLL, 16U, 17U) + 1U) * 2U;
- /* PLL clock source selection, HXTAL or IRC8M/2 */
+ /* PLL clock source selection, HXTAL or IRC16M/2 */
pllsel = (RCU_PLL & RCU_PLL_PLLSEL);
if (RCU_PLLSRC_HXTAL == pllsel) {
ck_src = HXTAL_VALUE;
@@ -1249,17 +1297,17 @@ uint32_t rcu_clock_freq_get(rcu_clock_freq_enum clock)
idx = GET_BITS(RCU_CFG0, 4, 7);
clk_exp = ahb_exp[idx];
ahb_freq = cksys_freq >> clk_exp;
-
+
/* calculate APB1 clock frequency */
idx = GET_BITS(RCU_CFG0, 10, 12);
clk_exp = apb1_exp[idx];
apb1_freq = ahb_freq >> clk_exp;
-
+
/* calculate APB2 clock frequency */
idx = GET_BITS(RCU_CFG0, 13, 15);
clk_exp = apb2_exp[idx];
apb2_freq = ahb_freq >> clk_exp;
-
+
/* return the clocks frequency */
switch(clock){
case CK_SYS:
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_rtc.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_rtc.c
index 8e2713ceb1..12ee6c3207 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_rtc.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_rtc.c
@@ -1,14 +1,40 @@
/*!
- \file gd32f4xx_rtc.c
- \brief RTC driver
+ \file gd32f4xx_rtc.c
+ \brief RTC driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
+
#include "gd32f4xx_rtc.h"
/* RTC timeout value */
@@ -42,7 +68,7 @@ ErrStatus rtc_deinit(void)
error_status = rtc_init_mode_enter();
if(ERROR != error_status){
- /* reset RTC_CTL register, but RTC_CTL[2��0] */
+ /* reset RTC_CTL register, but RTC_CTL[2��0] */
RTC_CTL &= (RTC_REGISTER_RESET | RTC_CTL_WTCS);
/* before reset RTC_TIME and RTC_DATE, BPSHAD bit in RTC_CTL should be reset as the condition.
in order to read calendar from shadow register, not the real registers being reset */
@@ -50,7 +76,7 @@ ErrStatus rtc_deinit(void)
RTC_DATE = RTC_DATE_RESET;
RTC_PSC = RTC_PSC_RESET;
- /* only when RTC_CTL_WTEN=0 and RTC_STAT_WTWF=1 can write RTC_CTL[2��0] */
+ /* only when RTC_CTL_WTEN=0 and RTC_STAT_WTWF=1 can write RTC_CTL[2��0] */
/* wait until the WTWF flag to be set */
do{
flag_status = RTC_STAT & RTC_STAT_WTWF;
@@ -63,7 +89,7 @@ ErrStatus rtc_deinit(void)
RTC_WUT = RTC_WUT_RESET;
RTC_COSC = RTC_REGISTER_RESET;
/* to write RTC_ALRMxSS register, ALRMxEN bit in RTC_CTL register should be reset as the condition */
- RTC_ALRM0TD = RTC_REGISTER_RESET;
+ RTC_ALRM0TD = RTC_REGISTER_RESET;
RTC_ALRM1TD = RTC_REGISTER_RESET;
RTC_ALRM0SS = RTC_REGISTER_RESET;
RTC_ALRM1SS = RTC_REGISTER_RESET;
@@ -71,9 +97,9 @@ ErrStatus rtc_deinit(void)
at the same time, RTC_STAT_SOPF bit is reset, as the condition to reset RTC_SHIFTCTL register later */
RTC_STAT = RTC_STAT_RESET;
/* reset RTC_SHIFTCTL and RTC_HRFC register, this can be done without the init mode */
- RTC_SHIFTCTL = RTC_REGISTER_RESET;
+ RTC_SHIFTCTL = RTC_REGISTER_RESET;
RTC_HRFC = RTC_REGISTER_RESET;
- error_status = rtc_register_sync_wait();
+ error_status = rtc_register_sync_wait();
}
}
@@ -85,7 +111,7 @@ ErrStatus rtc_deinit(void)
/*!
\brief initialize RTC registers
- \param[in] rtc_initpara_struct: pointer to a rtc_parameter_struct structure which contains
+ \param[in] rtc_initpara_struct: pointer to a rtc_parameter_struct structure which contains
parameters for initialization of the rtc peripheral
members of the structure and the member values are shown as below:
year: 0x0 - 0x99(BCD format)
@@ -112,13 +138,13 @@ ErrStatus rtc_init(rtc_parameter_struct* rtc_initpara_struct)
reg_date = (DATE_YR(rtc_initpara_struct->year) | \
DATE_DOW(rtc_initpara_struct->day_of_week) | \
DATE_MON(rtc_initpara_struct->month) | \
- DATE_DAY(rtc_initpara_struct->date));
-
+ DATE_DAY(rtc_initpara_struct->date));
+
reg_time = (rtc_initpara_struct->am_pm| \
TIME_HR(rtc_initpara_struct->hour) | \
TIME_MN(rtc_initpara_struct->minute) | \
- TIME_SC(rtc_initpara_struct->second));
-
+ TIME_SC(rtc_initpara_struct->second));
+
/* 1st: disable the write protection */
RTC_WPK = RTC_UNLOCK_KEY1;
RTC_WPK = RTC_UNLOCK_KEY2;
@@ -126,7 +152,7 @@ ErrStatus rtc_init(rtc_parameter_struct* rtc_initpara_struct)
/* 2nd: enter init mode */
error_status = rtc_init_mode_enter();
- if(ERROR != error_status){
+ if(ERROR != error_status){
RTC_PSC = (uint32_t)(PSC_FACTOR_A(rtc_initpara_struct->factor_asyn)| \
PSC_FACTOR_S(rtc_initpara_struct->factor_syn));
@@ -135,11 +161,11 @@ ErrStatus rtc_init(rtc_parameter_struct* rtc_initpara_struct)
RTC_CTL &= (uint32_t)(~RTC_CTL_CS);
RTC_CTL |= rtc_initpara_struct->display_format;
-
- /* 3rd: exit init mode */
+
+ /* 3rd: exit init mode */
rtc_init_mode_exit();
-
- /* 4th: wait the RSYNF flag to set */
+
+ /* 4th: wait the RSYNF flag to set */
error_status = rtc_register_sync_wait();
}
@@ -162,15 +188,15 @@ ErrStatus rtc_init_mode_enter(void)
ErrStatus error_status = ERROR;
/* check whether it has been in init mode */
- if ((uint32_t)RESET == (RTC_STAT & RTC_STAT_INITF)){
+ if ((uint32_t)RESET == (RTC_STAT & RTC_STAT_INITF)){
RTC_STAT |= RTC_STAT_INITM;
-
+
/* wait until the INITF flag to be set */
do{
flag_status = RTC_STAT & RTC_STAT_INITF;
}while((--time_index > 0U) && ((uint32_t)RESET == flag_status));
- if ((uint32_t)RESET != flag_status){
+ if ((uint32_t)RESET != flag_status){
error_status = SUCCESS;
}
}else{
@@ -191,7 +217,7 @@ void rtc_init_mode_exit(void)
}
/*!
- \brief wait until RTC_TIME and RTC_DATE registers are synchronized with APB clock, and the shadow
+ \brief wait until RTC_TIME and RTC_DATE registers are synchronized with APB clock, and the shadow
registers are updated
\param[in] none
\param[out] none
@@ -216,13 +242,13 @@ ErrStatus rtc_register_sync_wait(void)
flag_status = RTC_STAT & RTC_STAT_RSYNF;
}while((--time_index > 0U) && ((uint32_t)RESET == flag_status));
- if ((uint32_t)RESET != flag_status){
+ if ((uint32_t)RESET != flag_status){
error_status = SUCCESS;
}
-
+
/* enable the write protection */
RTC_WPK = RTC_LOCK_KEY;
- }else{
+ }else{
error_status = SUCCESS;
}
@@ -232,7 +258,7 @@ ErrStatus rtc_register_sync_wait(void)
/*!
\brief get current time and date
\param[in] none
- \param[out] rtc_initpara_struct: pointer to a rtc_parameter_struct structure which contains
+ \param[out] rtc_initpara_struct: pointer to a rtc_parameter_struct structure which contains
parameters for initialization of the rtc peripheral
members of the structure and the member values are shown as below:
year: 0x0 - 0x99(BCD format)
@@ -254,22 +280,22 @@ void rtc_current_time_get(rtc_parameter_struct* rtc_initpara_struct)
{
uint32_t temp_tr = 0U, temp_dr = 0U, temp_pscr = 0U, temp_ctlr = 0U;
- temp_tr = (uint32_t)RTC_TIME;
+ temp_tr = (uint32_t)RTC_TIME;
temp_dr = (uint32_t)RTC_DATE;
temp_pscr = (uint32_t)RTC_PSC;
temp_ctlr = (uint32_t)RTC_CTL;
-
+
/* get current time and construct rtc_parameter_struct structure */
rtc_initpara_struct->year = (uint8_t)GET_DATE_YR(temp_dr);
rtc_initpara_struct->month = (uint8_t)GET_DATE_MON(temp_dr);
rtc_initpara_struct->date = (uint8_t)GET_DATE_DAY(temp_dr);
- rtc_initpara_struct->day_of_week = (uint8_t)GET_DATE_DOW(temp_dr);
+ rtc_initpara_struct->day_of_week = (uint8_t)GET_DATE_DOW(temp_dr);
rtc_initpara_struct->hour = (uint8_t)GET_TIME_HR(temp_tr);
rtc_initpara_struct->minute = (uint8_t)GET_TIME_MN(temp_tr);
rtc_initpara_struct->second = (uint8_t)GET_TIME_SC(temp_tr);
rtc_initpara_struct->factor_asyn = (uint16_t)GET_PSC_FACTOR_A(temp_pscr);
rtc_initpara_struct->factor_syn = (uint16_t)GET_PSC_FACTOR_S(temp_pscr);
- rtc_initpara_struct->am_pm = (uint32_t)(temp_pscr & RTC_TIME_PM);
+ rtc_initpara_struct->am_pm = (uint32_t)(temp_pscr & RTC_TIME_PM);
rtc_initpara_struct->display_format = (uint32_t)(temp_ctlr & RTC_CTL_CS);
}
@@ -293,7 +319,7 @@ uint32_t rtc_subsecond_get(void)
/*!
\brief configure RTC alarm
\param[in] rtc_alarm: RTC_ALARM0 or RTC_ALARM1
- \param[in] rtc_alarm_time: pointer to a rtc_alarm_struct structure which contains
+ \param[in] rtc_alarm_time: pointer to a rtc_alarm_struct structure which contains
parameters for RTC alarm configuration
members of the structure and the member values are shown as below:
alarm_mask: RTC_ALARM_NONE_MASK, RTC_ALARM_DATE_MASK, RTC_ALARM_HOUR_MASK
@@ -327,7 +353,7 @@ void rtc_alarm_config(uint8_t rtc_alarm, rtc_alarm_struct* rtc_alarm_time)
if(RTC_ALARM0 == rtc_alarm){
RTC_ALRM0TD = (uint32_t)reg_alrmtd;
-
+
}else{
RTC_ALRM1TD = (uint32_t)reg_alrmtd;
}
@@ -363,12 +389,12 @@ void rtc_alarm_subsecond_config(uint8_t rtc_alarm, uint32_t mask_subsecond, uint
{
/* disable the write protection */
RTC_WPK = RTC_UNLOCK_KEY1;
- RTC_WPK = RTC_UNLOCK_KEY2;
+ RTC_WPK = RTC_UNLOCK_KEY2;
if(RTC_ALARM0 == rtc_alarm){
- RTC_ALRM0SS = mask_subsecond | subsecond;
+ RTC_ALRM0SS = mask_subsecond | subsecond;
}else{
- RTC_ALRM1SS = mask_subsecond | subsecond;
+ RTC_ALRM1SS = mask_subsecond | subsecond;
}
/* enable the write protection */
RTC_WPK = RTC_LOCK_KEY;
@@ -377,7 +403,7 @@ void rtc_alarm_subsecond_config(uint8_t rtc_alarm, uint32_t mask_subsecond, uint
/*!
\brief get RTC alarm
\param[in] rtc_alarm: RTC_ALARM0 or RTC_ALARM1
- \param[out] rtc_alarm_time: pointer to a rtc_alarm_struct structure which contains
+ \param[out] rtc_alarm_time: pointer to a rtc_alarm_struct structure which contains
parameters for RTC alarm configuration
members of the structure and the member values are shown as below:
alarm_mask: RTC_ALARM_NONE_MASK, RTC_ALARM_DATE_MASK, RTC_ALARM_HOUR_MASK
@@ -403,13 +429,13 @@ void rtc_alarm_get(uint8_t rtc_alarm, rtc_alarm_struct* rtc_alarm_time)
reg_alrmtd = RTC_ALRM1TD;
}
/* get alarm parameters and construct the rtc_alarm_struct structure */
- rtc_alarm_time->alarm_mask = reg_alrmtd & RTC_ALARM_ALL_MASK;
+ rtc_alarm_time->alarm_mask = reg_alrmtd & RTC_ALARM_ALL_MASK;
rtc_alarm_time->am_pm = (uint32_t)(reg_alrmtd & RTC_ALRMXTD_PM);
rtc_alarm_time->weekday_or_date = (uint32_t)(reg_alrmtd & RTC_ALRMXTD_DOWS);
rtc_alarm_time->alarm_day = (uint8_t)GET_ALRMTD_DAY(reg_alrmtd);
rtc_alarm_time->alarm_hour = (uint8_t)GET_ALRMTD_HR(reg_alrmtd);
rtc_alarm_time->alarm_minute = (uint8_t)GET_ALRMTD_MN(reg_alrmtd);
- rtc_alarm_time->alarm_second = (uint8_t)GET_ALRMTD_SC(reg_alrmtd);
+ rtc_alarm_time->alarm_second = (uint8_t)GET_ALRMTD_SC(reg_alrmtd);
}
/*!
@@ -463,23 +489,23 @@ ErrStatus rtc_alarm_disable(uint8_t rtc_alarm)
/* disable the write protection */
RTC_WPK = RTC_UNLOCK_KEY1;
RTC_WPK = RTC_UNLOCK_KEY2;
-
+
/* clear the state of alarm */
if(RTC_ALARM0 == rtc_alarm){
- RTC_CTL &= (uint32_t)(~RTC_CTL_ALRM0EN);
+ RTC_CTL &= (uint32_t)(~RTC_CTL_ALRM0EN);
/* wait until ALRM0WF flag to be set after the alarm is disabled */
do{
flag_status = RTC_STAT & RTC_STAT_ALRM0WF;
- }while((--time_index > 0U) && ((uint32_t)RESET == flag_status));
+ }while((--time_index > 0U) && ((uint32_t)RESET == flag_status));
}else{
- RTC_CTL &= (uint32_t)(~RTC_CTL_ALRM1EN);
+ RTC_CTL &= (uint32_t)(~RTC_CTL_ALRM1EN);
/* wait until ALRM1WF flag to be set after the alarm is disabled */
do{
flag_status = RTC_STAT & RTC_STAT_ALRM1WF;
}while((--time_index > 0U) && ((uint32_t)RESET == flag_status));
}
-
- if ((uint32_t)RESET != flag_status){
+
+ if ((uint32_t)RESET != flag_status){
error_status = SUCCESS;
}
@@ -506,7 +532,7 @@ void rtc_timestamp_enable(uint32_t edge)
/* new configuration */
reg_ctl |= (uint32_t)(edge | RTC_CTL_TSEN);
-
+
/* disable the write protection */
RTC_WPK = RTC_UNLOCK_KEY1;
RTC_WPK = RTC_UNLOCK_KEY2;
@@ -528,7 +554,7 @@ void rtc_timestamp_disable(void)
/* disable the write protection */
RTC_WPK = RTC_UNLOCK_KEY1;
RTC_WPK = RTC_UNLOCK_KEY2;
-
+
/* clear the TSEN bit */
RTC_CTL &= (uint32_t)(~ RTC_CTL_TSEN);
@@ -539,7 +565,7 @@ void rtc_timestamp_disable(void)
/*!
\brief get RTC timestamp time and date
\param[in] none
- \param[out] rtc_timestamp: pointer to a rtc_timestamp_struct structure which contains
+ \param[out] rtc_timestamp: pointer to a rtc_timestamp_struct structure which contains
parameters for RTC time-stamp configuration
members of the structure and the member values are shown as below:
timestamp_month: RTC_JAN, RTC_FEB, RTC_MAR, RTC_APR, RTC_MAY, RTC_JUN,
@@ -560,7 +586,7 @@ void rtc_timestamp_get(rtc_timestamp_struct* rtc_timestamp)
/* get the value of time_stamp registers */
temp_tts = (uint32_t)RTC_TTS;
temp_dts = (uint32_t)RTC_DTS;
-
+
/* get timestamp time and construct the rtc_timestamp_struct structure */
rtc_timestamp->am_pm = (uint32_t)(temp_tts & RTC_TTS_PM);
rtc_timestamp->timestamp_month = (uint8_t)GET_DTS_MON(temp_dts);
@@ -583,7 +609,7 @@ uint32_t rtc_timestamp_subsecond_get(void)
}
/*!
- \brief RTC time-stamp mapping
+ \brief RTC time-stamp mapping
\param[in] rtc_af:
\arg RTC_AF0_TIMESTAMP: RTC_AF0 use for timestamp
\arg RTC_AF1_TIMESTAMP: RTC_AF1 use for timestamp
@@ -598,13 +624,19 @@ void rtc_timestamp_pin_map(uint32_t rtc_af)
/*!
\brief enable RTC tamper
- \param[in] rtc_tamper: pointer to a rtc_tamper_struct structure which contains
+ \param[in] rtc_tamper: pointer to a rtc_tamper_struct structure which contains
parameters for RTC tamper configuration
members of the structure and the member values are shown as below:
+ detecting tamper event can using edge mode or level mode
+ (1) using edge mode configuration:
tamper_source: RTC_TAMPER0, RTC_TAMPER1
tamper_trigger: RTC_TAMPER_TRIGGER_EDGE_RISING, RTC_TAMPER_TRIGGER_EDGE_FALLING
- RTC_TAMPER_TRIGGER_LEVEL_LOW, RTC_TAMPER_TRIGGER_LEVEL_HIGH
- tamper_filter: RTC_FLT_EDGE, RTC_FLT_2S, RTC_FLT_4S, RTC_FLT_8S
+ tamper_filter: RTC_FLT_EDGE
+ tamper_with_timestamp: DISABLE, ENABLE
+ (2) using level mode configuration:
+ tamper_source: RTC_TAMPER0, RTC_TAMPER1
+ tamper_trigger:RTC_TAMPER_TRIGGER_LEVEL_LOW, RTC_TAMPER_TRIGGER_LEVEL_HIGH
+ tamper_filter: RTC_FLT_2S, RTC_FLT_4S, RTC_FLT_8S
tamper_sample_frequency: RTC_FREQ_DIV32768, RTC_FREQ_DIV16384, RTC_FREQ_DIV8192,
RTC_FREQ_DIV4096, RTC_FREQ_DIV2048, RTC_FREQ_DIV1024,
RTC_FREQ_DIV512, RTC_FREQ_DIV256
@@ -617,40 +649,46 @@ void rtc_timestamp_pin_map(uint32_t rtc_af)
void rtc_tamper_enable(rtc_tamper_struct* rtc_tamper)
{
/* disable tamper */
- RTC_TAMP &= (uint32_t)~(rtc_tamper->tamper_source);
+ RTC_TAMP &= (uint32_t)~(rtc_tamper->tamper_source);
/* tamper filter must be used when the tamper source is voltage level detection */
RTC_TAMP &= (uint32_t)~RTC_TAMP_FLT;
-
+
/* the tamper source is voltage level detection */
- if((uint32_t)(rtc_tamper->tamper_filter) != RTC_FLT_EDGE ){
+ if((uint32_t)(rtc_tamper->tamper_filter) != RTC_FLT_EDGE ){
RTC_TAMP &= (uint32_t)~(RTC_TAMP_DISPU | RTC_TAMP_PRCH | RTC_TAMP_FREQ | RTC_TAMP_FLT);
/* check if the tamper pin need precharge, if need, then configure the precharge time */
if(DISABLE == rtc_tamper->tamper_precharge_enable){
- RTC_TAMP |= (uint32_t)RTC_TAMP_DISPU;
+ RTC_TAMP |= (uint32_t)RTC_TAMP_DISPU;
}else{
RTC_TAMP |= (uint32_t)(rtc_tamper->tamper_precharge_time);
}
RTC_TAMP |= (uint32_t)(rtc_tamper->tamper_sample_frequency);
RTC_TAMP |= (uint32_t)(rtc_tamper->tamper_filter);
+
+ /* configure the tamper trigger */
+ RTC_TAMP &= ((uint32_t)~((rtc_tamper->tamper_source) << RTC_TAMPER_TRIGGER_POS));
+ if(RTC_TAMPER_TRIGGER_LEVEL_LOW != rtc_tamper->tamper_trigger){
+ RTC_TAMP |= (uint32_t)((rtc_tamper->tamper_source)<< RTC_TAMPER_TRIGGER_POS);
+ }
+ }else{
+
+ /* configure the tamper trigger */
+ RTC_TAMP &= ((uint32_t)~((rtc_tamper->tamper_source) << RTC_TAMPER_TRIGGER_POS));
+ if(RTC_TAMPER_TRIGGER_EDGE_RISING != rtc_tamper->tamper_trigger){
+ RTC_TAMP |= (uint32_t)((rtc_tamper->tamper_source)<< RTC_TAMPER_TRIGGER_POS);
+ }
}
-
- RTC_TAMP &= (uint32_t)~RTC_TAMP_TPTS;
-
- if(DISABLE != rtc_tamper->tamper_with_timestamp){
+
+ RTC_TAMP &= (uint32_t)~RTC_TAMP_TPTS;
+ if(DISABLE != rtc_tamper->tamper_with_timestamp){
/* the tamper event also cause a time-stamp event */
RTC_TAMP |= (uint32_t)RTC_TAMP_TPTS;
- }
-
- /* configure the tamper trigger */
- RTC_TAMP &= ((uint32_t)~((rtc_tamper->tamper_source) << RTC_TAMPER_TRIGGER_POS));
- if(RTC_TAMPER_TRIGGER_EDGE_RISING != rtc_tamper->tamper_trigger){
- RTC_TAMP |= (uint32_t)((rtc_tamper->tamper_source)<< RTC_TAMPER_TRIGGER_POS);
- }
+ }
/* enable tamper */
- RTC_TAMP |= (uint32_t)(rtc_tamper->tamper_source);
+ RTC_TAMP |= (uint32_t)(rtc_tamper->tamper_source);
}
/*!
@@ -664,12 +702,12 @@ void rtc_tamper_enable(rtc_tamper_struct* rtc_tamper)
void rtc_tamper_disable(uint32_t source)
{
/* disable tamper */
- RTC_TAMP &= (uint32_t)~source;
+ RTC_TAMP &= (uint32_t)~source;
}
/*!
- \brief RTC tamper0 mapping
+ \brief RTC tamper0 mapping
\param[in] rtc_af:
\arg RTC_AF0_TAMPER0: RTC_AF0 use for tamper0
\arg RTC_AF1_TAMPER0: RTC_AF1 use for tamper0
@@ -681,30 +719,31 @@ void rtc_tamper0_pin_map(uint32_t rtc_af)
RTC_TAMP &= ~(RTC_TAMP_TP0EN | RTC_TAMP_TP0SEL);
RTC_TAMP |= rtc_af;
}
+
/*!
\brief enable specified RTC interrupt
\param[in] interrupt: specify which interrupt source to be enabled
\arg RTC_INT_TIMESTAMP: timestamp interrupt
\arg RTC_INT_ALARM0: alarm0 interrupt
\arg RTC_INT_ALARM1: alarm1 interrupt
- \arg RTC_INT_TAMP: tamp interrupt
+ \arg RTC_INT_TAMP: tamper detection interrupt
\arg RTC_INT_WAKEUP: wakeup timer interrupt
\param[out] none
\retval none
*/
void rtc_interrupt_enable(uint32_t interrupt)
-{
+{
/* disable the write protection */
RTC_WPK = RTC_UNLOCK_KEY1;
RTC_WPK = RTC_UNLOCK_KEY2;
-
+
/* enable the interrupts in RTC_CTL register */
RTC_CTL |= (uint32_t)(interrupt & (uint32_t)~RTC_TAMP_TPIE);
/* enable the interrupts in RTC_TAMP register */
RTC_TAMP |= (uint32_t)(interrupt & RTC_TAMP_TPIE);
-
+
/* enable the write protection */
- RTC_WPK = RTC_LOCK_KEY;
+ RTC_WPK = RTC_LOCK_KEY;
}
/*!
@@ -713,17 +752,17 @@ void rtc_interrupt_enable(uint32_t interrupt)
\arg RTC_INT_TIMESTAMP: timestamp interrupt
\arg RTC_INT_ALARM0: alarm interrupt
\arg RTC_INT_ALARM1: alarm interrupt
- \arg RTC_INT_TAMP: tamp interrupt
+ \arg RTC_INT_TAMP: tamper detection interrupt
\arg RTC_INT_WAKEUP: wakeup timer interrupt
\param[out] none
\retval none
*/
void rtc_interrupt_disable(uint32_t interrupt)
-{
+{
/* disable the write protection */
RTC_WPK = RTC_UNLOCK_KEY1;
RTC_WPK = RTC_UNLOCK_KEY2;
-
+
/* disable the interrupts in RTC_CTL register */
RTC_CTL &= (uint32_t)~(interrupt & (uint32_t)~RTC_TAMP_TPIE);
/* disable the interrupts in RTC_TAMP register */
@@ -736,28 +775,28 @@ void rtc_interrupt_disable(uint32_t interrupt)
/*!
\brief check specified flag
\param[in] flag: specify which flag to check
- \arg RTC_STAT_RECPF: recalibration pending flag
- \arg RTC_STAT_TP1F: tamper 1 event flag
- \arg RTC_STAT_TP0F: tamper 0 event flag
- \arg RTC_STAT_TSOVRF: time-stamp overflow event flag
- \arg RTC_STAT_TSF: time-stamp event flag
- \arg RTC_STAT_ALRM0F: alarm0 event flag
- \arg RTC_STAT_ALRM1F: alarm1 event flag
- \arg RTC_STAT_WTF: wakeup timer event flag
- \arg RTC_STAT_INITF: init mode event flag
- \arg RTC_STAT_RSYNF: time and date registers synchronized event flag
- \arg RTC_STAT_YCM: year parameter configured event flag
- \arg RTC_STAT_SOPF: shift operation pending flag
- \arg RTC_STAT_ALRM0WF: alarm0 writen available flag
- \arg RTC_STAT_ALRM1WF: alarm1 writen available flag
- \arg RTC_STAT_WTWF: wakeup timer writen available flag
+ \arg RTC_STAT_SCP: smooth calibration pending flag
+ \arg RTC_FLAG_TP1: RTC tamper 1 detected flag
+ \arg RTC_FLAG_TP0: RTC tamper 0 detected flag
+ \arg RTC_FLAG_TSOVR: time-stamp overflow flag
+ \arg RTC_FLAG_TS: time-stamp flag
+ \arg RTC_FLAG_ALARM0: alarm0 occurs flag
+ \arg RTC_FLAG_ALARM1: alarm1 occurs flag
+ \arg RTC_FLAG_WT: wakeup timer occurs flag
+ \arg RTC_FLAG_INIT: initialization state flag
+ \arg RTC_FLAG_RSYN: register synchronization flag
+ \arg RTC_FLAG_YCM: year configuration mark status flag
+ \arg RTC_FLAG_SOP: shift function operation pending flag
+ \arg RTC_FLAG_ALRM0W: alarm0 configuration can be write flag
+ \arg RTC_FLAG_ALRM1W: alarm1 configuration can be write flag
+ \arg RTC_FLAG_WTW: wakeup timer can be write flag
\param[out] none
\retval FlagStatus: SET or RESET
*/
FlagStatus rtc_flag_get(uint32_t flag)
{
FlagStatus flag_state = RESET;
-
+
if ((uint32_t)RESET != (RTC_STAT & flag)){
flag_state = SET;
}
@@ -766,21 +805,20 @@ FlagStatus rtc_flag_get(uint32_t flag)
/*!
\brief clear specified flag
- \param[in] flag: specify which flag to clear
- \arg RTC_STAT_TP1F: tamper 1 event flag
- \arg RTC_STAT_TP0F: tamper 0 event flag
- \arg RTC_STAT_TSOVRF: time-stamp overflow event flag
- \arg RTC_STAT_TSF: time-stamp event flag
- \arg RTC_STAT_WTF: time-stamp event flag
- \arg RTC_STAT_ALRM0F: alarm0 event flag
- \arg RTC_STAT_ALRM1F: alarm1 event flag
- \arg RTC_STAT_RSYNF: time and date registers synchronized event flag
+ \arg RTC_FLAG_TP1: RTC tamper 1 detected flag
+ \arg RTC_FLAG_TP0: RTC tamper 0 detected flag
+ \arg RTC_FLAG_TSOVR: time-stamp overflow flag
+ \arg RTC_FLAG_TS: time-stamp flag
+ \arg RTC_FLAG_WT: wakeup timer occurs flag
+ \arg RTC_FLAG_ALARM0: alarm0 occurs flag
+ \arg RTC_FLAG_ALARM1: alarm1 occurs flag
+ \arg RTC_FLAG_RSYN: register synchronization flag
\param[out] none
\retval none
*/
void rtc_flag_clear(uint32_t flag)
{
- RTC_STAT &= (uint32_t)(~flag);
+ RTC_STAT &= (uint32_t)(~flag);
}
/*!
@@ -818,10 +856,10 @@ void rtc_alarm_output_config(uint32_t source, uint32_t mode)
/*!
\brief configure rtc calibration output source
\param[in] source: specify signal to output
- \arg RTC_CALIBRATION_512HZ: when the LSE freqency is 32768Hz and the RTC_PSC
+ \arg RTC_CALIBRATION_512HZ: when the LSE freqency is 32768Hz and the RTC_PSC
is the default value, output 512Hz signal
- \arg RTC_CALIBRATION_1HZ: when the LSE freqency is 32768Hz and the RTC_PSC
- is the default value, output 512Hz signal
+ \arg RTC_CALIBRATION_1HZ: when the LSE freqency is 32768Hz and the RTC_PSC
+ is the default value, output 1Hz signal
\param[out] none
\retval none
*/
@@ -852,7 +890,7 @@ void rtc_hour_adjust(uint32_t operation)
/* disable the write protection */
RTC_WPK = RTC_UNLOCK_KEY1;
RTC_WPK = RTC_UNLOCK_KEY2;
-
+
RTC_CTL |= (uint32_t)(operation);
/* enable the write protection */
@@ -877,17 +915,17 @@ ErrStatus rtc_second_adjust(uint32_t add, uint32_t minus)
/* disable the write protection */
RTC_WPK = RTC_UNLOCK_KEY1;
RTC_WPK = RTC_UNLOCK_KEY2;
-
- /* check if a shift operation is ongoing */
+
+ /* check if a shift operation is ongoing */
do{
flag_status = RTC_STAT & RTC_STAT_SOPF;
}while((--time_index > 0U) && ((uint32_t)RESET != flag_status));
-
+
/* check if the function of reference clock detection is disabled */
temp = RTC_CTL & RTC_CTL_REFEN;
- if((RESET == flag_status) && (RESET == temp)){
+ if((RESET == flag_status) && (RESET == temp)){
RTC_SHIFTCTL = (uint32_t)(add | SHIFTCTL_SFS(minus));
- error_status = rtc_register_sync_wait();
+ error_status = rtc_register_sync_wait();
}
/* enable the write protection */
@@ -903,7 +941,7 @@ ErrStatus rtc_second_adjust(uint32_t add, uint32_t minus)
\retval none
*/
void rtc_bypass_shadow_enable(void)
-{
+{
/* disable the write protection */
RTC_WPK = RTC_UNLOCK_KEY1;
RTC_WPK = RTC_UNLOCK_KEY2;
@@ -921,7 +959,7 @@ void rtc_bypass_shadow_enable(void)
\retval none
*/
void rtc_bypass_shadow_disable(void)
-{
+{
/* disable the write protection */
RTC_WPK = RTC_UNLOCK_KEY1;
RTC_WPK = RTC_UNLOCK_KEY2;
@@ -941,7 +979,7 @@ void rtc_bypass_shadow_disable(void)
ErrStatus rtc_refclock_detection_enable(void)
{
ErrStatus error_status = ERROR;
-
+
/* disable the write protection */
RTC_WPK = RTC_UNLOCK_KEY1;
RTC_WPK = RTC_UNLOCK_KEY2;
@@ -970,7 +1008,7 @@ ErrStatus rtc_refclock_detection_enable(void)
ErrStatus rtc_refclock_detection_disable(void)
{
ErrStatus error_status = ERROR;
-
+
/* disable the write protection */
RTC_WPK = RTC_UNLOCK_KEY1;
RTC_WPK = RTC_UNLOCK_KEY2;
@@ -978,7 +1016,7 @@ ErrStatus rtc_refclock_detection_disable(void)
/* enter init mode */
error_status = rtc_init_mode_enter();
- if(ERROR != error_status){
+ if(ERROR != error_status){
RTC_CTL &= (uint32_t)~RTC_CTL_REFEN;
/* exit init mode */
rtc_init_mode_exit();
@@ -1000,7 +1038,7 @@ void rtc_wakeup_enable(void)
{
/* disable the write protection */
RTC_WPK = RTC_UNLOCK_KEY1;
- RTC_WPK = RTC_UNLOCK_KEY2;
+ RTC_WPK = RTC_UNLOCK_KEY2;
RTC_CTL |= RTC_CTL_WTEN;
@@ -1041,12 +1079,12 @@ ErrStatus rtc_wakeup_disable(void)
/*!
\brief set RTC auto wakeup timer clock
\param[in] wakeup_clock:
- \arg WAKEUP_RTCCK_DIV16: RTC auto wakeup timer clock is RTC clock divided by 16
- \arg WAKEUP_RTCCK_DIV8: RTC auto wakeup timer clock is RTC clock divided by 8
- \arg WAKEUP_RTCCK_DIV4: RTC auto wakeup timer clock is RTC clock divided by 4
- \arg WAKEUP_RTCCK_DIV2: RTC auto wakeup timer clock is RTC clock divided by 2
+ \arg WAKEUP_RTCCK_DIV16: RTC auto wakeup timer clock is RTC clock divided by 16
+ \arg WAKEUP_RTCCK_DIV8: RTC auto wakeup timer clock is RTC clock divided by 8
+ \arg WAKEUP_RTCCK_DIV4: RTC auto wakeup timer clock is RTC clock divided by 4
+ \arg WAKEUP_RTCCK_DIV2: RTC auto wakeup timer clock is RTC clock divided by 2
\arg WAKEUP_CKSPRE: RTC auto wakeup timer clock is ckspre
- \arg WAKEUP_CKSPRE_2EXP16: RTC auto wakeup timer clock is ckspre and wakeup timer add 2exp16
+ \arg WAKEUP_CKSPRE_2EXP16: RTC auto wakeup timer clock is ckspre and wakeup timer add 2exp16
\param[out] none
\retval ErrStatus: ERROR or SUCCESS
*/
@@ -1057,8 +1095,8 @@ ErrStatus rtc_wakeup_clock_set(uint8_t wakeup_clock)
uint32_t flag_status = RESET;
/* disable the write protection */
RTC_WPK = RTC_UNLOCK_KEY1;
- RTC_WPK = RTC_UNLOCK_KEY2;
- /* only when RTC_CTL_WTEN=0 and RTC_STAT_WTWF=1 can write RTC_CTL[2��0] */
+ RTC_WPK = RTC_UNLOCK_KEY2;
+ /* only when RTC_CTL_WTEN=0 and RTC_STAT_WTWF=1 can write RTC_CTL[2��0] */
/* wait until the WTWF flag to be set */
do{
flag_status = RTC_STAT & RTC_STAT_WTWF;
@@ -1073,7 +1111,7 @@ ErrStatus rtc_wakeup_clock_set(uint8_t wakeup_clock)
}
/* enable the write protection */
RTC_WPK = RTC_LOCK_KEY;
-
+
return error_status;
}
@@ -1136,16 +1174,16 @@ ErrStatus rtc_smooth_calibration_config(uint32_t window, uint32_t plus, uint32_t
volatile uint32_t time_index = RTC_HRFC_TIMEOUT;
ErrStatus error_status = ERROR;
uint32_t flag_status = RESET;
-
+
/* disable the write protection */
RTC_WPK = RTC_UNLOCK_KEY1;
- RTC_WPK = RTC_UNLOCK_KEY2;
-
- /* check if a smooth calibration operation is ongoing */
+ RTC_WPK = RTC_UNLOCK_KEY2;
+
+ /* check if a smooth calibration operation is ongoing */
do{
flag_status = RTC_STAT & RTC_STAT_SCPF;
}while((--time_index > 0U) && ((uint32_t)RESET != flag_status));
-
+
if((uint32_t)RESET == flag_status){
RTC_HRFC = (uint32_t)(window | plus | HRFC_CMSK(minus));
error_status = SUCCESS;
@@ -1172,12 +1210,12 @@ ErrStatus rtc_coarse_calibration_enable(void)
/* enter init mode */
error_status = rtc_init_mode_enter();
- if(ERROR != error_status){
+ if(ERROR != error_status){
RTC_CTL |= (uint32_t)RTC_CTL_CCEN;
/* exit init mode */
rtc_init_mode_exit();
}
-
+
/* enable the write protection */
RTC_WPK = RTC_LOCK_KEY;
return error_status;
@@ -1194,24 +1232,24 @@ ErrStatus rtc_coarse_calibration_disable(void)
ErrStatus error_status = ERROR;
/* disable the write protection */
RTC_WPK = RTC_UNLOCK_KEY1;
- RTC_WPK = RTC_UNLOCK_KEY2;
+ RTC_WPK = RTC_UNLOCK_KEY2;
/* enter init mode */
error_status = rtc_init_mode_enter();
- if(ERROR != error_status){
+ if(ERROR != error_status){
RTC_CTL &= (uint32_t)~RTC_CTL_CCEN;
/* exit init mode */
rtc_init_mode_exit();
}
-
+
/* enable the write protection */
- RTC_WPK = RTC_LOCK_KEY;
+ RTC_WPK = RTC_LOCK_KEY;
return error_status;
}
/*!
\brief config coarse calibration direction and step
- \param[in] direction: CALIB_INCREASE or CALIB_DECREASE
+ \param[in] direction: CALIB_INCREASE or CALIB_DECREASE
\param[in] step: 0x00-0x1F
COSD=0:
0x00:+0 PPM
@@ -1234,11 +1272,11 @@ ErrStatus rtc_coarse_calibration_config(uint8_t direction, uint8_t step)
/* disable the write protection */
RTC_WPK = RTC_UNLOCK_KEY1;
RTC_WPK = RTC_UNLOCK_KEY2;
-
+
/* enter init mode */
error_status = rtc_init_mode_enter();
- if(ERROR != error_status){
+ if(ERROR != error_status){
if(CALIB_DECREASE == direction){
RTC_COSC |= (uint32_t)RTC_COSC_COSD;
}else{
@@ -1249,9 +1287,9 @@ ErrStatus rtc_coarse_calibration_config(uint8_t direction, uint8_t step)
/* exit init mode */
rtc_init_mode_exit();
}
-
+
/* enable the write protection */
RTC_WPK = RTC_LOCK_KEY;
-
+
return error_status;
}
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_sdio.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_sdio.c
index f7b26358b5..d1d0a0be32 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_sdio.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_sdio.c
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_sdio.c
- \brief SDIO driver
+ \file gd32f4xx_sdio.c
+ \brief SDIO driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.1, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#include "gd32f4xx_sdio.h"
@@ -26,12 +51,15 @@ void sdio_deinit(void)
/*!
\brief configure the SDIO clock
\param[in] clock_edge: SDIO_CLK clock edge
+ only one parameter can be selected which is shown as below:
\arg SDIO_SDIOCLKEDGE_RISING: select the rising edge of the SDIOCLK to generate SDIO_CLK
\arg SDIO_SDIOCLKEDGE_FALLING: select the falling edge of the SDIOCLK to generate SDIO_CLK
\param[in] clock_bypass: clock bypass
+ only one parameter can be selected which is shown as below:
\arg SDIO_CLOCKBYPASS_ENABLE: clock bypass
\arg SDIO_CLOCKBYPASS_DISABLE: no bypass
\param[in] clock_powersave: SDIO_CLK clock dynamic switch on/off for power saving
+ only one parameter can be selected which is shown as below:
\arg SDIO_CLOCKPWRSAVE_ENABLE: SDIO_CLK closed when bus is idle
\arg SDIO_CLOCKPWRSAVE_DISABLE: SDIO_CLK clock is always on
\param[in] clock_division: clock division, less than 512
@@ -79,6 +107,7 @@ void sdio_hardware_clock_disable(void)
/*!
\brief set different SDIO card bus mode
\param[in] bus_mode: SDIO card bus mode
+ only one parameter can be selected which is shown as below:
\arg SDIO_BUSMODE_1BIT: 1-bit SDIO card bus mode
\arg SDIO_BUSMODE_4BIT: 4-bit SDIO card bus mode
\arg SDIO_BUSMODE_8BIT: 8-bit SDIO card bus mode
@@ -95,6 +124,7 @@ void sdio_bus_mode_set(uint32_t bus_mode)
/*!
\brief set the SDIO power state
\param[in] power_state: SDIO power state
+ only one parameter can be selected which is shown as below:
\arg SDIO_POWER_ON: SDIO power on
\arg SDIO_POWER_OFF: SDIO power off
\param[out] none
@@ -105,7 +135,6 @@ void sdio_power_state_set(uint32_t power_state)
SDIO_PWRCTL = power_state;
}
-/* get the SDIO power state */
/*!
\brief get the SDIO power state
\param[in] none
@@ -146,6 +175,7 @@ void sdio_clock_disable(void)
\param[in] cmd_index: command index, refer to the related specifications
\param[in] cmd_argument: command argument, refer to the related specifications
\param[in] response_type: response type
+ only one parameter can be selected which is shown as below:
\arg SDIO_RESPONSETYPE_NO: no response
\arg SDIO_RESPONSETYPE_SHORT: short response
\arg SDIO_RESPONSETYPE_LONG: long response
@@ -155,6 +185,8 @@ void sdio_clock_disable(void)
void sdio_command_response_config(uint32_t cmd_index, uint32_t cmd_argument, uint32_t response_type)
{
uint32_t cmd_config = 0U;
+ /* disable the CSM */
+ SDIO_CMDCTL &= ~SDIO_CMDCTL_CSMEN;
/* reset the command index, command argument and response type */
SDIO_CMDAGMT &= ~SDIO_CMDAGMT_CMDAGMT;
SDIO_CMDAGMT = cmd_argument;
@@ -168,6 +200,7 @@ void sdio_command_response_config(uint32_t cmd_index, uint32_t cmd_argument, uin
/*!
\brief set the command state machine wait type
\param[in] wait_type: wait type
+ only one parameter can be selected which is shown as below:
\arg SDIO_WAITTYPE_NO: not wait interrupt
\arg SDIO_WAITTYPE_INTERRUPT: wait interrupt
\arg SDIO_WAITTYPE_DATAEND: wait the end of data transfer
@@ -218,6 +251,7 @@ uint8_t sdio_command_index_get(void)
/*!
\brief get the response for the last received command
\param[in] sdio_responsex: SDIO response
+ only one parameter can be selected which is shown as below:
\arg SDIO_RESPONSE0: card response[31:0]/card response[127:96]
\arg SDIO_RESPONSE1: card response[95:64]
\arg SDIO_RESPONSE2: card response[63:32]
@@ -252,6 +286,7 @@ uint32_t sdio_response_get(uint32_t sdio_responsex)
\param[in] data_timeout: data timeout period in card bus clock periods
\param[in] data_length: number of data bytes to be transferred
\param[in] data_blocksize: size of data block for block transfer
+ only one parameter can be selected which is shown as below:
\arg SDIO_DATABLOCKSIZE_1BYTE: block size = 1 byte
\arg SDIO_DATABLOCKSIZE_2BYTES: block size = 2 bytes
\arg SDIO_DATABLOCKSIZE_4BYTES: block size = 4 bytes
@@ -285,9 +320,11 @@ void sdio_data_config(uint32_t data_timeout, uint32_t data_length, uint32_t data
/*!
\brief configure the data transfer mode and direction
\param[in] transfer_mode: mode of data transfer
+ only one parameter can be selected which is shown as below:
\arg SDIO_TRANSMODE_BLOCK: block transfer
\arg SDIO_TRANSMODE_STREAM: stream transfer or SDIO multibyte transfer
\param[in] transfer_direction: data transfer direction, read or write
+ only one parameter can be selected which is shown as below:
\arg SDIO_TRANSDIRECTION_TOCARD: write data to card
\arg SDIO_TRANSDIRECTION_TOSDIO: read data from card
\param[out] none
@@ -394,6 +431,7 @@ void sdio_dma_disable(void)
/*!
\brief get the flags state of SDIO
\param[in] flag: flags state of SDIO
+ one or more parameters can be selected which are shown as below:
\arg SDIO_FLAG_CCRCERR: command response received (CRC check failed) flag
\arg SDIO_FLAG_DTCRCERR: data block sent/received (CRC check failed) flag
\arg SDIO_FLAG_CMDTMOUT: command response timeout flag
@@ -433,6 +471,7 @@ FlagStatus sdio_flag_get(uint32_t flag)
/*!
\brief clear the pending flags of SDIO
\param[in] flag: flags state of SDIO
+ one or more parameters can be selected which are shown as below:
\arg SDIO_FLAG_CCRCERR: command response received (CRC check failed) flag
\arg SDIO_FLAG_DTCRCERR: data block sent/received (CRC check failed) flag
\arg SDIO_FLAG_CMDTMOUT: command response timeout flag
@@ -457,6 +496,7 @@ void sdio_flag_clear(uint32_t flag)
/*!
\brief enable the SDIO interrupt
\param[in] int_flag: interrupt flags state of SDIO
+ one or more parameters can be selected which are shown as below:
\arg SDIO_INT_CCRCERR: SDIO CCRCERR interrupt
\arg SDIO_INT_DTCRCERR: SDIO DTCRCERR interrupt
\arg SDIO_INT_CMDTMOUT: SDIO CMDTMOUT interrupt
@@ -492,6 +532,7 @@ void sdio_interrupt_enable(uint32_t int_flag)
/*!
\brief disable the SDIO interrupt
\param[in] int_flag: interrupt flags state of SDIO
+ one or more parameters can be selected which are shown as below:
\arg SDIO_INT_CCRCERR: SDIO CCRCERR interrupt
\arg SDIO_INT_DTCRCERR: SDIO DTCRCERR interrupt
\arg SDIO_INT_CMDTMOUT: SDIO CMDTMOUT interrupt
@@ -527,30 +568,31 @@ void sdio_interrupt_disable(uint32_t int_flag)
/*!
\brief get the interrupt flags state of SDIO
\param[in] int_flag: interrupt flags state of SDIO
- \arg SDIO_INT_CCRCERR: SDIO CCRCERR interrupt
- \arg SDIO_INT_DTCRCERR: SDIO DTCRCERR interrupt
- \arg SDIO_INT_CMDTMOUT: SDIO CMDTMOUT interrupt
- \arg SDIO_INT_DTTMOUT: SDIO DTTMOUT interrupt
- \arg SDIO_INT_TXURE: SDIO TXURE interrupt
- \arg SDIO_INT_RXORE: SDIO RXORE interrupt
- \arg SDIO_INT_CMDRECV: SDIO CMDRECV interrupt
- \arg SDIO_INT_CMDSEND: SDIO CMDSEND interrupt
- \arg SDIO_INT_DTEND: SDIO DTEND interrupt
- \arg SDIO_INT_STBITE: SDIO STBITE interrupt
- \arg SDIO_INT_DTBLKEND: SDIO DTBLKEND interrupt
- \arg SDIO_INT_CMDRUN: SDIO CMDRUN interrupt
- \arg SDIO_INT_TXRUN: SDIO TXRUN interrupt
- \arg SDIO_INT_RXRUN: SDIO RXRUN interrupt
- \arg SDIO_INT_TFH: SDIO TFH interrupt
- \arg SDIO_INT_RFH: SDIO RFH interrupt
- \arg SDIO_INT_TFF: SDIO TFF interrupt
- \arg SDIO_INT_RFF: SDIO RFF interrupt
- \arg SDIO_INT_TFE: SDIO TFE interrupt
- \arg SDIO_INT_RFE: SDIO RFE interrupt
- \arg SDIO_INT_TXDTVAL: SDIO TXDTVAL interrupt
- \arg SDIO_INT_RXDTVAL: SDIO RXDTVAL interrupt
- \arg SDIO_INT_SDIOINT: SDIO SDIOINT interrupt
- \arg SDIO_INT_ATAEND: SDIO ATAEND interrupt
+ one or more parameters can be selected which are shown as below:
+ \arg SDIO_INT_FLAG_CCRCERR: SDIO CCRCERR interrupt flag
+ \arg SDIO_INT_FLAG_DTCRCERR: SDIO DTCRCERR interrupt flag
+ \arg SDIO_INT_FLAG_CMDTMOUT: SDIO CMDTMOUT interrupt flag
+ \arg SDIO_INT_FLAG_DTTMOUT: SDIO DTTMOUT interrupt flag
+ \arg SDIO_INT_FLAG_TXURE: SDIO TXURE interrupt flag
+ \arg SDIO_INT_FLAG_RXORE: SDIO RXORE interrupt flag
+ \arg SDIO_INT_FLAG_CMDRECV: SDIO CMDRECV interrupt flag
+ \arg SDIO_INT_FLAG_CMDSEND: SDIO CMDSEND interrupt flag
+ \arg SDIO_INT_FLAG_DTEND: SDIO DTEND interrupt flag
+ \arg SDIO_INT_FLAG_STBITE: SDIO STBITE interrupt flag
+ \arg SDIO_INT_FLAG_DTBLKEND: SDIO DTBLKEND interrupt flag
+ \arg SDIO_INT_FLAG_CMDRUN: SDIO CMDRUN interrupt flag
+ \arg SDIO_INT_FLAG_TXRUN: SDIO TXRUN interrupt flag
+ \arg SDIO_INT_FLAG_RXRUN: SDIO RXRUN interrupt flag
+ \arg SDIO_INT_FLAG_TFH: SDIO TFH interrupt flag
+ \arg SDIO_INT_FLAG_RFH: SDIO RFH interrupt flag
+ \arg SDIO_INT_FLAG_TFF: SDIO TFF interrupt flag
+ \arg SDIO_INT_FLAG_RFF: SDIO RFF interrupt flag
+ \arg SDIO_INT_FLAG_TFE: SDIO TFE interrupt flag
+ \arg SDIO_INT_FLAG_RFE: SDIO RFE interrupt flag
+ \arg SDIO_INT_FLAG_TXDTVAL: SDIO TXDTVAL interrupt flag
+ \arg SDIO_INT_FLAG_RXDTVAL: SDIO RXDTVAL interrupt flag
+ \arg SDIO_INT_FLAG_SDIOINT: SDIO SDIOINT interrupt flag
+ \arg SDIO_INT_FLAG_ATAEND: SDIO ATAEND interrupt flag
\param[out] none
\retval FlagStatus: SET or RESET
*/
@@ -566,19 +608,20 @@ FlagStatus sdio_interrupt_flag_get(uint32_t int_flag)
/*!
\brief clear the interrupt pending flags of SDIO
\param[in] int_flag: interrupt flags state of SDIO
- \arg SDIO_INT_CCRCERR: command response received (CRC check failed) flag
- \arg SDIO_INT_DTCRCERR: data block sent/received (CRC check failed) flag
- \arg SDIO_INT_CMDTMOUT: command response timeout flag
- \arg SDIO_INT_DTTMOUT: data timeout flag
- \arg SDIO_INT_TXURE: transmit FIFO underrun error occurs flag
- \arg SDIO_INT_RXORE: received FIFO overrun error occurs flag
- \arg SDIO_INT_CMDRECV: command response received (CRC check passed) flag
- \arg SDIO_INT_CMDSEND: command sent (no response required) flag
- \arg SDIO_INT_DTEND: data end (data counter, SDIO_DATACNT, is zero) flag
- \arg SDIO_INT_STBITE: start bit error in the bus flag
- \arg SDIO_INT_DTBLKEND: data block sent/received (CRC check passed) flag
- \arg SDIO_INT_SDIOINT: SD I/O interrupt received flag
- \arg SDIO_INT_ATAEND: CE-ATA command completion signal received (only for CMD61) flag
+ one or more parameters can be selected which are shown as below:
+ \arg SDIO_INT_FLAG_CCRCERR: command response received (CRC check failed) flag
+ \arg SDIO_INT_FLAG_DTCRCERR: data block sent/received (CRC check failed) flag
+ \arg SDIO_INT_FLAG_CMDTMOUT: command response timeout flag
+ \arg SDIO_INT_FLAG_DTTMOUT: data timeout flag
+ \arg SDIO_INT_FLAG_TXURE: transmit FIFO underrun error occurs flag
+ \arg SDIO_INT_FLAG_RXORE: received FIFO overrun error occurs flag
+ \arg SDIO_INT_FLAG_CMDRECV: command response received (CRC check passed) flag
+ \arg SDIO_INT_FLAG_CMDSEND: command sent (no response required) flag
+ \arg SDIO_INT_FLAG_DTEND: data end (data counter, SDIO_DATACNT, is zero) flag
+ \arg SDIO_INT_FLAG_STBITE: start bit error in the bus flag
+ \arg SDIO_INT_FLAG_DTBLKEND: data block sent/received (CRC check passed) flag
+ \arg SDIO_INT_FLAG_SDIOINT: SD I/O interrupt received flag
+ \arg SDIO_INT_FLAG_ATAEND: CE-ATA command completion signal received (only for CMD61) flag
\param[out] none
\retval none
*/
@@ -634,6 +677,7 @@ void sdio_stop_readwait_disable(void)
/*!
\brief set the read wait type(SD I/O only)
\param[in] readwait_type: SD I/O read wait type
+ only one parameter can be selected which is shown as below:
\arg SDIO_READWAITTYPE_CLK: read wait control by stopping SDIO_CLK
\arg SDIO_READWAITTYPE_DAT2: read wait control using SDIO_DAT[2]
\param[out] none
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_spi.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_spi.c
index c5947cf174..3f842251fc 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_spi.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_spi.c
@@ -1,23 +1,53 @@
/*!
- \file gd32f4xx_spi.c
- \brief SPI driver
+ \file gd32f4xx_spi.c
+ \brief SPI driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.1, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
+
#include "gd32f4xx_spi.h"
#include "gd32f4xx_rcu.h"
-#define SPI_INIT_MASK ((uint32_t)0x00003040U)
-#define I2S_INIT_MASK ((uint32_t)0x0000F047U)
-#define I2S_FULL_DUPLEX_MASK ((uint32_t)0x0000F040U)
+/* SPI/I2S parameter initialization mask */
+#define SPI_INIT_MASK ((uint32_t)0x00003040U) /*!< SPI parameter initialization mask */
+#define I2S_INIT_MASK ((uint32_t)0x0000F047U) /*!< I2S parameter initialization mask */
+#define I2S_FULL_DUPLEX_MASK ((uint32_t)0x00000480U) /*!< I2S full duples mode configure parameter initialization mask */
+
+/* default value */
+#define SPI_I2SPSC_DEFAULT_VALUE ((uint32_t)0x00000002U) /*!< default value of SPI_I2SPSC register */
/*!
- \brief SPI and I2S reset
+ \brief deinitialize SPI and I2S
\param[in] spi_periph: SPIx(x=0,1,2,3,4,5),include I2S1_ADD and I2S2_ADD
\param[out] none
\retval none
@@ -26,7 +56,7 @@ void spi_i2s_deinit(uint32_t spi_periph)
{
switch(spi_periph){
case SPI0:
- /* reset SPI0 and I2S0 */
+ /* reset SPI0 */
rcu_periph_reset_enable(RCU_SPI0RST);
rcu_periph_reset_disable(RCU_SPI0RST);
break;
@@ -41,12 +71,12 @@ void spi_i2s_deinit(uint32_t spi_periph)
rcu_periph_reset_disable(RCU_SPI2RST);
break;
case SPI3:
- /* reset SPI3 and I2S3 */
+ /* reset SPI3 */
rcu_periph_reset_enable(RCU_SPI3RST);
rcu_periph_reset_disable(RCU_SPI3RST);
break;
case SPI4:
- /* reset SPI4 and I2S4 */
+ /* reset SPI4 */
rcu_periph_reset_enable(RCU_SPI4RST);
rcu_periph_reset_disable(RCU_SPI4RST);
break;
@@ -61,41 +91,58 @@ void spi_i2s_deinit(uint32_t spi_periph)
}
/*!
- \brief SPI parameter initialization
+ \brief initialize the parameters of SPI struct with default values
+ \param[in] none
+ \param[out] spi_parameter_struct: the initialized struct spi_parameter_struct pointer
+ \retval none
+*/
+void spi_struct_para_init(spi_parameter_struct *spi_struct)
+{
+ /* configure the structure with default value */
+ spi_struct->device_mode = SPI_SLAVE;
+ spi_struct->trans_mode = SPI_TRANSMODE_FULLDUPLEX;
+ spi_struct->frame_size = SPI_FRAMESIZE_8BIT;
+ spi_struct->nss = SPI_NSS_HARD;
+ spi_struct->clock_polarity_phase = SPI_CK_PL_LOW_PH_1EDGE;
+ spi_struct->prescale = SPI_PSC_2;
+ spi_struct->endian = SPI_ENDIAN_MSB;
+}
+/*!
+ \brief initialize SPI parameter
\param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
- \param[in] spi_struct: SPI parameter initialization stuct
- members of the structure and the member values are shown as below:
- device_mode : SPI_MASTER, SPI_SLAVE.
- trans_mode : SPI_TRANSMODE_FULLDUPLEX, SPI_TRANSMODE_RECEIVEONLY,
- SPI_TRANSMODE_BDRECEIVE, SPI_TRANSMODE_BDTRANSMIT
- frame_size : SPI_FRAMESIZE_16BIT, SPI_FRAMESIZE_8BIT
- nss: : SPI_NSS_SOFT, SPI_NSS_HARD
- endian : SPI_ENDIAN_MSB, SPI_ENDIAN_LSB
- clock_polarity_phase : SPI_CK_PL_LOW_PH_1EDGE, SPI_CK_PL_HIGH_PH_1EDGE
- SPI_CK_PL_LOW_PH_2EDGE, SPI_CK_PL_HIGH_PH_2EDGE
- prescale : SPI_PSC_n (n=2,4,8,16,32,64,128,256)
+ \param[in] spi_struct: SPI parameter initialization stuct members of the structure
+ and the member values are shown as below:
+ device_mode: SPI_MASTER, SPI_SLAVE.
+ trans_mode: SPI_TRANSMODE_FULLDUPLEX, SPI_TRANSMODE_RECEIVEONLY,
+ SPI_TRANSMODE_BDRECEIVE, SPI_TRANSMODE_BDTRANSMIT
+ frame_size: SPI_FRAMESIZE_16BIT, SPI_FRAMESIZE_8BIT
+ nss: SPI_NSS_SOFT, SPI_NSS_HARD
+ endian: SPI_ENDIAN_MSB, SPI_ENDIAN_LSB
+ clock_polarity_phase: SPI_CK_PL_LOW_PH_1EDGE, SPI_CK_PL_HIGH_PH_1EDGE
+ SPI_CK_PL_LOW_PH_2EDGE, SPI_CK_PL_HIGH_PH_2EDGE
+ prescale: SPI_PSC_n (n=2,4,8,16,32,64,128,256)
\param[out] none
\retval none
*/
void spi_init(uint32_t spi_periph, spi_parameter_struct* spi_struct)
-{
+{
uint32_t reg = 0U;
reg = SPI_CTL0(spi_periph);
reg &= SPI_INIT_MASK;
- /* (1) select SPI as master or slave */
+ /* select SPI as master or slave */
reg |= spi_struct->device_mode;
- /* (2) select SPI transfer mode */
+ /* select SPI transfer mode */
reg |= spi_struct->trans_mode;
- /* (3) select SPI frame size */
+ /* select SPI frame size */
reg |= spi_struct->frame_size;
- /* (4) select SPI nss use hardware or software */
+ /* select SPI nss use hardware or software */
reg |= spi_struct->nss;
- /* (5) select SPI LSB or MSB */
+ /* select SPI LSB or MSB */
reg |= spi_struct->endian;
- /* (6) select SPI polarity and phase */
+ /* select SPI polarity and phase */
reg |= spi_struct->clock_polarity_phase;
- /* (7) select SPI prescale to adjust transmit speed */
+ /* select SPI prescale to adjust transmit speed */
reg |= spi_struct->prescale;
/* write to SPI_CTL0 register */
@@ -105,7 +152,7 @@ void spi_init(uint32_t spi_periph, spi_parameter_struct* spi_struct)
}
/*!
- \brief SPI enable
+ \brief enable SPI
\param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
\param[out] none
\retval none
@@ -116,7 +163,7 @@ void spi_enable(uint32_t spi_periph)
}
/*!
- \brief SPI disable
+ \brief disable SPI
\param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
\param[out] none
\retval none
@@ -127,24 +174,69 @@ void spi_disable(uint32_t spi_periph)
}
/*!
- \brief I2S prescale config
- \param[in] spi_periph: SPIx(x=0,1,2,3,4)
- \param[in] audiosample:
- \arg I2S_AUDIOSAMPLE_8K: audio sample rate is 8khz
- \arg I2S_AUDIOSAMPLE_11K: audio sample rate is 11khz
- \arg I2S_AUDIOSAMPLE_16K: audio sample rate is 16khz
- \arg I2S_AUDIOSAMPLE_22K: audio sample rate is 22khz
- \arg I2S_AUDIOSAMPLE_32K: audio sample rate is 32khz
- \arg I2S_AUDIOSAMPLE_44K: audio sample rate is 44khz
- \arg I2S_AUDIOSAMPLE_48K: audio sample rate is 48khz
- \arg I2S_AUDIOSAMPLE_96K: audio sample rate is 96khz
- \arg I2S_AUDIOSAMPLE_192K: audio sample rate is 192khz
- \param[in] frameformat:
+ \brief initialize I2S parameter
+ \param[in] spi_periph: SPIx(x=1,2)
+ \param[in] i2s_mode: I2S operation mode
+ only one parameter can be selected which is shown as below:
+ \arg I2S_MODE_SLAVETX : I2S slave transmit mode
+ \arg I2S_MODE_SLAVERX : I2S slave receive mode
+ \arg I2S_MODE_MASTERTX : I2S master transmit mode
+ \arg I2S_MODE_MASTERRX : I2S master receive mode
+ \param[in] i2s_standard: I2S standard
+ only one parameter can be selected which is shown as below:
+ \arg I2S_STD_PHILLIPS : I2S phillips standard
+ \arg I2S_STD_MSB : I2S MSB standard
+ \arg I2S_STD_LSB : I2S LSB standard
+ \arg I2S_STD_PCMSHORT : I2S PCM short standard
+ \arg I2S_STD_PCMLONG : I2S PCM long standard
+ \param[in] i2s_ckpl: I2S idle state clock polarity
+ only one parameter can be selected which is shown as below:
+ \arg I2S_CKPL_LOW : I2S clock polarity low level
+ \arg I2S_CKPL_HIGH : I2S clock polarity high level
+ \param[out] none
+ \retval none
+*/
+void i2s_init(uint32_t spi_periph, uint32_t i2s_mode, uint32_t i2s_standard, uint32_t i2s_ckpl)
+{
+ uint32_t reg= 0U;
+ reg = SPI_I2SCTL(spi_periph);
+ reg &= I2S_INIT_MASK;
+
+ /* enable I2S mode */
+ reg |= (uint32_t)SPI_I2SCTL_I2SSEL;
+ /* select I2S mode */
+ reg |= (uint32_t)i2s_mode;
+ /* select I2S standard */
+ reg |= (uint32_t)i2s_standard;
+ /* select I2S polarity */
+ reg |= (uint32_t)i2s_ckpl;
+
+ /* write to SPI_I2SCTL register */
+ SPI_I2SCTL(spi_periph) = (uint32_t)reg;
+}
+
+/*!
+ \brief configure I2S prescale
+ \param[in] spi_periph: SPIx(x=1,2)
+ \param[in] i2s_audiosample: I2S audio sample rate
+ only one parameter can be selected which is shown as below:
+ \arg I2S_AUDIOSAMPLE_8K: audio sample rate is 8KHz
+ \arg I2S_AUDIOSAMPLE_11K: audio sample rate is 11KHz
+ \arg I2S_AUDIOSAMPLE_16K: audio sample rate is 16KHz
+ \arg I2S_AUDIOSAMPLE_22K: audio sample rate is 22KHz
+ \arg I2S_AUDIOSAMPLE_32K: audio sample rate is 32KHz
+ \arg I2S_AUDIOSAMPLE_44K: audio sample rate is 44KHz
+ \arg I2S_AUDIOSAMPLE_48K: audio sample rate is 48KHz
+ \arg I2S_AUDIOSAMPLE_96K: audio sample rate is 96KHz
+ \arg I2S_AUDIOSAMPLE_192K: audio sample rate is 192KHz
+ \param[in] i2s_frameformat: I2S data length and channel length
+ only one parameter can be selected which is shown as below:
\arg I2S_FRAMEFORMAT_DT16B_CH16B: I2S data length is 16 bit and channel length is 16 bit
\arg I2S_FRAMEFORMAT_DT16B_CH32B: I2S data length is 16 bit and channel length is 32 bit
\arg I2S_FRAMEFORMAT_DT24B_CH32B: I2S data length is 24 bit and channel length is 32 bit
\arg I2S_FRAMEFORMAT_DT32B_CH32B: I2S data length is 32 bit and channel length is 32 bit
- \param[in] mckout:
+ \param[in] i2s_mckout: I2S master clock output
+ only one parameter can be selected which is shown as below:
\arg I2S_MCKOUT_ENABLE: I2S master clock output enable
\arg I2S_MCKOUT_DISABLE: I2S master clock output disable
\param[out] none
@@ -152,8 +244,8 @@ void spi_disable(uint32_t spi_periph)
*/
void i2s_psc_config(uint32_t spi_periph, uint32_t i2s_audiosample, uint32_t i2s_frameformat, uint32_t i2s_mckout)
{
- uint32_t temp_div = 2U, temp_of = 0U;
- uint32_t temp = 0U;
+ uint32_t i2sdiv = 2U, i2sof = 0U;
+ uint32_t clks = 0U;
uint32_t i2sclock = 0U;
#ifndef I2S_EXTERNAL_CLOCK_IN
@@ -161,7 +253,7 @@ void i2s_psc_config(uint32_t spi_periph, uint32_t i2s_audiosample, uint32_t i2s_
#endif /* I2S_EXTERNAL_CLOCK_IN */
/* deinit SPI_I2SPSC register */
- SPI_I2SPSC(spi_periph) = 0x0002U;
+ SPI_I2SPSC(spi_periph) = SPI_I2SPSC_DEFAULT_VALUE;
#ifdef I2S_EXTERNAL_CLOCK_IN
rcu_i2s_clock_config(RCU_I2SSRC_I2S_CKIN);
@@ -201,28 +293,28 @@ void i2s_psc_config(uint32_t spi_periph, uint32_t i2s_audiosample, uint32_t i2s_
/* config the prescaler depending on the mclk output state, the frame format and audio sample rate */
if(I2S_MCKOUT_ENABLE == i2s_mckout){
- temp = (uint32_t)(((i2sclock / 256U) * 10U) / i2s_audiosample);
+ clks = (uint32_t)(((i2sclock / 256U) * 10U) / i2s_audiosample);
}else{
if(I2S_FRAMEFORMAT_DT16B_CH16B == i2s_frameformat){
- temp = (uint32_t)(((i2sclock / 32U) *10U ) / i2s_audiosample);
+ clks = (uint32_t)(((i2sclock / 32U) *10U ) / i2s_audiosample);
}else{
- temp = (uint32_t)(((i2sclock / 64U) *10U ) / i2s_audiosample);
+ clks = (uint32_t)(((i2sclock / 64U) *10U ) / i2s_audiosample);
}
}
/* remove the floating point */
- temp = (temp + 5U) / 10U;
- temp_of = (temp & 0x00000001U);
- temp_div = ((temp - temp_of) / 2U);
- temp_of = (temp_of << 8);
+ clks = (clks + 5U) / 10U;
+ i2sof = (clks & 0x00000001U);
+ i2sdiv = ((clks - i2sof) / 2U);
+ i2sof = (i2sof << 8U);
/* set the default values */
- if((temp_div< 2U) || (temp_div > 255U)){
- temp_div = 2U;
- temp_of = 0U;
+ if((i2sdiv< 2U) || (i2sdiv > 255U)){
+ i2sdiv = 2U;
+ i2sof = 0U;
}
/* configure SPI_I2SPSC */
- SPI_I2SPSC(spi_periph) = (uint32_t)(temp_div | temp_of | i2s_mckout);
+ SPI_I2SPSC(spi_periph) = (uint32_t)(i2sdiv | i2sof | i2s_mckout);
/* clear SPI_I2SCTL_DTLEN and SPI_I2SCTL_CHLEN bits */
SPI_I2SCTL(spi_periph) &= (uint32_t)(~(SPI_I2SCTL_DTLEN|SPI_I2SCTL_CHLEN));
@@ -231,47 +323,8 @@ void i2s_psc_config(uint32_t spi_periph, uint32_t i2s_audiosample, uint32_t i2s_
}
/*!
- \brief I2S parameter configuration
- \param[in] spi_periph: SPIx(x=0,1,2,3,4)
- \param[in] i2s_mode:
- \arg I2S_MODE_SLAVETX : I2S slave transmit mode
- \arg I2S_MODE_SLAVERX : I2S slave receive mode
- \arg I2S_MODE_MASTERTX : I2S master transmit mode
- \arg I2S_MODE_MASTERRX : I2S master receive mode
- \param[in] i2s_std:
- \arg I2S_STD_PHILLIPS : I2S phillips standard
- \arg I2S_STD_MSB : I2S MSB standard
- \arg I2S_STD_LSB : I2S LSB standard
- \arg I2S_STD_PCMSHORT : I2S PCM short standard
- \arg I2S_STD_PCMLONG : I2S PCM long standard
- \param[in] i2s_ckpl:
- \arg I2S_CKPL_LOW : I2S clock polarity low level
- \arg I2S_CKPL_HIGH : I2S clock polarity high level
- \param[out] none
- \retval none
-*/
-void i2s_init(uint32_t spi_periph, uint32_t i2s_mode, uint32_t i2s_standard, uint32_t i2s_ckpl)
-{
- uint32_t reg= 0U;
- reg = SPI_I2SCTL(spi_periph);
- reg &= I2S_INIT_MASK;
-
- /* enable I2S mode */
- reg |= (uint32_t)SPI_I2SCTL_I2SSEL;
- /* select I2S mode */
- reg |= (uint32_t)i2s_mode;
- /* select I2S standard */
- reg |= (uint32_t)i2s_standard;
- /* select I2S polarity */
- reg |= (uint32_t)i2s_ckpl;
-
- /* write to SPI_I2SCTL register */
- SPI_I2SCTL(spi_periph) = (uint32_t)reg;
-}
-
-/*!
- \brief I2S enable
- \param[in] spi_periph: SPIx(x=0,1,2,3,4)
+ \brief enable I2S
+ \param[in] spi_periph: SPIx(x=1,2)
\param[out] none
\retval none
*/
@@ -281,8 +334,8 @@ void i2s_enable(uint32_t spi_periph)
}
/*!
- \brief I2S disable
- \param[in] spi_periph: SPIx(x=0,1,2,3,4)
+ \brief disable I2S
+ \param[in] spi_periph: SPIx(x=1,2)
\param[out] none
\retval none
*/
@@ -292,7 +345,7 @@ void i2s_disable(uint32_t spi_periph)
}
/*!
- \brief SPI nss output enable
+ \brief enable SPI nss output
\param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
\param[out] none
\retval none
@@ -303,7 +356,7 @@ void spi_nss_output_enable(uint32_t spi_periph)
}
/*!
- \brief SPI nss output disable
+ \brief disable SPI nss output
\param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
\param[out] none
\retval none
@@ -336,11 +389,12 @@ void spi_nss_internal_low(uint32_t spi_periph)
}
/*!
- \brief SPI dma send or receive enable
+ \brief enable SPI DMA send or receive
\param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
- \param[in] spi_dma:
- \arg SPI_DMA_TRANSMIT: enable DMA transmit
- \arg SPI_DMA_RECEIVE: enable DMA receive
+ \param[in] spi_dma: SPI DMA mode
+ only one parameter can be selected which is shown as below:
+ \arg SPI_DMA_TRANSMIT: SPI transmit data use DMA
+ \arg SPI_DMA_RECEIVE: SPI receive data use DMA
\param[out] none
\retval none
*/
@@ -354,11 +408,12 @@ void spi_dma_enable(uint32_t spi_periph, uint8_t spi_dma)
}
/*!
- \brief SPI dma send or receive diable
+ \brief diable SPI DMA send or receive
\param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
- \param[in] spi_dma:
- \arg SPI_DMA_TRANSMIT: disable DMA transmit
- \arg SPI_DMA_RECEIVE: disable DMA receive
+ \param[in] spi_dma: SPI DMA mode
+ only one parameter can be selected which is shown as below:
+ \arg SPI_DMA_TRANSMIT: SPI transmit data use DMA
+ \arg SPI_DMA_RECEIVE: SPI receive data use DMA
\param[out] none
\retval none
*/
@@ -374,7 +429,8 @@ void spi_dma_disable(uint32_t spi_periph, uint8_t spi_dma)
/*!
\brief configure SPI/I2S data frame format
\param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
- \param[in] frame_format:
+ \param[in] frame_format: SPI frame size
+ only one parameter can be selected which is shown as below:
\arg SPI_FRAMESIZE_16BIT: SPI frame size is 16 bits
\arg SPI_FRAMESIZE_8BIT: SPI frame size is 8 bits
\param[out] none
@@ -384,7 +440,7 @@ void spi_i2s_data_frame_format_config(uint32_t spi_periph, uint16_t frame_format
{
/* clear SPI_CTL0_FF16 bit */
SPI_CTL0(spi_periph) &= (uint32_t)(~SPI_CTL0_FF16);
- /* confige SPI_CTL0_FF16 bit */
+ /* configure SPI_CTL0_FF16 bit */
SPI_CTL0(spi_periph) |= (uint32_t)frame_format;
}
@@ -401,7 +457,7 @@ void spi_i2s_data_transmit(uint32_t spi_periph, uint16_t data)
}
/*!
- \brief receive data
+ \brief SPI receive data
\param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
\param[out] none
\retval 16-bit data
@@ -414,16 +470,17 @@ uint16_t spi_i2s_data_receive(uint32_t spi_periph)
/*!
\brief configure SPI bidirectional transfer direction
\param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
- \param[in] transfer_direction:
- \arg SPI_BIDIRECTIONAL_TEANSMIT: SPI work in transmit-only mode
+ \param[in] transfer_direction: SPI transfer direction
+ only one parameter can be selected which is shown as below:
+ \arg SPI_BIDIRECTIONAL_TRANSMIT: SPI work in transmit-only mode
\arg SPI_BIDIRECTIONAL_RECEIVE: SPI work in receive-only mode
\retval none
*/
void spi_bidirectional_transfer_config(uint32_t spi_periph, uint32_t transfer_direction)
{
- if(SPI_BIDIRECTIONAL_TEANSMIT == transfer_direction){
+ if(SPI_BIDIRECTIONAL_TRANSMIT == transfer_direction){
/* set the transmit only mode */
- SPI_CTL0(spi_periph) |= (uint32_t)SPI_BIDIRECTIONAL_TEANSMIT;
+ SPI_CTL0(spi_periph) |= (uint32_t)SPI_BIDIRECTIONAL_TRANSMIT;
}else{
/* set the receive only mode */
SPI_CTL0(spi_periph) &= SPI_BIDIRECTIONAL_RECEIVE;
@@ -431,166 +488,34 @@ void spi_bidirectional_transfer_config(uint32_t spi_periph, uint32_t transfer_di
}
/*!
- \brief SPI and I2S interrupt enable
+ \brief set SPI CRC polynomial
\param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
- \param[in] spi_i2s_int:
- \arg SPI_I2S_INT_TBE: transmit buffer empty interrupt
- \arg SPI_I2S_INT_RBNE: receive buffer not empty interrupt
- \arg SPI_I2S_INT_ERR: CRC error,configuration error,reception overrun error,
- transmission underrun error and format error interrupt
- \param[out] none
- \retval none
-*/
-void spi_i2s_interrupt_enable(uint32_t spi_periph, uint8_t spi_i2s_int)
-{
- switch(spi_i2s_int){
- case SPI_I2S_INT_TBE:
- SPI_CTL1(spi_periph) |= (uint32_t)SPI_CTL1_TBEIE;
- break;
- case SPI_I2S_INT_RBNE:
- SPI_CTL1(spi_periph) |= (uint32_t)SPI_CTL1_RBNEIE;
- break;
- case SPI_I2S_INT_ERR:
- SPI_CTL1(spi_periph) |= (uint32_t)SPI_CTL1_ERRIE;
- break;
- default:
- break;
- }
-}
-
-/*!
- \brief SPI and I2S interrupt disable
- \param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
- \param[in] spi_i2s_int:
- \arg SPI_I2S_INT_TBE: transmit buffer empty interrupt
- \arg SPI_I2S_INT_RBNE: receive buffer not empty interrupt
- \arg SPI_I2S_INT_ERR: CRC error,configuration error,reception overrun error,
- transmission underrun error and format error interrupt
+ \param[in] crc_poly: CRC polynomial value
\param[out] none
\retval none
*/
-void spi_i2s_interrupt_disable(uint32_t spi_periph, uint8_t spi_i2s_int)
-{
- switch(spi_i2s_int){
- case SPI_I2S_INT_TBE :
- SPI_CTL1(spi_periph) &= (uint32_t)(~SPI_CTL1_TBEIE);
- break;
- case SPI_I2S_INT_RBNE :
- SPI_CTL1(spi_periph) &= (uint32_t)(~SPI_CTL1_RBNEIE);
- break;
- case SPI_I2S_INT_ERR :
- SPI_CTL1(spi_periph) &= (uint32_t)(~SPI_CTL1_ERRIE);
- break;
- default :
- break;
- }
-}
-
-/*!
- \brief get interrupt flag status
- \param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
- \param[in] spi_i2s_int:
- \arg SPI_I2S_INT_TBE: transmit buffer empty interrupt
- \arg SPI_I2S_INT_RBNE: receive buffer not empty interrupt
- \arg SPI_I2S_INT_RXORERR: overrun interrupt
- \arg SPI_INT_CONFERR: config error interrupt
- \arg SPI_INT_CRCERR: CRC error interrupt
- \arg I2S_INT_TXURERR: underrun error interrupt
- \arg SPI_I2S_INT_FERR: format error interrupt
- \param[out] none
- \retval FlagStatus: SET or RESET
-*/
-FlagStatus spi_i2s_interrupt_flag_get(uint32_t spi_periph, uint8_t spi_i2s_int)
+void spi_crc_polynomial_set(uint32_t spi_periph,uint16_t crc_poly)
{
- uint32_t reg1 = SPI_STAT(spi_periph);
- uint32_t reg2 = SPI_CTL1(spi_periph);
-
- uint32_t temp1 = 0U;
- uint32_t temp2 = 0U;
-
- switch(spi_i2s_int){
- case SPI_I2S_INT_TBE :
- temp1 = reg1 & SPI_STAT_TBE;
- temp2 = reg2 & SPI_CTL1_TBEIE;
- break;
- case SPI_I2S_INT_RBNE :
- temp1 = reg1 & SPI_STAT_RBNE;
- temp2 = reg2 & SPI_CTL1_RBNEIE;
- break;
- case SPI_I2S_INT_RXORERR :
- temp1 = reg1 & SPI_STAT_RXORERR;
- temp2 = reg2 & SPI_CTL1_ERRIE;
- break;
- case SPI_INT_CONFERR :
- temp1 = reg1 & SPI_STAT_CONFERR;
- temp2 = reg2 & SPI_CTL1_ERRIE;
- break;
- case SPI_INT_CRCERR :
- temp1 = reg1 & SPI_STAT_CRCERR;
- temp2 = reg2 & SPI_CTL1_ERRIE;
- break;
- case I2S_INT_TXURERR :
- temp1 = reg1 & SPI_STAT_TXURERR;
- temp2 = reg2 & SPI_CTL1_ERRIE;
- break;
- case SPI_I2S_INT_FERR :
- temp1 = reg1 & SPI_STAT_FERR;
- temp2 = reg2 & SPI_CTL1_ERRIE;
- break;
- default :
- break;
- }
-
- if(temp1 && temp2){
- return SET;
- }else{
- return RESET;
- }
-}
+ /* enable SPI CRC */
+ SPI_CTL0(spi_periph) |= (uint32_t)SPI_CTL0_CRCEN;
-/*!
- \brief get flag status
- \param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
- \param[in] spi_i2s_flag:
- \arg SPI_FLAG_TBE: transmit buffer empty flag
- \arg SPI_FLAG_RBNE: receive buffer not empty flag
- \arg SPI_FLAG_TRANS: transmit on-going flag
- \arg SPI_FLAG_RXORERR: receive Overrun flag
- \arg SPI_FLAG_CONFERR: mode config error flag
- \arg SPI_FLAG_CRCERR: CRC error flag
- \arg SPI_FLAG_FERR: format error interrupt flag
- \arg I2S_FLAG_TBE: transmit buffer empty flag
- \arg I2S_FLAG_RBNE: receive buffer not empty flag
- \arg I2S_FLAG_TRANS: transmit on-going flag
- \arg I2S_FLAG_RXORERR: overrun flag
- \arg I2S_FLAG_TXURERR: underrun error flag
- \arg I2S_FLAG_CH: channel side flag
- \arg I2S_FLAG_FERR: format error interrupt flag
- \param[out] none
- \retval FlagStatus: SET or RESET
-*/
-FlagStatus spi_i2s_flag_get(uint32_t spi_periph, uint32_t spi_i2s_flag)
-{
- if(SPI_STAT(spi_periph) & spi_i2s_flag){
- return SET;
- }else{
- return RESET;
- }
+ /* set SPI CRC polynomial */
+ SPI_CRCPOLY(spi_periph) = (uint32_t)crc_poly;
}
/*!
- \brief clear SPI CRC error flag status
+ \brief get SPI CRC polynomial
\param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
\param[out] none
- \retval none
+ \retval 16-bit CRC polynomial
*/
-void spi_crc_error_clear(uint32_t spi_periph)
+uint16_t spi_crc_polynomial_get(uint32_t spi_periph)
{
- SPI_STAT(spi_periph) &= (uint32_t)(~SPI_FLAG_CRCERR);
+ return ((uint16_t)SPI_CRCPOLY(spi_periph));
}
/*!
- \brief CRC function turn on
+ \brief turn on CRC function
\param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
\param[out] none
\retval none
@@ -601,7 +526,7 @@ void spi_crc_on(uint32_t spi_periph)
}
/*!
- \brief CRC function turn off
+ \brief turn off CRC function
\param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
\param[out] none
\retval none
@@ -612,33 +537,6 @@ void spi_crc_off(uint32_t spi_periph)
}
/*!
- \brief CRC polynomial set
- \param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
- \param[in] crc_poly: CRC polynomial value
- \param[out] none
- \retval none
-*/
-void spi_crc_polynomial_set(uint32_t spi_periph,uint16_t crc_poly)
-{
- /* enable SPI CRC */
- SPI_CTL0(spi_periph) |= (uint32_t)SPI_CTL0_CRCEN;
-
- /* set SPI CRC polynomial */
- SPI_CRCPOLY(spi_periph) = (uint32_t)crc_poly;
-}
-
-/*!
- \brief get SPI CRC polynomial
- \param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
- \param[out] none
- \retval 16-bit CRC polynomial
-*/
-uint16_t spi_crc_polynomial_get(uint32_t spi_periph)
-{
- return ((uint16_t)SPI_CRCPOLY(spi_periph));
-}
-
-/*!
\brief SPI next data is CRC value
\param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
\param[out] none
@@ -652,7 +550,8 @@ void spi_crc_next(uint32_t spi_periph)
/*!
\brief get SPI CRC send value or receive value
\param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
- \param[in] spi_crc:
+ \param[in] spi_crc: SPI crc value
+ only one parameter can be selected which is shown as below:
\arg SPI_CRC_TX: get transmit crc value
\arg SPI_CRC_RX: get receive crc value
\param[out] none
@@ -692,18 +591,18 @@ void spi_ti_mode_disable(uint32_t spi_periph)
/*!
\brief configure i2s full duplex mode
\param[in] i2s_add_periph: I2Sx_ADD(x=1,2)
- \param[in] i2s_mode:
+ \param[in] i2s_mode:
\arg I2S_MODE_SLAVETX : I2S slave transmit mode
\arg I2S_MODE_SLAVERX : I2S slave receive mode
\arg I2S_MODE_MASTERTX : I2S master transmit mode
\arg I2S_MODE_MASTERRX : I2S master receive mode
- \param[in] i2s_standard:
+ \param[in] i2s_standard:
\arg I2S_STD_PHILLIPS : I2S phillips standard
\arg I2S_STD_MSB : I2S MSB standard
\arg I2S_STD_LSB : I2S LSB standard
\arg I2S_STD_PCMSHORT : I2S PCM short standard
\arg I2S_STD_PCMLONG : I2S PCM long standard
- \param[in] i2s_ckpl:
+ \param[in] i2s_ckpl:
\arg I2S_CKPL_LOW : I2S clock polarity low level
\arg I2S_CKPL_HIGH : I2S clock polarity high level
\param[in] i2s_frameformat:
@@ -720,7 +619,7 @@ void i2s_full_duplex_mode_config(uint32_t i2s_add_periph, uint32_t i2s_mode, uin
uint32_t reg = 0U, tmp = 0U;
reg = I2S_ADD_I2SCTL(i2s_add_periph);
- reg &= I2S_FULL_DUPLEX_MASK;
+ reg &= I2S_FULL_DUPLEX_MASK;
/* get the mode of the extra I2S module I2Sx_ADD */
if((I2S_MODE_MASTERTX == i2s_mode) || (I2S_MODE_SLAVETX == i2s_mode)){
@@ -730,7 +629,7 @@ void i2s_full_duplex_mode_config(uint32_t i2s_add_periph, uint32_t i2s_mode, uin
}
/* enable I2S mode */
- reg |= (uint32_t)SPI_I2SCTL_I2SSEL;
+ reg |= (uint32_t)SPI_I2SCTL_I2SSEL;
/* select I2S mode */
reg |= (uint32_t)tmp;
/* select I2S standard */
@@ -745,7 +644,7 @@ void i2s_full_duplex_mode_config(uint32_t i2s_add_periph, uint32_t i2s_mode, uin
}
/*!
- \brief quad wire SPI enable
+ \brief enable quad wire SPI
\param[in] spi_periph: SPIx(only x=5)
\param[out] none
\retval none
@@ -756,7 +655,7 @@ void qspi_enable(uint32_t spi_periph)
}
/*!
- \brief quad wire SPI disable
+ \brief disable quad wire SPI
\param[in] spi_periph: SPIx(only x=5)
\param[out] none
\retval none
@@ -767,7 +666,7 @@ void qspi_disable(uint32_t spi_periph)
}
/*!
- \brief quad wire SPI write enable
+ \brief enable quad wire SPI write
\param[in] spi_periph: SPIx(only x=5)
\param[out] none
\retval none
@@ -778,7 +677,7 @@ void qspi_write_enable(uint32_t spi_periph)
}
/*!
- \brief quad wire SPI read enable
+ \brief enable quad wire SPI read
\param[in] spi_periph: SPIx(only x=5)
\param[out] none
\retval none
@@ -789,7 +688,7 @@ void qspi_read_enable(uint32_t spi_periph)
}
/*!
- \brief SPI_IO2 and SPI_IO3 pin output enable
+ \brief enable SPI_IO2 and SPI_IO3 pin output
\param[in] spi_periph: SPIx(only x=5)
\param[out] none
\retval none
@@ -800,7 +699,7 @@ void qspi_io23_output_enable(uint32_t spi_periph)
}
/*!
- \brief SPI_IO2 and SPI_IO3 pin output disable
+ \brief disable SPI_IO2 and SPI_IO3 pin output
\param[in] spi_periph: SPIx(only x=5)
\param[out] none
\retval none
@@ -809,3 +708,175 @@ void qspi_io23_output_enable(uint32_t spi_periph)
{
SPI_QCTL(spi_periph) &= (uint32_t)(~SPI_QCTL_IO23_DRV);
}
+
+/*!
+ \brief enable SPI and I2S interrupt
+ \param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
+ \param[in] spi_i2s_int: SPI/I2S interrupt
+ only one parameter can be selected which is shown as below:
+ \arg SPI_I2S_INT_TBE: transmit buffer empty interrupt
+ \arg SPI_I2S_INT_RBNE: receive buffer not empty interrupt
+ \arg SPI_I2S_INT_ERR: CRC error,configuration error,reception overrun error,
+ transmission underrun error and format error interrupt
+ \param[out] none
+ \retval none
+*/
+void spi_i2s_interrupt_enable(uint32_t spi_periph, uint8_t spi_i2s_int)
+{
+ switch(spi_i2s_int){
+ /* SPI/I2S transmit buffer empty interrupt */
+ case SPI_I2S_INT_TBE:
+ SPI_CTL1(spi_periph) |= (uint32_t)SPI_CTL1_TBEIE;
+ break;
+ /* SPI/I2S receive buffer not empty interrupt */
+ case SPI_I2S_INT_RBNE:
+ SPI_CTL1(spi_periph) |= (uint32_t)SPI_CTL1_RBNEIE;
+ break;
+ /* SPI/I2S error */
+ case SPI_I2S_INT_ERR:
+ SPI_CTL1(spi_periph) |= (uint32_t)SPI_CTL1_ERRIE;
+ break;
+ default:
+ break;
+ }
+}
+
+/*!
+ \brief disable SPI and I2S interrupt
+ \param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
+ \param[in] spi_i2s_int: SPI/I2S interrupt
+ only one parameter can be selected which is shown as below:
+ \arg SPI_I2S_INT_TBE: transmit buffer empty interrupt
+ \arg SPI_I2S_INT_RBNE: receive buffer not empty interrupt
+ \arg SPI_I2S_INT_ERR: CRC error,configuration error,reception overrun error,
+ transmission underrun error and format error interrupt
+ \param[out] none
+ \retval none
+*/
+void spi_i2s_interrupt_disable(uint32_t spi_periph, uint8_t spi_i2s_int)
+{
+ switch(spi_i2s_int){
+ /* SPI/I2S transmit buffer empty interrupt */
+ case SPI_I2S_INT_TBE :
+ SPI_CTL1(spi_periph) &= (uint32_t)(~SPI_CTL1_TBEIE);
+ break;
+ /* SPI/I2S receive buffer not empty interrupt */
+ case SPI_I2S_INT_RBNE :
+ SPI_CTL1(spi_periph) &= (uint32_t)(~SPI_CTL1_RBNEIE);
+ break;
+ /* SPI/I2S error */
+ case SPI_I2S_INT_ERR :
+ SPI_CTL1(spi_periph) &= (uint32_t)(~SPI_CTL1_ERRIE);
+ break;
+ default :
+ break;
+ }
+}
+
+/*!
+ \brief get SPI and I2S interrupt flag status
+ \param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
+ \param[in] spi_i2s_int: SPI/I2S interrupt flag status
+ \arg SPI_I2S_INT_FLAG_TBE: transmit buffer empty interrupt flag
+ \arg SPI_I2S_INT_FLAG_RBNE: receive buffer not empty interrupt flag
+ \arg SPI_I2S_INT_FLAG_RXORERR: overrun interrupt flag
+ \arg SPI_INT_FLAG_CONFERR: config error interrupt flag
+ \arg SPI_INT_FLAG_CRCERR: CRC error interrupt flag
+ \arg I2S_INT_FLAG_TXURERR: underrun error interrupt flag
+ \arg SPI_I2S_INT_FLAG_FERR: format error interrupt flag
+ \param[out] none
+ \retval FlagStatus: SET or RESET
+*/
+FlagStatus spi_i2s_interrupt_flag_get(uint32_t spi_periph, uint8_t spi_i2s_int)
+{
+ uint32_t reg1 = SPI_STAT(spi_periph);
+ uint32_t reg2 = SPI_CTL1(spi_periph);
+
+ switch(spi_i2s_int){
+ /* SPI/I2S transmit buffer empty interrupt */
+ case SPI_I2S_INT_FLAG_TBE :
+ reg1 = reg1 & SPI_STAT_TBE;
+ reg2 = reg2 & SPI_CTL1_TBEIE;
+ break;
+ /* SPI/I2S receive buffer not empty interrupt */
+ case SPI_I2S_INT_FLAG_RBNE :
+ reg1 = reg1 & SPI_STAT_RBNE;
+ reg2 = reg2 & SPI_CTL1_RBNEIE;
+ break;
+ /* SPI/I2S overrun interrupt */
+ case SPI_I2S_INT_FLAG_RXORERR :
+ reg1 = reg1 & SPI_STAT_RXORERR;
+ reg2 = reg2 & SPI_CTL1_ERRIE;
+ break;
+ /* SPI config error interrupt */
+ case SPI_INT_FLAG_CONFERR :
+ reg1 = reg1 & SPI_STAT_CONFERR;
+ reg2 = reg2 & SPI_CTL1_ERRIE;
+ break;
+ /* SPI CRC error interrupt */
+ case SPI_INT_FLAG_CRCERR :
+ reg1 = reg1 & SPI_STAT_CRCERR;
+ reg2 = reg2 & SPI_CTL1_ERRIE;
+ break;
+ /* I2S underrun error interrupt */
+ case I2S_INT_FLAG_TXURERR :
+ reg1 = reg1 & SPI_STAT_TXURERR;
+ reg2 = reg2 & SPI_CTL1_ERRIE;
+ break;
+ /* SPI/I2S format error interrupt */
+ case SPI_I2S_INT_FLAG_FERR :
+ reg1 = reg1 & SPI_STAT_FERR;
+ reg2 = reg2 & SPI_CTL1_ERRIE;
+ break;
+ default :
+ break;
+ }
+ /*get SPI/I2S interrupt flag status */
+ if(reg1 && reg2){
+ return SET;
+ }else{
+ return RESET;
+ }
+}
+
+/*!
+ \brief get SPI and I2S flag status
+ \param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
+ \param[in] spi_i2s_flag: SPI/I2S flag status
+ \arg SPI_FLAG_TBE: transmit buffer empty flag
+ \arg SPI_FLAG_RBNE: receive buffer not empty flag
+ \arg SPI_FLAG_TRANS: transmit on-going flag
+ \arg SPI_FLAG_RXORERR: receive overrun error flag
+ \arg SPI_FLAG_CONFERR: mode config error flag
+ \arg SPI_FLAG_CRCERR: CRC error flag
+ \arg SPI_FLAG_FERR: format error flag
+ \arg I2S_FLAG_TBE: transmit buffer empty flag
+ \arg I2S_FLAG_RBNE: receive buffer not empty flag
+ \arg I2S_FLAG_TRANS: transmit on-going flag
+ \arg I2S_FLAG_RXORERR: overrun error flag
+ \arg I2S_FLAG_TXURERR: underrun error flag
+ \arg I2S_FLAG_CH: channel side flag
+ \arg I2S_FLAG_FERR: format error flag
+ \param[out] none
+ \retval FlagStatus: SET or RESET
+*/
+FlagStatus spi_i2s_flag_get(uint32_t spi_periph, uint32_t spi_i2s_flag)
+{
+ if(SPI_STAT(spi_periph) & spi_i2s_flag){
+ return SET;
+ }else{
+ return RESET;
+ }
+}
+
+/*!
+ \brief clear SPI CRC error flag status
+ \param[in] spi_periph: SPIx(x=0,1,2,3,4,5)
+ \param[out] none
+ \retval none
+*/
+void spi_crc_error_clear(uint32_t spi_periph)
+{
+ SPI_STAT(spi_periph) &= (uint32_t)(~SPI_FLAG_CRCERR);
+}
+
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_syscfg.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_syscfg.c
index d834462aba..6fa0a776d0 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_syscfg.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_syscfg.c
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_syscfg.c
- \brief SYSCFG driver
+ \file gd32f4xx_syscfg.c
+ \brief SYSCFG driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#include "gd32f4xx_syscfg.h"
@@ -24,8 +49,9 @@ void syscfg_deinit(void)
}
/*!
- \brief configure the boot mode
+ \brief configure the boot mode
\param[in] syscfg_bootmode: selects the memory remapping
+ only one parameter can be selected which is shown as below:
\arg SYSCFG_BOOTMODE_FLASH: main flash memory (0x08000000~0x083BFFFF) is mapped at address 0x00000000
\arg SYSCFG_BOOTMODE_BOOTLOADER: boot loader (0x1FFF0000 - 0x1FFF77FF) is mapped at address 0x00000000
\arg SYSCFG_BOOTMODE_EXMC_SRAM: SRAM/NOR 0 and 1 of EXMC (0x60000000~0x67FFFFFF) is mapped at address 0x00000000
@@ -44,6 +70,7 @@ void syscfg_bootmode_config(uint8_t syscfg_bootmode)
/*!
\brief FMC memory mapping swap
\param[in] syscfg_fmc_swap: selects the interal flash bank swapping
+ only one parameter can be selected which is shown as below:
\arg SYSCFG_FMC_SWP_BANK0: bank 0 is mapped at address 0x08000000 and bank 1 is mapped at address 0x08100000
\arg SYSCFG_FMC_SWP_BANK1: bank 1 is mapped at address 0x08000000 and bank 0 is mapped at address 0x08100000
\param[out] none
@@ -61,6 +88,7 @@ void syscfg_fmc_swap_config(uint32_t syscfg_fmc_swap)
/*!
\brief EXMC memory mapping swap
\param[in] syscfg_exmc_swap: selects the memories in EXMC swapping
+ only one parameter can be selected which is shown as below:
\arg SYSCFG_EXMC_SWP_ENABLE: SDRAM bank 0 and bank 1 are swapped with NAND bank 1 and PC card
\arg SYSCFG_EXMC_SWP_DISABLE: no memory mapping swap
\param[out] none
@@ -79,8 +107,10 @@ void syscfg_exmc_swap_config(uint32_t syscfg_exmc_swap)
/*!
\brief configure the GPIO pin as EXTI Line
\param[in] exti_port: specify the GPIO port used in EXTI
+ only one parameter can be selected which is shown as below:
\arg EXTI_SOURCE_GPIOx(x = A,B,C,D,E,F,G,H,I): EXTI GPIO port
\param[in] exti_pin: specify the EXTI line
+ only one parameter can be selected which is shown as below:
\arg EXTI_SOURCE_PINx(x = 0..15): EXTI GPIO pin
\param[out] none
\retval none
@@ -123,15 +153,16 @@ void syscfg_exti_line_config(uint8_t exti_port, uint8_t exti_pin)
/*!
\brief configure the PHY interface for the ethernet MAC
\param[in] syscfg_enet_phy_interface: specifies the media interface mode.
+ only one parameter can be selected which is shown as below:
\arg SYSCFG_ENET_PHY_MII: MII mode is selected
- \arg SYSCFG_ENET_PHY_RMII: RMII mode is selected
+ \arg SYSCFG_ENET_PHY_RMII: RMII mode is selected
\param[out] none
\retval none
*/
void syscfg_enet_phy_interface_config(uint32_t syscfg_enet_phy_interface)
-{
+{
uint32_t reg;
-
+
reg = SYSCFG_CFG1;
/* reset the ENET_PHY_SEL bit and set according to syscfg_enet_phy_interface */
reg &= ~SYSCFG_CFG1_ENET_PHY_SEL;
@@ -141,12 +172,13 @@ void syscfg_enet_phy_interface_config(uint32_t syscfg_enet_phy_interface)
/*!
\brief configure the I/O compensation cell
\param[in] syscfg_compensation: specifies the I/O compensation cell mode
+ only one parameter can be selected which is shown as below:
\arg SYSCFG_COMPENSATION_ENABLE: I/O compensation cell is enabled
\arg SYSCFG_COMPENSATION_DISABLE: I/O compensation cell is disabled
\param[out] none
\retval none
*/
-void syscfg_compensation_config(uint32_t syscfg_compensation)
+void syscfg_compensation_config(uint32_t syscfg_compensation)
{
uint32_t reg;
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_timer.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_timer.c
index 04c8fab0d3..e312680222 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_timer.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_timer.c
@@ -1,14 +1,40 @@
/*!
- \file gd32f4xx_timer.c
- \brief TIMER driver
+ \file gd32f4xx_timer.c
+ \brief TIMER driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
+
#include "gd32f4xx_timer.h"
/*!
@@ -96,9 +122,26 @@ void timer_deinit(uint32_t timer_periph)
}
/*!
+ \brief initialize TIMER init parameter struct with a default value
+ \param[in] initpara: init parameter struct
+ \param[out] none
+ \retval none
+*/
+void timer_struct_para_init(timer_parameter_struct* initpara)
+{
+ /* initialize the init parameter struct member with the default value */
+ initpara->prescaler = 0U;
+ initpara->alignedmode = TIMER_COUNTER_EDGE;
+ initpara->counterdirection = TIMER_COUNTER_UP;
+ initpara->period = 65535U;
+ initpara->clockdivision = TIMER_CKDIV_DIV1;
+ initpara->repetitioncounter = 0U;
+}
+
+/*!
\brief initialize TIMER counter
\param[in] timer_periph: TIMERx(x=0..13)
- \param[in] timer_initpara: init parameter struct
+ \param[in] initpara: init parameter struct
prescaler: prescaler value of the counter clock,0~65535
alignedmode: TIMER_COUNTER_EDGE,TIMER_COUNTER_CENTER_DOWN,TIMER_COUNTER_CENTER_UP,TIMER_COUNTER_CENTER_BOTH
counterdirection: TIMER_COUNTER_UP,TIMER_COUNTER_DOWN
@@ -108,31 +151,31 @@ void timer_deinit(uint32_t timer_periph)
\param[out] none
\retval none
*/
-void timer_init(uint32_t timer_periph, timer_parameter_struct* timer_initpara)
+void timer_init(uint32_t timer_periph, timer_parameter_struct* initpara)
{
/* configure the counter prescaler value */
- TIMER_PSC(timer_periph) = (uint16_t)timer_initpara->prescaler;
+ TIMER_PSC(timer_periph) = (uint16_t)initpara->prescaler;
/* configure the counter direction and aligned mode */
if((TIMER0 == timer_periph) || (TIMER1 == timer_periph) || (TIMER2 == timer_periph)
|| (TIMER3 == timer_periph) || (TIMER4 == timer_periph) || (TIMER7 == timer_periph)){
TIMER_CTL0(timer_periph) &= ~(uint32_t)(TIMER_CTL0_DIR|TIMER_CTL0_CAM);
- TIMER_CTL0(timer_periph) |= (uint32_t)timer_initpara->alignedmode;
- TIMER_CTL0(timer_periph) |= (uint32_t)timer_initpara->counterdirection;
+ TIMER_CTL0(timer_periph) |= (uint32_t)initpara->alignedmode;
+ TIMER_CTL0(timer_periph) |= (uint32_t)initpara->counterdirection;
}
/* configure the autoreload value */
- TIMER_CAR(timer_periph) = (uint32_t)timer_initpara->period;
+ TIMER_CAR(timer_periph) = (uint32_t)initpara->period;
if((TIMER5 != timer_periph) && (TIMER6 != timer_periph)){
/* reset the CKDIV bit */
TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_CKDIV;
- TIMER_CTL0(timer_periph) |= (uint32_t)timer_initpara->clockdivision;
+ TIMER_CTL0(timer_periph) |= (uint32_t)initpara->clockdivision;
}
if((TIMER0 == timer_periph) || (TIMER7 == timer_periph)){
/* configure the repetition counter value */
- TIMER_CREP(timer_periph) = (uint32_t)timer_initpara->repetitioncounter;
+ TIMER_CREP(timer_periph) = (uint32_t)initpara->repetitioncounter;
}
/* generate an update event */
@@ -208,7 +251,8 @@ void timer_update_event_disable(uint32_t timer_periph)
/*!
\brief set TIMER counter alignment mode
\param[in] timer_periph: TIMERx(x=0..4,7)
- \param[in] timer_aligned:
+ \param[in] aligned:
+ only one parameter can be selected which is shown as below:
\arg TIMER_COUNTER_EDGE: edge-aligned mode
\arg TIMER_COUNTER_CENTER_DOWN: center-aligned and counting down assert mode
\arg TIMER_COUNTER_CENTER_UP: center-aligned and counting up assert mode
@@ -216,10 +260,10 @@ void timer_update_event_disable(uint32_t timer_periph)
\param[out] none
\retval none
*/
-void timer_counter_alignment(uint32_t timer_periph,uint16_t timer_aligned)
+void timer_counter_alignment(uint32_t timer_periph, uint16_t aligned)
{
TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_CAM;
- TIMER_CTL0(timer_periph) |= (uint32_t)timer_aligned;
+ TIMER_CTL0(timer_periph) |= (uint32_t)aligned;
}
/*!
@@ -247,18 +291,19 @@ void timer_counter_down_direction(uint32_t timer_periph)
/*!
\brief configure TIMER prescaler
\param[in] timer_periph: TIMERx(x=0..13)
- \param[in] timer_prescaler: prescaler value
- \param[in] timer_pscreload: prescaler reload mode
+ \param[in] prescaler: prescaler value,0~65535
+ \param[in] pscreload: prescaler reload mode
+ only one parameter can be selected which is shown as below:
\arg TIMER_PSC_RELOAD_NOW: the prescaler is loaded right now
\arg TIMER_PSC_RELOAD_UPDATE: the prescaler is loaded at the next update event
\param[out] none
\retval none
*/
-void timer_prescaler_config(uint32_t timer_periph,uint16_t timer_prescaler,uint8_t timer_pscreload)
+void timer_prescaler_config(uint32_t timer_periph, uint16_t prescaler, uint8_t pscreload)
{
- TIMER_PSC(timer_periph) = (uint32_t)timer_prescaler;
-
- if(TIMER_PSC_RELOAD_NOW == timer_pscreload){
+ TIMER_PSC(timer_periph) = (uint32_t)prescaler;
+
+ if(TIMER_PSC_RELOAD_NOW == pscreload){
TIMER_SWEVG(timer_periph) |= (uint32_t)TIMER_SWEVG_UPG;
}
}
@@ -266,37 +311,37 @@ void timer_prescaler_config(uint32_t timer_periph,uint16_t timer_prescaler,uint8
/*!
\brief configure TIMER repetition register value
\param[in] timer_periph: TIMERx(x=0,7)
- \param[in] timer_repetition: the counter repetition value,0~255
+ \param[in] repetition: the counter repetition value,0~255
\param[out] none
\retval none
*/
-void timer_repetition_value_config(uint32_t timer_periph,uint16_t timer_repetition)
+void timer_repetition_value_config(uint32_t timer_periph, uint16_t repetition)
{
- TIMER_CREP(timer_periph) = (uint32_t)timer_repetition;
-}
-
+ TIMER_CREP(timer_periph) = (uint32_t)repetition;
+}
+
/*!
\brief configure TIMER autoreload register value
\param[in] timer_periph: TIMERx(x=0..13)
- \param[in] timer_autoreload: the counter auto-reload value
+ \param[in] autoreload: the counter auto-reload value
\param[out] none
\retval none
-*/
-void timer_autoreload_value_config(uint32_t timer_periph,uint32_t timer_autoreload)
+*/
+void timer_autoreload_value_config(uint32_t timer_periph,uint32_t autoreload)
{
- TIMER_CAR(timer_periph) = (uint32_t)timer_autoreload;
+ TIMER_CAR(timer_periph) = (uint32_t)autoreload;
}
/*!
\brief configure TIMER counter register value
\param[in] timer_periph: TIMERx(x=0..13)
- \param[in] timer_counter: the counter value
+ \param[in] counter: the counter value,0~65535
\param[out] none
\retval none
-*/
-void timer_counter_value_config(uint32_t timer_periph , uint32_t timer_counter)
+*/
+void timer_counter_value_config(uint32_t timer_periph , uint32_t counter)
{
- TIMER_CNT(timer_periph) = (uint32_t)timer_counter;
+ TIMER_CNT(timer_periph) = (uint32_t)counter;
}
/*!
@@ -304,7 +349,7 @@ void timer_counter_value_config(uint32_t timer_periph , uint32_t timer_counter)
\param[in] timer_periph: TIMERx(x=0..13)
\param[out] none
\retval counter value
-*/
+*/
uint32_t timer_counter_read(uint32_t timer_periph)
{
uint32_t count_value = 0U;
@@ -317,56 +362,61 @@ uint32_t timer_counter_read(uint32_t timer_periph)
\param[in] timer_periph: TIMERx(x=0..13)
\param[out] none
\retval prescaler register value
-*/
+*/
uint16_t timer_prescaler_read(uint32_t timer_periph)
{
uint16_t prescaler_value = 0U;
- prescaler_value = (uint16_t)(TIMER_CAR(timer_periph));
+ prescaler_value = (uint16_t)(TIMER_PSC(timer_periph));
return (prescaler_value);
}
/*!
\brief configure TIMER single pulse mode
\param[in] timer_periph: TIMERx(x=0..8,11)
- \param[in] timer_spmode:
+ \param[in] spmode:
+ only one parameter can be selected which is shown as below:
\arg TIMER_SP_MODE_SINGLE: single pulse mode
\arg TIMER_SP_MODE_REPETITIVE: repetitive pulse mode
\param[out] none
\retval none
*/
-void timer_single_pulse_mode_config(uint32_t timer_periph,uint8_t timer_spmode)
+void timer_single_pulse_mode_config(uint32_t timer_periph, uint32_t spmode)
{
- if(TIMER_SP_MODE_SINGLE == timer_spmode){
+ if(TIMER_SP_MODE_SINGLE == spmode){
TIMER_CTL0(timer_periph) |= (uint32_t)TIMER_CTL0_SPM;
- }else if(TIMER_SP_MODE_REPETITIVE == timer_spmode){
+ }else if(TIMER_SP_MODE_REPETITIVE == spmode){
TIMER_CTL0(timer_periph) &= ~((uint32_t)TIMER_CTL0_SPM);
}else{
+ /* illegal parameters */
}
}
/*!
- \brief configure TIMER update source
+ \brief configure TIMER update source
\param[in] timer_periph: TIMERx(x=0..13)
- \param[in] timer_update:
+ \param[in] update:
+ only one parameter can be selected which is shown as below:
\arg TIMER_UPDATE_SRC_GLOBAL: update generate by setting of UPG bit or the counter overflow/underflow,or the slave mode controller trigger
\arg TIMER_UPDATE_SRC_REGULAR: update generate only by counter overflow/underflow
\param[out] none
\retval none
*/
-void timer_update_source_config(uint32_t timer_periph,uint8_t timer_update)
+void timer_update_source_config(uint32_t timer_periph, uint32_t update)
{
- if(TIMER_UPDATE_SRC_REGULAR == timer_update){
+ if(TIMER_UPDATE_SRC_REGULAR == update){
TIMER_CTL0(timer_periph) |= (uint32_t)TIMER_CTL0_UPS;
- }else if(timer_update == TIMER_UPDATE_SRC_GLOBAL){
+ }else if(TIMER_UPDATE_SRC_GLOBAL == update){
TIMER_CTL0(timer_periph) &= ~(uint32_t)TIMER_CTL0_UPS;
}else{
+ /* illegal parameters */
}
}
/*!
\brief enable the TIMER interrupt
- \param[in] timer_periph: please refer to the following parameters
- \param[in] timer_interrupt: timer interrupt enable source
+ \param[in] timer_periph: please refer to the following parameters
+ \param[in] interrupt: timer interrupt enable source
+ only one parameter can be selected which is shown as below:
\arg TIMER_INT_UP: update interrupt enable, TIMERx(x=0..13)
\arg TIMER_INT_CH0: channel 0 interrupt enable, TIMERx(x=0..4,7..13)
\arg TIMER_INT_CH1: channel 1 interrupt enable, TIMERx(x=0..4,7,8,11)
@@ -378,15 +428,16 @@ void timer_update_source_config(uint32_t timer_periph,uint8_t timer_update)
\param[out] none
\retval none
*/
-void timer_interrupt_enable(uint32_t timer_periph,uint32_t timer_interrupt)
+void timer_interrupt_enable(uint32_t timer_periph, uint32_t interrupt)
{
- TIMER_DMAINTEN(timer_periph) |= (uint32_t) timer_interrupt;
+ TIMER_DMAINTEN(timer_periph) |= (uint32_t) interrupt;
}
/*!
\brief disable the TIMER interrupt
\param[in] timer_periph: please refer to the following parameters
- \param[in] timer_interrupt: timer interrupt source enable
+ \param[in] interrupt: timer interrupt source enable
+ only one parameter can be selected which is shown as below:
\arg TIMER_INT_UP: update interrupt enable, TIMERx(x=0..13)
\arg TIMER_INT_CH0: channel 0 interrupt enable, TIMERx(x=0..4,7..13)
\arg TIMER_INT_CH1: channel 1 interrupt enable, TIMERx(x=0..4,7,8,11)
@@ -398,31 +449,32 @@ void timer_interrupt_enable(uint32_t timer_periph,uint32_t timer_interrupt)
\param[out] none
\retval none
*/
-void timer_interrupt_disable(uint32_t timer_periph,uint32_t timer_interrupt)
+void timer_interrupt_disable(uint32_t timer_periph, uint32_t interrupt)
{
- TIMER_DMAINTEN(timer_periph) &= (~(uint32_t)timer_interrupt);
+ TIMER_DMAINTEN(timer_periph) &= (~(uint32_t)interrupt);
}
/*!
\brief get timer interrupt flag
\param[in] timer_periph: please refer to the following parameters
- \param[in] timer_interrupt: the timer interrupt bits
- \arg TIMER_INT_UP: update interrupt flag,TIMERx(x=0..13)
- \arg TIMER_INT_CH0: channel 0 interrupt flag,TIMERx(x=0..4,7..13)
- \arg TIMER_INT_CH1: channel 1 interrupt flag,TIMERx(x=0..4,7,8,11)
- \arg TIMER_INT_CH2: channel 2 interrupt flag,TIMERx(x=0..4,7)
- \arg TIMER_INT_CH3: channel 3 interrupt flag,TIMERx(x=0..4,7)
- \arg TIMER_INT_CMT: channel commutation interrupt flag,TIMERx(x=0,7)
- \arg TIMER_INT_TRG: trigger interrupt flag,TIMERx(x=0,7,8,11)
- \arg TIMER_INT_BRK: break interrupt flag,TIMERx(x=0,7)
+ \param[in] interrupt: the timer interrupt bits
+ only one parameter can be selected which is shown as below:
+ \arg TIMER_INT_FLAG_UP: update interrupt flag,TIMERx(x=0..13)
+ \arg TIMER_INT_FLAG_CH0: channel 0 interrupt flag,TIMERx(x=0..4,7..13)
+ \arg TIMER_INT_FLAG_CH1: channel 1 interrupt flag,TIMERx(x=0..4,7,8,11)
+ \arg TIMER_INT_FLAG_CH2: channel 2 interrupt flag,TIMERx(x=0..4,7)
+ \arg TIMER_INT_FLAG_CH3: channel 3 interrupt flag,TIMERx(x=0..4,7)
+ \arg TIMER_INT_FLAG_CMT: channel commutation interrupt flag,TIMERx(x=0,7)
+ \arg TIMER_INT_FLAG_TRG: trigger interrupt flag,TIMERx(x=0,7,8,11)
+ \arg TIMER_INT_FLAG_BRK: break interrupt flag,TIMERx(x=0,7)
\param[out] none
\retval FlagStatus: SET or RESET
*/
-FlagStatus timer_interrupt_flag_get(uint32_t timer_periph,uint32_t timer_interrupt)
+FlagStatus timer_interrupt_flag_get(uint32_t timer_periph, uint32_t interrupt)
{
uint32_t val;
- val = (TIMER_DMAINTEN(timer_periph) & timer_interrupt);
- if((RESET != (TIMER_INTF(timer_periph) & timer_interrupt) ) && (RESET != val)){
+ val = (TIMER_DMAINTEN(timer_periph) & interrupt);
+ if((RESET != (TIMER_INTF(timer_periph) & interrupt) ) && (RESET != val)){
return SET;
}else{
return RESET;
@@ -432,34 +484,36 @@ FlagStatus timer_interrupt_flag_get(uint32_t timer_periph,uint32_t timer_interru
/*!
\brief clear TIMER interrupt flag
\param[in] timer_periph: please refer to the following parameters
- \param[in] timer_interrupt: the timer interrupt bits
- \arg TIMER_INT_UP: update interrupt flag,TIMERx(x=0..13)
- \arg TIMER_INT_CH0: channel 0 interrupt flag,TIMERx(x=0..4,7..13)
- \arg TIMER_INT_CH1: channel 1 interrupt flag,TIMERx(x=0..4,7,8,11)
- \arg TIMER_INT_CH2: channel 2 interrupt flag,TIMERx(x=0..4,7)
- \arg TIMER_INT_CH3: channel 3 interrupt flag,TIMERx(x=0..4,7)
- \arg TIMER_INT_CMT: channel commutation interrupt flag,TIMERx(x=0,7)
- \arg TIMER_INT_TRG: trigger interrupt flag,TIMERx(x=0,7,8,11)
- \arg TIMER_INT_BRK: break interrupt flag,TIMERx(x=0,7)
+ \param[in] interrupt: the timer interrupt bits
+ only one parameter can be selected which is shown as below:
+ \arg TIMER_INT_FLAG_UP: update interrupt flag,TIMERx(x=0..13)
+ \arg TIMER_INT_FLAG_CH0: channel 0 interrupt flag,TIMERx(x=0..4,7..13)
+ \arg TIMER_INT_FLAG_CH1: channel 1 interrupt flag,TIMERx(x=0..4,7,8,11)
+ \arg TIMER_INT_FLAG_CH2: channel 2 interrupt flag,TIMERx(x=0..4,7)
+ \arg TIMER_INT_FLAG_CH3: channel 3 interrupt flag,TIMERx(x=0..4,7)
+ \arg TIMER_INT_FLAG_CMT: channel commutation interrupt flag,TIMERx(x=0,7)
+ \arg TIMER_INT_FLAG_TRG: trigger interrupt flag,TIMERx(x=0,7,8,11)
+ \arg TIMER_INT_FLAG_BRK: break interrupt flag,TIMERx(x=0,7)
\param[out] none
\retval none
*/
-void timer_interrupt_flag_clear(uint32_t timer_periph,uint32_t timer_interrupt)
+void timer_interrupt_flag_clear(uint32_t timer_periph, uint32_t interrupt)
{
- TIMER_INTF(timer_periph) &= (~(uint32_t)timer_interrupt);
+ TIMER_INTF(timer_periph) = (~(uint32_t)interrupt);
}
/*!
\brief get TIMER flags
\param[in] timer_periph: please refer to the following parameters
- \param[in] timer_flag: the timer interrupt flags
+ \param[in] flag: the timer interrupt flags
+ only one parameter can be selected which is shown as below:
\arg TIMER_FLAG_UP: update flag,TIMERx(x=0..13)
\arg TIMER_FLAG_CH0: channel 0 flag,TIMERx(x=0..4,7..13)
\arg TIMER_FLAG_CH1: channel 1 flag,TIMERx(x=0..4,7,8,11)
\arg TIMER_FLAG_CH2: channel 2 flag,TIMERx(x=0..4,7)
\arg TIMER_FLAG_CH3: channel 3 flag,TIMERx(x=0..4,7)
- \arg TIMER_FLAG_CMT: channel control update flag,TIMERx(x=0,7)
- \arg TIMER_FLAG_TRG: trigger flag,TIMERx(x=0,7,8,11)
+ \arg TIMER_FLAG_CMT: channel control update flag,TIMERx(x=0,7)
+ \arg TIMER_FLAG_TRG: trigger flag,TIMERx(x=0,7,8,11)
\arg TIMER_FLAG_BRK: break flag,TIMERx(x=0,7)
\arg TIMER_FLAG_CH0OF: channel 0 overcapture flag,TIMERx(x=0..4,7..11)
\arg TIMER_FLAG_CH1OF: channel 1 overcapture flag,TIMERx(x=0..4,7,8,11)
@@ -468,9 +522,9 @@ void timer_interrupt_flag_clear(uint32_t timer_periph,uint32_t timer_interrupt)
\param[out] none
\retval FlagStatus: SET or RESET
*/
-FlagStatus timer_flag_get(uint32_t timer_periph , uint32_t timer_flag)
+FlagStatus timer_flag_get(uint32_t timer_periph, uint32_t flag)
{
- if(RESET != (TIMER_INTF(timer_periph) & timer_flag)){
+ if(RESET != (TIMER_INTF(timer_periph) & flag)){
return SET;
}else{
return RESET;
@@ -480,14 +534,15 @@ FlagStatus timer_flag_get(uint32_t timer_periph , uint32_t timer_flag)
/*!
\brief clear TIMER flags
\param[in] timer_periph: please refer to the following parameters
- \param[in] timer_flag: the timer interrupt flags
+ \param[in] flag: the timer interrupt flags
+ only one parameter can be selected which is shown as below:
\arg TIMER_FLAG_UP: update flag,TIMERx(x=0..13)
\arg TIMER_FLAG_CH0: channel 0 flag,TIMERx(x=0..4,7..13)
\arg TIMER_FLAG_CH1: channel 1 flag,TIMERx(x=0..4,7,8,11)
\arg TIMER_FLAG_CH2: channel 2 flag,TIMERx(x=0..4,7)
\arg TIMER_FLAG_CH3: channel 3 flag,TIMERx(x=0..4,7)
- \arg TIMER_FLAG_CMT: channel control update flag,TIMERx(x=0,7)
- \arg TIMER_FLAG_TRG: trigger flag,TIMERx(x=0,7,8,11)
+ \arg TIMER_FLAG_CMT: channel control update flag,TIMERx(x=0,7)
+ \arg TIMER_FLAG_TRG: trigger flag,TIMERx(x=0,7,8,11)
\arg TIMER_FLAG_BRK: break flag,TIMERx(x=0,7)
\arg TIMER_FLAG_CH0OF: channel 0 overcapture flag,TIMERx(x=0..4,7..11)
\arg TIMER_FLAG_CH1OF: channel 1 overcapture flag,TIMERx(x=0..4,7,8,11)
@@ -496,72 +551,77 @@ FlagStatus timer_flag_get(uint32_t timer_periph , uint32_t timer_flag)
\param[out] none
\retval none
*/
-void timer_flag_clear(uint32_t timer_periph , uint32_t timer_flag)
+void timer_flag_clear(uint32_t timer_periph, uint32_t flag)
{
- TIMER_INTF(timer_periph) &= (~(uint32_t)timer_flag);
+ TIMER_INTF(timer_periph) = (~(uint32_t)flag);
}
/*!
\brief enable the TIMER DMA
- \param[in] timer_periph: TIMERx(x=0,1,2,5,14,15,16)
- \param[in] timer_dma: timer DMA source enable
- \arg TIMER_DMA_UPD: update DMA enable,TIMERx(x=0..7)
- \arg TIMER_DMA_CH0D: channel 0 DMA enable,TIMERx(x=0..4,7)
- \arg TIMER_DMA_CH1D: channel 1 DMA enable,TIMERx(x=0..4,7)
- \arg TIMER_DMA_CH2D: channel 2 DMA enable,TIMERx(x=0..4,7)
- \arg TIMER_DMA_CH3D: channel 3 DMA enable,TIMERx(x=0..4,7)
- \arg TIMER_DMA_CMTD: commutation DMA request enable,TIMERx(x=0,7)
- \arg TIMER_DMA_TRGD: trigger DMA enable,TIMERx(x=0..4,7)
+ \param[in] timer_periph: please refer to the following parameters
+ \param[in] dma: specify which DMA to enable
+ one or more parameters can be selected which is shown as below:
+ \arg TIMER_DMA_UPD: update DMA,TIMERx(x=0..7)
+ \arg TIMER_DMA_CH0D: channel 0 DMA request,TIMERx(x=0..4,7)
+ \arg TIMER_DMA_CH1D: channel 1 DMA request,TIMERx(x=0..4,7)
+ \arg TIMER_DMA_CH2D: channel 2 DMA request,TIMERx(x=0..4,7)
+ \arg TIMER_DMA_CH3D: channel 3 DMA request,TIMERx(x=0..4,7)
+ \arg TIMER_DMA_CMTD: commutation DMA request,TIMERx(x=0,7)
+ \arg TIMER_DMA_TRGD: trigger DMA request,TIMERx(x=0..4,7)
\param[out] none
\retval none
*/
-void timer_dma_enable(uint32_t timer_periph,uint16_t timer_dma)
+void timer_dma_enable(uint32_t timer_periph, uint16_t dma)
{
- TIMER_DMAINTEN(timer_periph) |= (uint32_t) timer_dma;
+ TIMER_DMAINTEN(timer_periph) |= (uint32_t) dma;
}
/*!
\brief disable the TIMER DMA
\param[in] timer_periph: please refer to the following parameters
- \param[in] timer_dma: timer DMA source enable
- \arg TIMER_DMA_UPD: update DMA enable,TIMERx(x=0..7)
- \arg TIMER_DMA_CH0D: channel 0 DMA enable,TIMERx(x=0..4,7)
- \arg TIMER_DMA_CH1D: channel 1 DMA enable,TIMERx(x=0..4,7)
- \arg TIMER_DMA_CH2D: channel 2 DMA enable,TIMERx(x=0..4,7)
- \arg TIMER_DMA_CH3D: channel 3 DMA enable,TIMERx(x=0..4,7)
- \arg TIMER_DMA_CMTD: commutation DMA request enable,TIMERx(x=0,7)
- \arg TIMER_DMA_TRGD: trigger DMA enable,TIMERx(x=0..4,7)
+ \param[in] dma: specify which DMA to disable
+ one or more parameters can be selected which are shown as below:
+ \arg TIMER_DMA_UPD: update DMA,TIMERx(x=0..7)
+ \arg TIMER_DMA_CH0D: channel 0 DMA request,TIMERx(x=0..4,7)
+ \arg TIMER_DMA_CH1D: channel 1 DMA request,TIMERx(x=0..4,7)
+ \arg TIMER_DMA_CH2D: channel 2 DMA request,TIMERx(x=0..4,7)
+ \arg TIMER_DMA_CH3D: channel 3 DMA request,TIMERx(x=0..4,7)
+ \arg TIMER_DMA_CMTD: commutation DMA request ,TIMERx(x=0,7)
+ \arg TIMER_DMA_TRGD: trigger DMA request,TIMERx(x=0..4,7)
\param[out] none
\retval none
*/
-void timer_dma_disable(uint32_t timer_periph,uint16_t timer_dma)
+void timer_dma_disable(uint32_t timer_periph, uint16_t dma)
{
- TIMER_DMAINTEN(timer_periph) &= (~(uint32_t)(timer_dma));
+ TIMER_DMAINTEN(timer_periph) &= (~(uint32_t)(dma));
}
/*!
\brief channel DMA request source selection
\param[in] timer_periph: TIMERx(x=0..4,7)
\param[in] dma_request: channel DMA request source selection
+ only one parameter can be selected which is shown as below:
\arg TIMER_DMAREQUEST_CHANNELEVENT: DMA request of channel y is sent when channel y event occurs
- \arg TIMER_DMAREQUEST_UPDATEEVENT: DMA request of channel y is sent when update event occurs
+ \arg TIMER_DMAREQUEST_UPDATEEVENT: DMA request of channel y is sent when update event occurs
\param[out] none
\retval none
*/
-void timer_channel_dma_request_source_select(uint32_t timer_periph,uint8_t dma_request)
+void timer_channel_dma_request_source_select(uint32_t timer_periph, uint8_t dma_request)
{
if(TIMER_DMAREQUEST_UPDATEEVENT == dma_request){
TIMER_CTL1(timer_periph) |= (uint32_t)TIMER_CTL1_DMAS;
}else if(TIMER_DMAREQUEST_CHANNELEVENT == dma_request){
TIMER_CTL1(timer_periph) &= ~(uint32_t)TIMER_CTL1_DMAS;
}else{
+ /* illegal parameters */
}
}
/*!
\brief configure the TIMER DMA transfer
\param[in] timer_periph: please refer to the following parameters
- \param[in] dma_baseaddr:
+ \param[in] dma_baseaddr:
+ only one parameter can be selected which is shown as below:
\arg TIMER_DMACFG_DMATA_CTL0: DMA transfer address is TIMER_CTL0,TIMERx(x=0..4,7)
\arg TIMER_DMACFG_DMATA_CTL1: DMA transfer address is TIMER_CTL1,TIMERx(x=0..4,7)
\arg TIMER_DMACFG_DMATA_SMCFG: DMA transfer address is TIMER_SMCFG,TIMERx(x=0..4,7)
@@ -579,44 +639,64 @@ void timer_channel_dma_request_source_select(uint32_t timer_periph,uint8_t dma_r
\arg TIMER_DMACFG_DMATA_CH1CV: DMA transfer address is TIMER_CH1CV,TIMERx(x=0..4,7)
\arg TIMER_DMACFG_DMATA_CH2CV: DMA transfer address is TIMER_CH2CV,TIMERx(x=0..4,7)
\arg TIMER_DMACFG_DMATA_CH3CV: DMA transfer address is TIMER_CH3CV,TIMERx(x=0..4,7)
- \arg TIMER_DMACFG_DMATA_CCHP: DMA transfer address is TIMER_CCHP,TIMERx(x=0,7)
+ \arg TIMER_DMACFG_DMATA_CCHP: DMA transfer address is TIMER_CCHP,TIMERx(x=0..4,7)
\arg TIMER_DMACFG_DMATA_DMACFG: DMA transfer address is TIMER_DMACFG,TIMERx(x=0..4,7)
\arg TIMER_DMACFG_DMATA_DMATB: DMA transfer address is TIMER_DMATB,TIMERx(x=0..4,7)
\param[in] dma_lenth:
+ only one parameter can be selected which is shown as below:
\arg TIMER_DMACFG_DMATC_xTRANSFER(x=1..18): DMA transfer x time
\param[out] none
\retval none
*/
-void timer_dma_transfer_config(uint32_t timer_periph,uint32_t dma_baseaddr,uint32_t dma_lenth)
+void timer_dma_transfer_config(uint32_t timer_periph, uint32_t dma_baseaddr, uint32_t dma_lenth)
{
TIMER_DMACFG(timer_periph) &= (~(uint32_t)(TIMER_DMACFG_DMATA | TIMER_DMACFG_DMATC));
TIMER_DMACFG(timer_periph) |= (uint32_t)(dma_baseaddr | dma_lenth);
}
/*!
- \brief software generate events
+ \brief software generate events
\param[in] timer_periph: please refer to the following parameters
- \param[in] timer_event: the timer software event generation sources
+ \param[in] event: the timer software event generation sources
+ one or more parameters can be selected which are shown as below:
\arg TIMER_EVENT_SRC_UPG: update event,TIMERx(x=0..13)
- \arg TIMER_EVENT_SRC_CH0G: channel 0 capture or compare event generation,TIMERx(x=0..4,7..13)
+ \arg TIMER_EVENT_SRC_CH0G: channel 0 capture or compare event generation,TIMERx(x=0..4,7..13)
\arg TIMER_EVENT_SRC_CH1G: channel 1 capture or compare event generation,TIMERx(x=0..4,7,8,11)
- \arg TIMER_EVENT_SRC_CH2G: channel 2 capture or compare event generation,TIMERx(x=0..4,7)
- \arg TIMER_EVENT_SRC_CH3G: channel 3 capture or compare event generation,TIMERx(x=0..4,7)
- \arg TIMER_EVENT_SRC_CMTG: channel commutation event generation,TIMERx(x=0,7)
+ \arg TIMER_EVENT_SRC_CH2G: channel 2 capture or compare event generation,TIMERx(x=0..4,7)
+ \arg TIMER_EVENT_SRC_CH3G: channel 3 capture or compare event generation,TIMERx(x=0..4,7)
+ \arg TIMER_EVENT_SRC_CMTG: channel commutation event generation,TIMERx(x=0,7)
\arg TIMER_EVENT_SRC_TRGG: trigger event generation,TIMERx(x=0..4,7,8,11)
\arg TIMER_EVENT_SRC_BRKG: break event generation,TIMERx(x=0,7)
\param[out] none
\retval none
*/
-void timer_event_software_generate(uint32_t timer_periph,uint16_t timer_event)
+void timer_event_software_generate(uint32_t timer_periph, uint16_t event)
{
- TIMER_SWEVG(timer_periph) |= (uint32_t)timer_event;
+ TIMER_SWEVG(timer_periph) |= (uint32_t)event;
}
/*!
- \brief configure TIMER break function
+ \brief initialize TIMER break parameter struct with a default value
+ \param[in] breakpara: TIMER break parameter struct
+ \param[out] none
+ \retval none
+*/
+void timer_break_struct_para_init(timer_break_parameter_struct* breakpara)
+{
+ /* initialize the break parameter struct member with the default value */
+ breakpara->runoffstate = TIMER_ROS_STATE_DISABLE;
+ breakpara->ideloffstate = TIMER_IOS_STATE_DISABLE;
+ breakpara->deadtime = 0U;
+ breakpara->breakpolarity = TIMER_BREAK_POLARITY_LOW;
+ breakpara->outputautostate = TIMER_OUTAUTO_DISABLE;
+ breakpara->protectmode = TIMER_CCHP_PROT_OFF;
+ breakpara->breakstate = TIMER_BREAK_DISABLE;
+}
+
+/*!
+ \brief configure TIMER break function
\param[in] timer_periph: TIMERx(x=0,7)
- \param[in] timer_bkdtpara: TIMER break parameter struct
+ \param[in] breakpara: TIMER break parameter struct
runoffstate: TIMER_ROS_STATE_ENABLE,TIMER_ROS_STATE_DISABLE
ideloffstate: TIMER_IOS_STATE_ENABLE,TIMER_IOS_STATE_DISABLE
deadtime: 0~255
@@ -627,15 +707,15 @@ void timer_event_software_generate(uint32_t timer_periph,uint16_t timer_event)
\param[out] none
\retval none
*/
-void timer_break_config(uint32_t timer_periph,timer_break_parameter_struct* timer_bkdtpara)
+void timer_break_config(uint32_t timer_periph, timer_break_parameter_struct* breakpara)
{
- TIMER_CCHP(timer_periph) = (uint32_t)(((uint32_t)(timer_bkdtpara->runoffstate))|
- ((uint32_t)(timer_bkdtpara->ideloffstate))|
- ((uint32_t)(timer_bkdtpara->deadtime))|
- ((uint32_t)(timer_bkdtpara->breakpolarity))|
- ((uint32_t)(timer_bkdtpara->outputautostate)) |
- ((uint32_t)(timer_bkdtpara->protectmode))|
- ((uint32_t)(timer_bkdtpara->breakstate))) ;
+ TIMER_CCHP(timer_periph) = (uint32_t)(((uint32_t)(breakpara->runoffstate))|
+ ((uint32_t)(breakpara->ideloffstate))|
+ ((uint32_t)(breakpara->deadtime))|
+ ((uint32_t)(breakpara->breakpolarity))|
+ ((uint32_t)(breakpara->outputautostate)) |
+ ((uint32_t)(breakpara->protectmode))|
+ ((uint32_t)(breakpara->breakstate))) ;
}
/*!
@@ -689,7 +769,7 @@ void timer_automatic_output_disable(uint32_t timer_periph)
\param[out] none
\retval none
*/
-void timer_primary_output_config(uint32_t timer_periph,ControlStatus newvalue)
+void timer_primary_output_config(uint32_t timer_periph, ControlStatus newvalue)
{
if(ENABLE == newvalue){
TIMER_CCHP(timer_periph) |= (uint32_t)TIMER_CCHP_POEN;
@@ -699,13 +779,13 @@ void timer_primary_output_config(uint32_t timer_periph,ControlStatus newvalue)
}
/*!
- \brief channel capture/compare control shadow register enable
+ \brief enable or disable channel capture/compare control shadow register
\param[in] timer_periph: TIMERx(x=0,7)
- \param[in] newvalue: ENABLE or DISABLE
+ \param[in] newvalue: ENABLE or DISABLE
\param[out] none
\retval none
*/
-void timer_channel_control_shadow_config(uint32_t timer_periph,ControlStatus newvalue)
+void timer_channel_control_shadow_config(uint32_t timer_periph, ControlStatus newvalue)
{
if(ENABLE == newvalue){
TIMER_CTL1(timer_periph) |= (uint32_t)TIMER_CTL1_CCSE;
@@ -717,31 +797,51 @@ void timer_channel_control_shadow_config(uint32_t timer_periph,ControlStatus new
/*!
\brief configure TIMER channel control shadow register update control
\param[in] timer_periph: TIMERx(x=0,7)
- \param[in] timer_ccuctl: channel control shadow register update control
+ \param[in] ccuctl: channel control shadow register update control
+ only one parameter can be selected which is shown as below:
\arg TIMER_UPDATECTL_CCU: the shadow registers update by when CMTG bit is set
- \arg TIMER_UPDATECTL_CCUTRI: the shadow registers update by when CMTG bit is set or an rising edge of TRGI occurs
+ \arg TIMER_UPDATECTL_CCUTRI: the shadow registers update by when CMTG bit is set or an rising edge of TRGI occurs
\param[out] none
\retval none
-*/
-void timer_channel_control_shadow_update_config(uint32_t timer_periph,uint8_t timer_ccuctl)
+*/
+void timer_channel_control_shadow_update_config(uint32_t timer_periph, uint8_t ccuctl)
{
- if(TIMER_UPDATECTL_CCU == timer_ccuctl){
+ if(TIMER_UPDATECTL_CCU == ccuctl){
TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_CCUC);
- }else if(TIMER_UPDATECTL_CCUTRI == timer_ccuctl){
+ }else if(TIMER_UPDATECTL_CCUTRI == ccuctl){
TIMER_CTL1(timer_periph) |= (uint32_t)TIMER_CTL1_CCUC;
}else{
+ /* illegal parameters */
}
}
/*!
+ \brief initialize TIMER channel output parameter struct with a default value
+ \param[in] ocpara: TIMER channel n output parameter struct
+ \param[out] none
+ \retval none
+*/
+void timer_channel_output_struct_para_init(timer_oc_parameter_struct* ocpara)
+{
+ /* initialize the channel output parameter struct member with the default value */
+ ocpara->outputstate = (uint16_t)TIMER_CCX_DISABLE;
+ ocpara->outputnstate = TIMER_CCXN_DISABLE;
+ ocpara->ocpolarity = TIMER_OC_POLARITY_HIGH;
+ ocpara->ocnpolarity = TIMER_OCN_POLARITY_HIGH;
+ ocpara->ocidlestate = TIMER_OC_IDLE_STATE_LOW;
+ ocpara->ocnidlestate = TIMER_OCN_IDLE_STATE_LOW;
+}
+
+/*!
\brief configure TIMER channel output function
\param[in] timer_periph: please refer to the following parameters
- \param[in] timer_channel:
+ \param[in] channel:
+ only one parameter can be selected which is shown as below:
\arg TIMER_CH_0: TIMER channel 0(TIMERx(x=0..4,7..13))
\arg TIMER_CH_1: TIMER channel 1(TIMERx(x=0..4,7,8,11))
\arg TIMER_CH_2: TIMER channel 2(TIMERx(x=0..4,7))
\arg TIMER_CH_3: TIMER channel 3(TIMERx(x=0..4,7))
- \param[in] timer_ocpara: TIMER channeln output parameter struct
+ \param[in] ocpara: TIMER channeln output parameter struct
outputstate: TIMER_CCX_ENABLE,TIMER_CCX_DISABLE
outputnstate: TIMER_CCXN_ENABLE,TIMER_CCXN_DISABLE
ocpolarity: TIMER_OC_POLARITY_HIGH,TIMER_OC_POLARITY_LOW
@@ -751,120 +851,120 @@ void timer_channel_control_shadow_update_config(uint32_t timer_periph,uint8_t ti
\param[out] none
\retval none
*/
-void timer_channel_output_config(uint32_t timer_periph,uint16_t timer_channel,timer_oc_parameter_struct* timer_ocpara)
+void timer_channel_output_config(uint32_t timer_periph, uint16_t channel, timer_oc_parameter_struct* ocpara)
{
- switch(timer_channel){
+ switch(channel){
/* configure TIMER_CH_0 */
case TIMER_CH_0:
/* reset the CH0EN bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0EN);
+ TIMER_CHCTL0(timer_periph) &= ~(uint32_t)TIMER_CHCTL0_CH0MS;
/* set the CH0EN bit */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)timer_ocpara->outputstate;
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)ocpara->outputstate;
/* reset the CH0P bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0P);
/* set the CH0P bit */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)timer_ocpara->ocpolarity;
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)ocpara->ocpolarity;
if((TIMER0 == timer_periph) || (TIMER7 == timer_periph)){
/* reset the CH0NEN bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0NEN);
/* set the CH0NEN bit */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)timer_ocpara->outputnstate;
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)ocpara->outputnstate;
/* reset the CH0NP bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0NP);
/* set the CH0NP bit */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)timer_ocpara->ocnpolarity;
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)ocpara->ocnpolarity;
/* reset the ISO0 bit */
TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_ISO0);
/* set the ISO0 bit */
- TIMER_CTL1(timer_periph) |= (uint32_t)timer_ocpara->ocidlestate;
+ TIMER_CTL1(timer_periph) |= (uint32_t)ocpara->ocidlestate;
/* reset the ISO0N bit */
TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_ISO0N);
/* set the ISO0N bit */
- TIMER_CTL1(timer_periph) |= (uint32_t)timer_ocpara->ocnidlestate;
+ TIMER_CTL1(timer_periph) |= (uint32_t)ocpara->ocnidlestate;
}
- TIMER_CHCTL0(timer_periph) &= ~(uint32_t)TIMER_CHCTL0_CH0MS;
break;
/* configure TIMER_CH_1 */
case TIMER_CH_1:
/* reset the CH1EN bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1EN);
+ TIMER_CHCTL0(timer_periph) &= ~(uint32_t)TIMER_CHCTL0_CH1MS;
/* set the CH1EN bit */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)(timer_ocpara->outputstate<< 4U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)ocpara->outputstate << 4U);
/* reset the CH1P bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1P);
/* set the CH1P bit */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(timer_ocpara->ocpolarity)<< 4U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocpolarity) << 4U);
if((TIMER0 == timer_periph) || (TIMER7 == timer_periph)){
/* reset the CH1NEN bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1NEN);
/* set the CH1NEN bit */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(timer_ocpara->outputnstate)<< 4U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->outputnstate) << 4U);
/* reset the CH1NP bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1NP);
/* set the CH1NP bit */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(timer_ocpara->ocnpolarity)<< 4U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocnpolarity) << 4U);
/* reset the ISO1 bit */
TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_ISO1);
/* set the ISO1 bit */
- TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(timer_ocpara->ocidlestate)<< 2U);
+ TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocidlestate) << 2U);
/* reset the ISO1N bit */
TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_ISO1N);
/* set the ISO1N bit */
- TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(timer_ocpara->ocnidlestate)<< 2U);
+ TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocnidlestate) << 2U);
}
- TIMER_CHCTL0(timer_periph) &= ~(uint32_t)TIMER_CHCTL0_CH1MS;
break;
/* configure TIMER_CH_2 */
case TIMER_CH_2:
/* reset the CH2EN bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH2EN);
+ TIMER_CHCTL1(timer_periph) &= ~(uint32_t)TIMER_CHCTL1_CH2MS;
/* set the CH2EN bit */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)(timer_ocpara->outputstate<< 8U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)ocpara->outputstate << 8U);
/* reset the CH2P bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH2P);
/* set the CH2P bit */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(timer_ocpara->ocpolarity)<< 8U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocpolarity) << 8U);
if((TIMER0 == timer_periph) || (TIMER7 == timer_periph)){
/* reset the CH2NEN bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH2NEN);
/* set the CH2NEN bit */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(timer_ocpara->outputnstate)<< 8U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->outputnstate) << 8U);
/* reset the CH2NP bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH2NP);
/* set the CH2NP bit */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(timer_ocpara->ocnpolarity)<< 8U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocnpolarity) << 8U);
/* reset the ISO2 bit */
TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_ISO2);
/* set the ISO2 bit */
- TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(timer_ocpara->ocidlestate)<< 4U);
+ TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocidlestate) << 4U);
/* reset the ISO2N bit */
TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_ISO2N);
/* set the ISO2N bit */
- TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(timer_ocpara->ocnidlestate)<< 4U);
+ TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocnidlestate) << 4U);
}
- TIMER_CHCTL1(timer_periph) &= ~(uint32_t)TIMER_CHCTL1_CH2MS;
break;
/* configure TIMER_CH_3 */
case TIMER_CH_3:
/* reset the CH3EN bit */
TIMER_CHCTL2(timer_periph) &=(~(uint32_t)TIMER_CHCTL2_CH3EN);
+ TIMER_CHCTL1(timer_periph) &= ~(uint32_t)TIMER_CHCTL1_CH3MS;
/* set the CH3EN bit */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)(timer_ocpara->outputstate<< 12U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)ocpara->outputstate << 12U);
/* reset the CH3P bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH3P);
/* set the CH3P bit */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(timer_ocpara->ocpolarity)<< 12U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocpolarity) << 12U);
if((TIMER0 == timer_periph) || (TIMER7 == timer_periph)){
/* reset the ISO3 bit */
TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_ISO3);
/* set the ISO3 bit */
- TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(timer_ocpara->ocidlestate)<< 6U);
+ TIMER_CTL1(timer_periph) |= (uint32_t)((uint32_t)(ocpara->ocidlestate) << 6U);
}
- TIMER_CHCTL1(timer_periph) &= ~(uint32_t)TIMER_CHCTL1_CH3MS;
break;
default:
break;
@@ -874,12 +974,14 @@ void timer_channel_output_config(uint32_t timer_periph,uint16_t timer_channel,ti
/*!
\brief configure TIMER channel output compare mode
\param[in] timer_periph: please refer to the following parameters
- \param[in] timer_channel:
+ \param[in] channel:
+ only one parameter can be selected which is shown as below:
\arg TIMER_CH_0: TIMER channel0(TIMERx(x=0..4,7..13))
\arg TIMER_CH_1: TIMER channel1(TIMERx(x=0..4,7,8,11))
\arg TIMER_CH_2: TIMER channel2(TIMERx(x=0..4,7))
\arg TIMER_CH_3: TIMER channel3(TIMERx(x=0..4,7))
- \param[in] timer_ocmode: channel output compare mode
+ \param[in] ocmode: channel output compare mode
+ only one parameter can be selected which is shown as below:
\arg TIMER_OC_MODE_TIMING: timing mode
\arg TIMER_OC_MODE_ACTIVE: active mode
\arg TIMER_OC_MODE_INACTIVE: inactive mode
@@ -891,28 +993,28 @@ void timer_channel_output_config(uint32_t timer_periph,uint16_t timer_channel,ti
\param[out] none
\retval none
*/
-void timer_channel_output_mode_config(uint32_t timer_periph,uint16_t timer_channel,uint16_t timer_ocmode)
+void timer_channel_output_mode_config(uint32_t timer_periph, uint16_t channel, uint16_t ocmode)
{
- switch(timer_channel){
+ switch(channel){
/* configure TIMER_CH_0 */
case TIMER_CH_0:
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0COMCTL);
- TIMER_CHCTL0(timer_periph) |= (uint32_t)timer_ocmode;
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)ocmode;
break;
/* configure TIMER_CH_1 */
case TIMER_CH_1:
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1COMCTL);
- TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(timer_ocmode)<< 8U);
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(ocmode) << 8U);
break;
/* configure TIMER_CH_2 */
case TIMER_CH_2:
TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH2COMCTL);
- TIMER_CHCTL1(timer_periph) |= (uint32_t)timer_ocmode;
+ TIMER_CHCTL1(timer_periph) |= (uint32_t)ocmode;
break;
/* configure TIMER_CH_3 */
case TIMER_CH_3:
TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH3COMCTL);
- TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)(timer_ocmode)<< 8U);
+ TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)(ocmode) << 8U);
break;
default:
break;
@@ -922,29 +1024,34 @@ void timer_channel_output_mode_config(uint32_t timer_periph,uint16_t timer_chann
/*!
\brief configure TIMER channel output pulse value
\param[in] timer_periph: please refer to the following parameters
- \param[in] timer_channel:
+ \param[in] channel:
+ only one parameter can be selected which is shown as below:
\arg TIMER_CH_0: TIMER channel0(TIMERx(x=0..4,7..13))
\arg TIMER_CH_1: TIMER channel1(TIMERx(x=0..4,7,8,11))
\arg TIMER_CH_2: TIMER channel2(TIMERx(x=0..4,7))
\arg TIMER_CH_3: TIMER channel3(TIMERx(x=0..4,7))
- \param[in] timer_pluse: channel output pulse value
+ \param[in] pulse: channel output pulse value,0~65535
\param[out] none
\retval none
*/
-void timer_channel_output_pulse_value_config(uint32_t timer_periph,uint16_t timer_channel,uint32_t timer_pluse)
+void timer_channel_output_pulse_value_config(uint32_t timer_periph, uint16_t channel, uint32_t pulse)
{
- switch(timer_channel){
+ switch(channel){
+ /* configure TIMER_CH_0 */
case TIMER_CH_0:
- TIMER_CH0CV(timer_periph) = (uint32_t)timer_pluse;
+ TIMER_CH0CV(timer_periph) = (uint32_t)pulse;
break;
+ /* configure TIMER_CH_1 */
case TIMER_CH_1:
- TIMER_CH1CV(timer_periph) = (uint32_t)timer_pluse;
+ TIMER_CH1CV(timer_periph) = (uint32_t)pulse;
break;
+ /* configure TIMER_CH_2 */
case TIMER_CH_2:
- TIMER_CH2CV(timer_periph) = (uint32_t)timer_pluse;
+ TIMER_CH2CV(timer_periph) = (uint32_t)pulse;
break;
+ /* configure TIMER_CH_3 */
case TIMER_CH_3:
- TIMER_CH3CV(timer_periph) = (uint32_t)timer_pluse;
+ TIMER_CH3CV(timer_periph) = (uint32_t)pulse;
break;
default:
break;
@@ -954,39 +1061,41 @@ void timer_channel_output_pulse_value_config(uint32_t timer_periph,uint16_t time
/*!
\brief configure TIMER channel output shadow function
\param[in] timer_periph: please refer to the following parameters
- \param[in] timer_channel:
+ \param[in] channel:
+ only one parameter can be selected which is shown as below:
\arg TIMER_CH_0: TIMER channel0(TIMERx(x=0..4,7..13))
\arg TIMER_CH_1: TIMER channel1(TIMERx(x=0..4,7,8,11))
\arg TIMER_CH_2: TIMER channel2(TIMERx(x=0..4,7))
\arg TIMER_CH_3: TIMER channel3(TIMERx(x=0..4,7))
- \param[in] timer_ocshadow: channel output shadow state
+ \param[in] ocshadow: channel output shadow state
+ only one parameter can be selected which is shown as below:
\arg TIMER_OC_SHADOW_ENABLE: channel output shadow state enable
\arg TIMER_OC_SHADOW_DISABLE: channel output shadow state disable
\param[out] none
\retval none
*/
-void timer_channel_output_shadow_config(uint32_t timer_periph,uint16_t timer_channel,uint16_t timer_ocshadow)
+void timer_channel_output_shadow_config(uint32_t timer_periph, uint16_t channel, uint16_t ocshadow)
{
- switch(timer_channel){
+ switch(channel){
/* configure TIMER_CH_0 */
case TIMER_CH_0:
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0COMSEN);
- TIMER_CHCTL0(timer_periph) |= (uint32_t)timer_ocshadow;
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)ocshadow;
break;
/* configure TIMER_CH_1 */
case TIMER_CH_1:
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1COMSEN);
- TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(timer_ocshadow) << 8U);
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(ocshadow) << 8U);
break;
/* configure TIMER_CH_2 */
case TIMER_CH_2:
TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH2COMSEN);
- TIMER_CHCTL1(timer_periph) |= (uint32_t)timer_ocshadow;
+ TIMER_CHCTL1(timer_periph) |= (uint32_t)ocshadow;
break;
/* configure TIMER_CH_3 */
case TIMER_CH_3:
TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH3COMSEN);
- TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)(timer_ocshadow) << 8U);
+ TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)(ocshadow) << 8U);
break;
default:
break;
@@ -996,39 +1105,41 @@ void timer_channel_output_shadow_config(uint32_t timer_periph,uint16_t timer_cha
/*!
\brief configure TIMER channel output fast function
\param[in] timer_periph: please refer to the following parameters
- \param[in] timer_channel:
+ \param[in] channel:
+ only one parameter can be selected which is shown as below:
\arg TIMER_CH_0: TIMER channel0(TIMERx(x=0..4,7..13))
\arg TIMER_CH_1: TIMER channel1(TIMERx(x=0..4,7,8,11))
\arg TIMER_CH_2: TIMER channel2(TIMERx(x=0..4,7))
\arg TIMER_CH_3: TIMER channel3(TIMERx(x=0..4,7))
- \param[in] timer_ocfast: channel output fast function
+ \param[in] ocfast: channel output fast function
+ only one parameter can be selected which is shown as below:
\arg TIMER_OC_FAST_ENABLE: channel output fast function enable
\arg TIMER_OC_FAST_DISABLE: channel output fast function disable
\param[out] none
\retval none
*/
-void timer_channel_output_fast_config(uint32_t timer_periph,uint16_t timer_channel,uint16_t timer_ocfast)
+void timer_channel_output_fast_config(uint32_t timer_periph, uint16_t channel, uint16_t ocfast)
{
- switch(timer_channel){
+ switch(channel){
/* configure TIMER_CH_0 */
case TIMER_CH_0:
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0COMFEN);
- TIMER_CHCTL0(timer_periph) |= (uint32_t)timer_ocfast;
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)ocfast;
break;
/* configure TIMER_CH_1 */
case TIMER_CH_1:
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1COMFEN);
- TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)timer_ocfast << 8U);
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)ocfast << 8U);
break;
/* configure TIMER_CH_2 */
case TIMER_CH_2:
TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH2COMFEN);
- TIMER_CHCTL1(timer_periph) |= (uint32_t)timer_ocfast;
+ TIMER_CHCTL1(timer_periph) |= (uint32_t)ocfast;
break;
/* configure TIMER_CH_3 */
case TIMER_CH_3:
TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH3COMFEN);
- TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)timer_ocfast << 8U);
+ TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)ocfast << 8U);
break;
default:
break;
@@ -1037,40 +1148,42 @@ void timer_channel_output_fast_config(uint32_t timer_periph,uint16_t timer_chann
/*!
\brief configure TIMER channel output clear function
- \param[in] timer_periph: TIMERx(x=0..4,7)
- \param[in] timer_channel:
- \arg TIMER_CH_0: TIMER channel0
- \arg TIMER_CH_1: TIMER channel1
- \arg TIMER_CH_2: TIMER channel2
- \arg TIMER_CH_3: TIMER channel3
- \param[in] timer_occlear: channel output clear function
+ \param[in] timer_periph: please refer to the following parameters
+ \param[in] channel:
+ only one parameter can be selected which is shown as below:
+ \arg TIMER_CH_0: TIMER channel0(TIMERx(x=0..4,7))
+ \arg TIMER_CH_1: TIMER channel1(TIMERx(x=0..4,7))
+ \arg TIMER_CH_2: TIMER channel2(TIMERx(x=0..4,7))
+ \arg TIMER_CH_3: TIMER channel3(TIMERx(x=0..4,7))
+ \param[in] occlear: channel output clear function
+ only one parameter can be selected which is shown as below:
\arg TIMER_OC_CLEAR_ENABLE: channel output clear function enable
\arg TIMER_OC_CLEAR_DISABLE: channel output clear function disable
\param[out] none
\retval none
*/
-void timer_channel_output_clear_config(uint32_t timer_periph,uint16_t timer_channel,uint16_t timer_occlear)
+void timer_channel_output_clear_config(uint32_t timer_periph, uint16_t channel, uint16_t occlear)
{
- switch(timer_channel){
+ switch(channel){
/* configure TIMER_CH_0 */
case TIMER_CH_0:
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0COMCEN);
- TIMER_CHCTL0(timer_periph) |= (uint32_t)timer_occlear;
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)occlear;
break;
/* configure TIMER_CH_1 */
case TIMER_CH_1:
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1COMCEN);
- TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)timer_occlear << 8U);
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)occlear << 8U);
break;
/* configure TIMER_CH_2 */
case TIMER_CH_2:
TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH2COMCEN);
- TIMER_CHCTL1(timer_periph) |= (uint32_t)timer_occlear;
+ TIMER_CHCTL1(timer_periph) |= (uint32_t)occlear;
break;
/* configure TIMER_CH_3 */
case TIMER_CH_3:
TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH3COMCEN);
- TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)timer_occlear << 8U);
+ TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)occlear << 8U);
break;
default:
break;
@@ -1078,41 +1191,43 @@ void timer_channel_output_clear_config(uint32_t timer_periph,uint16_t timer_chan
}
/*!
- \brief configure TIMER channel output polarity
+ \brief configure TIMER channel output polarity
\param[in] timer_periph: please refer to the following parameters
- \param[in] timer_channel:
+ \param[in] channel:
+ only one parameter can be selected which is shown as below:
\arg TIMER_CH_0: TIMER channel0(TIMERx(x=0..4,7..13))
\arg TIMER_CH_1: TIMER channel1(TIMERx(x=0..4,7,8,11))
\arg TIMER_CH_2: TIMER channel2(TIMERx(x=0..4,7))
\arg TIMER_CH_3: TIMER channel3(TIMERx(x=0..4,7))
- \param[in] timer_ocpolarity: channel output polarity
+ \param[in] ocpolarity: channel output polarity
+ only one parameter can be selected which is shown as below:
\arg TIMER_OC_POLARITY_HIGH: channel output polarity is high
\arg TIMER_OC_POLARITY_LOW: channel output polarity is low
\param[out] none
\retval none
*/
-void timer_channel_output_polarity_config(uint32_t timer_periph,uint16_t timer_channel,uint16_t timer_ocpolarity)
+void timer_channel_output_polarity_config(uint32_t timer_periph, uint16_t channel, uint16_t ocpolarity)
{
- switch(timer_channel){
+ switch(channel){
/* configure TIMER_CH_0 */
case TIMER_CH_0:
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0P);
- TIMER_CHCTL2(timer_periph) |= (uint32_t)timer_ocpolarity;
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)ocpolarity;
break;
/* configure TIMER_CH_1 */
case TIMER_CH_1:
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1P);
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)timer_ocpolarity << 4U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)ocpolarity << 4U);
break;
/* configure TIMER_CH_2 */
case TIMER_CH_2:
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH2P);
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)timer_ocpolarity << 8U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)ocpolarity << 8U);
break;
/* configure TIMER_CH_3 */
case TIMER_CH_3:
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH3P);
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)timer_ocpolarity << 12U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)ocpolarity << 12U);
break;
default:
break;
@@ -1120,35 +1235,37 @@ void timer_channel_output_polarity_config(uint32_t timer_periph,uint16_t timer_c
}
/*!
- \brief configure TIMER channel complementary output polarity
- \param[in] timer_periph: TIMERx(x=0,7)
- \param[in] timer_channel:
+ \brief configure TIMER channel complementary output polarity
+ \param[in] timer_periph: please refer to the following parameters
+ \param[in] channel:
+ only one parameter can be selected which is shown as below:
\arg TIMER_CH_0: TIMER channel0(TIMERx(x=0..4,7..13))
\arg TIMER_CH_1: TIMER channel1(TIMERx(x=0..4,7,8,11))
\arg TIMER_CH_2: TIMER channel2(TIMERx(x=0..4,7))
- \param[in] timer_ocnpolarity: channel complementary output polarity
+ \param[in] ocnpolarity: channel complementary output polarity
+ only one parameter can be selected which is shown as below:
\arg TIMER_OCN_POLARITY_HIGH: channel complementary output polarity is high
\arg TIMER_OCN_POLARITY_LOW: channel complementary output polarity is low
\param[out] none
\retval none
*/
-void timer_channel_complementary_output_polarity_config(uint32_t timer_periph,uint16_t timer_channel,uint16_t timer_ocnpolarity)
+void timer_channel_complementary_output_polarity_config(uint32_t timer_periph, uint16_t channel, uint16_t ocnpolarity)
{
- switch(timer_channel){
+ switch(channel){
/* configure TIMER_CH_0 */
case TIMER_CH_0:
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0NP);
- TIMER_CHCTL2(timer_periph) |= (uint32_t)timer_ocnpolarity;
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)ocnpolarity;
break;
/* configure TIMER_CH_1 */
case TIMER_CH_1:
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1NP);
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)timer_ocnpolarity << 4U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)ocnpolarity << 4U);
break;
/* configure TIMER_CH_2 */
case TIMER_CH_2:
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH2NP);
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)timer_ocnpolarity << 8U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)ocnpolarity << 8U);
break;
default:
break;
@@ -1158,39 +1275,41 @@ void timer_channel_complementary_output_polarity_config(uint32_t timer_periph,ui
/*!
\brief configure TIMER channel enable state
\param[in] timer_periph: please refer to the following parameters
- \param[in] timer_channel:
+ \param[in] channel:
+ only one parameter can be selected which is shown as below:
\arg TIMER_CH_0: TIMER channel0(TIMERx(x=0..4,7..13))
\arg TIMER_CH_1: TIMER channel1(TIMERx(x=0..4,7,8,11))
\arg TIMER_CH_2: TIMER channel2(TIMERx(x=0..4,7))
\arg TIMER_CH_3: TIMER channel3(TIMERx(x=0..4,7))
- \param[in] timer_state: TIMER channel enable state
- \arg TIMER_CCX_ENABLE: channel enable
- \arg TIMER_CCX_DISABLE: channel disable
+ \param[in] state: TIMER channel enable state
+ only one parameter can be selected which is shown as below:
+ \arg TIMER_CCX_ENABLE: channel enable
+ \arg TIMER_CCX_DISABLE: channel disable
\param[out] none
\retval none
*/
-void timer_channel_output_state_config(uint32_t timer_periph,uint16_t timer_channel,uint32_t timer_state)
+void timer_channel_output_state_config(uint32_t timer_periph, uint16_t channel, uint32_t state)
{
- switch(timer_channel){
+ switch(channel){
/* configure TIMER_CH_0 */
case TIMER_CH_0:
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0EN);
- TIMER_CHCTL2(timer_periph) |= (uint32_t)timer_state;
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)state;
break;
/* configure TIMER_CH_1 */
case TIMER_CH_1:
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1EN);
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)timer_state << 4U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)state << 4U);
break;
/* configure TIMER_CH_2 */
case TIMER_CH_2:
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH2EN);
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)timer_state << 8U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)state << 8U);
break;
/* configure TIMER_CH_3 */
case TIMER_CH_3:
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH3EN);
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)timer_state << 12U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)state << 12U);
break;
default:
break;
@@ -1200,33 +1319,35 @@ void timer_channel_output_state_config(uint32_t timer_periph,uint16_t timer_chan
/*!
\brief configure TIMER channel complementary output enable state
\param[in] timer_periph: TIMERx(x=0,7)
- \param[in] timer_channel:
+ \param[in] channel:
+ only one parameter can be selected which is shown as below:
\arg TIMER_CH_0: TIMER channel0
\arg TIMER_CH_1: TIMER channel1
\arg TIMER_CH_2: TIMER channel2
- \param[in] timer_ocnstate: TIMER channel complementary output enable state
- \arg TIMER_CCXN_ENABLE: channel complementary enable
- \arg TIMER_CCXN_DISABLE: channel complementary disable
+ \param[in] ocnstate: TIMER channel complementary output enable state
+ only one parameter can be selected which is shown as below:
+ \arg TIMER_CCXN_ENABLE: channel complementary enable
+ \arg TIMER_CCXN_DISABLE: channel complementary disable
\param[out] none
\retval none
*/
-void timer_channel_complementary_output_state_config(uint32_t timer_periph,uint16_t timer_channel,uint16_t timer_ocnstate)
+void timer_channel_complementary_output_state_config(uint32_t timer_periph, uint16_t channel, uint16_t ocnstate)
{
- switch(timer_channel){
+ switch(channel){
/* configure TIMER_CH_0 */
case TIMER_CH_0:
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0NEN);
- TIMER_CHCTL2(timer_periph) |= (uint32_t)timer_ocnstate;
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)ocnstate;
break;
/* configure TIMER_CH_1 */
case TIMER_CH_1:
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1NEN);
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)timer_ocnstate << 4U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)ocnstate << 4U);
break;
/* configure TIMER_CH_2 */
case TIMER_CH_2:
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH2NEN);
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)timer_ocnstate << 8U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)ocnstate << 8U);
break;
default:
break;
@@ -1234,14 +1355,30 @@ void timer_channel_complementary_output_state_config(uint32_t timer_periph,uint1
}
/*!
- \brief configure TIMER input capture parameter
+ \brief initialize TIMER channel input parameter struct with a default value
+ \param[in] icpara: TIMER channel intput parameter struct
+ \param[out] none
+ \retval none
+*/
+void timer_channel_input_struct_para_init(timer_ic_parameter_struct* icpara)
+{
+ /* initialize the channel input parameter struct member with the default value */
+ icpara->icpolarity = TIMER_IC_POLARITY_RISING;
+ icpara->icselection = TIMER_IC_SELECTION_DIRECTTI;
+ icpara->icprescaler = TIMER_IC_PSC_DIV1;
+ icpara->icfilter = 0U;
+}
+
+/*!
+ \brief configure TIMER input capture parameter
\param[in] timer_periph: please refer to the following parameters
- \param[in] timer_channel:
+ \param[in] channel:
+ only one parameter can be selected which is shown as below:
\arg TIMER_CH_0: TIMER channel0(TIMERx(x=0..4,7..13))
\arg TIMER_CH_1: TIMER channel1(TIMERx(x=0..4,7,8,11))
\arg TIMER_CH_2: TIMER channel2(TIMERx(x=0..4,7))
\arg TIMER_CH_3: TIMER channel3(TIMERx(x=0..4,7))
- \param[in] timer_icpara: TIMER channel intput parameter struct
+ \param[in] icpara: TIMER channel intput parameter struct
icpolarity: TIMER_IC_POLARITY_RISING,TIMER_IC_POLARITY_FALLING,TIMER_IC_POLARITY_BOTH_EDGE
icselection: TIMER_IC_SELECTION_DIRECTTI,TIMER_IC_SELECTION_INDIRECTTI,TIMER_IC_SELECTION_ITS
icprescaler: TIMER_IC_PSC_DIV1,TIMER_IC_PSC_DIV2,TIMER_IC_PSC_DIV4,TIMER_IC_PSC_DIV8
@@ -1249,9 +1386,9 @@ void timer_channel_complementary_output_state_config(uint32_t timer_periph,uint1
\param[out] none
\retval none
*/
-void timer_input_capture_config(uint32_t timer_periph,uint16_t timer_channel,timer_ic_parameter_struct* timer_icpara)
+void timer_input_capture_config(uint32_t timer_periph,uint16_t channel, timer_ic_parameter_struct* icpara)
{
- switch(timer_channel){
+ switch(channel){
/* configure TIMER_CH_0 */
case TIMER_CH_0:
/* reset the CH0EN bit */
@@ -1259,18 +1396,18 @@ void timer_input_capture_config(uint32_t timer_periph,uint16_t timer_channel,tim
/* reset the CH0P and CH0NP bits */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH0P | TIMER_CHCTL2_CH0NP));
- TIMER_CHCTL2(timer_periph) |= (uint32_t)(timer_icpara->icpolarity);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)(icpara->icpolarity);
/* reset the CH0MS bit */
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0MS);
- TIMER_CHCTL0(timer_periph) |= (uint32_t)(timer_icpara->icselection);
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)(icpara->icselection);
/* reset the CH0CAPFLT bit */
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0CAPFLT);
- TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(timer_icpara->icfilter) << 4U);
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(icpara->icfilter) << 4U);
/* set the CH0EN bit */
TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH0EN;
break;
-
+
/* configure TIMER_CH_1 */
case TIMER_CH_1:
/* reset the CH1EN bit */
@@ -1278,13 +1415,13 @@ void timer_input_capture_config(uint32_t timer_periph,uint16_t timer_channel,tim
/* reset the CH1P and CH1NP bits */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH1P | TIMER_CHCTL2_CH1NP));
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(timer_icpara->icpolarity)<< 4U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(icpara->icpolarity) << 4U);
/* reset the CH1MS bit */
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1MS);
- TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(timer_icpara->icselection)<< 8U);
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(icpara->icselection) << 8U);
/* reset the CH1CAPFLT bit */
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1CAPFLT);
- TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(timer_icpara->icfilter)<< 12U);
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(icpara->icfilter) << 12U);
/* set the CH1EN bit */
TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH1EN;
@@ -1296,15 +1433,15 @@ void timer_input_capture_config(uint32_t timer_periph,uint16_t timer_channel,tim
/* reset the CH2P and CH2NP bits */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH2P|TIMER_CHCTL2_CH2NP));
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(timer_icpara->icpolarity)<< 8U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(icpara->icpolarity) << 8U);
/* reset the CH2MS bit */
TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH2MS);
- TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)(timer_icpara->icselection));
+ TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)(icpara->icselection));
/* reset the CH2CAPFLT bit */
TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH2CAPFLT);
- TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)(timer_icpara->icfilter)<< 4U);
+ TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)(icpara->icfilter) << 4U);
/* set the CH2EN bit */
TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH2EN;
@@ -1316,15 +1453,15 @@ void timer_input_capture_config(uint32_t timer_periph,uint16_t timer_channel,tim
/* reset the CH3P bits */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH3P));
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(timer_icpara->icpolarity)<< 12U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(icpara->icpolarity) << 12U);
/* reset the CH3MS bit */
TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH3MS);
- TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)(timer_icpara->icselection)<< 8U);
+ TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)(icpara->icselection) << 8U);
/* reset the CH3CAPFLT bit */
TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH3CAPFLT);
- TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)(timer_icpara->icfilter)<< 12U);
+ TIMER_CHCTL1(timer_periph) |= (uint32_t)((uint32_t)(icpara->icfilter) << 12U);
/* set the CH3EN bit */
TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH3EN;
@@ -1333,18 +1470,20 @@ void timer_input_capture_config(uint32_t timer_periph,uint16_t timer_channel,tim
break;
}
/* configure TIMER channel input capture prescaler value */
- timer_channel_input_capture_prescaler_config(timer_periph,timer_channel,(uint16_t)(timer_icpara->icprescaler));
+ timer_channel_input_capture_prescaler_config(timer_periph, channel, (uint16_t)(icpara->icprescaler));
}
/*!
\brief configure TIMER channel input capture prescaler value
\param[in] timer_periph: please refer to the following parameters
- \param[in] timer_channel:
+ \param[in] channel:
+ only one parameter can be selected which is shown as below:
\arg TIMER_CH_0: TIMER channel0(TIMERx(x=0..4,7..13))
\arg TIMER_CH_1: TIMER channel1(TIMERx(x=0..4,7,8,11))
\arg TIMER_CH_2: TIMER channel2(TIMERx(x=0..4,7))
\arg TIMER_CH_3: TIMER channel3(TIMERx(x=0..4,7))
- \param[in] timer_prescaler: channel input capture prescaler value
+ \param[in] prescaler: channel input capture prescaler value
+ only one parameter can be selected which is shown as below:
\arg TIMER_IC_PSC_DIV1: no prescaler
\arg TIMER_IC_PSC_DIV2: divided by 2
\arg TIMER_IC_PSC_DIV4: divided by 4
@@ -1352,28 +1491,28 @@ void timer_input_capture_config(uint32_t timer_periph,uint16_t timer_channel,tim
\param[out] none
\retval none
*/
-void timer_channel_input_capture_prescaler_config(uint32_t timer_periph,uint16_t timer_channel,uint16_t timer_prescaler)
+void timer_channel_input_capture_prescaler_config(uint32_t timer_periph, uint16_t channel, uint16_t prescaler)
{
- switch(timer_channel){
+ switch(channel){
/* configure TIMER_CH_0 */
case TIMER_CH_0:
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0CAPPSC);
- TIMER_CHCTL0(timer_periph) |= (uint32_t)timer_prescaler;
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)prescaler;
break;
/* configure TIMER_CH_1 */
case TIMER_CH_1:
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1CAPPSC);
- TIMER_CHCTL0(timer_periph) |= ((uint32_t)timer_prescaler << 8U);
+ TIMER_CHCTL0(timer_periph) |= ((uint32_t)prescaler << 8U);
break;
/* configure TIMER_CH_2 */
case TIMER_CH_2:
TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH2CAPPSC);
- TIMER_CHCTL1(timer_periph) |= (uint32_t)timer_prescaler;
+ TIMER_CHCTL1(timer_periph) |= (uint32_t)prescaler;
break;
/* configure TIMER_CH_3 */
case TIMER_CH_3:
TIMER_CHCTL1(timer_periph) &= (~(uint32_t)TIMER_CHCTL1_CH3CAPPSC);
- TIMER_CHCTL1(timer_periph) |= ((uint32_t)timer_prescaler << 8U);
+ TIMER_CHCTL1(timer_periph) |= ((uint32_t)prescaler << 8U);
break;
default:
break;
@@ -1383,7 +1522,8 @@ void timer_channel_input_capture_prescaler_config(uint32_t timer_periph,uint16_t
/*!
\brief read TIMER channel capture compare register value
\param[in] timer_periph: please refer to the following parameters
- \param[in] timer_channel:
+ \param[in] channel:
+ only one parameter can be selected which is shown as below:
\arg TIMER_CH_0: TIMER channel0(TIMERx(x=0..4,7..13))
\arg TIMER_CH_1: TIMER channel1(TIMERx(x=0..4,7,8,11))
\arg TIMER_CH_2: TIMER channel2(TIMERx(x=0..4,7))
@@ -1391,20 +1531,24 @@ void timer_channel_input_capture_prescaler_config(uint32_t timer_periph,uint16_t
\param[out] none
\retval channel capture compare register value
*/
-uint32_t timer_channel_capture_value_register_read(uint32_t timer_periph,uint16_t timer_channel)
+uint32_t timer_channel_capture_value_register_read(uint32_t timer_periph, uint16_t channel)
{
uint32_t count_value = 0U;
- switch(timer_channel){
+ switch(channel){
+ /* read TIMER channel 0 capture compare register value */
case TIMER_CH_0:
count_value = TIMER_CH0CV(timer_periph);
break;
+ /* read TIMER channel 1 capture compare register value */
case TIMER_CH_1:
count_value = TIMER_CH1CV(timer_periph);
break;
+ /* read TIMER channel 2 capture compare register value */
case TIMER_CH_2:
count_value = TIMER_CH2CV(timer_periph);
break;
+ /* read TIMER channel 3 capture compare register value */
case TIMER_CH_3:
count_value = TIMER_CH3CV(timer_periph);
break;
@@ -1415,12 +1559,13 @@ uint32_t timer_channel_capture_value_register_read(uint32_t timer_periph,uint16_
}
/*!
- \brief configure TIMER input pwm capture function
+ \brief configure TIMER input pwm capture function
\param[in] timer_periph: TIMERx(x=0..4,7,8,11)
- \param[in] timer_channel:
+ \param[in] channel:
+ only one parameter can be selected which is shown as below:
\arg TIMER_CH_0: TIMER channel0
\arg TIMER_CH_1: TIMER channel1
- \param[in] timer_icpwm:TIMER channel intput pwm parameter struct
+ \param[in] icpwm:TIMER channel intput pwm parameter struct
icpolarity: TIMER_IC_POLARITY_RISING,TIMER_IC_POLARITY_FALLING
icselection: TIMER_IC_SELECTION_DIRECTTI,TIMER_IC_SELECTION_INDIRECTTI
icprescaler: TIMER_IC_PSC_DIV1,TIMER_IC_PSC_DIV2,TIMER_IC_PSC_DIV4,TIMER_IC_PSC_DIV8
@@ -1428,80 +1573,82 @@ uint32_t timer_channel_capture_value_register_read(uint32_t timer_periph,uint16_
\param[out] none
\retval none
*/
-void timer_input_pwm_capture_config(uint32_t timer_periph,uint16_t timer_channel,timer_ic_parameter_struct* timer_icpwm)
+void timer_input_pwm_capture_config(uint32_t timer_periph, uint16_t channel, timer_ic_parameter_struct* icpwm)
{
uint16_t icpolarity = 0x0U;
uint16_t icselection = 0x0U;
- if(TIMER_IC_POLARITY_RISING == timer_icpwm->icpolarity){
+ /* Set channel input polarity */
+ if(TIMER_IC_POLARITY_RISING == icpwm->icpolarity){
icpolarity = TIMER_IC_POLARITY_FALLING;
}else{
icpolarity = TIMER_IC_POLARITY_RISING;
}
- if(TIMER_IC_SELECTION_DIRECTTI == timer_icpwm->icselection){
+ /* Set channel input mode selection */
+ if(TIMER_IC_SELECTION_DIRECTTI == icpwm->icselection){
icselection = TIMER_IC_SELECTION_INDIRECTTI;
}else{
icselection = TIMER_IC_SELECTION_DIRECTTI;
}
- if(TIMER_CH_0 == timer_channel){
+ if(TIMER_CH_0 == channel){
/* reset the CH0EN bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0EN);
/* reset the CH0P and CH0NP bits */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH0P|TIMER_CHCTL2_CH0NP));
/* set the CH0P and CH0NP bits */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)(timer_icpwm->icpolarity);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)(icpwm->icpolarity);
/* reset the CH0MS bit */
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0MS);
/* set the CH0MS bit */
- TIMER_CHCTL0(timer_periph) |= (uint32_t)(timer_icpwm->icselection);
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)(icpwm->icselection);
/* reset the CH0CAPFLT bit */
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0CAPFLT);
/* set the CH0CAPFLT bit */
- TIMER_CHCTL0(timer_periph) |= ((uint32_t)(timer_icpwm->icfilter) << 4U);
+ TIMER_CHCTL0(timer_periph) |= ((uint32_t)(icpwm->icfilter) << 4U);
/* set the CH0EN bit */
TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH0EN;
/* configure TIMER channel input capture prescaler value */
- timer_channel_input_capture_prescaler_config(timer_periph,TIMER_CH_0,(uint16_t)(timer_icpwm->icprescaler));
+ timer_channel_input_capture_prescaler_config(timer_periph,TIMER_CH_0,(uint16_t)(icpwm->icprescaler));
/* reset the CH1EN bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1EN);
/* reset the CH1P and CH1NP bits */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH1P|TIMER_CHCTL2_CH1NP));
/* set the CH1P and CH1NP bits */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)icpolarity<< 4U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)icpolarity << 4U);
/* reset the CH1MS bit */
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1MS);
/* set the CH1MS bit */
- TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)icselection<< 8U);
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)icselection << 8U);
/* reset the CH1CAPFLT bit */
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1CAPFLT);
/* set the CH1CAPFLT bit */
- TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(timer_icpwm->icfilter)<< 12U);
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(icpwm->icfilter) << 12U);
/* set the CH1EN bit */
TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH1EN;
/* configure TIMER channel input capture prescaler value */
- timer_channel_input_capture_prescaler_config(timer_periph,TIMER_CH_1,(uint16_t)(timer_icpwm->icprescaler));
+ timer_channel_input_capture_prescaler_config(timer_periph,TIMER_CH_1,(uint16_t)(icpwm->icprescaler));
}else{
/* reset the CH1EN bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1EN);
/* reset the CH1P and CH1NP bits */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH1P|TIMER_CHCTL2_CH1NP));
/* set the CH1P and CH1NP bits */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(timer_icpwm->icpolarity)<< 4U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)(icpwm->icpolarity) << 4U);
/* reset the CH1MS bit */
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1MS);
/* set the CH1MS bit */
- TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(timer_icpwm->icselection)<< 8U);
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(icpwm->icselection) << 8U);
/* reset the CH1CAPFLT bit */
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1CAPFLT);
/* set the CH1CAPFLT bit */
- TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(timer_icpwm->icfilter)<< 12U);
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)(icpwm->icfilter) << 12U);
/* set the CH1EN bit */
TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH1EN;
/* configure TIMER channel input capture prescaler value */
- timer_channel_input_capture_prescaler_config(timer_periph,TIMER_CH_1,(uint16_t)(timer_icpwm->icprescaler));
+ timer_channel_input_capture_prescaler_config(timer_periph, TIMER_CH_1, (uint16_t)(icpwm->icprescaler));
/* reset the CH0EN bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH0EN);
@@ -1516,168 +1663,180 @@ void timer_input_pwm_capture_config(uint32_t timer_periph,uint16_t timer_channel
/* reset the CH0CAPFLT bit */
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0CAPFLT);
/* set the CH0CAPFLT bit */
- TIMER_CHCTL0(timer_periph) |= ((uint32_t)(timer_icpwm->icfilter) << 4U);
+ TIMER_CHCTL0(timer_periph) |= ((uint32_t)(icpwm->icfilter) << 4U);
/* set the CH0EN bit */
TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH0EN;
/* configure TIMER channel input capture prescaler value */
- timer_channel_input_capture_prescaler_config(timer_periph,TIMER_CH_0,(uint16_t)(timer_icpwm->icprescaler));
+ timer_channel_input_capture_prescaler_config(timer_periph, TIMER_CH_0, (uint16_t)(icpwm->icprescaler));
}
}
/*!
\brief configure TIMER hall sensor mode
\param[in] timer_periph: TIMERx(x=0..4,7)
- \param[in] timer_hallmode:
+ \param[in] hallmode:
+ only one parameter can be selected which is shown as below:
\arg TIMER_HALLINTERFACE_ENABLE: TIMER hall sensor mode enable
\arg TIMER_HALLINTERFACE_DISABLE: TIMER hall sensor mode disable
\param[out] none
\retval none
*/
-void timer_hall_mode_config(uint32_t timer_periph,uint8_t timer_hallmode)
+void timer_hall_mode_config(uint32_t timer_periph, uint32_t hallmode)
{
- if(TIMER_HALLINTERFACE_ENABLE == timer_hallmode){
+ if(TIMER_HALLINTERFACE_ENABLE == hallmode){
TIMER_CTL1(timer_periph) |= (uint32_t)TIMER_CTL1_TI0S;
- }else if(TIMER_HALLINTERFACE_DISABLE == timer_hallmode){
+ }else if(TIMER_HALLINTERFACE_DISABLE == hallmode){
TIMER_CTL1(timer_periph) &= ~(uint32_t)TIMER_CTL1_TI0S;
}else{
+ /* illegal parameters */
}
}
/*!
- \brief select TIMER input trigger source
- \param[in] timer_periph: TIMERx(x=0..4,7,8,11)
- \param[in] timer_intrigger:
- \arg TIMER_SMCFG_TRGSEL_ITI0: internal trigger 0
- \arg TIMER_SMCFG_TRGSEL_ITI1: internal trigger 1
- \arg TIMER_SMCFG_TRGSEL_ITI2: internal trigger 2
- \arg TIMER_SMCFG_TRGSEL_ITI3: internal trigger 3
- \arg TIMER_SMCFG_TRGSEL_CI0F_ED: TI0 Edge Detector
- \arg TIMER_SMCFG_TRGSEL_CI0FE0: filtered TIMER input 0
- \arg TIMER_SMCFG_TRGSEL_CI1FE1: filtered TIMER input 1
- \arg TIMER_SMCFG_TRGSEL_ETIFP: external trigger
+ \brief select TIMER input trigger source
+ \param[in] timer_periph: please refer to the following parameters
+ \param[in] intrigger:
+ only one parameter can be selected which is shown as below:
+ \arg TIMER_SMCFG_TRGSEL_ITI0: internal trigger 0(TIMERx(x=0..4,7,8,11))
+ \arg TIMER_SMCFG_TRGSEL_ITI1: internal trigger 1(TIMERx(x=0..4,7,8,11))
+ \arg TIMER_SMCFG_TRGSEL_ITI2: internal trigger 2(TIMERx(x=0..4,7,8,11))
+ \arg TIMER_SMCFG_TRGSEL_ITI3: internal trigger 3(TIMERx(x=0..4,7,8,11))
+ \arg TIMER_SMCFG_TRGSEL_CI0F_ED: TI0 edge detector(TIMERx(x=0..4,7,8,11))
+ \arg TIMER_SMCFG_TRGSEL_CI0FE0: filtered TIMER input 0(TIMERx(x=0..4,7,8,11))
+ \arg TIMER_SMCFG_TRGSEL_CI1FE1: filtered TIMER input 1(TIMERx(x=0..4,7,8,11))
+ \arg TIMER_SMCFG_TRGSEL_ETIFP: external trigger(TIMERx(x=0..4,7,8,11))
\param[out] none
\retval none
*/
-void timer_input_trigger_source_select(uint32_t timer_periph,uint32_t timer_intrigger)
+void timer_input_trigger_source_select(uint32_t timer_periph, uint32_t intrigger)
{
TIMER_SMCFG(timer_periph) &= (~(uint32_t)TIMER_SMCFG_TRGS);
- TIMER_SMCFG(timer_periph) |= (uint32_t)timer_intrigger;
+ TIMER_SMCFG(timer_periph) |= (uint32_t)intrigger;
}
/*!
- \brief select TIMER master mode output trigger source
+ \brief select TIMER master mode output trigger source
\param[in] timer_periph: TIMERx(x=0..7)
- \param[in] timer_outrigger:
- \arg TIMER_TRI_OUT_SRC_RESET: the UPG bit as trigger output
- \arg TIMER_TRI_OUT_SRC_ENABLE: the counter enable signal TIMER_CTL0_CEN as trigger output
- \arg TIMER_TRI_OUT_SRC_UPDATE: update event as trigger output
- \arg TIMER_TRI_OUT_SRC_CC0: a capture or a compare match occurred in channal0 as trigger output TRGO
- \arg TIMER_TRI_OUT_SRC_O0CPRE: O0CPRE as trigger output
- \arg TIMER_TRI_OUT_SRC_O1CPRE: O1CPRE as trigger output
- \arg TIMER_TRI_OUT_SRC_O2CPRE: O2CPRE as trigger output
- \arg TIMER_TRI_OUT_SRC_O3CPRE: O3CPRE as trigger output
+ \param[in] outrigger:
+ only one parameter can be selected which is shown as below:
+ \arg TIMER_TRI_OUT_SRC_RESET: the UPG bit as trigger output(TIMERx(x=0..7,9,10,12,13))
+ \arg TIMER_TRI_OUT_SRC_ENABLE: the counter enable signal TIMER_CTL0_CEN as trigger output(TIMERx(x=0..7,9,10,12,13))
+ \arg TIMER_TRI_OUT_SRC_UPDATE: update event as trigger output(TIMERx(x=0..7,9,10,12,13))
+ \arg TIMER_TRI_OUT_SRC_CH0: a capture or a compare match occurred in channal0 as trigger output TRGO(TIMERx(x=0..4,7,9,10,12,13))
+ \arg TIMER_TRI_OUT_SRC_O0CPRE: O0CPRE as trigger output(TIMERx(x=0..4,7,9,10,12,13))
+ \arg TIMER_TRI_OUT_SRC_O1CPRE: O1CPRE as trigger output(TIMERx(x=0..4,7))
+ \arg TIMER_TRI_OUT_SRC_O2CPRE: O2CPRE as trigger output(TIMERx(x=0..4,7))
+ \arg TIMER_TRI_OUT_SRC_O3CPRE: O3CPRE as trigger output(TIMERx(x=0..4,7))
\param[out] none
\retval none
*/
-void timer_master_output_trigger_source_select(uint32_t timer_periph,uint32_t timer_outrigger)
+void timer_master_output_trigger_source_select(uint32_t timer_periph, uint32_t outrigger)
{
TIMER_CTL1(timer_periph) &= (~(uint32_t)TIMER_CTL1_MMC);
- TIMER_CTL1(timer_periph) |= (uint32_t)timer_outrigger;
+ TIMER_CTL1(timer_periph) |= (uint32_t)outrigger;
}
/*!
- \brief select TIMER slave mode
+ \brief select TIMER slave mode
\param[in] timer_periph: TIMERx(x=0..4,7,8,11)
- \param[in] timer_slavemode:
- \arg TIMER_SLAVE_MODE_DISABLE: slave mode disable
- \arg TIMER_ENCODER_MODE0: encoder mode 0
- \arg TIMER_ENCODER_MODE1: encoder mode 1
- \arg TIMER_ENCODER_MODE2: encoder mode 2
- \arg TIMER_SLAVE_MODE_RESTART: restart mode
- \arg TIMER_SLAVE_MODE_PAUSE: pause mode
- \arg TIMER_SLAVE_MODE_EVENT: event mode
- \arg TIMER_SLAVE_MODE_EXTERNAL0: external clock mode 0.
+ \param[in] slavemode:
+ only one parameter can be selected which is shown as below:
+ \arg TIMER_SLAVE_MODE_DISABLE: slave mode disable(TIMERx(x=0..4,7,8,11))
+ \arg TIMER_ENCODER_MODE0: encoder mode 0(TIMERx(x=0..4,7))
+ \arg TIMER_ENCODER_MODE1: encoder mode 1(TIMERx(x=0..4,7))
+ \arg TIMER_ENCODER_MODE2: encoder mode 2(TIMERx(x=0..4,7))
+ \arg TIMER_SLAVE_MODE_RESTART: restart mode(TIMERx(x=0..4,7,8,11))
+ \arg TIMER_SLAVE_MODE_PAUSE: pause mode(TIMERx(x=0..4,7,8,11))
+ \arg TIMER_SLAVE_MODE_EVENT: event mode(TIMERx(x=0..4,7,8,11))
+ \arg TIMER_SLAVE_MODE_EXTERNAL0: external clock mode 0.(TIMERx(x=0..4,7,8,11))
\param[out] none
\retval none
*/
-void timer_slave_mode_select(uint32_t timer_periph,uint32_t timer_slavemode)
+void timer_slave_mode_select(uint32_t timer_periph, uint32_t slavemode)
{
TIMER_SMCFG(timer_periph) &= (~(uint32_t)TIMER_SMCFG_SMC);
- TIMER_SMCFG(timer_periph) |= (uint32_t)timer_slavemode;
+ TIMER_SMCFG(timer_periph) |= (uint32_t)slavemode;
}
/*!
- \brief configure TIMER master slave mode
+ \brief configure TIMER master slave mode
\param[in] timer_periph: TIMERx(x=0..4,7,8,11)
- \param[in] timer_masterslave:
+ \param[in] masterslave:
+ only one parameter can be selected which is shown as below:
\arg TIMER_MASTER_SLAVE_MODE_ENABLE: master slave mode enable
\arg TIMER_MASTER_SLAVE_MODE_DISABLE: master slave mode disable
\param[out] none
\retval none
-*/
-void timer_master_slave_mode_config(uint32_t timer_periph,uint8_t timer_masterslave)
+*/
+void timer_master_slave_mode_config(uint32_t timer_periph, uint32_t masterslave)
{
- if(TIMER_MASTER_SLAVE_MODE_ENABLE == timer_masterslave){
+ if(TIMER_MASTER_SLAVE_MODE_ENABLE == masterslave){
TIMER_SMCFG(timer_periph) |= (uint32_t)TIMER_SMCFG_MSM;
- }else if(TIMER_MASTER_SLAVE_MODE_DISABLE == timer_masterslave){
+ }else if(TIMER_MASTER_SLAVE_MODE_DISABLE == masterslave){
TIMER_SMCFG(timer_periph) &= ~(uint32_t)TIMER_SMCFG_MSM;
}else{
+ /* illegal parameters */
}
}
/*!
\brief configure TIMER external trigger input
\param[in] timer_periph: TIMERx(x=0..4,7)
- \param[in] timer_extprescaler:
+ \param[in] extprescaler:
+ only one parameter can be selected which is shown as below:
\arg TIMER_EXT_TRI_PSC_OFF: no divided
\arg TIMER_EXT_TRI_PSC_DIV2: divided by 2
\arg TIMER_EXT_TRI_PSC_DIV4: divided by 4
\arg TIMER_EXT_TRI_PSC_DIV8: divided by 8
- \param[in] timer_expolarity:
+ \param[in] extpolarity:
+ only one parameter can be selected which is shown as below:
\arg TIMER_ETP_FALLING: active low or falling edge active
\arg TIMER_ETP_RISING: active high or rising edge active
- \param[in] timer_extfilter: a value between 0 and 15
+ \param[in] extfilter: a value between 0 and 15
\param[out] none
\retval none
*/
-void timer_external_trigger_config(uint32_t timer_periph,uint32_t timer_extprescaler,
- uint32_t timer_expolarity,uint32_t timer_extfilter)
+void timer_external_trigger_config(uint32_t timer_periph, uint32_t extprescaler,
+ uint32_t extpolarity, uint32_t extfilter)
{
- TIMER_SMCFG(timer_periph) &= (~(uint32_t)(TIMER_SMCFG_ETP|TIMER_SMCFG_ETPSC|TIMER_SMCFG_ETFC));
- TIMER_SMCFG(timer_periph) |= (uint32_t)(timer_extprescaler|timer_expolarity);
- TIMER_SMCFG(timer_periph) |= (uint32_t)(timer_extfilter<< 8U);
+ TIMER_SMCFG(timer_periph) &= (~(uint32_t)(TIMER_SMCFG_ETP | TIMER_SMCFG_ETPSC | TIMER_SMCFG_ETFC));
+ TIMER_SMCFG(timer_periph) |= (uint32_t)(extprescaler | extpolarity);
+ TIMER_SMCFG(timer_periph) |= (uint32_t)(extfilter << 8U);
}
/*!
\brief configure TIMER quadrature decoder mode
\param[in] timer_periph: TIMERx(x=0..4,7,8,11)
- \param[in] timer_decomode:
+ \param[in] decomode:
+ only one parameter can be selected which is shown as below:
\arg TIMER_ENCODER_MODE0: counter counts on CI0FE0 edge depending on CI1FE1 level
\arg TIMER_ENCODER_MODE1: counter counts on CI1FE1 edge depending on CI0FE0 level
\arg TIMER_ENCODER_MODE2: counter counts on both CI0FE0 and CI1FE1 edges depending on the level of the other input
- \param[in] timer_ic0polarity:
+ \param[in] ic0polarity:
+ only one parameter can be selected which is shown as below:
\arg TIMER_IC_POLARITY_RISING: capture rising edge
\arg TIMER_IC_POLARITY_FALLING: capture falling edge
- \param[in] timer_ic1polarity:
+ \param[in] ic1polarity:
+ only one parameter can be selected which is shown as below:
\arg TIMER_IC_POLARITY_RISING: capture rising edge
\arg TIMER_IC_POLARITY_FALLING: capture falling edge
\param[out] none
\retval none
*/
-void timer_quadrature_decoder_mode_config(uint32_t timer_periph,uint32_t timer_decomode,
- uint16_t timer_ic0polarity,uint16_t timer_ic1polarity)
+void timer_quadrature_decoder_mode_config(uint32_t timer_periph, uint32_t decomode,
+ uint16_t ic0polarity, uint16_t ic1polarity)
{
TIMER_SMCFG(timer_periph) &= (~(uint32_t)TIMER_SMCFG_SMC);
- TIMER_SMCFG(timer_periph) |= (uint32_t)timer_decomode;
+ TIMER_SMCFG(timer_periph) |= (uint32_t)decomode;
TIMER_CHCTL0(timer_periph) &= (uint32_t)(((~(uint32_t)TIMER_CHCTL0_CH0MS))&((~(uint32_t)TIMER_CHCTL0_CH1MS)));
- TIMER_CHCTL0(timer_periph) |= (uint32_t)(TIMER_IC_SELECTION_DIRECTTI|((uint32_t)TIMER_IC_SELECTION_DIRECTTI<< 8U));
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)(TIMER_IC_SELECTION_DIRECTTI|((uint32_t)TIMER_IC_SELECTION_DIRECTTI << 8U));
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH0P|TIMER_CHCTL2_CH0NP));
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH1P|TIMER_CHCTL2_CH1NP));
- TIMER_CHCTL2(timer_periph) |= ((uint32_t)timer_ic0polarity|((uint32_t)timer_ic1polarity<< 4U));
+ TIMER_CHCTL2(timer_periph) |= ((uint32_t)ic0polarity|((uint32_t)ic1polarity << 4U));
}
/*!
@@ -1694,7 +1853,8 @@ void timer_internal_clock_config(uint32_t timer_periph)
/*!
\brief configure TIMER the internal trigger as external clock input
\param[in] timer_periph: TIMERx(x=0..4,7,8,11)
- \param[in] timer_intrigger:
+ \param[in] intrigger:
+ only one parameter can be selected which is shown as below:
\arg TIMER_SMCFG_TRGSEL_ITI0: internal trigger 0
\arg TIMER_SMCFG_TRGSEL_ITI1: internal trigger 1
\arg TIMER_SMCFG_TRGSEL_ITI2: internal trigger 2
@@ -1702,9 +1862,9 @@ void timer_internal_clock_config(uint32_t timer_periph)
\param[out] none
\retval none
*/
-void timer_internal_trigger_as_external_clock_config(uint32_t timer_periph, uint32_t timer_intrigger)
+void timer_internal_trigger_as_external_clock_config(uint32_t timer_periph, uint32_t intrigger)
{
- timer_input_trigger_source_select(timer_periph,timer_intrigger);
+ timer_input_trigger_source_select(timer_periph, intrigger);
TIMER_SMCFG(timer_periph) &= ~(uint32_t)TIMER_SMCFG_SMC;
TIMER_SMCFG(timer_periph) |= (uint32_t)TIMER_SLAVE_MODE_EXTERNAL0;
}
@@ -1712,35 +1872,37 @@ void timer_internal_trigger_as_external_clock_config(uint32_t timer_periph, uint
/*!
\brief configure TIMER the external trigger as external clock input
\param[in] timer_periph: TIMERx(x=0..4,7,8,11)
- \param[in] timer_extrigger:
- \arg TIMER_SMCFG_TRGSEL_CI0F_ED: TI0 Edge Detector
+ \param[in] extrigger:
+ only one parameter can be selected which is shown as below:
+ \arg TIMER_SMCFG_TRGSEL_CI0F_ED: TI0 edge detector
\arg TIMER_SMCFG_TRGSEL_CI0FE0: filtered TIMER input 0
\arg TIMER_SMCFG_TRGSEL_CI1FE1: filtered TIMER input 1
- \param[in] timer_expolarity:
- \arg TIMER_IC_POLARITY_RISING: active low or falling edge active
- \arg TIMER_IC_POLARITY_FALLING: active high or rising edge active
- \param[in] timer_extfilter: a value between 0 and 15
+ \param[in] extpolarity:
+ only one parameter can be selected which is shown as below:
+ \arg TIMER_IC_POLARITY_RISING: active high or rising edge active
+ \arg TIMER_IC_POLARITY_FALLING: active low or falling edge active
+ \param[in] extfilter: a value between 0 and 15
\param[out] none
\retval none
*/
-void timer_external_trigger_as_external_clock_config(uint32_t timer_periph,uint32_t timer_extrigger,
- uint16_t timer_expolarity,uint32_t timer_extfilter)
+void timer_external_trigger_as_external_clock_config(uint32_t timer_periph, uint32_t extrigger,
+ uint16_t extpolarity, uint32_t extfilter)
{
- if(TIMER_SMCFG_TRGSEL_CI1FE1 == timer_extrigger){
+ if(TIMER_SMCFG_TRGSEL_CI1FE1 == extrigger){
/* reset the CH1EN bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)TIMER_CHCTL2_CH1EN);
/* reset the CH1NP bit */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH1P|TIMER_CHCTL2_CH1NP));
/* set the CH1NP bit */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)timer_expolarity << 4U);
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)((uint32_t)extpolarity << 4U);
/* reset the CH1MS bit */
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1MS);
/* set the CH1MS bit */
- TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)TIMER_IC_SELECTION_DIRECTTI<< 8U);
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)((uint32_t)TIMER_IC_SELECTION_DIRECTTI << 8U);
/* reset the CH1CAPFLT bit */
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH1CAPFLT);
/* set the CH1CAPFLT bit */
- TIMER_CHCTL0(timer_periph) |= (uint32_t)(timer_extfilter<< 8U);
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)(extfilter << 12U);
/* set the CH1EN bit */
TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH1EN;
}else{
@@ -1749,7 +1911,7 @@ void timer_external_trigger_as_external_clock_config(uint32_t timer_periph,uint3
/* reset the CH0P and CH0NP bits */
TIMER_CHCTL2(timer_periph) &= (~(uint32_t)(TIMER_CHCTL2_CH0P|TIMER_CHCTL2_CH0NP));
/* set the CH0P and CH0NP bits */
- TIMER_CHCTL2(timer_periph) |= (uint32_t)timer_expolarity;
+ TIMER_CHCTL2(timer_periph) |= (uint32_t)extpolarity;
/* reset the CH0MS bit */
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0MS);
/* set the CH0MS bit */
@@ -1757,12 +1919,12 @@ void timer_external_trigger_as_external_clock_config(uint32_t timer_periph,uint3
/* reset the CH0CAPFLT bit */
TIMER_CHCTL0(timer_periph) &= (~(uint32_t)TIMER_CHCTL0_CH0CAPFLT);
/* reset the CH0CAPFLT bit */
- TIMER_CHCTL0(timer_periph) |= (uint32_t)timer_extfilter;
+ TIMER_CHCTL0(timer_periph) |= (uint32_t)(extfilter << 4U);
/* set the CH0EN bit */
TIMER_CHCTL2(timer_periph) |= (uint32_t)TIMER_CHCTL2_CH0EN;
}
/* select TIMER input trigger source */
- timer_input_trigger_source_select(timer_periph,timer_extrigger);
+ timer_input_trigger_source_select(timer_periph,extrigger);
/* reset the SMC bit */
TIMER_SMCFG(timer_periph) &= (~(uint32_t)TIMER_SMCFG_SMC);
/* set the SMC bit */
@@ -1772,23 +1934,25 @@ void timer_external_trigger_as_external_clock_config(uint32_t timer_periph,uint3
/*!
\brief configure TIMER the external clock mode0
\param[in] timer_periph: TIMERx(x=0..4,7,8,11)
- \param[in] timer_extprescaler:
+ \param[in] extprescaler:
+ only one parameter can be selected which is shown as below:
\arg TIMER_EXT_TRI_PSC_OFF: no divided
\arg TIMER_EXT_TRI_PSC_DIV2: divided by 2
\arg TIMER_EXT_TRI_PSC_DIV4: divided by 4
\arg TIMER_EXT_TRI_PSC_DIV8: divided by 8
- \param[in] timer_expolarity:
+ \param[in] extpolarity:
+ only one parameter can be selected which is shown as below:
\arg TIMER_ETP_FALLING: active low or falling edge active
\arg TIMER_ETP_RISING: active high or rising edge active
- \param[in] timer_extfilter: a value between 0 and 15
+ \param[in] extfilter: a value between 0 and 15
\param[out] none
\retval none
*/
-void timer_external_clock_mode0_config(uint32_t timer_periph,uint32_t timer_extprescaler,
- uint32_t timer_expolarity,uint32_t timer_extfilter)
+void timer_external_clock_mode0_config(uint32_t timer_periph, uint32_t extprescaler,
+ uint32_t extpolarity, uint32_t extfilter)
{
/* configure TIMER external trigger input */
- timer_external_trigger_config(timer_periph,timer_extprescaler,timer_expolarity,timer_extfilter);
+ timer_external_trigger_config(timer_periph, extprescaler, extpolarity, extfilter);
/* reset the SMC bit,TRGS bit */
TIMER_SMCFG(timer_periph) &= (~(uint32_t)(TIMER_SMCFG_SMC | TIMER_SMCFG_TRGS));
@@ -1799,23 +1963,25 @@ void timer_external_clock_mode0_config(uint32_t timer_periph,uint32_t timer_extp
/*!
\brief configure TIMER the external clock mode1
\param[in] timer_periph: TIMERx(x=0..4,7)
- \param[in] timer_extprescaler:
+ \param[in] extprescaler:
+ only one parameter can be selected which is shown as below:
\arg TIMER_EXT_TRI_PSC_OFF: no divided
\arg TIMER_EXT_TRI_PSC_DIV2: divided by 2
\arg TIMER_EXT_TRI_PSC_DIV4: divided by 4
\arg TIMER_EXT_TRI_PSC_DIV8: divided by 8
- \param[in] timer_expolarity:
+ \param[in] extpolarity:
+ only one parameter can be selected which is shown as below:
\arg TIMER_ETP_FALLING: active low or falling edge active
\arg TIMER_ETP_RISING: active high or rising edge active
- \param[in] timer_extfilter: a value between 0 and 15
+ \param[in] extfilter: a value between 0 and 15
\param[out] none
\retval none
*/
-void timer_external_clock_mode1_config(uint32_t timer_periph,uint32_t timer_extprescaler,
- uint32_t timer_expolarity,uint32_t timer_extfilter)
+void timer_external_clock_mode1_config(uint32_t timer_periph, uint32_t extprescaler,
+ uint32_t extpolarity, uint32_t extfilter)
{
/* configure TIMER external trigger input */
- timer_external_trigger_config(timer_periph,timer_extprescaler,timer_expolarity,timer_extfilter);
+ timer_external_trigger_config(timer_periph, extprescaler, extpolarity, extfilter);
TIMER_SMCFG(timer_periph) |= (uint32_t)TIMER_SMCFG_SMC1;
}
@@ -1832,9 +1998,10 @@ void timer_external_clock_mode1_disable(uint32_t timer_periph)
}
/*!
- \brief configure TIMER1 channel0 remap function
+ \brief configure TIMER channel remap function
\param[in] timer_periph: TIMERx(x=1,4,10)
- \param[in] timer_remap:
+ \param[in] remap:
+ only one parameter can be selected which is shown as below:
\arg TIMER1_ITI1_RMP_TIMER7_TRGO: timer1 internal trigger input1 remap to TIMER7_TRGO
\arg TIMER1_ITI1_RMP_ETHERNET_PTP: timer1 internal trigger input1 remap to ethernet PTP
\arg TIMER1_ITI1_RMP_USB_FS_SOF: timer1 internal trigger input1 remap to USB FS SOF
@@ -1842,51 +2009,55 @@ void timer_external_clock_mode1_disable(uint32_t timer_periph)
\arg TIMER4_CI3_RMP_GPIO: timer4 channel 3 input remap to GPIO pin
\arg TIMER4_CI3_RMP_IRC32K: timer4 channel 3 input remap to IRC32K
\arg TIMER4_CI3_RMP_LXTAL: timer4 channel 3 input remap to LXTAL
- \arg TIMER4_CI3_RMP_RTC_WAKEUP_INT: timer4 channel 3 input remap to RTC wakeup interrupt
+ \arg TIMER4_CI3_RMP_RTC_WAKEUP_INT: timer4 channel 3 input remap to RTC wakeup interrupt
\arg TIMER10_ITI1_RMP_GPIO: timer10 internal trigger input1 remap based on GPIO setting
\arg TIMER10_ITI1_RMP_RTC_HXTAL_DIV: timer10 internal trigger input1 remap HXTAL _DIV(clock used for RTC which is HXTAL clock divided by RTCDIV bits in RCU_CFG0 register)
\param[out] none
\retval none
*/
-void timer_channel_remap_config(uint32_t timer_periph,uint32_t timer_remap)
+void timer_channel_remap_config(uint32_t timer_periph, uint32_t remap)
{
- TIMER_IRMP(timer_periph) = (uint32_t)timer_remap;
+ TIMER_IRMP(timer_periph) = (uint32_t)remap;
}
/*!
\brief configure TIMER write CHxVAL register selection
\param[in] timer_periph: TIMERx(x=0,1,2,13,14,15,16)
- \param[in] timer_ccsel:
- \arg TIMER_CCSEL_DISABLE: no effect
- \arg TIMER_CCSEL_ENABLE: if write the CHxVAL register, the write value is same as the CHxVAL value, the write access ignored
+ \param[in] ccsel:
+ only one parameter can be selected which is shown as below:
+ \arg TIMER_CHVSEL_DISABLE: no effect
+ \arg TIMER_CHVSEL_ENABLE: when write the CHxVAL register, if the write value is same as the CHxVAL value, the write access is ignored
\param[out] none
\retval none
*/
-void timer_write_cc_register_config(uint32_t timer_periph, uint16_t timer_ccsel)
+void timer_write_chxval_register_config(uint32_t timer_periph, uint16_t ccsel)
{
- if(TIMER_CCSEL_ENABLE == timer_ccsel){
+ if(TIMER_CHVSEL_ENABLE == ccsel){
TIMER_CFG(timer_periph) |= (uint32_t)TIMER_CFG_CHVSEL;
- }else if(TIMER_CCSEL_DISABLE == timer_ccsel){
+ }else if(TIMER_CHVSEL_DISABLE == ccsel){
TIMER_CFG(timer_periph) &= ~(uint32_t)TIMER_CFG_CHVSEL;
}else{
+ /* illegal parameters */
}
}
/*!
\brief configure TIMER output value selection
\param[in] timer_periph: TIMERx(x=0,7)
- \param[in] timer_outsel:
+ \param[in] outsel:
+ only one parameter can be selected which is shown as below:
\arg TIMER_OUTSEL_DISABLE: no effect
\arg TIMER_OUTSEL_ENABLE: if POEN and IOS is 0, the output disabled
\param[out] none
\retval none
*/
-void timer_output_value_selection_config(uint32_t timer_periph, uint16_t timer_outsel)
+void timer_output_value_selection_config(uint32_t timer_periph, uint16_t outsel)
{
- if(TIMER_OUTSEL_ENABLE == timer_outsel){
+ if(TIMER_OUTSEL_ENABLE == outsel){
TIMER_CFG(timer_periph) |= (uint32_t)TIMER_CFG_OUTSEL;
- }else if(TIMER_OUTSEL_DISABLE == timer_outsel){
+ }else if(TIMER_OUTSEL_DISABLE == outsel){
TIMER_CFG(timer_periph) &= ~(uint32_t)TIMER_CFG_OUTSEL;
}else{
+ /* illegal parameters */
}
}
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_tli.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_tli.c
index dfa65744ba..9d719bb29b 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_tli.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_tli.c
@@ -1,18 +1,46 @@
/*!
- \file gd32f4xx_tli.c
- \brief TLI driver
+ \file gd32f4xx_tli.c
+ \brief TLI driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.1, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#include "gd32f4xx_tli.h"
+#define TLI_DEFAULT_VALUE 0x00000000U
+#define TLI_OPAQUE_VALUE 0x000000FFU
+
/*!
- \brief deinitialize TLI registers
+ \brief deinitialize TLI registers
\param[in] none
\param[out] none
\retval none
@@ -24,15 +52,57 @@ void tli_deinit(void)
}
/*!
- \brief initialize TLI display timing parameters
- \param[in] tli_struct: the data needed to initialize tli.
+ \brief initialize the parameters of TLI parameter structure with the default values, it is suggested
+ that call this function after a tli_parameter_struct structure is defined
+ \param[in] none
+ \param[out] tli_struct: the data needed to initialize TLI
synpsz_vpsz: size of the vertical synchronous pulse
synpsz_hpsz: size of the horizontal synchronous pulse
- backpsz_vbpsz: size of the vertical back porch plus synchronous pulse
+ backpsz_vbpsz: size of the vertical back porch plus synchronous pulse
backpsz_hbpsz: size of the horizontal back porch plus synchronous pulse
activesz_vasz: size of the vertical active area width plus back porch and synchronous pulse
activesz_hasz: size of the horizontal active area width plus back porch and synchronous pulse
- totalsz_vtsz: vertical total size of the display, including active area, back porch, synchronous
+ totalsz_vtsz: vertical total size of the display, including active area, back porch, synchronous
+ totalsz_htsz: vorizontal total size of the display, including active area, back porch, synchronous
+ backcolor_red: background value red
+ backcolor_green: background value green
+ backcolor_blue: background value blue
+ signalpolarity_hs: TLI_HSYN_ACTLIVE_LOW,TLI_HSYN_ACTLIVE_HIGHT
+ signalpolarity_vs: TLI_VSYN_ACTLIVE_LOW,TLI_VSYN_ACTLIVE_HIGHT
+ signalpolarity_de: TLI_DE_ACTLIVE_LOW,TLI_DE_ACTLIVE_HIGHT
+ signalpolarity_pixelck: TLI_PIXEL_CLOCK_TLI,TLI_PIXEL_CLOCK_INVERTEDTLI
+ \retval none
+*/
+void tli_struct_para_init(tli_parameter_struct *tli_struct)
+{
+ /* initialize the struct parameters with default values */
+ tli_struct->synpsz_vpsz = TLI_DEFAULT_VALUE;
+ tli_struct->synpsz_hpsz = TLI_DEFAULT_VALUE;
+ tli_struct->backpsz_vbpsz = TLI_DEFAULT_VALUE;
+ tli_struct->backpsz_hbpsz = TLI_DEFAULT_VALUE;
+ tli_struct->activesz_vasz = TLI_DEFAULT_VALUE;
+ tli_struct->activesz_hasz = TLI_DEFAULT_VALUE;
+ tli_struct->totalsz_vtsz = TLI_DEFAULT_VALUE;
+ tli_struct->totalsz_htsz = TLI_DEFAULT_VALUE;
+ tli_struct->backcolor_red = TLI_DEFAULT_VALUE;
+ tli_struct->backcolor_green = TLI_DEFAULT_VALUE;
+ tli_struct->backcolor_blue = TLI_DEFAULT_VALUE;
+ tli_struct->signalpolarity_hs = TLI_HSYN_ACTLIVE_LOW;
+ tli_struct->signalpolarity_vs = TLI_VSYN_ACTLIVE_LOW;
+ tli_struct->signalpolarity_de = TLI_DE_ACTLIVE_LOW;
+ tli_struct->signalpolarity_pixelck = TLI_PIXEL_CLOCK_TLI;
+}
+
+/*!
+ \brief initialize TLI display timing parameters
+ \param[in] tli_struct: the data needed to initialize TLI
+ synpsz_vpsz: size of the vertical synchronous pulse
+ synpsz_hpsz: size of the horizontal synchronous pulse
+ backpsz_vbpsz: size of the vertical back porch plus synchronous pulse
+ backpsz_hbpsz: size of the horizontal back porch plus synchronous pulse
+ activesz_vasz: size of the vertical active area width plus back porch and synchronous pulse
+ activesz_hasz: size of the horizontal active area width plus back porch and synchronous pulse
+ totalsz_vtsz: vertical total size of the display, including active area, back porch, synchronous
totalsz_htsz: vorizontal total size of the display, including active area, back porch, synchronous
backcolor_red: background value red
backcolor_green: background value green
@@ -48,19 +118,19 @@ void tli_init(tli_parameter_struct *tli_struct)
{
/* synchronous pulse size configuration */
TLI_SPSZ &= ~(TLI_SPSZ_VPSZ|TLI_SPSZ_HPSZ);
- TLI_SPSZ = (tli_struct->synpsz_vpsz|(tli_struct->synpsz_hpsz<<16U));
+ TLI_SPSZ = (uint32_t)((uint32_t)tli_struct->synpsz_vpsz|((uint32_t)tli_struct->synpsz_hpsz<<16U));
/* back-porch size configuration */
TLI_BPSZ &= ~(TLI_BPSZ_VBPSZ|TLI_BPSZ_HBPSZ);
- TLI_BPSZ = (tli_struct->backpsz_vbpsz|(tli_struct->backpsz_hbpsz<<16U));
- /* active size configuration */
+ TLI_BPSZ = (uint32_t)((uint32_t)tli_struct->backpsz_vbpsz|((uint32_t)tli_struct->backpsz_hbpsz<<16U));
+ /* active size configuration */
TLI_ASZ &= ~(TLI_ASZ_VASZ|TLI_ASZ_HASZ);
TLI_ASZ = (tli_struct->activesz_vasz|(tli_struct->activesz_hasz<<16U));
- /* total size configuration */
+ /* total size configuration */
TLI_TSZ &= ~(TLI_TSZ_VTSZ|TLI_TSZ_HTSZ);
TLI_TSZ = (tli_struct->totalsz_vtsz|(tli_struct->totalsz_htsz<<16U));
- /* background color configuration */
+ /* background color configuration */
TLI_BGC &= ~(TLI_BGC_BVB|(TLI_BGC_BVG)|(TLI_BGC_BVR));
- TLI_BGC = (tli_struct->backcolor_blue|(tli_struct->backcolor_green<<8U)|(tli_struct->backcolor_red<<16U));
+ TLI_BGC = (tli_struct->backcolor_blue|(tli_struct->backcolor_green<<8U)|(tli_struct->backcolor_red<<16U));
TLI_CTL &= ~(TLI_CTL_HPPS|TLI_CTL_VPPS|TLI_CTL_DEPS|TLI_CTL_CLKPS);
TLI_CTL |= (tli_struct->signalpolarity_hs|tli_struct->signalpolarity_vs|\
tli_struct->signalpolarity_de|tli_struct->signalpolarity_pixelck);
@@ -68,14 +138,17 @@ void tli_init(tli_parameter_struct *tli_struct)
}
/*!
- \brief dither function configure
- \param[in] ditherstat: TLI_DITHER_ENABLE,TLI_DITHER_DISABLE
+ \brief configure TLI dither function
+ \param[in] dither_stat
+ only one parameter can be selected which is shown as below:
+ \arg TLI_DITHER_ENABLE
+ \arg TLI_DITHER_DISABLE
\param[out] none
\retval none
*/
-void tli_dither_config(uint8_t ditherstat)
+void tli_dither_config(uint8_t dither_stat)
{
- if(TLI_DITHER_ENABLE == ditherstat){
+ if(TLI_DITHER_ENABLE == dither_stat){
TLI_CTL |= TLI_CTL_DFEN;
}else{
TLI_CTL &= ~(TLI_CTL_DFEN);
@@ -83,8 +156,8 @@ void tli_dither_config(uint8_t ditherstat)
}
/*!
- \brief TLI enable
- \param[in] none.
+ \brief enable TLI
+ \param[in] none
\param[out] none
\retval none
*/
@@ -94,145 +167,247 @@ void tli_enable(void)
}
/*!
- \brief TLI disable
- \param[in] none.
+ \brief disable TLI
+ \param[in] none
\param[out] none
\retval none
*/
void tli_disable(void)
{
- TLI_CTL &= ~(TLI_CTL_DFEN);
+ TLI_CTL &= ~(TLI_CTL_TLIEN);
}
/*!
- \brief TLI reload layer configure
- \param[in] reloadmod: TLI_FRAME_BLANK_RELOAD_EN,TLI_REQUEST_RELOAD_EN
+ \brief configure TLI reload mode
+ \param[in] reload_mod
+ only one parameter can be selected which is shown as below:
+ \arg TLI_FRAME_BLANK_RELOAD_EN
+ \arg TLI_REQUEST_RELOAD_EN
\param[out] none
\retval none
*/
-void tli_reload_config(uint8_t reloadmod)
+void tli_reload_config(uint8_t reload_mod)
{
- if(TLI_FRAME_BLANK_RELOAD_EN == reloadmod){
+ if(TLI_FRAME_BLANK_RELOAD_EN == reload_mod){
+ /* the layer configuration will be reloaded at frame blank */
TLI_RL |= TLI_RL_FBR;
}else{
+ /* the layer configuration will be reloaded after this bit sets */
TLI_RL |= TLI_RL_RQR;
}
}
/*!
- \brief TLI interrupt enable
- \param[in] inttype: TLI interrupt bits.
- \arg TLI_INTEN_LMIE: line mark interrupt
- \arg TLI_INTEN_FEIE: FIFO error interrupt
- \arg TLI_INTEN_TEIE: transaction error interrupt
- \arg TLI_INTEN_LCRIE: layer configuration reloaded interrupt
- \param[out] none
+ \brief initialize the parameters of TLI layer structure with the default values, it is suggested
+ that call this function after a tli_layer_parameter_struct structure is defined
+ \param[in] none
+ \param[out] layer_struct: TLI Layer parameter struct
+ layer_window_rightpos: window right position
+ layer_window_leftpos: window left position
+ layer_window_bottompos: window bottom position
+ layer_window_toppos: window top position
+ layer_ppf: LAYER_PPF_ARGB8888,LAYER_PPF_RGB888,LAYER_PPF_RGB565,
+ LAYER_PPF_ARG1555,LAYER_PPF_ARGB4444,LAYER_PPF_L8,
+ LAYER_PPF_AL44,LAYER_PPF_AL88
+ layer_sa: specified alpha
+ layer_default_alpha: the default color alpha
+ layer_default_red: the default color red
+ layer_default_green: the default color green
+ layer_default_blue: the default color blue
+ layer_acf1: LAYER_ACF1_SA,LAYER_ACF1_PASA
+ layer_acf2: LAYER_ACF2_SA,LAYER_ACF2_PASA
+ layer_frame_bufaddr: frame buffer base address
+ layer_frame_buf_stride_offset: frame buffer stride offset
+ layer_frame_line_length: frame line length
+ layer_frame_total_line_number: frame total line number
\retval none
*/
-void tli_interrupt_enable(uint32_t inttype)
+void tli_layer_struct_para_init(tli_layer_parameter_struct *layer_struct)
{
- TLI_INTEN |= (inttype);
+ /* initialize the struct parameters with default values */
+ layer_struct->layer_window_rightpos = TLI_DEFAULT_VALUE;
+ layer_struct->layer_window_leftpos = TLI_DEFAULT_VALUE;
+ layer_struct->layer_window_bottompos = TLI_DEFAULT_VALUE;
+ layer_struct->layer_window_toppos = TLI_DEFAULT_VALUE;
+ layer_struct->layer_ppf = LAYER_PPF_ARGB8888;
+ layer_struct->layer_sa = TLI_OPAQUE_VALUE;
+ layer_struct->layer_default_alpha = TLI_DEFAULT_VALUE;
+ layer_struct->layer_default_red = TLI_DEFAULT_VALUE;
+ layer_struct->layer_default_green = TLI_DEFAULT_VALUE;
+ layer_struct->layer_default_blue = TLI_DEFAULT_VALUE;
+ layer_struct->layer_acf1 = LAYER_ACF1_PASA;
+ layer_struct->layer_acf2 = LAYER_ACF2_PASA;
+ layer_struct->layer_frame_bufaddr = TLI_DEFAULT_VALUE;
+ layer_struct->layer_frame_buf_stride_offset = TLI_DEFAULT_VALUE;
+ layer_struct->layer_frame_line_length = TLI_DEFAULT_VALUE;
+ layer_struct->layer_frame_total_line_number = TLI_DEFAULT_VALUE;
}
/*!
- \brief TLI interrupt disable
- \param[in] inttype: TLI interrupt bits.
- \arg TLI_INTEN_LMIE: line mark interrupt
- \arg TLI_INTEN_FEIE: FIFO error interrupt
- \arg TLI_INTEN_TEIE: transaction error interrupt
- \arg TLI_INTEN_LCRIE: layer configuration reloaded interrupt
+ \brief initialize TLI layer
+ \param[in] layerx: LAYERx(x=0,1)
+ \param[in] layer_struct: TLI Layer parameter struct
+ layer_window_rightpos: window right position
+ layer_window_leftpos: window left position
+ layer_window_bottompos: window bottom position
+ layer_window_toppos: window top position
+ layer_ppf: LAYER_PPF_ARGB8888,LAYER_PPF_RGB888,LAYER_PPF_RGB565,
+ LAYER_PPF_ARG1555,LAYER_PPF_ARGB4444,LAYER_PPF_L8,
+ LAYER_PPF_AL44,LAYER_PPF_AL88
+ layer_sa: specified alpha
+ layer_default_alpha: the default color alpha
+ layer_default_red: the default color red
+ layer_default_green: the default color green
+ layer_default_blue: the default color blue
+ layer_acf1: LAYER_ACF1_SA,LAYER_ACF1_PASA
+ layer_acf2: LAYER_ACF2_SA,LAYER_ACF2_PASA
+ layer_frame_bufaddr: frame buffer base address
+ layer_frame_buf_stride_offset: frame buffer stride offset
+ layer_frame_line_length: frame line length
+ layer_frame_total_line_number: frame total line number
\param[out] none
\retval none
*/
-void tli_interrupt_disable(uint32_t inttype)
+void tli_layer_init(uint32_t layerx,tli_layer_parameter_struct *layer_struct)
{
- TLI_INTEN &= ~(inttype);
-}
+ /* configure layer window horizontal position */
+ TLI_LxHPOS(layerx) &= ~(TLI_LxHPOS_WLP|(TLI_LxHPOS_WRP));
+ TLI_LxHPOS(layerx) = (uint32_t)((uint32_t)layer_struct->layer_window_leftpos|((uint32_t)layer_struct->layer_window_rightpos<<16U));
+ /* configure layer window vertical position */
+ TLI_LxVPOS(layerx) &= ~(TLI_LxVPOS_WTP|(TLI_LxVPOS_WBP));
+ TLI_LxVPOS(layerx) = (uint32_t)((uint32_t)layer_struct->layer_window_toppos|((uint32_t)layer_struct->layer_window_bottompos<<16U));
+ /* configure layer packeted pixel format */
+ TLI_LxPPF(layerx) &= ~(TLI_LxPPF_PPF);
+ TLI_LxPPF(layerx) = layer_struct->layer_ppf;
+ /* configure layer specified alpha */
+ TLI_LxSA(layerx) &= ~(TLI_LxSA_SA);
+ TLI_LxSA(layerx) = layer_struct->layer_sa;
+ /* configure layer default color */
+ TLI_LxDC(layerx) &= ~(TLI_LxDC_DCB|(TLI_LxDC_DCG)|(TLI_LxDC_DCR)|(TLI_LxDC_DCA));
+ TLI_LxDC(layerx) = (uint32_t)((uint32_t)layer_struct->layer_default_blue|((uint32_t)layer_struct->layer_default_green<<8U)
+ |((uint32_t)layer_struct->layer_default_red<<16U)
+ |((uint32_t)layer_struct->layer_default_alpha<<24U));
+
+ /* configure layer alpha calculation factors */
+ TLI_LxBLEND(layerx) &= ~(TLI_LxBLEND_ACF2|(TLI_LxBLEND_ACF1));
+ TLI_LxBLEND(layerx) = ((layer_struct->layer_acf2)|(layer_struct->layer_acf1));
+ /* configure layer frame buffer base address */
+ TLI_LxFBADDR(layerx) &= ~(TLI_LxFBADDR_FBADD);
+ TLI_LxFBADDR(layerx) = (layer_struct->layer_frame_bufaddr);
+ /* configure layer frame line length */
+ TLI_LxFLLEN(layerx) &= ~(TLI_LxFLLEN_FLL|(TLI_LxFLLEN_STDOFF));
+ TLI_LxFLLEN(layerx) = (uint32_t)((uint32_t)layer_struct->layer_frame_line_length|((uint32_t)layer_struct->layer_frame_buf_stride_offset<<16U));
+ /* configure layer frame total line number */
+ TLI_LxFTLN(layerx) &= ~(TLI_LxFTLN_FTLN);
+ TLI_LxFTLN(layerx) = (uint32_t)(layer_struct->layer_frame_total_line_number);
-/*!
- \brief get TLI interrupt flag
- \param[in] intflag: TLI interrupt flag bits.
- \arg TLI_INTF_LMF: line mark flag
- \arg TLI_INTF_FEF: FIFO error flag
- \arg TLI_INTF_TEF: transaction error flag
- \arg TLI_INTF_LCRF: layer configuration reloaded flag
- \param[out] none
- \retval none
-*/
-FlagStatus tli_interrupt_flag_get(uint32_t intflag)
-{
- uint32_t state;
- state = TLI_INTF;
- if(state & intflag){
- return SET;
- }else{
- return RESET;
- }
}
/*!
- \brief clear TLI interrupt flag
- \param[in] intflag: TLI interrupt flag bits.
- \arg TLI_INTC_LMC: line mark flag
- \arg TLI_INTC_FEC: FIFO error flag
- \arg TLI_INTC_TEC: transaction error flag
- \arg TLI_INTC_LCRC: layer configuration reloaded flag
+ \brief reconfigure window position
+ \param[in] layerx: LAYERx(x=0,1)
+ \param[in] offset_x: new horizontal offset
+ \param[in] offset_y: new vertical offset
\param[out] none
\retval none
*/
-void tli_interrupt_flag_clear(uint32_t intflag)
+void tli_layer_window_offset_modify(uint32_t layerx,uint16_t offset_x,uint16_t offset_y)
{
- TLI_INTC |= (intflag);
+ /* configure window start position */
+ uint32_t layer_ppf, line_num, hstart, vstart;
+ uint32_t line_length = 0U;
+ TLI_LxHPOS(layerx) &= ~(TLI_LxHPOS_WLP|(TLI_LxHPOS_WRP));
+ TLI_LxVPOS(layerx) &= ~(TLI_LxVPOS_WTP|(TLI_LxVPOS_WBP));
+ hstart = (uint32_t)offset_x+(((TLI_BPSZ & TLI_BPSZ_HBPSZ)>>16U)+1U);
+ vstart = (uint32_t)offset_y+((TLI_BPSZ & TLI_BPSZ_VBPSZ)+1U);
+ line_num = (TLI_LxFTLN(layerx) & TLI_LxFTLN_FTLN);
+ layer_ppf = (TLI_LxPPF(layerx) & TLI_LxPPF_PPF);
+ /* the bytes of a line equal TLI_LxFLLEN_FLL bits value minus 3 */
+ switch(layer_ppf){
+ case LAYER_PPF_ARGB8888:
+ /* each pixel includes 4bytes, when pixel format is ARGB8888 */
+ line_length = (((TLI_LxFLLEN(layerx) & TLI_LxFLLEN_FLL)-3U)/4U);
+ break;
+ case LAYER_PPF_RGB888:
+ /* each pixel includes 3bytes, when pixel format is RGB888 */
+ line_length = (((TLI_LxFLLEN(layerx) & TLI_LxFLLEN_FLL)-3U)/3U);
+ break;
+ case LAYER_PPF_RGB565:
+ case LAYER_PPF_ARGB1555:
+ case LAYER_PPF_ARGB4444:
+ case LAYER_PPF_AL88:
+ /* each pixel includes 2bytes, when pixel format is RGB565,ARG1555,ARGB4444 or AL88 */
+ line_length = (((TLI_LxFLLEN(layerx) & TLI_LxFLLEN_FLL)-3U)/2U);
+ break;
+ case LAYER_PPF_L8:
+ case LAYER_PPF_AL44:
+ /* each pixel includes 1byte, when pixel format is L8 or AL44 */
+ line_length = (((TLI_LxFLLEN(layerx) & TLI_LxFLLEN_FLL)-3U));
+ break;
+ default:
+ break;
+ }
+ /* reconfigure window position */
+ TLI_LxHPOS(layerx) = (hstart|((hstart+line_length-1U)<<16U));
+ TLI_LxVPOS(layerx) = (vstart|((vstart+line_num-1U)<<16U));
}
/*!
- \brief set line mark value
- \param[in] linenum: line number.
- \param[out] none
+ \brief initialize the parameters of TLI layer LUT structure with the default values, it is suggested
+ that call this function after a tli_layer_lut_parameter_struct structure is defined
+ \param[in] none
+ \param[out] lut_struct: TLI layer LUT parameter struct
+ layer_table_addr: look up table write address
+ layer_lut_channel_red: red channel of a LUT entry
+ layer_lut_channel_green: green channel of a LUT entry
+ layer_lut_channel_blue: blue channel of a LUT entry
\retval none
*/
-void tli_line_mark_set(uint32_t linenum)
+void tli_lut_struct_para_init(tli_layer_lut_parameter_struct *lut_struct)
{
- TLI_LM &= ~(TLI_LM_LM);
- TLI_LM = linenum;
+ /* initialize the struct parameters with default values */
+ lut_struct->layer_table_addr = TLI_DEFAULT_VALUE;
+ lut_struct->layer_lut_channel_red = TLI_DEFAULT_VALUE;
+ lut_struct->layer_lut_channel_green = TLI_DEFAULT_VALUE;
+ lut_struct->layer_lut_channel_blue = TLI_DEFAULT_VALUE;
}
/*!
- \brief get current displayed position
- \param[in] none
+ \brief initialize TLI layer LUT
+ \param[in] layerx: LAYERx(x=0,1)
+ \param[in] lut_struct: TLI layer LUT parameter struct
+ layer_table_addr: look up table write address
+ layer_lut_channel_red: red channel of a LUT entry
+ layer_lut_channel_green: green channel of a LUT entry
+ layer_lut_channel_blue: blue channel of a LUT entry
\param[out] none
\retval none
*/
-uint32_t tli_current_pos_get(void)
+void tli_lut_init(uint32_t layerx,tli_layer_lut_parameter_struct *lut_struct)
{
- return TLI_CPPOS;
+ TLI_LxLUT(layerx) &= ~(TLI_LxLUT_TB|TLI_LxLUT_TG|TLI_LxLUT_TR|TLI_LxLUT_TADD);
+ TLI_LxLUT(layerx) = (uint32_t)(((uint32_t)lut_struct->layer_lut_channel_blue)|((uint32_t)lut_struct->layer_lut_channel_green<<8U)
+ |((uint32_t)lut_struct->layer_lut_channel_red<<16U
+ |((uint32_t)lut_struct->layer_table_addr<<24U)));
}
-
/*!
- \brief get TLI state
- \param[in] state: TLI state.
- \arg TLI_STAT_VDE: current VDE state
- \arg TLI_STAT_HDE: current HDE state
- \arg TLI_STAT_VS: current vs state
- \arg TLI_STAT_HS: current hs state
+ \brief initialize TLI layer color key
+ \param[in] layerx: LAYERx(x=0,1)
+ \param[in] redkey: color key red
+ \param[in] greenkey: color key green
+ \param[in] bluekey: color key blue
\param[out] none
\retval none
*/
-FlagStatus tli_flag_get(uint32_t state)
+void tli_color_key_init(uint32_t layerx,uint8_t redkey,uint8_t greenkey,uint8_t bluekey)
{
- uint32_t stat;
- stat = TLI_STAT;
- if(state & stat){
- return SET;
- }else{
- return RESET;
- }
+ TLI_LxCKEY(layerx) = (((uint32_t)bluekey)|((uint32_t)greenkey<<8U)|((uint32_t)redkey<<16U));
}
/*!
- \brief TLI layer enable
- \param[in] layerx: LAYERx(x=0,1).
+ \brief enable TLI layer
+ \param[in] layerx: LAYERx(x=0,1)
\param[out] none
\retval none
*/
@@ -242,8 +417,8 @@ void tli_layer_enable(uint32_t layerx)
}
/*!
- \brief TLI layer disable
- \param[in] layerx: LAYERx(x=0,1).
+ \brief disable TLI layer
+ \param[in] layerx: LAYERx(x=0,1)
\param[out] none
\retval none
*/
@@ -253,8 +428,8 @@ void tli_layer_disable(uint32_t layerx)
}
/*!
- \brief TLI layer color keying enable
- \param[in] layerx: LAYERx(x=0,1).
+ \brief enable TLI layer color keying
+ \param[in] layerx: LAYERx(x=0,1)
\param[out] none
\retval none
*/
@@ -264,8 +439,8 @@ void tli_color_key_enable(uint32_t layerx)
}
/*!
- \brief TLI layer color keying disable
- \param[in] layerx: LAYERx(x=0,1).
+ \brief disable TLI layer color keying
+ \param[in] layerx: LAYERx(x=0,1)
\param[out] none
\retval none
*/
@@ -275,8 +450,8 @@ void tli_color_key_disable(uint32_t layerx)
}
/*!
- \brief TLI layer LUT enable
- \param[in] layerx: LAYERx(x=0,1).
+ \brief enable TLI layer LUT
+ \param[in] layerx: LAYERx(x=0,1)
\param[out] none
\retval none
*/
@@ -286,8 +461,8 @@ void tli_lut_enable(uint32_t layerx)
}
/*!
- \brief TLI layer LUT disable
- \param[in] layerx: LAYERx(x=0,1).
+ \brief disable TLI layer LUT
+ \param[in] layerx: LAYERx(x=0,1)
\param[out] none
\retval none
*/
@@ -297,147 +472,127 @@ void tli_lut_disable(uint32_t layerx)
}
/*!
- \brief TLI layer initialize
- \param[in] layerx: LAYERx(x=0,1)
- \param[in] layer_struct: TLI Layer parameter struct
- layer_window_rightpos: window right position
- layer_window_leftpos: window left position
- layer_window_bottompos: window bottom position
- layer_window_toppos: window top position
- layer_ppf: LAYER_PPF_ARGB8888,LAYER_PPF_RGB888,LAYER_PPF_RGB565,
- LAYER_PPF_ARG1555,LAYER_PPF_ARGB4444,LAYER_PPF_L8,
- LAYER_PPF_AL44,LAYER_PPF_AL88
- layer_sa: specified alpha
- layer_default_alpha: the default color alpha
- layer_default_red: the default color red
- layer_default_green: the default color green
- layer_default_blue: the default color blue
- layer_acf1: LAYER_ACF1_SA,LAYER_ACF1_PASA
- layer_acf2: LAYER_ACF2_SA,LAYER_ACF2_PASA
- layer_frame_bufaddr: frame buffer base address
- layer_frame_buf_stride_offset: frame buffer stride offset
- layer_frame_line_length: frame line length
- layer_frame_total_line_number: frame total line number
+ \brief set line mark value
+ \param[in] line_num: line number
\param[out] none
\retval none
*/
-void tli_layer_init(uint32_t layerx,tli_layer_parameter_struct *layer_struct)
+void tli_line_mark_set(uint16_t line_num)
{
- /* configure layer window horizontal position */
- TLI_LxHPOS(layerx) &= ~(TLI_LxHPOS_WLP|(TLI_LxHPOS_WRP));
- TLI_LxHPOS(layerx) = (layer_struct->layer_window_leftpos | (layer_struct->layer_window_rightpos<<16U));
- /* configure layer window vertical position */
- TLI_LxVPOS(layerx) &= ~(TLI_LxVPOS_WTP|(TLI_LxVPOS_WBP));
- TLI_LxVPOS(layerx) = (layer_struct->layer_window_toppos |(layer_struct->layer_window_bottompos<<16U));
- /* configure layer packeted pixel format */
- TLI_LxPPF(layerx) &= ~(TLI_LxPPF_PPF);
- TLI_LxPPF(layerx) = layer_struct->layer_ppf;
- /* configure layer specified alpha */
- TLI_LxSA(layerx) &= ~(TLI_LxSA_SA);
- TLI_LxSA(layerx) = layer_struct->layer_sa;
- /* configure layer default color */
- TLI_LxDC(layerx) &= ~(TLI_LxDC_DCB|(TLI_LxDC_DCG)|(TLI_LxDC_DCR)|(TLI_LxDC_DCA));
- TLI_LxDC(layerx) = (layer_struct->layer_default_blue |(layer_struct->layer_default_green<<8U)
- |(layer_struct->layer_default_red<<16U)
- |(layer_struct->layer_default_alpha<<24U));
+ TLI_LM &= ~(TLI_LM_LM);
+ TLI_LM = (uint32_t)line_num;
+}
- /* configure layer alpha calculation factors */
- TLI_LxBLEND(layerx) &= ~(TLI_LxBLEND_ACF2|(TLI_LxBLEND_ACF1));
- TLI_LxBLEND(layerx) = ((layer_struct->layer_acf2)|(layer_struct->layer_acf1));
- /* configure layer frame buffer base address */
- TLI_LxFBADDR(layerx) &= ~(TLI_LxFBADDR_FBADD);
- TLI_LxFBADDR(layerx) = (layer_struct->layer_frame_bufaddr);
- /* configure layer frame line length */
- TLI_LxFLLEN(layerx) &= ~(TLI_LxFLLEN_FLL|(TLI_LxFLLEN_STDOFF));
- TLI_LxFLLEN(layerx) = (layer_struct->layer_frame_line_length|(layer_struct->layer_frame_buf_stride_offset<<16U));
- /* configure layer frame buffer base address */
- TLI_LxFBADDR(layerx) &= ~(TLI_LxFBADDR_FBADD);
- TLI_LxFBADDR(layerx) = (layer_struct->layer_frame_bufaddr);
- /* configure layer frame total line number */
- TLI_LxFTLN(layerx) &= ~(TLI_LxFTLN_FTLN);
- TLI_LxFTLN(layerx) = (layer_struct->layer_frame_total_line_number);
+/*!
+ \brief get current displayed position
+ \param[in] none
+ \param[out] none
+ \retval position of current pixel
+*/
+uint32_t tli_current_pos_get(void)
+{
+ return TLI_CPPOS;
+}
+/*!
+ \brief enable TLI interrupt
+ \param[in] int_flag: TLI interrupt flags
+ one or more parameters can be selected which are shown as below:
+ \arg TLI_INT_LM: line mark interrupt
+ \arg TLI_INT_FE: FIFO error interrupt
+ \arg TLI_INT_TE: transaction error interrupt
+ \arg TLI_INT_LCR: layer configuration reloaded interrupt
+ \param[out] none
+ \retval none
+*/
+void tli_interrupt_enable(uint32_t int_flag)
+{
+ TLI_INTEN |= (int_flag);
}
/*!
- \brief reconfigure window position
- \param[in] layerx: LAYERx(x=0,1).
- \param[in] offset_x: new horizontal offset .
- \param[in] offset_y: new vertical offset.
+ \brief disable TLI interrupt
+ \param[in] int_flag: TLI interrupt flags
+ one or more parameters can be selected which are shown as below:
+ \arg TLI_INT_LM: line mark interrupt
+ \arg TLI_INT_FE: FIFO error interrupt
+ \arg TLI_INT_TE: transaction error interrupt
+ \arg TLI_INT_LCR: layer configuration reloaded interrupt
\param[out] none
\retval none
*/
-void tli_layer_window_offset_modify(uint32_t layerx,uint32_t offset_x,uint32_t offset_y)
+void tli_interrupt_disable(uint32_t int_flag)
{
- /* configure window start position */
- uint32_t layer_ppf,line_length,line_num,hstart,vstart;
- TLI_LxHPOS(layerx) &= ~(TLI_LxHPOS_WLP|(TLI_LxHPOS_WRP));
- TLI_LxVPOS(layerx) &= ~(TLI_LxVPOS_WTP|(TLI_LxVPOS_WBP));
- hstart = offset_x+(((TLI_BPSZ & TLI_BPSZ_HBPSZ)>>16U)+1U);
- vstart = offset_y+((TLI_BPSZ & TLI_BPSZ_VBPSZ)+1U);
- line_num = (TLI_LxFTLN(layerx) & TLI_LxFTLN_FTLN);
- layer_ppf = (TLI_LxPPF(layerx) & TLI_LxPPF_PPF);
- /* the bytes of a line equal TLI_LxFLLEN_FLL bits value minus 3 */
- switch(layer_ppf){
- case LAYER_PPF_ARGB8888:
- /* each pixel includes 4bytes,when pixel format is ARGB8888 */
- line_length = (((TLI_LxFLLEN(layerx) & TLI_LxFLLEN_FLL)-3U)/4U);
- break;
- case LAYER_PPF_RGB888:
- /* each pixel includes 3bytes,when pixel format is RGB888 */
- line_length = (((TLI_LxFLLEN(layerx) & TLI_LxFLLEN_FLL)-3U)/3U);
- break;
- case LAYER_PPF_RGB565:
- case LAYER_PPF_ARGB1555:
- case LAYER_PPF_ARGB4444:
- case LAYER_PPF_AL88:
- /* each pixel includes 2bytes,when pixel format is RGB565,ARG1555,ARGB4444 or AL88 */
- line_length = (((TLI_LxFLLEN(layerx) & TLI_LxFLLEN_FLL)-3U)/2U);
- break;
- case LAYER_PPF_L8:
- case LAYER_PPF_AL44:
- /* each pixel includes 1byte,when pixel format is L8 or AL44 */
- line_length = (((TLI_LxFLLEN(layerx) & TLI_LxFLLEN_FLL)-3U));
- break;
- default:
- break;
+ TLI_INTEN &= ~(int_flag);
+}
+
+/*!
+ \brief get TLI interrupt flag
+ \param[in] int_flag: TLI interrupt flags
+ one or more parameters can be selected which are shown as below:
+ \arg TLI_INT_FLAG_LM: line mark interrupt flag
+ \arg TLI_INT_FLAG_FE: FIFO error interrupt flag
+ \arg TLI_INT_FLAG_TE: transaction error interrupt flag
+ \arg TLI_INT_FLAG_LCR: layer configuration reloaded interrupt flag
+ \param[out] none
+ \retval FlagStatus: SET or RESET
+*/
+FlagStatus tli_interrupt_flag_get(uint32_t int_flag)
+{
+ uint32_t state;
+ state = TLI_INTF;
+ if(state & int_flag){
+ state = TLI_INTEN;
+ if(state & int_flag){
+ return SET;
+ }
}
- /* reconfigure window position */
- TLI_LxHPOS(layerx) = (hstart|((hstart+line_length-1U)<<16U));
- TLI_LxVPOS(layerx) = (vstart|((vstart+line_num-1U)<<16U));
-
-
+ return RESET;
}
/*!
- \brief TLI layer lut initialize
- \param[in] layerx: LAYERx(x=0,1)
- \param[in] lut_struct: TLI layer LUT parameter struct
- layer_table_addr: window right position
- layer_lut_channel_red: window left position
- layer_window_bottompos: window bottom position
- layer_window_toppos: window top position
+ \brief clear TLI interrupt flag
+ \param[in] int_flag: TLI interrupt flags
+ one or more parameters can be selected which are shown as below:
+ \arg TLI_INT_FLAG_LM: line mark interrupt flag
+ \arg TLI_INT_FLAG_FE: FIFO error interrupt flag
+ \arg TLI_INT_FLAG_TE: transaction error interrupt flag
+ \arg TLI_INT_FLAG_LCR: layer configuration reloaded interrupt flag
\param[out] none
\retval none
*/
-void tli_lut_init(uint32_t layerx,tli_layer_lut_parameter_struct *lut_struct)
+void tli_interrupt_flag_clear(uint32_t int_flag)
{
- TLI_LxLUT(layerx) &= ~(TLI_LxLUT_TB|TLI_LxLUT_TG|TLI_LxLUT_TR|TLI_LxLUT_TADD);
- TLI_LxLUT(layerx) = ((lut_struct->layer_lut_channel_blue)|(lut_struct->layer_lut_channel_green<<8)
- |(lut_struct->layer_lut_channel_red<<16
- |(lut_struct->layer_table_addr<<24)));
+ TLI_INTC |= (int_flag);
}
/*!
- \brief TLI layer key initialize
- \param[in] layerx: LAYERx(x=0,1).
- \param[in] redkey: color key red.
- \param[in] greenkey: color key green
- \param[in] bluekey: color key blue.
+ \brief get TLI flag or state in TLI_INTF register or TLI_STAT register
+ \param[in] flag: TLI flags or states
+ only one parameter can be selected which is shown as below:
+ \arg TLI_FLAG_VDE: current VDE state
+ \arg TLI_FLAG_HDE: current HDE state
+ \arg TLI_FLAG_VS: current VS status of the TLI
+ \arg TLI_FLAG_HS: current HS status of the TLI
+ \arg TLI_FLAG_LM: line mark interrupt flag
+ \arg TLI_FLAG_FE: FIFO error interrupt flag
+ \arg TLI_FLAG_TE: transaction error interrupt flag
+ \arg TLI_FLAG_LCR: layer configuration reloaded interrupt flag
\param[out] none
- \retval none
+ \retval FlagStatus: SET or RESET
*/
-void tli_ckey_init(uint32_t layerx,uint32_t redkey,uint32_t greenkey,uint32_t bluekey)
+FlagStatus tli_flag_get(uint32_t flag)
{
- TLI_LxCKEY(layerx) = ((bluekey)|(greenkey<<8U)|(redkey<<16U));
+ uint32_t stat;
+ /* choose which register to get flag or state */
+ if(flag >> 31U){
+ stat = TLI_INTF;
+ }else{
+ stat = TLI_STAT;
+ }
+ if(flag & stat){
+ return SET;
+ }else{
+ return RESET;
+ }
}
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_trng.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_trng.c
index f0defdcd51..8c86bb832e 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_trng.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_trng.c
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_trng.c
- \brief TRNG driver
+ \file gd32f4xx_trng.c
+ \brief TRNG driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#include "gd32f4xx_trng.h"
@@ -57,45 +82,12 @@ uint32_t trng_get_true_random_data(void)
}
/*!
- \brief get the trng status flags
- \param[in] flag: trng status flag, refer to trng_flag_enum
- only one parameter can be selected which is shown as below:
- \arg TRNG_FLAG_DRDY: Random Data ready status
- \arg TRNG_FLAG_CECS: Clock error current status
- \arg TRNG_FLAG_SECS: Seed error current status
- \param[out] none
- \retval FlagStatus: SET or RESET
-*/
-FlagStatus trng_flag_get(trng_flag_enum flag)
-{
- if(RESET != (TRNG_STAT & flag)){
- return SET;
- }else{
- return RESET;
- }
-}
-
-/*!
- \brief clear the trng status flags
- \param[in] flag: the special status flag
- only one parameter can be selected which is shown as below:
- \arg TRNG_FLAG_CECS: Clock error current status
- \arg TRNG_FLAG_SECS: Seed error current status
- \param[out] none
- \retval none
-*/
-void trng_flag_clear(trng_flag_enum flag)
-{
- TRNG_STAT &= ~(uint32_t)flag;
-}
-
-/*!
\brief enable the TRNG interrupt
\param[in] none
\param[out] none
\retval none
*/
-void trng_interrupt_enable(void)
+void trng_interrupt_enable(void)
{
TRNG_CTL |= TRNG_CTL_IE;
}
@@ -112,6 +104,25 @@ void trng_interrupt_disable(void)
}
/*!
+ \brief get the trng status flags
+ \param[in] flag: trng status flag, refer to trng_flag_enum
+ only one parameter can be selected which is shown as below:
+ \arg TRNG_FLAG_DRDY: Random Data ready status
+ \arg TRNG_FLAG_CECS: Clock error current status
+ \arg TRNG_FLAG_SECS: Seed error current status
+ \param[out] none
+ \retval FlagStatus: SET or RESET
+*/
+FlagStatus trng_flag_get(trng_flag_enum flag)
+{
+ if(RESET != (TRNG_STAT & flag)){
+ return SET;
+ }else{
+ return RESET;
+ }
+}
+
+/*!
\brief get the trng interrupt flags
\param[in] int_flag: trng interrupt flag, refer to trng_int_flag_enum
only one parameter can be selected which is shown as below:
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_usart.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_usart.c
index 945e60bc73..1b864e3b96 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_usart.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_usart.c
@@ -1,18 +1,49 @@
/*!
- \file gd32f4xx_usart.c
- \brief USART driver
+ \file gd32f4xx_usart.c
+ \brief USART driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
+
#include "gd32f4xx_usart.h"
+/* USART register bit offset */
+#define GP_GUAT_OFFSET ((uint32_t)8U) /* bit offset of GUAT in USART_GP */
+#define CTL3_SCRTNUM_OFFSET ((uint32_t)1U) /* bit offset of SCRTNUM in USART_CTL3 */
+#define RT_BL_OFFSET ((uint32_t)24U) /* bit offset of BL in USART_RT */
+
/*!
- \brief reset USART/UART
+ \brief reset USART/UART
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
\param[out] none
\retval none
@@ -63,7 +94,7 @@ void usart_deinit(uint32_t usart_periph)
\param[in] baudval: baud rate value
\param[out] none
\retval none
-*/
+*/
void usart_baudrate_set(uint32_t usart_periph, uint32_t baudval)
{
uint32_t uclk=0U, intdiv=0U, fradiv=0U, udiv=0U;
@@ -100,24 +131,25 @@ void usart_baudrate_set(uint32_t usart_periph, uint32_t baudval)
/* when oversampling by 8, configure the value of USART_BAUD */
udiv = ((2U*uclk) + baudval/2U)/baudval;
intdiv = udiv & 0xfff0U;
- fradiv = udiv & 0x7U;
- USART_BAUD(usart_periph) |= ((USART_BAUD_FRADIV | USART_BAUD_INTDIV) & (intdiv | fradiv));
+ fradiv = (udiv>>1U) & 0x7U;
+ USART_BAUD(usart_periph) = ((USART_BAUD_FRADIV | USART_BAUD_INTDIV) & (intdiv | fradiv));
}else{
/* when oversampling by 16, configure the value of USART_BAUD */
udiv = (uclk+baudval/2U)/baudval;
intdiv = udiv & 0xfff0U;
fradiv = udiv & 0xfU;
- USART_BAUD(usart_periph) |= ((USART_BAUD_FRADIV | USART_BAUD_INTDIV) & (intdiv | fradiv));
- }
+ USART_BAUD(usart_periph) = ((USART_BAUD_FRADIV | USART_BAUD_INTDIV) & (intdiv | fradiv));
+ }
}
/*!
\brief configure USART parity function
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
\param[in] paritycfg: configure USART parity
+ only one parameter can be selected which is shown as below:
\arg USART_PM_NONE: no parity
+ \arg USART_PM_EVEN: even parity
\arg USART_PM_ODD: odd parity
- \arg USART_PM_EVEN: even parity
\param[out] none
\retval none
*/
@@ -133,6 +165,7 @@ void usart_parity_config(uint32_t usart_periph, uint32_t paritycfg)
\brief configure USART word length
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
\param[in] wlen: USART word length configure
+ only one parameter can be selected which is shown as below:
\arg USART_WL_8BIT: 8 bits
\arg USART_WL_9BIT: 9 bits
\param[out] none
@@ -150,17 +183,18 @@ void usart_word_length_set(uint32_t usart_periph, uint32_t wlen)
\brief configure USART stop bit length
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
\param[in] stblen: USART stop bit configure
+ only one parameter can be selected which is shown as below:
\arg USART_STB_1BIT: 1 bit
- \arg USART_STB_0_5BIT: 0.5 bit
+ \arg USART_STB_0_5BIT: 0.5 bit(not available for UARTx(x=3,4,6,7))
\arg USART_STB_2BIT: 2 bits
- \arg USART_STB_1_5BIT: 1.5 bits
+ \arg USART_STB_1_5BIT: 1.5 bits(not available for UARTx(x=3,4,6,7))
\param[out] none
\retval none
*/
void usart_stop_bit_set(uint32_t usart_periph, uint32_t stblen)
{
/* clear USART_CTL1 STB bits */
- USART_CTL1(usart_periph) &= ~USART_CTL1_STB;
+ USART_CTL1(usart_periph) &= ~USART_CTL1_STB;
/* configure USART stop bits */
USART_CTL1(usart_periph) |= stblen;
}
@@ -189,7 +223,8 @@ void usart_disable(uint32_t usart_periph)
/*!
\brief configure USART transmitter
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
- \param[in] rtconfig: enable or disable USART transmitter
+ \param[in] txconfig: enable or disable USART transmitter
+ only one parameter can be selected which is shown as below:
\arg USART_TRANSMIT_ENABLE: enable USART transmission
\arg USART_TRANSMIT_DISABLE: enable USART transmission
\param[out] none
@@ -198,7 +233,7 @@ void usart_disable(uint32_t usart_periph)
void usart_transmit_config(uint32_t usart_periph, uint32_t txconfig)
{
uint32_t ctl = 0U;
-
+
ctl = USART_CTL0(usart_periph);
ctl &= ~USART_CTL0_TEN;
ctl |= txconfig;
@@ -209,7 +244,8 @@ void usart_transmit_config(uint32_t usart_periph, uint32_t txconfig)
/*!
\brief configure USART receiver
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
- \param[in] rtconfig: enable or disable USART receiver
+ \param[in] rxconfig: enable or disable USART receiver
+ only one parameter can be selected which is shown as below:
\arg USART_RECEIVE_ENABLE: enable USART reception
\arg USART_RECEIVE_DISABLE: disable USART reception
\param[out] none
@@ -218,7 +254,7 @@ void usart_transmit_config(uint32_t usart_periph, uint32_t txconfig)
void usart_receive_config(uint32_t usart_periph, uint32_t rxconfig)
{
uint32_t ctl = 0U;
-
+
ctl = USART_CTL0(usart_periph);
ctl &= ~USART_CTL0_REN;
ctl |= rxconfig;
@@ -230,6 +266,7 @@ void usart_receive_config(uint32_t usart_periph, uint32_t rxconfig)
\brief data is transmitted/received with the LSB/MSB first
\param[in] usart_periph: USARTx(x=0,1,2,5)
\param[in] msbf: LSB/MSB
+ only one parameter can be selected which is shown as below:
\arg USART_MSBF_LSB: LSB first
\arg USART_MSBF_MSB: MSB first
\param[out] none
@@ -237,14 +274,20 @@ void usart_receive_config(uint32_t usart_periph, uint32_t rxconfig)
*/
void usart_data_first_config(uint32_t usart_periph, uint32_t msbf)
{
- USART_CTL3(usart_periph) &= ~(USART_CTL3_MSBF);
- USART_CTL3(usart_periph) |= msbf;
+ uint32_t ctl = 0U;
+
+ ctl = USART_CTL3(usart_periph);
+ ctl &= ~(USART_CTL3_MSBF);
+ ctl |= msbf;
+ /* configure data transmitted/received mode */
+ USART_CTL3(usart_periph) = ctl;
}
/*!
\brief configure USART inversion
\param[in] usart_periph: USARTx(x=0,1,2,5)
\param[in] invertpara: refer to enum USART_INVERT_CONFIG
+ only one parameter can be selected which is shown as below:
\arg USART_DINV_ENABLE: data bit level inversion
\arg USART_DINV_DISABLE: data bit level not inversion
\arg USART_TXPIN_ENABLE: TX pin level inversion
@@ -256,7 +299,7 @@ void usart_data_first_config(uint32_t usart_periph, uint32_t msbf)
*/
void usart_invert_config(uint32_t usart_periph, usart_invert_enum invertpara)
{
- /* inverted or not the specified siginal */
+ /* inverted or not the specified siginal */
switch(invertpara){
case USART_DINV_ENABLE:
USART_CTL3(usart_periph) |= USART_CTL3_DINV;
@@ -282,9 +325,10 @@ void usart_invert_config(uint32_t usart_periph, usart_invert_enum invertpara)
}
/*!
- \brief configure the USART oversample mode
+ \brief configure the USART oversample mode
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
\param[in] oversamp: oversample value
+ only one parameter can be selected which is shown as below:
\arg USART_OVSMOD_8: 8 bits
\arg USART_OVSMOD_16: 16 bits
\param[out] none
@@ -301,6 +345,7 @@ void usart_oversample_config(uint32_t usart_periph, uint32_t oversamp)
\brief configure sample bit method
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
\param[in] obsm: sample bit
+ only one parameter can be selected which is shown as below:
\arg USART_OSB_1bit: 1 bit
\arg USART_OSB_3bit: 3 bits
\param[out] none
@@ -308,7 +353,7 @@ void usart_oversample_config(uint32_t usart_periph, uint32_t oversamp)
*/
void usart_sample_bit_config(uint32_t usart_periph, uint32_t obsm)
{
- USART_CTL2(usart_periph) &= ~(USART_CTL2_OSB);
+ USART_CTL2(usart_periph) &= ~(USART_CTL2_OSB);
USART_CTL2(usart_periph) |= obsm;
}
@@ -350,7 +395,7 @@ void usart_receiver_timeout_threshold_config(uint32_t usart_periph, uint32_t rti
/*!
\brief USART transmit data function
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
- \param[in] data: data of transmission
+ \param[in] data: data of transmission
\param[out] none
\retval none
*/
@@ -367,7 +412,7 @@ void usart_data_transmit(uint32_t usart_periph, uint32_t data)
*/
uint16_t usart_data_receive(uint32_t usart_periph)
{
- return (uint16_t)(USART_DATA(usart_periph) & (uint16_t)USART_DATA_DATA);
+ return (uint16_t)(GET_BITS(USART_DATA(usart_periph), 0U, 8U));
}
/*!
@@ -384,7 +429,7 @@ void usart_address_config(uint32_t usart_periph, uint8_t addr)
}
/*!
- \brief receiver in mute mode
+ \brief enable mute mode
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
\param[out] none
\retval none
@@ -395,7 +440,7 @@ void usart_mute_mode_enable(uint32_t usart_periph)
}
/*!
- \brief receiver in active mode
+ \brief disable mute mode
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
\param[out] none
\retval none
@@ -409,6 +454,7 @@ void usart_mute_mode_disable(uint32_t usart_periph)
\brief configure wakeup method in mute mode
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
\param[in] wmehtod: two method be used to enter or exit the mute mode
+ only one parameter can be selected which is shown as below:
\arg USART_WM_IDLE: idle line
\arg USART_WM_ADDR: address mask
\param[out] none
@@ -427,7 +473,7 @@ void usart_mute_mode_wakeup_config(uint32_t usart_periph, uint32_t wmehtod)
\retval none
*/
void usart_lin_mode_enable(uint32_t usart_periph)
-{
+{
USART_CTL1(usart_periph) |= USART_CTL1_LMEN;
}
@@ -438,7 +484,7 @@ void usart_lin_mode_enable(uint32_t usart_periph)
\retval none
*/
void usart_lin_mode_disable(uint32_t usart_periph)
-{
+{
USART_CTL1(usart_periph) &= ~(USART_CTL1_LMEN);
}
@@ -446,12 +492,13 @@ void usart_lin_mode_disable(uint32_t usart_periph)
\brief configure lin break frame length
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
\param[in] lblen: lin break frame length
+ only one parameter can be selected which is shown as below:
\arg USART_LBLEN_10B: 10 bits
\arg USART_LBLEN_11B: 11 bits
\param[out] none
\retval none
*/
-void usart_lin_break_dection_length_config(uint32_t usart_periph, uint32_t lblen)
+void usart_lin_break_detection_length_config(uint32_t usart_periph, uint32_t lblen)
{
USART_CTL1(usart_periph) &= ~(USART_CTL1_LBLEN);
USART_CTL1(usart_periph) |= (USART_CTL1_LBLEN & lblen);
@@ -475,7 +522,7 @@ void usart_send_break(uint32_t usart_periph)
\retval none
*/
void usart_halfduplex_enable(uint32_t usart_periph)
-{
+{
USART_CTL2(usart_periph) |= USART_CTL2_HDEN;
}
@@ -486,7 +533,7 @@ void usart_halfduplex_enable(uint32_t usart_periph)
\retval none
*/
void usart_halfduplex_disable(uint32_t usart_periph)
-{
+{
USART_CTL2(usart_periph) &= ~(USART_CTL2_HDEN);
}
@@ -516,13 +563,16 @@ void usart_synchronous_clock_disable(uint32_t usart_periph)
\brief configure USART synchronous mode parameters
\param[in] usart_periph: USARTx(x=0,1,2,5)
\param[in] clen: CK length
- \arg USART_CLEN_NONE: there are 7 CK pulses for an 8 bit frame and 8 CK pulses for a 9 bit frame
+ only one parameter can be selected which is shown as below:
+ \arg USART_CLEN_NONE: there are 7 CK pulses for an 8 bit frame and 8 CK pulses for a 9 bit frame
\arg USART_CLEN_EN: there are 8 CK pulses for an 8 bit frame and 9 CK pulses for a 9 bit frame
\param[in] cph: clock phase
- \arg USART_CPH_1CK: first clock transition is the first data capture edge
+ only one parameter can be selected which is shown as below:
+ \arg USART_CPH_1CK: first clock transition is the first data capture edge
\arg USART_CPH_2CK: second clock transition is the first data capture edge
- \param[in] cpl: clock polarity
- \arg USART_CPL_LOW: steady low value on CK pin
+ \param[in] cpl: clock polarity
+ only one parameter can be selected which is shown as below:
+ \arg USART_CPL_LOW: steady low value on CK pin
\arg USART_CPL_HIGH: steady high value on CK pin
\param[out] none
\retval none
@@ -530,26 +580,27 @@ void usart_synchronous_clock_disable(uint32_t usart_periph)
void usart_synchronous_clock_config(uint32_t usart_periph, uint32_t clen, uint32_t cph, uint32_t cpl)
{
uint32_t ctl = 0U;
-
+
/* read USART_CTL1 register */
ctl = USART_CTL1(usart_periph);
+ ctl &= ~(USART_CTL1_CLEN | USART_CTL1_CPH | USART_CTL1_CPL);
/* set CK length, CK phase, CK polarity */
ctl |= (USART_CTL1_CLEN & clen) | (USART_CTL1_CPH & cph) | (USART_CTL1_CPL & cpl);
- USART_CTL1(usart_periph) |= ctl;
+ USART_CTL1(usart_periph) = ctl;
}
/*!
\brief configure guard time value in smartcard mode
\param[in] usart_periph: USARTx(x=0,1,2,5)
- \param[in] gaut: guard time value
+ \param[in] guat: guard time value, 0-0xFF
\param[out] none
\retval none
*/
-void usart_guard_time_config(uint32_t usart_periph,uint32_t gaut)
+void usart_guard_time_config(uint32_t usart_periph,uint32_t guat)
{
USART_GP(usart_periph) &= ~(USART_GP_GUAT);
- USART_GP(usart_periph) |= (USART_GP_GUAT & ((gaut)<<8));
+ USART_GP(usart_periph) |= (USART_GP_GUAT & ((guat)<<GP_GUAT_OFFSET));
}
/*!
@@ -606,7 +657,7 @@ void usart_smartcard_mode_nack_disable(uint32_t usart_periph)
void usart_smartcard_autoretry_config(uint32_t usart_periph, uint32_t scrtnum)
{
USART_CTL3(usart_periph) &= ~(USART_CTL3_SCRTNUM);
- USART_CTL3(usart_periph) |= (USART_CTL3_SCRTNUM & ((scrtnum)<<1));
+ USART_CTL3(usart_periph) |= (USART_CTL3_SCRTNUM & ((scrtnum)<<CTL3_SCRTNUM_OFFSET));
}
/*!
@@ -619,7 +670,7 @@ void usart_smartcard_autoretry_config(uint32_t usart_periph, uint32_t scrtnum)
void usart_block_length_config(uint32_t usart_periph, uint32_t bl)
{
USART_RT(usart_periph) &= ~(USART_RT_BL);
- USART_RT(usart_periph) |= (USART_RT_BL & ((bl)<<24));
+ USART_RT(usart_periph) |= (USART_RT_BL & ((bl)<<RT_BL_OFFSET));
}
/*!
@@ -647,11 +698,11 @@ void usart_irda_mode_disable(uint32_t usart_periph)
/*!
\brief configure the peripheral clock prescaler in USART IrDA low-power mode
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
- \param[in] psc: 0-0x00FFFFFF
+ \param[in] psc: 0-0xFF
\param[out] none
\retval none
*/
-void usart_prescaler_config(uint32_t usart_periph, uint32_t psc)
+void usart_prescaler_config(uint32_t usart_periph, uint8_t psc)
{
USART_GP(usart_periph) &= ~(USART_GP_PSC);
USART_GP(usart_periph) |= psc;
@@ -661,7 +712,8 @@ void usart_prescaler_config(uint32_t usart_periph, uint32_t psc)
\brief configure IrDA low-power
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
\param[in] irlp: IrDA low-power or normal
- \arg USART_IRLP_LOW: low-power
+ only one parameter can be selected which is shown as below:
+ \arg USART_IRLP_LOW: low-power
\arg USART_IRLP_NORMAL: normal
\param[out] none
\retval none
@@ -675,7 +727,8 @@ void usart_irda_lowpower_config(uint32_t usart_periph, uint32_t irlp)
/*!
\brief configure hardware flow control RTS
\param[in] usart_periph: USARTx(x=0,1,2,5)
- \param[in] hardwareflow: enable or disable RTS
+ \param[in] rtsconfig: enable or disable RTS
+ only one parameter can be selected which is shown as below:
\arg USART_RTS_ENABLE: enable RTS
\arg USART_RTS_DISABLE: disable RTS
\param[out] none
@@ -684,7 +737,7 @@ void usart_irda_lowpower_config(uint32_t usart_periph, uint32_t irlp)
void usart_hardware_flow_rts_config(uint32_t usart_periph, uint32_t rtsconfig)
{
uint32_t ctl = 0U;
-
+
ctl = USART_CTL2(usart_periph);
ctl &= ~USART_CTL2_RTSEN;
ctl |= rtsconfig;
@@ -695,7 +748,8 @@ void usart_hardware_flow_rts_config(uint32_t usart_periph, uint32_t rtsconfig)
/*!
\brief configure hardware flow control CTS
\param[in] usart_periph: USARTx(x=0,1,2,5)
- \param[in] hardwareflow: enable or disable CTS
+ \param[in] ctsconfig: enable or disable CTS
+ only one parameter can be selected which is shown as below:
\arg USART_CTS_ENABLE: enable CTS
\arg USART_CTS_DISABLE: disable CTS
\param[out] none
@@ -704,7 +758,7 @@ void usart_hardware_flow_rts_config(uint32_t usart_periph, uint32_t rtsconfig)
void usart_hardware_flow_cts_config(uint32_t usart_periph, uint32_t ctsconfig)
{
uint32_t ctl = 0U;
-
+
ctl = USART_CTL2(usart_periph);
ctl &= ~USART_CTL2_CTSEN;
ctl |= ctsconfig;
@@ -715,7 +769,8 @@ void usart_hardware_flow_cts_config(uint32_t usart_periph, uint32_t ctsconfig)
/*!
\brief configure break frame coherence mode
\param[in] usart_periph: USARTx(x=0,1,2,5)
- \param[in] bcm:
+ \param[in] bcm:
+ only one parameter can be selected which is shown as below:
\arg USART_BCM_NONE: no parity error is detected
\arg USART_BCM_EN: parity error is detected
\param[out] none
@@ -730,7 +785,8 @@ void usart_break_frame_coherence_config(uint32_t usart_periph, uint32_t bcm)
/*!
\brief configure parity check coherence mode
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
- \param[in] pcm:
+ \param[in] pcm:
+ only one parameter can be selected which is shown as below:
\arg USART_PCM_NONE: not check parity
\arg USART_PCM_EN: check the parity
\param[out] none
@@ -745,7 +801,8 @@ void usart_parity_check_coherence_config(uint32_t usart_periph, uint32_t pcm)
/*!
\brief configure hardware flow control coherence mode
\param[in] usart_periph: USARTx(x=0,1,2,5)
- \param[in] hcm:
+ \param[in] hcm:
+ only one parameter can be selected which is shown as below:
\arg USART_HCM_NONE: nRTS signal equals to the rxne status register
\arg USART_HCM_EN: nRTS signal is set when the last data bit has been sampled
\param[out] none
@@ -761,6 +818,7 @@ void usart_hardware_flow_coherence_config(uint32_t usart_periph, uint32_t hcm)
\brief configure USART DMA reception
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
\param[in] dmacmd: enable or disable DMA for reception
+ only one parameter can be selected which is shown as below:
\arg USART_DENR_ENABLE: DMA enable for reception
\arg USART_DENR_DISABLE: DMA disable for reception
\param[out] none
@@ -769,7 +827,7 @@ void usart_hardware_flow_coherence_config(uint32_t usart_periph, uint32_t hcm)
void usart_dma_receive_config(uint32_t usart_periph, uint32_t dmacmd)
{
uint32_t ctl = 0U;
-
+
ctl = USART_CTL2(usart_periph);
ctl &= ~USART_CTL2_DENR;
ctl |= dmacmd;
@@ -781,6 +839,7 @@ void usart_dma_receive_config(uint32_t usart_periph, uint32_t dmacmd)
\brief configure USART DMA transmission
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
\param[in] dmacmd: enable or disable DMA for transmission
+ only one parameter can be selected which is shown as below:
\arg USART_DENT_ENABLE: DMA enable for transmission
\arg USART_DENT_DISABLE: DMA disable for transmission
\param[out] none
@@ -789,7 +848,7 @@ void usart_dma_receive_config(uint32_t usart_periph, uint32_t dmacmd)
void usart_dma_transmit_config(uint32_t usart_periph, uint32_t dmacmd)
{
uint32_t ctl = 0U;
-
+
ctl = USART_CTL2(usart_periph);
ctl &= ~USART_CTL2_DENT;
ctl |= dmacmd;
@@ -801,19 +860,20 @@ void usart_dma_transmit_config(uint32_t usart_periph, uint32_t dmacmd)
\brief get flag in STAT0/STAT1/CHC register
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
\param[in] flag: USART flags, refer to usart_flag_enum
- \arg USART_FLAG_CTSF: CTS change flag
- \arg USART_FLAG_LBDF: LIN break detected flag
- \arg USART_FLAG_TBE: transmit data buffer empty
- \arg USART_FLAG_TC: transmission complete
- \arg USART_FLAG_RBNE: read data buffer not empty
- \arg USART_FLAG_IDLEF: IDLE frame detected flag
- \arg USART_FLAG_ORERR: overrun error
- \arg USART_FLAG_NERR: noise error flag
- \arg USART_FLAG_FERR: frame error flag
- \arg USART_FLAG_PERR: parity error flag
- \arg USART_FLAG_BSY: busy flag
- \arg USART_FLAG_EBF: end of block flag
- \arg USART_FLAG_RTF: receiver timeout flag
+ only one parameter can be selected which is shown as below:
+ \arg USART_FLAG_CTS: CTS change flag
+ \arg USART_FLAG_LBD: LIN break detected flag
+ \arg USART_FLAG_TBE: transmit data buffer empty
+ \arg USART_FLAG_TC: transmission complete
+ \arg USART_FLAG_RBNE: read data buffer not empty
+ \arg USART_FLAG_IDLE: IDLE frame detected flag
+ \arg USART_FLAG_ORERR: overrun error
+ \arg USART_FLAG_NERR: noise error flag
+ \arg USART_FLAG_FERR: frame error flag
+ \arg USART_FLAG_PERR: parity error flag
+ \arg USART_FLAG_BSY: busy flag
+ \arg USART_FLAG_EB: end of block flag
+ \arg USART_FLAG_RT: receiver timeout flag
\arg USART_FLAG_EPERR: early parity error flag
\param[out] none
\retval FlagStatus: SET or RESET
@@ -831,12 +891,13 @@ FlagStatus usart_flag_get(uint32_t usart_periph, usart_flag_enum flag)
\brief clear flag in STAT0/STAT1/CHC register
\param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
\param[in] flag: USART flags, refer to usart_flag_enum
- \arg USART_FLAG_CTSF: CTS change flag
- \arg USART_FLAG_LBDF: LIN break detected flag
+ only one parameter can be selected which is shown as below:
+ \arg USART_FLAG_CTS: CTS change flag
+ \arg USART_FLAG_LBD: LIN break detected flag
\arg USART_FLAG_TC: transmission complete
\arg USART_FLAG_RBNE: read data buffer not empty
- \arg USART_FLAG_EBF: end of block flag
- \arg USART_FLAG_RTF: receiver timeout flag
+ \arg USART_FLAG_EB: end of block flag
+ \arg USART_FLAG_RT: receiver timeout flag
\arg USART_FLAG_EPERR: early parity error flag
\param[out] none
\retval none
@@ -848,105 +909,101 @@ void usart_flag_clear(uint32_t usart_periph, usart_flag_enum flag)
/*!
\brief enable USART interrupt
- \param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
- \param[in] int_flag
- \arg USART_INTEN_PERRIE: parity error interrupt
- \arg USART_INTEN_TBEIE: transmitter buffer empty interrupt
- \arg USART_INTEN_TCIE: transmission complete interrupt
- \arg USART_INTEN_RBNEIE: read data buffer not empty interrupt and overrun error interrupt
- \arg USART_INTEN_IDLEIE: IDLE line detected interrupt
- \arg USART_INTEN_LBDIE: LIN break detected interrupt
- \arg USART_INTEN_ERRIE: error interrupt
- \arg USART_INTEN_CTSIE: CTS interrupt
- \arg USART_INTEN_RTIE: interrupt enable bit of receive timeout event
- \arg USART_INTEN_EBIE: interrupt enable bit of end of block event
+ \param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
+ \param[in] interrupt: USART interrupts, refer to usart_interrupt_enum
+ only one parameter can be selected which is shown as below:
+ \arg USART_INT_PERR: parity error interrupt
+ \arg USART_INT_TBE: transmitter buffer empty interrupt
+ \arg USART_INT_TC: transmission complete interrupt
+ \arg USART_INT_RBNE: read data buffer not empty interrupt and overrun error interrupt
+ \arg USART_INT_IDLE: IDLE line detected interrupt
+ \arg USART_INT_LBD: LIN break detected interrupt
+ \arg USART_INT_ERR: error interrupt
+ \arg USART_INT_CTS: CTS interrupt
+ \arg USART_INT_RT: interrupt enable bit of receive timeout event
+ \arg USART_INT_EB: interrupt enable bit of end of block event
\param[out] none
+ \retval none
*/
-void usart_interrupt_enable(uint32_t usart_periph, uint32_t int_flag)
+void usart_interrupt_enable(uint32_t usart_periph, usart_interrupt_enum interrupt)
{
- uint32_t usart_reg = 0U;
-
- usart_reg = int_flag & (~(uint32_t)USART_INTEN_MASK);
- int_flag &= USART_INTEN_MASK;
- /* flags in USART_CTL0 */
- if(USART_INTS_CTL0 == usart_reg){
- USART_CTL0(usart_periph) |= int_flag;
- /* flags in USART_CTL1 */
- }else if(USART_INTS_CTL1 == usart_reg){
- USART_CTL1(usart_periph) |= int_flag;
- /* flags in USART_CTL2 */
- }else if(USART_INTS_CTL2 == usart_reg){
- USART_CTL2(usart_periph) |= int_flag;
- /* flags in USART_CTL3 */
- }else if(USART_INTS_CTL3 == usart_reg){
- USART_CTL3(usart_periph) |= int_flag;
- }else{
- /* illegal parameters */
- }
+ USART_REG_VAL(usart_periph, interrupt) |= BIT(USART_BIT_POS(interrupt));
}
/*!
\brief disable USART interrupt
- \param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
- \param[in] int_flag
- \arg USART_INTEN_PERRIE: parity error interrupt
- \arg USART_INTEN_TBEIE: transmitter buffer empty interrupt
- \arg USART_INTEN_TCIE: transmission complete interrupt
- \arg USART_INTEN_RBNEIE: read data buffer not empty interrupt and overrun error interrupt
- \arg USART_INTEN_IDLEIE: IDLE line detected interrupt
- \arg USART_INTEN_LBDIE: LIN break detected interrupt
- \arg USART_INTEN_ERRIE: error interrupt
- \arg USART_INTEN_CTSIE: CTS interrupt
- \arg USART_INTEN_RTIE: interrupt enable bit of receive timeout event
- \arg USART_INTEN_EBIE: interrupt enable bit of end of block event
+ \param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
+ \param[in] interrupt: USART interrupts, refer to usart_interrupt_enum
+ only one parameter can be selected which is shown as below:
+ \arg USART_INT_PERR: parity error interrupt
+ \arg USART_INT_TBE: transmitter buffer empty interrupt
+ \arg USART_INT_TC: transmission complete interrupt
+ \arg USART_INT_RBNE: read data buffer not empty interrupt and overrun error interrupt
+ \arg USART_INT_IDLE: IDLE line detected interrupt
+ \arg USART_INT_LBD: LIN break detected interrupt
+ \arg USART_INT_ERR: error interrupt
+ \arg USART_INT_CTS: CTS interrupt
+ \arg USART_INT_RT: interrupt enable bit of receive timeout event
+ \arg USART_INT_EB: interrupt enable bit of end of block event
\param[out] none
+ \retval none
*/
-void usart_interrupt_disable(uint32_t usart_periph, uint32_t int_flag)
+void usart_interrupt_disable(uint32_t usart_periph, usart_interrupt_enum interrupt)
{
- uint32_t usart_reg = 0U;
-
- usart_reg = int_flag & (~(uint32_t)USART_INTEN_MASK);
- int_flag &= USART_INTEN_MASK;
- /* flags in USART_CTL0 */
- if(USART_INTS_CTL0 == usart_reg){
- USART_CTL0(usart_periph) &= ~(int_flag);
- /* flags in USART_CTL1 */
- }else if(USART_INTS_CTL1 == usart_reg){
- USART_CTL1(usart_periph) &= ~(int_flag);
- /* flags in USART_CTL2 */
- }else if(USART_INTS_CTL2 == usart_reg){
- USART_CTL2(usart_periph) &= ~(int_flag);
- /* flags in USART_CTL3 */
- }else if(USART_INTS_CTL3 == usart_reg){
- USART_CTL3(usart_periph) &= ~(int_flag);
- }else{
- /* illegal parameters */
- }
+ USART_REG_VAL(usart_periph, interrupt) &= ~BIT(USART_BIT_POS(interrupt));
}
/*!
- \brief get USART interrupt enable flag
- \param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
- \param[in] int_flag
- \arg USART_INT_PERRIE: parity error interrupt
- \arg USART_INT_TBEIE: transmitter buffer empty interrupt
- \arg USART_INT_TCIE: transmission complete interrupt
- \arg USART_INT_RBNEIE: read data buffer not empty interrupt and overrun error interrupt
- \arg USART_INT_IDLEIE: IDLE line detected interrupt
- \arg USART_INT_LBDIE: LIN break detected interrupt
- \arg USART_INT_CTSIE: CTS interrupt
- \arg USART_INT_ERRIE: error interrupt
- \arg USART_INT_EBIE: interrupt enable bit of end of block event
- \arg USART_INT_RTIE: interrupt enable bit of receive timeout event
+ \brief get USART interrupt and flag status
+ \param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
+ \param[in] int_flag: USART interrupt flags, refer to usart_interrupt_flag_enum
+ only one parameter can be selected which is shown as below:
+ \arg USART_INT_FLAG_PERR: parity error interrupt and flag
+ \arg USART_INT_FLAG_TBE: transmitter buffer empty interrupt and flag
+ \arg USART_INT_FLAG_TC: transmission complete interrupt and flag
+ \arg USART_INT_FLAG_RBNE: read data buffer not empty interrupt and flag
+ \arg USART_INT_FLAG_RBNE_ORERR: read data buffer not empty interrupt and overrun error flag
+ \arg USART_INT_FLAG_IDLE: IDLE line detected interrupt and flag
+ \arg USART_INT_FLAG_LBD: LIN break detected interrupt and flag
+ \arg USART_INT_FLAG_CTS: CTS interrupt and flag
+ \arg USART_INT_FLAG_ERR_ORERR: error interrupt and overrun error
+ \arg USART_INT_FLAG_ERR_NERR: error interrupt and noise error flag
+ \arg USART_INT_FLAG_ERR_FERR: error interrupt and frame error flag
+ \arg USART_INT_FLAG_EB: interrupt enable bit of end of block event and flag
+ \arg USART_INT_FLAG_RT: interrupt enable bit of receive timeout event and flag
\param[out] none
- \retval FlagStatus
+ \retval FlagStatus: SET or RESET
*/
-FlagStatus usart_interrupt_flag_get(uint32_t usart_periph, uint32_t int_flag)
+FlagStatus usart_interrupt_flag_get(uint32_t usart_periph, usart_interrupt_flag_enum int_flag)
{
- if(RESET != (USART_REG_VAL(usart_periph, int_flag) & BIT(USART_BIT_POS(int_flag)))){
+ uint32_t intenable = 0U, flagstatus = 0U;
+ /* get the interrupt enable bit status */
+ intenable = (USART_REG_VAL(usart_periph, int_flag) & BIT(USART_BIT_POS(int_flag)));
+ /* get the corresponding flag bit status */
+ flagstatus = (USART_REG_VAL2(usart_periph, int_flag) & BIT(USART_BIT_POS2(int_flag)));
+
+ if((0U != flagstatus) && (0U != intenable)){
return SET;
}else{
return RESET;
}
}
+/*!
+ \brief clear USART interrupt flag in STAT0/STAT1 register
+ \param[in] usart_periph: USARTx(x=0,1,2,5)/UARTx(x=3,4,6,7)
+ \param[in] int_flag: USART interrupt flags, refer to usart_interrupt_flag_enum
+ only one parameter can be selected which is shown as below:
+ \arg USART_INT_FLAG_CTS: CTS change flag
+ \arg USART_INT_FLAG_LBD: LIN break detected flag
+ \arg USART_INT_FLAG_TC: transmission complete
+ \arg USART_INT_FLAG_RBNE: read data buffer not empty
+ \arg USART_INT_FLAG_EB: end of block flag
+ \arg USART_INT_FLAG_RT: receiver timeout flag
+ \param[out] none
+ \retval none
+*/
+void usart_interrupt_flag_clear(uint32_t usart_periph, usart_interrupt_flag_enum int_flag)
+{
+ USART_REG_VAL2(usart_periph, int_flag) &= ~BIT(USART_BIT_POS2(int_flag));
+}
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_wwdgt.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_wwdgt.c
index 94a50ac996..e788c26614 100644
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_wwdgt.c
+++ b/bsp/gd32450z-eval/Libraries/GD32F4xx_standard_peripheral/Source/gd32f4xx_wwdgt.c
@@ -1,12 +1,37 @@
/*!
- \file gd32f4xx_wwdgt.c
- \brief WWDGT driver
+ \file gd32f4xx_wwdgt.c
+ \brief WWDGT driver
+
+ \version 2016-08-15, V1.0.0, firmware for GD32F4xx
+ \version 2018-12-12, V2.0.0, firmware for GD32F4xx
+ \version 2020-09-30, V2.1.0, firmware for GD32F4xx
*/
/*
- Copyright (C) 2016 GigaDevice
+ Copyright (c) 2020, GigaDevice Semiconductor Inc.
+
+ Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
- 2016-08-15, V1.0.0, firmware for GD32F4xx
+ 1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ 3. Neither the name of the copyright holder nor the names of its contributors
+ may be used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+OF SUCH DAMAGE.
*/
#include "gd32f4xx_wwdgt.h"
@@ -29,37 +54,38 @@ void wwdgt_deinit(void)
}
/*!
- \brief configure the window watchdog timer counter value
- \param[in] counter_value: 0x00 - 0x7F
+ \brief start the window watchdog timer counter
+ \param[in] none
\param[out] none
\retval none
*/
-void wwdgt_counter_update(uint16_t counter_value)
+void wwdgt_enable(void)
{
- uint32_t reg = 0U;
-
- reg = (WWDGT_CTL & (~WWDGT_CTL_CNT));
- reg |= CTL_CNT(counter_value);
-
- WWDGT_CTL = reg;
+ WWDGT_CTL |= WWDGT_CTL_WDGTEN;
}
/*!
- \brief start the window watchdog timer counter
- \param[in] none
+ \brief configure the window watchdog timer counter value
+ \param[in] counter_value: 0x00 - 0x7F
\param[out] none
\retval none
*/
-void wwdgt_enable(void)
+void wwdgt_counter_update(uint16_t counter_value)
{
- WWDGT_CTL |= WWDGT_CTL_WDGTEN;
+ uint32_t reg = 0U;
+
+ reg = (WWDGT_CTL & (~WWDGT_CTL_CNT));
+ reg |= CTL_CNT(counter_value);
+
+ WWDGT_CTL = reg;
}
/*!
- \brief configure counter value, window value, and prescaler divider value
- \param[in] counter: 0x00 - 0x7F
+ \brief configure counter value, window value, and prescaler divider value
+ \param[in] counter: 0x00 - 0x7F
\param[in] window: 0x00 - 0x7F
\param[in] prescaler: wwdgt prescaler value
+ only one parameter can be selected which is shown as below:
\arg WWDGT_CFG_PSC_DIV1: the time base of window watchdog counter = (PCLK1/4096)/1
\arg WWDGT_CFG_PSC_DIV2: the time base of window watchdog counter = (PCLK1/4096)/2
\arg WWDGT_CFG_PSC_DIV4: the time base of window watchdog counter = (PCLK1/4096)/4
@@ -74,12 +100,12 @@ void wwdgt_config(uint16_t counter, uint16_t window, uint32_t prescaler)
/* clear WIN and PSC bits, clear CNT bit */
reg_cfg = (WWDGT_CFG &(~(WWDGT_CFG_WIN|WWDGT_CFG_PSC)));
reg_ctl = (WWDGT_CTL &(~WWDGT_CTL_CNT));
-
+
/* configure WIN and PSC bits, configure CNT bit */
reg_cfg |= CFG_WIN(window);
reg_cfg |= prescaler;
reg_ctl |= CTL_CNT(counter);
-
+
WWDGT_CTL = reg_ctl;
WWDGT_CFG = reg_cfg;
}
@@ -103,7 +129,7 @@ void wwdgt_interrupt_enable(void)
*/
FlagStatus wwdgt_flag_get(void)
{
- if(WWDGT_STAT & WWDGT_STAT_EWIF){
+ if(RESET != (WWDGT_STAT & WWDGT_STAT_EWIF)){
return SET;
}
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usb_core.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usb_core.h
deleted file mode 100644
index 2891e0219c..0000000000
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usb_core.h
+++ /dev/null
@@ -1,287 +0,0 @@
-/*!
- \file usb_core.h
- \brief USB core driver header file
-*/
-
-/*
- Copyright (C) 2016 GigaDevice
-
- 2016-08-15, V1.0.0, firmware for GD32F4xx
-*/
-
-#ifndef USB_CORE_H
-#define USB_CORE_H
-
-#include "usb_conf.h"
-#include "usb_regs.h"
-#include "usb_defines.h"
-
-#define USB_MAX_EP0_SIZE 64U /* endpoint 0 max packet size */
-#define RX_MAX_DATA_LENGTH 512U /* host rx buffer max data length */
-#define HC_MAX_PACKET_COUNT 140U /* host channel max packet count */
-
-#ifdef USE_USBFS
- #define USB_MAX_DEV_EPCOUNT USBFS_MAX_DEV_EPCOUNT
- #define USB_MAX_FIFOS (USBFS_MAX_HOST_CHANNELCOUNT * 2U - 1U)
-#elif defined(USE_USBHS)
- #define USB_MAX_DEV_EPCOUNT USBHS_MAX_DEV_EPCOUNT
- #define USB_MAX_FIFOS (USBHS_MAX_HOST_CHANNELCOUNT * 2U - 1U)
-#endif /* USE_USBFS */
-
-/* USB core status */
-typedef enum
-{
- USB_OK = 0, /* USB core OK status */
- USB_FAIL /* USB core fail status */
-}usb_status_enum;
-
-/* USB host channel status */
-typedef enum
-{
- HC_IDLE = 0, /* USB host channel idle status */
- HC_XF, /* USB host channel transfer status */
- HC_HALTED, /* USB host channel halted status */
- HC_NAK, /* USB host channel nak status */
- HC_NYET, /* USB host channel nyet status */
- HC_STALL, /* USB host channel stall status */
- HC_TRACERR, /* USB host channel tracerr status */
- HC_BBERR, /* USB host channel bberr status */
- HC_DTGERR, /* USB host channel dtgerr status */
-}hc_status_enum;
-
-/* USB URB(USB request block) state */
-typedef enum
-{
- URB_IDLE = 0, /* USB URB idle status */
- URB_DONE, /* USB URB done status */
- URB_NOTREADY, /* USB URB notready status */
- URB_ERROR, /* USB URB error status */
- URB_STALL, /* USB URB stall status */
- URB_PING /* USB URB ping status */
-}urb_state_enum;
-
-/* USB core configuration */
-typedef struct
-{
- uint8_t core_id; /* USB core id */
- uint8_t core_speed; /* USB core speed */
- uint8_t phy_interface; /* USB PHY interface */
- uint8_t host_channel_num; /* USB host channel number */
- uint8_t dev_endp_num; /* USB device endpoint number */
- uint8_t dma_enable; /* USBHS can use DMA */
- uint8_t sof_output; /* USB SOF output */
- uint8_t low_power; /* USB low power */
- uint16_t max_packet_size; /* USB max packet size */
- uint16_t max_fifo_size; /* USB fifo size */
-}usb_core_cfgs_struct;
-
-typedef enum
-{
- USBD_OK = 0, /* USB device ok status */
- USBD_BUSY, /* USB device busy status */
- USBD_FAIL, /* USB device fail stauts */
-}usbd_status_enum;
-
-/* USB control transfer state */
-typedef enum
-{
- USB_CTRL_IDLE = 0, /* USB control transfer idle state */
- USB_CTRL_SETUP, /* USB control transfer setup state */
- USB_CTRL_DATA_IN, /* USB control transfer data in state */
- USB_CTRL_DATA_OUT, /* USB control transfer data out state */
- USB_CTRL_STATUS_IN, /* USB control transfer status in state*/
- USB_CTRL_STATUS_OUT, /* USB control transfer status out state */
- USB_CTRL_STALL /* USB control transfer stall state */
-}usbd_control_state_enum;
-
-/* USB transfer direction */
-typedef enum
-{
- USBD_RX = 0, /* receive direction type value */
- USBD_TX /* transmit direction type value */
-}usbd_dir_enum;
-
-/* USB endpoint in device mode */
-typedef struct
-{
- uint8_t endp_type; /* USB endpoint type */
- uint8_t endp_frame; /* USB endpoint frame */
- uint32_t endp_mps; /* USB endpoint max packet size */
-
- /* Transaction level variables */
- uint8_t *xfer_buff; /* USB transfer buffer */
- uint32_t xfer_len; /* USB transfer length */
- uint32_t xfer_count; /* USB transfer count */
-
- uint32_t dma_addr; /* USBHS can use DMA */
-}usb_ep_struct;
-
-/* USB device standard request */
-typedef struct
-{
- uint8_t bmRequestType; /* USB device request type */
- uint8_t bRequest; /* USB device request */
- uint16_t wValue; /* USB device request value */
- uint16_t wIndex; /* USB device request index */
- uint16_t wLength; /* USB device request length */
-}usb_device_req_struct;
-
-/* USB core device driver */
-typedef struct
-{
- uint8_t config_num; /* USB configuration number */
- uint8_t status; /* USB status */
- uint8_t ctl_status; /* USB control status */
- uint8_t prev_status; /* USB previous status */
- uint8_t connection_status; /* USB connection status */
- uint32_t remote_wakeup; /* USB remote wakeup */
-
- /* transfer level variables */
- uint32_t remain_len; /* USB remain length */
- uint32_t sum_len; /* USB sum length */
- uint32_t ctl_len; /* USB control length */
- uint8_t setup_packet[8 * 3]; /* USB setup packet */
-
- usb_ep_struct in_ep[USB_MAX_DEV_EPCOUNT]; /* USB IN endpoint */
- usb_ep_struct out_ep[USB_MAX_DEV_EPCOUNT]; /* USB OUT endpoint */
-
- uint8_t *dev_desc; /* device descriptor */
- uint8_t *config_desc; /* configuration descriptor */
- uint8_t* *strings; /* configuration strings */
-
- /* device class handler */
- uint8_t (*class_init) (void *pudev, uint8_t config_index); /* device class initialize */
- uint8_t (*class_deinit) (void *pudev, uint8_t config_index); /* device class deinitialize */
- uint8_t (*class_req_handler) (void *pudev, usb_device_req_struct *req); /* device request handler */
- uint8_t (*class_data_handler) (void *pudev, usbd_dir_enum rx_tx, uint8_t ep_id); /* device data handler */
-}dcd_dev_struct;
-
-/* USB core host mode channel */
-typedef struct
-{
- uint8_t dev_addr; /* device address */
- uint8_t dev_speed; /* device speed */
- uint8_t DPID; /* endpoint transfer data pid */
- uint8_t endp_id; /* endpoint id */
- uint8_t endp_in; /* endpoint in */
- uint8_t endp_type; /* endpoint type */
- uint16_t endp_mps; /* endpoint max pactet size */
- uint16_t info; /* channel information */
-
- uint8_t do_ping; /* USBHS ping */
-
- uint8_t *xfer_buff; /* transfer buffer */
- uint32_t xfer_len; /* transfer length */
- uint32_t xfer_count; /* trasnfer count */
-
- uint32_t err_count; /* USB transfer error count */
- uint32_t dma_addr; /* USBHS can use DMA */
-
- hc_status_enum status; /* channel status */
- urb_state_enum urb_state; /* URB state */
-
- uint8_t data_tg_in; /* data in toggle */
- uint8_t data_tg_out; /* data out toggle */
-}usb_hostchannel_struct;
-
-/* USB core host driver */
-typedef struct
-{
- uint8_t rx_buffer[RX_MAX_DATA_LENGTH]; /* rx buffer */
- uint8_t connect_status; /* device connect status */
- usb_hostchannel_struct host_channel[USB_MAX_FIFOS]; /* host channel */
- void (*vbus_drive) (void *pudev, uint8_t state); /* the vbus driver function */
-}hcd_dev_struct;
-
-#ifdef USE_OTG_MODE
-
-/* USB core OTG-mode driver */
-typedef struct
-{
- uint8_t OTG_State; /* OTG state */
- uint8_t OTG_PrevState; /* OTG previous state */
- uint8_t OTG_Mode; /* OTG mode */
-}otg_dev_struct;
-
-#endif /* USE_OTG_MODE */
-
-/* USB core driver */
-typedef struct
-{
- usb_core_cfgs_struct cfg;
-
-#ifdef USE_DEVICE_MODE
- dcd_dev_struct dev;
-#endif /* USE_DEVICE_MODE */
-
-#ifdef USE_HOST_MODE
- hcd_dev_struct host;
-#endif /* USE_HOST_MODE */
-
-#ifdef USE_OTG_MODE
- otg_dev_struct otg;
-#endif /* USE_OTG_MODE */
-
- void (*udelay) (const uint32_t usec);
- void (*mdelay) (const uint32_t msec);
-}usb_core_handle_struct;
-
-/* function declarations */
-
-/* global APIs */
-/* initializes the USB controller registers and prepares the core device mode or host mode operation */
-usb_status_enum usb_core_init (usb_core_handle_struct *pudev);
-/* initialize core parameters */
-usb_status_enum usb_core_select (usb_core_handle_struct *pudev, usb_core_id_enum core_id);
-/* read a packet from the Rx FIFO associated with the endpoint */
-void* usb_fifo_read (uint8_t *dest, uint16_t len);
-/* write a packet into the Tx FIFO associated with the endpoint */
-usb_status_enum usb_fifo_write (uint8_t *src, uint8_t ep_id, uint16_t len);
-/* flush a Tx FIFO or all Tx FIFOs */
-usb_status_enum usb_txfifo_flush (usb_core_handle_struct *pudev, uint8_t fifo_num);
-/* flush the entire Rx FIFO */
-usb_status_enum usb_rxfifo_flush (usb_core_handle_struct *pudev);
-/* set operation mode (host or device) */
-usb_status_enum usb_mode_set (usb_core_handle_struct *pudev, uint8_t mode);
-
-/* host APIs */
-#ifdef USE_HOST_MODE
-
-/* initializes USB core for host mode */
-usb_status_enum usb_hostcore_init (usb_core_handle_struct *pudev);
-/* enables the host mode interrupts */
-usb_status_enum usb_hostint_enable (usb_core_handle_struct *pudev);
-/* initialize host channel */
-usb_status_enum usb_hostchannel_init (usb_core_handle_struct *pudev, uint8_t hc_num);
-/* halt channel */
-usb_status_enum usb_hostchannel_halt (usb_core_handle_struct *pudev, uint8_t hc_num);
-/* prepare host channel for transferring packets */
-usb_status_enum usb_hostchannel_startxfer (usb_core_handle_struct *pudev, uint8_t hc_num);
-/* issue a ping token */
-usb_status_enum usb_hostchannel_ping (usb_core_handle_struct *pudev, uint8_t hc_num);
-/* reset host port */
-uint32_t usb_port_reset (usb_core_handle_struct *pudev);
-/* control the VBUS to power */
-void usb_vbus_drive (usb_core_handle_struct *pudev, uint8_t state);
-/* stop the USB host and clean up fifos */
-void usb_host_stop (usb_core_handle_struct *pudev);
-
-#endif /* USE_HOST_MODE */
-
-/* device APIs */
-#ifdef USE_DEVICE_MODE
-
-/* initialize USB core registers for device mode */
-usb_status_enum usb_devcore_init (usb_core_handle_struct *pudev);
-/* configures endpoint 0 to receive SETUP packets */
-void usb_ep0_startout (usb_core_handle_struct *pudev);
-/* active remote wakeup signalling */
-void usb_remotewakeup_active (usb_core_handle_struct *pudev);
-/* active USB core clock */
-void usb_clock_ungate (usb_core_handle_struct *pudev);
-/* stop the device and clean up fifos */
-void usb_device_stop (usb_core_handle_struct *pudev);
-
-#endif /* USE_DEVICE_MODE */
-
-#endif /* USB_CORE_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usb_defines.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usb_defines.h
deleted file mode 100644
index 309e23f32f..0000000000
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usb_defines.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/*!
- \file usb_defines.h
- \brief USB core defines
-*/
-
-/*
- Copyright (C) 2016 GigaDevice
-
- 2016-08-15, V1.0.0, firmware for GD32F4xx
-*/
-
-#ifndef USB_DEFINES_H
-#define USB_DEFINES_H
-
-#include "usb_conf.h"
-
-#ifndef NULL
- #define NULL (void *)0 /*!< USB null marco value*/
-#endif /* NULL */
-
-#define USB_CORE_SPEED_HIGH 0U /* USB core speed is high-speed */
-#define USB_CORE_SPEED_FULL 1U /* USB core speed is full-speed */
-
-#define USBFS_MAX_PACKET_SIZE 64U /* USBFS max packet size */
-#define USBFS_MAX_HOST_CHANNELCOUNT 8U /* USBFS host channel count */
-#define USBFS_MAX_DEV_EPCOUNT 4U /* USBFS device endpoint count */
-#define USBFS_MAX_FIFO_WORDLEN 320U /* USBFS max fifo size in words */
-
-#define USBHS_MAX_PACKET_SIZE 512U /* USBHS max packet size */
-#define USBHS_MAX_HOST_CHANNELCOUNT 12U /* USBHS host channel count */
-#define USBHS_MAX_DEV_EPCOUNT 6U /* USBHS device endpoint count */
-#define USBHS_MAX_FIFO_WORDLEN 1280U /* USBHS max fifo size in words */
-
-#define USB_CORE_ULPI_PHY 1U /* USB core use external ULPI PHY */
-#define USB_CORE_EMBEDDED_PHY 2U /* USB core use embedded PHY */
-
-#define DSTAT_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ 0U /* USB enumerate speed use high-speed PHY clock in 30MHz or 60MHz */
-#define DSTAT_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ 1U /* USB enumerate speed use full-speed PHY clock in 30MHz or 60MHz */
-#define DSTAT_ENUMSPD_LS_PHY_6MHZ 2U /* USB enumerate speed use low-speed PHY clock in 6MHz */
-#define DSTAT_ENUMSPD_FS_PHY_48MHZ 3U /* USB enumerate speed use full-speed PHY clock in 48MHz */
-
-#define GRSTATR_RPCKST_IN 2U /* IN data packet received */
-#define GRSTATR_RPCKST_IN_XFER_COMP 3U /* IN transfer completed (generates an interrupt if poped) */
-#define GRSTATR_RPCKST_DATA_TOGGLE_ERR 5U /* Data toggle error (generates an interrupt if poped) */
-#define GRSTATR_RPCKST_CH_HALTED 7U /* Channel halted (generates an interrupt if poped) */
-
-#define DEVICE_MODE 0U /* USB core in device mode */
-#define HOST_MODE 1U /* USB core in host mode */
-#define OTG_MODE 2U /* USB core in OTG mode */
-
-#define USB_EPTYPE_CTRL 0U /* USB control endpoint type */
-#define USB_EPTYPE_ISOC 1U /* USB synchronous endpoint type */
-#define USB_EPTYPE_BULK 2U /* USB bulk endpoint type */
-#define USB_EPTYPE_INTR 3U /* USB interrupt endpoint type */
-#define USB_EPTYPE_MASK 3U /* USB endpoint type mask */
-
-#define RXSTAT_GOUT_NAK 1U /* global OUT NAK (triggers an interrupt) */
-#define RXSTAT_DATA_UPDT 2U /* OUT data packet received */
-#define RXSTAT_XFER_COMP 3U /* OUT transfer completed (triggers an interrupt) */
-#define RXSTAT_SETUP_COMP 4U /* SETUP transaction completed (triggers an interrupt) */
-#define RXSTAT_SETUP_UPDT 6U /* SETUP data packet received */
-
-#define DPID_DATA0 0U /* device endpoint data PID is DATA0 */
-#define DPID_DATA1 2U /* device endpoint data PID is DATA1 */
-#define DPID_DATA2 1U /* device endpoint data PID is DATA2 */
-#define DPID_MDATA 3U /* device endpoint data PID is MDATA */
-
-#define HC_PID_DATA0 0U /* host channel data PID is DATA0 */
-#define HC_PID_DATA2 1U /* host channel data PID is DATA2 */
-#define HC_PID_DATA1 2U /* host channel data PID is DATA1 */
-#define HC_PID_SETUP 3U /* host channel data PID is SETUP */
-
-#define HPRT_PRTSPD_HIGH_SPEED 0U /* host port speed use high speed */
-#define HPRT_PRTSPD_FULL_SPEED 1U /* host port speed use full speed */
-#define HPRT_PRTSPD_LOW_SPEED 2U /* host port speed use low speed */
-
-#define HCTLR_30_60_MHZ 0U /* USB PHY(ULPI) clock is 60MHz */
-#define HCTLR_48_MHZ 1U /* USB PHY(embedded full-speed) clock is 48MHz */
-#define HCTLR_6_MHZ 2U /* USB PHY(embedded low-speed) clock is 6MHz */
-
-#define HCCHAR_CTRL 0U /* control channel type */
-#define HCCHAR_ISOC 1U /* synchronous channel type */
-#define HCCHAR_BULK 2U /* bulk channel type */
-#define HCCHAR_INTR 3U /* interrupt channel type */
-
-typedef enum
-{
- USB_HS_CORE_ID = 0,
- USB_FS_CORE_ID = 1
-}usb_core_id_enum;
-
-typedef enum
-{
- USB_SPEED_UNKNOWN = 0,
- USB_SPEED_LOW,
- USB_SPEED_FULL,
- USB_SPEED_HIGH
-}usb_speed_enum;
-
-#endif /* USB_DEFINES_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usb_regs.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usb_regs.h
deleted file mode 100644
index db05aa25ff..0000000000
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usb_regs.h
+++ /dev/null
@@ -1,676 +0,0 @@
-/*!
- \file usb_regs.h
- \brief USB FS&HS cell registers definition and handle macros
-*/
-
-/*
- Copyright (C) 2016 GigaDevice
-
- 2016-08-15, V1.0.0, firmware for GD32F4xx
-*/
-
-#ifndef USB_REGS_H
-#define USB_REGS_H
-
-#include "usb_conf.h"
-
-#define USBFS USBFS_BASE /*!< base address of USBFS registers */
-#define USBHS USBHS_BASE /*!< base address of USBHS registers */
-
-#ifdef USE_USBFS
- #define USBX USBFS /*!< USB full speed mode */
-#endif /* USE_USBFS */
-
-#ifdef USE_USBHS
- #define USBX USBHS /*!< USB high speed mode */
-#endif /* USE_USBHS */
-
-/* registers location definitions */
-#define LOCATE_DIEPTFLEN(x) (0x104U + 4U * ((x) - 1U)) /*!< locate device IN endpoint-x transfer length registers */
-#define LOCATE_HCHCTL(x) (0x500U + 0x20U * (x)) /*!< locate host channel-x control registers */
-#define LOCATE_HCHSTCTL(x) (0x504U + 0x20U * (x)) /*!< locate host channel-x split transaction control registers */
-#define LOCATE_HCHINTF(x) (0x508U + 0x20U * (x)) /*!< locate host channel-x interrupt flag registers */
-#define LOCATE_HCHINTEN(x) (0x50CU + 0x20U * (x)) /*!< locate host channel-x interrupt enable registers */
-#define LOCATE_HCHLEN(x) (0x510U + 0x20U * (x)) /*!< locate host channel-x transfer length registers */
-#define LOCATE_HCHDMAADDR(x) (0x514U + 0x20U * (x)) /*!< locate host channel-x DMA address registers */
-#define LOCATE_DIEPCTL(x) (0x900U + 0x20U * (x)) /*!< locate device IN endpoint-x control registers */
-#define LOCATE_DOEPCTL(x) (0xB00U + 0x20U * (x)) /*!< locate device OUT endpoint-x control registers */
-#define LOCATE_DIEPINTF(x) (0x908U + 0x20U * (x)) /*!< locate device IN endpoint-x interrupt flag registers */
-#define LOCATE_DOEPINTF(x) (0xB08U + 0x20U * (x)) /*!< locate device OUT endpoint-x interrupt flag registers */
-#define LOCATE_DIEPLEN(x) (0x910U + 0x20U * (x)) /*!< locate device IN endpoint-x transfer length registers */
-#define LOCATE_DOEPLEN(x) (0xB10U + 0x20U * (x)) /*!< locate device OUT endpoint-x transfer length registers */
-#define LOCATE_DIEPxDMAADDR(x) (0x914U + 0x20U * (x)) /*!< locate device IN endpoint-x DMA address registers */
-#define LOCATE_DOEPxDMAADDR(x) (0xB14U + 0x20U * (x)) /*!< locate device OUT endpoint-x DMA address registers */
-#define LOCATE_DIEPxTFSTAT(x) (0x918U + 0x20U * (x)) /*!< locate Device IN endpoint-x transmit FIFO status register */
-#define LOCATE_FIFO(x) (((x) + 1U) << 12U) /*!< locate FIFO-x memory */
-
-/* registers definitions */
-#define USB_GOTGCS REG32(((USBX) + 0x0000U)) /*!< global OTG control and status register */
-#define USB_GOTGINTF REG32(((USBX) + 0x0004U)) /*!< global OTG interrupt flag register */
-#define USB_GAHBCS REG32(((USBX) + 0x0008U)) /*!< global AHB control and status register */
-#define USB_GUSBCS REG32(((USBX) + 0x000CU)) /*!< global USB control and status register */
-#define USB_GRSTCTL REG32(((USBX) + 0x0010U)) /*!< global reset control register */
-#define USB_GINTF REG32(((USBX) + 0x0014U)) /*!< global interrupt flag register */
-#define USB_GINTEN REG32(((USBX) + 0x0018U)) /*!< global interrupt enable register */
-#define USB_GRSTATR REG32(((USBX) + 0x001CU)) /*!< global receive status read register */
-#define USB_GRSTATP REG32(((USBX) + 0x0020U)) /*!< global receive status read and pop register */
-#define USB_GRFLEN REG32(((USBX) + 0x0024U)) /*!< global receive FIFO length register */
-#define USB_HNPTFLEN REG32(((USBX) + 0x0028U)) /*!< host non-periodic transmit FIFO length register */
-#define USB_DIEP0TFLEN REG32(((USBX) + 0x0028U)) /*!< device IN endpoint 0 transmit FIFO length register */
-#define USB_HNPTFQSTAT REG32(((USBX) + 0x002CU)) /*!< host non-periodic transmint FIFO/queue status register */
-#define USB_GCCFG REG32(((USBX) + 0x0038U)) /*!< global core configuration register */
-#define USB_CID REG32(((USBX) + 0x003CU)) /*!< core id register */
-#define USB_HPTFLEN REG32(((USBX) + 0x0100U)) /*!< host periodic transmit FIFO length register */
-#define USB_DIEPxTFLEN(x) REG32(((USBX) + LOCATE_DIEPTFLEN(x))) /*!< device IN endpoint transmit FIFO length register */
-
-#define USB_HCTL REG32(((USBX) + 0x0400U)) /*!< host control register */
-#define USB_HFT REG32(((USBX) + 0x0404U)) /*!< host frame interval register */
-#define USB_HFINFR REG32(((USBX) + 0x0408U)) /*!< host frame information remaining register */
-#define USB_HPTFQSTAT REG32(((USBX) + 0x0410U)) /*!< host periodic transmit FIFO/queue status register */
-#define USB_HACHINT REG32(((USBX) + 0x0414U)) /*!< host all channels interrupt register */
-#define USB_HACHINTEN REG32(((USBX) + 0x0418U)) /*!< host all channels interrupt enable register */
-#define USB_HPCS REG32(((USBX) + 0x0440U)) /*!< host port control and status register */
-#define USB_HCHxCTL(x) REG32(((USBX) + LOCATE_HCHCTL(x))) /*!< host channel-x control register */
-#define USB_HCHxSTCTL(x) REG32(((USBX) + LOCATE_HCHSTCTL(x))) /*!< host channel-x split transaction control register */
-#define USB_HCHxINTF(x) REG32(((USBX) + LOCATE_HCHINTF(x))) /*!< host channel-x interrupt flag register */
-#define USB_HCHxINTEN(x) REG32(((USBX) + LOCATE_HCHINTEN(x))) /*!< host channel-x interrupt enable register */
-#define USB_HCHxLEN(x) REG32(((USBX) + LOCATE_HCHLEN(x))) /*!< host channel-x tranfer length register */
-#define USB_HCHxDMAADDR(x) REG32(((USBX) + LOCATE_HCHDMAADDR(x))) /*!< host channel-x DMA address register */
-
-#define USB_DCFG REG32(((USBX) + 0x0800U)) /*!< device configuration register */
-#define USB_DCTL REG32(((USBX) + 0x0804U)) /*!< device control register */
-#define USB_DSTAT REG32(((USBX) + 0x0808U)) /*!< device status register */
-#define USB_DIEPINTEN REG32(((USBX) + 0x0810U)) /*!< device IN endpoint common interrupt enable register */
-#define USB_DOEPINTEN REG32(((USBX) + 0x0814U)) /*!< device OUT endpoint common interrupt enable register */
-#define USB_DAEPINT REG32(((USBX) + 0x0818U)) /*!< device all endpoints interrupt register */
-#define USB_DAEPINTEN REG32(((USBX) + 0x081CU)) /*!< device all endpoints interrupt enable register */
-#define USB_DVBUSDT REG32(((USBX) + 0x0828U)) /*!< device vbus discharge time register */
-#define USB_DVBUSPT REG32(((USBX) + 0x082CU)) /*!< device vbus pulsing time register */
-#define USB_DIEPFEINTEN REG32(((USBX) + 0x0834U)) /*!< device IN endpoint FIFO empty interrupt enable register */
-#define USB_DEP1INT REG32(((USBX) + 0x0838U)) /*!< device endpoint 1 interrupt register */
-#define USB_DEP1INTEN REG32(((USBX) + 0x083CU)) /*!< device endpoint 1 interrupt enable register */
-#define USB_DIEP1INTEN REG32(((USBX) + 0x0844U)) /*!< device IN endpoint 1 interrupt enable register */
-#define USB_DOEP1INTEN REG32(((USBX) + 0x0884U)) /*!< device OUT endpoint 1 interrupt enable register */
-#define USB_DIEP0CTL REG32(((USBX) + 0x0900U)) /*!< device IN endpoint 0 control register */
-#define USB_DIEP0LEN REG32(((USBX) + 0x0910U)) /*!< device IN endpoint 0 transfer length register */
-#define USB_DOEP0CTL REG32(((USBX) + 0x0B00U)) /*!< device OUT endpoint 0 control register */
-#define USB_DOEP0LEN REG32(((USBX) + 0x0B10U)) /*!< device OUT endpoint 0 transfer length register */
-#define USB_DIEPxCTL(x) REG32(((USBX) + LOCATE_DIEPCTL(x))) /*!< device IN endpoint-x control register */
-#define USB_DOEPxCTL(x) REG32(((USBX) + LOCATE_DOEPCTL(x))) /*!< device OUT endpoint-x control register */
-#define USB_DIEPxINTF(x) REG32(((USBX) + LOCATE_DIEPINTF(x))) /*!< device IN endpoint-x interrupt flag register */
-#define USB_DOEPxINTF(x) REG32(((USBX) + LOCATE_DOEPINTF(x))) /*!< device OUT endpoint-x interrupt flag register */
-#define USB_DIEPxLEN(x) REG32(((USBX) + LOCATE_DIEPLEN(x))) /*!< device IN endpoint-x transfer length register */
-#define USB_DOEPxLEN(x) REG32(((USBX) + LOCATE_DOEPLEN(x))) /*!< device OUT endpoint-x transfer length register */
-#define USB_DIEPxDMAADDR(x) REG32(((USBX) + LOCATE_DIEPxDMAADDR(x)))/*!< device IN endpoint-x DMA address register */
-#define USB_DOEPxDMAADDR(x) REG32(((USBX) + LOCATE_DOEPxDMAADDR(x)))/*!< device OUT endpoint-x DMA address register */
-#define USB_DIEPxTFSTAT(x) REG32(((USBX) + LOCATE_DIEPxTFSTAT(x))) /*!< device IN endpoint-x transmit FIFO status register */
-
-#define USB_PWRCLKCTL REG32(((USBX) + 0x0E00U)) /*!< power and clock register */
-
-#define USB_FIFO(x) (&REG32(((USBX) + LOCATE_FIFO(x)))) /*!< FIFO memory */
-
-/* global OTG control and status register bits definitions */
-#define GOTGCS_BSV BIT(19) /*!< B-Session Valid */
-#define GOTGCS_ASV BIT(18) /*!< A-session valid */
-#define GOTGCS_DI BIT(17) /*!< debounce interval */
-#define GOTGCS_CIDPS BIT(16) /*!< id pin status */
-#define GOTGCS_DHNPEN BIT(11) /*!< device HNP enable */
-#define GOTGCS_HHNPEN BIT(10) /*!< host HNP enable */
-#define GOTGCS_HNPREQ BIT(9) /*!< HNP request */
-#define GOTGCS_HNPS BIT(8) /*!< HNP successes */
-#define GOTGCS_SRPREQ BIT(1) /*!< SRP request */
-#define GOTGCS_SRPS BIT(0) /*!< SRP successes */
-
-/* global OTG interrupt flag register bits definitions */
-#define GOTGINTF_DF BIT(19) /*!< debounce finish */
-#define GOTGINTF_ADTO BIT(18) /*!< A-device timeout */
-#define GOTGINTF_HNPDET BIT(17) /*!< host negotiation request detected */
-#define GOTGINTF_HNPEND BIT(9) /*!< HNP end */
-#define GOTGINTF_SRPEND BIT(8) /*!< SRP end */
-#define GOTGINTF_SESEND BIT(2) /*!< session end */
-
-/* global AHB control and status register bits definitions */
-#define GAHBCS_PTXFTH BIT(8) /*!< periodic Tx FIFO threshold */
-#define GAHBCS_TXFTH BIT(7) /*!< tx FIFO threshold */
-#define GAHBCS_DMAEN BIT(5) /*!< DMA function Enable */
-#define GAHBCS_BURST BITS(1, 4) /*!< the AHB burst type used by DMA */
-#define GAHBCS_GINTEN BIT(0) /*!< global interrupt enable */
-
-/* global USB control and status register bits definitions */
-#define GUSBCS_FDM BIT(30) /*!< force device mode */
-#define GUSBCS_FHM BIT(29) /*!< force host mode */
-#define GUSBCS_ULPIEOI BIT(21) /*!< ULPI external over-current indicator */
-#define GUSBCS_ULPIEVD BIT(20) /*!< ULPI external VBUS driver */
-#define GUSBCS_UTT BITS(10, 13) /*!< USB turnaround time */
-#define GUSBCS_HNPCEN BIT(9) /*!< HNP capability enable */
-#define GUSBCS_SRPCEN BIT(8) /*!< SRP capability enable */
-#define GUSBCS_EMBPHY BIT(6) /*!< embedded PHY selected */
-#define GUSBCS_TOC BITS(0, 2) /*!< timeout calibration */
-
-/* global reset control register bits definitions */
-#define GRSTCTL_DMAIDL BIT(31) /*!< DMA idle state */
-#define GRSTCTL_DMABSY BIT(30) /*!< DMA busy */
-#define GRSTCTL_TXFNUM BITS(6, 10) /*!< tx FIFO number */
-#define GRSTCTL_TXFF BIT(5) /*!< tx FIFO flush */
-#define GRSTCTL_RXFF BIT(4) /*!< rx FIFO flush */
-#define GRSTCTL_HFCRST BIT(2) /*!< host frame counter reset */
-#define GRSTCTL_HCSRST BIT(1) /*!< HCLK soft reset */
-#define GRSTCTL_CSRST BIT(0) /*!< core soft reset */
-
-/* global interrupt flag register bits definitions */
-#define GINTF_WKUPIF BIT(31) /*!< wakeup interrupt flag */
-#define GINTF_SESIF BIT(30) /*!< session interrupt flag */
-#define GINTF_DISCIF BIT(29) /*!< disconnect interrupt flag */
-#define GINTF_IDPSC BIT(28) /*!< id pin status change */
-#define GINTF_PTXFEIF BIT(26) /*!< periodic tx FIFO empty interrupt flag */
-#define GINTF_HCIF BIT(25) /*!< host channels interrupt flag */
-#define GINTF_HPIF BIT(24) /*!< host port interrupt flag */
-#define GINTF_PXNCIF BIT(21) /*!< periodic transfer not complete interrupt flag */
-#define GINTF_ISOONCIF BIT(21) /*!< isochronous OUT transfer not complete interrupt flag */
-#define GINTF_ISOINCIF BIT(20) /*!< isochronous IN transfer not complete interrupt flag */
-#define GINTF_OEPIF BIT(19) /*!< OUT endpoint interrupt flag */
-#define GINTF_IEPIF BIT(18) /*!< IN endpoint interrupt flag */
-#define GINTF_EOPFIF BIT(15) /*!< end of periodic frame interrupt flag */
-#define GINTF_ISOOPDIF BIT(14) /*!< isochronous OUT packet dropped interrupt flag */
-#define GINTF_ENUMFIF BIT(13) /*!< enumeration finished */
-#define GINTF_RST BIT(12) /*!< USB reset */
-#define GINTF_SP BIT(11) /*!< USB suspend */
-#define GINTF_ESP BIT(10) /*!< early suspend */
-#define GINTF_GONAK BIT(7) /*!< global OUT NAK effective */
-#define GINTF_GNPINAK BIT(6) /*!< global IN non-periodic NAK effective */
-#define GINTF_NPTXFEIF BIT(5) /*!< non-periodic tx FIFO empty interrupt flag */
-#define GINTF_RXFNEIF BIT(4) /*!< rx FIFO non-empty interrupt flag */
-#define GINTF_SOF BIT(3) /*!< start of frame */
-#define GINTF_OTGIF BIT(2) /*!< OTG interrupt flag */
-#define GINTF_MFIF BIT(1) /*!< mode fault interrupt flag */
-#define GINTF_COPM BIT(0) /*!< current operation mode */
-
-/* global interrupt enable register bits definitions */
-#define GINTEN_WKUPIE BIT(31) /*!< wakeup interrupt enable */
-#define GINTEN_SESIE BIT(30) /*!< session interrupt enable */
-#define GINTEN_DISCIE BIT(29) /*!< disconnect interrupt enable */
-#define GINTEN_IDPSCIE BIT(28) /*!< id pin status change interrupt enable */
-#define GINTEN_PTXFEIE BIT(26) /*!< periodic tx FIFO empty interrupt enable */
-#define GINTEN_HCIE BIT(25) /*!< host channels interrupt enable */
-#define GINTEN_HPIE BIT(24) /*!< host port interrupt enable */
-#define GINTEN_IPXIE BIT(21) /*!< periodic transfer not complete interrupt enable */
-#define GINTEN_ISOONCIE BIT(21) /*!< isochronous OUT transfer not complete interrupt enable */
-#define GINTEN_ISOINCIE BIT(20) /*!< isochronous IN transfer not complete interrupt enable */
-#define GINTEN_OEPIE BIT(19) /*!< OUT endpoints interrupt enable */
-#define GINTEN_IEPIE BIT(18) /*!< IN endpoints interrupt enable */
-#define GINTEN_EOPFIE BIT(15) /*!< end of periodic frame interrupt enable */
-#define GINTEN_ISOOPDIE BIT(14) /*!< isochronous OUT packet dropped interrupt enable */
-#define GINTEN_ENUMFIE BIT(13) /*!< enumeration finish enable */
-#define GINTEN_RSTIE BIT(12) /*!< USB reset interrupt enable */
-#define GINTEN_SPIE BIT(11) /*!< USB suspend interrupt enable */
-#define GINTEN_ESPIE BIT(10) /*!< early suspend interrupt enable */
-#define GINTEN_GONAKIE BIT(7) /*!< global OUT NAK effective interrupt enable */
-#define GINTEN_GNPINAKIE BIT(6) /*!< global non-periodic IN NAK effective interrupt enable */
-#define GINTEN_NPTXFEIE BIT(5) /*!< non-periodic Tx FIFO empty interrupt enable */
-#define GINTEN_RXFNEIE BIT(4) /*!< receive FIFO non-empty interrupt enable */
-#define GINTEN_SOFIE BIT(3) /*!< start of frame interrupt enable */
-#define GINTEN_OTGIE BIT(2) /*!< OTG interrupt enable */
-#define GINTEN_MFIE BIT(1) /*!< mode fault interrupt enable */
-
-/* global receive status debug read register bits definitions */
-#define GRSTATR_RPCKST BITS(17, 20) /*!< received packet status */
-#define GRSTATR_DPID BITS(15, 16) /*!< data PID */
-#define GRSTATR_BCOUNT BITS(4, 14) /*!< byte count */
-#define GRSTATR_CNUM BITS(0, 3) /*!< channel number */
-
-/* global status read and pop register bits definitions */
-#define GRSTATP_RPCKST BITS(17, 20) /*!< received packet status */
-#define GRSTATP_DPID BITS(15, 16) /*!< data PID */
-#define GRSTATP_BCOUNT BITS(4, 14) /*!< byte count */
-#define GRSTATP_EPNUM BITS(0, 3) /*!< endpoint number */
-
-/* global receive FIFO length register bits definitions */
-#define GRFLEN_RXFD BITS(0, 15) /*!< rx FIFO depth */
-
-/* host non-periodic transmit FIFO length register bits definitions */
-#define HNPTFLEN_HNPTXFD BITS(16, 31) /*!< non-periodic Tx FIFO depth */
-#define HNPTFLEN_HNPTXRSAR BITS(0, 15) /*!< non-periodic Tx RAM start address */
-
-/* IN endpoint 0 transmit FIFO length register bits definitions */
-#define DIEP0TFLEN_IEP0TXFD BITS(16, 31) /*!< IN Endpoint 0 Tx FIFO depth */
-#define DIEP0TFLEN_IEP0TXRSAR BITS(0, 15) /*!< IN Endpoint 0 TX RAM start address */
-
-/* host non-periodic transmit FIFO/queue status register bits definitions */
-#define HNPTFQSTAT_NPTXRQTOP BITS(24, 30) /*!< top entry of the non-periodic Tx request queue */
-#define HNPTFQSTAT_NPTXRQS BITS(16, 23) /*!< non-periodic Tx request queue space */
-#define HNPTFQSTAT_NPTXFS BITS(0, 15) /*!< non-periodic Tx FIFO space */
-#define HNPTFQSTAT_CNUM BITS(27, 30) /*!< channel number*/
-#define HNPTFQSTAT_EPNUM BITS(27, 30) /*!< endpoint number */
-#define HNPTFQSTAT_TYPE BITS(25, 26) /*!< token type */
-#define HNPTFQSTAT_TMF BIT(24) /*!< terminate flag */
-
-/* global core configuration register bits definitions */
-#define GCCFG_VBUSIG BIT(21) /*!< vbus ignored */
-#define GCCFG_SOFOEN BIT(20) /*!< SOF output enable */
-#define GCCFG_VBUSBCEN BIT(19) /*!< the VBUS B-device comparer enable */
-#define GCCFG_VBUSACEN BIT(18) /*!< the VBUS A-device comparer enable */
-#define GCCFG_PWRON BIT(16) /*!< power on */
-
-/* core ID register bits definitions */
-#define CID_CID BITS(0, 31) /*!< core ID */
-
-/* host periodic transmit FIFO length register bits definitions */
-#define HPTFLEN_HPTXFD BITS(16, 31) /*!< host periodic Tx FIFO depth */
-#define HPTFLEN_HPTXFSAR BITS(0, 15) /*!< host periodic Tx RAM start address */
-
-/* device IN endpoint transmit FIFO length register bits definitions */
-#define DIEPTFLEN_IEPTXFD BITS(16, 31) /*!< IN endpoint Tx FIFO x depth */
-#define DIEPTFLEN_IEPTXRSAR BITS(0, 15) /*!< IN endpoint FIFOx Tx x RAM start address */
-
-/* host control register bits definitions */
-#define HCTL_SPDFSLS BIT(2) /*!< speed limited to FS and LS */
-#define HCTL_CLKSEL BITS(0, 1) /*!< clock select for USB clock */
-
-/* host frame interval register bits definitions */
-#define HFT_FRI BITS(0, 15) /*!< frame interval */
-
-/* host frame information remaining register bits definitions */
-#define HFINFR_FRT BITS(16, 31) /*!< frame remaining time */
-#define HFINFR_FRNUM BITS(0, 15) /*!< frame number */
-
-/* host periodic transmit FIFO/queue status register bits definitions */
-#define HPTFQSTAT_PTXREQT BITS(24, 31) /*!< top entry of the periodic Tx request queue */
-#define HPTFQSTAT_PTXREQS BITS(16, 23) /*!< periodic Tx request queue space */
-#define HPTFQSTAT_PTXFS BITS(0, 15) /*!< periodic Tx FIFO space */
-#define HPTFQSTAT_OEFRM BIT(31) /*!< odd/eveb frame */
-#define HPTFQSTAT_CNUM BITS(27, 30) /*!< channel number */
-#define HPTFQSTAT_EPNUM BITS(27, 30) /*!< endpoint number */
-#define HPTFQSTAT_TYPE BITS(25, 26) /*!< token type */
-#define HPTFQSTAT_TMF BIT(24) /*!< terminate flag */
-
-/* host all channels interrupt register bits definitions */
-#define HACHINT_HACHINT BITS(0, 11) /*!< host all channel interrupts */
-
-/* host all channels interrupt enable register bits definitions */
-#define HACHINTEN_CINTEN BITS(0, 11) /*!< channel interrupt enable */
-
-/* host port control and status register bits definitions */
-#define HPCS_PS BITS(17, 18) /*!< port speed */
-#define HPCS_PP BIT(12) /*!< port power */
-#define HPCS_PLST BITS(10, 11) /*!< port line status */
-#define HPCS_PRST BIT(8) /*!< port reset */
-#define HPCS_PSP BIT(7) /*!< port suspend */
-#define HPCS_PREM BIT(6) /*!< port resume */
-#define HPCS_PEDC BIT(3) /*!< port enable/disable change */
-#define HPCS_PE BIT(2) /*!< port enable */
-#define HPCS_PCD BIT(1) /*!< port connect detected */
-#define HPCS_PCST BIT(0) /*!< port connect status */
-
-/* host channel-x control register bits definitions */
-#define HCHCTL_CEN BIT(31) /*!< channel enable */
-#define HCHCTL_CDIS BIT(30) /*!< channel disable */
-#define HCHCTL_ODDFRM BIT(29) /*!< odd frame */
-#define HCHCTL_DAR BITS(22, 28) /*!< device address */
-#define HCHCTL_MPC BITS(20, 21) /*!< multiple packet count */
-#define HCHCTL_EPTYPE BITS(18, 19) /*!< endpoint type */
-#define HCHCTL_LSD BIT(17) /*!< low-speed device */
-#define HCHCTL_EPDIR BIT(15) /*!< endpoint direction */
-#define HCHCTL_EPNUM BITS(11, 14) /*!< endpoint number */
-#define HCHCTL_MPL BITS(0, 10) /*!< maximum packet length */
-
-/* host channel-x split transaction register bits definitions */
-#define HCHSTCTL_SPLEN BIT(31) /*!< enable high-speed split transaction */
-#define HCHSTCTL_CSPLT BIT(16) /*!< complete-split enable */
-#define HCHSTCTL_ISOPCE BITS(14, 15) /*!< isochronous OUT payload continuation encoding */
-#define HCHSTCTL_HADDR BITS(7, 13) /*!< HUB address */
-#define HCHSTCTL_PADDR BITS(0, 6) /*!< port address */
-
-/* host channel-x interrupt flag register bits definitions */
-#define HCHINTF_DTER BIT(10) /*!< data toggle error */
-#define HCHINTF_REQOVR BIT(9) /*!< request queue overrun */
-#define HCHINTF_BBER BIT(8) /*!< babble error */
-#define HCHINTF_USBER BIT(7) /*!< USB bus Error */
-#define HCHINTF_NYET BIT(6) /*!< NYET */
-#define HCHINTF_ACK BIT(5) /*!< ACK */
-#define HCHINTF_NAK BIT(4) /*!< NAK */
-#define HCHINTF_STALL BIT(3) /*!< STALL */
-#define HCHINTF_DMAER BIT(2) /*!< DMA error */
-#define HCHINTF_CH BIT(1) /*!< channel halted */
-#define HCHINTF_TF BIT(0) /*!< transfer finished */
-
-/* host channel-x interrupt enable register bits definitions */
-#define HCHINTEN_DTERIE BIT(10) /*!< data toggle error interrupt enable */
-#define HCHINTEN_REQOVRIE BIT(9) /*!< request queue overrun interrupt enable */
-#define HCHINTEN_BBERIE BIT(8) /*!< babble error interrupt enable */
-#define HCHINTEN_USBERIE BIT(7) /*!< USB bus error interrupt enable */
-#define HCHINTEN_NYETIE BIT(6) /*!< NYET interrupt enable */
-#define HCHINTEN_ACKIE BIT(5) /*!< ACK interrupt enable */
-#define HCHINTEN_NAKIE BIT(4) /*!< NAK interrupt enable */
-#define HCHINTEN_STALLIE BIT(3) /*!< STALL interrupt enable */
-#define HCHINTEN_DMAERIE BIT(2) /*!< DMA error interrupt enable */
-#define HCHINTEN_CHIE BIT(1) /*!< channel halted interrupt enable */
-#define HCHINTEN_TFIE BIT(0) /*!< transfer finished interrupt enable */
-
-/* host channel-x transfer length register bits definitions */
-#define HCHLEN_PING BIT(31) /*!< PING token request */
-#define HCHLEN_DPID BITS(29, 30) /*!< data PID */
-#define HCHLEN_PCNT BITS(19, 28) /*!< packet count */
-#define HCHLEN_TLEN BITS(0, 18) /*!< transfer length */
-
-/* host channel-x DMA address register bits definitions */
-#define HCHDMAADDR_DMAADDR BITS(0, 31) /*!< DMA address */
-
-/* device control and status registers */
-/* device configuration registers bits definitions */
-#define DCFG_EOPFT BITS(11, 12) /*!< end of periodic frame time */
-#define DCFG_DAR BITS(4, 10) /*!< device address */
-#define DCFG_NZLSOH BIT(2) /*!< non-zero-length status OUT handshake */
-#define DCFG_DS BITS(0, 1) /*!< device speed */
-
-/* device control registers bits definitions */
-#define DCTL_POIF BIT(11) /*!< power-on initialization finished */
-#define DCTL_CGONAK BIT(10) /*!< clear global OUT NAK */
-#define DCTL_SGONAK BIT(9) /*!< set global OUT NAK */
-#define DCTL_CGINAK BIT(8) /*!< clear global IN NAK */
-#define DCTL_SGINAK BIT(7) /*!< set global IN NAK */
-#define DCTL_GONS BIT(3) /*!< global OUT NAK status */
-#define DCTL_GINS BIT(2) /*!< global IN NAK status */
-#define DCTL_SD BIT(1) /*!< soft disconnect */
-#define DCTL_RWKUP BIT(0) /*!< remote wakeup */
-
-/* device status registers bits definitions */
-#define DSTAT_FNRSOF BITS(8, 21) /*!< the frame number of the received SOF. */
-#define DSTAT_ES BITS(1, 2) /*!< enumerated speed */
-#define DSTAT_SPST BIT(0) /*!< suspend status */
-
-/* device IN endpoint common interrupt enable registers bits definitions */
-#define DIEPINTEN_NAKEN BIT(13) /*!< NAK handshake sent by USBHS interrupt enable bit */
-#define DIEPINTEN_TXFEEN BIT(7) /*!< transmit FIFO empty interrupt enable bit */
-#define DIEPINTEN_IEPNEEN BIT(6) /*!< IN endpoint NAK effective interrupt enable bit */
-#define DIEPINTEN_EPTXFUDEN BIT(4) /*!< endpoint Tx FIFO underrun interrupt enable bit */
-#define DIEPINTEN_CITOEN BIT(3) /*!< control In Timeout interrupt enable bit */
-#define DIEPINTEN_EPDISEN BIT(1) /*!< endpoint disabled interrupt enable bit */
-#define DIEPINTEN_TFEN BIT(0) /*!< transfer finished interrupt enable bit */
-
-/* device OUT endpoint common interrupt enable registers bits definitions */
-#define DOEPINTEN_NYETEN BIT(14) /*!< NYET handshake is sent interrupt enable bit */
-#define DOEPINTEN_BTBSTPEN BIT(6) /*!< back-to-back SETUP packets interrupt enable bit */
-#define DOEPINTEN_EPRXFOVREN BIT(4) /*!< endpoint Rx FIFO overrun interrupt enable bit */
-#define DOEPINTEN_STPFEN BIT(3) /*!< SETUP phase finished interrupt enable bit */
-#define DOEPINTEN_EPDISEN BIT(1) /*!< endpoint disabled interrupt enable bit */
-#define DOEPINTEN_TFEN BIT(0) /*!< transfer finished interrupt enable bit */
-
-/* device all endpoints interrupt registers bits definitions */
-#define DAEPINT_OEPITB BITS(16, 21) /*!< device all OUT endpoint interrupt bits */
-#define DAEPINT_IEPITB BITS(0, 5) /*!< device all IN endpoint interrupt bits */
-
-/* device all endpoints interrupt enable registers bits definitions */
-#define DAEPINTEN_OEPIE BITS(16, 21) /*!< OUT endpoint interrupt enable */
-#define DAEPINTEN_IEPIE BITS(0, 3) /*!< IN endpoint interrupt enable */
-
-/* device Vbus discharge time registers bits definitions */
-#define DVBUSDT_DVBUSDT BITS(0, 15) /*!< device VBUS discharge time */
-
-/* device Vbus pulsing time registers bits definitions */
-#define DVBUSPT_DVBUSPT BITS(0, 11) /*!< device VBUS pulsing time */
-
-/* device IN endpoint FIFO empty interrupt enable register bits definitions */
-#define DIEPFEINTEN_IEPTXFEIE BITS(0, 5) /*!< IN endpoint Tx FIFO empty interrupt enable bits */
-
-/* device endpoint 1 interrupt register bits definitions */
-#define DEP1INT_OEP1INT BIT(17) /*!< OUT Endpoint 1 interrupt */
-#define DEP1INT_IEP1INT BIT(1) /*!< IN Endpoint 1 interrupt */
-
-/* device endpoint 1 interrupt register enable bits definitions */
-#define DEP1INTEN_OEP1INTEN BIT(17) /*!< OUT Endpoint 1 interrupt enable */
-#define DEP1INTEN_IEP1INTEN BIT(1) /*!< IN Endpoint 1 interrupt enable */
-
-/* device IN endpoint 1 interrupt enable register bits definitions */
-#define DIEP1INTEN_NAKEN BIT(13) /*!< NAK handshake sent by USBHS interrupt enable bit */
-#define DIEP1INTEN_IEPNEEN BIT(6) /*!< IN endpoint NAK effective interrupt enable bit */
-#define DIEP1INTEN_EPTXFUDEN BIT(4) /*!< endpoint Tx FIFO underrun interrupt enable bit */
-#define DIEP1INTEN_CITOEN BIT(3) /*!< control In Timeout interrupt enable bit */
-#define DIEP1INTEN_EPDISEN BIT(1) /*!< endpoint disabled interrupt enable bit */
-#define DIEP1INTEN_TFEN BIT(0) /*!< transfer finished interrupt enable bit */
-
-/* device OUT endpoint 1 interrupt enable register bits definitions */
-#define DOEP1INTEN_NYETEN BIT(14) /*!< NYET handshake is sent interrupt enable bit */
-#define DOEP1INTEN_BTBSTPEN BIT(6) /*!< back-to-back SETUP packets interrupt enable bit */
-#define DOEP1INTEN_EPRXOVREN BIT(4) /*!< endpoint Rx FIFO over run interrupt enable bit */
-#define DOEP1INTEN_STPFEN BIT(3) /*!< SETUP phase finished interrupt enable bit */
-#define DOEP1INTEN_EPDISEN BIT(1) /*!< endpoint disabled interrupt enable bit */
-#define DOEP1INTEN_TFEN BIT(0) /*!< back-to-back SETUP packets interrupt enable bit */
-
-/* device IN endpoint 0 control register bits definitions */
-#define DIEP0CTL_EPEN BIT(31) /*!< endpoint enable */
-#define DIEP0CTL_EPD BIT(30) /*!< endpoint disable */
-#define DIEP0CTL_SNAK BIT(27) /*!< set NAK */
-#define DIEP0CTL_CNAK BIT(26) /*!< clear NAK */
-#define DIEP0CTL_TXFNUM BITS(22, 25) /*!< tx FIFO number */
-#define DIEP0CTL_STALL BIT(21) /*!< STALL handshake */
-#define DIEP0CTL_EPTYPE BITS(18, 19) /*!< endpoint type */
-#define DIEP0CTL_NAKS BIT(17) /*!< NAK status */
-#define DIEP0CTL_EPACT BIT(15) /*!< endpoint active */
-#define DIEP0CTL_MPL BITS(0, 1) /*!< maximum packet length */
-
-/* device IN endpoint x control register bits definitions */
-#define DIEPCTL_EPEN BIT(31) /*!< endpoint enable */
-#define DIEPCTL_EPD BIT(30) /*!< endpoint disable */
-#define DIEPCTL_SODDFRM BIT(29) /*!< set odd frame */
-#define DIEPCTL_SD1PID BIT(29) /*!< set DATA1 PID */
-#define DIEPCTL_SEVNFRM BIT(28) /*!< set even frame */
-#define DIEPCTL_SD0PID BIT(28) /*!< set DATA0 PID */
-#define DIEPCTL_SNAK BIT(27) /*!< set NAK */
-#define DIEPCTL_CNAK BIT(26) /*!< clear NAK */
-#define DIEPCTL_TXFNUM BITS(22, 25) /*!< tx FIFO number */
-#define DIEPCTL_STALL BIT(21) /*!< STALL handshake */
-#define DIEPCTL_EPTYPE BITS(18, 19) /*!< endpoint type */
-#define DIEPCTL_NAKS BIT(17) /*!< NAK status */
-#define DIEPCTL_EOFRM BIT(16) /*!< even/odd frame */
-#define DIEPCTL_DPID BIT(16) /*!< endpoint data PID */
-#define DIEPCTL_EPACT BIT(15) /*!< endpoint active */
-#define DIEPCTL_MPL BITS(0, 10) /*!< maximum packet length */
-
-/* device OUT endpoint 0 control register bits definitions */
-#define DOEP0CTL_EPEN BIT(31) /*!< endpoint enable */
-#define DOEP0CTL_EPD BIT(30) /*!< endpoint disable */
-#define DOEP0CTL_SNAK BIT(27) /*!< set NAK */
-#define DOEP0CTL_CNAK BIT(26) /*!< clear NAK */
-#define DOEP0CTL_STALL BIT(21) /*!< STALL handshake */
-#define DOEP0CTL_SNOOP BIT(20) /*!< snoop mode */
-#define DOEP0CTL_EPTYPE BITS(18, 19) /*!< endpoint type */
-#define DOEP0CTL_NAKS BIT(17) /*!< NAK status */
-#define DOEP0CTL_EPACT BIT(15) /*!< endpoint active */
-#define DOEP0CTL_MPL BITS(0, 1) /*!< maximum packet length */
-
-/* device OUT endpoint-x control register bits definitions */
-#define DOEPCTL_EPEN BIT(31) /*!< endpoint enable */
-#define DOEPCTL_EPD BIT(30) /*!< endpoint disable */
-#define DOEPCTL_SODDFRM BIT(29) /*!< set odd frame */
-#define DOEPCTL_SD1PID BIT(29) /*!< set DATA1 PID */
-#define DOEPCTL_SEVNFRM BIT(28) /*!< set even frame */
-#define DOEPCTL_SD0PID BIT(28) /*!< set DATA0 PID */
-#define DOEPCTL_SNAK BIT(27) /*!< set NAK */
-#define DOEPCTL_CNAK BIT(26) /*!< clear NAK */
-#define DOEPCTL_STALL BIT(21) /*!< STALL handshake */
-#define DOEPCTL_SNOOP BIT(20) /*!< snoop mode */
-#define DOEPCTL_EPTYPE BITS(18, 19) /*!< endpoint type */
-#define DOEPCTL_NAKS BIT(17) /*!< NAK status */
-#define DOEPCTL_EOFRM BIT(16) /*!< even/odd frame */
-#define DOEPCTL_DPID BIT(16) /*!< endpoint data PID */
-#define DOEPCTL_EPACT BIT(15) /*!< endpoint active */
-#define DOEPCTL_MPL BITS(0, 10) /*!< maximum packet length */
-
-/* device IN endpoint-x interrupt flag register bits definitions */
-#define DIEPINTF_NAK BIT(13) /*!< NAK handshake sent by USBHS */
-#define DIEPINTF_TXFE BIT(7) /*!< transmit FIFO empty */
-#define DIEPINTF_IEPNE BIT(6) /*!< IN endpoint NAK effective */
-#define DIEPINTF_EPTXFUD BIT(4) /*!< endpoint Tx FIFO underrun */
-#define DIEPINTF_CITO BIT(3) /*!< control In Timeout interrupt */
-#define DIEPINTF_EPDIS BIT(1) /*!< endpoint disabled */
-#define DIEPINTF_TF BIT(0) /*!< transfer finished */
-
-/* device OUT endpoint-x interrupt flag register bits definitions */
-#define DOEPINTF_NYET BIT(14) /*!< NYET handshake is sent */
-#define DOEPINTF_BTBSTP BIT(6) /*!< back-to-back SETUP packets */
-#define DOEPINTF_EPRXFOVR BIT(4) /*!< endpoint Rx FIFO overrun */
-#define DOEPINTF_STPF BIT(3) /*!< SETUP phase finished */
-#define DOEPINTF_EPDIS BIT(1) /*!< endpoint disabled */
-#define DOEPINTF_TF BIT(0) /*!< transfer finished */
-
-/* device IN endpoint 0 transfer length register bits definitions */
-#define DIEP0LEN_PCNT BITS(19, 20) /*!< packet count */
-#define DIEP0LEN_TLEN BITS(0, 6) /*!< transfer length */
-
-/* device OUT endpoint 0 transfer length register bits definitions */
-#define DOEP0LEN_STPCNT BITS(29, 30) /*!< SETUP packet count */
-#define DOEP0LEN_PCNT BIT(19) /*!< packet count */
-#define DOEP0LEN_TLEN BITS(0, 6) /*!< transfer length */
-
-/* device IN endpoint-x transfer length register bits definitions */
-#define DIEPLEN_MCNT BITS(29, 30) /*!< multi count */
-#define DIEPLEN_PCNT BITS(19, 28) /*!< packet count */
-#define DIEPLEN_TLEN BITS(0, 18) /*!< transfer length */
-
-/* device OUT endpoint-x transfer length register bits definitions */
-#define DOEPLEN_RXDPID BITS(29, 30) /*!< received data PID */
-#define DOEPLEN_STPCNT BITS(29, 30) /*!< SETUP packet count */
-#define DOEPLEN_PCNT BITS(19, 28) /*!< packet count */
-#define DOEPLEN_TLEN BITS(0, 18) /*!< transfer length */
-
-/* device IN endpoint-x DMA address register bits definitions */
-#define DIEPDMAADDR_DMAADDR BITS(0, 31) /*!< DMA address */
-
-/* device OUT endpoint-x DMA address register bits definitions */
-#define DOEPDMAADDR_DMAADDR BITS(0, 31) /*!< DMA address */
-
-/* device IN endpoint-x transmit FIFO status register bits definitions */
-#define DIEPTFSTAT_IEPTFS BITS(0, 15) /*!< IN endpoint��s Tx FIFO space remaining */
-
-/* USB power and clock registers bits definition */
-#define PWRCLKCTL_SHCLK BIT(1) /*!< stop HCLK */
-#define PWRCLKCTL_SUCLK BIT(0) /*!< stop the USB clock */
-
-/* register options defines */
-#define DCFG_DEVSPEED(regval) (DCFG_DS & ((regval) << 0U)) /*!< device speed configuration */
-
-#define USB_SPEED_EXP_HIGH DCFG_DEVSPEED(0U) /*!< device external PHY high speed */
-#define USB_SPEED_EXP_FULL DCFG_DEVSPEED(1U) /*!< device external PHY full speed */
-#define USB_SPEED_INP_FULL DCFG_DEVSPEED(3U) /*!< device internal PHY full speed */
-
-#define GAHBCS_TFEL(regval) (GAHBCS_TXFTH & ((regval) << 7U)) /*!< device speed configuration */
-
-#define TXFIFO_EMPTY_HALF GAHBCS_TFEL(0U) /*!< Tx FIFO half empty */
-#define TXFIFO_EMPTY GAHBCS_TFEL(1U) /*!< Tx FIFO completely empty */
-
-#define GAHBCS_DMAINCR(regval) (GAHBCS_BURST & ((regval) << 1U)) /*!< AHB burst type used by DMA*/
-
-#define DMA_INCR0 GAHBCS_DMAINCR(0U) /*!< single burst type used by DMA*/
-#define DMA_INCR1 GAHBCS_DMAINCR(1U) /*!< 4-beat incrementing burst type used by DMA*/
-#define DMA_INCR4 GAHBCS_DMAINCR(3U) /*!< 8-beat incrementing burst type used by DMA*/
-#define DMA_INCR8 GAHBCS_DMAINCR(5U) /*!< 16-beat incrementing burst type used by DMA*/
-#define DMA_INCR16 GAHBCS_DMAINCR(7U) /*!< 32-beat incrementing burst type used by DMA*/
-
-#define DCFG_PFRI(regval) (DCFG_EOPFT & ((regval) << 11U)) /*!< end of periodic frame time configuration */
-
-#define FRAME_INTERVAL_80 DCFG_PFRI(0U) /*!< 80% of the frame time */
-#define FRAME_INTERVAL_85 DCFG_PFRI(1U) /*!< 85% of the frame time */
-#define FRAME_INTERVAL_90 DCFG_PFRI(2U) /*!< 90% of the frame time */
-#define FRAME_INTERVAL_95 DCFG_PFRI(3U) /*!< 95% of the frame time */
-
-#define DEP0CTL_MPL(regval) (DOEP0CTL_MPL & ((regval) << 0U)) /*!< maximum packet length configuration */
-
-#define EP0MPL_64 DEP0CTL_MPL(0U) /*!< maximum packet length 64 bytes */
-#define EP0MPL_32 DEP0CTL_MPL(1U) /*!< maximum packet length 32 bytes */
-#define EP0MPL_16 DEP0CTL_MPL(2U) /*!< maximum packet length 16 bytes */
-#define EP0MPL_8 DEP0CTL_MPL(3U) /*!< maximum packet length 8 bytes */
-
-/* endpoints address */
-
-/* first bit is direction(0 for Rx and 1 for Tx) */
-#define EP0_OUT ((uint8_t)0x00U) /*!< endpoint out 0 */
-#define EP0_IN ((uint8_t)0x80U) /*!< endpoint in 0 */
-#define EP1_OUT ((uint8_t)0x01U) /*!< endpoint out 1 */
-#define EP1_IN ((uint8_t)0x81U) /*!< endpoint in 1 */
-#define EP2_OUT ((uint8_t)0x02U) /*!< endpoint out 2 */
-#define EP2_IN ((uint8_t)0x82U) /*!< endpoint in 2 */
-#define EP3_OUT ((uint8_t)0x03U) /*!< endpoint out 3 */
-#define EP3_IN ((uint8_t)0x83U) /*!< endpoint in 3 */
-
-/* enable global interrupt */
-#define USB_GLOBAL_INT_ENABLE() (USB_GAHBCS |= GAHBCS_GINTEN)
-
-/* disable global interrupt */
-#define USB_GLOBAL_INT_DISABLE() (USB_GAHBCS &= ~GAHBCS_GINTEN)
-
-/* get current operation mode */
-#define USB_CURRENT_MODE_GET() (USB_GINTF & GINTF_COPM)
-
-/* read global interrupt flag */
-#define USB_CORE_INTR_READ(x) \
-do { \
- uint32_t global_intf = USB_GINTF; \
- (x) = global_intf & USB_GINTEN; \
-} while(0)
-
-/* read global interrupt flag */
-#define USB_DAOEP_INTR_READ(x) \
-do { \
- uint32_t dev_all_ep_inten = USB_DAEPINTEN; \
- uint32_t dev_all_ep_int = USB_DAEPINT; \
- uint32_t out_ep_intb = DAEPINT_OEPITB; \
- (x) = (dev_all_ep_inten & dev_all_ep_int & out_ep_intb) >> 16; \
-} while(0)
-
-/* read out endpoint-x interrupt flag */
-#define USB_DOEP_INTR_READ(x, EpID) \
-do { \
- uint32_t out_epintf = USB_DOEPxINTF(EpID); \
- (x) = out_epintf & USB_DOEPINTEN; \
-} while(0)
-
-/* read all in endpoint interrupt flag */
-#define USB_DAIEP_INTR_READ(x) \
-do { \
- uint32_t dev_all_ep_inten = USB_DAEPINTEN; \
- uint32_t dev_all_ep_int = USB_DAEPINT; \
- uint32_t in_ep_intb = DAEPINT_IEPITB; \
- (x) = dev_all_ep_inten & dev_all_ep_int & in_ep_intb; \
-} while(0)
-
-
-/* read in endpoint-x interrupt flag */
-#define USB_DIEP_INTR_READ(x, EpID) \
-do { \
- uint32_t dev_ep_intf = USB_DIEPxINTF(EpID); \
- uint32_t dev_ep_fifoempty_intf = (((USB_DIEPFEINTEN >> (EpID)) & 0x1U) << 7U); \
- uint32_t dev_inep_inten = USB_DIEPINTEN; \
- (x) = dev_ep_intf & (dev_ep_fifoempty_intf | dev_inep_inten); \
-} while(0)
-
-/* generate remote wakup signal */
-#define USB_REMOTE_WAKEUP_SET() (USB_DCTL |= DCTL_RWKUP)
-
-/* no remote wakup signal generate */
-#define USB_REMOTE_WAKEUP_RESET() (USB_DCTL &= ~DCTL_RWKUP)
-
-/* generate soft disconnect */
-#define USB_SOFT_DISCONNECT_ENABLE() (USB_DCTL |= DCTL_SD)
-
-/* no soft disconnect generate */
-#define USB_SOFT_DISCONNECT_DISABLE() (USB_DCTL &= ~DCTL_SD)
-
-/* set device address */
-#define USB_SET_DEVADDR(DevAddr) (USB_DCFG |= (DevAddr) << 4U)
-
-/* check whether frame is even */
-#define USB_EVEN_FRAME() (!(USB_HFINFR & 0x01U))
-
-/* read port status */
-#define USB_PORT_READ() (USB_HPCS & (~HPCS_PE) & (~HPCS_PCD) & (~HPCS_PEDC))
-
-/* usb clock initialize */
-#define USB_FSLSCLOCK_INIT(ClockFreq) (USB_HCTL &= ~HCTL_CLKSEL | (ClockFreq))
-
-/* get usb current speed */
-#define USB_CURRENT_SPEED_GET() ((USB_HPCS & HPCS_PS) >> 17)
-
-/* get usb current frame */
-#define USB_CURRENT_FRAME_GET() (USB_HFINFR & 0xFFFFU)
-
-#endif /* USB_REGS_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usb_std.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usb_std.h
deleted file mode 100644
index b7fa5d8e9a..0000000000
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usb_std.h
+++ /dev/null
@@ -1,188 +0,0 @@
-/*!
- \file usb_std.h
- \brief USB 2.0 standard defines
-*/
-
-/*
- Copyright (C) 2016 GigaDevice
-
- 2016-08-15, V1.0.0, firmware for GD32F4xx
-*/
-
-#ifndef USB_STD_H
-#define USB_STD_H
-
-#include "usb_conf.h"
-
-#define USB_DEV_QUALIFIER_DESC_LEN 0x0AU /*!< USB device qualifier descriptor length */
-#define USB_DEV_DESC_LEN 0x12U /*!< USB device descriptor length */
-#define USB_CFG_DESC_LEN 0x09U /*!< USB device configuration descriptor length */
-#define USB_IF_DESC_LEN 0x09U /*!< USB device interface descriptor length */
-#define USB_EP_DESC_LEN 0x07U /*!< USB device endpoint descriptor length */
-#define USB_OTG_DESC_LEN 0x03U /*!< USB device OTG descriptor length */
-
-/* bit 7 of bmRequestType: data phase transfer direction */
-#define USB_DIR_MASK 0x80U /*!< USB transfer direction mask */
-#define USB_DIR_OUT 0x00U /*!< USB transfer OUT direction */
-#define USB_DIR_IN 0x80U /*!< USB transfer IN direction */
-
-/* bit 6..5 of bmRequestType: request type */
-#define USB_STANDARD_REQ 0x00U /*!< USB standard request */
-#define USB_CLASS_REQ 0x20U /*!< USB class request */
-#define USB_VENDOR_REQ 0x40U /*!< USB vebdor request */
-#define USB_REQ_MASK 0x60U /*!< USB request mask */
-
-/* bit 4..0 of bmRequestType: recipient type */
-#define USB_REQTYPE_DEVICE 0x00U /*!< USB device request type */
-#define USB_REQTYPE_INTERFACE 0x01U /*!< USB interface request type*/
-#define USB_REQTYPE_ENDPOINT 0x02U /*!< USB endpoint request type*/
-#define USB_REQTYPE_MASK 0x03U /*!< USB request type mask*/
-
-/* bRequest value */
-#define USBREQ_GET_STATUS 0x00U /*!< USB get status request*/
-#define USBREQ_CLEAR_FEATURE 0x01U /*!< USB clear feature request*/
-#define USBREQ_SET_FEATURE 0x03U /*!< USB set feature request*/
-#define USBREQ_SET_ADDRESS 0x05U /*!< USB set address request*/
-#define USBREQ_GET_DESCRIPTOR 0x06U /*!< USB get descriptor request*/
-#define USBREQ_SET_DESCRIPTOR 0x07U /*!< USB set descriptor request*/
-#define USBREQ_GET_CONFIGURATION 0x08U /*!< USB get configuration request*/
-#define USBREQ_SET_CONFIGURATION 0x09U /*!< USB set configuration request*/
-#define USBREQ_GET_INTERFACE 0x0AU /*!< USB get interface request*/
-#define USBREQ_SET_INTERFACE 0x0BU /*!< USB set interface request*/
-#define USBREQ_SYNCH_FRAME 0x0CU /*!< USB synchronize frame request*/
-
-/* descriptor types of usb specifications */
-#define USB_DESCTYPE_DEVICE 0x01U /*!< USB device descriptor type*/
-#define USB_DESCTYPE_CONFIGURATION 0x02U /*!< USB configuration descriptor type*/
-#define USB_DESCTYPE_STRING 0x03U /*!< USB string descriptor type*/
-#define USB_DESCTYPE_INTERFACE 0x04U /*!< USB interface descriptor type*/
-#define USB_DESCTYPE_ENDPOINT 0x05U /*!< USB endpoint descriptor type*/
-#define USB_DESCTYPE_DEVICE_QUALIFIER 0x06U /*!< USB device qualtfier descriptor type*/
-#define USB_DESCTYPE_OTHER_SPEED_CONFIGURATION 0x07U /*!< USB other speed configuration descriptor type*/
-#define USB_DESCTYPE_INTERFACE_POWER 0x08U /*!< USB interface power descriptor type*/
-
-#define USB_DESCTYPE_HID 0x21U /*!< USB HID descriptor type*/
-#define USB_DESCTYPE_HID_REPORT 0x22U /*!< USB HID report descriptor type*/
-
-#define USB_DEVDESC_SIZE 18U /*!< USB device descriptor size*/
-#define USB_CFGDESC_SIZE 9U /*!< USB configure descriptor size*/
-#define USB_INTDESC_SIZE 9U /*!< USB interface descriptor size*/
-#define USB_EPDESC_SIZE 7U /*!< USB endpoint descriptor size*/
-
-/* descriptor type and descriptor index */
-/* use the following values when USB host need to get descriptor */
-#define USB_DEVDESC ((USB_DESCTYPE_DEVICE << 8U) & 0xFF00U) /*!< USB device operation marco */
-#define USB_CFGDESC ((USB_DESCTYPE_CONFIGURATION << 8U) & 0xFF00U) /*!< USB configuration operation marco */
-#define USB_STRDESC ((USB_DESCTYPE_STRING << 8U) & 0xFF00U) /*!< USB string operation marco */
-#define USB_INTDESC ((USB_DESCTYPE_INTERFACE << 8U) & 0xFF00U) /*!< USB interface operation marco */
-#define USB_EPDESC ((USB_DESCTYPE_INTERFACE << 8U) & 0xFF00U) /*!< USB endpoint operation marco */
-#define USB_DEVQUADESC ((USB_DESCTYPE_DEVICE_QUALIFIER << 8U) & 0xFF00U) /*!< USB device qualifier operation marco */
-#define USB_OSPCFGDESC ((USB_DESCTYPE_OTHER_SPEED_CONFIGURATION << 8U) & 0xFF00U) /*!< USB other speed configuration operation marco */
-#define USB_INTPWRDESC ((USB_DESCTYPE_INTERFACE_POWER << 8U) & 0xFF00U) /*!< USB interface power operation marco */
-#define USB_HIDREPDESC ((USB_DESCTYPE_HID_REPORT << 8U) & 0xFF00U) /*!< USB HID report operation marco */
-#define USB_HIDDESC ((USB_DESCTYPE_HID << 8U) & 0xFF00U) /*!< USB HID operation marco */
-
-#define SWAPBYTE(addr) (((uint16_t)(*((uint8_t *)(addr)))) + \
- (uint16_t)(((uint16_t)(*(((uint8_t *)(addr)) + 1U))) << 8U))
-
-/* supported classes */
-#define USB_MSC_CLASS 0x08U /*!< USB MSC class*/
-#define USB_HID_CLASS 0x03U /*!< USB HID class*/
-
-/* interface descriptor field values for hid boot protocol */
-#define HID_BOOT_CODE 0x01U /*!< USB HID boot code*/
-#define HID_KEYBRD_BOOT_CODE 0x01U /*!< USB HID keyboard boot code*/
-#define HID_MOUSE_BOOT_CODE 0x02U /*!< USB HID mouse boot code*/
-
-/* as per usb specs 9.2.6.4 :standard request with data request timeout: 5sec
- standard request with no data stage timeout : 50ms */
-#define DATA_STAGE_TIMEOUT 5000U /*!< USB data stage timeout*/
-#define NODATA_STAGE_TIMEOUT 50U /*!< USB no data stage timeout*/
-
-#define USBH_CFG_DESC_SET_SIZE (USB_CFGDESC_SIZE + USB_INTDESC_SIZE \
- + (USBH_MAX_EP_NUM * USB_EPDESC_SIZE)) /*!< USB host set configuration descriptor size */
-
-#pragma pack(1)
-
-typedef union
-{
- uint8_t data[8];
-
- struct _setup_packet_struct
- {
- uint8_t bmRequestType; /*!< type of request */
- uint8_t bRequest; /*!< request of setup packet */
- uint16_t wValue; /*!< value of setup packet */
- uint16_t wIndex; /*!< index of setup packet */
- uint16_t wLength; /*!< length of setup packet */
- } b;
-}usb_setup_union;
-
-typedef struct
-{
- uint8_t bLength; /*!< size of the descriptor */
- uint8_t bDescriptorType; /*!< type of the descriptor */
-} usb_descriptor_header_struct;
-
-typedef struct
-{
- usb_descriptor_header_struct Header; /*!< descriptor header, including type and size */
-
- uint16_t bcdUSB; /*!< BCD of the supported USB specification */
- uint8_t bDeviceClass; /*!< USB device class */
- uint8_t bDeviceSubClass; /*!< USB device subclass */
- uint8_t bDeviceProtocol; /*!< USB device protocol */
- uint8_t bMaxPacketSize0; /*!< size of the control (address 0) endpoint's bank in bytes */
- uint16_t idVendor; /*!< vendor ID for the USB product */
- uint16_t idProduct; /*!< unique product ID for the USB product */
- uint16_t bcdDevice; /*!< product release (version) number */
- uint8_t iManufacturer; /*!< string index for the manufacturer's name */
- uint8_t iProduct; /*!< string index for the product name/details */
- uint8_t iSerialNumber; /*!< string index for the product's globally unique hexadecimal serial number */
- uint8_t bNumberConfigurations; /*!< total number of configurations supported by the device */
-} usb_descriptor_device_struct;
-
-typedef struct
-{
- usb_descriptor_header_struct Header; /*!< descriptor header, including type and size */
-
- uint16_t wTotalLength; /*!< size of the configuration descriptor header,and all sub descriptors inside the configuration */
- uint8_t bNumInterfaces; /*!< total number of interfaces in the configuration */
- uint8_t bConfigurationValue; /*!< configuration index of the current configuration */
- uint8_t iConfiguration; /*!< index of a string descriptor describing the configuration */
- uint8_t bmAttributes; /*!< configuration attributes */
- uint8_t bMaxPower; /*!< maximum power consumption of the device while in the current configuration */
-} usb_descriptor_configuration_struct;
-
-typedef struct
-{
- usb_descriptor_header_struct Header; /*!< descriptor header, including type and size */
-
- uint8_t bInterfaceNumber; /*!< index of the interface in the current configuration */
- uint8_t bAlternateSetting; /*!< alternate setting for the interface number */
- uint8_t bNumEndpoints; /*!< total number of endpoints in the interface */
- uint8_t bInterfaceClass; /*!< interface class ID */
- uint8_t bInterfaceSubClass; /*!< interface subclass ID */
- uint8_t bInterfaceProtocol; /*!< interface protocol ID */
- uint8_t iInterface; /*!< index of the string descriptor describing the interface */
-} usb_descriptor_interface_struct;
-
-typedef struct
-{
- usb_descriptor_header_struct Header; /*!< descriptor header, including type and size. */
-
- uint8_t bEndpointAddress; /*!< logical address of the endpoint */
- uint8_t bmAttributes; /*!< endpoint attributes */
- uint16_t wMaxPacketSize; /*!< size of the endpoint bank, in bytes */
- uint8_t bInterval; /*!< polling interval in milliseconds for the endpoint if it is an INTERRUPT or ISOCHRONOUS type */
-} usb_descriptor_endpoint_struct;
-
-typedef struct
-{
- usb_descriptor_header_struct Header; /*!< descriptor header, including type and size. */
- uint16_t wLANGID; /*!< LANGID code */
-}usb_descriptor_language_id_struct;
-
-#pragma pack()
-
-#endif /* USB_STD_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbd_core.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbd_core.h
deleted file mode 100644
index 8b79c2ed5a..0000000000
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbd_core.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*!
- \file usbd_core.h
- \brief USB device-mode core driver header file
-*/
-
-/*
- Copyright (C) 2016 GigaDevice
-
- 2016-08-15, V1.0.0, firmware for GD32F4xx
-*/
-
-
-#ifndef USBD_CORE_H
-#define USBD_CORE_H
-
-#include "usbd_conf.h"
-#include "usb_core.h"
-#include "usbd_std.h"
-
-/* device status */
-#define USB_STATUS_DEFAULT 1U /* default status */
-#define USB_STATUS_ADDRESSED 2U /* addressed status */
-#define USB_STATUS_CONFIGURED 3U /* configured status */
-#define USB_STATUS_SUSPENDED 4U /* suspended status */
-
-/* function declarations */
-/* initailizes the USB device-mode handler stack */
-void usbd_init (usb_core_handle_struct *pudev, usb_core_id_enum core_id);
-/* endpoint initialization */
-void usbd_ep_init (usb_core_handle_struct *pudev, const usb_descriptor_endpoint_struct *pep_desc);
-/* endpoint deinitialize */
-void usbd_ep_deinit (usb_core_handle_struct *pudev, uint8_t ep_addr);
-/* endpoint prepare to receive data */
-void usbd_ep_rx (usb_core_handle_struct *pudev, uint8_t ep_addr, uint8_t *pbuf, uint16_t buf_len);
-/* endpoint prepare to transmit data */
-void usbd_ep_tx (usb_core_handle_struct *pudev, uint8_t ep_addr, uint8_t *pbuf, uint32_t buf_len);
-/* transmit data on the control channel */
-usbd_status_enum usbd_ctltx (usb_core_handle_struct *pudev, uint8_t *pbuf, uint16_t len);
-/* receive data on the control channel */
-usbd_status_enum usbd_ctlrx (usb_core_handle_struct *pudev, uint8_t *pbuf, uint16_t len);
-/* transmit status on the control channel */
-usbd_status_enum usbd_ctlstatus_tx (usb_core_handle_struct *pudev);
-/* receive status on the control channel */
-usbd_status_enum usbd_ctlstatus_rx (usb_core_handle_struct *pudev);
-/* set an endpoint to STALL status */
-void usbd_ep_stall (usb_core_handle_struct *pudev, uint8_t ep_addr);
-/* clear endpoint stalled status */
-void usbd_ep_clear_stall (usb_core_handle_struct *pudev, uint8_t ep_addr);
-/* flushes the FIFOs */
-void usbd_ep_fifo_flush (usb_core_handle_struct *pudev, uint8_t ep_addr);
-/* get the received data length */
-uint16_t usbd_rxcount_get (usb_core_handle_struct *pudev, uint8_t ep_id);
-
-#endif /* USBD_CORE_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbd_int.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbd_int.h
deleted file mode 100644
index 3247853be5..0000000000
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbd_int.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*!
- \file usbd_int.h
- \brief USB device-mode interrupt handler header file
-*/
-
-/*
- Copyright (C) 2016 GigaDevice
-
- 2016-08-15, V1.0.0, firmware for GD32F4xx
-*/
-
-#ifndef USBD_INT_H
-#define USBD_INT_H
-
-#include "usbd_core.h"
-
-/* function declarations */
-/* USB device-mode interrupts global service routine handler */
-uint32_t usbd_isr (usb_core_handle_struct *pudev);
-
-#ifdef USBHS_DEDICATED_EP1_ENABLED
-
-/* USB dedicated OUT endpoint 1 interrupt service routine handler */
-uint32_t USBD_EP1OUT_ISR_Handler (usb_core_handle_struct *pudev);
-/* USB dedicated IN endpoint 1 interrupt service routine handler */
-uint32_t USBD_EP1IN_ISR_Handler (usb_core_handle_struct *pudev);
-
-#endif /* USBHS_DEDICATED_EP1_ENABLED */
-
-#endif /* USBD_INT_H */
-
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbd_std.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbd_std.h
deleted file mode 100644
index 494f0ec3aa..0000000000
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbd_std.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*!
- \file usbd_std.h
- \brief USB 2.0 standard driver
-*/
-
-/*
- Copyright (C) 2016 GigaDevice
-
- 2016-06-30, V1.0.0, firmware for GD32F4xx
-*/
-
-#ifndef USBD_STD_H
-#define USBD_STD_H
-
-#include "usb_std.h"
-#include "usbd_core.h"
-#include "usbd_conf.h"
-#include <wchar.h>
-
-#define USBD_LANGID_STR_IDX 0x00U /*!< USB language ID string index*/
-#define USBD_MFC_STR_IDX 0x01U /*!< USB manufacturer string index*/
-#define USBD_PRODUCT_STR_IDX 0x02U /*!< USB product string index*/
-#define USBD_SERIAL_STR_IDX 0x03U /*!< USB serial string index*/
-#define USBD_CONFIG_STR_IDX 0x04U /*!< USB configuration string index*/
-#define USBD_INTERFACE_STR_IDX 0x05U /*!< USB interface string index*/
-
-#define USB_STATUS_REMOTE_WAKEUP 0x02U /*!< USB remote wakeup status*/
-#define USB_STATUS_SELF_POWERED 0x01U /*!< USB self power status*/
-
-#define USB_FEATURE_ENDP_HALT 0x00U /*!< USB halt endpoint feature*/
-#define USB_FEATURE_REMOTE_WAKEUP 0x01U /*!< USB remote wakeup feature*/
-#define USB_FEATURE_TEST_MODE 0x02U /*!< USB test mode feature*/
-
-#define ENG_LANGID 0x0409U /*!< USB english language id*/
-#define CHN_LANGID 0x0804U /*!< USB chinese language id*/
-
-#define USB_DEVICE_DESC_SIZE 0x12U /*!< USB device descriptor size*/
-
-#define LOWBYTE(x) ((uint8_t)((x) & 0x00FFU)) /*!< USB lowbyte operation marco*/
-#define HIGHBYTE(x) ((uint8_t)(((x) & 0xFF00U) >> 8U)) /*!< USB highbyte operation marco*/
-
-#define USB_MIN(a, b) (((a) < (b)) ? (a) : (b)) /*!< USB minimum operation marco*/
-
-#define WIDE_STRING(string) _WIDE_STRING(string)
-#define _WIDE_STRING(string) L##string
-
-#define USBD_STRING_DESC(string) \
- (uint8_t *)&(struct { \
- uint8_t _len; \
- uint8_t _type; \
- wchar_t _data[sizeof(string)]; \
- }) { \
- sizeof(WIDE_STRING(string)) + 2U - 2U, \
- USB_DESCTYPE_STRING, \
- WIDE_STRING(string) \
- }
-
-#define IS_NOT_EP0(ep_addr) (((ep_addr) != 0x00U) && ((ep_addr) != 0x80U))
-
-/* function declarations */
-/* USB device setup transaction*/
-usbd_status_enum usbd_setup_transaction (usb_core_handle_struct *pudev);
-/* USB device out transaction*/
-usbd_status_enum usbd_out_transaction (usb_core_handle_struct *pudev, uint8_t endp_num);
-/* USB device in transaction*/
-usbd_status_enum usbd_in_transaction (usb_core_handle_struct *pudev, uint8_t endp_num);
-/* USB device enum error handle*/
-void usbd_enum_error (usb_core_handle_struct *pudev, usb_device_req_struct *req);
-
-#endif /* USBD_STD_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbh_core.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbh_core.h
deleted file mode 100644
index f4e8739687..0000000000
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbh_core.h
+++ /dev/null
@@ -1,283 +0,0 @@
-/*!
- \file usbh_core.h
- \brief header file for usbh_core.c
-*/
-
-/*
- Copyright (C) 2016 GigaDevice
-
- 2016-08-15, V1.0.1, firmware for GD32F4xx
-*/
-
-#ifndef USBH_CORE_H
-#define USBH_CORE_H
-
-#include "usbh_conf.h"
-#include "usb_std.h"
-#include "usb_core.h"
-
-#define MSC_CLASS 0x08 /*!< the MSC class define */
-#define HID_CLASS 0x03 /*!< the HID class define */
-#define MSC_PROTOCOL 0x50 /*!< the MSC protocal define */
-#define CBI_PROTOCOL 0x01 /*!< the CBI protocal define */
-
-#define USBH_DEVICE_ADDRESS_DEFAULT 0U /*!< the default device address define */
-#define USBH_DEVICE_ADDRESS 1U /*!< the device address define */
-#define USBH_MAX_ERROR_COUNT 2U /*!< the max error count define */
-
-#define HOST_USER_SELECT_CONFIGURATION 1U /*!< the user select configuration define */
-#define HOST_USER_CLASS_ACTIVE 2U /*!< the user class active define */
-#define HOST_USER_CLASS_SELECTED 3U /*!< the user class selected define */
-#define HOST_USER_CONNECTION 4U /*!< the user connecttion define */
-#define HOST_USER_DISCONNECTION 5U /*!< the user disconnection define */
-#define HOST_USER_UNRECOVERED_ERROR 6U /*!< the user unrecovered error define */
-
-#define MAX_USBH_STATE_STACK_DEEP 4 /*!< the max state stack deep define */
-#define MAX_USBH_STATE_TABLE_NUM 10U /*!< the max state table number */
-
-#define HOST_FSM_ID 0U /*!< the host state table id */
-#define ENUM_FSM_ID 1U /*!< the enum state table id */
-#define CMD_FSM_ID 2U /*!< the cmd state table id */
-#define CTRL_FSM_ID 3U /*!< the ctrl state table id */
-#define CLASS_REQ_FSM_ID 4U /*!< the class req state table id */
-#define CLASS_FSM_ID 5U /*!< the class state table id */
-
-#define UP_STATE 100U /*!< up state define */
-#define GO_TO_UP_STATE_EVENT 100U /*!< go to up state event define */
-
-#define HOST_HANDLE_TABLE_SIZE 9U /*!< the host handle table size define */
-
-/* the enum of host state */
-typedef enum
-{
- HOST_IDLE = 0, /* the host idle state definition */
- HOST_DEV_ATTACHED, /* the host device attached state definition */
- HOST_DEV_DETACHED, /* the host device detached state definition */
- HOST_DETECT_DEV_SPEED, /* the host detect device speed state definition */
- HOST_ENUMERATION, /* the host enumeration state definition */
- HOST_CLASS_REQUEST, /* the host class request state definition */
- HOST_CLASS, /* the host class state definition */
- HOST_USER_INPUT, /* the host user input state definition */
- HOST_SUSPENDED, /* the host suspended state definition */
- HOST_ERROR /* the host error state definition */
-}host_state_enum;
-
-/* the enum of host event */
-typedef enum
-{
- HOST_EVENT_ATTACHED = 0, /* the host attached event */
- HOST_EVENT_ENUM, /* the host enum event */
- HOST_EVENT_USER_INPUT, /* the host user input event */
- HOST_EVENT_CLASS_REQ, /* the host class request event */
- HOST_EVENT_CLASS, /* the host class event */
- HOST_EVENT_ERROR, /* the host error event */
- HOST_EVENT_DEV_DETACHED, /* the host device detached event */
- HOST_EVENT_IDLE /* the host idle event */
-}host_event_enum;
-
-/* the enum of enum state */
-typedef enum
-{
- ENUM_IDLE = 0, /* the enum idle state definition */
- ENUM_SET_ADDR, /* the enum set address state definition */
- ENUM_GET_FULL_DEV_DESC, /* the enum get full device descripter state definition */
- ENUM_GET_CFG_DESC, /* the enum get configuration descripter state definition */
- ENUM_GET_FULL_CFG_DESC, /* the enum get full configuration descripter state definition */
- ENUM_GET_MFC_STRING_DESC, /* the enum get MFC string descripter state definition */
- ENUM_GET_PRODUCT_STRING_DESC, /* the enum get product string descripter state definition */
- ENUM_GET_SERIALNUM_STRING_DESC, /* the enum get serialnum string descripter state definition */
- ENUM_SET_CONFIGURATION, /* the enum set congiguration state definition */
- ENUM_DEV_CONFIGURED /* the enum device configuration state definition */
-}enum_state_enum;
-
-/* the enum of ctrl state */
-typedef enum
-{
- CTRL_IDLE = 0, /* the ctrl idle state definition */
- CTRL_SETUP, /* the ctrl setup state definition */
- CTRL_DATA, /* the ctrl data state definition */
- CTRL_STATUS, /* the ctrl status state definition */
- CTRL_ERROR, /* the ctrl error state definition */
- CTRL_STALLED, /* the ctrl stalled state definition */
- CTRL_COMPLETE /* the ctrl complete state definition */
-}ctrl_state_enum;
-
-/* the enum of host status */
-typedef enum
-{
- USBH_OK = 0, /* the usbh ok status definition */
- USBH_BUSY, /* the usbh busy status definition */
- USBH_FAIL, /* the usbh fail status definition */
- USBH_NOT_SUPPORTED, /* the usbh not supported status definition */
- USBH_UNRECOVERED_ERROR, /* the usbh unrecovered error status definition */
- USBH_SPEED_UNKNOWN_ERROR, /* the usbh speed unknown error status definition */
- USBH_APPLY_DEINIT /* the usbh apply deinit status definition */
-}usbh_status_enum;
-
-/* the state of user action */
-typedef enum
-{
- USBH_USER_NO_RESP = 0, /* the user no response */
- USBH_USER_RESP_OK = 1, /* the user response ok */
-}usbh_user_status_enum;
-
-/* control transfer information */
-typedef struct
-{
- uint8_t hc_in_num; /* the host in channel number */
- uint8_t hc_out_num; /* the host out channel number */
- uint8_t ep0_size; /* the endpoint 0 max packet size */
- uint8_t error_count; /* the error count */
- uint16_t length; /* the length */
- uint16_t timer; /* the timer */
- uint8_t *buff; /* the buffer */
- usb_setup_union setup; /* the setup packet */
-}usbh_ctrl_struct;
-
-/* device property */
-typedef struct
-{
- uint8_t address; /* the device address */
- uint8_t speed; /* the device speed */
- usb_descriptor_device_struct dev_desc; /* the device descripter */
- usb_descriptor_configuration_struct cfg_desc; /* the configuration descripter */
- usb_descriptor_interface_struct itf_desc[USBH_MAX_INTERFACES_NUM]; /* the interface descripter */
- usb_descriptor_endpoint_struct ep_desc[USBH_MAX_INTERFACES_NUM][USBH_MAX_EP_NUM]; /* the endpoint descripter */
-}usbh_device_struct;
-
-/* user callbacks */
-typedef struct
-{
- void (*init) (void); /* the user callback init function */
- void (*deinit) (void); /* the user callback deinit function */
- void (*device_connected) (void); /* the user callback device connected function */
- void (*device_reset) (void); /* the user callback device reset function */
- void (*device_disconnected) (void); /* the user callback device disconnected function */
- void (*over_current_detected) (void); /* the user callback over current detected function */
- void (*device_speed_detected) (uint8_t device_speed); /* the user callback device speed detected function */
- void (*device_desc_available) (void *devDesc); /* the user callback device descrpiter available function */
- void (*device_address_set) (void); /* the user callback set device address function */
-
- void (*configuration_desc_available)(usb_descriptor_configuration_struct *cfg_desc,
- usb_descriptor_interface_struct *itf_desc,
- usb_descriptor_endpoint_struct *ep_desc);
- /* the configuration descripter available function */
-
- void (*manufacturer_string) (void *mfc_string); /* the user callback manufacturer string function */
- void (*product_string) (void *prod_string); /* the user callback product string function */
- void (*serial_num_string) (void *serial_string); /* the user callback serial number string function */
- void (*enumeration_finish) (void); /* the user callback enumeration finish function */
- usbh_user_status_enum (*user_input) (void); /* the user callback user input function */
- int (*user_application) (usb_core_handle_struct *pudev, uint8_t id);
- /* the user callback user appliction function */
- void (*device_not_supported) (void); /* the user callback device not supported function */
- void (*unrecovered_error) (void); /* the user callback unrecovered error function */
-}usbh_user_callback_struct;
-
-/* the backup state struct */
-typedef struct
-{
- host_state_enum host_backup_state; /* the host backup state */
- enum_state_enum enum_backup_state; /* the enum backup state */
- ctrl_state_enum ctrl_backup_state; /* the ctrl backup state */
- uint8_t class_req_backup_state;/* the class request backup state */
- uint8_t class_backup_state; /* the class backup state */
-} backup_state_struct;
-
-/* host information */
-typedef struct
-{
- backup_state_struct usbh_backup_state; /* the usbh backup state variable */
- usbh_ctrl_struct control; /* the control struct variable */
- usbh_device_struct device; /* the device struct variable */
- usbh_user_callback_struct *usr_cb; /* the user callback function */
- usbh_status_enum (*class_init) (usb_core_handle_struct *pudev, void *phost); /* the class init function */
- void (*class_deinit) (usb_core_handle_struct *pudev, void *phost); /* the class deinit function */
-}usbh_host_struct;
-
-/* the action function definition */
-typedef usbh_status_enum (*ACT_FUN) (usb_core_handle_struct *pudev, usbh_host_struct *puhost, void* pustate);
-
-/* the state table struct */
-typedef struct
-{
- uint8_t cur_state; /* the current state */
- uint8_t cur_event; /* the current event */
- uint8_t next_state; /* the next state */
- ACT_FUN event_action_fun; /* the event action function entry */
-} state_table_struct;
-
-/* the state stack struct */
-typedef struct
-{
- uint8_t state; /* the state in state stack */
- state_table_struct* table; /* the table in state stack */
- uint8_t table_size; /* the table size in state stack */
-} usbh_state_stack_struct;
-
-/* the state regist table struct */
-typedef struct
-{
- uint8_t id; /* the id of the state table */
- state_table_struct* table; /* the table entry to regist */
- uint8_t table_size; /* the table size to regist */
-} usbh_state_regist_table_struct;
-
-/* the state handle struct */
-typedef struct
-{
- uint8_t usbh_current_state; /* current state */
- uint8_t usbh_current_state_table_size; /* current state table size */
- state_table_struct* usbh_current_state_table; /* current state table */
-
- usbh_state_stack_struct stack[MAX_USBH_STATE_STACK_DEEP]; /* the stack of state table */
- int8_t usbh_current_state_stack_top; /* the current state top */
-
- usbh_state_regist_table_struct usbh_regist_state_table[MAX_USBH_STATE_TABLE_NUM]; /* the array of regist state table */
- uint8_t usbh_regist_state_table_num; /* the number of regist state table */
-} usbh_state_handle_struct;
-
-/* function declarations */
-/* the host core driver function */
-usbh_status_enum host_state_polling_fun (usb_core_handle_struct *pudev, usbh_host_struct *puhost, void *pustate);
-/* initialize the host portion of the driver */
-uint32_t hcd_init (usb_core_handle_struct *pudev, usb_core_id_enum core_id);
-/* check if the device is connected */
-uint32_t hcd_is_device_connected (usb_core_handle_struct *pudev);
-/* this function returns the last URBstate */
-urb_state_enum hcd_urb_state_get (usb_core_handle_struct *pudev, uint8_t channel_num);
-/* this function returns the last URBstate */
-uint32_t hcd_xfer_count_get (usb_core_handle_struct *pudev, uint8_t channel_num);
-/* de-initialize host */
-usbh_status_enum usbh_deinit (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct* pustate);
-
-/* the state core driver function */
-/* state core driver init */
-void scd_init (usbh_state_handle_struct* pustate);
-/* state core driver table regist */
-void scd_table_regist (usbh_state_handle_struct* pustate,
- state_table_struct* pstate_table,
- uint8_t table_id,
- uint8_t current_table_size);
-/* state core driver begin */
-void scd_begin (usbh_state_handle_struct* pustate, uint8_t table_id);
-/* state core driver move state */
-void scd_state_move (usbh_state_handle_struct* pustate, uint8_t state);
-/* state core driver event handle */
-usbh_status_enum scd_event_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct* pustate,
- uint8_t event,
- uint8_t state);
-/* state core driver table push */
-void scd_table_push (usbh_state_handle_struct* pustate);
-/* state core driver table pop */
-void scd_table_pop (usbh_state_handle_struct* pustate);
-/* the function is only used to state move */
-usbh_status_enum only_state_move (usb_core_handle_struct *pudev, usbh_host_struct *puhost, void *pustate);
-/* the function to the up state */
-usbh_status_enum goto_up_state_fun (usb_core_handle_struct *pudev, usbh_host_struct *puhost, void *pustate);
-
-#endif /* USBH_CORE_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbh_ctrl.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbh_ctrl.h
deleted file mode 100644
index 4b30c64d1a..0000000000
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbh_ctrl.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*!
- \file usbh_ctrl.h
- \brief header file for usbh_ctrl.c
-*/
-
-/*
- Copyright (C) 2016 GigaDevice
-
- 2016-08-15, V1.0.0, firmware for GD32F4xx
-*/
-
-#ifndef USBH_CTRL_H
-#define USBH_CTRL_H
-
-#include "usbh_core.h"
-#include "usbh_usr.h"
-
-#define CTRL_HANDLE_TABLE_SIZE 13U /*!< the ctrl handle table size define */
-
-extern state_table_struct ctrl_handle_table[CTRL_HANDLE_TABLE_SIZE];
-extern uint8_t ctrl_polling_handle_flag;
-
-/* the enum of CTRL event */
-typedef enum
-{
- CTRL_EVENT_IDLE = 0, /* the ctrl idle event */
- CTRL_EVENT_SETUP, /* the ctrl setup event */
- CTRL_EVENT_DATA, /* the ctrl data event */
- CTRL_EVENT_STATUS, /* the ctrl status event */
- CTRL_EVENT_COMPLETE, /* the ctrl complete event */
- CTRL_EVENT_ERROR, /* the ctrl error event */
- CTRL_EVENT_STALLED, /* the ctrl stalled event */
-}ctrl_event_enum;
-
-/* function declarations */
-/* the polling function of control transfer state handle */
-usbh_status_enum ctrl_state_polling_fun (usb_core_handle_struct *pudev, usbh_host_struct *puhost, void *pustate);
-/* send datas from the host channel */
-usbh_status_enum usbh_xfer (usb_core_handle_struct *pudev, uint8_t *buf, uint8_t hc_num, uint16_t len);
-/* send the setup packet to the device */
-usbh_status_enum usbh_ctltx_setup (usb_core_handle_struct *pudev, uint8_t *buf, uint8_t hc_num);
-/* this function prepare a hc and start a transfer */
-uint32_t hcd_submit_request (usb_core_handle_struct *pudev, uint8_t channel_num);
-
-#endif /* USBH_CTRL_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbh_hcs.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbh_hcs.h
deleted file mode 100644
index 34bdff55b7..0000000000
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbh_hcs.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*!
- \file usbh_hcs.h
- \brief header file for usbh_hcs.c
-*/
-
-/*
- Copyright (C) 2016 GigaDevice
-
- 2016-08-15, V1.0.0, firmware for GD32F4xx
-*/
-
-#ifndef USBH_HCS_H
-#define USBH_HCS_H
-
-#include "usbh_core.h"
-
-#define HC_MAX 8U
-
-#define HC_OK 0x0000U
-#define HC_USED 0x8000U
-#define HC_ERROR 0xFFFFU
-#define HC_USED_MASK 0x7FFFU
-
-/* function declarations */
-/* allocate a new channel for the pipe */
-uint8_t usbh_channel_alloc (usb_core_handle_struct *pudev, uint8_t ep_addr);
-/* free all usb host channel */
-uint8_t usbh_allchannel_dealloc (usb_core_handle_struct *pudev);
-/* free the usb host channel */
-uint8_t usbh_channel_free (usb_core_handle_struct *pudev, uint8_t index);
-/* open a channel */
-uint8_t usbh_channel_open (usb_core_handle_struct *pudev,
- uint8_t channel_num,
- uint8_t dev_addr,
- uint8_t dev_speed,
- uint8_t ep_type,
- uint16_t ep_mps);
-/* modify a channel */
-uint8_t usbh_channel_modify (usb_core_handle_struct *pudev,
- uint8_t channel_num,
- uint8_t dev_addr,
- uint8_t dev_speed,
- uint8_t ep_type,
- uint16_t ep_mps);
-
-#endif /* USBH_HCS_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbh_int.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbh_int.h
deleted file mode 100644
index 9fac257295..0000000000
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbh_int.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*!
- \file usbh_int.h
- \brief USB host mode interrupt handler header file
-*/
-
-/*
- Copyright (C) 2016 GigaDevice
-
- 2016-08-15, V1.0.1, firmware for GD32F4xx
-*/
-
-#ifndef USBH_INT_H
-#define USBH_INT_H
-
-#include "usb_core.h"
-
-typedef struct
-{
- uint8_t (*sof) (usb_core_handle_struct *pudev);
- uint8_t (*device_connected) (usb_core_handle_struct *pudev);
- uint8_t (*device_disconnected) (usb_core_handle_struct *pudev);
-}usbh_hcd_int_cb_struct;
-
-extern usbh_hcd_int_cb_struct *usbh_hcd_int_fops;
-
-/* function declarations */
-/* handle global host interrupt */
-uint32_t usbh_isr (usb_core_handle_struct *pudev);
-
-#endif /* USBH_INT_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbh_std.h b/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbh_std.h
deleted file mode 100644
index 2dbc45ee30..0000000000
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Include/usbh_std.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*!
- \file usbh_std.h
- \brief header file for usbh_std.c
-*/
-
-/*
- Copyright (C) 2016 GigaDevice
-
- 2016-08-15, V1.0.0, firmware for GD32F4xx
-*/
-
-#ifndef USBH_STD_H
-#define USBH_STD_H
-
-#include "usbh_core.h"
-#include "usbh_usr.h"
-
-/* standard feature selector for clear feature command */
-#define FEATURE_SELECTOR_ENDPOINT 0x00U
-#define FEATURE_SELECTOR_DEVICE 0x01U
-
-#define USBH_SETUP_PACKET_SIZE 8U /* setup packet size */
-#define ENUM_HANDLE_TABLE_SIZE 10U /* enumerate handle table size */
-
-extern uint8_t usbh_cfg_desc[512];
-extern uint8_t enum_polling_handle_flag;
-extern state_table_struct enum_handle_table[ENUM_HANDLE_TABLE_SIZE];
-
-typedef enum
-{
- ENUN_EVENT_IDLE = 0, /* the enum idle event */
- ENUM_EVENT_SET_ADDR, /* the enum set address event */
- ENUN_EVENT_GET_FULL_DEV_DESC, /* the enum get full device descripter event */
- ENUN_EVENT_GET_CFG_DESC, /* the enum get congiguration descripter event */
- ENUN_EVENT_GET_FULL_CFG_DESC, /* the enum get full configuration descripter event */
- ENUN_EVENT_GET_MFC_STRING_DESC, /* the enum get MFC string descripter event */
- ENUN_EVENT_GET_PRODUCT_STRING_DESC, /* the enum get product string event */
- ENUN_EVENT_GET_SERIALNUM_STRING_DESC, /* the enum get serialnum string event */
- ENUN_EVENT_SET_CONFIGURATION, /* the enum set configuration event */
- ENUN_EVENT_DEV_CONFIGURED /* the enum device configured event */
-}enum_event_enum;
-
-/* function declarations */
-/* the polling function of enumeration state */
-usbh_status_enum enum_state_polling_fun (usb_core_handle_struct *pudev, usbh_host_struct *puhost, void *pustate);
-/* get descriptor in usb host enumeration stage */
-void usbh_enum_desc_get (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- uint8_t *buf,
- uint8_t req_type,
- uint16_t value_idx,
- uint16_t len);
-/* set address in usb host enumeration stage */
-void usbh_enum_addr_set (usb_core_handle_struct *pudev, usbh_host_struct *puhost, uint8_t device_address);
-/* set configuration in usb host enumeration stage */
-void usbh_enum_cfg_set (usb_core_handle_struct *pudev, usbh_host_struct *puhost, uint16_t cfg_idx);
-/* parse the device descriptor */
-void usbh_device_desc_parse (usb_descriptor_device_struct *dev_desc, uint8_t *buf, uint16_t len);
-/* parse the configuration descriptor */
-void usbh_cfg_desc_parse (usb_descriptor_configuration_struct *cfg_desc,
- usb_descriptor_interface_struct *itf_desc,
- usb_descriptor_endpoint_struct ep_desc[][USBH_MAX_EP_NUM],
- uint8_t *buf,
- uint16_t len);
-/* parse the interface descriptor */
-void usbh_interface_desc_parse (usb_descriptor_interface_struct *itf_desc, uint8_t *buf);
-/* parse the endpoint descriptor */
-void usbh_endpoint_desc_parse (usb_descriptor_endpoint_struct *ep_desc, uint8_t *buf);
-/* parse the string descriptor */
-void usbh_string_desc_parse (uint8_t *psrc, uint8_t *pdest, uint16_t len);
-/* get the next descriptor header */
-usb_descriptor_header_struct *usbh_next_desc_get (uint8_t *pbuf, uint16_t *ptr);
-
-#endif /* USBH_STD_H */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usb_core.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usb_core.c
deleted file mode 100644
index 18834acd9e..0000000000
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usb_core.c
+++ /dev/null
@@ -1,1132 +0,0 @@
-/*!
- \file usb_core.c
- \brief USB core driver which can operate in host-mode and device-mode
-*/
-
-/*
- Copyright (C) 2016 GigaDevice
-
- 2016-08-15, V1.0.0, firmware for GD32F4xx
-*/
-
-#include "usb_core.h"
-
-static void usb_commonint_enable (usb_core_handle_struct *pudev);
-static usb_status_enum usb_core_reset (usb_core_handle_struct *pudev);
-
-/*!
- \brief enable the commmon interrupts which are used in both device and host modes
- \param[in] pudev: pointer to selected usb device
- \param[out] none
- \retval none
-*/
-static void usb_commonint_enable (usb_core_handle_struct *pudev)
-{
-#ifndef USE_OTG_MODE
-
- /* clear any pending USB interrupts */
- USB_GOTGINTF = 0xFFFFFFFFU;
-
-#endif /* USE_OTG_MODE */
-
- /* enable the usb wakeup and suspend interrupts */
- USB_GINTEN = GINTEN_WKUPIE | GINTEN_SPIE;
-
-#ifdef USE_OTG_MODE
-
- /* enable the OTG interrupts, session interrrupts and connector ID pin interrupt */
- USB_GINTEN |= GINTEN_OTGIE | GINTEN_SESIE | GINTEN_CIDPSCIE;
-
-#endif /* USE_OTG_MODE */
-}
-
-/*!
- \brief soft reset of the OTG_FS core
- \param[in] pudev: pointer to usb device
- \param[out] none
- \retval operation status
-*/
-static usb_status_enum usb_core_reset (usb_core_handle_struct *pudev)
-{
- uint32_t count = 0U;
-
- /* enable core soft reset */
- USB_GRSTCTL |= GRSTCTL_CSRST;
-
- /* wait for the core to be soft reset */
- do {
- if (++count > 200000U) {
- break;
- }
- } while (1U == (USB_GRSTCTL & GRSTCTL_CSRST));
-
- /* wait for addtional 3 PHY clocks */
- if (NULL != pudev->udelay) {
- pudev->udelay(3U);
- }
-
- return USB_OK;
-}
-
-/*!
- \brief write a packet into the Tx FIFO associated with the endpoint
- \param[in] src: pointer to source buffer
- \param[in] ep_id: endpoint identifier which is in (0..3)
- \param[in] len: packet length
- \param[out] none
- \retval operation status
-*/
-usb_status_enum usb_fifo_write (uint8_t *src, uint8_t ep_id, uint16_t len)
-{
- uint32_t count32b = 0U, i = 0U;
- __IO uint32_t *fifo = USB_FIFO(ep_id);
-
- count32b = (len + 3U) / 4U;
-
- for (i = 0U; i < count32b; i++) {
- *fifo = *((__packed uint32_t *)src);
-
- src += 4U;
- }
-
- return USB_OK;
-}
-
-/*!
- \brief read a packet from the Rx FIFO associated with the endpoint
- \param[in] dest: pointer to destination buffer
- \param[in] len: packet length
- \param[out] none
- \retval void type pointer
-*/
-void *usb_fifo_read (uint8_t *dest, uint16_t len)
-{
- uint32_t i = 0U;
- uint32_t count32b = (len + 3U) / 4U;
-
- __IO uint32_t *fifo = USB_FIFO(0U);
-
- for (i = 0U; i < count32b; i++) {
- *(__packed uint32_t *)dest = *fifo;
-
- dest += 4U;
- }
-
- return ((void *)dest);
-}
-
-/*!
- \brief initialize core parameters
- \param[in] pudev: pointer to usb device
- \param[in] core_id: USB core id
- \param[out] none
- \retval operation status
-*/
-usb_status_enum usb_core_select (usb_core_handle_struct *pudev, usb_core_id_enum core_id)
-{
- /* at startup the core is in FS mode */
- pudev->cfg.core_speed = USB_CORE_SPEED_FULL;
- pudev->cfg.max_packet_size = USBFS_MAX_PACKET_SIZE;
-
- pudev->cfg.dma_enable = 0U;
-
- /* initialize the core parameters */
- if (USB_FS_CORE_ID == core_id) {
- pudev->cfg.core_id = USB_FS_CORE_ID;
-
- /* set the host channel numbers */
- pudev->cfg.host_channel_num = USBFS_MAX_HOST_CHANNELCOUNT;
-
- /* set the device endpoint numbers */
- pudev->cfg.dev_endp_num = USBFS_MAX_DEV_EPCOUNT;
-
- /* fifo size is in terms of DWORD */
- pudev->cfg.max_fifo_size = USBFS_MAX_FIFO_WORDLEN;
-
- /* OTG_FS core use embedded physical layer */
- pudev->cfg.phy_interface = USB_CORE_EMBEDDED_PHY;
-
-#ifdef USBFS_SOF_OUTPUT_ENABLED
- pudev->cfg.sof_output = 1U;
-#endif /* USBFS_SOF_OUTPUT_ENABLED */
-
-#ifdef USBFS_LOW_PWR_MGMT_SUPPORT
- pudev->cfg.low_power = 1U;
-#endif /* USBFS_LOW_PWR_MGMT_SUPPORT */
-
- } else if (USB_HS_CORE_ID == core_id) {
- pudev->cfg.core_id = USB_HS_CORE_ID;
-
- /* set the host channel numbers */
- pudev->cfg.host_channel_num = USBHS_MAX_HOST_CHANNELCOUNT;
-
- /* set the device endpoint numbers */
- pudev->cfg.dev_endp_num = USBHS_MAX_DEV_EPCOUNT;
-
- /* fifo size is in terms of DWORD */
- pudev->cfg.max_fifo_size = USBHS_MAX_FIFO_WORDLEN;
-
-#ifdef USB_ULPI_PHY_ENABLED
- pudev->cfg.phy_interface = USB_CORE_ULPI_PHY;
-#elif defined(USB_EMBEDDED_PHY_ENABLED)
- pudev->cfg.phy_interface = USB_CORE_EMBEDDED_PHY;
-#endif /* USB_ULPI_PHY_ENABLED */
-
-#ifdef USBHS_INTERNAL_DMA_ENABLED
- pudev->cfg.dma_enable = 1U;
-#endif /* USBHS_INTERNAL_DMA_ENABLED */
-
-#ifdef USBHS_SOF_OUTPUT_ENABLED
- pudev->cfg.sof_output = 1U;
-#endif /* USBHS_SOF_OUTPUT_ENABLED */
-
-#ifdef USBHS_LOW_PWR_MGMT_SUPPORT
- pudev->cfg.low_power = 1U;
-#endif /* USBHS_LOW_PWR_MGMT_SUPPORT */
- } else {
- /* no operation */
- }
-
- return USB_OK;
-}
-
-/*!
- \brief initializes the USB controller registers and
- prepares the core device mode or host mode operation
- \param[in] pudev: pointer to usb device
- \param[out] none
- \retval operation status
-*/
-usb_status_enum usb_core_init (usb_core_handle_struct *pudev)
-{
- if (USB_CORE_ULPI_PHY == pudev->cfg.phy_interface) {
- USB_GCCFG &= ~GCCFG_PWRON;
-
- if (pudev->cfg.sof_output) {
- USB_GCCFG |= GCCFG_SOFOEN;
- }
-
- /* use high-speed interface */
- USB_GUSBCS &= ~GUSBCS_EMBPHY;
-
- /* use internal over-current indicator */
- USB_GUSBCS &= ~GUSBCS_ULPIEOI;
-
-#ifdef USBHS_EXTERNAL_VBUS_ENABLED
- /* use external VBUS driver */
- USB_GUSBCS |= GUSBCS_ULPIEVD;
-#else
- /* use internal VBUS driver */
- USB_GUSBCS &= ~GUSBCS_ULPIEVD;
-#endif
-
- /* soft reset the core */
- usb_core_reset(pudev);
- } else if (USB_CORE_EMBEDDED_PHY == pudev->cfg.phy_interface) {
- if (USB_HS_CORE_ID == pudev->cfg.core_id) {
- USB_GUSBCS |= GUSBCS_EMBPHY;
- }
-
- /* soft reset the core */
- usb_core_reset(pudev);
-
- /* active the transceiver and enable vbus sensing */
- USB_GCCFG |= GCCFG_PWRON | GCCFG_VBUSACEN | GCCFG_VBUSBCEN;
-
- /* set Tx FIFO empty level to half empty mode */
- USB_GAHBCS &= ~GAHBCS_TXFTH | TXFIFO_EMPTY_HALF;
-
-#ifndef VBUS_SENSING_ENABLED
- USB_GCCFG |= GCCFG_VBUSIG;
-#endif /* VBUS_SENSING_ENABLED */
-
- if(pudev->cfg.sof_output){
- USB_GCCFG |= GCCFG_SOFOEN;
- }
-
- if (NULL != pudev->mdelay) {
- pudev->mdelay(20U);
- }
- } else {
- /* no operation */
- }
-
- if (1U == pudev->cfg.dma_enable) {
- USB_GAHBCS = DMA_INCR8 | GAHBCS_DMAEN;
- }
-
-#ifdef USE_OTG_MODE
- /* enable OTG features */
- USB_GUSBCS |= GUSBCS_HNPCAP | GUSBCS_SRPCAP;
- USB_OTG_EnableCommonInt(pudev);
-
-#endif /* USE_OTG_MODE */
-
- return USB_OK;
-}
-
-/*!
- \brief flush a Tx FIFO or all Tx FIFOs
- \param[in] pudev: pointer to usb device
- \param[in] fifo_num: FIFO number which is in (0..3)
- \param[out] none
- \retval operation status
-*/
-usb_status_enum usb_txfifo_flush (usb_core_handle_struct *pudev, uint8_t fifo_num)
-{
- uint32_t count = 0U;
-
- USB_GRSTCTL = ((uint32_t)fifo_num << 6U) | GRSTCTL_TXFF;
-
- /* wait for Tx FIFO flush bit is set */
- do {
- if (++count > 200000U) {
- break;
- }
- } while (USB_GRSTCTL & GRSTCTL_TXFF);
-
- /* wait for 3 PHY clocks */
- if (NULL != pudev->udelay) {
- pudev->udelay(3U);
- }
-
- return USB_OK;
-}
-
-/*!
- \brief flush the entire Rx FIFO
- \param[in] pudev: pointer to usb device
- \param[out] none
- \retval operation status
-*/
-usb_status_enum usb_rxfifo_flush (usb_core_handle_struct *pudev)
-{
- uint32_t count = 0U;
-
- USB_GRSTCTL = GRSTCTL_RXFF;
-
- /* wait for Rx FIFO flush bit is set */
- do {
- if (++count > 200000U) {
- break;
- }
- } while (USB_GRSTCTL & GRSTCTL_RXFF);
-
- /* wait for 3 PHY clocks */
- if (NULL != pudev->udelay) {
- pudev->udelay(3U);
- }
-
- return USB_OK;
-}
-
-/*!
- \brief set operation mode (host or device)
- \param[in] pudev: pointer to usb device
- \param[in] mode: operation mode which need to set
- \arg HOST_MODE
- \arg DEVICE_MODE
- \param[out] none
- \retval operation status
-*/
-usb_status_enum usb_mode_set (usb_core_handle_struct *pudev, uint8_t mode)
-{
- if (HOST_MODE == mode) {
- USB_GUSBCS &= ~GUSBCS_FDM;
- USB_GUSBCS |= GUSBCS_FHM;
- } else if (DEVICE_MODE == mode) {
- USB_GUSBCS &= ~GUSBCS_FHM;
- USB_GUSBCS |= GUSBCS_FDM;
- } else {
- /* no operation */
- }
-
- if (NULL != pudev->mdelay) {
- pudev->mdelay(50U);
- }
-
- return USB_OK;
-}
-
-#ifdef USE_HOST_MODE
-
-/*!
- \brief initializes USB core for host mode
- \param[in] pudev: pointer to selected usb host
- \param[out] none
- \retval operation status
-*/
-usb_status_enum usb_hostcore_init (usb_core_handle_struct *pudev)
-{
- uint32_t i = 0U;
- __IO uint32_t host_nptxfifo_size = 0U;
- __IO uint32_t host_ptxfifo_size = 0U;
-
-#ifdef USE_OTG_MODE
- __IO uint32_t OtgCtrl = 0;
-#endif /* USE_OTG_MODE */
-
- /* restart the PHY clock */
- USB_PWRCLKCTL = 0U;
-
- /* initialize host configuration register */
- if (USB_CORE_ULPI_PHY == pudev->cfg.phy_interface) {
- USB_FSLSCLOCK_INIT(HCTLR_30_60_MHZ);
- } else {
- USB_FSLSCLOCK_INIT(HCTLR_48_MHZ);
- }
-
- /* configure data FIFO sizes */
-#ifdef USBFS_CORE
- if (USB_FS_CORE_ID == pudev->cfg.core_id) {
- /* set Rx FIFO size */
- USB_GRFLEN = USBFS_RX_FIFO_SIZE;
-
- /* set non-periodic Tx FIFO size and address */
- host_nptxfifo_size &= ~HNPTFLEN_HNPTXRSAR;
- host_nptxfifo_size |= USBFS_RX_FIFO_SIZE;
- host_nptxfifo_size &= ~HNPTFLEN_HNPTXFD;
- host_nptxfifo_size |= USBFS_HTX_NPFIFO_SIZE << 16;
- USB_HNPTFLEN = host_nptxfifo_size;
-
- /* set periodic Tx FIFO size and address */
- host_ptxfifo_size &= ~HPTFLEN_HPTXFSAR;
- host_ptxfifo_size |= USBFS_RX_FIFO_SIZE + USBFS_HTX_PFIFO_SIZE;
- host_ptxfifo_size &= ~HPTFLEN_HPTXFD;
- host_ptxfifo_size |= USBFS_HTX_PFIFO_SIZE << 16;
- USB_HPTFLEN = host_ptxfifo_size;
- }
-#endif /* USBFS_CORE */
-
-#ifdef USBHS_CORE
- if (USB_HS_CORE_ID == pudev->cfg.core_id) {
- /* set Rx FIFO size */
- USB_GRFLEN = USBHS_RX_FIFO_SIZE;
-
- /* set non-periodic Tx FIFO size and address */
- host_nptxfifo_size &= ~HNPTFLEN_HNPTXRSAR;
- host_nptxfifo_size |= USBHS_RX_FIFO_SIZE;
- host_nptxfifo_size &= ~HNPTFLEN_HNPTXFD;
- host_nptxfifo_size |= USBHS_HTX_NPFIFO_SIZE << 16;
- USB_HNPTFLEN = host_nptxfifo_size;
-
- /* set periodic Tx FIFO size and address */
- host_ptxfifo_size &= ~HPTFLEN_HPTXFSAR;
- host_ptxfifo_size |= USBHS_RX_FIFO_SIZE + USBHS_HTX_PFIFO_SIZE;
- host_ptxfifo_size &= ~HPTFLEN_HPTXFD;
- host_ptxfifo_size |= USBHS_HTX_PFIFO_SIZE << 16;
- USB_HPTFLEN = host_ptxfifo_size;
- }
-#endif /* USBHS_CORE */
-
-#ifdef USE_OTG_MODE
-
- /* clear Host Set HNP Enable bit in the USB OTG Control Register */
- OtgCtrl |= GOTGCS_HHNPEN;
- USB_GOTGCS &= ~OtgCtrl;
- USB_GOTGCS |= 0;
-
-#endif /* USE_OTG_MODE */
-
- /* make sure the FIFOs are flushed */
-
- /* flush all Tx FIFOs in device or host mode */
- usb_txfifo_flush(pudev, 0x10U);
-
- /* flush the entire Rx FIFO */
- usb_rxfifo_flush(pudev);
-
- /* clear all pending host channel interrupts */
- USB_HACHINTEN &= ~HACHINTEN_CINTEN;
-
- for (i = 0U; i < pudev->cfg.host_channel_num; i++) {
- USB_HCHxINTEN(i) = 0U;
- USB_HCHxINTF(i) = 0xFFFFFFFFU;
- }
-
-#ifndef USE_OTG_MODE
- usb_vbus_drive(pudev, 1U);
-#endif /* USE_OTG_MODE */
-
- usb_hostint_enable(pudev);
-
- return USB_OK;
-}
-
-/*!
- \brief control the VBUS to power
- \param[in] pudev: pointer to selected usb host
- \param[in] state: VBUS state
- \param[out] none
- \retval none
-*/
-void usb_vbus_drive (usb_core_handle_struct *pudev, uint8_t state)
-{
- __IO uint32_t host_port = 0U;
-
- /* enable or disable the external charge pump */
- if ((void *)0 != pudev->host.vbus_drive) {
- pudev->host.vbus_drive(pudev, state);
- }
-
- /* turn on the host port power. */
- host_port = USB_PORT_READ();
-
- if ((0U == (host_port & HPCS_PP)) && (1U == state)) {
- host_port |= HPCS_PP;
- } else if ((1U == (host_port & HPCS_PP)) && (0U == state)) {
- host_port &= ~HPCS_PP;
- } else {
- /* no operation */
- }
-
- USB_HPCS = host_port;
-
- if (NULL != pudev->mdelay) {
- pudev->mdelay(200U);
- }
-}
-
-/*!
- \brief enables the host mode interrupts
- \param[in] pudev: pointer to selected usb host
- \param[out] none
- \retval operation status
-*/
-usb_status_enum usb_hostint_enable (usb_core_handle_struct *pudev)
-{
- uint32_t global_int_flag = 0U;
-
- /* disable all interrupts */
- USB_GINTEN = 0U;
-
- /* clear any pending interrupts */
- USB_GINTF = 0xFFFFFFFFU;
-
- /* enable the common interrupts */
- usb_commonint_enable(pudev);
-
- if (0U == pudev->cfg.dma_enable) {
- global_int_flag |= GINTF_RXFNEIF;
- }
-
- /* enable host_mode-related interrupts */
- global_int_flag |= GINTF_HPIF | GINTF_HCIF | GINTF_DISCIF \
- | GINTF_SOF | GINTF_ISOONCIF;
-
- USB_GINTEN &= ~global_int_flag;
- USB_GINTEN |= global_int_flag;
-
- return USB_OK;
-}
-
-/*!
- \brief reset host port
- \param[in] pudev: pointer to usb device
- \param[out] none
- \retval operation status
-*/
-uint32_t usb_port_reset (usb_core_handle_struct *pudev)
-{
- USB_HPCS = USB_PORT_READ() | HPCS_PRST;
-
- if (NULL != pudev->mdelay) {
- pudev->mdelay(10U);
- }
-
- USB_HPCS &= ~HPCS_PRST;
-
- if (NULL != pudev->mdelay) {
- pudev->mdelay(20U);
- }
-
- return USB_OK;
-}
-
-/*!
- \brief initialize host channel
- \param[in] pudev: pointer to usb device
- \param[in] hc_num: host channel number which is in (0..7)
- \param[out] none
- \retval operation status
-*/
-usb_status_enum usb_hostchannel_init(usb_core_handle_struct *pudev, uint8_t hc_num)
-{
- usb_status_enum status = USB_OK;
- uint8_t is_low_speed = 0U;
- __IO uint32_t host_channel_inten = 0U;
- __IO uint32_t host_channel_ctlr = 0U;
-
- usb_hostchannel_struct *puhc = &pudev->host.host_channel[hc_num];
-
- /* clear old interrupt conditions for this host channel */
- USB_HCHxINTF((uint16_t)hc_num) = 0xFFFFFFFFU;
-
- if (1U == pudev->cfg.dma_enable) {
- host_channel_inten |= HCHINTEN_DMAERIE;
- }
-
- /* enable channel interrupts required for this transfer */
- switch (puhc->endp_type) {
- case USB_EPTYPE_CTRL:
- case USB_EPTYPE_BULK:
- host_channel_inten |= HCHINTEN_TFIE | HCHINTEN_STALLIE | HCHINTEN_USBERIE \
- | HCHINTEN_DTERIE | HCHINTEN_NAKIE;
-
- if (puhc->endp_in) {
- host_channel_inten |= HCHINTEN_BBERIE;
- } else {
- host_channel_inten |= HCHINTEN_NYETIE;
-
- if (puhc->do_ping) {
- host_channel_inten |= HCHINTEN_ACKIE;
- }
- }
- break;
-
- case USB_EPTYPE_INTR:
- host_channel_inten |= HCHINTEN_TFIE | HCHINTEN_STALLIE | HCHINTEN_USBERIE | HCHINTEN_DTERIE \
- | HCHINTEN_NAKIE | HCHINTEN_REQOVRIE;
-
- if (puhc->endp_in) {
- host_channel_inten |= HCHINTEN_BBERIE;
- }
- break;
-
- case USB_EPTYPE_ISOC:
- host_channel_inten |= HCHINTEN_TFIE | HCHINTEN_REQOVRIE | HCHINTEN_ACKIE;
-
- if (puhc->endp_in) {
- host_channel_inten |= HCHINTEN_USBERIE | HCHINTEN_BBERIE;
- }
- break;
-
- default:
- break;
- }
-
- USB_HCHxINTEN((uint16_t)hc_num) = host_channel_inten;
-
- /* enable the top level host channel interrupt */
- USB_HACHINTEN |= 1U << hc_num;
-
- /* make sure host channel interrupts are enabled */
- USB_GINTEN |= GINTEN_HCIE;
-
- /* program the hcctlr register */
- host_channel_ctlr = 0U;
-
- if (HPRT_PRTSPD_LOW_SPEED == puhc->dev_speed) {
- is_low_speed = 1U;
- }
-
- host_channel_ctlr |= (uint32_t)puhc->dev_addr << 22U;
- host_channel_ctlr |= (uint32_t)puhc->endp_type << 18U;
- host_channel_ctlr |= (uint32_t)puhc->endp_id << 11U;
- host_channel_ctlr |= (uint32_t)puhc->endp_in << 15U;
- host_channel_ctlr |= (uint32_t)is_low_speed << 17U;
- host_channel_ctlr |= puhc->endp_mps;
-
- if (HCCHAR_INTR == puhc->endp_type) {
- host_channel_ctlr |= HCHCTL_ODDFRM;
- }
-
- USB_HCHxCTL((uint16_t)hc_num) = host_channel_ctlr;
-
- return status;
-}
-
-/*!
- \brief prepare host channel for transferring packets
- \param[in] pudev: pointer to usb device
- \param[in] hc_num: host channel number which is in (0..7)
- \param[out] none
- \retval operation status
-*/
-usb_status_enum usb_hostchannel_startxfer(usb_core_handle_struct *pudev, uint8_t hc_num)
-{
- usb_status_enum status = USB_OK;
-
- uint16_t dword_len = 0U;
- uint16_t packet_num = 0U;
-
- __IO uint32_t host_channel_xlen = 0U;
- __IO uint32_t host_channel_ctlr = 0U;
-
- usb_hostchannel_struct *puhc = &pudev->host.host_channel[hc_num];
-
- /* compute the expected number of packets associated to the transfer */
- if (puhc->xfer_len > 0U) {
- packet_num = ((uint16_t)puhc->xfer_len + puhc->endp_mps - 1U) / puhc->endp_mps;
-
- if (packet_num > HC_MAX_PACKET_COUNT) {
- packet_num = HC_MAX_PACKET_COUNT;
- puhc->xfer_len = (uint32_t)(packet_num) * (uint32_t)(puhc->endp_mps);
- }
- } else {
- packet_num = 1U;
- }
-
- if (puhc->endp_in) {
- puhc->xfer_len = (uint32_t)(packet_num) * (uint32_t)(puhc->endp_mps);
- }
-
- /* initialize the host channel length register */
- host_channel_xlen &= ~HCHLEN_TLEN;
- host_channel_xlen |= puhc->xfer_len;
- host_channel_xlen &= ~HCHLEN_PCNT;
- host_channel_xlen |= (uint32_t)packet_num << 19U;
- host_channel_xlen &= ~HCHLEN_DPID;
- host_channel_xlen |= (uint32_t)(puhc->DPID) << 29U;
- USB_HCHxLEN((uint16_t)hc_num) = (uint32_t)host_channel_xlen;
-
- if (1U == pudev->cfg.dma_enable) {
- USB_HCHxDMAADDR((uint16_t)hc_num) = (uint32_t)puhc->xfer_buff;
- }
-
- /* set host channel enable */
- host_channel_ctlr = USB_HCHxCTL((uint16_t)hc_num);
-
- if (1U == USB_EVEN_FRAME()) {
- host_channel_ctlr |= HCHCTL_ODDFRM;
- } else {
- host_channel_ctlr &= ~HCHCTL_ODDFRM;
- }
-
- host_channel_ctlr |= HCHCTL_CEN;
- host_channel_ctlr &= ~HCHCTL_CDIS;
- USB_HCHxCTL((uint16_t)hc_num) = host_channel_ctlr;
-
- if (0U == pudev->cfg.dma_enable) {
- if ((0U == puhc->endp_in) && (puhc->xfer_len > 0U)) {
- dword_len = (uint16_t)(puhc->xfer_len + 3U) / 4U;
-
- switch (puhc->endp_type) {
- /* non-periodic transfer */
- case USB_EPTYPE_CTRL:
- case USB_EPTYPE_BULK:
- /* check if there is enough space in fifo space */
- if (dword_len > (USB_HNPTFQSTAT & HNPTFQSTAT_NPTXFS)) {
- /* need to process data in non-periodic transfer fifo empty interrupt */
- USB_GINTEN |= GINTEN_NPTXFEIE;
- }
- break;
-
- /* periodic transfer */
- case USB_EPTYPE_INTR:
- case USB_EPTYPE_ISOC:
- /* check if there is enough space in FIFO space */
- if (dword_len > (USB_HPTFQSTAT & HPTFQSTAT_PTXFS)) {
- /* need to process data in periodic transfer fifo empty interrupt */
- USB_GINTEN |= GINTEN_PTXFEIE;
- }
- break;
-
- default:
- break;
- }
-
- /* write packet into the Tx FIFO. */
- usb_fifo_write(puhc->xfer_buff, hc_num, (uint16_t)puhc->xfer_len);
- }
- }
-
- return status;
-}
-
-/*!
- \brief halt channel
- \param[in] pudev: pointer to usb device
- \param[in] hc_num: host channel number which is in (0..7)
- \param[out] none
- \retval operation status
-*/
-usb_status_enum usb_hostchannel_halt(usb_core_handle_struct *pudev, uint8_t hc_num)
-{
- uint8_t endp_type = 0U;
- __IO uint32_t host_channel_ctrl = USB_HCHxCTL((uint16_t)hc_num);
-
- host_channel_ctrl |= HCHCTL_CEN | HCHCTL_CDIS;
-
- endp_type = (uint8_t)((host_channel_ctrl & HCHCTL_EPTYPE) >> 18U);
-
- /* check for space in the request queue to issue the halt. */
- if ((HCCHAR_CTRL == endp_type) || (HCCHAR_BULK == endp_type)) {
- if (0U == (USB_HNPTFQSTAT & HNPTFQSTAT_NPTXFS)) {
- host_channel_ctrl |= HCHCTL_CDIS;
- }
- } else {
- if (0U == (USB_HPTFQSTAT & HPTFQSTAT_PTXFS)) {
- host_channel_ctrl |= HCHCTL_CEN;
- }
- }
-
- USB_HCHxCTL((uint16_t)hc_num) = host_channel_ctrl;
-
- return USB_OK;
-}
-
-/*!
- \brief issue a ping token
- \param[in] pudev: pointer to usb device
- \param[in] hc_num: host channel number which is in (0..7)
- \param[out] none
- \retval operation status
-*/
-usb_status_enum usb_hostchannel_ping(usb_core_handle_struct *pudev, uint8_t hc_num)
-{
- uint32_t host_channel_ctrl = 0U;
-
- USB_HCHxLEN((uint16_t)hc_num) = HCHLEN_PING | (HCHLEN_PCNT & (1U << 19U));
-
- host_channel_ctrl = USB_HCHxCTL((uint16_t)hc_num);
- host_channel_ctrl |= HCHCTL_CEN;
- host_channel_ctrl &= ~HCHCTL_CDIS;
-
- USB_HCHxCTL((uint16_t)hc_num) = host_channel_ctrl;
-
- return USB_OK;
-}
-
-/*!
- \brief stop the USB host and clean up fifos
- \param[in] none
- \param[out] none
- \retval none
-*/
-void usb_host_stop(usb_core_handle_struct *pudev)
-{
- uint32_t i;
-
- /* disable all host channel interrupt */
- USB_HACHINTEN = 0U;
- USB_HACHINT = 0xFFFFFFFFU;
-
- /* flush out any leftover queued requests */
- for (i = 0U; i < pudev->cfg.host_channel_num; i++) {
- USB_HCHxCTL(i) |= HCHCTL_CEN | HCHCTL_CDIS | HCHCTL_EPDIR;
- }
-
- /* flush the FIFO */
- usb_rxfifo_flush(pudev);
- usb_txfifo_flush(pudev, 0x10U);
-}
-
-#endif /* USE_HOST_MODE */
-
-
-#ifdef USE_DEVICE_MODE
-
-#ifdef USBFS_CORE
-
-/* USB endpoint Tx FIFO size */
-static uint16_t USBFS_TX_FIFO_SIZE[USBFS_MAX_DEV_EPCOUNT] =
-{
- (uint16_t)TX0_FIFO_FS_SIZE,
- (uint16_t)TX1_FIFO_FS_SIZE,
- (uint16_t)TX2_FIFO_FS_SIZE,
- (uint16_t)TX3_FIFO_FS_SIZE
-};
-
-#elif defined(USBHS_CORE)
-
-uint16_t USBHS_TX_FIFO_SIZE[USBHS_MAX_DEV_EPCOUNT] =
-{
- (uint16_t)TX0_FIFO_HS_SIZE,
- (uint16_t)TX1_FIFO_HS_SIZE,
- (uint16_t)TX2_FIFO_HS_SIZE,
- (uint16_t)TX3_FIFO_HS_SIZE,
- (uint16_t)TX4_FIFO_HS_SIZE,
- (uint16_t)TX5_FIFO_HS_SIZE
-};
-
-#endif /* USBFS_CORE */
-
-static usb_status_enum usb_devint_enable(usb_core_handle_struct *pudev);
-
-/*!
- \brief initialize USB core registers for device mode
- \param[in] pudev: pointer to usb device
- \param[out] none
- \retval operation status
-*/
-usb_status_enum usb_devcore_init (usb_core_handle_struct *pudev)
-{
- uint32_t i, ram_address = 0U;
- __IO uint32_t dev_in_ep0_inf = USB_DIEP0TFLEN;
- __IO uint32_t dev_in_ep_inf = 0U;
-
- /* restart the Phy Clock (Maybe don't need to...) */
- USB_PWRCLKCTL = 0U;
-
- /* config periodic frmae interval to default */
- USB_DCFG &= ~DCFG_EOPFT;
- USB_DCFG |= FRAME_INTERVAL_80;
-
-#ifdef USBFS_CORE
- if (USB_FS_CORE_ID == pudev->cfg.core_id) {
- /* set full speed PHY */
- USB_DCFG &= ~DCFG_DS;
- USB_DCFG |= USB_SPEED_INP_FULL;
-
- /* set Rx FIFO size */
- USB_GRFLEN &= ~GRFLEN_RXFD;
- USB_GRFLEN |= RX_FIFO_FS_SIZE;
-
- /* set endpoint 0 Tx FIFO length and RAM address */
- dev_in_ep0_inf &= ~DIEP0TFLEN_IEP0TXFD;
- dev_in_ep0_inf |= TX0_FIFO_FS_SIZE << 16;
- dev_in_ep0_inf &= ~DIEP0TFLEN_IEP0TXRSAR;
- dev_in_ep0_inf |= RX_FIFO_FS_SIZE;
-
- USB_DIEP0TFLEN = dev_in_ep0_inf;
-
- ram_address = RX_FIFO_FS_SIZE;
-
- /* set endpoint 1 to 3's Tx FIFO length and RAM address */
- for (i = 1U; i < USBFS_MAX_DEV_EPCOUNT; i++) {
- ram_address += USBFS_TX_FIFO_SIZE[i - 1U];
-
- dev_in_ep_inf &= ~DIEPTFLEN_IEPTXFD;
- dev_in_ep_inf |= (uint32_t)USBFS_TX_FIFO_SIZE[i] << 16U;
- dev_in_ep_inf &= ~DIEPTFLEN_IEPTXRSAR;
- dev_in_ep_inf |= ram_address;
-
- USB_DIEPxTFLEN(i) = dev_in_ep_inf;
- }
- }
-#endif /* USBFS_CORE */
-
-#ifdef USBHS_CORE
- if (USB_HS_CORE_ID == pudev->cfg.core_id) {
- USB_DCFG &= ~DCFG_DS;
-
- if (USB_CORE_EMBEDDED_PHY == pudev->cfg.phy_interface) {
- /* set full speed PHY in USB high speed core */
- USB_DCFG |= USB_SPEED_INP_FULL;
- } else if (USB_CORE_ULPI_PHY == pudev->cfg.phy_interface) {
- USB_DCFG |= USB_SPEED_EXP_HIGH;
- }
-
- /* set Rx FIFO size */
- USB_GRFLEN &= ~GRFLEN_RXFD;
- USB_GRFLEN |= RX_FIFO_HS_SIZE;
-
- /* set endpoint 0 Tx FIFO length and RAM address */
- dev_in_ep0_inf &= ~DIEP0TFLEN_IEP0TXFD;
- dev_in_ep0_inf |= TX0_FIFO_HS_SIZE << 16;
- dev_in_ep0_inf &= ~DIEP0TFLEN_IEP0TXRSAR;
- dev_in_ep0_inf |= RX_FIFO_HS_SIZE;
-
- USB_DIEP0TFLEN = dev_in_ep0_inf;
-
- ram_address = RX_FIFO_HS_SIZE;
-
- /* set endpoint 1 to 3's Tx FIFO length and RAM address */
- for (i = 1; i < USBHS_MAX_DEV_EPCOUNT; i++) {
- ram_address += USBHS_TX_FIFO_SIZE[i - 1];
-
- dev_in_ep_inf &= ~DIEPTFLEN_IEPTXFD;
- dev_in_ep_inf |= USBHS_TX_FIFO_SIZE[i] << 16;
- dev_in_ep_inf &= ~DIEPTFLEN_IEPTXRSAR;
- dev_in_ep_inf |= ram_address;
-
- USB_DIEPxTFLEN(i) = dev_in_ep_inf;
- }
- }
-#endif /* USBHS_CORE */
-
- /* make sure all FIFOs are flushed */
-
- /* flush all Tx FIFOs */
- usb_txfifo_flush(pudev, 0x10U);
-
- /* flush entire Rx FIFO */
- usb_rxfifo_flush(pudev);
-
- /* clear all pending device interrupts */
- USB_DIEPINTEN = 0U;
- USB_DOEPINTEN = 0U;
- USB_DAEPINT = 0xFFFFFFFF;
- USB_DAEPINTEN = 0U;
-
- /* configure all IN/OUT endpoints */
- for (i = 0U; i < pudev->cfg.dev_endp_num; i++) {
- if (USB_DIEPxCTL(i) & DIEPCTL_EPEN) {
- USB_DIEPxCTL(i) |= DIEPCTL_EPD | DIEPCTL_SNAK;
- } else {
- USB_DIEPxCTL(i) = 0U;
- }
-
- if (USB_DOEPxCTL(i) & DOEPCTL_EPEN) {
- USB_DOEPxCTL(i) |= DOEPCTL_EPD | DOEPCTL_SNAK;
- } else {
- USB_DOEPxCTL(i) = 0U;
- }
-
- /* set IN/OUT endpoint transfer length to 0 */
- USB_DIEPxLEN(i) = 0U;
- USB_DOEPxLEN(i) = 0U;
-
- /* clear all pending IN/OUT endpoints interrupts */
- USB_DIEPxINTF(i) = 0xFFU;
- USB_DOEPxINTF(i) = 0xFFU;
- }
-
- USB_DIEPINTEN |= DIEPINTEN_EPTXFUDEN;
- usb_devint_enable(pudev);
-
- return USB_OK;
-}
-
-/*!
- \brief enable the device mode interrupts
- \param[in] pudev: pointer to usb device
- \param[out] none
- \retval status
-*/
-static usb_status_enum usb_devint_enable(usb_core_handle_struct *pudev)
-{
- uint32_t int_mask = 0U;
-
- /* disable all interrupts */
- USB_GINTEN = 0U;
-
- /* clear any pending interrupts */
- USB_GINTF = 0xBFFFFFFFU;
-
- /* enable the common interrupts */
- usb_commonint_enable(pudev);
-
- if (0U == pudev->cfg.dma_enable) {
- int_mask = GINTEN_RXFNEIE;
- }
-
- /* enable device_mode-related interrupts */
- int_mask |= GINTEN_SPIE | GINTEN_RSTIE | GINTEN_ENUMFIE \
- | GINTEN_IEPIE | GINTEN_OEPIE | GINTEN_SOFIE | GINTEN_ISOONCIE \
- | GINTEN_ISOINCIE;
-
-#ifdef VBUS_SENSING_ENABLED
- int_mask |= GINTEN_SESIE | GINTEN_OTGIE;
-#endif /* VBUS_SENSING_ENABLED */
-
- USB_GINTEN &= ~int_mask;
- USB_GINTEN |= int_mask;
-
- return USB_OK;
-}
-
-/*!
- \brief configures endpoint 0 to receive SETUP packets
- \param[in] pudev: pointer to usb device
- \param[out] none
- \retval none
-*/
-void usb_ep0_startout(usb_core_handle_struct *pudev)
-{
- __IO uint32_t ep0_xlen = 0U;
-
- /* set OUT endpoint 0 receive length to 24 bytes */
- ep0_xlen &= ~DOEP0LEN_TLEN;
- ep0_xlen |= 8U * 3U;
-
- /* set OUT endpoint 0 receive length to 1 packet */
- ep0_xlen &= ~DOEP0LEN_PCNT;
- ep0_xlen |= 1U << 19;
-
- /* set SETUP packet count to 3 */
- ep0_xlen &= ~DOEP0LEN_STPCNT;
- ep0_xlen |= 3U << 29;
-
- USB_DOEPxLEN(0U) = ep0_xlen;
-
- if (1U == pudev->cfg.dma_enable) {
- USB_DOEPxDMAADDR(0U) = (uint32_t)&pudev->dev.setup_packet;
-
- USB_DOEPxCTL(0U) = DOEPCTL_EPEN | DOEPCTL_EPACT;
- }
-}
-
-/*!
- \brief active remote wakeup signalling
- \param[in] pudev: pointer to usb device
- \param[out] none
- \retval none
-*/
-void usb_remotewakeup_active(usb_core_handle_struct *pudev)
-{
- __IO uint32_t power_clock;
-
- if (pudev->dev.remote_wakeup) {
- if (1U == (USB_DSTAT & DSTAT_SPST)) {
- if (pudev->cfg.low_power) {
- /* ungate USB core clock */
- power_clock = USB_PWRCLKCTL;
- power_clock &= ~PWRCLKCTL_SHCLK;
- power_clock &= ~PWRCLKCTL_SUCLK;
-
- USB_PWRCLKCTL = power_clock;
- }
-
- /* active remote wakeup signaling */
- USB_DCTL |= DCTL_RWKUP;
-
- if (pudev->mdelay != (void *)0) {
- pudev->mdelay(5U);
- }
-
- USB_DCTL &= ~DCTL_RWKUP;
- }
- }
-}
-
-/*!
- \brief active USB core clock
- \param[in] pudev: pointer to usb device
- \param[out] none
- \retval none
-*/
-void usb_clock_ungate(usb_core_handle_struct *pudev)
-{
- if (pudev->cfg.low_power) {
- __IO uint32_t power_clock;
-
- if (1U == (USB_DSTAT & DSTAT_SPST)) {
- /* un-gate USB core clock */
- power_clock = USB_PWRCLKCTL;
- power_clock &= ~PWRCLKCTL_SHCLK;
- power_clock &= ~PWRCLKCTL_SUCLK;
-
- USB_PWRCLKCTL = power_clock;
- }
- }
-}
-
-/*!
- \brief stop the device and clean up fifos
- \param[in] pudev: pointer to usb device
- \param[out] none
- \retval none
-*/
-void usb_device_stop (usb_core_handle_struct *pudev)
-{
- uint32_t i;
-
- pudev->dev.status = 1U;
-
- for (i = 0U; i < pudev->cfg.dev_endp_num; i++) {
- USB_DIEPxINTF(i) = 0xFFU;
- USB_DOEPxINTF(i) = 0xFFU;
- }
-
- USB_DIEPINTEN = 0U;
- USB_DOEPINTEN = 0U;
- USB_DAEPINTEN = 0U;
- USB_DAEPINT = 0xFFFFFFFFU;
-
- /* flush the FIFO */
- usb_rxfifo_flush(pudev);
- usb_txfifo_flush(pudev, 0x10U);
-}
-#endif /* USE_DEVICE_MODE */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbd_core.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbd_core.c
deleted file mode 100644
index 0d15a7950f..0000000000
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbd_core.c
+++ /dev/null
@@ -1,520 +0,0 @@
-/*!
- \file usbd_core.c
- \brief USB device-mode core driver
-*/
-
-/*
- Copyright (C) 2016 GigaDevice
-
- 2016-08-15, V1.0.0, firmware for GD32F4xx
-*/
-
-#include "usbd_core.h"
-#include "usbd_std.h"
-
-/*!
- \brief initailizes the USB device-mode handler stack
- \param[in] pudev: pointer to usb device instance
- \param[in] core_id: USB core ID
- \param[out] none
- \retval none
-*/
-void usbd_init (usb_core_handle_struct *pudev, usb_core_id_enum core_id)
-{
- /* select USB core */
- usb_core_select (pudev, core_id);
-
- pudev->dev.status = USB_STATUS_DEFAULT;
-
- /* disable USB global interrupt */
- USB_GLOBAL_INT_DISABLE();
-
- /* init the core (common init.) */
- usb_core_init(pudev);
-
- /* force device mode*/
- usb_mode_set(pudev, DEVICE_MODE);
-
- /* set device disconnect */
- USB_SOFT_DISCONNECT_ENABLE();
-
- if ((void *)0 != pudev->mdelay) {
- pudev->mdelay(3U);
- }
-
- /* init device */
- usb_devcore_init(pudev);
-
- /* set device Connect */
- USB_SOFT_DISCONNECT_DISABLE();
-
- if ((void *)0 != pudev->mdelay) {
- pudev->mdelay(3U);
- }
-
- /* enable USB global interrupt */
- USB_GLOBAL_INT_ENABLE();
-}
-
-/*!
- \brief endpoint initialization
- \param[in] pudev: pointer to usb device instance
- \param[in] pep_desc: pointer to usb endpoint descriptor
- \param[out] none
- \retval none
-*/
-void usbd_ep_init (usb_core_handle_struct *pudev, const usb_descriptor_endpoint_struct *pep_desc)
-{
- usb_ep_struct *ep;
-
- uint32_t dev_all_ep_int_en = 0U;
- uint32_t dev_ep_ctlr = 0U;
-
- uint8_t ep_id = pep_desc->bEndpointAddress & 0x7FU;
- uint8_t ep_type = pep_desc->bmAttributes & USB_EPTYPE_MASK;
- uint16_t ep_mps = pep_desc->wMaxPacketSize;
-
- if (pep_desc->bEndpointAddress >> 7) {
- ep = &pudev->dev.in_ep[ep_id];
-
- dev_all_ep_int_en |= 1U << ep_id;
- dev_ep_ctlr = USB_DIEPxCTL((uint16_t)ep_id);
-
- /* if the endpoint is not active, need change the endpoint control register */
- if (!(dev_ep_ctlr & DIEPCTL_EPACT)) {
- if (0U == ep_id) {
- dev_ep_ctlr &= ~DIEP0CTL_MPL;
- } else {
- dev_ep_ctlr &= ~DIEPCTL_MPL;
- }
- dev_ep_ctlr |= ep_mps;
-
- dev_ep_ctlr &= ~DIEPCTL_EPTYPE;
- dev_ep_ctlr |= (uint32_t)ep_type << 18;
-
- dev_ep_ctlr &= ~DIEPCTL_TXFNUM;
- dev_ep_ctlr |= (uint32_t)ep_id << 22;
-
- if (0U != ep_id) {
- dev_ep_ctlr |= DIEPCTL_SD0PID;
- dev_ep_ctlr |= DIEPCTL_EPACT;
- }
-
- USB_DIEPxCTL((uint16_t)ep_id) = dev_ep_ctlr;
- }
- } else {
- ep = &pudev->dev.out_ep[ep_id];
-
- dev_all_ep_int_en |= (1U << ep_id) << 16;
- dev_ep_ctlr = USB_DOEPxCTL((uint16_t)ep_id);
-
- /* if the endpoint is not active, need change the endpoint control register */
- if (!(dev_ep_ctlr & DOEPCTL_EPACT)) {
- if (0U == ep_id) {
- dev_ep_ctlr &= ~DOEP0CTL_MPL;
- } else {
- dev_ep_ctlr &= ~DOEPCTL_MPL;
- }
- dev_ep_ctlr |= ep_mps;
-
- dev_ep_ctlr &= ~DOEPCTL_EPTYPE;
- dev_ep_ctlr |= (uint32_t)ep_type << 18;
-
- if (0U != ep_id) {
- dev_ep_ctlr |= DOEPCTL_SD0PID;
- dev_ep_ctlr |= DOEPCTL_EPACT;
- }
-
- USB_DOEPxCTL((uint16_t)ep_id) = dev_ep_ctlr;
- }
- }
-
- ep->endp_mps = ep_mps;
- ep->endp_type = ep_type;
-
- /* enable the interrupts for this endpoint */
-#ifdef USBHS_DEDICATED_EP1_ENABLED
- if ((1 == ep_id) && (USB_HS_CORE_ID == pudev->cfg.core_id)) {
- USB_DEP1INTEN |= dev_all_ep_int_en;
- } else
-#endif /* USBHS_DEDICATED_EP1_ENABLED */
- {
- USB_DAEPINTEN |= dev_all_ep_int_en;
- }
-}
-
-/*!
- \brief endpoint deinitialize
- \param[in] pudev: pointer to usb device instance
- \param[in] ep_addr: endpoint address
- \param[out] none
- \retval none
-*/
-void usbd_ep_deinit (usb_core_handle_struct *pudev, uint8_t ep_addr)
-{
- uint32_t dev_all_ep_int_en = 0U;
- uint8_t ep_id = ep_addr & 0x7FU;
-
- if (ep_addr >> 7) {
- dev_all_ep_int_en |= 1U << ep_id;
-
- USB_DIEPxCTL((uint16_t)ep_id) &= ~DIEPCTL_EPACT;
- } else {
- dev_all_ep_int_en |= (1U << ep_id) << 16U;
-
- USB_DOEPxCTL((uint16_t)ep_id) &= ~DOEPCTL_EPACT;
- }
-
- /* disable the interrupts for this endpoint */
-#ifdef USBHS_DEDICATED_EP1_ENABLED
- if ((1U == ep_id) && (USB_HS_CORE_ID == pudev->cfg.core_id)) {
- USB_DEP1INTEN &= ~dev_all_ep_int_en;
- } else
-#endif /* USBHS_DEDICATED_EP1_ENABLED */
- {
- USB_DAEPINTEN &= ~dev_all_ep_int_en;
- }
-}
-
-/*!
- \brief endpoint prepare to receive data
- \param[in] pudev: pointer to usb device instance
- \param[in] ep_addr: endpoint address
- \param[in] pbuf: pointer to buffer
- \param[in] buf_len: buffer length
- \param[out] none
- \retval none
-*/
-void usbd_ep_rx (usb_core_handle_struct *pudev, uint8_t ep_addr, uint8_t *pbuf, uint16_t buf_len)
-{
- usb_ep_struct *ep;
- uint8_t ep_id = ep_addr & 0x7FU;
- uint32_t dev_ep_ctlr = 0U, dev_ep_xlen = 0U;
-
- ep = &pudev->dev.out_ep[ep_id];
-
- /* setup and start the Xfer */
- ep->xfer_buff = pbuf;
- ep->xfer_len = buf_len;
- ep->xfer_count = 0U;
-
- if (1U == pudev->cfg.dma_enable) {
- ep->dma_addr = (uint32_t)pbuf;
- }
-
- dev_ep_ctlr = USB_DOEPxCTL((uint16_t)ep_id);
- dev_ep_xlen = USB_DOEPxLEN((uint16_t)ep_id);
-
- dev_ep_xlen &= ~DOEPLEN_TLEN;
- dev_ep_xlen &= ~DOEPLEN_PCNT;
-
- /* zero length packet */
- if (0U == ep->xfer_len) {
- /* set the transfer length to max packet size */
- dev_ep_xlen |= ep->endp_mps;
-
- /* set the transfer packet count to 1 */
- dev_ep_xlen |= 1U << 19U;
- } else {
- if (0U == ep_id) {
- /* set the transfer length to max packet size */
- dev_ep_xlen |= ep->endp_mps;
-
- /* set the transfer packet count to 1 */
- dev_ep_xlen |= 1U << 19U;
- } else {
- /* configure the transfer size and packet count as follows:
- * pktcnt = N
- * xfersize = N * maxpacket
- */
- dev_ep_xlen |= ((ep->xfer_len + ep->endp_mps - 1U) / ep->endp_mps) << 19U;
- dev_ep_xlen |= ((dev_ep_xlen & DOEPLEN_PCNT) >> 19U) * ep->endp_mps;
- }
- }
-
- USB_DOEPxLEN((uint16_t)ep_id) = dev_ep_xlen;
-
- if (1U == pudev->cfg.dma_enable) {
- USB_DOEPxDMAADDR((uint16_t)ep_id) = ep->dma_addr;
- }
-
- if (USB_EPTYPE_ISOC == ep->endp_type) {
- if (ep->endp_frame) {
- dev_ep_ctlr |= DOEPCTL_SODDFRM;
- } else {
- dev_ep_ctlr |= DOEPCTL_SEVNFRM;
- }
- }
-
- /* enable the endpoint and clear the NAK */
- dev_ep_ctlr |= DOEPCTL_EPEN | DOEPCTL_CNAK;
-
- USB_DOEPxCTL((uint16_t)ep_id) = dev_ep_ctlr;
-}
-
-/*!
- \brief endpoint prepare to transmit data
- \param[in] pudev: pointer to usb device instance
- \param[in] ep_addr: endpoint address
- \param[in] pbuf: pointer to buffer
- \param[in] len: buffer length
- \param[out] none
- \retval none
-*/
-void usbd_ep_tx (usb_core_handle_struct *pudev, uint8_t ep_addr, uint8_t *pbuf, uint32_t buf_len)
-{
- usb_ep_struct *ep;
- uint8_t ep_id = ep_addr & 0x7FU;
- __IO uint32_t dev_ep_ctlr = 0U;
- __IO uint32_t dev_ep_xlen = 0U;
-
- ep = &pudev->dev.in_ep[ep_id];
-
- /* setup and start the transfer */
- ep->xfer_buff = pbuf;
- ep->xfer_len = buf_len;
- ep->xfer_count = 0U;
-
- if (1U == pudev->cfg.dma_enable) {
- ep->dma_addr = (uint32_t)pbuf;
- }
-
- dev_ep_ctlr = USB_DIEPxCTL((uint16_t)ep_id);
- dev_ep_xlen = USB_DIEPxLEN((uint16_t)ep_id);
-
- /* clear transfer length to 0 */
- dev_ep_xlen &= ~DIEPLEN_TLEN;
-
- /* clear transfer packet to 0 */
- dev_ep_xlen &= ~DIEPLEN_PCNT;
-
- /* zero length packet */
- if (0U == ep->xfer_len) {
- /* set transfer packet count to 1 */
- dev_ep_xlen |= 1U << 19U;
- } else {
- if (0U == ep_id) {
- if (ep->xfer_len > ep->endp_mps) {
- ep->xfer_len = ep->endp_mps;
- }
-
- dev_ep_xlen |= 1U << 19U;
- } else {
- dev_ep_xlen |= ((ep->xfer_len - 1U + ep->endp_mps) / ep->endp_mps) << 19U;
- }
-
- /* configure the transfer size and packet count as follows:
- * xfersize = N * maxpacket + short_packet
- * pktcnt = N + (short_packet exist ? 1 : 0)
- */
- dev_ep_xlen |= ep->xfer_len;
-
- if (USB_EPTYPE_ISOC == ep->endp_type) {
- dev_ep_xlen |= DIEPLEN_MCNT & (1U << 29U);
- }
- }
-
- USB_DIEPxLEN((uint16_t)ep_id) = dev_ep_xlen;
-
- if (USB_EPTYPE_ISOC == ep->endp_type) {
- if (0U == (((USB_DSTAT & DSTAT_FNRSOF) >> 8U) & 0x1U)) {
- dev_ep_ctlr |= DIEPCTL_SODDFRM;
- } else {
- dev_ep_ctlr |= DIEPCTL_SEVNFRM;
- }
- }
-
- if (1U == pudev->cfg.dma_enable) {
- USB_DIEPxDMAADDR((uint16_t)ep_id) = ep->dma_addr;
- }
-
- /* enable the endpoint and clear the NAK */
- dev_ep_ctlr |= DIEPCTL_EPEN | DIEPCTL_CNAK;
-
- USB_DIEPxCTL((uint16_t)ep_id) = dev_ep_ctlr;
-
- if (0U == pudev->cfg.dma_enable) {
- if (USB_EPTYPE_ISOC != ep->endp_type) {
- /* enable the Tx FIFO empty interrupt for this endpoint */
- if (ep->xfer_len > 0U) {
- USB_DIEPFEINTEN |= 1U << ep_id;
- }
- } else {
- usb_fifo_write(ep->xfer_buff, ep_id, (uint16_t)ep->xfer_len);
- }
- }
-}
-
-/*!
- \brief transmit data on the control channel
- \param[in] pudev: pointer to usb device instance
- \param[in] pbuf: pointer to buffer
- \param[in] len: buffer length
- \param[out] none
- \retval usb device operation status
-*/
-usbd_status_enum usbd_ctltx (usb_core_handle_struct *pudev, uint8_t *pbuf, uint16_t len)
-{
- usbd_status_enum ret = USBD_OK;
-
- pudev->dev.sum_len = len;
- pudev->dev.remain_len = len;
- pudev->dev.ctl_status = USB_CTRL_DATA_IN;
-
- usbd_ep_tx (pudev, 0U, pbuf, (uint32_t)len);
-
- return ret;
-}
-
-/*!
- \brief receive data on the control channel
- \param[in] pudev: pointer to usb device instance
- \param[in] pbuf: pointer to buffer
- \param[in] len: buffer length
- \param[out] none
- \retval usb device operation status
-*/
-usbd_status_enum usbd_ctlrx (usb_core_handle_struct *pudev, uint8_t *pbuf, uint16_t len)
-{
- pudev->dev.sum_len = len;
- pudev->dev.remain_len = len;
- pudev->dev.ctl_status = USB_CTRL_DATA_OUT;
-
- usbd_ep_rx (pudev, 0U, pbuf, len);
-
- return USBD_OK;
-}
-
-/*!
- \brief transmit status on the control channel
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval usb device operation status
-*/
-usbd_status_enum usbd_ctlstatus_tx (usb_core_handle_struct *pudev)
-{
- pudev->dev.ctl_status = USB_CTRL_STATUS_IN;
-
- usbd_ep_tx (pudev, 0U, NULL, 0U);
-
- usb_ep0_startout(pudev);
-
- return USBD_OK;
-}
-
-/*!
- \brief receive status on the control channel
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval usb device operation status
-*/
-usbd_status_enum usbd_ctlstatus_rx (usb_core_handle_struct *pudev)
-{
- pudev->dev.ctl_status = USB_CTRL_STATUS_OUT;
-
- usbd_ep_rx (pudev, 0U, NULL, 0U);
-
- usb_ep0_startout(pudev);
-
- return USBD_OK;
-}
-
-/*!
- \brief set an endpoint to STALL status
- \param[in] pudev: pointer to usb device instance
- \param[in] ep_addr: endpoint address
- \param[out] none
- \retval none
-*/
-void usbd_ep_stall (usb_core_handle_struct *pudev, uint8_t ep_addr)
-{
- uint8_t ep_id = ep_addr & 0x7FU;
- __IO uint32_t dev_ep_ctlr = 0U;
-
- if (ep_addr >> 7U) {
- dev_ep_ctlr = USB_DIEPxCTL((uint16_t)ep_id);
-
- /* set the endpoint disable bit */
- if (dev_ep_ctlr & DIEPCTL_EPEN) {
- dev_ep_ctlr |= DIEPCTL_EPD;
- }
-
- /* set the endpoint stall bit */
- dev_ep_ctlr |= DIEPCTL_STALL;
-
- USB_DIEPxCTL((uint16_t)ep_id) = dev_ep_ctlr;
- } else {
- /* set the endpoint stall bit */
- USB_DOEPxCTL((uint16_t)ep_id) |= DOEPCTL_STALL;
- }
-}
-
-/*!
- \brief clear endpoint stalled status
- \param[in] pudev: pointer to usb device instance
- \param[in] ep_addr: endpoint address
- \param[out] none
- \retval none
-*/
-void usbd_ep_clear_stall (usb_core_handle_struct *pudev, uint8_t ep_addr)
-{
- usb_ep_struct *ep;
- uint8_t ep_id = ep_addr & 0x7FU;
- __IO uint32_t dev_ep_ctlr = 0U;
-
- if(ep_addr >> 7){
- ep = &pudev->dev.in_ep[ep_id];
-
- dev_ep_ctlr = USB_DIEPxCTL((uint16_t)ep_id);
-
- /* clear the IN endpoint stall bits */
- dev_ep_ctlr &= ~DIEPCTL_STALL;
-
- if ((USB_EPTYPE_INTR == ep->endp_type) || (USB_EPTYPE_BULK == ep->endp_type)) {
- dev_ep_ctlr |= DIEPCTL_SEVNFRM;
- }
-
- USB_DIEPxCTL((uint16_t)ep_id) = dev_ep_ctlr;
- } else {
- ep = &pudev->dev.out_ep[ep_id];
-
- dev_ep_ctlr = USB_DOEPxCTL((uint16_t)ep_id);
-
- /* clear the OUT endpoint stall bits */
- dev_ep_ctlr &= ~DOEPCTL_STALL;
-
- if ((USB_EPTYPE_INTR == ep->endp_type) || (USB_EPTYPE_BULK == ep->endp_type)) {
- dev_ep_ctlr |= DOEPCTL_SEVNFRM;
- }
-
- USB_DOEPxCTL((uint16_t)ep_id) = dev_ep_ctlr;
- }
-}
-
-/*!
- \brief flushes the FIFOs
- \param[in] pudev: pointer to usb device instance
- \param[in] ep_addr: endpoint address
- \param[out] none
- \retval none
-*/
-void usbd_ep_fifo_flush (usb_core_handle_struct *pudev, uint8_t ep_addr)
-{
- if (ep_addr >> 7) {
- usb_txfifo_flush(pudev, ep_addr & 0x7FU);
- } else {
- usb_rxfifo_flush(pudev);
- }
-}
-
-/*!
- \brief get the received data length
- \param[in] pudev: pointer to usb device instance
- \param[in] ep_id: endpoint identifier which is in (0..3)
- \param[out] none
- \retval received data length
-*/
-uint16_t usbd_rxcount_get (usb_core_handle_struct *pudev, uint8_t ep_id)
-{
- return (uint16_t)pudev->dev.out_ep[ep_id].xfer_count;
-}
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbd_int.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbd_int.c
deleted file mode 100644
index 01338e2e9b..0000000000
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbd_int.c
+++ /dev/null
@@ -1,758 +0,0 @@
-/*!
- \file usbd_int.c
- \brief USB device mode interrupt routines
-*/
-
-/*
- Copyright (C) 2016 GigaDevice
-
- 2016-08-15, V1.0.0, firmware for GD32F4xx
-*/
-
-#include "usbd_int.h"
-#include "usbd_std.h"
-
-/* interrupt handlers */
-static uint32_t usbd_intf_outep (usb_core_handle_struct *pudev);
-static uint32_t usbd_intf_inep (usb_core_handle_struct *pudev);
-static uint32_t usbd_intf_earlysuspend (usb_core_handle_struct *pudev);
-static uint32_t usbd_intf_suspend (usb_core_handle_struct *pudev);
-static uint32_t usbd_intf_resume (usb_core_handle_struct *pudev);
-static uint32_t usbd_intf_sof (usb_core_handle_struct *pudev);
-static uint32_t usbd_intf_rxfifo (usb_core_handle_struct *pudev);
-static uint32_t usbd_intf_reset (usb_core_handle_struct *pudev);
-static uint32_t usbd_intf_enumfinish (usb_core_handle_struct *pudev);
-static uint32_t usbd_intf_isoinincomplete (usb_core_handle_struct *pudev);
-static uint32_t usbd_intf_isooutincomplete (usb_core_handle_struct *pudev);
-
-static uint32_t usbd_emptytxfifo_write (usb_core_handle_struct *pudev, uint8_t ep_num);
-
-#ifdef VBUS_SENSING_ENABLED
-
- static uint32_t usbd_intf_otg (usb_core_handle_struct *pudev);
- static uint32_t usbd_intf_sessionrequest (usb_core_handle_struct *pudev);
-
-#endif
-
-static usb_speed_enum USB_SPEED[4] = {
- [DSTAT_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ] = USB_SPEED_HIGH,
- [DSTAT_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ] = USB_SPEED_FULL,
- [DSTAT_ENUMSPD_FS_PHY_48MHZ] = USB_SPEED_FULL,
- [DSTAT_ENUMSPD_LS_PHY_6MHZ] = USB_SPEED_LOW
-};
-
-static const uint8_t EP0_MAXLEN[4] = {
- [DSTAT_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ] = EP0MPL_64,
- [DSTAT_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ] = EP0MPL_64,
- [DSTAT_ENUMSPD_FS_PHY_48MHZ] = EP0MPL_64,
- [DSTAT_ENUMSPD_LS_PHY_6MHZ] = EP0MPL_8
-};
-
-#ifdef USBHS_DEDICATED_EP1_ENABLED
-
-/*!
- \brief USB dedicated OUT endpoint 1 interrupt service routine handler
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval operation status
-*/
-uint32_t USBD_EP1OUT_ISR_Handler (usb_core_handle_struct *pudev)
-{
- uint32_t out_endp_int = 0;
- uint32_t out_endp_size = 0;
-
- out_endp_int = USB_DOEPxINTF(1);
- out_endp_int &= USB_DOEP1INTEN;
-
- /* transfer complete */
- if (out_endp_int & DOEPINTF_TF) {
- /* clear the interrupt bit */
- USB_DOEPxINTF(1) = DOEPINTF_TF;
-
- if (1U == pudev->cfg.dma_enable) {
- out_endp_size = USB_DOEPxLEN(1);
-
- /* handle more than one single MPS size packet */
- pudev->dev.out_ep[1].xfer_count = pudev->dev.out_ep[1].endp_mps - \
- (out_endp_size & DOEPLEN_TLEN);
- }
-
- /* inform upper layer: data ready */
-
- /* receive complete */
- usbd_out_transaction(pudev, 1);
- }
-
- /* endpoint disable interrupt */
- if (out_endp_int & DOEPINTF_EPDIS) {
- /* clear the interrupt bit */
- USB_DOEPxINTF(1) = DOEPINTF_EPDIS;
- }
-
- return 1;
-}
-
-/*!
- \brief USB dedicated IN endpoint 1 interrupt service routine handler
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval operation status
-*/
-uint32_t USBD_EP1IN_ISR_Handler (usb_core_handle_struct *pudev)
-{
- uint32_t fifoemptymask = 0, mask = 0;
- uint32_t in_endp_int = 0;
-
- mask = USB_DIEP1INTEN;
- mask |= ((USB_DIEPFEINTEN >> 1) & 0x01) << 7;
- in_endp_int = USB_DIEPxINTF(1) & mask;
-
- if (in_endp_int & DIEPINTF_TF) {
- fifoemptymask = 0x01 << 1;
- USB_DIEPFEINTEN &= ~fifoemptymask;
-
- USB_DIEPxINTF(1) = DIEPINTF_TF;
-
- /* transmit complete */
- usbd_in_transaction(pudev , 1);
- }
-
- if (in_endp_int & DIEPINTF_EPDIS) {
- USB_DIEPxINTF(1) = DIEPINTF_EPDIS;
- }
-
- if (in_endp_int & DIEPINTF_CITO) {
- USB_DIEPxINTF(1) = DIEPINTF_CITO;
- }
-
- if (in_endp_int & DIEPINTF_EPTXFUD) {
- USB_DIEPxINTF(1) = DIEPINTF_EPTXFUD;
- }
-
- if (in_endp_int & DIEPINTF_IEPNE) {
- USB_DIEPxINTF(1) = DIEPINTF_IEPNE;
- }
-
- if (in_endp_int & DIEPINTF_TXFE) {
- usbd_emptytxfifo_write(pudev, 1);
-
- USB_DIEPxINTF(1) = DIEPINTF_IEPNE;
- }
-
- return 1;
-}
-
-#endif
-
-
-/*!
- \brief USB device-mode interrupts global service routine handler
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval operation status
-*/
-uint32_t usbd_isr (usb_core_handle_struct *pudev)
-{
- uint32_t retval = 0U;
- uint32_t int_status = 0U, gintf = USB_GINTF, ginten = USB_GINTEN;
-
- /* ensure the core is in device mode */
- if (DEVICE_MODE == USB_CURRENT_MODE_GET()) {
- int_status = gintf & ginten;
-
- /* there are no interrupts, avoid spurious interrupt */
- if (!int_status) {
- return 0U;
- }
-
- /* OUT endpoints interrupts */
- if (int_status & GINTF_OEPIF) {
- retval |= usbd_intf_outep(pudev);
- }
-
- /* IN endpoints interrupts */
- if (int_status & GINTF_IEPIF) {
- retval |= usbd_intf_inep(pudev);
- }
-
- /* mode mismatch interrupt */
- if (int_status & GINTF_MFIF) {
- /* clear interrupt */
- USB_GINTF = GINTF_MFIF;
- }
-
- /* early suspend interrupt */
- if (int_status & GINTF_ESP) {
- retval |= usbd_intf_earlysuspend(pudev);
- }
-
- /* suspend interrupt */
- if (int_status & GINTF_SP) {
- retval |= usbd_intf_suspend(pudev);
- }
-
- /* wakeup interrupt */
- if (int_status & GINTF_WKUPIF) {
- retval |= usbd_intf_resume(pudev);
- }
-
- /* start of frame interrupt */
- if (int_status & GINTF_SOF) {
- retval |= usbd_intf_sof(pudev);
- }
-
- /* reveive fifo not empty interrupt */
- if (int_status & GINTF_RXFNEIF) {
- retval |= usbd_intf_rxfifo(pudev);
- }
-
- /* USB reset interrupt */
- if (int_status & GINTF_RST) {
- retval |= usbd_intf_reset(pudev);
- }
-
- /* enumeration has been finished interrupt */
- if (int_status & GINTF_ENUMFIF) {
- retval |= usbd_intf_enumfinish(pudev);
- }
-
- /* incomplete synchronization in transfer interrupt*/
- if (int_status & GINTF_ISOINCIF) {
- retval |= usbd_intf_isoinincomplete(pudev);
- }
-
- /* incomplete synchronization out transfer interrupt*/
- if (int_status & GINTF_ISOONCIF) {
- retval |= usbd_intf_isooutincomplete(pudev);
- }
-
-#ifdef VBUS_SENSING_ENABLED
-
- /* session request interrupt */
- if (int_status & GINTF_SESIF) {
- retval |= usbd_intf_sessionrequest(pudev);
- }
-
- /* OTG mode interrupt */
- if (int_status & GINTF_OTGIF) {
- retval |= usbd_intf_otg(pudev);
- }
-#endif /* VBUS_SENSING_ENABLED */
- }
-
- return retval;
-}
-
-/*!
- \brief indicates that an OUT endpoint has a pending interrupt
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval operation status
-*/
-static uint32_t usbd_intf_outep (usb_core_handle_struct *pudev)
-{
- uint8_t endp_num = 0U;
- uint32_t endp_intr = 0U;
-
- __IO uint32_t out_endp_intr = 0U;
-
- /* read in the device interrupt bits */
- USB_DAOEP_INTR_READ(endp_intr);
-
- while (endp_intr) {
- if (endp_intr & 0x1U) {
- USB_DOEP_INTR_READ(out_endp_intr, (uint16_t)endp_num);
-
- /* transfer complete interrupt */
- if (out_endp_intr & DOEPINTF_TF) {
- USB_DOEPxINTF((uint16_t)endp_num) = DOEPINTF_TF;
-
- if (1U == pudev->cfg.dma_enable) {
- uint32_t xfer_size = USB_DOEPxLEN((uint16_t)endp_num) & DOEPLEN_TLEN;
-
- pudev->dev.out_ep[endp_num].xfer_count = pudev->dev.out_ep[endp_num].endp_mps - \
- xfer_size;
- }
-
- /* data receive is completed */
- usbd_out_transaction(pudev, endp_num);
-
- if (1U == pudev->cfg.dma_enable) {
- if ((0U == endp_num) && (USB_CTRL_STATUS_OUT == pudev->dev.ctl_status)) {
- /* prepare to receive more setup packets */
- usb_ep0_startout(pudev);
- }
- }
- }
-
- /* endpoint disable interrupt */
- if (out_endp_intr & DOEPINTF_EPDIS) {
- USB_DOEPxINTF((uint16_t)endp_num) = DOEPINTF_EPDIS;
- }
-
- /* setup phase finished interrupt (just for control endpoints) */
- if (out_endp_intr & DOEPINTF_STPF) {
- /* setup phase is completed */
- usbd_setup_transaction(pudev);
-
- USB_DOEPxINTF((uint16_t)endp_num) = DOEPINTF_STPF;
- }
-
- /* back to back setup packets received */
- if (out_endp_intr & DOEPINTF_BTBSTP) {
- USB_DOEPxINTF((uint16_t)endp_num) = DOEPINTF_BTBSTP;
- }
- }
-
- endp_num ++;
- endp_intr >>= 1;
- }
-
- return 1U;
-}
-
-/*!
- \brief indicates that an IN endpoint has a pending interrupt
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval operation status
-*/
-static uint32_t usbd_intf_inep(usb_core_handle_struct *pudev)
-{
- uint8_t endp_num = 0U;
- uint32_t endp_intr = 0U;
-
- __IO uint32_t in_endp_intr = 0U;
-
- /* get all in endpoints which have interrupts */
- USB_DAIEP_INTR_READ(endp_intr);
-
- while (endp_intr) {
- if (endp_intr & 0x1U) {
- USB_DIEP_INTR_READ(in_endp_intr, (uint16_t)endp_num);
-
- if (in_endp_intr & DIEPINTF_TF) {
- /* disable the fifo empty interrupt for the endpoint */
- USB_DIEPFEINTEN &= ~(0x1U << endp_num);
-
- USB_DIEPxINTF((uint16_t)endp_num) = DIEPINTF_TF;
-
- /* data transmittion is completed */
- usbd_in_transaction(pudev, endp_num);
-
- if (1U == pudev->cfg.dma_enable) {
- if ((0U == endp_num) && (USB_CTRL_STATUS_IN == pudev->dev.ctl_status)) {
- /* prepare to receive more setup packets */
- usb_ep0_startout(pudev);
- }
- }
- }
-
- if (in_endp_intr & DIEPINTF_CITO) {
- USB_DIEPxINTF((uint16_t)endp_num) = DIEPINTF_CITO;
- }
-
- if (in_endp_intr & DIEPINTF_IEPNE) {
- USB_DIEPxINTF((uint16_t)endp_num) = DIEPINTF_IEPNE;
- }
-
- if (in_endp_intr & DIEPINTF_EPDIS) {
- USB_DIEPxINTF((uint16_t)endp_num) = DIEPINTF_EPDIS;
- }
-
- if (in_endp_intr & DIEPINTF_TXFE) {
- usbd_emptytxfifo_write(pudev, endp_num);
- USB_DIEPxINTF((uint16_t)endp_num) = DIEPINTF_TXFE;
- }
- }
-
- endp_num ++;
- endp_intr >>= 1;
- }
-
- return 1U;
-}
-
-/*!
- \brief indicates that early SUSPEND state has been detected on the USB
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval operation status
-*/
-static uint32_t usbd_intf_earlysuspend (usb_core_handle_struct *pudev)
-{
- USB_GINTEN &= ~GINTEN_ESPIE;
- USB_GINTF = GINTF_ESP;
-
- return 1U;
-}
-
-/*!
- \brief indicates that SUSPEND state has been detected on the USB
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval operation status
-*/
-static uint32_t usbd_intf_suspend(usb_core_handle_struct *pudev)
-{
- __IO uint8_t low_power = pudev->cfg.low_power;
- __IO uint8_t suspend = (uint8_t)(USB_DSTAT & DSTAT_SPST);
- __IO uint8_t is_configured = (pudev->dev.status == USB_STATUS_CONFIGURED)? 1U : 0U;
-
- pudev->dev.prev_status = pudev->dev.status;
- pudev->dev.status = USB_STATUS_SUSPENDED;
-
- if (low_power && suspend && is_configured) {
- /* switch-off the otg clocks */
- USB_PWRCLKCTL |= PWRCLKCTL_SUCLK | PWRCLKCTL_SHCLK;
-
- /* enter DEEP_SLEEP mode with LDO in low power mode */
- pmu_to_deepsleepmode(PMU_LDO_LOWPOWER, WFI_CMD);
- }
-
- /* clear interrupt */
- USB_GINTF = GINTF_SP;
-
- return 1U;
-}
-
-/*!
- \brief indicates that the USB controller has detected a resume or remote Wake-up sequence
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval operation status
-*/
-static uint32_t usbd_intf_resume (usb_core_handle_struct *pudev)
-{
- pudev->dev.status = pudev->dev.prev_status;
- pudev->dev.status = USB_STATUS_CONFIGURED;
-
- /* clear interrupt */
- USB_GINTF = GINTF_WKUPIF;
-
- return 1U;
-}
-
-/*!
- \brief handle the SOF interrupts
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval operation status
-*/
-static uint32_t usbd_intf_sof(usb_core_handle_struct *pudev)
-{
-// USBD_DCD_INT_fops->SOF(pudev);
-
- USB_GINTF = GINTF_SOF;
-
- return 1U;
-}
-
-/*!
- \brief handle the Rx status queue level interrupt
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval operation status
-*/
-static uint32_t usbd_intf_rxfifo (usb_core_handle_struct *pudev)
-{
- usb_ep_struct *ep;
- uint8_t data_pid = 0U, endp_num = 0U;
- uint32_t bcount = 0U;
-
- /* get the status from the top of the fifo (must be read to a variable) */
- __IO uint32_t rx_status = USB_GRSTATP;
-
- /* disable the rx fifo non-empty interrupt */
- USB_GINTEN &= ~GINTEN_RXFNEIE;
-
- endp_num = (uint8_t)(rx_status & GRSTATP_EPNUM);
- bcount = (rx_status & GRSTATP_BCOUNT) >> 4U;
- data_pid = (uint8_t)((rx_status & GRSTATP_DPID) >> 15U);
-
- if ((endp_num == 1) && ((*(uint32_t *)0x40040B30 & 0x1FF80000) == 0)) {
- *(uint32_t *)0x40040B20 = ((*(uint32_t *)0x40040B20 | 0x08000000) & 0x3FFFFFFF);
- }
-
- ep = &pudev->dev.out_ep[endp_num];
-
- switch ((rx_status & GRSTATP_RPCKST) >> 17U) {
- case RXSTAT_GOUT_NAK:
- if(0U != bcount) {
- return 0U;
- }
- break;
- case RXSTAT_DATA_UPDT:
- if (bcount > 0U) {
- usb_fifo_read(ep->xfer_buff, (uint16_t)bcount);
- ep->xfer_buff += bcount;
- ep->xfer_count += bcount;
- }
- break;
- case RXSTAT_XFER_COMP:
- if (0U != bcount) {
- return 0U;
- }
- break;
- case RXSTAT_SETUP_COMP:
- if(0U != bcount) {
- return 0U;
- }
- break;
- case RXSTAT_SETUP_UPDT:
- if ((0U == endp_num) && (8U == bcount) && (DPID_DATA0 == data_pid)) {
- /* copy the setup packet received in fifo into the setup buffer in ram */
- usb_fifo_read(pudev->dev.setup_packet, 8U);
-
- ep->xfer_count += bcount;
- }
- break;
- default:
- break;
- }
-
- /* enable the Rx fifo non-empty interrupt */
- USB_GINTEN |= GINTEN_RXFNEIE;
-
- return 1U;
-}
-
-/*!
- \brief handle USB reset interrupt
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval status
-*/
-static uint32_t usbd_intf_reset(usb_core_handle_struct *pudev)
-{
- uint8_t i = 0U;
- usb_ep_struct *ep;
-
- /* clear the remote wakeup signaling */
- USB_DCTL &= ~DCTL_RWKUP;
-
- /* flush the tx fifo */
- usb_txfifo_flush(pudev, 0U);
-
- for (i = 0U; i < pudev->cfg.dev_endp_num; i++) {
- USB_DIEPxINTF((uint16_t)i) = 0xFFU;
- USB_DOEPxINTF((uint16_t)i) = 0xFFU;
- }
-
- /* clear all pending device endpoint interrupts */
- USB_DAEPINT = 0xFFFFFFFF;
-
- /* enable endpoint 0 interrupts */
- USB_DAEPINTEN &= ~DAEPINTEN_OEPIE;
- USB_DAEPINTEN &= ~DAEPINTEN_IEPIE;
- USB_DAEPINTEN = (1U << 16) | 1U;
-
- /* enable out endpoint interrupts */
- USB_DOEPINTEN = DOEPINTEN_STPFEN | DOEPINTEN_TFEN | DOEPINTEN_EPDISEN;
-
-#ifdef USBHS_DEDICATED_EP1_ENABLED
- USB_DOEP1INTEN = DOEPINTEN_STPFEN | DOEPINTEN_TFEN | DOEPINTEN_EPDISEN;
-#endif
-
- /* enable in endpoint interrupts */
- USB_DIEPINTEN = DIEPINTEN_TFEN | DIEPINTEN_CITOEN | DIEPINTEN_EPDISEN;
-
-#ifdef USBHS_DEDICATED_EP1_ENABLED
- USB_DIEP1INTEN = DIEPINTEN_TFEN | DIEPINTEN_CITOEN | DIEPINTEN_EPDISEN;
-#endif
-
- /* reset device address */
- USB_DCFG &= ~DCFG_DAR;
- USB_DCFG |= 0U << 4U;
-
- /* configure endpoint 0 to receive setup packets */
- usb_ep0_startout(pudev);
-
- /* clear usb reset interrupt */
- USB_GINTF = GINTF_RST;
-
- /* open EP0 IN */
- ep = &pudev->dev.in_ep[0];
-
- USB_DIEPxCTL(0U) &= ~DIEP0CTL_MPL;
- USB_DIEPxCTL(0U) &= ~DIEPCTL_EPTYPE;
- USB_DIEPxCTL(0U) &= ~DIEPCTL_TXFNUM;
-
- if (!(USB_DIEPxCTL(0U) & DIEPCTL_EPACT)) {
- USB_DIEPxCTL(0U) |= USB_MAX_EP0_SIZE;
- USB_DIEPxCTL(0U) |= (USB_EPTYPE_CTRL << 18U);
- USB_DIEPxCTL(0U) |= DIEP0CTL_EPACT;
- }
-
- ep->endp_mps = USB_MAX_EP0_SIZE;
- ep->endp_type = USB_EPTYPE_CTRL;
-
- /* open EP0 OUT */
- ep = &pudev->dev.out_ep[0];
-
- USB_DOEPxCTL(0U) &= ~DOEP0CTL_MPL;
- USB_DOEPxCTL(0U) &= ~DOEPCTL_EPTYPE;
-
- if (!(USB_DOEPxCTL(0U) & DOEPCTL_EPACT)) {
- USB_DOEPxCTL(0U) |= USB_MAX_EP0_SIZE;
- USB_DOEPxCTL(0U) |= (USB_EPTYPE_CTRL << 18U);
- USB_DOEPxCTL(0U) |= DOEP0CTL_EPACT;
- }
-
- ep->endp_mps = USB_MAX_EP0_SIZE;
- ep->endp_type = USB_EPTYPE_CTRL;
-
- pudev->dev.status = USB_STATUS_DEFAULT;
-
- return 1U;
-}
-
-/*!
- \brief handle enumeration finish interrupt
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval status
-*/
-static uint32_t usbd_intf_enumfinish(usb_core_handle_struct *pudev)
-{
- uint8_t enum_speed = (uint8_t)((USB_DSTAT & DSTAT_ES) >> 1U);
-
- /* set the max packet size of devie in endpoint based on the enumeration speed */
- USB_DIEPxCTL(0U) |= EP0_MAXLEN[enum_speed];
-
- /* clear global IN NAK */
- USB_DCTL &= ~DCTL_CGINAK;
- USB_DCTL |= DCTL_CGINAK;
-
- /* set USB turn-around time based on device speed and PHY interface */
- if (USB_SPEED_HIGH == USB_SPEED[enum_speed]) {
- pudev->cfg.core_speed = USB_CORE_SPEED_HIGH;
- pudev->cfg.max_packet_size = USBHS_MAX_PACKET_SIZE;
-
- USB_GUSBCS &= ~GUSBCS_UTT;
- USB_GUSBCS |= 0x09U << 10;
- } else {
- pudev->cfg.core_speed = USB_CORE_SPEED_FULL;
- pudev->cfg.max_packet_size = USBFS_MAX_PACKET_SIZE;
-
- USB_GUSBCS &= ~GUSBCS_UTT;
- USB_GUSBCS |= 0x05U << 10;
- }
-
- /* clear interrupt */
- USB_GINTF = GINTF_ENUMFIF;
-
- return 1U;
-}
-
-/*!
- \brief handle the ISO IN incomplete interrupt
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval status
-*/
-static uint32_t usbd_intf_isoinincomplete(usb_core_handle_struct *pudev)
-{
-// USBD_DCD_INT_fops->IsoINIncomplete (pudev);
-
- /* clear interrupt */
- USB_GINTF = GINTF_ISOINCIF;
-
- return 1U;
-}
-
-/*!
- \brief handle the ISO OUT incomplete interrupt
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval status
-*/
-static uint32_t usbd_intf_isooutincomplete(usb_core_handle_struct *pudev)
-{
-// USBD_DCD_INT_fops->IsoOUTIncomplete (pudev);
-
- /* clear interrupt */
- USB_GINTF = GINTF_ISOONCIF;
-
- return 1U;
-}
-
-/*!
- \brief check FIFO for the next packet to be loaded
- \param[in] pudev: pointer to usb device instance
- \param[in] ep_id: endpoint identifier which is in (0..3)
- \param[out] none
- \retval status
-*/
-static uint32_t usbd_emptytxfifo_write(usb_core_handle_struct *pudev, uint8_t ep_num)
-{
- uint32_t len = 0U, word_len = 0U;
- usb_ep_struct *ep;
-
- ep = &pudev->dev.in_ep[ep_num];
- len = ep->xfer_len - ep->xfer_count;
-
- if (len > ep->endp_mps) {
- len = ep->endp_mps;
- }
-
- word_len = (len + 3U) / 4U;
-
- while (((USB_DIEPxTFSTAT((uint16_t)ep_num) & DIEPTFSTAT_IEPTFS) > word_len) &&
- (ep->xfer_count < ep->xfer_len)) {
- /* write the FIFO */
- len = ep->xfer_len - ep->xfer_count;
-
- if (len > ep->endp_mps) {
- len = ep->endp_mps;
- }
-
- word_len = (len + 3U) / 4U;
-
- usb_fifo_write (ep->xfer_buff, ep_num, (uint16_t)len);
-
- ep->xfer_buff += len;
- ep->xfer_count += len;
- }
-
- return 1U;
-}
-
-#ifdef VBUS_SENSING_ENABLED
-
-/*!
- \brief indicates that the USB_OTG controller has detected a connection
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval status
-*/
-static uint32_t usbd_intf_sessionrequest(usb_core_handle_struct *pudev)
-{
- pudev->dev.connection_status = 1U;
-
- /* clear the interrupt bit */
- USB_GINTF = GINTF_SESIF;
-
- return 1;
-}
-
-/*!
- \brief indicates that the USB_OTG controller has detected an OTG event
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval status
-*/
-static uint32_t usbd_intf_otg(usb_core_handle_struct *pudev)
-{
- if (USB_GOTGINTF & GOTGINTF_SESEND) {
- pudev->dev.class_deinit(pudev, 0);
- pudev->dev.connection_status = 0;
- }
-
- /* clear OTG interrupt */
- USB_GOTGINTF |= GOTGINTF_SESEND;
-
- return 1;
-}
-
-#endif /* VBUS_SENSING_ENABLED */
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbd_std.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbd_std.c
deleted file mode 100644
index 0ae93e4472..0000000000
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbd_std.c
+++ /dev/null
@@ -1,699 +0,0 @@
-/*!
- \file usbd_std.c
- \brief USB 2.0 standard handler driver
-*/
-
-/*
- Copyright (C) 2016 GigaDevice
-
- 2016-08-15, V1.0.0, firmware for GD32F4xx
-*/
-
-#include "usbd_std.h"
-#include "usb_core.h"
-
-static usbd_status_enum usbd_standard_request (usb_core_handle_struct *pudev, usb_device_req_struct *req);
-static usbd_status_enum usbd_device_class_request (usb_core_handle_struct *pudev, usb_device_req_struct *req);
-static usbd_status_enum usbd_vendor_request (usb_core_handle_struct *pudev, usb_device_req_struct *req);
-
-static void usbd_setup_request_parse(usb_core_handle_struct *pudev, usb_device_req_struct *req);
-
-static void usbd_getdescriptor (usb_core_handle_struct *pudev, usb_device_req_struct *req);
-static void usbd_setaddress (usb_core_handle_struct *pudev, usb_device_req_struct *req);
-static void usbd_setconfig (usb_core_handle_struct *pudev, usb_device_req_struct *req);
-static void usbd_getconfig (usb_core_handle_struct *pudev, usb_device_req_struct *req);
-static void usbd_getstatus (usb_core_handle_struct *pudev, usb_device_req_struct *req);
-static void usbd_setfeature (usb_core_handle_struct *pudev, usb_device_req_struct *req);
-static void usbd_clrfeature (usb_core_handle_struct *pudev, usb_device_req_struct *req);
-static void usbd_reserved (usb_core_handle_struct *pudev, usb_device_req_struct *req);
-static void usbd_setdescriptor (usb_core_handle_struct *pudev, usb_device_req_struct *req);
-static void usbd_getinterface (usb_core_handle_struct *pudev, usb_device_req_struct *req);
-static void usbd_setinterface (usb_core_handle_struct *pudev, usb_device_req_struct *req);
-static void usbd_synchframe (usb_core_handle_struct *pudev, usb_device_req_struct *req);
-
-static uint8_t* usbd_device_descriptor_get (usb_core_handle_struct *pudev, uint8_t index, uint16_t *pLen);
-static uint8_t* usbd_configuration_descriptor_get (usb_core_handle_struct *pudev, uint8_t index, uint16_t *pLen);
-static uint8_t* usbd_string_descriptor_get (usb_core_handle_struct *pudev, uint8_t index, uint16_t *pLen);
-
-static void (*StandardDeviceRequest[])(usb_core_handle_struct *pudev, usb_device_req_struct *req) =
-{
- usbd_getstatus,
- usbd_clrfeature,
- usbd_reserved,
- usbd_setfeature,
- usbd_reserved,
- usbd_setaddress,
- usbd_getdescriptor,
- usbd_setdescriptor,
- usbd_getconfig,
- usbd_setconfig,
- usbd_getinterface,
- usbd_setinterface,
- usbd_synchframe,
-};
-
-/* get standard descriptor handler */
-static uint8_t* (*standard_descriptor_get[])(usb_core_handle_struct *pudev, uint8_t index, uint16_t *pLen) =
-{
- usbd_device_descriptor_get,
- usbd_configuration_descriptor_get,
- usbd_string_descriptor_get
-};
-
-/*!
- \brief USB setup stage processing
- \param[in] pudev: pointer to USB device instance
- \param[out] none
- \retval USB device operation status
-*/
-usbd_status_enum usbd_setup_transaction(usb_core_handle_struct *pudev)
-{
- usb_device_req_struct req;
-
- usbd_setup_request_parse(pudev, &req);
-
- switch (req.bmRequestType & USB_REQ_MASK) {
- /* standard device request */
- case USB_STANDARD_REQ:
- usbd_standard_request(pudev, &req);
- break;
- /* device class request */
- case USB_CLASS_REQ:
- usbd_device_class_request(pudev, &req);
- break;
- /* vendor defined request */
- case USB_VENDOR_REQ:
- usbd_vendor_request(pudev, &req);
- break;
- default:
- usbd_ep_stall(pudev, req.bmRequestType & 0x80U);
- break;
- }
-
- return USBD_OK;
-}
-
-/*!
- \brief data out stage processing
- \param[in] pudev: pointer to USB device instance
- \param[in] ep_id: endpoint identifier(0..7)
- \param[out] none
- \retval USB device operation status
-*/
-usbd_status_enum usbd_out_transaction (usb_core_handle_struct *pudev, uint8_t endp_num)
-{
- usb_ep_struct *ep;
-
- if (0U == endp_num) {
- ep = &pudev->dev.out_ep[0];
-
- if (USB_CTRL_DATA_OUT == pudev->dev.ctl_status) {
- if (pudev->dev.remain_len > ep->endp_mps) {
- pudev->dev.remain_len -= ep->endp_mps;
-
- if (1U == pudev->cfg.dma_enable) {
- /* update buffer location */
- ep->xfer_buff += ep->endp_mps;
- }
-
- usbd_ep_rx (pudev,
- 0U,
- ep->xfer_buff,
- (uint16_t)USB_MIN(pudev->dev.remain_len, ep->endp_mps));
- } else {
- if (USB_STATUS_CONFIGURED == pudev->dev.status) {
- pudev->dev.class_data_handler(pudev, USBD_RX, 0U);
- }
-
- usbd_ctlstatus_tx(pudev);
- }
- }
- } else if (USB_STATUS_CONFIGURED == pudev->dev.status) {
- pudev->dev.class_data_handler(pudev, USBD_RX, endp_num);
- } else {
- /* no operation */
- }
-
- return USBD_OK;
-}
-
-/*!
- \brief data in stage processing
- \param[in] pudev: pointer to USB device instance
- \param[in] ep_id: endpoint identifier(0..7)
- \param[out] none
- \retval USB device operation status
-*/
-usbd_status_enum usbd_in_transaction (usb_core_handle_struct *pudev, uint8_t endp_num)
-{
- usb_ep_struct *ep;
-
- if (0U == endp_num) {
- ep = &pudev->dev.in_ep[0];
-
- if (USB_CTRL_DATA_IN == pudev->dev.ctl_status) {
- if (pudev->dev.remain_len > ep->endp_mps) {
- pudev->dev.remain_len -= ep->endp_mps;
-
- if (1U == pudev->cfg.dma_enable) {
- /* update buffer location */
- ep->xfer_buff += ep->endp_mps;
- }
-
- usbd_ep_tx (pudev, 0U, ep->xfer_buff, pudev->dev.remain_len);
- } else {
- /* last packet is MPS multiple, so send ZLP packet */
- if ((pudev->dev.sum_len % ep->endp_mps == 0U) &&
- (pudev->dev.sum_len >= ep->endp_mps) &&
- (pudev->dev.sum_len < pudev->dev.ctl_len)) {
- usbd_ep_tx (pudev, 0U, NULL, 0U);
- pudev->dev.ctl_len = 0U;
- } else {
- if (USB_STATUS_CONFIGURED == pudev->dev.status) {
- pudev->dev.class_data_handler(pudev, USBD_TX, 0U);
- }
-
- usbd_ctlstatus_rx(pudev);
- }
- }
- }
- } else if (USB_STATUS_CONFIGURED == pudev->dev.status) {
- pudev->dev.class_data_handler(pudev, USBD_TX, endp_num);
- } else {
- /* no operation */
- }
-
- return USBD_OK;
-}
-
-/*!
- \brief handle USB standard device request
- \param[in] pudev: pointer to USB device instance
- \param[in] req: pointer to USB device request
- \param[out] none
- \retval USB device operation status
-*/
-static usbd_status_enum usbd_standard_request (usb_core_handle_struct *pudev, usb_device_req_struct *req)
-{
- /* call device request handle function */
- (*StandardDeviceRequest[req->bRequest])(pudev, req);
-
- return USBD_OK;
-}
-
-/*!
- \brief handle USB device class request
- \param[in] pudev: pointer to USB device instance
- \param[in] req: pointer to USB device class request
- \param[out] none
- \retval USB device operation status
-*/
-static usbd_status_enum usbd_device_class_request (usb_core_handle_struct *pudev, usb_device_req_struct *req)
-{
- usbd_status_enum ret = USBD_OK;
-
- switch (pudev->dev.status) {
- case USB_STATUS_CONFIGURED:
- if (LOWBYTE(req->wIndex) <= USBD_ITF_MAX_NUM) {
- ret = (usbd_status_enum)(pudev->dev.class_req_handler(pudev, req));
-
- if ((0U == req->wLength) && (USBD_OK == ret)) {
- /* no data stage */
- usbd_ctlstatus_tx(pudev);
- }
- } else {
- usbd_enum_error(pudev, req);
- }
- break;
-
- default:
- usbd_enum_error(pudev, req);
- break;
- }
-
- return ret;
-}
-
-/*!
- \brief handle USB vendor request
- \param[in] pudev: pointer to USB device instance
- \param[in] req: pointer to USB vendor request
- \param[out] none
- \retval USB device operation status
-*/
-static usbd_status_enum usbd_vendor_request (usb_core_handle_struct *pudev, usb_device_req_struct *req)
-{
- /* added by user... */
-
- return USBD_OK;
-}
-
-/*!
- \brief no operation, just for reserved
- \param[in] pudev: pointer to USB device instance
- \param[in] req: pointer to USB device request
- \param[out] none
- \retval none
-*/
-static void usbd_reserved (usb_core_handle_struct *pudev, usb_device_req_struct *req)
-{
- /* no operation... */
-}
-
-/*!
- \brief get the device descriptor
- \brief[in] index: no use
- \param[in] none
- \param[out] pLen: data length pointer
- \retval descriptor buffer pointer
-*/
-static uint8_t* usbd_device_descriptor_get (usb_core_handle_struct *pudev, uint8_t index, uint16_t *pLen)
-{
- *pLen = pudev->dev.dev_desc[0];
-
- return pudev->dev.dev_desc;
-}
-
-/*!
- \brief get the configuration descriptor
- \brief[in] index: no use
- \param[in] none
- \param[out] pLen: data length pointer
- \retval descriptor buffer pointer
-*/
-static uint8_t* usbd_configuration_descriptor_get (usb_core_handle_struct *pudev, uint8_t index, uint16_t *pLen)
-{
- *pLen = pudev->dev.config_desc[2];
-
- return pudev->dev.config_desc;
-}
-
-/*!
- \brief get string descriptor
- \param[in] index: string descriptor index
- \param[in] pLen: pointer to string length
- \param[out] none
- \retval none
-*/
-static uint8_t* usbd_string_descriptor_get (usb_core_handle_struct *pudev, uint8_t index, uint16_t *pLen)
-{
- uint8_t *desc = pudev->dev.strings[index];
-
- *pLen = desc[0];
-
- return desc;
-}
-
-/*!
- \brief handle Get_Status request
- \param[in] pudev: pointer to USB device instance
- \param[in] req: pointer to USB device request
- \param[out] none
- \retval none
-*/
-static void usbd_getstatus (usb_core_handle_struct *pudev, usb_device_req_struct *req)
-{
-}
-
-/*!
- \brief handle USB Clear_Feature request
- \param[in] pudev: pointer to USB device instance
- \param[in] req: USB device request
- \param[out] none
- \retval none
-*/
-static void usbd_clrfeature (usb_core_handle_struct *pudev, usb_device_req_struct *req)
-{
- uint8_t ep_addr = 0U;
-
- switch (req->bmRequestType & USB_REQTYPE_MASK) {
- case USB_REQTYPE_DEVICE:
- switch (pudev->dev.status) {
- case USB_STATUS_ADDRESSED:
- case USB_STATUS_CONFIGURED:
- if (USB_FEATURE_REMOTE_WAKEUP == req->wValue) {
- pudev->dev.remote_wakeup = 0U;
- pudev->dev.class_req_handler(pudev, req);
-
- usbd_ctlstatus_tx(pudev);
- }
- break;
-
- default:
- usbd_enum_error(pudev, req);
- break;
- }
- break;
- case USB_REQTYPE_INTERFACE:
- switch (pudev->dev.status) {
- case USB_STATUS_ADDRESSED:
- usbd_enum_error(pudev, req);
- break;
- case USB_STATUS_CONFIGURED:
- if (LOWBYTE(req->wIndex) <= USBD_ITF_MAX_NUM) {
- /* no operation */
- } else {
- usbd_enum_error(pudev, req);
- }
- break;
- default:
- break;
- }
- break;
- case USB_REQTYPE_ENDPOINT:
- ep_addr = LOWBYTE(req->wIndex);
-
- switch (pudev->dev.status) {
- case USB_STATUS_ADDRESSED:
- if (IS_NOT_EP0(ep_addr)) {
- usbd_ep_stall(pudev, ep_addr);
- }
- break;
- case USB_STATUS_CONFIGURED:
- if (USB_FEATURE_ENDP_HALT == req->wValue) {
- if (IS_NOT_EP0(ep_addr)) {
- usbd_ep_clear_stall(pudev, ep_addr);
-
- pudev->dev.class_req_handler(pudev, req);
- }
- }
- usbd_ctlstatus_tx(pudev);
- break;
- default:
- break;
- }
- break;
- default:
- usbd_enum_error(pudev, req);
- break;
- }
-}
-
-/*!
- \brief handle USB Set_Feature request
- \param[in] pudev: pointer to USB device instance
- \param[in] req: pointer to USB device request
- \param[out] none
- \retval none
-*/
-static void usbd_setfeature (usb_core_handle_struct *pudev, usb_device_req_struct *req)
-{
- uint8_t ep_addr = 0U;
- __IO uint32_t DctlrStatus;
-
- switch (req->bmRequestType & USB_REQ_MASK) {
- case USB_REQTYPE_DEVICE:
- switch (pudev->dev.status) {
- case USB_STATUS_ADDRESSED:
- case USB_STATUS_CONFIGURED:
- if (USB_FEATURE_REMOTE_WAKEUP == req->wValue) {
- pudev->dev.remote_wakeup = 1U;
- pudev->dev.class_req_handler(pudev, req);
-
- usbd_ctlstatus_tx(pudev);
- } else if ((req->wValue == USB_FEATURE_TEST_MODE) &&
- (0U == (req->wIndex & 0xFFU))) {
- DctlrStatus = USB_DCTL;
-
- usbd_ctlstatus_tx(pudev);
- } else {
- /* no operation */
- }
- break;
- default:
- break;
- }
- break;
- case USB_REQTYPE_INTERFACE:
- switch (pudev->dev.status) {
- case USB_STATUS_ADDRESSED:
- usbd_enum_error(pudev, req);
- break;
- case USB_STATUS_CONFIGURED:
- if (LOWBYTE(req->wIndex) <= USBD_ITF_MAX_NUM) {
- /* no operation */
- } else {
- usbd_enum_error(pudev, req);
- }
- break;
- default:
- break;
- }
- break;
- case USB_REQTYPE_ENDPOINT:
- switch (pudev->dev.status) {
- case USB_STATUS_ADDRESSED:
- if (IS_NOT_EP0(ep_addr)) {
- usbd_ep_stall(pudev, ep_addr);
- }
- break;
- case USB_STATUS_CONFIGURED:
- if (USB_FEATURE_ENDP_HALT == req->wValue) {
- if (IS_NOT_EP0(ep_addr)) {
- usbd_ep_stall(pudev, ep_addr);
- }
- }
- pudev->dev.class_req_handler(pudev, req);
-
- usbd_ctlstatus_tx(pudev);
- break;
- default:
- break;
- }
- break;
- default:
- usbd_enum_error(pudev, req);
- break;
- }
-}
-
-/*!
- \brief handle USB Set_Address request
- \param[in] pudev: pointer to USB device instance
- \param[in] req: pointer to USB device request
- \param[out] none
- \retval none
-*/
-static void usbd_setaddress (usb_core_handle_struct *pudev, usb_device_req_struct *req)
-{
- uint8_t DevAddr;
-
- if ((0U == req->wIndex) && (0U == req->wLength)) {
- DevAddr = (uint8_t)(req->wValue) & 0x7FU;
-
- if (USB_STATUS_CONFIGURED == pudev->dev.status) {
- usbd_enum_error(pudev, req);
- } else {
- USB_SET_DEVADDR((uint32_t)DevAddr);
-
- usbd_ctlstatus_tx(pudev);
-
- if (0U != DevAddr) {
- pudev->dev.status = USB_STATUS_ADDRESSED;
- } else {
- pudev->dev.status = USB_STATUS_DEFAULT;
- }
- }
- } else {
- usbd_enum_error(pudev, req);
- }
-}
-
-/*!
- \brief handle USB Get_Descriptor request
- \param[in] pudev: pointer to USB device instance
- \param[in] req: pointer to USB device request
- \param[out] none
- \retval none
-*/
-static void usbd_getdescriptor (usb_core_handle_struct *pudev, usb_device_req_struct *req)
-{
- if (USB_REQTYPE_DEVICE == (req->bmRequestType & USB_REQTYPE_MASK)) {
- uint8_t desc_index = (uint8_t)(req->wValue >> 8U);
-
- if (desc_index <= 0x03U) {
- uint16_t len;
- uint8_t *pbuf;
-
- /* call corresponding descriptor get function */
- pbuf = standard_descriptor_get[desc_index - 1U](pudev, (uint8_t)(req->wValue) & 0xFFU, &len);
-
- if ((0U != len) && (0U != req->wLength)) {
- len = USB_MIN(len, req->wLength);
-
- if ((1U == desc_index) && (64U == req->wLength)) {
- len = 8U;
- }
-
- usbd_ctltx(pudev, pbuf, len);
- }
- } else {
- usbd_enum_error(pudev, req);
- }
- } else if (USB_REQTYPE_INTERFACE == (req->bmRequestType & USB_REQTYPE_MASK)) {
- pudev->dev.class_req_handler(pudev, req);
- } else {
- /* no operation */
- }
-}
-
-/*!
- \brief handle USB Set_Descriptor request
- \param[in] pudev: pointer to USB device instance
- \param[in] req: pointer to USB device request
- \param[out] none
- \retval none
-*/
-static void usbd_setdescriptor (usb_core_handle_struct *pudev, usb_device_req_struct *req)
-{
- /* no handle... */
-}
-
-/*!
- \brief handle USB Get_Configuration request
- \param[in] pudev: pointer to USB device instance
- \param[in] req: pointer to USB device request
- \param[out] none
- \retval none
-*/
-static void usbd_getconfig (usb_core_handle_struct *pudev, usb_device_req_struct *req)
-{
- uint32_t USBD_default_config = 0U;
-
- if (1U != req->wLength) {
- usbd_enum_error(pudev, req);
- } else {
- switch (pudev->dev.status) {
- case USB_STATUS_ADDRESSED:
- usbd_ctltx(pudev, (uint8_t *)&USBD_default_config, 1U);
- break;
- case USB_STATUS_CONFIGURED:
- usbd_ctltx(pudev, &pudev->dev.config_num, 1U);
- break;
- default:
- usbd_enum_error(pudev, req);
- break;
- }
- }
-}
-
-/*!
- \brief handle USB Set_Configuration request
- \param[in] pudev: pointer to USB device instance
- \param[in] req: pointer to USB device request
- \param[out] none
- \retval none
-*/
-static void usbd_setconfig (usb_core_handle_struct *pudev, usb_device_req_struct *req)
-{
- static uint8_t cfgidx;
-
- cfgidx = (uint8_t)(req->wValue);
-
- if (cfgidx > USBD_CFG_MAX_NUM) {
- usbd_enum_error(pudev, req);
- } else {
- switch (pudev->dev.status) {
- case USB_STATUS_ADDRESSED:
- if (cfgidx) {
- pudev->dev.config_num = cfgidx;
- pudev->dev.status = USB_STATUS_CONFIGURED;
- pudev->dev.class_init(pudev, cfgidx);
- }
-
- usbd_ctlstatus_tx(pudev);
- break;
- case USB_STATUS_CONFIGURED:
- if (0U == cfgidx) {
- pudev->dev.status = USB_STATUS_ADDRESSED;
- pudev->dev.config_num = cfgidx;
- pudev->dev.class_deinit(pudev, cfgidx);
- } else if (cfgidx != pudev->dev.config_num) {
- /* clear old configuration */
- pudev->dev.class_deinit(pudev, pudev->dev.config_num);
-
- /* set new configuration */
- pudev->dev.config_num = cfgidx;
- pudev->dev.class_init(pudev, cfgidx);
- } else {
- /* no operation */
- }
-
- usbd_ctlstatus_tx(pudev);
- break;
- default:
- usbd_enum_error(pudev, req);
- break;
- }
- }
-}
-
-/*!
- \brief handle USB Get_Interface request
- \param[in] pudev: pointer to USB device instance
- \param[in] req: pointer to USB device request
- \param[out] none
- \retval none
-*/
-static void usbd_getinterface (usb_core_handle_struct *pudev, usb_device_req_struct *req)
-{
- pudev->dev.class_req_handler(pudev, req);
-}
-
-/*!
- \brief handle USB Set_Interface request
- \param[in] pudev: pointer to USB device instance
- \param[in] req: pointer to USB device request
- \param[out] none
- \retval none
-*/
-static void usbd_setinterface (usb_core_handle_struct *pudev, usb_device_req_struct *req)
-{
- pudev->dev.class_req_handler(pudev, req);
-}
-
-/*!
- \brief handle USB SynchFrame request
- \param[in] pudev: pointer to USB device instance
- \param[in] req: pointer to USB device request
- \param[out] none
- \retval none
-*/
-static void usbd_synchframe (usb_core_handle_struct *pudev, usb_device_req_struct *req)
-{
- /* no handle... */
-}
-
-/*!
- \brief decode setup data packet
- \param[in] pudev: pointer to USB device instance
- \param[in] req: pointer to USB device request
- \param[out] none
- \retval none
-*/
-static void usbd_setup_request_parse(usb_core_handle_struct *pudev, usb_device_req_struct *req)
-{
- uint8_t *psetup = pudev->dev.setup_packet;
-
- req->bmRequestType = *psetup;
- req->bRequest = *(uint8_t *)(psetup + 1U);
- req->wValue = SWAPBYTE (psetup + 2U);
- req->wIndex = SWAPBYTE (psetup + 4U);
- req->wLength = SWAPBYTE (psetup + 6U);
-
- pudev->dev.ctl_len = req->wLength;
-}
-
-/*!
- \brief handle USB low level error event
- \param[in] pudev: pointer to USB device instance
- \param[in] req: pointer to USB device request
- \param[out] none
- \retval none
-*/
-void usbd_enum_error(usb_core_handle_struct *pudev, usb_device_req_struct *req)
-{
- usbd_ep_stall(pudev, 0x80U);
- usbd_ep_stall(pudev, 0x00U);
- usb_ep0_startout(pudev);
-}
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbh_core.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbh_core.c
deleted file mode 100644
index 1c90b55187..0000000000
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbh_core.c
+++ /dev/null
@@ -1,710 +0,0 @@
-/*!
- \file usbh_core.c
- \brief this file implements the functions for the core state machine process
-*/
-
-/*
- Copyright (C) 2016 GigaDevice
-
- 2016-08-15, V1.0.0, firmware for GD32F4xx
-*/
-
-#include "usbh_hcs.h"
-#include "usbh_core.h"
-#include "usbh_int.h"
-#include "stdio.h"
-#include "usbh_std.h"
-#include "usbh_ctrl.h"
-#include "usb_core.h"
-
-extern class_polling_fun_cb_struct class_polling_cb;
-
-uint8_t usbh_sof (usb_core_handle_struct *pudev);
-uint8_t usbh_connected (usb_core_handle_struct *pudev);
-uint8_t usbh_disconnected (usb_core_handle_struct *pudev);
-
-usbh_hcd_int_cb_struct usbh_hcd_int_cb =
-{
- usbh_sof,
- usbh_connected,
- usbh_disconnected,
-};
-
-usbh_hcd_int_cb_struct *usbh_hcd_int_fops = &usbh_hcd_int_cb;
-extern usbh_state_handle_struct usbh_state_core;
-
-static void host_idle_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-static void host_dev_attached_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-static void host_dev_detached_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-static void host_detect_dev_speed_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-static void host_enum_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-static void host_class_request_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-static void host_class_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-static void host_user_input_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-static void host_suspended_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-static void host_error_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-
-static usbh_status_enum class_req_state_polling_fun (usb_core_handle_struct *pudev, usbh_host_struct *puhost, void *pustate);
-static usbh_status_enum class_state_polling_fun (usb_core_handle_struct *pudev, usbh_host_struct *puhost, void *pustate);
-
-/* the host state handle function array */
-void (*host_state_handle[]) (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate) =
-{
- host_idle_handle,
- host_dev_attached_handle,
- host_dev_detached_handle,
- host_detect_dev_speed_handle,
- host_enum_handle,
- host_class_request_handle,
- host_class_handle,
- host_user_input_handle,
- host_suspended_handle,
- host_error_handle,
-};
-
-/* the host state handle table */
-state_table_struct host_handle_table[HOST_HANDLE_TABLE_SIZE] =
-{
- /* the current state the current event the next state the event function */
- {HOST_IDLE, HOST_EVENT_ATTACHED, HOST_DEV_ATTACHED, only_state_move },
- {HOST_DEV_ATTACHED, HOST_EVENT_ENUM, HOST_ENUMERATION, only_state_move },
- {HOST_ENUMERATION, HOST_EVENT_USER_INPUT, HOST_USER_INPUT, only_state_move },
- {HOST_USER_INPUT, HOST_EVENT_CLASS_REQ, HOST_CLASS_REQUEST, only_state_move },
- {HOST_CLASS_REQUEST, HOST_EVENT_CLASS, HOST_CLASS, only_state_move },
- {HOST_CLASS, HOST_EVENT_ERROR, HOST_ERROR, only_state_move },
- {HOST_ERROR, HOST_EVENT_IDLE, HOST_IDLE, only_state_move },
- {HOST_DEV_DETACHED, HOST_EVENT_IDLE, HOST_IDLE, only_state_move },
- {HOST_CLASS_REQUEST, HOST_EVENT_ERROR, HOST_ERROR, only_state_move },
-};
-
-/*!
- \brief the polling function of HOST state
- \param[in] pudev: pointer to usb device
- \param[in] puhost: pointer to usb host
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval none
-*/
-usbh_status_enum host_state_polling_fun (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- void *pustate)
-{
- usbh_state_handle_struct *p_state = (usbh_state_handle_struct *)pustate;
-
- scd_begin(p_state, HOST_FSM_ID);
-
- if (-1 == p_state->usbh_current_state_stack_top) {
- uint8_t cur_state = p_state->usbh_current_state;
-
- if ((0U == hcd_is_device_connected(pudev)) && (HOST_IDLE != cur_state)) {
- if (HOST_DEV_DETACHED != cur_state) {
- p_state->usbh_current_state = HOST_DEV_DETACHED;
- cur_state = HOST_DEV_DETACHED;
- }
- }
-
- host_state_handle[cur_state](pudev, puhost, p_state);
- } else {
- uint8_t stack0_state = p_state->stack[0].state;
-
- if ((0U == hcd_is_device_connected(pudev)) && (HOST_IDLE != stack0_state)) {
- if (HOST_DEV_DETACHED != stack0_state) {
- p_state->stack[0].state = HOST_DEV_DETACHED;
- stack0_state = HOST_DEV_DETACHED;
- p_state->usbh_current_state = HOST_DEV_DETACHED;
- }
- }
-
- host_state_handle[stack0_state](pudev, puhost, p_state);
- }
-
- return USBH_OK;
-}
-
-/*!
- \brief the handle function of HOST_IDLE state
- \param[in] pudev: pointer to usb device
- \param[in] puhost: pointer to usb host
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval none
-*/
-static void host_idle_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
- if (hcd_is_device_connected(pudev)) {
- scd_event_handle(pudev, puhost, pustate, HOST_EVENT_ATTACHED, pustate->usbh_current_state);
-
- if ((void *)0 != pudev->mdelay) {
- pudev->mdelay(100U);
- }
- }
-}
-
-/*!
- \brief the handle function of HOST_DEV_ATTACHED state
- \param[in] pudev: pointer to usb device
- \param[in] puhost: pointer to usb host
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval none
-*/
-static void host_dev_attached_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
- puhost->usr_cb->device_connected();
- puhost->control.hc_out_num = usbh_channel_alloc(pudev, 0x00U);
- puhost->control.hc_in_num = usbh_channel_alloc(pudev, 0x80U);
-
- /* reset usb device */
- if (0U == usb_port_reset(pudev)) {
- puhost->usr_cb->device_reset();
-
- /* wait for USB USBH_ISR_PrtEnDisableChange()
- * host is now ready to start the enumeration
- */
- puhost->device.speed = (uint8_t)USB_CURRENT_SPEED_GET();
- puhost->usr_cb->device_speed_detected(puhost->device.speed);
-
- /* open IN control pipes */
- usbh_channel_open (pudev,
- puhost->control.hc_in_num,
- puhost->device.address,
- puhost->device.speed,
- USB_EPTYPE_CTRL,
- (uint16_t)puhost->control.ep0_size);
-
- /* open OUT control pipes */
- usbh_channel_open (pudev,
- puhost->control.hc_out_num,
- puhost->device.address,
- puhost->device.speed,
- USB_EPTYPE_CTRL,
- (uint16_t)puhost->control.ep0_size);
-
- scd_event_handle(pudev, puhost, pustate, HOST_EVENT_ENUM, pustate->usbh_current_state);
- }
-}
-
-/*!
- \brief the handle function of HOST_ENUMERATION state
- \param[in] pudev: pointer to usb device
- \param[in] puhost: pointer to usb host
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval none
-*/
-static void host_enum_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
- if (USBH_OK == enum_state_polling_fun(pudev, puhost, pustate)) {
- puhost->usr_cb->enumeration_finish();
- scd_event_handle(pudev,
- puhost,
- pustate,
- HOST_EVENT_USER_INPUT,
- pustate->usbh_current_state);
- }
-}
-
-/*!
- \brief the handle function of HOST_USER_INPUT state
- \param[in] pudev: pointer to usb device
- \param[in] puhost: pointer to usb host
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval none
-*/
-static void host_user_input_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
- if (USBH_USER_RESP_OK == puhost->usr_cb->user_input()) {
- if (USBH_OK == (puhost->class_init(pudev, puhost))) {
- scd_event_handle(pudev,
- puhost,
- pustate,
- HOST_EVENT_CLASS_REQ,
- pustate->usbh_current_state);
- }
- }
-}
-
-/*!
- \brief the handle function of HOST_CLASS_REQUEST state
- \param[in] pudev: pointer to usb device
- \param[in] puhost: pointer to usb host
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval none
-*/
-static void host_class_request_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
- if (USBH_OK == class_req_state_polling_fun(pudev, puhost, pustate)) {
- scd_event_handle(pudev, puhost, pustate, HOST_EVENT_CLASS, pustate->usbh_current_state);
- }
-}
-
-/*!
- \brief the handle function of HOST_CLASS state
- \param[in] pudev: pointer to usb device
- \param[in] puhost: pointer to usb host
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval none
-*/
-static void host_class_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
- class_state_polling_fun(pudev, puhost, pustate);
-}
-
-/*!
- \brief the handle function of HOST_SUSPENDED state
- \param[in] pudev: pointer to usb device
- \param[in] puhost: pointer to usb host
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval none
-*/
-static void host_suspended_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
- /* no operation */
-}
-
-/*!
- \brief the handle function of HOST_ERROR state
- \param[in] pudev: pointer to usb device
- \param[in] puhost: pointer to usb host
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval none
-*/
-static void host_error_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
- /* re-initilaize host for new enumeration */
- usbh_deinit (pudev, puhost,&usbh_state_core);
- puhost->usr_cb->deinit();
- puhost->class_deinit(pudev, &puhost->device);
- scd_event_handle(pudev, puhost, pustate, HOST_EVENT_IDLE, pustate->usbh_current_state);
-}
-
-/*!
- \brief the handle function of HOST_DEV_DETACHED state
- \param[in] pudev: pointer to usb device
- \param[in] puhost: pointer to usb host
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval none
-*/
-static void host_dev_detached_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
- /* manage user disconnect operations*/
- puhost->usr_cb->device_disconnected();
-
- /* re-initilaize host for new enumeration */
- usbh_deinit(pudev, puhost,&usbh_state_core);
- puhost->usr_cb->deinit();
- puhost->class_deinit(pudev, &puhost->device);
- usbh_allchannel_dealloc(pudev);
- scd_event_handle(pudev, puhost, pustate, HOST_EVENT_IDLE, pustate->usbh_current_state);
-}
-
-/*!
- \brief the handle function of HOST_DETECT_DEV_SPEED state
- \param[in] pudev: pointer to usb device
- \param[in] puhost: pointer to usb host
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval none
-*/
-static void host_detect_dev_speed_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
- /* no operation */
-}
-
-/*!
- \brief usb connect callback function from the interrupt.
- \param[in] pudev: pointer to usb device
- \param[out] none
- \retval operation status
-*/
-uint8_t usbh_connected (usb_core_handle_struct *pudev)
-{
- pudev->host.connect_status = 1U;
-
- return 0U;
-}
-
-/*!
- \brief usb disconnect callback function from the interrupt.
- \param[in] pudev: pointer to usb device
- \param[out] none
- \retval operation status
-*/
-uint8_t usbh_disconnected (usb_core_handle_struct *pudev)
-{
- pudev->host.connect_status = 0U;
-
- return 0U;
-}
-
-/*!
- \brief usb sof callback function from the interrupt.
- \param[in] pudev: pointer to usb device
- \param[out] none
- \retval operation status
-*/
-uint8_t usbh_sof (usb_core_handle_struct *pudev)
-{
- /* this callback could be used to implement a scheduler process */
- return 0U;
-}
-
-/*!
- \brief initialize the host portion of the driver.
- \param[in] pudev: pointer to usb device
- \param[in] core_id: usb otg core identifier(high-speed or full-speed)
- \param[out] none
- \retval operation status
-*/
-uint32_t hcd_init(usb_core_handle_struct *pudev, usb_core_id_enum core_id)
-{
- pudev->host.connect_status = 0U;
-
- pudev->host.host_channel[0].endp_mps = 8U;
-
- usb_core_select(pudev, core_id);
-
-#ifndef DUAL_ROLE_MODE_ENABLED
-
- USB_GLOBAL_INT_DISABLE();
-
- usb_core_init(pudev);
-
- /* force host mode*/
- usb_mode_set(pudev, HOST_MODE);
-
- usb_hostcore_init(pudev);
-
- USB_GLOBAL_INT_ENABLE();
-
-#endif
-
- return 0U;
-}
-
-/*!
- \brief check if the device is connected.
- \param[in] pudev: pointer to usb device
- \param[out] none
- \retval device connection status. 1 -> connected and 0 -> disconnected
-*/
-uint32_t hcd_is_device_connected(usb_core_handle_struct *pudev)
-{
- return (uint32_t)(pudev->host.connect_status);
-}
-
-/*!
- \brief this function returns the last URBstate
- \param[in] pudev: pointer to usb device
- \param[in] channel_num: host channel number which is in (0..7)
- \param[out] none
- \retval urb_state_enum
-*/
-urb_state_enum hcd_urb_state_get (usb_core_handle_struct *pudev, uint8_t channel_num)
-{
- return pudev->host.host_channel[channel_num].urb_state;
-}
-
-/*!
- \brief this function returns the last URBstate
- \param[in] pudev: pointer to usb device
- \param[in] channel_num: host channel number which is in (0..7)
- \param[out] none
- \retval No. of data bytes transferred
-*/
-uint32_t hcd_xfer_count_get (usb_core_handle_struct *pudev, uint8_t channel_num)
-{
- return pudev->host.host_channel[channel_num].xfer_count;
-}
-
-/*!
- \brief de-initialize host
- \param[in] pudev: pointer to usb device
- \param[in] puhost: pointer to usb host
- \param[out] none
- \retval host status
-*/
-usbh_status_enum usbh_deinit(usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct* pustate)
-{
- /* software init */
-
- puhost->control.ep0_size = USB_MAX_EP0_SIZE;
-
- puhost->device.address = USBH_DEVICE_ADDRESS_DEFAULT;
- puhost->device.speed = HPRT_PRTSPD_FULL_SPEED;
-
- usbh_channel_free(pudev, puhost->control.hc_in_num);
- usbh_channel_free(pudev, puhost->control.hc_out_num);
-
- scd_init(pustate);
- scd_table_regist(pustate, host_handle_table, HOST_FSM_ID, HOST_HANDLE_TABLE_SIZE);
- scd_table_regist(pustate, enum_handle_table, ENUM_FSM_ID, ENUM_HANDLE_TABLE_SIZE);
- scd_table_regist(pustate, ctrl_handle_table, CTRL_FSM_ID, CTRL_HANDLE_TABLE_SIZE);
-
- scd_begin(pustate,HOST_FSM_ID);
- scd_state_move(pustate, HOST_IDLE);
-
- return USBH_OK;
-}
-
-/*!
- \brief state core driver init
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval none
-*/
-void scd_init(usbh_state_handle_struct* pustate)
-{
- /* init the state core */
- pustate->usbh_current_state = 0U;
- pustate->usbh_current_state_table = NULL;
- pustate->usbh_current_state_table_size = 0U;
-
- pustate->usbh_current_state_stack_top = -1;
- pustate->stack->state = 0U;
- pustate->stack->table_size = 0U;
- pustate->stack->table = NULL;
-
- pustate->usbh_regist_state_table_num = 0U;
- pustate->usbh_regist_state_table->table = NULL;
- pustate->usbh_regist_state_table->table_size = 0U;
- pustate->usbh_regist_state_table->id = 0U;
-
- /* init the control and the enumeration polling handle flag */
- ctrl_polling_handle_flag = 0U;
- enum_polling_handle_flag = 0U;
-}
-
-/*!
- \brief state core driver table regist
- \param[in] pustate: pointer to usb state driver
- \param[in] pstate_table: pointer to the table to regist
- \param[in] table_id: the id of the table to regist
- \param[in] current_table_size: the size of the current table to regist
- \param[out] none
- \retval none
-*/
-void scd_table_regist (usbh_state_handle_struct* pustate,
- state_table_struct* pstate_table,
- uint8_t table_id,
- uint8_t current_table_size)
-{
- usbh_state_regist_table_struct *cur_state_reg_table;
-
- cur_state_reg_table = &pustate->usbh_regist_state_table[pustate->usbh_regist_state_table_num];
-
- cur_state_reg_table->id = table_id;
- cur_state_reg_table->table = pstate_table;
- cur_state_reg_table->table_size = current_table_size;
-
- pustate->usbh_regist_state_table_num++;
-}
-
-/*!
- \brief state core driver begin
- \param[in] pustate: pointer to usb state driver
- \param[in] table_id: the id of the table to begin
- \param[out] none
- \retval none
-*/
-void scd_begin(usbh_state_handle_struct* pustate, uint8_t table_id)
-{
- uint8_t i = 0, table_num = pustate->usbh_regist_state_table_num;
- usbh_state_regist_table_struct *cur_state_reg_table;
-
- for (i = 0; i < table_num; i++) {
- cur_state_reg_table = &pustate->usbh_regist_state_table[i];
-
- if (table_id == cur_state_reg_table->id) {
- pustate->usbh_current_state_table = cur_state_reg_table->table;
- pustate->usbh_current_state_table_size = cur_state_reg_table->table_size;
- break;
- }
- }
-}
-
-/*!
- \brief state core driver move state
- \param[in] pustate: pointer to usb state driver
- \param[in] state: the state to move
- \param[out] none
- \retval none
-*/
-void scd_state_move(usbh_state_handle_struct* pustate, uint8_t state)
-{
- pustate->usbh_current_state = state;
-}
-
-/*!
- \brief state core driver event handle
- \param[in] pudev: pointer to usb device
- \param[in] puhost: pointer to usb host
- \param[in] pustate: pointer to usb state driver
- \param[in] event: the current event
- \param[in] state: the current state
- \param[out] none
- \retval host status
-*/
-usbh_status_enum scd_event_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct* pustate,
- uint8_t event,
- uint8_t state)
-{
- uint8_t i = 0;
- ACT_FUN event_act_fun = NULL;
- state_table_struct *backup_state_t = pustate->usbh_current_state_table;
- state_table_struct *executive_state_table = pustate->usbh_current_state_table;
-
- /* look up the table to find the action function */
- for (i = 0; i < pustate->usbh_current_state_table_size; i++) {
- if (state == executive_state_table->cur_state) {
- if (event == executive_state_table->cur_event) {
- state = executive_state_table->next_state;
- event_act_fun = executive_state_table->event_action_fun;
- break;
- } else {
- executive_state_table++;
- }
- } else {
- executive_state_table++;
- }
- }
-
- pustate->usbh_current_state_table = backup_state_t;
-
- /* if the action function is not NULL, execute the action function */
- if (event_act_fun) {
- if (event_act_fun == &only_state_move) {
- pustate->usbh_current_state = state;
- } else {
- return event_act_fun(pudev, puhost, pustate);
- }
- }
-
- return USBH_BUSY;
-}
-
-/*!
- \brief state core driver table push
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval none
-*/
-void scd_table_push(usbh_state_handle_struct* pustate)
-{
- usbh_state_stack_struct *top_state_element;
-
- if (pustate->usbh_current_state_stack_top < MAX_USBH_STATE_STACK_DEEP) {
- pustate->usbh_current_state_stack_top++;
-
- top_state_element = &pustate->stack[pustate->usbh_current_state_stack_top];
-
- /* put the current state table into the state stack */
- top_state_element->state = pustate->usbh_current_state;
- top_state_element->table = pustate->usbh_current_state_table;
- top_state_element->table_size = pustate->usbh_current_state_table_size;
- }
-}
-
-/*!
- \brief state core driver table pop
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval none
-*/
-void scd_table_pop (usbh_state_handle_struct* pustate)
-{
- usbh_state_stack_struct *top_state_element;
-
- top_state_element = &pustate->stack[pustate->usbh_current_state_stack_top];
-
- if (pustate->usbh_current_state_stack_top > -1) {
- /* get the current state table from the state stack */
- pustate->usbh_current_state = top_state_element->state;
- pustate->usbh_current_state_table = top_state_element->table;
- pustate->usbh_current_state_table_size = top_state_element->table_size;
- pustate->usbh_current_state_stack_top--;
- }
-}
-/*!
- \brief the polling function of class req state
- \param[in] pudev: pointer to usb device
- \param[in] puhost: pointer to usb host
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval host status
-*/
-static usbh_status_enum class_req_state_polling_fun (usb_core_handle_struct *pudev, usbh_host_struct *puhost, void *pustate)
-{
- return class_polling_cb.class_req_polling(pudev, puhost, pustate);
-}
-
-/*!
- \brief the polling function of class state
- \param[in] pudev: pointer to usb device
- \param[in] puhost: pointer to usb host
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval host status
-*/
-static usbh_status_enum class_state_polling_fun (usb_core_handle_struct *pudev, usbh_host_struct *puhost, void *pustate)
-{
- return class_polling_cb.class_polling(pudev, puhost, pustate);
-}
-
-/*!
- \brief the function is only used to state move
- \param[in] pudev: pointer to usb device
- \param[in] puhost: pointer to usb host
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval none
-*/
-usbh_status_enum only_state_move (usb_core_handle_struct *pudev, usbh_host_struct *puhost, void *pustate)
-{
- return USBH_OK;
-}
-
-/*!
- \brief the function to the up state
- \param[in] pudev: pointer to usb device
- \param[in] puhost: pointer to usb host
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval none
-*/
-usbh_status_enum goto_up_state_fun (usb_core_handle_struct *pudev, usbh_host_struct *puhost, void *pustate)
-{
- scd_table_pop((usbh_state_handle_struct *)pustate);
-
- return USBH_OK;
-}
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbh_ctrl.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbh_ctrl.c
deleted file mode 100644
index b61484053e..0000000000
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbh_ctrl.c
+++ /dev/null
@@ -1,620 +0,0 @@
-/*!
- \file usbh_ctrl.c
- \brief this file implements the functions for the control transmit process
-*/
-
-/*
- Copyright (C) 2016 GigaDevice
-
- 2016-08-15, V1.0.0, firmware for GD32F4xx
-*/
-#include "usbh_core.h"
-#include "usbh_std.h"
-#include "usbh_ctrl.h"
-
-uint8_t ctrl_polling_handle_flag = 0U;
-uint8_t ctrl_setup_wait_flag = 0U;
-uint8_t ctrl_data_wait_flag = 0U;
-uint8_t ctrl_status_wait_flag = 0U;
-
-static uint16_t timeout = 0U;
-
-static void ctrl_idle_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-static void ctrl_setup_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-static void ctrl_data_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-static void ctrl_status_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-static void ctrl_error_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-static void ctrl_stalled_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-static void ctrl_complete_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-
-/* the ctrl state handle function array */
-void (*ctrl_state_handle[]) (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate) =
-{
- ctrl_idle_handle,
- ctrl_setup_handle,
- ctrl_data_handle,
- ctrl_status_handle,
- ctrl_error_handle,
- ctrl_stalled_handle,
- ctrl_complete_handle,
-};
-
-/* the ctrl state handle table */
-state_table_struct ctrl_handle_table[CTRL_HANDLE_TABLE_SIZE] =
-{
- /* the current state the current event the next state the event function */
- {CTRL_IDLE, CTRL_EVENT_SETUP, CTRL_SETUP, only_state_move },
- {CTRL_SETUP, CTRL_EVENT_DATA, CTRL_DATA, only_state_move },
- {CTRL_SETUP, CTRL_EVENT_STATUS, CTRL_STATUS, only_state_move },
- {CTRL_SETUP, CTRL_EVENT_ERROR, CTRL_ERROR, only_state_move },
- {CTRL_DATA, CTRL_EVENT_STATUS, CTRL_STATUS, only_state_move },
- {CTRL_DATA, CTRL_EVENT_ERROR, CTRL_ERROR, only_state_move },
- {CTRL_DATA, CTRL_EVENT_STALLED, CTRL_STALLED, only_state_move },
- {CTRL_STATUS, CTRL_EVENT_COMPLETE, CTRL_COMPLETE, only_state_move },
- {CTRL_STATUS, CTRL_EVENT_ERROR, CTRL_ERROR, only_state_move },
- {CTRL_STATUS, CTRL_EVENT_STALLED, CTRL_STALLED, only_state_move },
- {CTRL_ERROR, GO_TO_UP_STATE_EVENT, UP_STATE, goto_up_state_fun },
- {CTRL_STALLED, GO_TO_UP_STATE_EVENT, UP_STATE, goto_up_state_fun },
- {CTRL_COMPLETE, GO_TO_UP_STATE_EVENT, UP_STATE, goto_up_state_fun },
-};
-
-/*!
- \brief the polling function of CTRL state
- \param[in] pudev: pointer to usb device
- \param[in] puhost: pointer to usb host
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval none
-*/
-usbh_status_enum ctrl_state_polling_fun (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- void *pustate)
-{
- usbh_status_enum exe_state = USBH_BUSY;
- usbh_state_handle_struct *p_state;
-
- p_state = (usbh_state_handle_struct *)pustate;
-
- /* if first enter this function, begin the ctrl state */
- if (0U == ctrl_polling_handle_flag) {
- ctrl_polling_handle_flag = 1U;
- scd_table_push(p_state);
- scd_state_move(p_state, CTRL_IDLE);
- }
-
- /* base on the current state to handle the ctrl state */
- scd_begin(p_state, CTRL_FSM_ID);
- ctrl_state_handle[p_state->usbh_current_state](pudev, puhost, p_state);
-
- /* determine the control transfer whether to complete */
- switch (puhost->usbh_backup_state.ctrl_backup_state) {
- case CTRL_COMPLETE:
- ctrl_polling_handle_flag = 0U;
- puhost->usbh_backup_state.ctrl_backup_state = CTRL_IDLE;
- exe_state = USBH_OK;
- break;
- case CTRL_STALLED:
- ctrl_polling_handle_flag = 0U;
- puhost->usbh_backup_state.ctrl_backup_state = CTRL_IDLE;
- exe_state = USBH_NOT_SUPPORTED;
- break;
- case CTRL_ERROR:
- ctrl_polling_handle_flag = 0U;
- puhost->usbh_backup_state.ctrl_backup_state = CTRL_IDLE;
- exe_state = USBH_FAIL;
- break;
- default:
- exe_state = USBH_BUSY;
- break;
- }
-
- return exe_state;
-}
-
-/*!
- \brief the handle function of CTRL_IDLE state
- \param[in] pudev: pointer to usb device
- \param[in] puhost: pointer to usb host
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval none
-*/
-static void ctrl_idle_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
- puhost->usbh_backup_state.ctrl_backup_state = CTRL_IDLE;
- scd_event_handle(pudev, puhost, pustate, CTRL_EVENT_SETUP, pustate->usbh_current_state);
-}
-
-/*!
- \brief the handle function of CTRL_SETUP state
- \param[in] pudev: pointer to usb device
- \param[in] puhost: pointer to usb host
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval none
-*/
-static void ctrl_setup_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
- urb_state_enum urb_status = URB_IDLE;
- puhost->usbh_backup_state.ctrl_backup_state = CTRL_SETUP;
-
- if (0U == ctrl_setup_wait_flag) {
- ctrl_setup_wait_flag = 1U;
-
- /* send a setup packet */
- usbh_ctltx_setup (pudev,
- puhost->control.setup.data,
- puhost->control.hc_out_num);
- } else {
- urb_status = hcd_urb_state_get(pudev, puhost->control.hc_out_num);
-
- /* case setup packet sent successfully */
- if (URB_DONE == urb_status) {
- /* check if there is a data stage */
- if (0U != puhost->control.setup.b.wLength) {
- ctrl_setup_wait_flag = 0U;
- timeout = DATA_STAGE_TIMEOUT;
- scd_event_handle(pudev, puhost, pustate, CTRL_EVENT_DATA, pustate->usbh_current_state);
- /* no data stage */
- } else {
- timeout = NODATA_STAGE_TIMEOUT;
- ctrl_setup_wait_flag = 0U;
- scd_event_handle(pudev,
- puhost,
- pustate,
- CTRL_EVENT_STATUS,
- pustate->usbh_current_state);
- }
-
- /* set the delay timer to enable timeout for data stage completion */
- puhost->control.timer = (uint16_t)USB_CURRENT_FRAME_GET();
- } else if (URB_ERROR == urb_status) {
- ctrl_setup_wait_flag = 0U;
- scd_event_handle(pudev, puhost, pustate, CTRL_EVENT_ERROR, pustate->usbh_current_state);
- } else {
- /* no operation */
- }
- }
-}
-
-/*!
- \brief the handle function of CTRL_DATA state
- \param[in] pudev: pointer to usb device
- \param[in] puhost: pointer to usb host
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval none
-*/
-static void ctrl_data_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
- uint8_t direction;
- urb_state_enum urb_status = URB_IDLE;
- puhost->usbh_backup_state.ctrl_backup_state = CTRL_DATA;
-
- direction = (puhost->control.setup.b.bmRequestType & USB_DIR_MASK);
-
- if (USB_DIR_IN == direction) {
- if (0U == ctrl_data_wait_flag) {
- ctrl_data_wait_flag = 1U;
-
- /* issue an IN token */
- usbh_xfer(pudev,
- puhost->control.buff,
- puhost->control.hc_in_num,
- puhost->control.length);
- } else {
- urb_status = hcd_urb_state_get(pudev, puhost->control.hc_in_num);
-
- /* check is data packet transfered successfully */
- switch (urb_status) {
- case URB_DONE:
- ctrl_data_wait_flag = 0U;
-
- scd_event_handle(pudev,
- puhost,
- pustate,
- CTRL_EVENT_STATUS,
- pustate->usbh_current_state);
- break;
- case URB_STALL:
- ctrl_data_wait_flag = 0U;
-
- scd_event_handle(pudev,
- puhost,
- pustate,
- CTRL_EVENT_STALLED,
- pustate->usbh_current_state);
- break;
- case URB_ERROR:
- ctrl_data_wait_flag = 0U;
-
- /* device error */
- scd_event_handle(pudev,
- puhost,
- pustate,
- CTRL_EVENT_ERROR,
- pustate->usbh_current_state);
- break;
- default:
- if (((uint16_t)USB_CURRENT_FRAME_GET() - puhost->control.timer) > timeout) {
- ctrl_data_wait_flag = 0U;
-
- /* timeout for IN transfer */
- scd_event_handle(pudev,
- puhost,
- pustate,
- CTRL_EVENT_ERROR,
- pustate->usbh_current_state);
- }
- break;
- }
- }
- } else {
- if (0U == ctrl_data_wait_flag) {
- ctrl_data_wait_flag = 1U;
-
- /* start DATA out transfer (only one DATA packet)*/
- pudev->host.host_channel[puhost->control.hc_out_num].data_tg_out = 1U;
-
- usbh_xfer(pudev,
- puhost->control.buff,
- puhost->control.hc_out_num,
- puhost->control.length);
- } else {
- urb_status = hcd_urb_state_get(pudev, puhost->control.hc_out_num);
-
- switch (urb_status) {
- case URB_DONE:
- ctrl_data_wait_flag = 0U;
-
- /* if the setup pkt is sent successful, then change the state */
- scd_event_handle(pudev,
- puhost,
- pustate,
- CTRL_EVENT_STATUS,
- pustate->usbh_current_state);
- break;
- case URB_STALL:
- ctrl_data_wait_flag = 0U;
-
- scd_event_handle(pudev,
- puhost,
- pustate,
- CTRL_EVENT_STALLED,
- pustate->usbh_current_state);
- break;
- case URB_NOTREADY:
- /* nack received from device */
- ctrl_data_wait_flag = 0U;
- break;
- case URB_ERROR:
- ctrl_data_wait_flag = 0U;
-
- /* device error */
- scd_event_handle(pudev,
- puhost,
- pustate,
- CTRL_EVENT_ERROR,
- pustate->usbh_current_state);
- break;
- default:
- break;
- }
- }
- }
-}
-
-/*!
- \brief the handle function of CTRL_STATUS state
- \param[in] pudev: pointer to usb device
- \param[in] puhost: pointer to usb host
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval none
-*/
-static void ctrl_status_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
- uint8_t direction;
- urb_state_enum urb_status = URB_IDLE;
-
- puhost->usbh_backup_state.ctrl_backup_state = CTRL_STATUS;
-
- /* get the transfer direction in the data state, but the transfer direction in the status state is opposite */
- direction = (puhost->control.setup.b.bmRequestType & USB_DIR_MASK);
-
- if (USB_DIR_OUT == direction) {
- /* handle status in */
- if (0U == ctrl_status_wait_flag) {
- ctrl_status_wait_flag = 1U;
- usbh_xfer (pudev, 0U, puhost->control.hc_in_num, 0U);
- } else {
- urb_status = hcd_urb_state_get(pudev, puhost->control.hc_in_num);
-
- switch (urb_status) {
- case URB_DONE:
- ctrl_status_wait_flag = 0U;
-
- /* handle URB_DONE status */
- scd_event_handle(pudev,
- puhost,
- pustate,
- CTRL_EVENT_COMPLETE,
- pustate->usbh_current_state);
- break;
- case URB_ERROR:
- ctrl_status_wait_flag = 0U;
-
- /* handle URB_STALL status*/
- scd_event_handle(pudev,
- puhost,
- pustate,
- CTRL_EVENT_ERROR,
- pustate->usbh_current_state);
- break;
- case URB_STALL:
- ctrl_status_wait_flag = 0U;
-
- /* handle URB_STALL status */
- scd_event_handle(pudev,
- puhost,
- pustate,
- CTRL_EVENT_STALLED,
- pustate->usbh_current_state);
- break;
- default:
- if (((uint16_t)USB_CURRENT_FRAME_GET() - puhost->control.timer) > timeout) {
- ctrl_status_wait_flag = 0U;
-
- /* handle timeout */
- scd_event_handle(pudev,
- puhost,
- pustate,
- CTRL_EVENT_ERROR,
- pustate->usbh_current_state);
- }
- break;
- }
- }
- } else {
- /* handle status out */
- if (0U == ctrl_status_wait_flag) {
- ctrl_status_wait_flag = 1U;
- pudev->host.host_channel[puhost->control.hc_out_num].data_tg_out ^= 1U;
- usbh_xfer (pudev, 0U, puhost->control.hc_out_num, 0U);
-
- {
- uint32_t host_ctlr = 0;
-
- host_ctlr = USB_HCHxLEN(puhost->control.hc_out_num);
- USB_HCHxLEN(puhost->control.hc_out_num) = host_ctlr | 1;
- host_ctlr = USB_HCHxCTL(puhost->control.hc_out_num);
- USB_HCHxCTL(puhost->control.hc_out_num) = (host_ctlr & 0x3FFFFFFF) | 0x80000000;
- }
- } else {
- urb_status = hcd_urb_state_get(pudev, puhost->control.hc_out_num);
-
- switch (urb_status) {
- case URB_DONE:
- ctrl_status_wait_flag = 0U;
-
- /* handle URB_DONE status */
- scd_event_handle(pudev,
- puhost,
- pustate,
- CTRL_EVENT_COMPLETE,
- pustate->usbh_current_state);
- break;
- case URB_NOTREADY:
- /* handle URB_NOTREADY status */
- ctrl_status_wait_flag = 0U;
- break;
- case URB_ERROR:
- ctrl_status_wait_flag = 0U;
-
- /* handle URB_ERROR status */
- scd_event_handle(pudev,
- puhost,
- pustate,
- CTRL_EVENT_ERROR,
- pustate->usbh_current_state);
- break;
- default:
- break;
- }
- }
- }
-}
-
-/*!
- \brief the handle function of CTRL_ERROR state
- \param[in] pudev: pointer to usb device
- \param[in] puhost: pointer to usb host
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval none
-*/
-static void ctrl_error_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
- puhost->usbh_backup_state.ctrl_backup_state = CTRL_ERROR;
-
- if (++puhost->control.error_count <= USBH_MAX_ERROR_COUNT) {
- /* do the transmission again, starting from SETUP Packet */
- scd_event_handle(pudev, puhost, pustate, CTRL_EVENT_SETUP, pustate->usbh_current_state);
- } else {
- scd_event_handle(pudev, puhost, pustate, GO_TO_UP_STATE_EVENT, pustate->usbh_current_state);
- }
-}
-
-/*!
- \brief the handle function of CTRL_STALLED state
- \param[in] pudev: pointer to usb device
- \param[in] puhost: pointer to usb host
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval none
-*/
-static void ctrl_stalled_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
- puhost->usbh_backup_state.ctrl_backup_state = CTRL_STALLED;
- scd_event_handle(pudev, puhost, pustate, GO_TO_UP_STATE_EVENT, pustate->usbh_current_state);
-}
-
-/*!
- \brief the handle function of CTRL_COMPLETE state
- \param[in] pudev: pointer to usb device
- \param[in] puhost: pointer to usb host
- \param[in] pustate: pointer to usb state driver
- \param[out] none
- \retval none
-*/
-static void ctrl_complete_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
- puhost->usbh_backup_state.ctrl_backup_state = CTRL_COMPLETE;
- scd_event_handle(pudev, puhost, pustate, GO_TO_UP_STATE_EVENT, pustate->usbh_current_state);
-}
-
-/*!
- \brief send datas from the host channel
- \param[in] pudev: pointer to usb device
- \param[in] buf: data buffer address to send datas
- \param[in] hc_num: the number of the host channel
- \param[in] len: length of the send data
- \param[out] none
- \retval host operation status
-*/
-usbh_status_enum usbh_xfer (usb_core_handle_struct *pudev,
- uint8_t *buf,
- uint8_t hc_num,
- uint16_t len)
-{
- usb_hostchannel_struct *puhc = &pudev->host.host_channel[hc_num];
-
- puhc->xfer_buff = buf;
- puhc->xfer_len = len;
-
- switch (puhc->endp_type) {
- case USB_EPTYPE_CTRL:
- if (0U == puhc->endp_in) {
- if (0U == len) {
- /* for status out stage, length = 0, status out pid = 1 */
- puhc->data_tg_out = 1U;
- }
-
- /* set the data toggle bit as per the flag */
- if (0U == puhc->data_tg_out) {
- /* put the pid 0 */
- puhc->DPID = HC_PID_DATA0;
- } else {
- /* put the pid 1 */
- puhc->DPID = HC_PID_DATA1;
- }
- } else {
- puhc->DPID = HC_PID_DATA1;
- }
- break;
-
- case USB_EPTYPE_ISOC:
- puhc->DPID = HC_PID_DATA0;
- break;
-
- case USB_EPTYPE_BULK:
- if (0U == puhc->endp_in) {
- /* set the data toggle bit as per the flag */
- if (0U == puhc->data_tg_out) {
- /* put the pid 0 */
- puhc->DPID = HC_PID_DATA0;
- } else {
- /* put the pid 1 */
- puhc->DPID = HC_PID_DATA1;
- }
- } else {
- if (0U == puhc->data_tg_in) {
- puhc->DPID = HC_PID_DATA0;
- } else {
- puhc->DPID = HC_PID_DATA1;
- }
- }
- break;
-
- case USB_EPTYPE_INTR:
- if (0U == puhc->endp_in) {
- if (0U == puhc->data_tg_out) {
- puhc->DPID = HC_PID_DATA0;
- } else {
- puhc->DPID = HC_PID_DATA1;
- }
-
- /* toggle data pid */
- puhc->data_tg_out ^= 1U;
- } else {
- if (0U == puhc->data_tg_in) {
- puhc->DPID = HC_PID_DATA0;
- } else {
- puhc->DPID = HC_PID_DATA1;
- }
-
- /* toggle data pid */
- puhc->data_tg_in ^= 1U;
- }
- break;
-
- default:
- break;
- }
-
- hcd_submit_request (pudev, hc_num);
-
- return USBH_OK;
-}
-
-/*!
- \brief send the setup packet to the device
- \param[in] pudev: pointer to usb device
- \param[in] buf: buffer pointer from which the data will be send to device
- \param[in] hc_num: host channel number
- \param[out] none
- \retval host operation status
-*/
-usbh_status_enum usbh_ctltx_setup (usb_core_handle_struct *pudev, uint8_t *buf, uint8_t hc_num)
-{
- usb_hostchannel_struct *puhc = &pudev->host.host_channel[hc_num];
-
- puhc->DPID = HC_PID_SETUP;
- puhc->xfer_buff = buf;
- puhc->xfer_len = USBH_SETUP_PACKET_SIZE;
-
- return (usbh_status_enum)hcd_submit_request (pudev, hc_num);
-}
-
-/*!
- \brief this function prepare a hc and start a transfer
- \param[in] pudev: pointer to usb device
- \param[in] channel_num: host channel number which is in (0..7)
- \param[out] none
- \retval host operation status
-*/
-uint32_t hcd_submit_request (usb_core_handle_struct *pudev, uint8_t channel_num)
-{
- usb_hostchannel_struct *puhc = &pudev->host.host_channel[channel_num];
-
- puhc->urb_state = URB_IDLE;
- puhc->xfer_count = 0U;
-
- return (uint32_t)usb_hostchannel_startxfer(pudev, channel_num);
-}
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbh_hcs.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbh_hcs.c
deleted file mode 100644
index 035459d195..0000000000
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbh_hcs.c
+++ /dev/null
@@ -1,162 +0,0 @@
-/*!
- \file usbh_hcs.c
- \brief this file implements functions for opening and closing host channels
-*/
-
-/*
- Copyright (C) 2016 GigaDevice
-
- 2016-08-15, V1.0.0, firmware for GD32F4xx
-*/
-
-#include "usbh_hcs.h"
-
-static uint16_t usbh_freechannel_get (usb_core_handle_struct *pudev);
-
-/*!
- \brief open a channel
- \param[in] pudev: pointer to usb device
- \param[in] channel_num: host channel number which is in (0..7)
- \param[in] dev_addr: USB device address allocated to attached device
- \param[in] dev_speed: USB device speed (Full speed/Low speed)
- \param[in] ep_type: endpoint type (bulk/int/ctl)
- \param[in] ep_mps: max packet size
- \param[out] none
- \retval operation status
-*/
-uint8_t usbh_channel_open (usb_core_handle_struct *pudev,
- uint8_t channel_num,
- uint8_t dev_addr,
- uint8_t dev_speed,
- uint8_t ep_type,
- uint16_t ep_mps)
-{
- usb_hostchannel_struct *puhc = &pudev->host.host_channel[channel_num];
- uint16_t channel_info = puhc->info;
-
- puhc->endp_id = (uint8_t)channel_info & 0x7FU;
- puhc->endp_in = (uint8_t)(channel_info & 0x80U) >> 7;
- puhc->endp_type = ep_type;
- puhc->endp_mps = ep_mps;
- puhc->dev_addr = dev_addr;
- puhc->dev_speed = dev_speed;
-
- puhc->data_tg_in = 0U;
- puhc->data_tg_out = 0U;
-
- if (HPRT_PRTSPD_HIGH_SPEED == dev_speed) {
- puhc->do_ping = 1U;
- }
-
- usb_hostchannel_init(pudev, channel_num);
-
- return (uint8_t)HC_OK;
-}
-
-/*!
- \brief modify a channel
- \param[in] pudev: pointer to usb device
- \param[in] channel_num: host channel number which is in (0..7)
- \param[in] dev_addr: USB Device address allocated to attached device
- \param[in] dev_speed: USB device speed (Full speed/Low speed)
- \param[in] ep_type: endpoint type (bulk/int/ctl)
- \param[in] ep_mps: max packet size
- \param[out] none
- \retval operation status
-*/
-uint8_t usbh_channel_modify (usb_core_handle_struct *pudev,
- uint8_t channel_num,
- uint8_t dev_addr,
- uint8_t dev_speed,
- uint8_t ep_type,
- uint16_t ep_mps)
-{
- usb_hostchannel_struct *puhc = &pudev->host.host_channel[channel_num];
-
- if (0U != dev_addr) {
- puhc->dev_addr = dev_addr;
- }
-
- if ((puhc->endp_mps != ep_mps) && (0U != ep_mps)) {
- puhc->endp_mps = ep_mps;
- }
-
- if ((puhc->dev_speed != dev_speed) && (0U != dev_speed)) {
- puhc->dev_speed = dev_speed;
- }
-
- usb_hostchannel_init(pudev, channel_num);
-
- return (uint8_t)HC_OK;
-}
-
-/*!
- \brief allocate a new channel for the pipe
- \param[in] pudev: pointer to usb device
- \param[in] ep_addr: endpoint for which the channel to be allocated
- \param[out] none
- \retval host channel number
-*/
-uint8_t usbh_channel_alloc (usb_core_handle_struct *pudev, uint8_t ep_addr)
-{
- uint16_t hc_num = usbh_freechannel_get(pudev);
-
- if ((uint16_t)HC_ERROR != hc_num) {
- pudev->host.host_channel[hc_num].info = HC_USED | ep_addr;
- }
-
- return (uint8_t)hc_num;
-}
-
-/*!
- \brief free the usb host channel
- \param[in] pudev: pointer to usb device
- \param[in] index: channel number to be freed which is in (0..7)
- \param[out] none
- \retval host operation status
-*/
-uint8_t usbh_channel_free (usb_core_handle_struct *pudev, uint8_t index)
-{
- if (index < HC_MAX) {
- pudev->host.host_channel[index].info &= HC_USED_MASK;
- }
-
- return USBH_OK;
-}
-
-/*!
- \brief free all usb host channel
- \param[in] pudev: pointer to usb device
- \param[out] none
- \retval host operation status
-*/
-uint8_t usbh_allchannel_dealloc (usb_core_handle_struct *pudev)
-{
- uint8_t index;
-
- for (index = 2U; index < HC_MAX; index ++) {
- pudev->host.host_channel[index].info = 0U;
- }
-
- return USBH_OK;
-}
-
-/*!
- \brief get a free channel number for allocation to a device endpoint
- \param[in] pudev: pointer to usb device
- \param[out] none
- \retval free channel number
-*/
-static uint16_t usbh_freechannel_get (usb_core_handle_struct *pudev)
-{
- uint8_t index = 0U;
-
- for (index = 0U; index < HC_MAX; index++) {
- if (0U == (pudev->host.host_channel[index].info & HC_USED)) {
- return (uint16_t)index;
- }
- }
-
- return HC_ERROR;
-}
-
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbh_int.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbh_int.c
deleted file mode 100644
index a386d185ed..0000000000
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbh_int.c
+++ /dev/null
@@ -1,591 +0,0 @@
-/*!
- \file usbh_int.c
- \brief USB host mode interrupt handler file
-*/
-
-/*
- Copyright (C) 2016 GigaDevice
-
- 2016-08-15, V1.0.1, firmware for GD32F4xx
-*/
-
-#include "usb_core.h"
-#include "usb_defines.h"
-#include "usbh_int.h"
-
-static uint32_t usbh_intf_sof (usb_core_handle_struct *pudev);
-static uint32_t usbh_intf_port (usb_core_handle_struct *pudev);
-static uint32_t usbh_intf_hc (usb_core_handle_struct *pudev);
-static uint32_t usbh_intf_hc_in (usb_core_handle_struct *pudev, uint8_t channel_num);
-static uint32_t usbh_intf_hc_out (usb_core_handle_struct *pudev, uint8_t channel_num);
-static uint32_t usbh_intf_rxfifo_noempty (usb_core_handle_struct *pudev);
-static uint32_t usbh_intf_nptxfifo_empty (usb_core_handle_struct *pudev);
-static uint32_t usbh_intf_ptxfifo_empty (usb_core_handle_struct *pudev);
-static uint32_t usbh_intf_disconnect (usb_core_handle_struct *pudev);
-static uint32_t usbh_intf_iso_incomplete_xfer (usb_core_handle_struct *pudev);
-
-/*!
- \brief handle global host interrupt
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval operation status
-*/
-uint32_t usbh_isr (usb_core_handle_struct *pudev)
-{
- uint32_t retval = 0U;
- uint32_t int_flag = 0U;
-
- /* check if host mode */
- if (USB_CURRENT_MODE_GET() == HOST_MODE) {
- USB_CORE_INTR_READ(int_flag);
-
- if (!int_flag) {
- return 0U;
- }
-
- /* start of frame interrupt handle */
- if (int_flag & GINTF_SOF) {
- retval |= usbh_intf_sof (pudev);
- }
-
- /* Rx FIFO non-empty interrupt handle */
- if (int_flag & GINTF_RXFNEIF) {
- retval |= usbh_intf_rxfifo_noempty (pudev);
- }
-
- /* Non-Periodic Tx FIFO empty interrupt hanlde */
- if (int_flag & GINTF_NPTXFEIF) {
- retval |= usbh_intf_nptxfifo_empty (pudev);
- }
-
- /* periodic Tx FIFO empty interrupt handle */
- if (int_flag & GINTF_PTXFEIF) {
- retval |= usbh_intf_ptxfifo_empty (pudev);
- }
-
- /* host channels interrupt handle */
- if (int_flag & GINTF_HCIF) {
- retval |= usbh_intf_hc (pudev);
- }
-
- /* host port interrupt handle */
- if (int_flag & GINTF_HPIF) {
- retval |= usbh_intf_port (pudev);
- }
-
- /* disconnect interrupt handle */
- if (int_flag & GINTF_DISCIF) {
- retval |= usbh_intf_disconnect (pudev);
- }
-
- /* isochronous IN transfer not complete interrupt handle */
- if (int_flag & GINTF_ISOONCIF) {
- retval |= usbh_intf_iso_incomplete_xfer (pudev);
- }
- }
-
- return retval;
-}
-
-/*!
- \brief handle the start-of-frame interrupt in host mode
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval operation status
-*/
-static uint32_t usbh_intf_sof (usb_core_handle_struct *pudev)
-{
- usbh_hcd_int_fops->sof(pudev);
-
- /* clear interrupt */
- USB_GINTF = GINTF_SOF;
-
- return 1U;
-}
-
-/*!
- \brief handle all host channels interrupt in host mode
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval operation status
-*/
-static uint32_t usbh_intf_hc (usb_core_handle_struct *pudev)
-{
- uint8_t i = 0U;
- uint32_t retval = 0U;
-
- for (i = 0U; i < pudev->cfg.host_channel_num; i++) {
- if ((USB_HACHINT & HACHINT_HACHINT) & ((uint32_t)1U << i)) {
- if ((USB_HCHxCTL((uint16_t)i) & HCHCTL_EPDIR) >> 15U) {
- retval |= usbh_intf_hc_in (pudev, i);
- } else {
- retval |= usbh_intf_hc_out (pudev, i);
- }
- }
- }
-
- return retval;
-}
-
-/*!
- \brief handle the disconnect interrupt
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval operation status
-*/
-static uint32_t usbh_intf_disconnect (usb_core_handle_struct *pudev)
-{
- usbh_hcd_int_fops->device_disconnected(pudev);
-
- /* clear interrupt */
- USB_GINTF = GINTF_DISCIF;
-
- return 1U;
-}
-
-/*!
- \brief handle the non-periodic tx fifo empty interrupt
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval operation status
-*/
-static uint32_t usbh_intf_nptxfifo_empty (usb_core_handle_struct *pudev)
-{
- uint8_t channel_num = 0U;
- uint32_t dword_len = 0U, len = 0U;
- usb_hostchannel_struct *puhc;
-
- channel_num = (uint8_t)((USB_HNPTFQSTAT & HNPTFQSTAT_CNUM) >> 27U);
- puhc = &pudev->host.host_channel[channel_num];
- dword_len = (puhc->xfer_len + 3U) / 4U;
-
- while (((USB_HNPTFQSTAT & HNPTFQSTAT_NPTXFS) > dword_len) && (0U != puhc->xfer_len)) {
- len = (USB_HNPTFQSTAT & HNPTFQSTAT_NPTXFS) * 4U;
-
- if (len > puhc->xfer_len) {
- /* last packet */
- len = (uint16_t)puhc->xfer_len;
-
- USB_GINTEN &= ~GINTF_NPTXFEIF;
-
- }
-
- dword_len = (puhc->xfer_len + 3U) / 4U;
- usb_fifo_write (puhc->xfer_buff, channel_num, (uint16_t)len);
-
- puhc->xfer_buff += len;
- puhc->xfer_len -= len;
- puhc->xfer_count += len;
- }
-
- return 1U;
-}
-
-/*!
- \brief handle the periodic tx fifo empty interrupt
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval operation status
-*/
-static uint32_t usbh_intf_ptxfifo_empty (usb_core_handle_struct *pudev)
-{
- uint8_t channel_num = 0U;
- uint32_t dword_len = 0U, len = 0U;
- usb_hostchannel_struct *puhc;
-
- channel_num = (uint8_t)((USB_HPTFQSTAT & HPTFQSTAT_CNUM) >> 27U);
- puhc = &pudev->host.host_channel[channel_num];
- dword_len = (puhc->xfer_len + 3U) / 4U;
-
- while (((USB_HPTFQSTAT & HPTFQSTAT_PTXFS) > dword_len) && (0U != puhc->xfer_len)) {
- len = (USB_HPTFQSTAT & HPTFQSTAT_PTXFS) * 4U;
-
- if (len > puhc->xfer_len) {
- len = puhc->xfer_len;
-
- /* last packet */
- USB_GINTEN &= ~GINTF_PTXFEIF;
- }
-
- dword_len = (puhc->xfer_len + 3U) / 4U;
- usb_fifo_write (puhc->xfer_buff, channel_num, (uint16_t)len);
-
- puhc->xfer_buff += len;
- puhc->xfer_len -= len;
- puhc->xfer_count += len;
- }
-
- return 1U;
-}
-
-/*!
- \brief handle the host port interrupt
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval operation status
-*/
-static uint32_t usbh_intf_port (usb_core_handle_struct *pudev)
-{
- uint8_t port_speed = 0U;
- uint8_t port_reset = 0U;
- uint32_t retval = 0U;
- __IO uint32_t hostportdup = USB_HPCS;
-
- /* clear the interrupt bits in gintsts */
- hostportdup &= ~HPCS_PE;
- hostportdup &= ~HPCS_PCD;
- hostportdup &= ~HPCS_PEDC;
-
- /* port connect detected */
- if (USB_HPCS & HPCS_PCD) {
- hostportdup |= HPCS_PCD;
- usbh_hcd_int_fops->device_connected(pudev);
- retval |= 1U;
- }
-
- /* port enable changed */
- if (USB_HPCS & HPCS_PEDC) {
- hostportdup |= HPCS_PEDC;
-
- if (USB_HPCS & HPCS_PE) {
- port_speed = (uint8_t)((USB_HPCS & HPCS_PS) >> 17U);
-
- if (HPRT_PRTSPD_LOW_SPEED == port_speed) {
- USB_HFT = 6000U;
-
- if (HCTLR_6_MHZ != (USB_HCTL & HCTL_CLKSEL)) {
- if (USB_CORE_EMBEDDED_PHY == pudev->cfg.phy_interface) {
- USB_FSLSCLOCK_INIT(HCTLR_6_MHZ);
- }
- port_reset = 1U;
- }
- } else if(HPRT_PRTSPD_FULL_SPEED == port_speed) {
- USB_HFT = 48000U;
-
- if (HCTLR_48_MHZ != (USB_HCTL & HCTL_CLKSEL)) {
- if (USB_CORE_EMBEDDED_PHY == pudev->cfg.phy_interface) {
- USB_FSLSCLOCK_INIT(HCTLR_48_MHZ);
- }
- port_reset = 1U;
- }
- } else {
- /* for high speed device and others */
- port_reset = 1U;
- }
-
-
- }
- }
-
- if (port_reset) {
- usb_port_reset(pudev);
- }
-
- /* clear port interrupts */
- USB_HPCS = hostportdup;
-
- return retval;
-}
-
-/*!
- \brief handle the OUT channel interrupt
- \param[in] pudev: pointer to usb device instance
- \param[in] channel_num: host channel number which is in (0..7)
- \param[out] none
- \retval operation status
-*/
-static uint32_t usbh_intf_hc_out (usb_core_handle_struct *pudev, uint8_t channel_num)
-{
- uint32_t channel_intr = USB_HCHxINTF((uint16_t)channel_num);
- usb_hostchannel_struct *puhc = &pudev->host.host_channel[channel_num];
-
- channel_intr &= USB_HCHxINTEN((uint16_t)channel_num);
-
- if (channel_intr & HCHINTF_ACK) {
- if (URB_PING == puhc->urb_state) {
- puhc->err_count = 0U;
- USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
- usb_hostchannel_halt(pudev, channel_num);
- USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_TF;
- puhc->status = HC_XF;
- }
-
- USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_ACK;
- } else if (channel_intr & HCHINTF_REQOVR) {
- USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
- usb_hostchannel_halt(pudev, channel_num);
- USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_REQOVR;
- } else if (channel_intr & HCHINTF_TF) {
- puhc->err_count = 0U;
- USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
- usb_hostchannel_halt(pudev, channel_num);
- USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_TF;
- puhc->status = HC_XF;
- } else if (channel_intr & HCHINTF_STALL) {
- USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
- USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_STALL;
- usb_hostchannel_halt(pudev, channel_num);
- puhc->status = HC_STALL;
- } else if (channel_intr & HCHINTF_NAK) {
- puhc->err_count = 0U;
- USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
- usb_hostchannel_halt(pudev, channel_num);
- USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_NAK;
- puhc->status = HC_NAK;
- } else if (channel_intr & HCHINTF_USBER) {
- USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
- usb_hostchannel_halt(pudev, channel_num);
- puhc->err_count ++;
- puhc->status = HC_TRACERR;
- USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_USBER;
- } else if (channel_intr & HCHINTF_NYET) {
- puhc->err_count = 0U;
- USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
- puhc->status = HC_NYET;
- USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_NYET;
- } else if (channel_intr & HCHINTF_DTER) {
- USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
- usb_hostchannel_halt(pudev, channel_num);
- puhc->status= HC_DTGERR;
- USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_DTER;
- } else if (channel_intr & HCHINTF_CH) {
- USB_HCHxINTEN((uint16_t)channel_num) &= ~HCHINTEN_CHIE;
-
- switch (puhc->status) {
- case HC_XF:
- puhc->urb_state = URB_DONE;
-
- if (USB_EPTYPE_BULK == ((USB_HCHxCTL((uint16_t)channel_num) & HCHCTL_EPTYPE) >> 18)) {
- puhc->data_tg_out ^= 1U;
- }
- break;
- case HC_NAK:
- if (URB_PING == puhc->urb_state) {
- usb_hostchannel_ping(pudev, channel_num);
- } else {
- puhc->urb_state = URB_NOTREADY;
- }
- break;
- case HC_NYET:
- if (1U == puhc->do_ping) {
- usb_hostchannel_ping(pudev, channel_num);
- puhc->urb_state = URB_PING;
- }
- break;
- case HC_STALL:
- puhc->urb_state = URB_STALL;
- break;
- case HC_TRACERR:
- if (3U == puhc->err_count) {
- puhc->urb_state = URB_ERROR;
- puhc->err_count = 0U;
- }
- break;
- default:
- break;
- }
-
- USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_CH;
- } else {
- /* no operation */
- }
-
- return 1U;
-}
-
-/*!
- \brief handle the IN channel interrupt
- \param[in] pudev: pointer to usb device instance
- \param[in] channel_num: host channel number which is in (0..7)
- \param[out] none
- \retval operation status
-*/
-static uint32_t usbh_intf_hc_in (usb_core_handle_struct *pudev, uint8_t channel_num)
-{
- uint8_t endp_type = 0U;
- usb_hostchannel_struct *puhc = &pudev->host.host_channel[channel_num];
-
- uint32_t channle_intf = USB_HCHxINTF((uint16_t)channel_num);
- __IO uint32_t channel_ctrl = USB_HCHxCTL((uint16_t)channel_num);
-
- channle_intf &= USB_HCHxINTEN((uint16_t)channel_num);
-
- endp_type = (uint8_t)((channel_ctrl & HCHCTL_EPTYPE) >> 18U);
-
- if (channle_intf & HCHINTF_ACK) {
- USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_ACK;
- } else if (channle_intf & HCHINTF_STALL) {
- USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
- puhc->status = HC_STALL;
- USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_NAK;
- USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_STALL;
-
- /* NOTE: When there is a 'stall', reset also nak,
- else, the pudev->host.status = HC_STALL
- will be overwritten by 'nak' in code below */
- channle_intf &= ~HCHINTF_NAK;
-
- usb_hostchannel_halt(pudev, channel_num);
- } else if (channle_intf & HCHINTF_DTER) {
- USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
- usb_hostchannel_halt(pudev, channel_num);
- USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_NAK;
- puhc->status = HC_DTGERR;
- USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_DTER;
- } else {
- /* no operation */
- }
-
- if (channle_intf & HCHINTF_REQOVR) {
- USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
- usb_hostchannel_halt(pudev, channel_num);
- USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_REQOVR;
- } else if (channle_intf & HCHINTF_TF) {
- if (pudev->cfg.dma_enable == 1U) {
- uint32_t xfer_size = USB_HCHxLEN((uint16_t)channel_num) & HCHLEN_TLEN;
- puhc->xfer_count = puhc->xfer_len - xfer_size;
- }
-
- puhc->status = HC_XF;
- puhc->err_count = 0U;
- USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_TF;
-
- if ((USB_EPTYPE_CTRL == endp_type) || (USB_EPTYPE_BULK == endp_type)) {
- USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
- usb_hostchannel_halt(pudev, channel_num);
- USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_NAK;
- puhc->data_tg_in ^= 1U;
- } else if (USB_EPTYPE_INTR == endp_type) {
- channel_ctrl |= HCHCTL_ODDFRM;
- USB_HCHxCTL((uint16_t)channel_num) = channel_ctrl;
- puhc->urb_state = URB_DONE;
- } else {
- /* no operation */
- }
- } else if (channle_intf & HCHINTF_CH) {
- USB_HCHxINTEN((uint16_t)channel_num) &= ~HCHINTEN_CHIE;
-
- switch (puhc->status) {
- case HC_XF:
- puhc->urb_state = URB_DONE;
- break;
- case HC_TRACERR:
- case HC_DTGERR:
- puhc->err_count = 0U;
- puhc->urb_state = URB_ERROR;
- break;
- case HC_STALL:
- puhc->urb_state = URB_STALL;
- break;
- default:
- if (USB_EPTYPE_INTR == endp_type) {
- puhc->data_tg_in ^= 1U;
- }
- break;
- }
-
- USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_CH;
- } else if (channle_intf & HCHINTF_USBER) {
- USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
- (puhc->err_count)++;
- puhc->status = HC_TRACERR;
- usb_hostchannel_halt(pudev, channel_num);
- USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_USBER;
- } else if (channle_intf & HCHINTF_NAK) {
- if (USB_EPTYPE_INTR == endp_type) {
- USB_HCHxINTEN((uint16_t)channel_num) |= HCHINTEN_CHIE;
- usb_hostchannel_halt(pudev, channel_num);
- } else if ((USB_EPTYPE_CTRL == endp_type) || (USB_EPTYPE_BULK == endp_type)) {
- /* re-activate the channel */
- channel_ctrl |= HCHCTL_CEN;
- channel_ctrl &= ~HCHCTL_CDIS;
- USB_HCHxCTL((uint16_t)channel_num) = channel_ctrl;
- } else {
- /* no operation */
- }
-
- puhc->status = HC_NAK;
- USB_HCHxINTF((uint16_t)channel_num) = HCHINTF_NAK;
- } else {
- /* no operation */
- }
-
- return 1U;
-}
-
-/*!
- \brief handle the rx fifo non-empty interrupt
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval operation status
-*/
-static uint32_t usbh_intf_rxfifo_noempty (usb_core_handle_struct *pudev)
-{
- uint32_t count = 0U;
- __IO uint8_t channel_num = 0U;
- __IO uint32_t rx_status = 0U;
- uint32_t usbh_ch_ctl_reg = 0U;
- usb_hostchannel_struct *puhc;
-
- /* disable the Rx status queue level interrupt */
- USB_GINTEN &= ~GINTF_RXFNEIF;
-
- rx_status = USB_GRSTATP;
- channel_num = (uint8_t)(rx_status & GRSTATR_CNUM);
- puhc = &pudev->host.host_channel[channel_num];
-
- switch ((rx_status & GRSTATR_RPCKST) >> 17) {
- case GRSTATR_RPCKST_IN:
- count = (rx_status & GRSTATR_BCOUNT) >> 4;
-
- /* read the data into the host buffer. */
- if ((count > 0U) && (puhc->xfer_buff != (void *)0)) {
- usb_fifo_read(puhc->xfer_buff, (uint16_t)count);
-
- /* manage multiple Xfer */
- puhc->xfer_buff += count;
- puhc->xfer_count += count;
-
- if (USB_HCHxLEN((uint16_t)channel_num) & HCHLEN_PCNT) {
- /* re-activate the channel when more packets are expected */
- usbh_ch_ctl_reg = USB_HCHxCTL((uint16_t)channel_num);
- usbh_ch_ctl_reg |= HCHCTL_CEN;
- usbh_ch_ctl_reg &= ~HCHCTL_CDIS;
- USB_HCHxCTL((uint16_t)channel_num) = usbh_ch_ctl_reg;
- }
- }
- break;
- case GRSTATR_RPCKST_IN_XFER_COMP:
- case GRSTATR_RPCKST_DATA_TOGGLE_ERR:
- case GRSTATR_RPCKST_CH_HALTED:
- default:
- break;
- }
-
- /* enable the Rx status queue level interrupt */
- USB_GINTEN |= GINTF_RXFNEIF;
-
- return 1U;
-}
-
-/*!
- \brief handle the incomplete periodic transfer interrupt
- \param[in] pudev: pointer to usb device instance
- \param[out] none
- \retval operation status
-*/
-static uint32_t usbh_intf_iso_incomplete_xfer (usb_core_handle_struct *pudev)
-{
- __IO uint32_t gint_flag = 0U;
-
- gint_flag = USB_HCHxCTL(0U);
- USB_HCHxCTL(0U) = 0U;
-
- gint_flag = 0U;
-
- /* clear interrupt */
- gint_flag |= GINTF_ISOONCIF;
- USB_GINTF = gint_flag;
-
- return 1U;
-}
diff --git a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbh_std.c b/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbh_std.c
deleted file mode 100644
index 57f9e996a4..0000000000
--- a/bsp/gd32450z-eval/Libraries/GD32F4xx_usb_driver/Source/usbh_std.c
+++ /dev/null
@@ -1,808 +0,0 @@
-/*!
- \file usbh_std.c
- \brief USB 2.0 standard function definition
-*/
-
-/*
- Copyright (C) 2016 GigaDevice
-
- 2016-08-15, V1.0.1, firmware for GD32F4xx
-*/
-
-#include "usbh_core.h"
-#include "usbh_usr.h"
-#include "usbh_std.h"
-#include "usbh_ctrl.h"
-
-uint8_t local_buffer[64];
-uint8_t usbh_cfg_desc[512];
-uint8_t enum_polling_handle_flag = 0U;
-
-static void enum_idle_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-static void enum_get_full_dev_desc_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-static void enum_set_addr_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-static void enum_get_cfg_desc_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-static void enum_get_full_cfg_desc_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-static void enum_get_mfc_string_desc_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-static void enum_get_product_string_desc_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-static void enum_get_serialnum_string_desc_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-static void enum_set_configuration_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-static void enum_dev_configured_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate);
-
-/* the enumeration state handle function array */
-void (*enum_state_handle[]) (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate) =
-{
- enum_idle_handle,
- enum_set_addr_handle,
- enum_get_full_dev_desc_handle,
- enum_get_cfg_desc_handle,
- enum_get_full_cfg_desc_handle,
- enum_get_mfc_string_desc_handle,
- enum_get_product_string_desc_handle,
- enum_get_serialnum_string_desc_handle,
- enum_set_configuration_handle,
- enum_dev_configured_handle,
-};
-
-/* the enumeration state handle table */
-state_table_struct enum_handle_table[ENUM_HANDLE_TABLE_SIZE] =
-{
- /* the current state the current event the next state the event function */
- {ENUM_IDLE, ENUM_EVENT_SET_ADDR, ENUM_SET_ADDR, only_state_move },
- {ENUM_SET_ADDR, ENUN_EVENT_GET_FULL_DEV_DESC, ENUM_GET_FULL_DEV_DESC, only_state_move },
- {ENUM_GET_FULL_DEV_DESC, ENUN_EVENT_GET_CFG_DESC, ENUM_GET_CFG_DESC, only_state_move },
- {ENUM_GET_CFG_DESC, ENUN_EVENT_GET_FULL_CFG_DESC, ENUM_GET_FULL_CFG_DESC, only_state_move },
- {ENUM_GET_FULL_CFG_DESC, ENUN_EVENT_GET_MFC_STRING_DESC, ENUM_GET_MFC_STRING_DESC, only_state_move },
- {ENUM_GET_MFC_STRING_DESC, ENUN_EVENT_GET_PRODUCT_STRING_DESC, ENUM_GET_PRODUCT_STRING_DESC, only_state_move },
- {ENUM_GET_PRODUCT_STRING_DESC, ENUN_EVENT_GET_SERIALNUM_STRING_DESC, ENUM_GET_SERIALNUM_STRING_DESC, only_state_move },
- {ENUM_GET_SERIALNUM_STRING_DESC, ENUN_EVENT_SET_CONFIGURATION, ENUM_SET_CONFIGURATION, only_state_move },
- {ENUM_SET_CONFIGURATION, ENUN_EVENT_DEV_CONFIGURED, ENUM_DEV_CONFIGURED, only_state_move },
- {ENUM_DEV_CONFIGURED, GO_TO_UP_STATE_EVENT, UP_STATE, goto_up_state_fun },
-};
-
-/*!
- \brief the polling function of enumeration state
- \param[in] pudev: pointer to USB device
- \param[in] puhost: pointer to USB host
- \param[in] pustate: pointer to USB state driver
- \param[out] none
- \retval usb host status
-*/
-usbh_status_enum enum_state_polling_fun (usb_core_handle_struct *pudev, usbh_host_struct *puhost, void *pustate)
-{
- usbh_status_enum exe_state = USBH_BUSY;
- usbh_state_handle_struct *p_state;
- p_state = (usbh_state_handle_struct *)pustate;
-
- if (0U == enum_polling_handle_flag) {
- enum_polling_handle_flag = 1U;
- scd_table_push(p_state);
- scd_state_move(p_state, ENUM_IDLE);
- }
-
- /* start the enumeration state handle */
- scd_begin(p_state,ENUM_FSM_ID);
-
- if (0U == p_state->usbh_current_state_stack_top) {
- enum_state_handle[p_state->usbh_current_state](pudev, puhost, p_state);
- } else {
- enum_state_handle[p_state->stack[1].state](pudev, puhost, p_state);
- }
-
- /* determine the enumeration whether to complete */
- if (ENUM_DEV_CONFIGURED == puhost->usbh_backup_state.enum_backup_state) {
- puhost->usbh_backup_state.enum_backup_state = ENUM_IDLE;
- enum_polling_handle_flag = 0U;
- exe_state = USBH_OK;
- }
-
- return exe_state;
-}
-
-/*!
- \brief the handle function of ENUM_IDLE state
- \param[in] pudev: pointer to USB device
- \param[in] puhost: pointer to USB host
- \param[in] pustate: pointer to USB state driver
- \param[out] none
- \retval none
-*/
-static void enum_idle_handle (usb_core_handle_struct *pudev, usbh_host_struct *puhost, usbh_state_handle_struct *pustate)
-{
- puhost->usbh_backup_state.enum_backup_state = ENUM_IDLE;
-
- if (CTRL_IDLE == puhost->usbh_backup_state.ctrl_backup_state) {
- usbh_enum_desc_get(pudev,
- puhost,
- pudev->host.rx_buffer,
- USB_REQTYPE_DEVICE | USB_STANDARD_REQ,
- USB_DEVDESC,
- 8U);
- if ((void *)0 != pudev->mdelay) {
- pudev->mdelay(100U);
- }
- }
-
- if (USBH_OK == ctrl_state_polling_fun(pudev, puhost, pustate)) {
- usbh_device_desc_parse(&puhost->device.dev_desc, pudev->host.rx_buffer, 8U);
- puhost->control.ep0_size = puhost->device.dev_desc.bMaxPacketSize0;
-
- /* issue reset */
- usb_port_reset(pudev);
-
- /* modify control channels configuration for maxpacket size */
- usbh_channel_modify (pudev,
- puhost->control.hc_out_num,
- 0U,
- 0U,
- 0U,
- (uint16_t)puhost->control.ep0_size);
-
- usbh_channel_modify (pudev,
- puhost->control.hc_in_num,
- 0U,
- 0U,
- 0U,
- (uint16_t)puhost->control.ep0_size);
-
- scd_event_handle(pudev,
- puhost,
- pustate,
- ENUM_EVENT_SET_ADDR,
- pustate->usbh_current_state);
- }
-}
-
-/*!
- \brief the handle function of ENUM_GET_FULL_DEV_DESC state
- \param[in] pudev: pointer to USB device
- \param[in] puhost: pointer to USB host
- \param[in] pustate: pointer to USB state driver
- \param[out] none
- \retval none
-*/
-static void enum_get_full_dev_desc_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
- puhost->usbh_backup_state.enum_backup_state = ENUM_GET_FULL_DEV_DESC;
-
- if (CTRL_IDLE == puhost->usbh_backup_state.ctrl_backup_state) {
- usbh_enum_desc_get(pudev,
- puhost,
- pudev->host.rx_buffer,
- USB_REQTYPE_DEVICE | USB_STANDARD_REQ,
- USB_DEVDESC,
- USB_DEVDESC_SIZE);
- }
-
- if(USBH_OK == ctrl_state_polling_fun(pudev, puhost, pustate)){
- usbh_device_desc_parse(&puhost->device.dev_desc, pudev->host.rx_buffer, USB_DEVDESC_SIZE);
- puhost->usr_cb->device_desc_available(&puhost->device.dev_desc);
-
- scd_event_handle(pudev,
- puhost,
- pustate,
- ENUN_EVENT_GET_CFG_DESC,
- pustate->usbh_current_state);
- }
-}
-
-/*!
- \brief the handle function of ENUM_SET_ADDR state
- \param[in] pudev: pointer to USB device
- \param[in] puhost: pointer to USB host
- \param[in] pustate: pointer to USB state driver
- \param[out] none
- \retval none
-*/
-static void enum_set_addr_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
- puhost->usbh_backup_state.enum_backup_state = ENUM_SET_ADDR;
-
- if (CTRL_IDLE == puhost->usbh_backup_state.ctrl_backup_state) {
- usbh_enum_addr_set(pudev, puhost,USBH_DEVICE_ADDRESS);
- if ((void *)0 != pudev->mdelay) {
- pudev->mdelay(100U);
- }
- }
-
- if (USBH_OK == ctrl_state_polling_fun(pudev, puhost, pustate)) {
- if ((void *)0 != pudev->mdelay) {
- pudev->mdelay(2U);
- }
- puhost->device.address = USBH_DEVICE_ADDRESS;
-
- /* user callback for device address assigned */
- puhost->usr_cb->device_address_set();
-
- /* modify control channels to update device address */
- usbh_channel_modify (pudev,
- puhost->control.hc_in_num,
- puhost->device.address,
- 0U,
- 0U,
- 0U);
-
- usbh_channel_modify (pudev,
- puhost->control.hc_out_num,
- puhost->device.address,
- 0U,
- 0U,
- 0U);
-
- scd_event_handle(pudev,
- puhost,
- pustate,
- ENUN_EVENT_GET_FULL_DEV_DESC,
- pustate->usbh_current_state);
- }
-}
-
-/*!
- \brief the handle function of ENUM_GET_CFG_DESC state
- \param[in] pudev: pointer to USB device
- \param[in] puhost: pointer to USB host
- \param[in] pustate: pointer to USB state driver
- \param[out] none
- \retval none
-*/
-static void enum_get_cfg_desc_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
- uint16_t index = 0U;
-
- puhost->usbh_backup_state.enum_backup_state = ENUM_GET_CFG_DESC;
-
- if (CTRL_IDLE == puhost->usbh_backup_state.ctrl_backup_state) {
- usbh_enum_desc_get(pudev,
- puhost,
- pudev->host.rx_buffer,
- USB_REQTYPE_DEVICE | USB_STANDARD_REQ,
- USB_CFGDESC,
- USB_CFGDESC_SIZE);
- }
-
- if (USBH_OK == ctrl_state_polling_fun(pudev, puhost, pustate)) {
- /* save configuration descriptor for class parsing usage */
- for (; index < USB_CFGDESC_SIZE; index ++) {
- usbh_cfg_desc[index] = pudev->host.rx_buffer[index];
- }
-
- /* commands successfully sent and response received */
- usbh_cfg_desc_parse (&puhost->device.cfg_desc,
- puhost->device.itf_desc,
- puhost->device.ep_desc,
- pudev->host.rx_buffer,
- USB_CFGDESC_SIZE);
-
- scd_event_handle(pudev,
- puhost,
- pustate,
- ENUN_EVENT_GET_FULL_CFG_DESC,
- pustate->usbh_current_state);
- }
-}
-
-/*!
- \brief the handle function of ENUM_GET_FULL_CFG_DESC state
- \param[in] pudev: pointer to USB device
- \param[in] puhost: pointer to USB host
- \param[in] pustate: pointer to USB state driver
- \param[out] none
- \retval none
-*/
-static void enum_get_full_cfg_desc_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
-
- uint16_t index = 0U;
-
- puhost->usbh_backup_state.enum_backup_state = ENUM_GET_FULL_CFG_DESC;
-
- if (CTRL_IDLE == puhost->usbh_backup_state.ctrl_backup_state) {
- usbh_enum_desc_get (pudev, puhost, pudev->host.rx_buffer,
- USB_REQTYPE_DEVICE | USB_STANDARD_REQ,
- USB_CFGDESC, puhost->device.cfg_desc.wTotalLength);
- }
-
-
- if (USBH_OK == ctrl_state_polling_fun(pudev, puhost, pustate)) {
- /* save configuration descriptor for class parsing usage */
- for (; index < puhost->device.cfg_desc.wTotalLength; index ++) {
- usbh_cfg_desc[index] = pudev->host.rx_buffer[index];
- }
-
- /* commands successfully sent and response received */
- usbh_cfg_desc_parse (&puhost->device.cfg_desc,
- puhost->device.itf_desc,
- puhost->device.ep_desc,
- pudev->host.rx_buffer,
- puhost->device.cfg_desc.wTotalLength);
-
- /* User callback for configuration descriptors available */
- puhost->usr_cb->configuration_desc_available(&puhost->device.cfg_desc,
- puhost->device.itf_desc,
- puhost->device.ep_desc[0]);
-
- scd_event_handle(pudev,
- puhost,
- pustate,
- ENUN_EVENT_GET_MFC_STRING_DESC,
- pustate->usbh_current_state);
- }
-}
-
-/*!
- \brief the handle function of ENUM_GET_MFC_STRING_DESC state
- \param[in] pudev: pointer to USB device
- \param[in] puhost: pointer to USB host
- \param[in] pustate: pointer to USB state driver
- \param[out] none
- \retval none
-*/
-static void enum_get_mfc_string_desc_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
- puhost->usbh_backup_state.enum_backup_state = ENUM_GET_MFC_STRING_DESC;
-
- if (0U != puhost->device.dev_desc.iManufacturer) {
- if(CTRL_IDLE == puhost->usbh_backup_state.ctrl_backup_state) {
- usbh_enum_desc_get(pudev,
- puhost,
- pudev->host.rx_buffer,
- USB_REQTYPE_DEVICE | USB_STANDARD_REQ,
- USB_STRDESC | puhost->device.dev_desc.iManufacturer,
- 0xffU);
- }
-
- if (USBH_OK == ctrl_state_polling_fun(pudev, puhost, pustate)) {
- usbh_string_desc_parse(pudev->host.rx_buffer, local_buffer, 0xffU);
- puhost->usr_cb->manufacturer_string(local_buffer);
-
- scd_event_handle(pudev,
- puhost,
- pustate,
- ENUN_EVENT_GET_PRODUCT_STRING_DESC,
- pustate->usbh_current_state);
- }
- } else {
- puhost->usr_cb->manufacturer_string("N/A");
- scd_state_move((usbh_state_handle_struct *)pustate, ENUM_GET_PRODUCT_STRING_DESC);
- }
-}
-
-/*!
- \brief the handle function of ENUM_GET_PRODUCT_STRING_DESC state
- \param[in] pudev: pointer to USB device
- \param[in] puhost: pointer to USB host
- \param[in] pustate: pointer to USB state driver
- \param[out] none
- \retval none
-*/
-static void enum_get_product_string_desc_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
- puhost->usbh_backup_state.enum_backup_state = ENUM_GET_PRODUCT_STRING_DESC;
-
- if (0U != puhost->device.dev_desc.iProduct) {
- if (CTRL_IDLE == puhost->usbh_backup_state.ctrl_backup_state) {
- usbh_enum_desc_get(pudev,
- puhost,
- pudev->host.rx_buffer,
- USB_REQTYPE_DEVICE | USB_STANDARD_REQ,
- USB_STRDESC | puhost->device.dev_desc.iProduct,
- 0xffU);
- }
-
- if (USBH_OK == ctrl_state_polling_fun(pudev, puhost, pustate)) {
- usbh_string_desc_parse(pudev->host.rx_buffer, local_buffer, 0xffU);
-
- /* User callback for Product string */
- puhost->usr_cb->product_string(local_buffer);
-
- scd_event_handle(pudev,
- puhost,
- pustate,
- ENUN_EVENT_GET_SERIALNUM_STRING_DESC,
- pustate->usbh_current_state);
- }
-
- } else {
- puhost->usr_cb->product_string("N/A");
- scd_event_handle(pudev,
- puhost,
- pustate,
- ENUN_EVENT_GET_SERIALNUM_STRING_DESC,
- pustate->usbh_current_state);
- }
-}
-
-/*!
- \brief the handle function of ENUM_GET_SERIALNUM_STRING_DESC state
- \param[in] pudev: pointer to USB device
- \param[in] puhost: pointer to USB host
- \param[in] pustate: pointer to USB state driver
- \param[out] none
- \retval none
-*/
-static void enum_get_serialnum_string_desc_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
- puhost->usbh_backup_state.enum_backup_state = ENUM_GET_SERIALNUM_STRING_DESC;
-
- if (0U != puhost->device.dev_desc.iSerialNumber) {
- if (CTRL_IDLE == puhost->usbh_backup_state.ctrl_backup_state) {
- usbh_enum_desc_get(pudev,
- puhost,
- pudev->host.rx_buffer,
- USB_REQTYPE_DEVICE | USB_STANDARD_REQ,
- USB_STRDESC | puhost->device.dev_desc.iSerialNumber,
- 0xffU);
- }
-
- if (USBH_OK == ctrl_state_polling_fun(pudev, puhost, pustate)){
- usbh_string_desc_parse(pudev->host.rx_buffer, local_buffer, 0xffU);
-
- /* user callback for product string */
- puhost->usr_cb->serial_num_string(local_buffer);
- scd_event_handle(pudev,
- puhost,
- pustate,
- ENUN_EVENT_SET_CONFIGURATION,
- pustate->usbh_current_state);
- }
- } else {
- puhost->usr_cb->serial_num_string("N/A");
- scd_event_handle(pudev,
- puhost,
- pustate,
- ENUN_EVENT_SET_CONFIGURATION,
- pustate->usbh_current_state);
- }
-}
-
-/*!
- \brief the handle function of ENUM_SET_CONFIGURATION state
- \param[in] pudev: pointer to USB device
- \param[in] puhost: pointer to USB host
- \param[in] pustate: pointer to USB state driver
- \param[out] none
- \retval none
-*/
-static void enum_set_configuration_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
- puhost->usbh_backup_state.enum_backup_state = ENUM_SET_CONFIGURATION;
-
- if (CTRL_IDLE == puhost->usbh_backup_state.ctrl_backup_state ) {
- usbh_enum_cfg_set(pudev, puhost, (uint16_t)puhost->device.cfg_desc.bConfigurationValue);
- }
-
- if (USBH_OK == ctrl_state_polling_fun(pudev, puhost, pustate)) {
- scd_event_handle(pudev,
- puhost,
- pustate,
- ENUN_EVENT_DEV_CONFIGURED,
- pustate->usbh_current_state);
- }
-}
-
-/*!
- \brief the handle function of ENUM_DEV_CONFIGURED state
- \param[in] pudev: pointer to USB device
- \param[in] puhost: pointer to USB host
- \param[in] pustate: pointer to USB state driver
- \param[out] none
- \retval none
-*/
-static void enum_dev_configured_handle (usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- usbh_state_handle_struct *pustate)
-{
- puhost->usbh_backup_state.enum_backup_state = ENUM_DEV_CONFIGURED;
- scd_event_handle(pudev, puhost, pustate, GO_TO_UP_STATE_EVENT, pustate->usbh_current_state);
-}
-
-/*!
- \brief get descriptor in usb host enumeration stage
- \param[in] pudev: pointer to USB device
- \param[in] puhost: pointer to USB host
- \param[in] buf: buffer to store the descriptor
- \param[in] ReqType: descriptor type
- \param[in] ValueIdx: wValue for the GetDescriptr request
- \param[in] Len: length of the descriptor
- \param[out] none
- \retval none
-*/
-void usbh_enum_desc_get(usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- uint8_t *buf,
- uint8_t req_type,
- uint16_t value_idx,
- uint16_t len)
-{
- usb_setup_union *pSetup = &(puhost->control.setup);
-
- pSetup->b.bmRequestType = USB_DIR_IN | req_type;
- pSetup->b.bRequest = USBREQ_GET_DESCRIPTOR;
- pSetup->b.wValue = value_idx;
-
- if (USB_STRDESC == (value_idx & 0xff00U)){
- pSetup->b.wIndex = 0x0409U;
- } else {
- pSetup->b.wIndex = 0U;
- }
-
- pSetup->b.wLength = len;
-
- puhost->control.buff = buf;
- puhost->control.length = len;
-
-}
-
-/*!
- \brief set address in usb host enumeration stage
- \param[in] pudev: pointer to USB device
- \param[in] puhost: pointer to USB host
- \param[in] device_address: the device address
- \param[out] none
- \retval none
-*/
-void usbh_enum_addr_set(usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- uint8_t device_address)
-{
- usb_setup_union *p_setup = &(puhost->control.setup);
-
- p_setup->b.bmRequestType = USB_DIR_OUT | USB_REQTYPE_DEVICE | USB_STANDARD_REQ;
- p_setup->b.bRequest = USBREQ_SET_ADDRESS;
- p_setup->b.wValue = (uint16_t)device_address;
- p_setup->b.wIndex = 0U;
- p_setup->b.wLength = 0U;
- puhost->control.buff = 0U;
- puhost->control.length = 0U;
-}
-
-/*!
- \brief set configuration in usb host enumeration stage
- \param[in] pudev: pointer to USB device
- \param[in] puhost: pointer to USB host
- \param[in] cfg_idx: the index of the configuration
- \param[out] none
- \retval none
-*/
-void usbh_enum_cfg_set(usb_core_handle_struct *pudev,
- usbh_host_struct *puhost,
- uint16_t cfg_idx)
-{
- usb_setup_union *p_setup = &(puhost->control.setup);
-
- p_setup->b.bmRequestType = USB_DIR_OUT | USB_REQTYPE_DEVICE | USB_STANDARD_REQ;
- p_setup->b.bRequest = USBREQ_SET_CONFIGURATION;
- p_setup->b.wValue = cfg_idx;
- p_setup->b.wIndex = 0U;
- p_setup->b.wLength = 0U;
- puhost->control.buff = 0;
- puhost->control.length = 0U;
-}
-
-/*!
- \brief parse the device descriptor
- \param[in] dev_desc: device_descriptor destinaton address
- \param[in] buf: buffer where the source descriptor is available
- \param[in] len: length of the descriptor
- \param[out] none
- \retval none
-*/
-void usbh_device_desc_parse (usb_descriptor_device_struct *dev_desc, uint8_t *buf, uint16_t len)
-{
- dev_desc->Header.bLength = *(uint8_t *)(buf + 0);
- dev_desc->Header.bDescriptorType = *(uint8_t *)(buf + 1);
- dev_desc->bcdUSB = SWAPBYTE(buf + 2);
- dev_desc->bDeviceClass = *(uint8_t *)(buf + 4);
- dev_desc->bDeviceSubClass = *(uint8_t *)(buf + 5);
- dev_desc->bDeviceProtocol = *(uint8_t *)(buf + 6);
- dev_desc->bMaxPacketSize0 = *(uint8_t *)(buf + 7);
-
- if (len > 8U){
- /* for 1st time after device connection, host may issue only 8 bytes for device descriptor length */
- dev_desc->idVendor = SWAPBYTE(buf + 8);
- dev_desc->idProduct = SWAPBYTE(buf + 10);
- dev_desc->bcdDevice = SWAPBYTE(buf + 12);
- dev_desc->iManufacturer = *(uint8_t *)(buf + 14);
- dev_desc->iProduct = *(uint8_t *)(buf + 15);
- dev_desc->iSerialNumber = *(uint8_t *)(buf + 16);
- dev_desc->bNumberConfigurations = *(uint8_t *)(buf + 17);
- }
-}
-
-/*!
- \brief parse the configuration descriptor
- \param[in] cfg_desc: configuration descriptor address
- \param[in] itf_desc: interface descriptor address
- \param[in] ep_desc: endpoint descriptor address
- \param[in] buf: buffer where the source descriptor is available
- \param[in] len: length of the descriptor
- \param[out] none
- \retval none
-*/
-void usbh_cfg_desc_parse (usb_descriptor_configuration_struct *cfg_desc,
- usb_descriptor_interface_struct *itf_desc,
- usb_descriptor_endpoint_struct ep_desc[][USBH_MAX_EP_NUM],
- uint8_t *buf,
- uint16_t len)
-{
- usb_descriptor_interface_struct *pitf = NULL;
- usb_descriptor_interface_struct temp_pitf;
- usb_descriptor_endpoint_struct *pep = NULL;
- usb_descriptor_header_struct *pdesc = (usb_descriptor_header_struct *)buf;
-
- uint8_t itf_ix = 0U;
- uint8_t ep_ix = 0U;
- uint16_t ptr = 0U;
- static uint8_t prev_itf = 0U;
- static uint16_t prev_ep_size = 0U;
-
- /* parse configuration descriptor */
- cfg_desc->Header.bLength = *(uint8_t *)(buf + 0);
- cfg_desc->Header.bDescriptorType = *(uint8_t *)(buf + 1);
- cfg_desc->wTotalLength = SWAPBYTE(buf + 2);
- cfg_desc->bNumInterfaces = *(uint8_t *)(buf + 4);
- cfg_desc->bConfigurationValue = *(uint8_t *)(buf + 5);
- cfg_desc->iConfiguration = *(uint8_t *)(buf + 6);
- cfg_desc->bmAttributes = *(uint8_t *)(buf + 7);
- cfg_desc->bMaxPower = *(uint8_t *)(buf + 8);
-
- if (len > USB_CFGDESC_SIZE) {
- ptr = USB_CFG_DESC_LEN;
-
- if (cfg_desc->bNumInterfaces <= USBH_MAX_INTERFACES_NUM) {
- pitf = (usb_descriptor_interface_struct *)0;
-
- for (; ptr < cfg_desc->wTotalLength; ) {
- pdesc = usbh_next_desc_get((uint8_t *)pdesc, &ptr);
-
- if (USB_DESCTYPE_INTERFACE == pdesc->bDescriptorType) {
- itf_ix = *((uint8_t *)pdesc + 2U);
- pitf = &itf_desc[itf_ix];
-
- if (*((uint8_t *)pdesc + 3U) < 3U) {
- usbh_interface_desc_parse (&temp_pitf, (uint8_t *)pdesc);
-
- /* parse endpoint descriptors relative to the current interface */
- if (temp_pitf.bNumEndpoints <= USBH_MAX_EP_NUM) {
- for (ep_ix = 0U; ep_ix < temp_pitf.bNumEndpoints;) {
- pdesc = usbh_next_desc_get((void* )pdesc, &ptr);
-
- if (USB_DESCTYPE_ENDPOINT == pdesc->bDescriptorType) {
- pep = &ep_desc[itf_ix][ep_ix];
-
- if (prev_itf != itf_ix) {
- prev_itf = itf_ix;
- usbh_interface_desc_parse (pitf, (uint8_t *)&temp_pitf);
- } else {
- if (prev_ep_size > SWAPBYTE((uint8_t *)pdesc + 4)) {
- break;
- } else {
- usbh_interface_desc_parse (pitf, (uint8_t *)&temp_pitf);
- }
- }
-
- usbh_endpoint_desc_parse (pep, (uint8_t *)pdesc);
- prev_ep_size = SWAPBYTE((uint8_t *)pdesc + 4);
- ep_ix++;
- }
- }
- }
- }
- }
- }
- }
-
- prev_ep_size = 0U;
- prev_itf = 0U;
- }
-}
-
-/*!
- \brief parse the interface descriptor
- \param[in] itf_desc: interface descriptor destination
- \param[in] buf: buffer where the descriptor data is available
- \param[out] none
- \retval none
-*/
-void usbh_interface_desc_parse (usb_descriptor_interface_struct *itf_desc, uint8_t *buf)
-{
- itf_desc->Header.bLength = *(uint8_t *)(buf + 0);
- itf_desc->Header.bDescriptorType = *(uint8_t *)(buf + 1);
- itf_desc->bInterfaceNumber = *(uint8_t *)(buf + 2);
- itf_desc->bAlternateSetting = *(uint8_t *)(buf + 3);
- itf_desc->bNumEndpoints = *(uint8_t *)(buf + 4);
- itf_desc->bInterfaceClass = *(uint8_t *)(buf + 5);
- itf_desc->bInterfaceSubClass = *(uint8_t *)(buf + 6);
- itf_desc->bInterfaceProtocol = *(uint8_t *)(buf + 7);
- itf_desc->iInterface = *(uint8_t *)(buf + 8);
-}
-
-/*!
- \brief parse the endpoint descriptor
- \param[in] ep_desc: endpoint descriptor destination address
- \param[in] buf: buffer where the parsed descriptor stored
- \param[out] none
- \retval none
-*/
-void usbh_endpoint_desc_parse (usb_descriptor_endpoint_struct *ep_desc, uint8_t *buf)
-{
- ep_desc->Header.bLength = *(uint8_t *)(buf + 0);
- ep_desc->Header.bDescriptorType = *(uint8_t *)(buf + 1);
- ep_desc->bEndpointAddress = *(uint8_t *)(buf + 2);
- ep_desc->bmAttributes = *(uint8_t *)(buf + 3);
- ep_desc->wMaxPacketSize = SWAPBYTE(buf + 4);
- ep_desc->bInterval = *(uint8_t *)(buf + 6);
-}
-
-/*!
- \brief parse the string descriptor
- \param[in] psrc: source pointer containing the descriptor data
- \param[in] pdest: destination address pointer
- \param[in] len: length of the descriptor
- \param[out] none
- \retval none
-*/
-void usbh_string_desc_parse (uint8_t* psrc, uint8_t* pdest, uint16_t len)
-{
- uint16_t strlength;
- uint16_t idx;
-
- /* the unicode string descriptor is not null-terminated. the string length is
- computed by substracting two from the value of the first byte of the descriptor.
- */
-
- /* check which is lower size, the size of string or the length of bytes read from the device */
-
- if (USB_DESCTYPE_STRING == psrc[1]){
- /* make sure the descriptor is string type */
-
- /* psrc[0] contains size of descriptor, subtract 2 to get the length of string */
- strlength = ((((uint16_t)psrc[0] - 2U) <= len) ? ((uint16_t)psrc[0] - 2U) : len);
- psrc += 2; /* adjust the offset ignoring the string len and descriptor type */
-
- for (idx = 0U; idx < strlength; idx += 2U) {
- /* copy only the string and ignore the unicode id, hence add the src */
- *pdest = psrc[idx];
- pdest++;
- }
-
- *pdest = 0U; /* mark end of string */
- }
-}
-
-/*!
- \brief get the next descriptor header
- \param[in] pbuf: pointer to buffer where the cfg descriptor is available
- \param[in] ptr: data popinter inside the configuration descriptor
- \param[out] none
- \retval next descriptor header
-*/
-usb_descriptor_header_struct *usbh_next_desc_get (uint8_t *pbuf, uint16_t *ptr)
-{
- uint8_t len = ((usb_descriptor_header_struct *)pbuf)->bLength;
-
- usb_descriptor_header_struct *pnext;
-
- *ptr += len;
-
- pnext = (usb_descriptor_header_struct *)((uint8_t *)pbuf + len);
-
- return(pnext);
-}
-
diff --git a/bsp/gd32450z-eval/Libraries/SConscript b/bsp/gd32450z-eval/Libraries/SConscript
index 75df263b3e..e9d6e45aae 100644
--- a/bsp/gd32450z-eval/Libraries/SConscript
+++ b/bsp/gd32450z-eval/Libraries/SConscript
@@ -21,12 +21,12 @@ path = [
cwd + '/CMSIS/GD/GD32F4xx/Include',
cwd + '/CMSIS',
cwd + '/GD32F4xx_standard_peripheral/Include',]
-
+
if GetDepend(['RT_USING_BSP_USB']):
path += [cwd + '/GD32F4xx_usb_driver/Include']
src += [cwd + '/GD32F4xx_usb_driver/Source']
-CPPDEFINES = ['USE_STDPERIPH_DRIVER', 'GD32F4XX']
+CPPDEFINES = ['USE_STDPERIPH_DRIVER']
group = DefineGroup('Libraries', src, depend = [''], CPPPATH = path, CPPDEFINES = CPPDEFINES)
diff --git a/bsp/gd32450z-eval/drivers/drv_usart.c b/bsp/gd32450z-eval/drivers/drv_usart.c
index fa691a42b9..423befbc93 100644
--- a/bsp/gd32450z-eval/drivers/drv_usart.c
+++ b/bsp/gd32450z-eval/drivers/drv_usart.c
@@ -377,14 +377,14 @@ static rt_err_t gd32_control(struct rt_serial_device *serial, int cmd, void *arg
/* disable rx irq */
NVIC_DisableIRQ(uart->irqn);
/* disable interrupt */
- usart_interrupt_disable(uart->uart_periph, USART_INTEN_RBNEIE);
+ usart_interrupt_disable(uart->uart_periph, USART_INT_RBNE);
break;
case RT_DEVICE_CTRL_SET_INT:
/* enable rx irq */
NVIC_EnableIRQ(uart->irqn);
/* enable interrupt */
- usart_interrupt_enable(uart->uart_periph, USART_INTEN_RBNEIE);
+ usart_interrupt_enable(uart->uart_periph, USART_INT_RBNE);
break;
}
@@ -430,7 +430,7 @@ static void uart_isr(struct rt_serial_device *serial)
RT_ASSERT(uart != RT_NULL);
/* UART in mode Receiver -------------------------------------------------*/
- if ((usart_interrupt_flag_get(uart->uart_periph, USART_INT_RBNEIE) != RESET) &&
+ if ((usart_interrupt_flag_get(uart->uart_periph, USART_INT_FLAG_RBNE) != RESET) &&
(usart_flag_get(uart->uart_periph, USART_FLAG_RBNE) != RESET))
{
rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_IND);
diff --git a/bsp/gd32450z-eval/rtconfig.py b/bsp/gd32450z-eval/rtconfig.py
index f137cf5a65..1f01ffe88b 100644
--- a/bsp/gd32450z-eval/rtconfig.py
+++ b/bsp/gd32450z-eval/rtconfig.py
@@ -38,7 +38,7 @@ if PLATFORM == 'gcc':
OBJDUMP = PREFIX + 'objdump'
OBJCPY = PREFIX + 'objcopy'
- DEVICE = ' -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections'
+ DEVICE = ' -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -ffunction-sections -fdata-sections -DGD32F450'
CFLAGS = DEVICE + ' -Dgcc' # -D' + PART_TYPE
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp -Wa,-mimplicit-it=thumb '
LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread-gd32.map,-cref,-u,Reset_Handler -T gd32_rom.ld'
diff --git a/bsp/imx6ul/.config b/bsp/imx6ul/.config
index 91e1e6fac2..6d71016845 100644
--- a/bsp/imx6ul/.config
+++ b/bsp/imx6ul/.config
@@ -71,15 +71,14 @@ CONFIG_RT_USING_DEVICE=y
# CONFIG_RT_USING_INTERRUPT_INFO is not set
CONFIG_RT_USING_CONSOLE=y
CONFIG_RT_CONSOLEBUF_SIZE=128
-CONFIG_RT_CONSOLE_DEVICE_NAME="uart"
-CONFIG_RT_VER_NUM=0x40003
+CONFIG_RT_CONSOLE_DEVICE_NAME="uart1"
+CONFIG_RT_VER_NUM=0x40004
CONFIG_ARCH_ARM=y
-# CONFIG_RT_USING_CPU_FFS is not set
+CONFIG_RT_USING_CPU_FFS=y
CONFIG_ARCH_ARM_CORTEX_A=y
# CONFIG_RT_SMP_AUTO_BOOT is not set
CONFIG_RT_USING_GIC_V2=y
# CONFIG_RT_USING_GIC_V3 is not set
-# CONFIG_RT_NO_USING_GIC is not set
CONFIG_ARCH_ARM_CORTEX_A7=y
# CONFIG_ARCH_CPU_STACK_GROWS_UPWARD is not set
@@ -177,6 +176,7 @@ CONFIG_RT_USING_POSIX=y
# CONFIG_RT_USING_POSIX_GETLINE is not set
# CONFIG_RT_USING_POSIX_AIO is not set
# CONFIG_RT_USING_MODULE is not set
+CONFIG_RT_LIBC_FIXED_TIMEZONE=8
#
# Network
@@ -213,9 +213,15 @@ CONFIG_RT_USING_POSIX=y
# CONFIG_RT_USING_RYM is not set
# CONFIG_RT_USING_ULOG is not set
# CONFIG_RT_USING_UTEST is not set
+# CONFIG_RT_USING_RT_LINK is not set
# CONFIG_RT_USING_LWP is not set
#
+# RT-Thread Utestcases
+#
+# CONFIG_RT_USING_UTESTCASES is not set
+
+#
# RT-Thread online packages
#
@@ -282,8 +288,6 @@ CONFIG_RT_USING_POSIX=y
# CONFIG_PKG_USING_LIBRWS is not set
# CONFIG_PKG_USING_TCPSERVER is not set
# CONFIG_PKG_USING_PROTOBUF_C is not set
-# CONFIG_PKG_USING_ONNX_PARSER is not set
-# CONFIG_PKG_USING_ONNX_BACKEND is not set
# CONFIG_PKG_USING_DLT645 is not set
# CONFIG_PKG_USING_QXWZ is not set
# CONFIG_PKG_USING_SMTP_CLIENT is not set
@@ -297,6 +301,13 @@ CONFIG_RT_USING_POSIX=y
# CONFIG_PKG_USING_PDULIB is not set
# CONFIG_PKG_USING_BTSTACK is not set
# CONFIG_PKG_USING_LORAWAN_ED_STACK is not set
+# CONFIG_PKG_USING_WAYZ_IOTKIT is not set
+# CONFIG_PKG_USING_MAVLINK is not set
+# CONFIG_PKG_USING_RAPIDJSON is not set
+# CONFIG_PKG_USING_BSAL is not set
+# CONFIG_PKG_USING_AGILE_MODBUS is not set
+# CONFIG_PKG_USING_AGILE_FTP is not set
+# CONFIG_PKG_USING_EMBEDDEDPROTO is not set
#
# security packages
@@ -322,7 +333,10 @@ CONFIG_RT_USING_POSIX=y
# CONFIG_PKG_USING_STEMWIN is not set
# CONFIG_PKG_USING_WAVPLAYER is not set
# CONFIG_PKG_USING_TJPGD is not set
+# CONFIG_PKG_USING_PDFGEN is not set
# CONFIG_PKG_USING_HELIX is not set
+# CONFIG_PKG_USING_AZUREGUIX is not set
+# CONFIG_PKG_USING_TOUCHGFX2RTT is not set
#
# tools packages
@@ -334,9 +348,12 @@ CONFIG_RT_USING_POSIX=y
# CONFIG_PKG_USING_RDB is not set
# CONFIG_PKG_USING_QRCODE is not set
# CONFIG_PKG_USING_ULOG_EASYFLASH is not set
+# CONFIG_PKG_USING_ULOG_FILE is not set
+# CONFIG_PKG_USING_LOGMGR is not set
# CONFIG_PKG_USING_ADBD is not set
# CONFIG_PKG_USING_COREMARK is not set
# CONFIG_PKG_USING_DHRYSTONE is not set
+# CONFIG_PKG_USING_MEMORYPERF is not set
# CONFIG_PKG_USING_NR_MICRO_SHELL is not set
# CONFIG_PKG_USING_CHINESE_FONT_LIBRARY is not set
# CONFIG_PKG_USING_LUNAR_CALENDAR is not set
@@ -344,6 +361,22 @@ CONFIG_RT_USING_POSIX=y
# CONFIG_PKG_USING_GPS_RMC is not set
# CONFIG_PKG_USING_URLENCODE is not set
# CONFIG_PKG_USING_UMCN is not set
+# CONFIG_PKG_USING_LWRB2RTT is not set
+# CONFIG_PKG_USING_CPU_USAGE is not set
+# CONFIG_PKG_USING_GBK2UTF8 is not set
+# CONFIG_PKG_USING_VCONSOLE is not set
+# CONFIG_PKG_USING_KDB is not set
+# CONFIG_PKG_USING_WAMR is not set
+# CONFIG_PKG_USING_MICRO_XRCE_DDS_CLIENT is not set
+# CONFIG_PKG_USING_LWLOG is not set
+# CONFIG_PKG_USING_ANV_TRACE is not set
+# CONFIG_PKG_USING_ANV_MEMLEAK is not set
+# CONFIG_PKG_USING_ANV_TESTSUIT is not set
+# CONFIG_PKG_USING_ANV_BENCH is not set
+# CONFIG_PKG_USING_DEVMEM is not set
+# CONFIG_PKG_USING_REGEX is not set
+# CONFIG_PKG_USING_MEM_SANDBOX is not set
+# CONFIG_PKG_USING_SOLAR_TERMS is not set
#
# system packages
@@ -352,7 +385,6 @@ CONFIG_RT_USING_POSIX=y
# CONFIG_PKG_USING_PERSIMMON is not set
# CONFIG_PKG_USING_CAIRO is not set
# CONFIG_PKG_USING_PIXMAN is not set
-# CONFIG_PKG_USING_LWEXT4 is not set
# CONFIG_PKG_USING_PARTITION is not set
# CONFIG_PKG_USING_FAL is not set
# CONFIG_PKG_USING_FLASHDB is not set
@@ -362,6 +394,9 @@ CONFIG_RT_USING_POSIX=y
# CONFIG_PKG_USING_CMSIS is not set
# CONFIG_PKG_USING_DFS_YAFFS is not set
# CONFIG_PKG_USING_LITTLEFS is not set
+# CONFIG_PKG_USING_DFS_JFFS2 is not set
+# CONFIG_PKG_USING_DFS_UFFS is not set
+# CONFIG_PKG_USING_LWEXT4 is not set
# CONFIG_PKG_USING_THREAD_POOL is not set
# CONFIG_PKG_USING_ROBOTS is not set
# CONFIG_PKG_USING_EV is not set
@@ -371,7 +406,26 @@ CONFIG_RT_USING_POSIX=y
# CONFIG_PKG_USING_RAMDISK is not set
# CONFIG_PKG_USING_MININI is not set
# CONFIG_PKG_USING_QBOOT is not set
+
+#
+# Micrium: Micrium software products porting for RT-Thread
+#
+# CONFIG_PKG_USING_UCOSIII_WRAPPER is not set
+# CONFIG_PKG_USING_UCOSII_WRAPPER is not set
+# CONFIG_PKG_USING_UC_CRC is not set
+# CONFIG_PKG_USING_UC_CLK is not set
+# CONFIG_PKG_USING_UC_COMMON is not set
+# CONFIG_PKG_USING_UC_MODBUS is not set
# CONFIG_PKG_USING_PPOOL is not set
+# CONFIG_PKG_USING_OPENAMP is not set
+# CONFIG_PKG_USING_RT_KPRINTF_THREADSAFE is not set
+# CONFIG_PKG_USING_RT_MEMCPY_CM is not set
+# CONFIG_PKG_USING_QFPLIB_M0_FULL is not set
+# CONFIG_PKG_USING_QFPLIB_M0_TINY is not set
+# CONFIG_PKG_USING_QFPLIB_M3 is not set
+# CONFIG_PKG_USING_LPM is not set
+# CONFIG_PKG_USING_TLSF is not set
+# CONFIG_PKG_USING_EVENT_RECORDER is not set
#
# peripheral libraries and drivers
@@ -380,6 +434,7 @@ CONFIG_RT_USING_POSIX=y
# CONFIG_PKG_USING_REALTEK_AMEBA is not set
# CONFIG_PKG_USING_SHT2X is not set
# CONFIG_PKG_USING_SHT3X is not set
+# CONFIG_PKG_USING_AS7341 is not set
# CONFIG_PKG_USING_STM32_SDIO is not set
# CONFIG_PKG_USING_ICM20608 is not set
# CONFIG_PKG_USING_U8G2 is not set
@@ -427,6 +482,30 @@ CONFIG_RT_USING_POSIX=y
# CONFIG_PKG_USING_LY68L6400 is not set
# CONFIG_PKG_USING_DM9051 is not set
# CONFIG_PKG_USING_SSD1306 is not set
+# CONFIG_PKG_USING_QKEY is not set
+# CONFIG_PKG_USING_RS485 is not set
+# CONFIG_PKG_USING_NES is not set
+# CONFIG_PKG_USING_VIRTUAL_SENSOR is not set
+# CONFIG_PKG_USING_VDEVICE is not set
+# CONFIG_PKG_USING_SGM706 is not set
+# CONFIG_PKG_USING_STM32WB55_SDK is not set
+# CONFIG_PKG_USING_RDA58XX is not set
+# CONFIG_PKG_USING_LIBNFC is not set
+# CONFIG_PKG_USING_MFOC is not set
+# CONFIG_PKG_USING_TMC51XX is not set
+
+#
+# AI packages
+#
+# CONFIG_PKG_USING_LIBANN is not set
+# CONFIG_PKG_USING_NNOM is not set
+# CONFIG_PKG_USING_ONNX_BACKEND is not set
+# CONFIG_PKG_USING_ONNX_PARSER is not set
+# CONFIG_PKG_USING_TENSORFLOWLITEMICRO is not set
+# CONFIG_PKG_USING_ELAPACK is not set
+# CONFIG_PKG_USING_ULAPACK is not set
+# CONFIG_PKG_USING_QUEST is not set
+# CONFIG_PKG_USING_NAXOS is not set
#
# miscellaneous packages
@@ -436,6 +515,7 @@ CONFIG_RT_USING_POSIX=y
# CONFIG_PKG_USING_FASTLZ is not set
# CONFIG_PKG_USING_MINILZO is not set
# CONFIG_PKG_USING_QUICKLZ is not set
+# CONFIG_PKG_USING_LZMA is not set
# CONFIG_PKG_USING_MULTIBUTTON is not set
# CONFIG_PKG_USING_FLEXIBLE_BUTTON is not set
# CONFIG_PKG_USING_CANFESTIVAL is not set
@@ -456,17 +536,24 @@ CONFIG_RT_USING_POSIX=y
# CONFIG_PKG_USING_PERIPHERAL_SAMPLES is not set
# CONFIG_PKG_USING_HELLO is not set
# CONFIG_PKG_USING_VI is not set
-# CONFIG_PKG_USING_NNOM is not set
-# CONFIG_PKG_USING_LIBANN is not set
-# CONFIG_PKG_USING_ELAPACK is not set
+# CONFIG_PKG_USING_KI is not set
# CONFIG_PKG_USING_ARMv7M_DWT is not set
# CONFIG_PKG_USING_VT100 is not set
-# CONFIG_PKG_USING_TETRIS is not set
-# CONFIG_PKG_USING_ULAPACK is not set
# CONFIG_PKG_USING_UKAL is not set
# CONFIG_PKG_USING_CRCLIB is not set
+
+#
+# entertainment: terminal games and other interesting software packages
+#
# CONFIG_PKG_USING_THREES is not set
# CONFIG_PKG_USING_2048 is not set
+# CONFIG_PKG_USING_SNAKE is not set
+# CONFIG_PKG_USING_TETRIS is not set
+# CONFIG_PKG_USING_DONUT is not set
+# CONFIG_PKG_USING_ACLOCK is not set
# CONFIG_PKG_USING_LWGPS is not set
-# CONFIG_PKG_USING_TENSORFLOWLITEMICRO is not set
+# CONFIG_PKG_USING_STATE_MACHINE is not set
+# CONFIG_PKG_USING_MCURSES is not set
+# CONFIG_PKG_USING_COWSAY is not set
+CONFIG_RT_USING_UART1=y
CONFIG_SOC_MCIMX6X4=y
diff --git a/bsp/imx6ul/Kconfig b/bsp/imx6ul/Kconfig
index 9fbc95e841..9cd9ab8dd5 100644
--- a/bsp/imx6ul/Kconfig
+++ b/bsp/imx6ul/Kconfig
@@ -18,6 +18,7 @@ config PKGS_DIR
config BOARD_IMX6UL
bool
select ARCH_ARM_CORTEX_A7
+ select RT_USING_GIC_V2
default y
source "$RTT_DIR/Kconfig"
diff --git a/bsp/imx6ul/SConstruct b/bsp/imx6ul/SConstruct
index 8c9e4ee347..de15998d09 100644
--- a/bsp/imx6ul/SConstruct
+++ b/bsp/imx6ul/SConstruct
@@ -10,7 +10,7 @@ else:
sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')]
from building import *
-TARGET = 'rtthread-imx6.' + rtconfig.TARGET_EXT
+TARGET = 'rtthread.' + rtconfig.TARGET_EXT
DefaultEnvironment(tools=[])
env = Environment(tools = ['mingw'],
diff --git a/bsp/imx6ul/drivers/Kconfig b/bsp/imx6ul/drivers/Kconfig
index e69de29bb2..95c536178d 100644
--- a/bsp/imx6ul/drivers/Kconfig
+++ b/bsp/imx6ul/drivers/Kconfig
@@ -0,0 +1,3 @@
+config RT_USING_UART1
+ bool "Enable UART1"
+ default y
diff --git a/bsp/imx6ul/drivers/iomux/uart_iomux_config.c b/bsp/imx6ul/drivers/iomux/uart_iomux_config.c
index bad8e945c3..4da7598986 100644
--- a/bsp/imx6ul/drivers/iomux/uart_iomux_config.c
+++ b/bsp/imx6ul/drivers/iomux/uart_iomux_config.c
@@ -33,10 +33,21 @@
#include "io.h"
#include <assert.h>
-#define MX6UL_PAD_UART1_TX_DATA__UART1_TX1 (IOMUXC_BASE_ADDR+0x084)
-#define MX6UL_PAD_UART1_RX_DATA__UART1_RX1 (IOMUXC_BASE_ADDR+0x088)
+#define MX6UL_PAD_UART1_TX_DATA__UART1_TX1 (IOMUXC_BASE_ADDR+0x084)
+#define MX6UL_PAD_UART1_RX_DATA__UART1_RX1 (IOMUXC_BASE_ADDR+0x088)
#define IOMUXC_UART1_UART_RXD_MUX_SELECT_INPUT1 (IOMUXC_BASE_ADDR+0x624)
+#define PIN_CFG(mux_ctl_offset, pad_ctl_offset, select_input_offset, mux_mode, daisy, pad_setting) \
+ do {\
+ writel(mux_mode, IOMUXC_BASE_ADDR + mux_ctl_offset);\
+ if (select_input_offset != 0)\
+ writel(daisy, IOMUXC_BASE_ADDR + select_input_offset);\
+ writel(pad_setting, IOMUXC_BASE_ADDR + pad_ctl_offset);\
+ } while(0);
+
+#define MX6UL_PAD_UART1_TX_DATA__UART1_TX(p) PIN_CFG(0x0084, 0x0310, 0x0624, 0x0, 0x2, p)
+#define MX6UL_PAD_UART1_RX_DATA__UART1_RX(p) PIN_CFG(0x0088, 0x0314, 0x0624, 0x0, 0x3, p)
+
void uart1_iomux_config(void)
{
/* UART1 TXD */
@@ -97,11 +108,11 @@ void uart_iomux_config(int instance)
return uart5_iomux_config();
case HW_UART7:
- return uart5_iomux_config();
+ return uart5_iomux_config();
case HW_UART8:
- return uart5_iomux_config();
-
+ return uart5_iomux_config();
+
default:
assert(false);
}
diff --git a/bsp/imx6ul/drivers/serial.c b/bsp/imx6ul/drivers/serial.c
index ce46050c92..5764d088de 100644
--- a/bsp/imx6ul/drivers/serial.c
+++ b/bsp/imx6ul/drivers/serial.c
@@ -11,9 +11,7 @@
#include <rthw.h>
#include <registers/regsuart.h>
#include <imx_uart.h>
-
#include <rtdevice.h>
-
#include "serial.h"
struct hw_uart_device
@@ -123,16 +121,6 @@ static const struct rt_uart_ops _uart_ops =
uart_getc,
};
-#ifdef RT_USING_UART0
-/* UART device driver structure */
-static struct hw_uart_device _uart0_device =
-{
- HW_UART0,
- IMX_INT_UART0
-};
-static struct rt_serial_device _serial0;
-#endif
-
#ifdef RT_USING_UART1
/* UART1 device driver structure */
static struct hw_uart_device _uart1_device =
@@ -156,18 +144,6 @@ int rt_hw_uart_init(void)
config.invert = NRZ_NORMAL;
config.bufsz = RT_SERIAL_RB_BUFSZ;
-#ifdef RT_USING_UART0
- uart = &_uart0_device;
-
- _serial0.ops = &_uart_ops;
- _serial0.config = config;
-
- /* register UART1 device */
- rt_hw_serial_register(&_serial0, "uart0",
- RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
- uart);
-#endif
-
#ifdef RT_USING_UART1
uart = &_uart1_device;
_serial1.ops = &_uart_ops;
diff --git a/bsp/imx6ul/imx6.lds b/bsp/imx6ul/link.lds
index a889774f85..a889774f85 100644
--- a/bsp/imx6ul/imx6.lds
+++ b/bsp/imx6ul/link.lds
diff --git a/bsp/imx6ul/platform/include/mx6ul/imx6ul-pinfunc.h b/bsp/imx6ul/platform/include/mx6ul/imx6ul-pinfunc.h
deleted file mode 100644
index dc66fe20ed..0000000000
--- a/bsp/imx6ul/platform/include/mx6ul/imx6ul-pinfunc.h
+++ /dev/null
@@ -1,915 +0,0 @@
-/*
- * Copyright 2014 - 2015 Freescale Semiconductor, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- */
-
-#ifndef __DTS_IMX6UL_PINFUNC_H
-#define __DTS_IMX6UL_PINFUNC_H
-
-#define PIN_CFG(mux_ctl_offset, pad_ctl_offset, select_input_offset, mux_mode, daisy, pad_setting) \
- do {\
- writel(mux_mode, IOMUXC_BASE_ADDR + mux_ctl_offset);\
- if (select_input_offset != 0)\
- writel(daisy, IOMUXC_BASE_ADDR + select_input_offset);\
- writel(pad_setting, IOMUXC_BASE_ADDR + pad_ctl_offset);\
- } while(0);
-
-/*
- * The pin function ID is a tuple of
- * <mux_reg conf_reg input_reg mux_mode input_val>
- */
-#define MX6UL_PAD_JTAG_MOD__SJC_MOD(p) PIN_CFG(0x0044, 0x02D0, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_JTAG_MOD__GPT2_CLK(p) PIN_CFG(0x0044, 0x02D0, 0x05A0, 0x1, 0x0, p)
-#define MX6UL_PAD_JTAG_MOD__SPDIF_OUT(p) PIN_CFG(0x0044, 0x02D0, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_JTAG_MOD__ENET1_REF_CLK_25M(p) PIN_CFG(0x0044, 0x02D0, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_JTAG_MOD__CCM_PMIC_RDY(p) PIN_CFG(0x0044, 0x02D0, 0x04C0, 0x4, 0x0, p)
-#define MX6UL_PAD_JTAG_MOD__GPIO1_IO10(p) PIN_CFG(0x0044, 0x02D0, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_JTAG_MOD__SDMA_EXT_EVENT00(p) PIN_CFG(0x0044, 0x02D0, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_JTAG_TMS__SJC_TMS(p) PIN_CFG(0x0048, 0x02D4, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_JTAG_TMS__GPT2_CAPTURE1(p) PIN_CFG(0x0048, 0x02D4, 0x0598, 0x1, 0x0, p)
-#define MX6UL_PAD_JTAG_TMS__SAI2_MCLK(p) PIN_CFG(0x0048, 0x02D4, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_JTAG_TMS__CCM_CLKO1(p) PIN_CFG(0x0048, 0x02D4, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_JTAG_TMS__CCM_WAIT(p) PIN_CFG(0x0048, 0x02D4, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_JTAG_TMS__GPIO1_IO11(p) PIN_CFG(0x0048, 0x02D4, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_JTAG_TMS__SDMA_EXT_EVENT01(p) PIN_CFG(0x0048, 0x02D4, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_JTAG_TMS__EPIT1_OUT(p) PIN_CFG(0x0048, 0x02D4, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_JTAG_TDO__SJC_TDO(p) PIN_CFG(0x004C, 0x02D8, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_JTAG_TDO__GPT2_CAPTURE2(p) PIN_CFG(0x004C, 0x02D8, 0x059C, 0x1, 0x0, p)
-#define MX6UL_PAD_JTAG_TDO__SAI2_TX_SYNC(p) PIN_CFG(0x004C, 0x02D8, 0x05FC, 0x2, 0x0, p)
-#define MX6UL_PAD_JTAG_TDO__CCM_CLKO2(p) PIN_CFG(0x004C, 0x02D8, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_JTAG_TDO__CCM_STOP(p) PIN_CFG(0x004C, 0x02D8, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_JTAG_TDO__GPIO1_IO12(p) PIN_CFG(0x004C, 0x02D8, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_JTAG_TDO__MQS_RIGHT(p) PIN_CFG(0x004C, 0x02D8, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_JTAG_TDO__EPIT2_OUT(p) PIN_CFG(0x004C, 0x02D8, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_JTAG_TDI__SJC_TDI(p) PIN_CFG(0x0050, 0x02DC, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_JTAG_TDI__GPT2_COMPARE1(p) PIN_CFG(0x0050, 0x02DC, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_JTAG_TDI__SAI2_TX_BCLK(p) PIN_CFG(0x0050, 0x02DC, 0x05F8, 0x2, 0x0, p)
-#define MX6UL_PAD_JTAG_TDI__PWM6_OUT(p) PIN_CFG(0x0050, 0x02DC, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_JTAG_TDI__GPIO1_IO13(p) PIN_CFG(0x0050, 0x02DC, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_JTAG_TDI__MQS_LEFT(p) PIN_CFG(0x0050, 0x02DC, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_JTAG_TDI__SIM1_POWER_FAIL(p) PIN_CFG(0x0050, 0x02DC, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_JTAG_TCK__SJC_TCK(p) PIN_CFG(0x0054, 0x02E0, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_JTAG_TCK__GPT2_COMPARE2(p) PIN_CFG(0x0054, 0x02E0, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_JTAG_TCK__SAI2_RX_DATA(p) PIN_CFG(0x0054, 0x02E0, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_JTAG_TCK__PWM7_OUT(p) PIN_CFG(0x0054, 0x02E0, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_JTAG_TCK__GPIO1_IO14(p) PIN_CFG(0x0054, 0x02E0, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_JTAG_TCK__SIM2_POWER_FAIL(p) PIN_CFG(0x0054, 0x02E0, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_JTAG_TRST_B__SJC_TRSTB(p) PIN_CFG(0x0058, 0x02E4, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_JTAG_TRST_B__GPT2_COMPARE3(p) PIN_CFG(0x0058, 0x02E4, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_JTAG_TRST_B__SAI2_TX_DATA(p) PIN_CFG(0x0058, 0x02E4, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_JTAG_TRST_B__PWM8_OUT(p) PIN_CFG(0x0058, 0x02E4, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_JTAG_TRST_B__GPIO1_IO15(p) PIN_CFG(0x0058, 0x02E4, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_JTAG_TRST_B__CAAM_RNG_OSC_OBS(p) PIN_CFG(0x0058, 0x02E4, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO00__I2C2_SCL(p) PIN_CFG(0x005C, 0x02E8, 0x05AC, 0x0, 0x1, p)
-#define MX6UL_PAD_GPIO1_IO00__GPT1_CAPTURE1(p) PIN_CFG(0x005C, 0x02E8, 0x058C, 0x1, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO00__ANATOP_OTG1_ID(p) PIN_CFG(0x005C, 0x02E8, 0x04B8, 0x2, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO00__ENET1_REF_CLK1(p) PIN_CFG(0x005C, 0x02E8, 0x0574, 0x3, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO00__MQS_RIGHT(p) PIN_CFG(0x005C, 0x02E8, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO00__GPIO1_IO00(p) PIN_CFG(0x005C, 0x02E8, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO00__ENET1_1588_EVENT0_IN(p) PIN_CFG(0x005C, 0x02E8, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO00__SRC_SYSTEM_RESET(p) PIN_CFG(0x005C, 0x02E8, 0x0000, 0x7, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO00__WDOG3_WDOG_B(p) PIN_CFG(0x005C, 0x02E8, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO01__I2C2_SDA(p) PIN_CFG(0x0060, 0x02EC, 0x05B0, 0x0, 0x1, p)
-#define MX6UL_PAD_GPIO1_IO01__GPT1_COMPARE1(p) PIN_CFG(0x0060, 0x02EC, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO01__USB_OTG1_OC(p) PIN_CFG(0x0060, 0x02EC, 0x0664, 0x2, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO01__ENET2_REF_CLK2(p) PIN_CFG(0x0060, 0x02EC, 0x057C, 0x3, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO01__MQS_LEFT(p) PIN_CFG(0x0060, 0x02EC, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO01__GPIO1_IO01(p) PIN_CFG(0x0060, 0x02EC, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO01__ENET1_1588_EVENT0_OUT(p) PIN_CFG(0x0060, 0x02EC, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO01__SRC_EARLY_RESET(p) PIN_CFG(0x0060, 0x02EC, 0x0000, 0x7, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO01__WDOG1_WDOG_B(p) PIN_CFG(0x0060, 0x02EC, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO02__I2C1_SCL(p) PIN_CFG(0x0064, 0x02F0, 0x05A4, 0x0, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO02__GPT1_COMPARE2(p) PIN_CFG(0x0064, 0x02F0, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO02__USB_OTG2_PWR(p) PIN_CFG(0x0064, 0x02F0, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO02__ENET1_REF_CLK_25M(p) PIN_CFG(0x0064, 0x02F0, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO02__USDHC1_WP(p) PIN_CFG(0x0064, 0x02F0, 0x066C, 0x4, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO02__GPIO1_IO02(p) PIN_CFG(0x0064, 0x02F0, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO02__SDMA_EXT_EVENT00(p) PIN_CFG(0x0064, 0x02F0, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO02__SRC_ANY_PU_RESET(p) PIN_CFG(0x0064, 0x02F0, 0x0000, 0x7, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO02__UART1_TX(p) PIN_CFG(0x0064, 0x02F0, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO03__I2C1_SDA(p) PIN_CFG(0x0068, 0x02F4, 0x05A8, 0x0, 0x1, p)
-#define MX6UL_PAD_GPIO1_IO03__GPT1_COMPARE3(p) PIN_CFG(0x0068, 0x02F4, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO03__USB_OTG2_OC(p) PIN_CFG(0x0068, 0x02F4, 0x0660, 0x2, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO03__USDHC1_CD_B(p) PIN_CFG(0x0068, 0x02F4, 0x0668, 0x4, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO03__GPIO1_IO03(p) PIN_CFG(0x0068, 0x02F4, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO03__CCM_DI0_EXT_CLK(p) PIN_CFG(0x0068, 0x02F4, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO03__SRC_TESTER_ACK(p) PIN_CFG(0x0068, 0x02F4, 0x0000, 0x7, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO03__UART1_RX(p) PIN_CFG(0x0068, 0x02F4, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO04__ENET1_REF_CLK1(p) PIN_CFG(0x006C, 0x02F8, 0x0574, 0x0, 0x1, p)
-#define MX6UL_PAD_GPIO1_IO04__PWM3_OUT(p) PIN_CFG(0x006C, 0x02F8, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO04__USB_OTG1_PWR(p) PIN_CFG(0x006C, 0x02F8, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO04__USDHC1_RESET_B(p) PIN_CFG(0x006C, 0x02F8, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO04__GPIO1_IO04(p) PIN_CFG(0x006C, 0x02F8, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO04__ENET2_1588_EVENT0_IN(p) PIN_CFG(0x006C, 0x02F8, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO04__UART5_TX(p) PIN_CFG(0x006C, 0x02F8, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO05__ENET2_REF_CLK2(p) PIN_CFG(0x0070, 0x02FC, 0x057C, 0x0, 0x1, p)
-#define MX6UL_PAD_GPIO1_IO05__PWM4_OUT(p) PIN_CFG(0x0070, 0x02FC, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO05__ANATOP_OTG2_ID(p) PIN_CFG(0x0070, 0x02FC, 0x04BC, 0x2, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO05__CSI_FIELD(p) PIN_CFG(0x0070, 0x02FC, 0x0530, 0x3, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO05__USDHC1_VSELECT(p) PIN_CFG(0x0070, 0x02FC, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO05__GPIO1_IO05(p) PIN_CFG(0x0070, 0x02FC, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO05__ENET2_1588_EVENT0_OUT(p) PIN_CFG(0x0070, 0x02FC, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO05__UART5_RX(p) PIN_CFG(0x0070, 0x02FC, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO06__ENET1_MDIO(p) PIN_CFG(0x0074, 0x0300, 0x0578, 0x0, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO06__ENET2_MDIO(p) PIN_CFG(0x0074, 0x0300, 0x0580, 0x1, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO06__USB_OTG_PWR_WAKE(p) PIN_CFG(0x0074, 0x0300, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO06__CSI_MCLK(p) PIN_CFG(0x0074, 0x0300, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO06__USDHC2_WP(p) PIN_CFG(0x0074, 0x0300, 0x069C, 0x4, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO06__GPIO1_IO06(p) PIN_CFG(0x0074, 0x0300, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO06__CCM_WAIT(p) PIN_CFG(0x0074, 0x0300, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO06__CCM_REF_EN_B(p) PIN_CFG(0x0074, 0x0300, 0x0000, 0x7, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO06__UART1_DCE_CTS(p) PIN_CFG(0x0074, 0x0300, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO06__UART1_DTE_RTS(p) PIN_CFG(0x0074, 0x0300, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO07__ENET1_MDC(p) PIN_CFG(0x0078, 0x0304, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO07__ENET2_MDC(p) PIN_CFG(0x0078, 0x0304, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO07__USB_OTG_HOST_MODE(p) PIN_CFG(0x0078, 0x0304, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO07__CSI_PIXCLK(p) PIN_CFG(0x0078, 0x0304, 0x0528, 0x3, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO07__USDHC2_CD_B(p) PIN_CFG(0x0078, 0x0304, 0x0674, 0x4, 0x1, p)
-#define MX6UL_PAD_GPIO1_IO07__GPIO1_IO07(p) PIN_CFG(0x0078, 0x0304, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO07__CCM_STOP(p) PIN_CFG(0x0078, 0x0304, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO07__UART1_DCE_RTS(p) PIN_CFG(0x0078, 0x0304, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO07__UART1_DTE_CTS(p) PIN_CFG(0x0078, 0x0304, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO08__PWM1_OUT(p) PIN_CFG(0x007C, 0x0308, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO08__WDOG1_WDOG_B(p) PIN_CFG(0x007C, 0x0308, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO08__SPDIF_OUT(p) PIN_CFG(0x007C, 0x0308, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO08__CSI_VSYNC(p) PIN_CFG(0x007C, 0x0308, 0x052C, 0x3, 0x1, p)
-#define MX6UL_PAD_GPIO1_IO08__USDHC2_VSELECT(p) PIN_CFG(0x007C, 0x0308, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO08__GPIO1_IO08(p) PIN_CFG(0x007C, 0x0308, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO08__CCM_PMIC_RDY(p) PIN_CFG(0x007C, 0x0308, 0x04C0, 0x6, 0x1, p)
-#define MX6UL_PAD_GPIO1_IO08__UART5_DCE_RTS(p) PIN_CFG(0x007C, 0x0308, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO08__UART5_DTE_CTS(p) PIN_CFG(0x007C, 0x0308, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO09__PWM2_OUT(p) PIN_CFG(0x0080, 0x030C, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO09__WDOG1_WDOG_ANY(p) PIN_CFG(0x0080, 0x030C, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO09__SPDIF_IN(p) PIN_CFG(0x0080, 0x030C, 0x0618, 0x2, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO09__CSI_HSYNC(p) PIN_CFG(0x0080, 0x030C, 0x0524, 0x3, 0x1, p)
-#define MX6UL_PAD_GPIO1_IO09__USDHC2_RESET_B(p) PIN_CFG(0x0080, 0x030C, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO09__GPIO1_IO09(p) PIN_CFG(0x0080, 0x030C, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO09__USDHC1_RESET_B(p) PIN_CFG(0x0080, 0x030C, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO09__UART5_DCE_CTS(p) PIN_CFG(0x0080, 0x030C, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_GPIO1_IO09__UART5_DTE_RTS(p) PIN_CFG(0x0080, 0x030C, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_UART1_TX_DATA__UART1_TX(p) PIN_CFG(0x0084, 0x0310, 0x0624, 0x0, 0x2, p)
-#define MX6UL_PAD_UART1_TX_DATA__ENET1_RDATA02(p) PIN_CFG(0x0084, 0x0310, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_UART1_TX_DATA__I2C3_SCL(p) PIN_CFG(0x0084, 0x0310, 0x05B4, 0x2, 0x0, p)
-#define MX6UL_PAD_UART1_TX_DATA__CSI_DATA02(p) PIN_CFG(0x0084, 0x0310, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_UART1_TX_DATA__GPT1_COMPARE1(p) PIN_CFG(0x0084, 0x0310, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_UART1_TX_DATA__GPIO1_IO16(p) PIN_CFG(0x0084, 0x0310, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_UART1_TX_DATA__SPDIF_OUT(p) PIN_CFG(0x0084, 0x0310, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_UART1_RX_DATA__UART1_RX(p) PIN_CFG(0x0088, 0x0314, 0x0624, 0x0, 0x3, p)
-#define MX6UL_PAD_UART1_RX_DATA__ENET1_RDATA03(p) PIN_CFG(0x0088, 0x0314, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_UART1_RX_DATA__I2C3_SDA(p) PIN_CFG(0x0088, 0x0314, 0x05B8, 0x2, 0x0, p)
-#define MX6UL_PAD_UART1_RX_DATA__CSI_DATA03(p) PIN_CFG(0x0088, 0x0314, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_UART1_RX_DATA__GPT1_CLK(p) PIN_CFG(0x0088, 0x0314, 0x0594, 0x4, 0x0, p)
-#define MX6UL_PAD_UART1_RX_DATA__GPIO1_IO17(p) PIN_CFG(0x0088, 0x0314, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_UART1_RX_DATA__SPDIF_IN(p) PIN_CFG(0x0088, 0x0314, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_UART1_CTS_B__UART1_DCE_CTS(p) PIN_CFG(0x008C, 0x0318, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_UART1_CTS_B__UART1_DTE_RTS(p) PIN_CFG(0x008C, 0x0318, 0x0620, 0x0, 0x2, p)
-#define MX6UL_PAD_UART1_CTS_B__ENET1_RX_CLK(p) PIN_CFG(0x008C, 0x0318, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_UART1_CTS_B__USDHC1_WP(p) PIN_CFG(0x008C, 0x0318, 0x066C, 0x2, 0x1, p)
-#define MX6UL_PAD_UART1_CTS_B__CSI_DATA04(p) PIN_CFG(0x008C, 0x0318, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_UART1_CTS_B__ENET2_1588_EVENT1_IN(p) PIN_CFG(0x008C, 0x0318, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_UART1_CTS_B__GPIO1_IO18(p) PIN_CFG(0x008C, 0x0318, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_UART1_CTS_B__USDHC2_WP(p) PIN_CFG(0x008C, 0x0318, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_UART1_RTS_B__UART1_DCE_RTS(p) PIN_CFG(0x0090, 0x031C, 0x0620, 0x0, 0x3, p)
-#define MX6UL_PAD_UART1_RTS_B__UART1_DTE_CTS(p) PIN_CFG(0x0090, 0x031C, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_UART1_RTS_B__ENET1_TX_ER(p) PIN_CFG(0x0090, 0x031C, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_UART1_RTS_B__USDHC1_CD_B(p) PIN_CFG(0x0090, 0x031C, 0x0668, 0x2, 0x1, p)
-#define MX6UL_PAD_UART1_RTS_B__CSI_DATA05(p) PIN_CFG(0x0090, 0x031C, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_UART1_RTS_B__ENET2_1588_EVENT1_OUT(p) PIN_CFG(0x0090, 0x031C, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_UART1_RTS_B__GPIO1_IO19(p) PIN_CFG(0x0090, 0x031C, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_UART1_RTS_B__USDHC2_CD_B(p) PIN_CFG(0x0090, 0x031C, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_UART2_TX_DATA__UART2_TX(p) PIN_CFG(0x0094, 0x0320, 0x062C, 0x0, 0x0, p)
-#define MX6UL_PAD_UART2_TX_DATA__ENET1_TDATA02(p) PIN_CFG(0x0094, 0x0320, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_UART2_TX_DATA__I2C4_SCL(p) PIN_CFG(0x0094, 0x0320, 0x05BC, 0x2, 0x0, p)
-#define MX6UL_PAD_UART2_TX_DATA__CSI_DATA06(p) PIN_CFG(0x0094, 0x0320, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_UART2_TX_DATA__GPT1_CAPTURE1(p) PIN_CFG(0x0094, 0x0320, 0x058C, 0x4, 0x1, p)
-#define MX6UL_PAD_UART2_TX_DATA__GPIO1_IO20(p) PIN_CFG(0x0094, 0x0320, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_UART2_TX_DATA__ECSPI3_SS0(p) PIN_CFG(0x0094, 0x0320, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_UART2_RX_DATA__UART2_RX(p) PIN_CFG(0x0098, 0x0324, 0x062C, 0x0, 0x1, p)
-#define MX6UL_PAD_UART2_RX_DATA__ENET1_TDATA03(p) PIN_CFG(0x0098, 0x0324, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_UART2_RX_DATA__I2C4_SDA(p) PIN_CFG(0x0098, 0x0324, 0x05C0, 0x2, 0x0, p)
-#define MX6UL_PAD_UART2_RX_DATA__CSI_DATA07(p) PIN_CFG(0x0098, 0x0324, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_UART2_RX_DATA__GPT1_CAPTURE2(p) PIN_CFG(0x0098, 0x0324, 0x0590, 0x4, 0x0, p)
-#define MX6UL_PAD_UART2_RX_DATA__GPIO1_IO21(p) PIN_CFG(0x0098, 0x0324, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_UART2_RX_DATA__SJC_DONE(p) PIN_CFG(0x0098, 0x0324, 0x0000, 0x7, 0x0, p)
-#define MX6UL_PAD_UART2_RX_DATA__ECSPI3_SCLK(p) PIN_CFG(0x0098, 0x0324, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_UART2_CTS_B__UART2_DCE_CTS(p) PIN_CFG(0x009C, 0x0328, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_UART2_CTS_B__UART2_DTE_RTS(p) PIN_CFG(0x009C, 0x0328, 0x0628, 0x0, 0x0, p)
-#define MX6UL_PAD_UART2_CTS_B__ENET1_CRS(p) PIN_CFG(0x009C, 0x0328, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_UART2_CTS_B__FLEXCAN2_TX(p) PIN_CFG(0x009C, 0x0328, 0x0000, 0x12, 0x0, p)
-#define MX6UL_PAD_UART2_CTS_B__CSI_DATA08(p) PIN_CFG(0x009C, 0x0328, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_UART2_CTS_B__GPT1_COMPARE2(p) PIN_CFG(0x009C, 0x0328, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_UART2_CTS_B__GPIO1_IO22(p) PIN_CFG(0x009C, 0x0328, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_UART2_CTS_B__SJC_DE_B(p) PIN_CFG(0x009C, 0x0328, 0x0000, 0x7, 0x0, p)
-#define MX6UL_PAD_UART2_CTS_B__ECSPI3_MOSI(p) PIN_CFG(0x009C, 0x0328, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_UART2_RTS_B__UART2_DCE_RTS(p) PIN_CFG(0x00A0, 0x032C, 0x0628, 0x0, 0x1, p)
-#define MX6UL_PAD_UART2_RTS_B__UART2_DTE_CTS(p) PIN_CFG(0x00A0, 0x032C, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_UART2_RTS_B__ENET1_COL(p) PIN_CFG(0x00A0, 0x032C, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_UART2_RTS_B__FLEXCAN2_RX(p) PIN_CFG(0x00A0, 0x032C, 0x0588, 0x12, 0x0, p)
-#define MX6UL_PAD_UART2_RTS_B__CSI_DATA09(p) PIN_CFG(0x00A0, 0x032C, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_UART2_RTS_B__GPT1_COMPARE3(p) PIN_CFG(0x00A0, 0x032C, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_UART2_RTS_B__GPIO1_IO23(p) PIN_CFG(0x00A0, 0x032C, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_UART2_RTS_B__SJC_FAIL(p) PIN_CFG(0x00A0, 0x032C, 0x0000, 0x7, 0x0, p)
-#define MX6UL_PAD_UART2_RTS_B__ECSPI3_MISO(p) PIN_CFG(0x00A0, 0x032C, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_UART3_TX_DATA__UART3_TX(p) PIN_CFG(0x00A4, 0x0330, 0x0634, 0x0, 0x0, p)
-#define MX6UL_PAD_UART3_TX_DATA__ENET2_RDATA02(p) PIN_CFG(0x00A4, 0x0330, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_UART3_TX_DATA__SIM1_PORT0_PD(p) PIN_CFG(0x00A4, 0x0330, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_UART3_TX_DATA__CSI_DATA01(p) PIN_CFG(0x00A4, 0x0330, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_UART3_TX_DATA__UART2_DCE_CTS(p) PIN_CFG(0x00A4, 0x0330, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_UART3_TX_DATA__UART2_DTE_RTS(p) PIN_CFG(0x00A4, 0x0330, 0x0628, 0x4, 0x2, p)
-#define MX6UL_PAD_UART3_TX_DATA__GPIO1_IO24(p) PIN_CFG(0x00A4, 0x0330, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_UART3_TX_DATA__SJC_JTAG_ACT(p) PIN_CFG(0x00A4, 0x0330, 0x0000, 0x7, 0x0, p)
-#define MX6UL_PAD_UART3_TX_DATA__ANATOP_OTG1_ID(p) PIN_CFG(0x00A4, 0x0330, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_UART3_RX_DATA__UART3_RX(p) PIN_CFG(0x00A8, 0x0334, 0x0634, 0x0, 0x1, p)
-#define MX6UL_PAD_UART3_RX_DATA__ENET2_RDATA03(p) PIN_CFG(0x00A8, 0x0334, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_UART3_RX_DATA__SIM2_PORT0_PD(p) PIN_CFG(0x00A8, 0x0334, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_UART3_RX_DATA__CSI_DATA00(p) PIN_CFG(0x00A8, 0x0334, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_UART3_RX_DATA__UART2_DCE_RTS(p) PIN_CFG(0x00A8, 0x0334, 0x0628, 0x4, 0x3, p)
-#define MX6UL_PAD_UART3_RX_DATA__UART2_DTE_CTS(p) PIN_CFG(0x00A8, 0x0334, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_UART3_RX_DATA__GPIO1_IO25(p) PIN_CFG(0x00A8, 0x0334, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_UART3_RX_DATA__EPIT1_OUT(p) PIN_CFG(0x00A8, 0x0334, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_UART3_CTS_B__UART3_DCE_CTS(p) PIN_CFG(0x00AC, 0x0338, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_UART3_CTS_B__UART3_DTE_RTS(p) PIN_CFG(0x00AC, 0x0338, 0x0630, 0x0, 0x0, p)
-#define MX6UL_PAD_UART3_CTS_B__ENET2_RX_CLK(p) PIN_CFG(0x00AC, 0x0338, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_UART3_CTS_B__FLEXCAN1_TX(p) PIN_CFG(0x00AC, 0x0338, 0x0000, 0x12, 0x0, p)
-#define MX6UL_PAD_UART3_CTS_B__CSI_DATA10(p) PIN_CFG(0x00AC, 0x0338, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_UART3_CTS_B__ENET1_1588_EVENT1_IN(p) PIN_CFG(0x00AC, 0x0338, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_UART3_CTS_B__GPIO1_IO26(p) PIN_CFG(0x00AC, 0x0338, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_UART3_CTS_B__EPIT2_OUT(p) PIN_CFG(0x00AC, 0x0338, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_UART3_RTS_B__UART3_DCE_RTS(p) PIN_CFG(0x00B0, 0x033C, 0x0630, 0x0, 0x1, p)
-#define MX6UL_PAD_UART3_RTS_B__UART3_DTE_CTS(p) PIN_CFG(0x00B0, 0x033C, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_UART3_RTS_B__ENET2_TX_ER(p) PIN_CFG(0x00B0, 0x033C, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_UART3_RTS_B__FLEXCAN1_RX(p) PIN_CFG(0x00B0, 0x033C, 0x0584, 0x12, 0x0, p)
-#define MX6UL_PAD_UART3_RTS_B__CSI_DATA11(p) PIN_CFG(0x00B0, 0x033C, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_UART3_RTS_B__ENET1_1588_EVENT1_OUT(p) PIN_CFG(0x00B0, 0x033C, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_UART3_RTS_B__GPIO1_IO27(p) PIN_CFG(0x00B0, 0x033C, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_UART3_RTS_B__WDOG1_WDOG_B(p) PIN_CFG(0x00B0, 0x033C, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_UART4_TX_DATA__UART4_TX(p) PIN_CFG(0x00B4, 0x0340, 0x063C, 0x0, 0x0, p)
-#define MX6UL_PAD_UART4_TX_DATA__ENET2_TDATA02(p) PIN_CFG(0x00B4, 0x0340, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_UART4_TX_DATA__I2C1_SCL(p) PIN_CFG(0x00B4, 0x0340, 0x05A4, 0x12, 0x1, p)
-#define MX6UL_PAD_UART4_TX_DATA__CSI_DATA12(p) PIN_CFG(0x00B4, 0x0340, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_UART4_TX_DATA__CSU_CSU_ALARM_AUT02(p) PIN_CFG(0x00B4, 0x0340, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_UART4_TX_DATA__GPIO1_IO28(p) PIN_CFG(0x00B4, 0x0340, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_UART4_TX_DATA__ECSPI2_SCLK(p) PIN_CFG(0x00B4, 0x0340, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_UART4_RX_DATA__UART4_RX(p) PIN_CFG(0x00B8, 0x0344, 0x063C, 0x0, 0x1, p)
-#define MX6UL_PAD_UART4_RX_DATA__ENET2_TDATA03(p) PIN_CFG(0x00B8, 0x0344, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_UART4_RX_DATA__I2C1_SDA(p) PIN_CFG(0x00B8, 0x0344, 0x05A8, 0x12, 0x2, p)
-#define MX6UL_PAD_UART4_RX_DATA__CSI_DATA13(p) PIN_CFG(0x00B8, 0x0344, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_UART4_RX_DATA__CSU_CSU_ALARM_AUT01(p) PIN_CFG(0x00B8, 0x0344, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_UART4_RX_DATA__GPIO1_IO29(p) PIN_CFG(0x00B8, 0x0344, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_UART4_RX_DATA__ECSPI2_SS0(p) PIN_CFG(0x00B8, 0x0344, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_UART5_TX_DATA__GPIO1_IO30(p) PIN_CFG(0x00BC, 0x0348, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_UART5_TX_DATA__ECSPI2_MOSI(p) PIN_CFG(0x00BC, 0x0348, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_UART5_TX_DATA__UART5_TX(p) PIN_CFG(0x00BC, 0x0348, 0x0644, 0x0, 0x4, p)
-#define MX6UL_PAD_UART5_TX_DATA__ENET2_CRS(p) PIN_CFG(0x00BC, 0x0348, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_UART5_TX_DATA__I2C2_SCL(p) PIN_CFG(0x00BC, 0x0348, 0x05AC, 0x12, 0x2, p)
-#define MX6UL_PAD_UART5_TX_DATA__CSI_DATA14(p) PIN_CFG(0x00BC, 0x0348, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_UART5_TX_DATA__CSU_CSU_ALARM_AUT00(p) PIN_CFG(0x00BC, 0x0348, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_UART5_RX_DATA__UART5_RX(p) PIN_CFG(0x00C0, 0x034C, 0x0644, 0x0, 0x5, p)
-#define MX6UL_PAD_UART5_RX_DATA__ENET2_COL(p) PIN_CFG(0x00C0, 0x034C, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_UART5_RX_DATA__I2C2_SDA(p) PIN_CFG(0x00C0, 0x034C, 0x05B0, 0x12, 0x2, p)
-#define MX6UL_PAD_UART5_RX_DATA__CSI_DATA15(p) PIN_CFG(0x00C0, 0x034C, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_UART5_RX_DATA__CSU_CSU_INT_DEB(p) PIN_CFG(0x00C0, 0x034C, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_UART5_RX_DATA__GPIO1_IO31(p) PIN_CFG(0x00C0, 0x034C, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_UART5_RX_DATA__ECSPI2_MISO(p) PIN_CFG(0x00C0, 0x034C, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_DATA0__ENET1_RDATA00(p) PIN_CFG(0x00C4, 0x0350, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_DATA0__UART4_DCE_RTS(p) PIN_CFG(0x00C4, 0x0350, 0x0638, 0x1, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_DATA0__UART4_DTE_CTS(p) PIN_CFG(0x00C4, 0x0350, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_DATA0__PWM1_OUT(p) PIN_CFG(0x00C4, 0x0350, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_DATA0__CSI_DATA16(p) PIN_CFG(0x00C4, 0x0350, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_DATA0__FLEXCAN1_TX(p) PIN_CFG(0x00C4, 0x0350, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_DATA0__GPIO2_IO00(p) PIN_CFG(0x00C4, 0x0350, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_DATA0__KPP_ROW00(p) PIN_CFG(0x00C4, 0x0350, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_DATA0__USDHC1_LCTL(p) PIN_CFG(0x00C4, 0x0350, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_DATA1__ENET1_RDATA01(p) PIN_CFG(0x00C8, 0x0354, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_DATA1__UART4_DCE_CTS(p) PIN_CFG(0x00C8, 0x0354, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_DATA1__UART4_DTE_RTS(p) PIN_CFG(0x00C8, 0x0354, 0x0638, 0x1, 0x1, p)
-#define MX6UL_PAD_ENET1_RX_DATA1__PWM2_OUT(p) PIN_CFG(0x00C8, 0x0354, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_DATA1__CSI_DATA17(p) PIN_CFG(0x00C8, 0x0354, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_DATA1__FLEXCAN1_RX(p) PIN_CFG(0x00C8, 0x0354, 0x0584, 0x4, 0x1, p)
-#define MX6UL_PAD_ENET1_RX_DATA1__GPIO2_IO01(p) PIN_CFG(0x00C8, 0x0354, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_DATA1__KPP_COL00(p) PIN_CFG(0x00C8, 0x0354, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_DATA1__USDHC2_LCTL(p) PIN_CFG(0x00C8, 0x0354, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_EN__ENET1_RX_EN(p) PIN_CFG(0x00CC, 0x0358, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_EN__UART5_DCE_RTS(p) PIN_CFG(0x00CC, 0x0358, 0x0640, 0x1, 0x3, p)
-#define MX6UL_PAD_ENET1_RX_EN__UART5_DTE_CTS(p) PIN_CFG(0x00CC, 0x0358, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_EN__CSI_DATA18(p) PIN_CFG(0x00CC, 0x0358, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_EN__FLEXCAN2_TX(p) PIN_CFG(0x00CC, 0x0358, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_EN__GPIO2_IO02(p) PIN_CFG(0x00CC, 0x0358, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_EN__KPP_ROW01(p) PIN_CFG(0x00CC, 0x0358, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_EN__USDHC1_VSELECT(p) PIN_CFG(0x00CC, 0x0358, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_DATA0__ENET1_TDATA00(p) PIN_CFG(0x00D0, 0x035C, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_DATA0__UART5_DCE_CTS(p) PIN_CFG(0x00D0, 0x035C, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_DATA0__UART5_DTE_RTS(p) PIN_CFG(0x00D0, 0x035C, 0x0640, 0x1, 0x4, p)
-#define MX6UL_PAD_ENET1_TX_DATA0__CSI_DATA19(p) PIN_CFG(0x00D0, 0x035C, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_DATA0__FLEXCAN2_RX(p) PIN_CFG(0x00D0, 0x035C, 0x0588, 0x4, 0x1, p)
-#define MX6UL_PAD_ENET1_TX_DATA0__GPIO2_IO03(p) PIN_CFG(0x00D0, 0x035C, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_DATA0__KPP_COL01(p) PIN_CFG(0x00D0, 0x035C, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_DATA0__USDHC2_VSELECT(p) PIN_CFG(0x00D0, 0x035C, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_DATA1__ENET1_TDATA01(p) PIN_CFG(0x00D4, 0x0360, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_DATA1__UART6_DCE_CTS(p) PIN_CFG(0x00D4, 0x0360, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_DATA1__UART6_DTE_RTS(p) PIN_CFG(0x00D4, 0x0360, 0x0648, 0x1, 0x2, p)
-#define MX6UL_PAD_ENET1_TX_DATA1__PWM5_OUT(p) PIN_CFG(0x00D4, 0x0360, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_DATA1__CSI_DATA20(p) PIN_CFG(0x00D4, 0x0360, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_DATA1__ENET2_MDIO(p) PIN_CFG(0x00D4, 0x0360, 0x0580, 0x4, 0x1, p)
-#define MX6UL_PAD_ENET1_TX_DATA1__GPIO2_IO04(p) PIN_CFG(0x00D4, 0x0360, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_DATA1__KPP_ROW02(p) PIN_CFG(0x00D4, 0x0360, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_DATA1__WDOG1_WDOG_RST_B_DEB(p) PIN_CFG(0x00D4, 0x0360, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_EN__ENET1_TX_EN(p) PIN_CFG(0x00D8, 0x0364, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_EN__UART6_DCE_RTS(p) PIN_CFG(0x00D8, 0x0364, 0x0648, 0x1, 0x3, p)
-#define MX6UL_PAD_ENET1_TX_EN__UART6_DTE_CTS(p) PIN_CFG(0x00D8, 0x0364, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_EN__PWM6_OUT(p) PIN_CFG(0x00D8, 0x0364, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_EN__CSI_DATA21(p) PIN_CFG(0x00D8, 0x0364, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_EN__ENET2_MDC(p) PIN_CFG(0x00D8, 0x0364, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_EN__GPIO2_IO05(p) PIN_CFG(0x00D8, 0x0364, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_EN__KPP_COL02(p) PIN_CFG(0x00D8, 0x0364, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_EN__WDOG2_WDOG_RST_B_DEB(p) PIN_CFG(0x00D8, 0x0364, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_CLK__ENET1_TX_CLK(p) PIN_CFG(0x00DC, 0x0368, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_CLK__UART7_DCE_CTS(p) PIN_CFG(0x00DC, 0x0368, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_CLK__UART7_DTE_RTS(p) PIN_CFG(0x00DC, 0x0368, 0x0650, 0x1, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_CLK__PWM7_OUT(p) PIN_CFG(0x00DC, 0x0368, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_CLK__CSI_DATA22(p) PIN_CFG(0x00DC, 0x0368, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_CLK__ENET1_REF_CLK1(p) PIN_CFG(0x00DC, 0x0368, 0x0574, 0x14, 0x2, p)
-#define MX6UL_PAD_ENET1_TX_CLK__GPIO2_IO06(p) PIN_CFG(0x00DC, 0x0368, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_CLK__KPP_ROW03(p) PIN_CFG(0x00DC, 0x0368, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_ENET1_TX_CLK__GPT1_CLK(p) PIN_CFG(0x00DC, 0x0368, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_ER__ENET1_RX_ER(p) PIN_CFG(0x00E0, 0x036C, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_ER__UART7_DCE_RTS(p) PIN_CFG(0x00E0, 0x036C, 0x0650, 0x1, 0x1, p)
-#define MX6UL_PAD_ENET1_RX_ER__UART7_DTE_CTS(p) PIN_CFG(0x00E0, 0x036C, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_ER__PWM8_OUT(p) PIN_CFG(0x00E0, 0x036C, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_ER__CSI_DATA23(p) PIN_CFG(0x00E0, 0x036C, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_ER__EIM_CRE(p) PIN_CFG(0x00E0, 0x036C, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_ER__GPIO2_IO07(p) PIN_CFG(0x00E0, 0x036C, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_ER__KPP_COL03(p) PIN_CFG(0x00E0, 0x036C, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_ENET1_RX_ER__GPT1_CAPTURE2(p) PIN_CFG(0x00E0, 0x036C, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_DATA0__ENET2_RDATA00(p) PIN_CFG(0x00E4, 0x0370, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_DATA0__UART6_TX(p) PIN_CFG(0x00E4, 0x0370, 0x064C, 0x1, 0x1, p)
-#define MX6UL_PAD_ENET2_RX_DATA0__SIM1_PORT0_TRXD(p) PIN_CFG(0x00E4, 0x0370, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_DATA0__I2C3_SCL(p) PIN_CFG(0x00E4, 0x0370, 0x05B4, 0x3, 0x1, p)
-#define MX6UL_PAD_ENET2_RX_DATA0__ENET1_MDIO(p) PIN_CFG(0x00E4, 0x0370, 0x0578, 0x4, 0x1, p)
-#define MX6UL_PAD_ENET2_RX_DATA0__GPIO2_IO08(p) PIN_CFG(0x00E4, 0x0370, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_DATA0__KPP_ROW04(p) PIN_CFG(0x00E4, 0x0370, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_DATA0__USB_OTG1_PWR(p) PIN_CFG(0x00E4, 0x0370, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_DATA1__ENET2_RDATA01(p) PIN_CFG(0x00E8, 0x0374, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_DATA1__UART6_RX(p) PIN_CFG(0x00E8, 0x0374, 0x064C, 0x1, 0x2, p)
-#define MX6UL_PAD_ENET2_RX_DATA1__SIM1_PORT0_CLK(p) PIN_CFG(0x00E8, 0x0374, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_DATA1__I2C3_SDA(p) PIN_CFG(0x00E8, 0x0374, 0x05B8, 0x3, 0x1, p)
-#define MX6UL_PAD_ENET2_RX_DATA1__ENET1_MDC(p) PIN_CFG(0x00E8, 0x0374, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_DATA1__GPIO2_IO09(p) PIN_CFG(0x00E8, 0x0374, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_DATA1__KPP_COL04(p) PIN_CFG(0x00E8, 0x0374, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_DATA1__USB_OTG1_OC(p) PIN_CFG(0x00E8, 0x0374, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_EN__ENET2_RX_EN(p) PIN_CFG(0x00EC, 0x0378, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_EN__UART7_TX(p) PIN_CFG(0x00EC, 0x0378, 0x0654, 0x1, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_EN__SIM1_PORT0_RST_B(p) PIN_CFG(0x00EC, 0x0378, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_EN__I2C4_SCL(p) PIN_CFG(0x00EC, 0x0378, 0x05BC, 0x3, 0x1, p)
-#define MX6UL_PAD_ENET2_RX_EN__EIM_ADDR26(p) PIN_CFG(0x00EC, 0x0378, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_EN__GPIO2_IO10(p) PIN_CFG(0x00EC, 0x0378, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_EN__KPP_ROW05(p) PIN_CFG(0x00EC, 0x0378, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_EN__ENET1_REF_CLK_25M(p) PIN_CFG(0x00EC, 0x0378, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_DATA0__ENET2_TDATA00(p) PIN_CFG(0x00F0, 0x037C, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_DATA0__UART7_RX(p) PIN_CFG(0x00F0, 0x037C, 0x0654, 0x1, 0x1, p)
-#define MX6UL_PAD_ENET2_TX_DATA0__SIM1_PORT0_SVEN(p) PIN_CFG(0x00F0, 0x037C, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_DATA0__I2C4_SDA(p) PIN_CFG(0x00F0, 0x037C, 0x05C0, 0x3, 0x1, p)
-#define MX6UL_PAD_ENET2_TX_DATA0__EIM_EB_B02(p) PIN_CFG(0x00F0, 0x037C, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_DATA0__GPIO2_IO11(p) PIN_CFG(0x00F0, 0x037C, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_DATA0__KPP_COL05(p) PIN_CFG(0x00F0, 0x037C, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_DATA1__ENET2_TDATA01(p) PIN_CFG(0x00F4, 0x0380, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_DATA1__UART8_TX(p) PIN_CFG(0x00F4, 0x0380, 0x065C, 0x1, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_DATA1__SIM2_PORT0_TRXD(p) PIN_CFG(0x00F4, 0x0380, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_DATA1__ECSPI4_SCLK(p) PIN_CFG(0x00F4, 0x0380, 0x0564, 0x3, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_DATA1__EIM_EB_B03(p) PIN_CFG(0x00F4, 0x0380, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_DATA1__GPIO2_IO12(p) PIN_CFG(0x00F4, 0x0380, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_DATA1__KPP_ROW06(p) PIN_CFG(0x00F4, 0x0380, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_DATA1__USB_OTG2_PWR(p) PIN_CFG(0x00F4, 0x0380, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_EN__ENET2_TX_EN(p) PIN_CFG(0x00F8, 0x0384, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_EN__UART8_RX(p) PIN_CFG(0x00F8, 0x0384, 0x065C, 0x1, 0x1, p)
-#define MX6UL_PAD_ENET2_TX_EN__SIM2_PORT0_CLK(p) PIN_CFG(0x00F8, 0x0384, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_EN__ECSPI4_MOSI(p) PIN_CFG(0x00F8, 0x0384, 0x056C, 0x3, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_EN__EIM_ACLK_FREERUN(p) PIN_CFG(0x00F8, 0x0384, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_EN__GPIO2_IO13(p) PIN_CFG(0x00F8, 0x0384, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_EN__KPP_COL06(p) PIN_CFG(0x00F8, 0x0384, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_EN__USB_OTG2_OC(p) PIN_CFG(0x00F8, 0x0384, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_CLK__ENET2_TX_CLK(p) PIN_CFG(0x00FC, 0x0388, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_CLK__UART8_DCE_CTS(p) PIN_CFG(0x00FC, 0x0388, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_CLK__UART8_DTE_RTS(p) PIN_CFG(0x00FC, 0x0388, 0x0658, 0x1, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_CLK__SIM2_PORT0_RST_B(p) PIN_CFG(0x00FC, 0x0388, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_CLK__ECSPI4_MISO(p) PIN_CFG(0x00FC, 0x0388, 0x0568, 0x3, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_CLK__ENET2_REF_CLK2(p) PIN_CFG(0x00FC, 0x0388, 0x057C, 0x14, 0x2, p)
-#define MX6UL_PAD_ENET2_TX_CLK__GPIO2_IO14(p) PIN_CFG(0x00FC, 0x0388, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_CLK__KPP_ROW07(p) PIN_CFG(0x00FC, 0x0388, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_ENET2_TX_CLK__ANATOP_OTG2_ID(p) PIN_CFG(0x00FC, 0x0388, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_ER__ENET2_RX_ER(p) PIN_CFG(0x0100, 0x038C, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_ER__UART8_DCE_RTS(p) PIN_CFG(0x0100, 0x038C, 0x0658, 0x1, 0x1, p)
-#define MX6UL_PAD_ENET2_RX_ER__UART8_DTE_CTS(p) PIN_CFG(0x0100, 0x038C, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_ER__SIM2_PORT0_SVEN(p) PIN_CFG(0x0100, 0x038C, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_ER__ECSPI4_SS0(p) PIN_CFG(0x0100, 0x038C, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_ER__EIM_ADDR25(p) PIN_CFG(0x0100, 0x038C, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_ER__GPIO2_IO15(p) PIN_CFG(0x0100, 0x038C, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_ER__KPP_COL07(p) PIN_CFG(0x0100, 0x038C, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_ENET2_RX_ER__WDOG1_WDOG_ANY(p) PIN_CFG(0x0100, 0x038C, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_CLK__LCDIF_CLK(p) PIN_CFG(0x0104, 0x0390, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_CLK__LCDIF_WR_RWN(p) PIN_CFG(0x0104, 0x0390, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_LCD_CLK__UART4_TX(p) PIN_CFG(0x0104, 0x0390, 0x063C, 0x2, 0x2, p)
-#define MX6UL_PAD_LCD_CLK__SAI3_MCLK(p) PIN_CFG(0x0104, 0x0390, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_CLK__EIM_CS2_B(p) PIN_CFG(0x0104, 0x0390, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_LCD_CLK__GPIO3_IO00(p) PIN_CFG(0x0104, 0x0390, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_CLK__WDOG1_WDOG_RST_B_DEB(p) PIN_CFG(0x0104, 0x0390, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_ENABLE__LCDIF_ENABLE(p) PIN_CFG(0x0108, 0x0394, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_ENABLE__LCDIF_RD_E(p) PIN_CFG(0x0108, 0x0394, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_LCD_ENABLE__UART4_RX(p) PIN_CFG(0x0108, 0x0394, 0x063C, 0x2, 0x3, p)
-#define MX6UL_PAD_LCD_ENABLE__SAI3_TX_SYNC(p) PIN_CFG(0x0108, 0x0394, 0x060C, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_ENABLE__EIM_CS3_B(p) PIN_CFG(0x0108, 0x0394, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_LCD_ENABLE__GPIO3_IO01(p) PIN_CFG(0x0108, 0x0394, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_ENABLE__ECSPI2_RDY(p) PIN_CFG(0x0108, 0x0394, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_HSYNC__LCDIF_HSYNC(p) PIN_CFG(0x010C, 0x0398, 0x05DC, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_HSYNC__LCDIF_RS(p) PIN_CFG(0x010C, 0x0398, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_LCD_HSYNC__UART4_DCE_CTS(p) PIN_CFG(0x010C, 0x0398, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_LCD_HSYNC__UART4_DTE_RTS(p) PIN_CFG(0x010C, 0x0398, 0x0638, 0x2, 0x2, p)
-#define MX6UL_PAD_LCD_HSYNC__SAI3_TX_BCLK(p) PIN_CFG(0x010C, 0x0398, 0x0608, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_HSYNC__WDOG3_WDOG_RST_B_DEB(p) PIN_CFG(0x010C, 0x0398, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_LCD_HSYNC__GPIO3_IO02(p) PIN_CFG(0x010C, 0x0398, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_HSYNC__ECSPI2_SS1(p) PIN_CFG(0x010C, 0x0398, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_VSYNC__LCDIF_VSYNC(p) PIN_CFG(0x0110, 0x039C, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_VSYNC__LCDIF_BUSY(p) PIN_CFG(0x0110, 0x039C, 0x05DC, 0x1, 0x1, p)
-#define MX6UL_PAD_LCD_VSYNC__UART4_DCE_RTS(p) PIN_CFG(0x0110, 0x039C, 0x0638, 0x2, 0x3, p)
-#define MX6UL_PAD_LCD_VSYNC__UART4_DTE_CTS(p) PIN_CFG(0x0110, 0x039C, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_LCD_VSYNC__SAI3_RX_DATA(p) PIN_CFG(0x0110, 0x039C, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_VSYNC__WDOG2_WDOG_B(p) PIN_CFG(0x0110, 0x039C, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_LCD_VSYNC__GPIO3_IO03(p) PIN_CFG(0x0110, 0x039C, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_VSYNC__ECSPI2_SS2(p) PIN_CFG(0x0110, 0x039C, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_RESET__LCDIF_RESET(p) PIN_CFG(0x0114, 0x03A0, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_RESET__LCDIF_CS(p) PIN_CFG(0x0114, 0x03A0, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_LCD_RESET__CA7_MX6UL_EVENTI(p) PIN_CFG(0x0114, 0x03A0, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_LCD_RESET__SAI3_TX_DATA(p) PIN_CFG(0x0114, 0x03A0, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_RESET__WDOG1_WDOG_ANY(p) PIN_CFG(0x0114, 0x03A0, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_LCD_RESET__GPIO3_IO04(p) PIN_CFG(0x0114, 0x03A0, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_RESET__ECSPI2_SS3(p) PIN_CFG(0x0114, 0x03A0, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_DATA00__LCDIF_DATA00(p) PIN_CFG(0x0118, 0x03A4, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_DATA00__PWM1_OUT(p) PIN_CFG(0x0118, 0x03A4, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_LCD_DATA00__ENET1_1588_EVENT2_IN(p) PIN_CFG(0x0118, 0x03A4, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_DATA00__I2C3_SDA(p) PIN_CFG(0x0118, 0x03A4, 0x05B8, 0x4, 0x2, p)
-#define MX6UL_PAD_LCD_DATA00__GPIO3_IO05(p) PIN_CFG(0x0118, 0x03A4, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_DATA00__SRC_BT_CFG00(p) PIN_CFG(0x0118, 0x03A4, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_LCD_DATA00__SAI1_MCLK(p) PIN_CFG(0x0118, 0x03A4, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_DATA01__LCDIF_DATA01(p) PIN_CFG(0x011C, 0x03A8, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_DATA01__PWM2_OUT(p) PIN_CFG(0x011C, 0x03A8, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_LCD_DATA01__ENET1_1588_EVENT2_OUT(p) PIN_CFG(0x011C, 0x03A8, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_DATA01__I2C3_SCL(p) PIN_CFG(0x011C, 0x03A8, 0x05B4, 0x4, 0x2, p)
-#define MX6UL_PAD_LCD_DATA01__GPIO3_IO06(p) PIN_CFG(0x011C, 0x03A8, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_DATA01__SRC_BT_CFG01(p) PIN_CFG(0x011C, 0x03A8, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_LCD_DATA01__SAI1_TX_SYNC(p) PIN_CFG(0x011C, 0x03A8, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_DATA02__LCDIF_DATA02(p) PIN_CFG(0x0120, 0x03AC, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_DATA02__PWM3_OUT(p) PIN_CFG(0x0120, 0x03AC, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_LCD_DATA02__ENET1_1588_EVENT3_IN(p) PIN_CFG(0x0120, 0x03AC, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_DATA02__I2C4_SDA(p) PIN_CFG(0x0120, 0x03AC, 0x05C0, 0x4, 0x2, p)
-#define MX6UL_PAD_LCD_DATA02__GPIO3_IO07(p) PIN_CFG(0x0120, 0x03AC, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_DATA02__SRC_BT_CFG02(p) PIN_CFG(0x0120, 0x03AC, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_LCD_DATA02__SAI1_TX_BCLK(p) PIN_CFG(0x0120, 0x03AC, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_DATA03__LCDIF_DATA03(p) PIN_CFG(0x0124, 0x03B0, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_DATA03__PWM4_OUT(p) PIN_CFG(0x0124, 0x03B0, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_LCD_DATA03__ENET1_1588_EVENT3_OUT(p) PIN_CFG(0x0124, 0x03B0, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_DATA03__I2C4_SCL(p) PIN_CFG(0x0124, 0x03B0, 0x05BC, 0x4, 0x2, p)
-#define MX6UL_PAD_LCD_DATA03__GPIO3_IO08(p) PIN_CFG(0x0124, 0x03B0, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_DATA03__SRC_BT_CFG03(p) PIN_CFG(0x0124, 0x03B0, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_LCD_DATA03__SAI1_RX_DATA(p) PIN_CFG(0x0124, 0x03B0, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_DATA04__LCDIF_DATA04(p) PIN_CFG(0x0128, 0x03B4, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_DATA04__UART8_DCE_CTS(p) PIN_CFG(0x0128, 0x03B4, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_LCD_DATA04__UART8_DTE_RTS(p) PIN_CFG(0x0128, 0x03B4, 0x0658, 0x1, 0x2, p)
-#define MX6UL_PAD_LCD_DATA04__ENET2_1588_EVENT2_IN(p) PIN_CFG(0x0128, 0x03B4, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_DATA04__SPDIF_SR_CLK(p) PIN_CFG(0x0128, 0x03B4, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_LCD_DATA04__GPIO3_IO09(p) PIN_CFG(0x0128, 0x03B4, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_DATA04__SRC_BT_CFG04(p) PIN_CFG(0x0128, 0x03B4, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_LCD_DATA04__SAI1_TX_DATA(p) PIN_CFG(0x0128, 0x03B4, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_DATA05__LCDIF_DATA05(p) PIN_CFG(0x012C, 0x03B8, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_DATA05__UART8_DCE_RTS(p) PIN_CFG(0x012C, 0x03B8, 0x0658, 0x1, 0x3, p)
-#define MX6UL_PAD_LCD_DATA05__UART8_DTE_CTS(p) PIN_CFG(0x012C, 0x03B8, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_LCD_DATA05__ENET2_1588_EVENT2_OUT(p) PIN_CFG(0x012C, 0x03B8, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_DATA05__SPDIF_OUT(p) PIN_CFG(0x012C, 0x03B8, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_LCD_DATA05__GPIO3_IO10(p) PIN_CFG(0x012C, 0x03B8, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_DATA05__SRC_BT_CFG05(p) PIN_CFG(0x012C, 0x03B8, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_LCD_DATA05__ECSPI1_SS1(p) PIN_CFG(0x012C, 0x03B8, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_DATA06__LCDIF_DATA06(p) PIN_CFG(0x0130, 0x03BC, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_DATA06__UART7_DCE_CTS(p) PIN_CFG(0x0130, 0x03BC, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_LCD_DATA06__UART7_DTE_RTS(p) PIN_CFG(0x0130, 0x03BC, 0x0650, 0x1, 0x2, p)
-#define MX6UL_PAD_LCD_DATA06__ENET2_1588_EVENT3_IN(p) PIN_CFG(0x0130, 0x03BC, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_DATA06__SPDIF_LOCK(p) PIN_CFG(0x0130, 0x03BC, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_LCD_DATA06__GPIO3_IO11(p) PIN_CFG(0x0130, 0x03BC, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_DATA06__SRC_BT_CFG06(p) PIN_CFG(0x0130, 0x03BC, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_LCD_DATA06__ECSPI1_SS2(p) PIN_CFG(0x0130, 0x03BC, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_DATA07__LCDIF_DATA07(p) PIN_CFG(0x0134, 0x03C0, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_DATA07__UART7_DCE_RTS(p) PIN_CFG(0x0134, 0x03C0, 0x0650, 0x1, 0x3, p)
-#define MX6UL_PAD_LCD_DATA07__UART7_DTE_CTS(p) PIN_CFG(0x0134, 0x03C0, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_LCD_DATA07__ENET2_1588_EVENT3_OUT(p) PIN_CFG(0x0134, 0x03C0, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_DATA07__SPDIF_EXT_CLK(p) PIN_CFG(0x0134, 0x03C0, 0x061C, 0x4, 0x0, p)
-#define MX6UL_PAD_LCD_DATA07__GPIO3_IO12(p) PIN_CFG(0x0134, 0x03C0, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_DATA07__SRC_BT_CFG07(p) PIN_CFG(0x0134, 0x03C0, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_LCD_DATA07__ECSPI1_SS3(p) PIN_CFG(0x0134, 0x03C0, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_DATA08__LCDIF_DATA08(p) PIN_CFG(0x0138, 0x03C4, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_DATA08__SPDIF_IN(p) PIN_CFG(0x0138, 0x03C4, 0x0618, 0x1, 0x2, p)
-#define MX6UL_PAD_LCD_DATA08__CSI_DATA16(p) PIN_CFG(0x0138, 0x03C4, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_DATA08__EIM_DATA00(p) PIN_CFG(0x0138, 0x03C4, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_LCD_DATA08__GPIO3_IO13(p) PIN_CFG(0x0138, 0x03C4, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_DATA08__SRC_BT_CFG08(p) PIN_CFG(0x0138, 0x03C4, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_LCD_DATA08__FLEXCAN1_TX(p) PIN_CFG(0x0138, 0x03C4, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_DATA09__LCDIF_DATA09(p) PIN_CFG(0x013C, 0x03C8, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_DATA09__SAI3_MCLK(p) PIN_CFG(0x013C, 0x03C8, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_LCD_DATA09__CSI_DATA17(p) PIN_CFG(0x013C, 0x03C8, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_DATA09__EIM_DATA01(p) PIN_CFG(0x013C, 0x03C8, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_LCD_DATA09__GPIO3_IO14(p) PIN_CFG(0x013C, 0x03C8, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_DATA09__SRC_BT_CFG09(p) PIN_CFG(0x013C, 0x03C8, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_LCD_DATA09__FLEXCAN1_RX(p) PIN_CFG(0x013C, 0x03C8, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_DATA10__LCDIF_DATA10(p) PIN_CFG(0x0140, 0x03CC, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_DATA10__SAI3_RX_SYNC(p) PIN_CFG(0x0140, 0x03CC, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_LCD_DATA10__CSI_DATA18(p) PIN_CFG(0x0140, 0x03CC, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_DATA10__EIM_DATA02(p) PIN_CFG(0x0140, 0x03CC, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_LCD_DATA10__GPIO3_IO15(p) PIN_CFG(0x0140, 0x03CC, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_DATA10__SRC_BT_CFG10(p) PIN_CFG(0x0140, 0x03CC, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_LCD_DATA10__FLEXCAN2_TX(p) PIN_CFG(0x0140, 0x03CC, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_DATA11__LCDIF_DATA11(p) PIN_CFG(0x0144, 0x03D0, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_DATA11__SAI3_RX_BCLK(p) PIN_CFG(0x0144, 0x03D0, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_LCD_DATA11__CSI_DATA19(p) PIN_CFG(0x0144, 0x03D0, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_DATA11__EIM_DATA03(p) PIN_CFG(0x0144, 0x03D0, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_LCD_DATA11__GPIO3_IO16(p) PIN_CFG(0x0144, 0x03D0, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_DATA11__SRC_BT_CFG11(p) PIN_CFG(0x0144, 0x03D0, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_LCD_DATA11__FLEXCAN2_RX(p) PIN_CFG(0x0144, 0x03D0, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_DATA12__LCDIF_DATA12(p) PIN_CFG(0x0148, 0x03D4, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_DATA12__SAI3_TX_SYNC(p) PIN_CFG(0x0148, 0x03D4, 0x060C, 0x1, 0x1, p)
-#define MX6UL_PAD_LCD_DATA12__CSI_DATA20(p) PIN_CFG(0x0148, 0x03D4, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_DATA12__EIM_DATA04(p) PIN_CFG(0x0148, 0x03D4, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_LCD_DATA12__GPIO3_IO17(p) PIN_CFG(0x0148, 0x03D4, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_DATA12__SRC_BT_CFG12(p) PIN_CFG(0x0148, 0x03D4, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_LCD_DATA12__ECSPI1_RDY(p) PIN_CFG(0x0148, 0x03D4, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_DATA13__LCDIF_DATA13(p) PIN_CFG(0x014C, 0x03D8, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_DATA13__SAI3_TX_BCLK(p) PIN_CFG(0x014C, 0x03D8, 0x0608, 0x1, 0x1, p)
-#define MX6UL_PAD_LCD_DATA13__CSI_DATA21(p) PIN_CFG(0x014C, 0x03D8, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_DATA13__EIM_DATA05(p) PIN_CFG(0x014C, 0x03D8, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_LCD_DATA13__GPIO3_IO18(p) PIN_CFG(0x014C, 0x03D8, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_DATA13__SRC_BT_CFG13(p) PIN_CFG(0x014C, 0x03D8, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_LCD_DATA13__USDHC2_RESET_B(p) PIN_CFG(0x014C, 0x03D8, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_DATA14__LCDIF_DATA14(p) PIN_CFG(0x0150, 0x03DC, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_DATA14__SAI3_RX_DATA(p) PIN_CFG(0x0150, 0x03DC, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_LCD_DATA14__CSI_DATA22(p) PIN_CFG(0x0150, 0x03DC, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_DATA14__EIM_DATA06(p) PIN_CFG(0x0150, 0x03DC, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_LCD_DATA14__GPIO3_IO19(p) PIN_CFG(0x0150, 0x03DC, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_DATA14__SRC_BT_CFG14(p) PIN_CFG(0x0150, 0x03DC, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_LCD_DATA14__USDHC2_DATA4(p) PIN_CFG(0x0150, 0x03DC, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_DATA15__LCDIF_DATA15(p) PIN_CFG(0x0154, 0x03E0, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_DATA15__SAI3_TX_DATA(p) PIN_CFG(0x0154, 0x03E0, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_LCD_DATA15__CSI_DATA23(p) PIN_CFG(0x0154, 0x03E0, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_DATA15__EIM_DATA07(p) PIN_CFG(0x0154, 0x03E0, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_LCD_DATA15__GPIO3_IO20(p) PIN_CFG(0x0154, 0x03E0, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_DATA15__SRC_BT_CFG15(p) PIN_CFG(0x0154, 0x03E0, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_LCD_DATA15__USDHC2_DATA5(p) PIN_CFG(0x0154, 0x03E0, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_DATA16__LCDIF_DATA16(p) PIN_CFG(0x0158, 0x03E4, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_DATA16__UART7_TX(p) PIN_CFG(0x0158, 0x03E4, 0x0654, 0x1, 0x2, p)
-#define MX6UL_PAD_LCD_DATA16__CSI_DATA01(p) PIN_CFG(0x0158, 0x03E4, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_DATA16__EIM_DATA08(p) PIN_CFG(0x0158, 0x03E4, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_LCD_DATA16__GPIO3_IO21(p) PIN_CFG(0x0158, 0x03E4, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_DATA16__SRC_BT_CFG24(p) PIN_CFG(0x0158, 0x03E4, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_LCD_DATA16__USDHC2_DATA6(p) PIN_CFG(0x0158, 0x03E4, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_DATA17__LCDIF_DATA17(p) PIN_CFG(0x015C, 0x03E8, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_DATA17__UART7_RX(p) PIN_CFG(0x015C, 0x03E8, 0x0654, 0x1, 0x3, p)
-#define MX6UL_PAD_LCD_DATA17__CSI_DATA00(p) PIN_CFG(0x015C, 0x03E8, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_DATA17__EIM_DATA09(p) PIN_CFG(0x015C, 0x03E8, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_LCD_DATA17__GPIO3_IO22(p) PIN_CFG(0x015C, 0x03E8, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_DATA17__SRC_BT_CFG25(p) PIN_CFG(0x015C, 0x03E8, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_LCD_DATA17__USDHC2_DATA7(p) PIN_CFG(0x015C, 0x03E8, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_DATA18__LCDIF_DATA18(p) PIN_CFG(0x0160, 0x03EC, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_DATA18__PWM5_OUT(p) PIN_CFG(0x0160, 0x03EC, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_LCD_DATA18__CA7_MX6UL_EVENTO(p) PIN_CFG(0x0160, 0x03EC, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_LCD_DATA18__CSI_DATA10(p) PIN_CFG(0x0160, 0x03EC, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_DATA18__EIM_DATA10(p) PIN_CFG(0x0160, 0x03EC, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_LCD_DATA18__GPIO3_IO23(p) PIN_CFG(0x0160, 0x03EC, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_DATA18__SRC_BT_CFG26(p) PIN_CFG(0x0160, 0x03EC, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_LCD_DATA18__USDHC2_CMD(p) PIN_CFG(0x0160, 0x03EC, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_DATA19__EIM_DATA11(p) PIN_CFG(0x0164, 0x03F0, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_LCD_DATA19__GPIO3_IO24(p) PIN_CFG(0x0164, 0x03F0, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_DATA19__SRC_BT_CFG27(p) PIN_CFG(0x0164, 0x03F0, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_LCD_DATA19__USDHC2_CLK(p) PIN_CFG(0x0164, 0x03F0, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_DATA19__LCDIF_DATA19(p) PIN_CFG(0x0164, 0x03F0, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_DATA19__PWM6_OUT(p) PIN_CFG(0x0164, 0x03F0, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_LCD_DATA19__WDOG1_WDOG_ANY(p) PIN_CFG(0x0164, 0x03F0, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_LCD_DATA19__CSI_DATA11(p) PIN_CFG(0x0164, 0x03F0, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_DATA20__EIM_DATA12(p) PIN_CFG(0x0168, 0x03F4, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_LCD_DATA20__GPIO3_IO25(p) PIN_CFG(0x0168, 0x03F4, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_DATA20__SRC_BT_CFG28(p) PIN_CFG(0x0168, 0x03F4, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_LCD_DATA20__USDHC2_DATA0(p) PIN_CFG(0x0168, 0x03F4, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_DATA20__LCDIF_DATA20(p) PIN_CFG(0x0168, 0x03F4, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_DATA20__UART8_TX(p) PIN_CFG(0x0168, 0x03F4, 0x065C, 0x1, 0x2, p)
-#define MX6UL_PAD_LCD_DATA20__ECSPI1_SCLK(p) PIN_CFG(0x0168, 0x03F4, 0x0534, 0x2, 0x0, p)
-#define MX6UL_PAD_LCD_DATA20__CSI_DATA12(p) PIN_CFG(0x0168, 0x03F4, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_DATA21__LCDIF_DATA21(p) PIN_CFG(0x016C, 0x03F8, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_DATA21__UART8_RX(p) PIN_CFG(0x016C, 0x03F8, 0x065C, 0x1, 0x3, p)
-#define MX6UL_PAD_LCD_DATA21__ECSPI1_SS0(p) PIN_CFG(0x016C, 0x03F8, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_LCD_DATA21__CSI_DATA13(p) PIN_CFG(0x016C, 0x03F8, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_DATA21__EIM_DATA13(p) PIN_CFG(0x016C, 0x03F8, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_LCD_DATA21__GPIO3_IO26(p) PIN_CFG(0x016C, 0x03F8, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_DATA21__SRC_BT_CFG29(p) PIN_CFG(0x016C, 0x03F8, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_LCD_DATA21__USDHC2_DATA1(p) PIN_CFG(0x016C, 0x03F8, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_DATA22__LCDIF_DATA22(p) PIN_CFG(0x0170, 0x03FC, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_DATA22__MQS_RIGHT(p) PIN_CFG(0x0170, 0x03FC, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_LCD_DATA22__ECSPI1_MOSI(p) PIN_CFG(0x0170, 0x03FC, 0x053C, 0x2, 0x0, p)
-#define MX6UL_PAD_LCD_DATA22__CSI_DATA14(p) PIN_CFG(0x0170, 0x03FC, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_DATA22__EIM_DATA14(p) PIN_CFG(0x0170, 0x03FC, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_LCD_DATA22__GPIO3_IO27(p) PIN_CFG(0x0170, 0x03FC, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_DATA22__SRC_BT_CFG30(p) PIN_CFG(0x0170, 0x03FC, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_LCD_DATA22__USDHC2_DATA2(p) PIN_CFG(0x0170, 0x03FC, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_LCD_DATA23__LCDIF_DATA23(p) PIN_CFG(0x0174, 0x0400, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_LCD_DATA23__MQS_LEFT(p) PIN_CFG(0x0174, 0x0400, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_LCD_DATA23__ECSPI1_MISO(p) PIN_CFG(0x0174, 0x0400, 0x0538, 0x2, 0x0, p)
-#define MX6UL_PAD_LCD_DATA23__CSI_DATA15(p) PIN_CFG(0x0174, 0x0400, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_LCD_DATA23__EIM_DATA15(p) PIN_CFG(0x0174, 0x0400, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_LCD_DATA23__GPIO3_IO28(p) PIN_CFG(0x0174, 0x0400, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_LCD_DATA23__SRC_BT_CFG31(p) PIN_CFG(0x0174, 0x0400, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_LCD_DATA23__USDHC2_DATA3(p) PIN_CFG(0x0174, 0x0400, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_NAND_RE_B__RAWNAND_RE_B(p) PIN_CFG(0x0178, 0x0404, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_NAND_RE_B__USDHC2_CLK(p) PIN_CFG(0x0178, 0x0404, 0x0670, 0x1, 0x2, p)
-#define MX6UL_PAD_NAND_RE_B__QSPI_B_SCLK(p) PIN_CFG(0x0178, 0x0404, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_NAND_RE_B__KPP_ROW00(p) PIN_CFG(0x0178, 0x0404, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_NAND_RE_B__EIM_EB_B00(p) PIN_CFG(0x0178, 0x0404, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_NAND_RE_B__GPIO4_IO00(p) PIN_CFG(0x0178, 0x0404, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_NAND_RE_B__ECSPI3_SS2(p) PIN_CFG(0x0178, 0x0404, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_NAND_WE_B__RAWNAND_WE_B(p) PIN_CFG(0x017C, 0x0408, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_NAND_WE_B__USDHC2_CMD(p) PIN_CFG(0x017C, 0x0408, 0x0678, 0x1, 0x2, p)
-#define MX6UL_PAD_NAND_WE_B__QSPI_B_SS0_B(p) PIN_CFG(0x017C, 0x0408, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_NAND_WE_B__KPP_COL00(p) PIN_CFG(0x017C, 0x0408, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_NAND_WE_B__EIM_EB_B01(p) PIN_CFG(0x017C, 0x0408, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_NAND_WE_B__GPIO4_IO01(p) PIN_CFG(0x017C, 0x0408, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_NAND_WE_B__ECSPI3_SS3(p) PIN_CFG(0x017C, 0x0408, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_NAND_DATA00__RAWNAND_DATA00(p) PIN_CFG(0x0180, 0x040C, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_NAND_DATA00__USDHC2_DATA0(p) PIN_CFG(0x0180, 0x040C, 0x067C, 0x1, 0x2, p)
-#define MX6UL_PAD_NAND_DATA00__QSPI_B_SS1_B(p) PIN_CFG(0x0180, 0x040C, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_NAND_DATA00__KPP_ROW01(p) PIN_CFG(0x0180, 0x040C, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_NAND_DATA00__EIM_AD08(p) PIN_CFG(0x0180, 0x040C, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_NAND_DATA00__GPIO4_IO02(p) PIN_CFG(0x0180, 0x040C, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_NAND_DATA00__ECSPI4_RDY(p) PIN_CFG(0x0180, 0x040C, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_NAND_DATA01__RAWNAND_DATA01(p) PIN_CFG(0x0184, 0x0410, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_NAND_DATA01__USDHC2_DATA1(p) PIN_CFG(0x0184, 0x0410, 0x0680, 0x1, 0x2, p)
-#define MX6UL_PAD_NAND_DATA01__QSPI_B_DQS(p) PIN_CFG(0x0184, 0x0410, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_NAND_DATA01__KPP_COL01(p) PIN_CFG(0x0184, 0x0410, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_NAND_DATA01__EIM_AD09(p) PIN_CFG(0x0184, 0x0410, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_NAND_DATA01__GPIO4_IO03(p) PIN_CFG(0x0184, 0x0410, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_NAND_DATA01__ECSPI4_SS1(p) PIN_CFG(0x0184, 0x0410, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_NAND_DATA02__RAWNAND_DATA02(p) PIN_CFG(0x0188, 0x0414, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_NAND_DATA02__USDHC2_DATA2(p) PIN_CFG(0x0188, 0x0414, 0x0684, 0x1, 0x1, p)
-#define MX6UL_PAD_NAND_DATA02__QSPI_B_DATA00(p) PIN_CFG(0x0188, 0x0414, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_NAND_DATA02__KPP_ROW02(p) PIN_CFG(0x0188, 0x0414, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_NAND_DATA02__EIM_AD10(p) PIN_CFG(0x0188, 0x0414, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_NAND_DATA02__GPIO4_IO04(p) PIN_CFG(0x0188, 0x0414, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_NAND_DATA02__ECSPI4_SS2(p) PIN_CFG(0x0188, 0x0414, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_NAND_DATA03__RAWNAND_DATA03(p) PIN_CFG(0x018C, 0x0418, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_NAND_DATA03__USDHC2_DATA3(p) PIN_CFG(0x018C, 0x0418, 0x0688, 0x1, 0x2, p)
-#define MX6UL_PAD_NAND_DATA03__QSPI_B_DATA01(p) PIN_CFG(0x018C, 0x0418, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_NAND_DATA03__KPP_COL02(p) PIN_CFG(0x018C, 0x0418, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_NAND_DATA03__EIM_AD11(p) PIN_CFG(0x018C, 0x0418, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_NAND_DATA03__GPIO4_IO05(p) PIN_CFG(0x018C, 0x0418, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_NAND_DATA03__ECSPI4_SS3(p) PIN_CFG(0x018C, 0x0418, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_NAND_DATA04__RAWNAND_DATA04(p) PIN_CFG(0x0190, 0x041C, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_NAND_DATA04__USDHC2_DATA4(p) PIN_CFG(0x0190, 0x041C, 0x068C, 0x1, 0x1, p)
-#define MX6UL_PAD_NAND_DATA04__QSPI_B_DATA02(p) PIN_CFG(0x0190, 0x041C, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_NAND_DATA04__ECSPI4_SCLK(p) PIN_CFG(0x0190, 0x041C, 0x0564, 0x3, 0x1, p)
-#define MX6UL_PAD_NAND_DATA04__EIM_AD12(p) PIN_CFG(0x0190, 0x041C, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_NAND_DATA04__GPIO4_IO06(p) PIN_CFG(0x0190, 0x041C, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_NAND_DATA04__UART2_TX(p) PIN_CFG(0x0190, 0x041C, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_NAND_DATA05__RAWNAND_DATA05(p) PIN_CFG(0x0194, 0x0420, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_NAND_DATA05__USDHC2_DATA5(p) PIN_CFG(0x0194, 0x0420, 0x0690, 0x1, 0x1, p)
-#define MX6UL_PAD_NAND_DATA05__QSPI_B_DATA03(p) PIN_CFG(0x0194, 0x0420, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_NAND_DATA05__ECSPI4_MOSI(p) PIN_CFG(0x0194, 0x0420, 0x056C, 0x3, 0x1, p)
-#define MX6UL_PAD_NAND_DATA05__EIM_AD13(p) PIN_CFG(0x0194, 0x0420, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_NAND_DATA05__GPIO4_IO07(p) PIN_CFG(0x0194, 0x0420, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_NAND_DATA05__UART2_RX(p) PIN_CFG(0x0194, 0x0420, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_NAND_DATA06__RAWNAND_DATA06(p) PIN_CFG(0x0198, 0x0424, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_NAND_DATA06__USDHC2_DATA6(p) PIN_CFG(0x0198, 0x0424, 0x0694, 0x1, 0x1, p)
-#define MX6UL_PAD_NAND_DATA06__SAI2_RX_BCLK(p) PIN_CFG(0x0198, 0x0424, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_NAND_DATA06__ECSPI4_MISO(p) PIN_CFG(0x0198, 0x0424, 0x0568, 0x3, 0x1, p)
-#define MX6UL_PAD_NAND_DATA06__EIM_AD14(p) PIN_CFG(0x0198, 0x0424, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_NAND_DATA06__GPIO4_IO08(p) PIN_CFG(0x0198, 0x0424, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_NAND_DATA06__UART2_DCE_CTS(p) PIN_CFG(0x0198, 0x0424, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_NAND_DATA06__UART2_DTE_RTS(p) PIN_CFG(0x0198, 0x0424, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_NAND_DATA07__RAWNAND_DATA07(p) PIN_CFG(0x019C, 0x0428, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_NAND_DATA07__USDHC2_DATA7(p) PIN_CFG(0x019C, 0x0428, 0x0698, 0x1, 0x1, p)
-#define MX6UL_PAD_NAND_DATA07__QSPI_A_SS1_B(p) PIN_CFG(0x019C, 0x0428, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_NAND_DATA07__ECSPI4_SS0(p) PIN_CFG(0x019C, 0x0428, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_NAND_DATA07__EIM_AD15(p) PIN_CFG(0x019C, 0x0428, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_NAND_DATA07__GPIO4_IO09(p) PIN_CFG(0x019C, 0x0428, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_NAND_DATA07__UART2_DCE_RTS(p) PIN_CFG(0x019C, 0x0428, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_NAND_DATA07__UART2_DTE_CTS(p) PIN_CFG(0x019C, 0x0428, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_NAND_ALE__RAWNAND_ALE(p) PIN_CFG(0x01A0, 0x042C, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_NAND_ALE__USDHC2_RESET_B(p) PIN_CFG(0x01A0, 0x042C, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_NAND_ALE__QSPI_A_DQS(p) PIN_CFG(0x01A0, 0x042C, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_NAND_ALE__PWM3_OUT(p) PIN_CFG(0x01A0, 0x042C, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_NAND_ALE__EIM_ADDR17(p) PIN_CFG(0x01A0, 0x042C, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_NAND_ALE__GPIO4_IO10(p) PIN_CFG(0x01A0, 0x042C, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_NAND_ALE__ECSPI3_SS1(p) PIN_CFG(0x01A0, 0x042C, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_NAND_WP_B__RAWNAND_WP_B(p) PIN_CFG(0x01A4, 0x0430, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_NAND_WP_B__USDHC1_RESET_B(p) PIN_CFG(0x01A4, 0x0430, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_NAND_WP_B__QSPI_A_SCLK(p) PIN_CFG(0x01A4, 0x0430, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_NAND_WP_B__PWM4_OUT(p) PIN_CFG(0x01A4, 0x0430, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_NAND_WP_B__EIM_BCLK(p) PIN_CFG(0x01A4, 0x0430, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_NAND_WP_B__GPIO4_IO11(p) PIN_CFG(0x01A4, 0x0430, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_NAND_WP_B__ECSPI3_RDY(p) PIN_CFG(0x01A4, 0x0430, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_NAND_READY_B__RAWNAND_READY_B(p) PIN_CFG(0x01A8, 0x0434, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_NAND_READY_B__USDHC1_DATA4(p) PIN_CFG(0x01A8, 0x0434, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_NAND_READY_B__QSPI_A_DATA00(p) PIN_CFG(0x01A8, 0x0434, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_NAND_READY_B__ECSPI3_SS0(p) PIN_CFG(0x01A8, 0x0434, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_NAND_READY_B__EIM_CS1_B(p) PIN_CFG(0x01A8, 0x0434, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_NAND_READY_B__GPIO4_IO12(p) PIN_CFG(0x01A8, 0x0434, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_NAND_READY_B__UART3_TX(p) PIN_CFG(0x01A8, 0x0434, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_NAND_CE0_B__RAWNAND_CE0_B(p) PIN_CFG(0x01AC, 0x0438, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_NAND_CE0_B__USDHC1_DATA5(p) PIN_CFG(0x01AC, 0x0438, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_NAND_CE0_B__QSPI_A_DATA01(p) PIN_CFG(0x01AC, 0x0438, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_NAND_CE0_B__ECSPI3_SCLK(p) PIN_CFG(0x01AC, 0x0438, 0x0554, 0x3, 0x1, p)
-#define MX6UL_PAD_NAND_CE0_B__EIM_DTACK_B(p) PIN_CFG(0x01AC, 0x0438, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_NAND_CE0_B__GPIO4_IO13(p) PIN_CFG(0x01AC, 0x0438, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_NAND_CE0_B__UART3_RX(p) PIN_CFG(0x01AC, 0x0438, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_NAND_CE1_B__RAWNAND_CE1_B(p) PIN_CFG(0x01B0, 0x043C, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_NAND_CE1_B__USDHC1_DATA6(p) PIN_CFG(0x01B0, 0x043C, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_NAND_CE1_B__QSPI_A_DATA02(p) PIN_CFG(0x01B0, 0x043C, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_NAND_CE1_B__ECSPI3_MOSI(p) PIN_CFG(0x01B0, 0x043C, 0x055C, 0x3, 0x1, p)
-#define MX6UL_PAD_NAND_CE1_B__EIM_ADDR18(p) PIN_CFG(0x01B0, 0x043C, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_NAND_CE1_B__GPIO4_IO14(p) PIN_CFG(0x01B0, 0x043C, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_NAND_CE1_B__UART3_DCE_CTS(p) PIN_CFG(0x01B0, 0x043C, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_NAND_CE1_B__UART3_DTE_RTS(p) PIN_CFG(0x01B0, 0x043C, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_NAND_CLE__RAWNAND_CLE(p) PIN_CFG(0x01B4, 0x0440, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_NAND_CLE__USDHC1_DATA7(p) PIN_CFG(0x01B4, 0x0440, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_NAND_CLE__QSPI_A_DATA03(p) PIN_CFG(0x01B4, 0x0440, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_NAND_CLE__ECSPI3_MISO(p) PIN_CFG(0x01B4, 0x0440, 0x0558, 0x3, 0x1, p)
-#define MX6UL_PAD_NAND_CLE__EIM_ADDR16(p) PIN_CFG(0x01B4, 0x0440, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_NAND_CLE__GPIO4_IO15(p) PIN_CFG(0x01B4, 0x0440, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_NAND_CLE__UART3_DCE_RTS(p) PIN_CFG(0x01B4, 0x0440, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_NAND_CLE__UART3_DTE_CTS(p) PIN_CFG(0x01B4, 0x0440, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_NAND_DQS__RAWNAND_DQS(p) PIN_CFG(0x01B8, 0x0444, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_NAND_DQS__CSI_FIELD(p) PIN_CFG(0x01B8, 0x0444, 0x0530, 0x1, 0x1, p)
-#define MX6UL_PAD_NAND_DQS__QSPI_A_SS0_B(p) PIN_CFG(0x01B8, 0x0444, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_NAND_DQS__PWM5_OUT(p) PIN_CFG(0x01B8, 0x0444, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_NAND_DQS__EIM_WAIT(p) PIN_CFG(0x01B8, 0x0444, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_NAND_DQS__GPIO4_IO16(p) PIN_CFG(0x01B8, 0x0444, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_NAND_DQS__SDMA_EXT_EVENT01(p) PIN_CFG(0x01B8, 0x0444, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_NAND_DQS__SPDIF_EXT_CLK(p) PIN_CFG(0x01B8, 0x0444, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_SD1_CMD__USDHC1_CMD(p) PIN_CFG(0x01BC, 0x0448, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_SD1_CMD__GPT2_COMPARE1(p) PIN_CFG(0x01BC, 0x0448, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_SD1_CMD__SAI2_RX_SYNC(p) PIN_CFG(0x01BC, 0x0448, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_SD1_CMD__SPDIF_OUT(p) PIN_CFG(0x01BC, 0x0448, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_SD1_CMD__EIM_ADDR19(p) PIN_CFG(0x01BC, 0x0448, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_SD1_CMD__GPIO2_IO16(p) PIN_CFG(0x01BC, 0x0448, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_SD1_CMD__SDMA_EXT_EVENT00(p) PIN_CFG(0x01BC, 0x0448, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_SD1_CMD__USB_OTG1_PWR(p) PIN_CFG(0x01BC, 0x0448, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_SD1_CLK__USDHC1_CLK(p) PIN_CFG(0x01C0, 0x044C, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_SD1_CLK__GPT2_COMPARE2(p) PIN_CFG(0x01C0, 0x044C, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_SD1_CLK__SAI2_MCLK(p) PIN_CFG(0x01C0, 0x044C, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_SD1_CLK__SPDIF_IN(p) PIN_CFG(0x01C0, 0x044C, 0x0618, 0x3, 0x3, p)
-#define MX6UL_PAD_SD1_CLK__EIM_ADDR20(p) PIN_CFG(0x01C0, 0x044C, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_SD1_CLK__GPIO2_IO17(p) PIN_CFG(0x01C0, 0x044C, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_SD1_CLK__USB_OTG1_OC(p) PIN_CFG(0x01C0, 0x044C, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_SD1_DATA0__USDHC1_DATA0(p) PIN_CFG(0x01C4, 0x0450, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_SD1_DATA0__GPT2_COMPARE3(p) PIN_CFG(0x01C4, 0x0450, 0x0000, 0x1, 0x0, p)
-#define MX6UL_PAD_SD1_DATA0__SAI2_TX_SYNC(p) PIN_CFG(0x01C4, 0x0450, 0x05FC, 0x2, 0x1, p)
-#define MX6UL_PAD_SD1_DATA0__FLEXCAN1_TX(p) PIN_CFG(0x01C4, 0x0450, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_SD1_DATA0__EIM_ADDR21(p) PIN_CFG(0x01C4, 0x0450, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_SD1_DATA0__GPIO2_IO18(p) PIN_CFG(0x01C4, 0x0450, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_SD1_DATA0__ANATOP_OTG1_ID(p) PIN_CFG(0x01C4, 0x0450, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_SD1_DATA1__USDHC1_DATA1(p) PIN_CFG(0x01C8, 0x0454, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_SD1_DATA1__GPT2_CLK(p) PIN_CFG(0x01C8, 0x0454, 0x05A0, 0x1, 0x1, p)
-#define MX6UL_PAD_SD1_DATA1__SAI2_TX_BCLK(p) PIN_CFG(0x01C8, 0x0454, 0x05F8, 0x2, 0x1, p)
-#define MX6UL_PAD_SD1_DATA1__FLEXCAN1_RX(p) PIN_CFG(0x01C8, 0x0454, 0x0584, 0x3, 0x3, p)
-#define MX6UL_PAD_SD1_DATA1__EIM_ADDR22(p) PIN_CFG(0x01C8, 0x0454, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_SD1_DATA1__GPIO2_IO19(p) PIN_CFG(0x01C8, 0x0454, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_SD1_DATA1__USB_OTG2_PWR(p) PIN_CFG(0x01C8, 0x0454, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_SD1_DATA2__USDHC1_DATA2(p) PIN_CFG(0x01CC, 0x0458, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_SD1_DATA2__GPT2_CAPTURE1(p) PIN_CFG(0x01CC, 0x0458, 0x0598, 0x1, 0x1, p)
-#define MX6UL_PAD_SD1_DATA2__SAI2_RX_DATA(p) PIN_CFG(0x01CC, 0x0458, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_SD1_DATA2__FLEXCAN2_TX(p) PIN_CFG(0x01CC, 0x0458, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_SD1_DATA2__EIM_ADDR23(p) PIN_CFG(0x01CC, 0x0458, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_SD1_DATA2__GPIO2_IO20(p) PIN_CFG(0x01CC, 0x0458, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_SD1_DATA2__CCM_CLKO1(p) PIN_CFG(0x01CC, 0x0458, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_SD1_DATA2__USB_OTG2_OC(p) PIN_CFG(0x01CC, 0x0458, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_SD1_DATA3__USDHC1_DATA3(p) PIN_CFG(0x01D0, 0x045C, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_SD1_DATA3__GPT2_CAPTURE2(p) PIN_CFG(0x01D0, 0x045C, 0x059C, 0x1, 0x1, p)
-#define MX6UL_PAD_SD1_DATA3__SAI2_TX_DATA(p) PIN_CFG(0x01D0, 0x045C, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_SD1_DATA3__FLEXCAN2_RX(p) PIN_CFG(0x01D0, 0x045C, 0x0588, 0x3, 0x3, p)
-#define MX6UL_PAD_SD1_DATA3__EIM_ADDR24(p) PIN_CFG(0x01D0, 0x045C, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_SD1_DATA3__GPIO2_IO21(p) PIN_CFG(0x01D0, 0x045C, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_SD1_DATA3__CCM_CLKO2(p) PIN_CFG(0x01D0, 0x045C, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_SD1_DATA3__ANATOP_OTG2_ID(p) PIN_CFG(0x01D0, 0x045C, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_CSI_MCLK__CSI_MCLK(p) PIN_CFG(0x01D4, 0x0460, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_CSI_MCLK__USDHC2_CD_B(p) PIN_CFG(0x01D4, 0x0460, 0x0674, 0x1, 0x0, p)
-#define MX6UL_PAD_CSI_MCLK__RAWNAND_CE2_B(p) PIN_CFG(0x01D4, 0x0460, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_CSI_MCLK__I2C1_SDA(p) PIN_CFG(0x01D4, 0x0460, 0x05A8, 0x3, 0x0, p)
-#define MX6UL_PAD_CSI_MCLK__EIM_CS0_B(p) PIN_CFG(0x01D4, 0x0460, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_CSI_MCLK__GPIO4_IO17(p) PIN_CFG(0x01D4, 0x0460, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_CSI_MCLK__SNVS_HP_VIO_5_CTL(p) PIN_CFG(0x01D4, 0x0460, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_CSI_MCLK__UART6_TX(p) PIN_CFG(0x01D4, 0x0460, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_CSI_PIXCLK__CSI_PIXCLK(p) PIN_CFG(0x01D8, 0x0464, 0x0528, 0x0, 0x1, p)
-#define MX6UL_PAD_CSI_PIXCLK__USDHC2_WP(p) PIN_CFG(0x01D8, 0x0464, 0x069C, 0x1, 0x2, p)
-#define MX6UL_PAD_CSI_PIXCLK__RAWNAND_CE3_B(p) PIN_CFG(0x01D8, 0x0464, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_CSI_PIXCLK__I2C1_SCL(p) PIN_CFG(0x01D8, 0x0464, 0x05A4, 0x3, 0x2, p)
-#define MX6UL_PAD_CSI_PIXCLK__EIM_OE(p) PIN_CFG(0x01D8, 0x0464, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_CSI_PIXCLK__GPIO4_IO18(p) PIN_CFG(0x01D8, 0x0464, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_CSI_PIXCLK__SNVS_HP_VIO_5(p) PIN_CFG(0x01D8, 0x0464, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_CSI_PIXCLK__UART6_RX(p) PIN_CFG(0x01D8, 0x0464, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_CSI_VSYNC__CSI_VSYNC(p) PIN_CFG(0x01DC, 0x0468, 0x052C, 0x0, 0x0, p)
-#define MX6UL_PAD_CSI_VSYNC__USDHC2_CLK(p) PIN_CFG(0x01DC, 0x0468, 0x0670, 0x1, 0x0, p)
-#define MX6UL_PAD_CSI_VSYNC__SIM1_PORT1_CLK(p) PIN_CFG(0x01DC, 0x0468, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_CSI_VSYNC__I2C2_SDA(p) PIN_CFG(0x01DC, 0x0468, 0x05B0, 0x3, 0x0, p)
-#define MX6UL_PAD_CSI_VSYNC__EIM_RW(p) PIN_CFG(0x01DC, 0x0468, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_CSI_VSYNC__GPIO4_IO19(p) PIN_CFG(0x01DC, 0x0468, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_CSI_VSYNC__PWM7_OUT(p) PIN_CFG(0x01DC, 0x0468, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_CSI_VSYNC__UART6_DCE_RTS(p) PIN_CFG(0x01DC, 0x0468, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_CSI_VSYNC__UART6_DTE_CTS(p) PIN_CFG(0x01DC, 0x0468, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_CSI_HSYNC__CSI_HSYNC(p) PIN_CFG(0x01E0, 0x046C, 0x0524, 0x0, 0x0, p)
-#define MX6UL_PAD_CSI_HSYNC__USDHC2_CMD(p) PIN_CFG(0x01E0, 0x046C, 0x0678, 0x1, 0x0, p)
-#define MX6UL_PAD_CSI_HSYNC__SIM1_PORT1_PD(p) PIN_CFG(0x01E0, 0x046C, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_CSI_HSYNC__I2C2_SCL(p) PIN_CFG(0x01E0, 0x046C, 0x05AC, 0x3, 0x0, p)
-#define MX6UL_PAD_CSI_HSYNC__EIM_LBA_B(p) PIN_CFG(0x01E0, 0x046C, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_CSI_HSYNC__GPIO4_IO20(p) PIN_CFG(0x01E0, 0x046C, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_CSI_HSYNC__PWM8_OUT(p) PIN_CFG(0x01E0, 0x046C, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_CSI_HSYNC__UART6_DCE_CTS(p) PIN_CFG(0x01E0, 0x046C, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_CSI_HSYNC__UART6_DTE_RTS(p) PIN_CFG(0x01E0, 0x046C, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_CSI_DATA00__CSI_DATA02(p) PIN_CFG(0x01E4, 0x0470, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_CSI_DATA00__USDHC2_DATA0(p) PIN_CFG(0x01E4, 0x0470, 0x067C, 0x1, 0x0, p)
-#define MX6UL_PAD_CSI_DATA00__SIM1_PORT1_RST_B(p) PIN_CFG(0x01E4, 0x0470, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_CSI_DATA00__ECSPI2_SCLK(p) PIN_CFG(0x01E4, 0x0470, 0x0544, 0x3, 0x0, p)
-#define MX6UL_PAD_CSI_DATA00__EIM_AD00(p) PIN_CFG(0x01E4, 0x0470, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_CSI_DATA00__GPIO4_IO21(p) PIN_CFG(0x01E4, 0x0470, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_CSI_DATA00__SRC_INT_BOOT(p) PIN_CFG(0x01E4, 0x0470, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_CSI_DATA00__UART5_TX(p) PIN_CFG(0x01E4, 0x0470, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_CSI_DATA01__CSI_DATA03(p) PIN_CFG(0x01E8, 0x0474, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_CSI_DATA01__USDHC2_DATA1(p) PIN_CFG(0x01E8, 0x0474, 0x0680, 0x1, 0x0, p)
-#define MX6UL_PAD_CSI_DATA01__SIM1_PORT1_SVEN(p) PIN_CFG(0x01E8, 0x0474, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_CSI_DATA01__ECSPI2_SS0(p) PIN_CFG(0x01E8, 0x0474, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_CSI_DATA01__EIM_AD01(p) PIN_CFG(0x01E8, 0x0474, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_CSI_DATA01__GPIO4_IO22(p) PIN_CFG(0x01E8, 0x0474, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_CSI_DATA01__SAI1_MCLK(p) PIN_CFG(0x01E8, 0x0474, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_CSI_DATA01__UART5_RX(p) PIN_CFG(0x01E8, 0x0474, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_CSI_DATA02__CSI_DATA04(p) PIN_CFG(0x01EC, 0x0478, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_CSI_DATA02__USDHC2_DATA2(p) PIN_CFG(0x01EC, 0x0478, 0x0684, 0x1, 0x2, p)
-#define MX6UL_PAD_CSI_DATA02__SIM1_PORT1_TRXD(p) PIN_CFG(0x01EC, 0x0478, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_CSI_DATA02__ECSPI2_MOSI(p) PIN_CFG(0x01EC, 0x0478, 0x054C, 0x3, 0x1, p)
-#define MX6UL_PAD_CSI_DATA02__EIM_AD02(p) PIN_CFG(0x01EC, 0x0478, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_CSI_DATA02__GPIO4_IO23(p) PIN_CFG(0x01EC, 0x0478, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_CSI_DATA02__SAI1_RX_SYNC(p) PIN_CFG(0x01EC, 0x0478, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_CSI_DATA02__UART5_DCE_RTS(p) PIN_CFG(0x01EC, 0x0478, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_CSI_DATA02__UART5_DTE_CTS(p) PIN_CFG(0x01EC, 0x0478, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_CSI_DATA03__CSI_DATA05(p) PIN_CFG(0x01F0, 0x047C, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_CSI_DATA03__USDHC2_DATA3(p) PIN_CFG(0x01F0, 0x047C, 0x0688, 0x1, 0x0, p)
-#define MX6UL_PAD_CSI_DATA03__SIM2_PORT1_PD(p) PIN_CFG(0x01F0, 0x047C, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_CSI_DATA03__ECSPI2_MISO(p) PIN_CFG(0x01F0, 0x047C, 0x0548, 0x3, 0x0, p)
-#define MX6UL_PAD_CSI_DATA03__EIM_AD03(p) PIN_CFG(0x01F0, 0x047C, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_CSI_DATA03__GPIO4_IO24(p) PIN_CFG(0x01F0, 0x047C, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_CSI_DATA03__SAI1_RX_BCLK(p) PIN_CFG(0x01F0, 0x047C, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_CSI_DATA03__UART5_DCE_CTS(p) PIN_CFG(0x01F0, 0x047C, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_CSI_DATA03__UART5_DTE_RTS(p) PIN_CFG(0x01F0, 0x047C, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_CSI_DATA04__CSI_DATA06(p) PIN_CFG(0x01F4, 0x0480, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_CSI_DATA04__USDHC2_DATA4(p) PIN_CFG(0x01F4, 0x0480, 0x068C, 0x1, 0x2, p)
-#define MX6UL_PAD_CSI_DATA04__SIM2_PORT1_CLK(p) PIN_CFG(0x01F4, 0x0480, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_CSI_DATA04__ECSPI1_SCLK(p) PIN_CFG(0x01F4, 0x0480, 0x0534, 0x3, 0x1, p)
-#define MX6UL_PAD_CSI_DATA04__EIM_AD04(p) PIN_CFG(0x01F4, 0x0480, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_CSI_DATA04__GPIO4_IO25(p) PIN_CFG(0x01F4, 0x0480, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_CSI_DATA04__SAI1_TX_SYNC(p) PIN_CFG(0x01F4, 0x0480, 0x05EC, 0x6, 0x1, p)
-#define MX6UL_PAD_CSI_DATA04__USDHC1_WP(p) PIN_CFG(0x01F4, 0x0480, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_CSI_DATA05__CSI_DATA07(p) PIN_CFG(0x01F8, 0x0484, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_CSI_DATA05__USDHC2_DATA5(p) PIN_CFG(0x01F8, 0x0484, 0x0690, 0x1, 0x2, p)
-#define MX6UL_PAD_CSI_DATA05__SIM2_PORT1_RST_B(p) PIN_CFG(0x01F8, 0x0484, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_CSI_DATA05__ECSPI1_SS0(p) PIN_CFG(0x01F8, 0x0484, 0x0000, 0x3, 0x0, p)
-#define MX6UL_PAD_CSI_DATA05__EIM_AD05(p) PIN_CFG(0x01F8, 0x0484, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_CSI_DATA05__GPIO4_IO26(p) PIN_CFG(0x01F8, 0x0484, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_CSI_DATA05__SAI1_TX_BCLK(p) PIN_CFG(0x01F8, 0x0484, 0x05E8, 0x6, 0x1, p)
-#define MX6UL_PAD_CSI_DATA05__USDHC1_CD_B(p) PIN_CFG(0x01F8, 0x0484, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_CSI_DATA06__CSI_DATA08(p) PIN_CFG(0x01FC, 0x0488, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_CSI_DATA06__USDHC2_DATA6(p) PIN_CFG(0x01FC, 0x0488, 0x0694, 0x1, 0x2, p)
-#define MX6UL_PAD_CSI_DATA06__SIM2_PORT1_SVEN(p) PIN_CFG(0x01FC, 0x0488, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_CSI_DATA06__ECSPI1_MOSI(p) PIN_CFG(0x01FC, 0x0488, 0x053C, 0x3, 0x1, p)
-#define MX6UL_PAD_CSI_DATA06__EIM_AD06(p) PIN_CFG(0x01FC, 0x0488, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_CSI_DATA06__GPIO4_IO27(p) PIN_CFG(0x01FC, 0x0488, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_CSI_DATA06__SAI1_RX_DATA(p) PIN_CFG(0x01FC, 0x0488, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_CSI_DATA06__USDHC1_RESET_B(p) PIN_CFG(0x01FC, 0x0488, 0x0000, 0x8, 0x0, p)
-#define MX6UL_PAD_CSI_DATA07__CSI_DATA09(p) PIN_CFG(0x0200, 0x048C, 0x0000, 0x0, 0x0, p)
-#define MX6UL_PAD_CSI_DATA07__USDHC2_DATA7(p) PIN_CFG(0x0200, 0x048C, 0x0698, 0x1, 0x2, p)
-#define MX6UL_PAD_CSI_DATA07__SIM2_PORT1_TRXD(p) PIN_CFG(0x0200, 0x048C, 0x0000, 0x2, 0x0, p)
-#define MX6UL_PAD_CSI_DATA07__ECSPI1_MISO(p) PIN_CFG(0x0200, 0x048C, 0x0538, 0x3, 0x1, p)
-#define MX6UL_PAD_CSI_DATA07__EIM_AD07(p) PIN_CFG(0x0200, 0x048C, 0x0000, 0x4, 0x0, p)
-#define MX6UL_PAD_CSI_DATA07__GPIO4_IO28(p) PIN_CFG(0x0200, 0x048C, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_CSI_DATA07__SAI1_TX_DATA(p) PIN_CFG(0x0200, 0x048C, 0x0000, 0x6, 0x0, p)
-#define MX6UL_PAD_CSI_DATA07__USDHC1_VSELECT(p) PIN_CFG(0x0200, 0x048C, 0x0000, 0x8, 0x0, p)
-
-/*
- * The TAMPER Pin can be used for GPIO, which depends on
- * TAMPER_PIN_DISABLE[1:0] settings.
- */
-#define MX6UL_PAD_SNVS_TAMPER0__GPIO5_IO00(p) PIN_CFG(0x001C, 0x02A8, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_SNVS_TAMPER1__GPIO5_IO01(p) PIN_CFG(0x0020, 0x02AC, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_SNVS_TAMPER2__GPIO5_IO02(p) PIN_CFG(0x0024, 0x02B0, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_SNVS_TAMPER3__GPIO5_IO03(p) PIN_CFG(0x0028, 0x02B4, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_SNVS_TAMPER4__GPIO5_IO04(p) PIN_CFG(0x002C, 0x02B8, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_SNVS_TAMPER5__GPIO5_IO05(p) PIN_CFG(0x0030, 0x02BC, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_SNVS_TAMPER6__GPIO5_IO06(p) PIN_CFG(0x0034, 0x02C0, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_SNVS_TAMPER7__GPIO5_IO07(p) PIN_CFG(0x0038, 0x02C4, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_SNVS_TAMPER8__GPIO5_IO08(p) PIN_CFG(0x003C, 0x02C8, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_SNVS_TAMPER9__GPIO5_IO09(p) PIN_CFG(0x0040, 0x02CC, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_BOOT_MODE0__GPIO5_IO10(p) PIN_CFG(0x0014, 0x02A0, 0x0000, 0x5, 0x0, p)
-#define MX6UL_PAD_BOOT_MODE1__GPIO5_IO11(p) PIN_CFG(0x0018, 0x02A4, 0x0000, 0x5, 0x0, p)
-
-#endif /* __DTS_IMX6UL_PINFUNC_H */
diff --git a/bsp/imx6ul/platform/include/mx6ul/iomux_register.h b/bsp/imx6ul/platform/include/mx6ul/iomux_register.h
index c75a6617c9..fe92524cfb 100644
--- a/bsp/imx6ul/platform/include/mx6ul/iomux_register.h
+++ b/bsp/imx6ul/platform/include/mx6ul/iomux_register.h
@@ -1,5 +1,4 @@
#ifndef _IOMUX_REGISTER_H_
#define _IOMUX_REGISTER_H_
-#include "imx6ul-pinfunc.h"
-#endif
+#endif
diff --git a/bsp/imx6ul/rtconfig.h b/bsp/imx6ul/rtconfig.h
index 5478603dcb..e48a4fe0aa 100644
--- a/bsp/imx6ul/rtconfig.h
+++ b/bsp/imx6ul/rtconfig.h
@@ -42,9 +42,10 @@
#define RT_USING_DEVICE
#define RT_USING_CONSOLE
#define RT_CONSOLEBUF_SIZE 128
-#define RT_CONSOLE_DEVICE_NAME "uart"
-#define RT_VER_NUM 0x40003
+#define RT_CONSOLE_DEVICE_NAME "uart1"
+#define RT_VER_NUM 0x40004
#define ARCH_ARM
+#define RT_USING_CPU_FFS
#define ARCH_ARM_CORTEX_A
#define RT_USING_GIC_V2
#define ARCH_ARM_CORTEX_A7
@@ -96,6 +97,7 @@
#define RT_USING_LIBC
#define RT_USING_POSIX
+#define RT_LIBC_FIXED_TIMEZONE 8
/* Network */
@@ -117,6 +119,9 @@
/* Utilities */
+/* RT-Thread Utestcases */
+
+
/* RT-Thread online packages */
/* IoT - internet of things */
@@ -148,14 +153,24 @@
/* system packages */
+/* Micrium: Micrium software products porting for RT-Thread */
+
+
/* peripheral libraries and drivers */
+/* AI packages */
+
+
/* miscellaneous packages */
/* samples: kernel and components samples */
+
+/* entertainment: terminal games and other interesting software packages */
+
+#define RT_USING_UART1
#define SOC_MCIMX6X4
#endif
diff --git a/bsp/imx6ul/rtconfig.py b/bsp/imx6ul/rtconfig.py
index 0a9ea3dce3..258e035e5a 100644
--- a/bsp/imx6ul/rtconfig.py
+++ b/bsp/imx6ul/rtconfig.py
@@ -3,17 +3,11 @@ import os
# toolchains options
ARCH='arm'
CPU='cortex-a'
-CROSS_TOOL='gcc'
-
-if os.getenv('RTT_CC'):
- CROSS_TOOL = os.getenv('RTT_CC')
+CROSS_TOOL=os.getenv('RTT_CC') or 'gcc'
# only support GNU GCC compiler.
PLATFORM = 'gcc'
-EXEC_PATH = '/usr/bin'
-
-if os.getenv('RTT_EXEC_PATH'):
- EXEC_PATH = os.getenv('RTT_EXEC_PATH')
+EXEC_PATH = os.getenv('RTT_EXEC_PATH') or '/usr/bin'
BUILD = 'debug'
@@ -33,8 +27,8 @@ if PLATFORM == 'gcc':
DEVICE = ' -march=armv7-a -mtune=cortex-a9 -mfpu=vfpv3-d16 -ftree-vectorize -ffast-math -mfloat-abi=softfp'
CFLAGS = DEVICE + ' -Wall'
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp -D__ASSEMBLY__'
- LINK_SCRIPT = 'imx6.lds'
- LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread-imx6.map,-cref,-u,system_vectors'+\
+ LINK_SCRIPT = 'link.lds'
+ LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread.map,-cref,-u,system_vectors'+\
' -T %s' % LINK_SCRIPT
CPATH = ''
diff --git a/bsp/k210/driver/board.c b/bsp/k210/driver/board.c
index 3343da0fb7..d9c9279dca 100644
--- a/bsp/k210/driver/board.c
+++ b/bsp/k210/driver/board.c
@@ -1,10 +1,11 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
+ *2021-06-10 xiaoyu implement rt_hw_us_delay()
*/
#include <rthw.h>
@@ -117,3 +118,19 @@ void rt_hw_cpu_reset(void)
}
MSH_CMD_EXPORT_ALIAS(rt_hw_cpu_reset, reboot, reset machine);
+
+/**
+ * This function will delay for some us.
+ *
+ * @param us the delay time of us
+ */
+void rt_hw_us_delay(rt_uint32_t usec)
+{
+ rt_uint32_t cycle = read_cycle();
+ rt_uint32_t nop_all = usec * sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 1000000UL;
+ while (1)
+ {
+ if(read_cycle() - cycle >= nop_all)
+ break;
+ }
+}
diff --git a/bsp/qemu-riscv-virt64/.config b/bsp/qemu-riscv-virt64/.config
index 8a61ab72eb..49c8fff6b0 100644
--- a/bsp/qemu-riscv-virt64/.config
+++ b/bsp/qemu-riscv-virt64/.config
@@ -213,6 +213,7 @@ CONFIG_RT_LIBC_FIXED_TIMEZONE=8
# CONFIG_RT_USING_RYM is not set
# CONFIG_RT_USING_ULOG is not set
# CONFIG_RT_USING_UTEST is not set
+# CONFIG_RT_USING_RT_LINK is not set
#
# RT-Thread Utestcases
@@ -335,6 +336,7 @@ CONFIG_RT_LIBC_FIXED_TIMEZONE=8
# CONFIG_PKG_USING_HELIX is not set
# CONFIG_PKG_USING_AZUREGUIX is not set
# CONFIG_PKG_USING_TOUCHGFX2RTT is not set
+# CONFIG_PKG_USING_NUEMWIN is not set
#
# tools packages
@@ -492,6 +494,7 @@ CONFIG_RT_LIBC_FIXED_TIMEZONE=8
# CONFIG_PKG_USING_LIBNFC is not set
# CONFIG_PKG_USING_MFOC is not set
# CONFIG_PKG_USING_TMC51XX is not set
+# CONFIG_PKG_USING_TCA9534 is not set
#
# AI packages
@@ -519,6 +522,7 @@ CONFIG_RT_LIBC_FIXED_TIMEZONE=8
# CONFIG_PKG_USING_FLEXIBLE_BUTTON is not set
# CONFIG_PKG_USING_CANFESTIVAL is not set
# CONFIG_PKG_USING_ZLIB is not set
+# CONFIG_PKG_USING_MINIZIP is not set
# CONFIG_PKG_USING_DSTR is not set
# CONFIG_PKG_USING_TINYFRAME is not set
# CONFIG_PKG_USING_KENDRYTE_DEMO is not set
@@ -558,7 +562,8 @@ CONFIG_BOARD_virt=y
CONFIG_RT_USING_USERSPACE=y
#
-# General Purpose UARTs
+# RISCV qemu virt64 configs
#
# CONFIG_BSP_USING_UART1 is not set
+# CONFIG_RISCV_S_MODE is not set
CONFIG___STACKSIZE__=16384
diff --git a/bsp/qemu-riscv-virt64/README.md b/bsp/qemu-riscv-virt64/README.md
new file mode 100644
index 0000000000..d665500846
--- /dev/null
+++ b/bsp/qemu-riscv-virt64/README.md
@@ -0,0 +1,142 @@
+# QEMU/RISCV64 VIRT BSP Introduction
+
+[中文页](README_ZH.md) | English
+
+RISC-V is a free and open ISA enabling a new era of processor innovation through open standard collaboration. This project ported RT-Thread on QEMU RISCV64 VIRT machine.
+
+## 1. Compiling
+
+Download the cross compiler tool chain, it is recommended to use the sifive tool chain.
+
+```
+https://www.sifive.com/software
+```
+
+Select the fitting platform, we recommend Ubuntu.
+
+Unzip the tool chain to the specified directory.
+
+```
+export RTT_EXEC_PATH=~/gcc/bin
+```
+
+Enter `rt-thread/bsp/qemu-riscv-virt64` directory and input
+
+```
+scons
+```
+
+ `rtthread.elf` and `rtthread .bin` files are generated.
+
+## 2. Execution
+
+The project provides two configurable operating modes for riscv64, defaults to run under M-Mode.
+
+***M-Mode***
+
+Firstly, install the `qemu-system-riscv64`.
+
+```
+sudo apt install qemu-system-misc
+```
+
+Then enter
+
+```
+./qemu-nographic.sh
+```
+
+You'll see Project start running
+
+```
+heap: [0x80035804 - 0x86435804]
+
+ \ | /
+- RT - Thread Operating System
+ / | \ 4.0.4 build May 21 2021
+ 2006 - 2021 Copyright by rt-thread team
+Hello RISC-V!
+msh />
+```
+
+***S-Mode***
+
+When running in S-Mode, configuration is via menuconfig
+
+```
+scons --menuconfig
+```
+
+Select:
+
+```
+RISCV qemu virt64 configs --->
+ [*] RT-Thread run in riscv smode
+```
+
+Save it and compile `scons`.
+
+To get RT-Thread running in S-Mode, enable the opensbi, and then start up the RT-Thread through opensbi.
+
+Compile qemu or downloaded premiere-version qemu that built-in opensbi, then executing `./qemu-nographic-smode.sh` can get it successfully running.
+
+The qemu installed with `sudo apt install qemu-system-misc` is an ordinary-version and may compile the opensbi on its own.
+
+```
+git clone [email protected]:riscv/opensbi.git
+cd opensbi
+make PLATFORM=generic CROSS_COMPILE=~/gcc/bin/riscv64-unknown-elf-
+```
+
+`/build/platform/generic/firmware/fw_jump.elf` file is generated.
+
+Enter the following command to run:
+
+```
+qemu-system-riscv64 -nographic -machine virt -m 256M -kernel rtthread.bin -bios ~/opensbi/build/platform/generic/firmware/fw_jump.elf
+```
+
+Result is shown as follows:
+
+```
+OpenSBI v0.9
+ ____ _____ ____ _____
+ / __ \ / ____| _ \_ _|
+ | | | |_ __ ___ _ __ | (___ | |_) || |
+ | | | | '_ \ / _ \ '_ \ \___ \| _ < | |
+ | |__| | |_) | __/ | | |____) | |_) || |_
+ \____/| .__/ \___|_| |_|_____/|____/_____|
+ | |
+ |_|
+
+Platform Name : riscv-virtio,qemu
+Platform Features : timer,mfdeleg
+.
+.
+.
+Boot HART ISA : rv64imafdcsu
+Boot HART Features : scounteren,mcounteren
+Boot HART PMP Count : 16
+Boot HART PMP Granularity : 4
+Boot HART PMP Address Bits: 54
+Boot HART MHPM Count : 0
+Boot HART MHPM Count : 0
+Boot HART MIDELEG : 0x0000000000000222
+Boot HART MEDELEG : 0x000000000000b109
+heap: [0x80235a58 - 0x86635a58]
+
+ \ | /
+- RT - Thread Operating System
+ / | \ 4.0.4 build May 21 2021
+ 2006 - 2021 Copyright by rt-thread team
+Hello RISC-V!
+msh />
+```
+
+## 3. Condition
+
+| Driver | Condition | Remark |
+| ------ | --------- | ------ |
+| UART | Support | UART0 |
+| PLIC | Support | - |
+| CLIC | Support | - | \ No newline at end of file
diff --git a/bsp/qemu-riscv-virt64/README_ZH.md b/bsp/qemu-riscv-virt64/README_ZH.md
new file mode 100644
index 0000000000..a3631048e7
--- /dev/null
+++ b/bsp/qemu-riscv-virt64/README_ZH.md
@@ -0,0 +1,138 @@
+# QEMU/RISCV64 VIRT板级支持包说明
+
+中文页 | [English](README.md)
+
+## 1. 简介
+
+RISC-V是一种开放和免费的指令集体系结构(ISA)。本工程是在QEMU的RISCV64 VIRT版本上进行的一份移植。
+
+## 2. 编译说明
+
+首先可以下载交叉编译工具链,建议采用sifive的工具链进行编译。
+```
+https://www.sifive.com/software
+```
+选择对应的平台即可。
+
+这里推荐在Ubuntu上进行开发工作。
+
+解压工具链到指定的目录。
+
+```
+export RTT_EXEC_PATH=~/gcc/bin
+```
+
+进入到`rt-thread/bsp/qemu-riscv-virt64`目录进行输入
+```
+scons
+```
+可以看到正常生成`rtthread.elf`与`rtthread.bin`文件。
+
+## 3. 执行
+
+本工程提供了riscv64的两种可配置运行模式,默认运行在M-Mode下。
+
+*M-Mode*
+
+首先安装`qemu-system-riscv64`。
+
+```
+sudo apt install qemu-system-misc
+```
+直接输入
+```
+./qemu-nographic.sh
+```
+可以看到程序运行
+
+```
+heap: [0x80035804 - 0x86435804]
+
+ \ | /
+- RT - Thread Operating System
+ / | \ 4.0.4 build May 21 2021
+ 2006 - 2021 Copyright by rt-thread team
+Hello RISC-V!
+msh />
+```
+
+*S-Mode*
+
+如果运行在S-Mode下,那么需要通过menuconfig选择配置
+
+```
+scons --menuconfig
+```
+选择如下:
+```
+RISCV qemu virt64 configs --->
+ [*] RT-Thread run in riscv smode
+```
+保存后,重新`scons`编译即可。
+
+要让rt-thread运行在S-Mode,首先需要启动opensbi,然后通过opensbi启动rt-thread。
+
+自行编译的qemu或者下载的高版本的qemu内置opensbi,执行`./qemu-nographic-smode.sh`即可正常运行。
+
+通过`sudo apt install qemu-system-misc`安装的qemu版本较低,可自行编译opensbi。
+
+```
+git clone [email protected]:riscv/opensbi.git
+cd opensbi
+make PLATFORM=generic CROSS_COMPILE=~/gcc/bin/riscv64-unknown-elf-
+```
+最后生成的`/build/platform/generic/firmware/fw_jump.elf`则是需要的文件。
+
+输入以下的命令即可运行:
+
+```
+qemu-system-riscv64 -nographic -machine virt -m 256M -kernel rtthread.bin -bios ~/opensbi/build/platform/generic/firmware/fw_jump.elf
+```
+可以看到如下的结果
+```
+OpenSBI v0.9
+ ____ _____ ____ _____
+ / __ \ / ____| _ \_ _|
+ | | | |_ __ ___ _ __ | (___ | |_) || |
+ | | | | '_ \ / _ \ '_ \ \___ \| _ < | |
+ | |__| | |_) | __/ | | |____) | |_) || |_
+ \____/| .__/ \___|_| |_|_____/|____/_____|
+ | |
+ |_|
+
+Platform Name : riscv-virtio,qemu
+Platform Features : timer,mfdeleg
+.
+.
+.
+Boot HART ISA : rv64imafdcsu
+Boot HART Features : scounteren,mcounteren
+Boot HART PMP Count : 16
+Boot HART PMP Granularity : 4
+Boot HART PMP Address Bits: 54
+Boot HART MHPM Count : 0
+Boot HART MHPM Count : 0
+Boot HART MIDELEG : 0x0000000000000222
+Boot HART MEDELEG : 0x000000000000b109
+heap: [0x80235a58 - 0x86635a58]
+
+ \ | /
+- RT - Thread Operating System
+ / | \ 4.0.4 build May 21 2021
+ 2006 - 2021 Copyright by rt-thread team
+Hello RISC-V!
+msh />
+```
+## 4. 支持情况
+
+| 驱动 | 支持情况 | 备注 |
+| ------ | ---- | :------: |
+| UART | 支持 | UART0 |
+| PLIC | 支持 | - |
+| CLIC | 支持 | - |
+
+## 5. 联系人信息
+
+维护人:[bernard][1]
+
+[1]: https://github.com/BernardXiong
diff --git a/bsp/qemu-riscv-virt64/SConstruct b/bsp/qemu-riscv-virt64/SConstruct
index 422e592ccd..770a62ccc2 100644
--- a/bsp/qemu-riscv-virt64/SConstruct
+++ b/bsp/qemu-riscv-virt64/SConstruct
@@ -31,7 +31,11 @@ stack_size = 4096
stack_lds = open('link_stacksize.lds', 'w')
if GetDepend('__STACKSIZE__'): stack_size = GetDepend('__STACKSIZE__')
-stack_lds.write('__STACKSIZE__ = %d;' % stack_size)
+stack_lds.write('__STACKSIZE__ = %d;\r\n' % stack_size)
+if GetDepend('RISCV_S_MODE'): start_addr = int(0x80200000)
+else: start_addr = int(0x80000000)
+stack_lds.write('__START_ADDR__ = 0x%x;' % start_addr)
+
stack_lds.close()
# make a building
diff --git a/bsp/qemu-riscv-virt64/applications/main.c b/bsp/qemu-riscv-virt64/applications/main.c
index 288d4f08ba..50d2de7a22 100644
--- a/bsp/qemu-riscv-virt64/applications/main.c
+++ b/bsp/qemu-riscv-virt64/applications/main.c
@@ -1,10 +1,11 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
+ * 2021-05-20 bigmagic first version
*/
#include <rtthread.h>
@@ -14,9 +15,7 @@
int main(void)
{
- void rt_hw_uart_start_rx_thread();
- rt_hw_uart_start_rx_thread();
- printf("Hello RISC-V\n");
+ printf("Hello RISC-V!\n");
return 0;
}
diff --git a/bsp/qemu-riscv-virt64/driver/Kconfig b/bsp/qemu-riscv-virt64/driver/Kconfig
index 5744c89702..d6fca695ef 100644
--- a/bsp/qemu-riscv-virt64/driver/Kconfig
+++ b/bsp/qemu-riscv-virt64/driver/Kconfig
@@ -1,6 +1,6 @@
-menu "General Purpose UARTs"
+menu "RISCV qemu virt64 configs"
menuconfig BSP_USING_UART1
bool "Enable UART1"
@@ -14,5 +14,8 @@ menuconfig BSP_USING_UART1
default 21
endif
-endmenu
+config RISCV_S_MODE
+ bool "RT-Thread run in riscv smode"
+ default y
+endmenu
diff --git a/bsp/qemu-riscv-virt64/driver/board.c b/bsp/qemu-riscv-virt64/driver/board.c
index e723f49aca..91e8f25982 100644
--- a/bsp/qemu-riscv-virt64/driver/board.c
+++ b/bsp/qemu-riscv-virt64/driver/board.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2020, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -21,6 +21,9 @@
#include "sbi.h"
#include "riscv.h"
#include "stack.h"
+#include "riscv_io.h"
+#include "plic.h"
+#include "interrupt.h"
void primary_cpu_entry(void)
{
@@ -33,11 +36,6 @@ void primary_cpu_entry(void)
entry();
}
-void rt_hw_interrupt_init()
-{
- /* Enable machine external interrupts. */
- set_csr(sie, SIP_SEIP);
-}
void rt_hw_board_init(void)
{
@@ -46,10 +44,7 @@ void rt_hw_board_init(void)
/* initialize hardware interrupt */
rt_hw_uart_init();
- rt_hw_tick_init();
-
#ifdef RT_USING_HEAP
- rt_kprintf("heap: [0x%08x - 0x%08x]\n", (rt_ubase_t) RT_HW_HEAP_BEGIN, (rt_ubase_t) RT_HW_HEAP_END);
/* initialize memory system */
rt_system_heap_init(RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
#endif
@@ -58,6 +53,8 @@ void rt_hw_board_init(void)
/* set console device */
rt_console_set_device("uart");
#endif /* RT_USING_CONSOLE */
+ rt_hw_tick_init();
+ rt_kprintf("heap: [0x%08x - 0x%08x]\n", (rt_ubase_t) RT_HW_HEAP_BEGIN, (rt_ubase_t) RT_HW_HEAP_END);
#ifdef RT_USING_COMPONENTS_INIT
rt_components_board_init();
@@ -71,137 +68,3 @@ void rt_hw_cpu_reset(void)
}
MSH_CMD_EXPORT_ALIAS(rt_hw_cpu_reset, reboot, reset machine);
-void dump_regs(struct rt_hw_stack_frame *regs)
-{
- rt_kprintf("--------------Dump Registers-----------------\n");
-
- rt_kprintf("Function Registers:\n");
- rt_kprintf("\tra(x1) = 0x%p\tuser_sp = 0x%p\n",regs -> ra,regs -> user_sp_exc_stack);
- rt_kprintf("\tgp(x3) = 0x%p\ttp(x4) = 0x%p\n",regs -> gp,regs -> tp);
- rt_kprintf("Temporary Registers:\n");
- rt_kprintf("\tt0(x5) = 0x%p\tt1(x6) = 0x%p\n",regs -> t0,regs -> t1);
- rt_kprintf("\tt2(x7) = 0x%p\n",regs -> t2);
- rt_kprintf("\tt3(x28) = 0x%p\tt4(x29) = 0x%p\n",regs -> t3,regs -> t4);
- rt_kprintf("\tt5(x30) = 0x%p\tt6(x31) = 0x%p\n",regs -> t5,regs -> t6);
- rt_kprintf("Saved Registers:\n");
- rt_kprintf("\ts0/fp(x8) = 0x%p\ts1(x9) = 0x%p\n",regs -> s0_fp,regs -> s1);
- rt_kprintf("\ts2(x18) = 0x%p\ts3(x19) = 0x%p\n",regs -> s2,regs -> s3);
- rt_kprintf("\ts4(x20) = 0x%p\ts5(x21) = 0x%p\n",regs -> s4,regs -> s5);
- rt_kprintf("\ts6(x22) = 0x%p\ts7(x23) = 0x%p\n",regs -> s6,regs -> s7);
- rt_kprintf("\ts8(x24) = 0x%p\ts9(x25) = 0x%p\n",regs -> s8,regs -> s9);
- rt_kprintf("\ts10(x26) = 0x%p\ts11(x27) = 0x%p\n",regs -> s10,regs -> s11);
- rt_kprintf("Function Arguments Registers:\n");
- rt_kprintf("\ta0(x10) = 0x%p\ta1(x11) = 0x%p\n",regs -> a0,regs -> a1);
- rt_kprintf("\ta2(x12) = 0x%p\ta3(x13) = 0x%p\n",regs -> a2,regs -> a3);
- rt_kprintf("\ta4(x14) = 0x%p\ta5(x15) = 0x%p\n",regs -> a4,regs -> a5);
- rt_kprintf("\ta6(x16) = 0x%p\ta7(x17) = 0x%p\n",regs -> a6,regs -> a7);
- rt_kprintf("sstatus = 0x%p\n",regs -> sstatus);
- rt_kprintf("\t%s\n",(regs -> sstatus & SSTATUS_SIE) ? "Supervisor Interrupt Enabled" : "Supervisor Interrupt Disabled");
- rt_kprintf("\t%s\n",(regs -> sstatus & SSTATUS_SPIE) ? "Last Time Supervisor Interrupt Enabled" : "Last Time Supervisor Interrupt Disabled");
- rt_kprintf("\t%s\n",(regs -> sstatus & SSTATUS_SPP) ? "Last Privilege is Supervisor Mode" : "Last Privilege is User Mode");
- rt_kprintf("\t%s\n",(regs -> sstatus & SSTATUS_PUM) ? "Permit to Access User Page" : "Not Permit to Access User Page");
- rt_kprintf("\t%s\n",(regs -> sstatus & (1 << 19)) ? "Permit to Read Executable-only Page" : "Not Permit to Read Executable-only Page");
- rt_size_t satp_v = read_csr(satp);
- rt_kprintf("satp = 0x%p\n",satp_v);
- const char *mode_str = "Unknown Address Translation/Protection Mode";
-
- switch(__MASKVALUE(satp_v >> 60,__MASK(4)))
- {
- case 0:
- mode_str = "No Address Translation/Protection Mode";
- break;
-
- case 8:
- mode_str = "Page-based 39-bit Virtual Addressing Mode";
- break;
-
- case 9:
- mode_str = "Page-based 48-bit Virtual Addressing Mode";
- break;
- }
-
- rt_kprintf("\tMode = %s\n",mode_str);
- rt_kprintf("-----------------Dump OK---------------------\n");
-}
-
-static const char *Exception_Name[] =
- {
- "Instruction Address Misaligned",
- "Instruction Access Fault",
- "Illegal Instruction",
- "Breakpoint",
- "Load Address Misaligned",
- "Load Access Fault",
- "Store/AMO Address Misaligned",
- "Store/AMO Access Fault",
- "Environment call from U-mode",
- "Environment call from S-mode",
- "Reserved-10",
- "Reserved-11",
- "Instruction Page Fault",
- "Load Page Fault",
- "Reserved-14",
- "Store/AMO Page Fault"
- };
-
-static const char *Interrupt_Name[] =
- {
- "User Software Interrupt",
- "Supervisor Software Interrupt",
- "Reversed-2",
- "Reversed-3",
- "User Timer Interrupt",
- "Supervisor Timer Interrupt",
- "Reversed-6",
- "Reversed-7",
- "User External Interrupt",
- "Supervisor External Interrupt",
- "Reserved-10",
- "Reserved-11",
- };
-
-void handle_trap(rt_size_t scause,rt_size_t stval,rt_size_t sepc,struct rt_hw_stack_frame *sp)
-{
- if(scause == (uint64_t)(0x8000000000000005))
- {
- rt_interrupt_enter();
- tick_isr();
- rt_interrupt_leave();
- }
- else
- {
- rt_size_t id = __MASKVALUE(scause,__MASK(63UL));
- const char *msg;
-
- if(scause >> 63)
- {
- if(id < sizeof(Interrupt_Name) / sizeof(const char *))
- {
- msg = Interrupt_Name[id];
- }
- else
- {
- msg = "Unknown Interrupt";
- }
-
- rt_kprintf("Unhandled Interrupt %ld:%s\n",id,msg);
- }
- else
- {
- if(id < sizeof(Exception_Name) / sizeof(const char *))
- {
- msg = Exception_Name[id];
- }
- else
- {
- msg = "Unknown Exception";
- }
-
- rt_kprintf("Unhandled Exception %ld:%s\n",id,msg);
- }
-
- rt_kprintf("scause:0x%p,stval:0x%p,sepc:0x%p\n",scause,stval,sepc);
- dump_regs(sp);
- while(1);
- }
-}
diff --git a/bsp/qemu-riscv-virt64/driver/board.h b/bsp/qemu-riscv-virt64/driver/board.h
index 3193346508..3445852e40 100644
--- a/bsp/qemu-riscv-virt64/driver/board.h
+++ b/bsp/qemu-riscv-virt64/driver/board.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2020, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/bsp/qemu-riscv-virt64/driver/drv_uart.c b/bsp/qemu-riscv-virt64/driver/drv_uart.c
index 754a1fbfd1..c84ae6df7d 100644
--- a/bsp/qemu-riscv-virt64/driver/drv_uart.c
+++ b/bsp/qemu-riscv-virt64/driver/drv_uart.c
@@ -1,10 +1,12 @@
/*
- * Copyright (c) 2019-2020, Xim
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
+ * Change Logs:
+ * Date Author Notes
+ * 2021-05-20 bigmagic first version
*/
-
#include <rthw.h>
#include <rtdevice.h>
@@ -13,8 +15,7 @@
#include <stdio.h>
#include "sbi.h"
-
-#define UART_DEFAULT_BAUDRATE 115200
+#include "interrupt.h"
struct device_uart
{
@@ -27,23 +28,25 @@ static rt_err_t uart_control(struct rt_serial_device *serial, int cmd, void *arg
static int drv_uart_putc(struct rt_serial_device *serial, char c);
static int drv_uart_getc(struct rt_serial_device *serial);
-const struct rt_uart_ops _uart_ops =
+void virt_uart_init(void)
{
- rt_uart_configure,
- uart_control,
- drv_uart_putc,
- drv_uart_getc,
- //TODO: add DMA support
- RT_NULL
-};
+ //http://byterunner.com/16550.html
+ uart_write_reg(IER, 0x00);
-void uart_init(void)
-{
- return ;
-}
+ uint8_t lcr = uart_read_reg(LCR);
+ uart_write_reg(LCR, lcr | (1 << 7));
+ uart_write_reg(DLL, 0x03);
+ uart_write_reg(DLM, 0x00);
-struct rt_serial_device serial1;
-struct device_uart uart1;
+ lcr = 0;
+ uart_write_reg(LCR, lcr | (3 << 0));
+
+ /*
+ * enable receive interrupts.
+ */
+ uint8_t ier = uart_read_reg(IER);
+ uart_write_reg(IER, ier | (1 << 0));
+}
/*
* UART interface
@@ -58,22 +61,6 @@ static rt_err_t rt_uart_configure(struct rt_serial_device *serial, struct serial
return (RT_EOK);
}
-#define UART_LSR_DR 0x01 /* Data ready */
-#define UART_LSR_THRE 0x20 /* Xmit holding register empty */
-
-#define UART_RBR(hw) HWREG32(hw + 0x00)
-#define UART_IER(hw) HWREG32(hw + 0x04)
-#define UART_LSR(hw) HWREG32(hw + 0x14)
-
-static volatile uint64_t uart_hwbase = 0x10000000;
-
-void uart_putc(char c)
-{
- while ((UART_LSR(uart_hwbase) & UART_LSR_THRE) == 0);
-
- UART_RBR(uart_hwbase) = c;
-}
-
static rt_err_t uart_control(struct rt_serial_device *serial, int cmd, void *arg)
{
struct device_uart *uart;
@@ -98,37 +85,37 @@ static rt_err_t uart_control(struct rt_serial_device *serial, int cmd, void *arg
static int drv_uart_putc(struct rt_serial_device *serial, char c)
{
- sbi_console_putchar(c);
- return (1);
+ while ((uart_read_reg(LSR) & LSR_TX_IDLE) == 0);
+ return uart_write_reg(THR, c);
}
static int drv_uart_getc(struct rt_serial_device *serial)
{
- return sbi_console_getchar();
+ if (uart_read_reg(LSR) & LSR_RX_READY){
+ return uart_read_reg(RHR);
+ } else {
+ return -1;
+ }
+ //return sbi_console_getchar();
}
-char rt_hw_console_getchar(void)
+static void rt_hw_uart_isr(int irqno, void *param)
{
- return sbi_console_getchar();
+ struct rt_serial_device *serial = (struct rt_serial_device*)param;
+ rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_IND);
}
-static void uart_rx(void *param)
-{
- struct rt_serial_device *serial = (struct rt_serial_device *)param;
-
- while(1)
- {
- rt_hw_serial_isr((struct rt_serial_device *)serial,RT_SERIAL_EVENT_RX_IND);
- rt_thread_mdelay(10);
- }
-}
+struct rt_serial_device serial1;
+struct device_uart uart1;
-void rt_hw_uart_start_rx_thread()
+const struct rt_uart_ops _uart_ops =
{
- rt_thread_t th;
- RT_ASSERT((th = rt_thread_create("uartrx",uart_rx,(void *)&serial1,8192,8,20)) != RT_NULL);
- RT_ASSERT(rt_thread_startup(th) == RT_EOK);
-}
+ rt_uart_configure,
+ uart_control,
+ drv_uart_putc,
+ drv_uart_getc,
+ RT_NULL
+};
/*
* UART Initiation
@@ -138,7 +125,6 @@ int rt_hw_uart_init(void)
struct rt_serial_device *serial;
struct device_uart *uart;
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
-
{
serial = &serial1;
uart = &uart1;
@@ -147,19 +133,19 @@ int rt_hw_uart_init(void)
serial->config = config;
serial->config.baud_rate = UART_DEFAULT_BAUDRATE;
- uart->hw_base = 0x10000000;
- uart->irqno = 0xa;
+ uart->hw_base = UART_BASE;
+ uart->irqno = UART0_IRQ;
+
+ virt_uart_init();
rt_hw_serial_register(serial,
"uart",
RT_DEVICE_FLAG_STREAM | RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
uart);
+ rt_hw_interrupt_install(uart->irqno, rt_hw_uart_isr, serial, "uart");
+
+ rt_hw_interrupt_umask(uart->irqno);
}
-
- return 0;
-}
-/* WEAK for SDK 0.5.6 */
-RT_WEAK void uart_debug_init(int uart_channel)
-{
+ return 0;
}
diff --git a/bsp/qemu-riscv-virt64/driver/drv_uart.h b/bsp/qemu-riscv-virt64/driver/drv_uart.h
index a7a18d0dde..1a590b83df 100644
--- a/bsp/qemu-riscv-virt64/driver/drv_uart.h
+++ b/bsp/qemu-riscv-virt64/driver/drv_uart.h
@@ -1,15 +1,43 @@
/*
- * Copyright (c) 2019-2020, Xim
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
+ * Change Logs:
+ * Date Author Notes
+ * 2021-05-20 bigmagic first version
*/
#ifndef __DRV_UART_H__
#define __DRV_UART_H__
-void rt_hw_uart_start_rx_thread();
+#define UART0_IRQ (10)
+
+#define UART_DEFAULT_BAUDRATE 115200
+
+#define UART_BASE (0x10000000L)
+
+#define RHR 0 // Receive Holding Register (read mode)
+#define THR 0 // Transmit Holding Register (write mode)
+#define DLL 0 // LSB of Divisor Latch (write mode)
+#define IER 1 // Interrupt Enable Register (write mode)
+#define DLM 1 // MSB of Divisor Latch (write mode)
+#define FCR 2 // FIFO Control Register (write mode)
+#define ISR 2 // Interrupt Status Register (read mode)
+#define LCR 3 // Line Control Register
+#define MCR 4 // Modem Control Register
+#define LSR 5 // Line Status Register
+#define MSR 6 // Modem Status Register
+#define SPR 7 // ScratchPad Register
+
+#define UART_REG(reg) ((volatile uint8_t *)(UART_BASE + reg))
+
+#define LSR_RX_READY (1 << 0)
+#define LSR_TX_IDLE (1 << 5)
+
+#define uart_read_reg(reg) (*(UART_REG(reg)))
+#define uart_write_reg(reg, v) (*(UART_REG(reg)) = (v))
+
int rt_hw_uart_init(void);
-void drv_uart_puts(char *str); // for syscall
#endif /* __DRV_UART_H__ */
diff --git a/bsp/qemu-riscv-virt64/driver/io.h b/bsp/qemu-riscv-virt64/driver/io.h
index 8915b55306..1285d5955b 100644
--- a/bsp/qemu-riscv-virt64/driver/io.h
+++ b/bsp/qemu-riscv-virt64/driver/io.h
@@ -49,4 +49,4 @@ static inline uint32_t read_reg(
return readl(addr + offset);
}
-#endif // ARCH_IO_H \ No newline at end of file
+#endif // ARCH_IO_H
diff --git a/bsp/qemu-riscv-virt64/driver/plic.c b/bsp/qemu-riscv-virt64/driver/plic.c
new file mode 100644
index 0000000000..f502bc9da0
--- /dev/null
+++ b/bsp/qemu-riscv-virt64/driver/plic.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-05-20 bigmagic first version
+ */
+#include "rtthread.h"
+#include "plic.h"
+#include <riscv_io.h>
+#include "encoding.h"
+
+/*
+* Each PLIC interrupt source can be assigned a priority by writing
+* to its 32-bit memory-mapped priority register.
+* The QEMU-virt (the same as FU540-C000) supports 7 levels of priority.
+* A priority value of 0 is reserved to mean "never interrupt" and
+* effectively disables the interrupt.
+* Priority 1 is the lowest active priority, and priority 7 is the highest.
+* Ties between global interrupts of the same priority are broken by
+* the Interrupt ID; interrupts with the lowest ID have the highest
+* effective priority.
+*/
+void plic_set_priority(int irq, int priority)
+{
+ *(uint32_t*)PLIC_PRIORITY(irq) = priority;
+}
+
+/*
+* Each global interrupt can be enabled by setting the corresponding
+* bit in the enables registers.
+*/
+void plic_irq_enable(int irq)
+{
+ int hart = r_mhartid();
+ *(uint32_t*)PLIC_ENABLE(hart) = ((*(uint32_t*)PLIC_ENABLE(hart)) | (1 << irq));
+#ifdef RISCV_S_MODE
+ set_csr(sie, read_csr(sie) | MIP_SEIP);
+#else
+ set_csr(mie, read_csr(mie) | MIP_MEIP);
+#endif
+}
+
+void plic_irq_disable(int irq)
+{
+ int hart = r_mhartid();
+ *(uint32_t*)PLIC_ENABLE(hart) = (((*(uint32_t*)PLIC_ENABLE(hart)) & (~(1 << irq))));
+}
+
+/*
+* PLIC will mask all interrupts of a priority less than or equal to threshold.
+* Maximum threshold is 7.
+* For example, a threshold value of zero permits all interrupts with
+* non-zero priority, whereas a value of 7 masks all interrupts.
+* Notice, the threshold is global for PLIC, not for each interrupt source.
+*/
+void plic_set_threshold(int threshold)
+{
+ int hart = r_mhartid();
+ *(uint32_t*)PLIC_THRESHOLD(hart) = threshold;
+}
+
+/*
+ * DESCRIPTION:
+ * Query the PLIC what interrupt we should serve.
+ * Perform an interrupt claim by reading the claim register, which
+ * returns the ID of the highest-priority pending interrupt or zero if there
+ * is no pending interrupt.
+ * A successful claim also atomically clears the corresponding pending bit
+ * on the interrupt source.
+ * RETURN VALUE:
+ * the ID of the highest-priority pending interrupt or zero if there
+ * is no pending interrupt.
+ */
+int plic_claim(void)
+{
+ int hart = r_mhartid();
+ int irq = *(uint32_t*)PLIC_CLAIM(hart);
+ return irq;
+}
+
+/*
+ * DESCRIPTION:
+ * Writing the interrupt ID it received from the claim (irq) to the
+ * complete register would signal the PLIC we've served this IRQ.
+ * The PLIC does not check whether the completion ID is the same as the
+ * last claim ID for that target. If the completion ID does not match an
+ * interrupt source that is currently enabled for the target, the completion
+ * is silently ignored.
+ * RETURN VALUE: none
+ */
+void plic_complete(int irq)
+{
+ int hart = r_mhartid();
+ *(uint32_t*)PLIC_COMPLETE(hart) = irq;
+}
diff --git a/bsp/qemu-riscv-virt64/driver/plic.h b/bsp/qemu-riscv-virt64/driver/plic.h
new file mode 100644
index 0000000000..5d0fea6eb2
--- /dev/null
+++ b/bsp/qemu-riscv-virt64/driver/plic.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-05-20 bigmagic first version
+ */
+
+#ifndef PLIC_H
+#define PLIC_H
+
+#include <rtconfig.h>
+/*
+ * This machine puts platform-level interrupt controller (PLIC) here.
+ * Here only list PLIC registers in Machine mode.
+ *
+ */
+
+#define VIRT_PLIC_BASE 0x0c000000L
+
+#define PLIC_PRIORITY_OFFSET (0x0)
+#define PLIC_PENDING_OFFSET (0x1000)
+
+#ifndef RISCV_S_MODE
+#define PLIC_MENABLE_OFFSET (0x2000)
+#define PLIC_MTHRESHOLD_OFFSET (0x200000)
+#define PLIC_MCLAIM_OFFSET (0x200004)
+#define PLIC_MCOMPLETE_OFFSET (0x200004)
+
+#define PLIC_ENABLE(hart) (VIRT_PLIC_BASE + PLIC_MENABLE_OFFSET + (hart) * 0x80)
+#define PLIC_THRESHOLD(hart) (VIRT_PLIC_BASE + PLIC_MTHRESHOLD_OFFSET + (hart) * 0x1000)
+#define PLIC_CLAIM(hart) (VIRT_PLIC_BASE + PLIC_MCLAIM_OFFSET + (hart) * 0x1000)
+#define PLIC_COMPLETE(hart) (VIRT_PLIC_BASE + PLIC_MCOMPLETE_OFFSET + (hart) * 0x1000)
+
+#else
+#define PLIC_SENABLE_OFFSET (0x2080)
+#define PLIC_STHRESHOLD_OFFSET (0x201000)
+#define PLIC_SCLAIM_OFFSET (0x201004)
+#define PLIC_SCOMPLETE_OFFSET (0x201004)
+
+#define PLIC_ENABLE(hart) (VIRT_PLIC_BASE + PLIC_SENABLE_OFFSET + (hart) * 0x80)
+#define PLIC_THRESHOLD(hart) (VIRT_PLIC_BASE + PLIC_STHRESHOLD_OFFSET + (hart) * 0x1000)
+#define PLIC_CLAIM(hart) (VIRT_PLIC_BASE + PLIC_SCLAIM_OFFSET + (hart) * 0x1000)
+#define PLIC_COMPLETE(hart) (VIRT_PLIC_BASE + PLIC_SCOMPLETE_OFFSET + (hart) * 0x1000)
+#endif
+
+#define PLIC_PRIORITY(id) (VIRT_PLIC_BASE + PLIC_PRIORITY_OFFSET + (id) * 4)
+#define PLIC_PENDING(id) (VIRT_PLIC_BASE + PLIC_PENDING_OFFSET + ((id) / 32))
+
+void plic_set_priority(int irq, int priority);
+void plic_irq_enable(int irq);
+void plic_irq_disable(int irq);
+void plic_set_threshold(int mthreshold);
+int plic_claim(void);
+void plic_complete(int irq);
+
+#endif
diff --git a/bsp/qemu-riscv-virt64/link.lds b/bsp/qemu-riscv-virt64/link.lds
index e8c0db9c24..2614e0eb36 100644
--- a/bsp/qemu-riscv-virt64/link.lds
+++ b/bsp/qemu-riscv-virt64/link.lds
@@ -21,13 +21,13 @@ OUTPUT_ARCH( "riscv" )
MEMORY
{
- SRAM : ORIGIN = 0x80200000, LENGTH = 0x7FF000
+ SRAM : ORIGIN = __START_ADDR__, LENGTH = 0x7FF000
}
ENTRY(_start)
SECTIONS
{
- . = 0x80200000 ;
+ . = __START_ADDR__ ;
/* __STACKSIZE__ = 4096; */
diff --git a/bsp/qemu-riscv-virt64/link_stacksize.lds b/bsp/qemu-riscv-virt64/link_stacksize.lds
index 8685bc0f1c..4a0d736ae8 100644
--- a/bsp/qemu-riscv-virt64/link_stacksize.lds
+++ b/bsp/qemu-riscv-virt64/link_stacksize.lds
@@ -1 +1,2 @@
-__STACKSIZE__ = 16384; \ No newline at end of file
+__STACKSIZE__ = 16384;
+__START_ADDR__ = 0x80000000; \ No newline at end of file
diff --git a/bsp/qemu-riscv-virt64/qemu-nographic-smode.sh b/bsp/qemu-riscv-virt64/qemu-nographic-smode.sh
new file mode 100755
index 0000000000..750f6f0fcd
--- /dev/null
+++ b/bsp/qemu-riscv-virt64/qemu-nographic-smode.sh
@@ -0,0 +1 @@
+qemu-system-riscv64 -nographic -machine virt -m 256M -kernel rtthread.bin \ No newline at end of file
diff --git a/bsp/qemu-riscv-virt64/qemu-nographic.sh b/bsp/qemu-riscv-virt64/qemu-nographic.sh
index 934c4f935b..546e7a3d87 100644..100755
--- a/bsp/qemu-riscv-virt64/qemu-nographic.sh
+++ b/bsp/qemu-riscv-virt64/qemu-nographic.sh
@@ -1 +1 @@
-qemu-system-riscv64 -nographic -machine virt -m 256M -kernel rtthread.bin
+qemu-system-riscv64 -nographic -machine virt -m 256M -bios rtthread.bin
diff --git a/bsp/qemu-riscv-virt64/rtconfig.h b/bsp/qemu-riscv-virt64/rtconfig.h
index 38d19a2265..fab069701e 100644
--- a/bsp/qemu-riscv-virt64/rtconfig.h
+++ b/bsp/qemu-riscv-virt64/rtconfig.h
@@ -177,7 +177,7 @@
#define BOARD_virt
#define RT_USING_USERSPACE
-/* General Purpose UARTs */
+/* RISCV qemu virt64 configs */
#define __STACKSIZE__ 16384
diff --git a/bsp/qemu-vexpress-a9/.config b/bsp/qemu-vexpress-a9/.config
index f9fa185ce7..290cddd947 100644
--- a/bsp/qemu-vexpress-a9/.config
+++ b/bsp/qemu-vexpress-a9/.config
@@ -77,12 +77,11 @@ CONFIG_RT_CONSOLEBUF_SIZE=256
CONFIG_RT_CONSOLE_DEVICE_NAME="uart0"
CONFIG_RT_VER_NUM=0x40004
CONFIG_ARCH_ARM=y
-# CONFIG_RT_USING_CPU_FFS is not set
+CONFIG_RT_USING_CPU_FFS=y
CONFIG_ARCH_ARM_CORTEX_A=y
# CONFIG_RT_SMP_AUTO_BOOT is not set
CONFIG_RT_USING_GIC_V2=y
# CONFIG_RT_USING_GIC_V3 is not set
-# CONFIG_RT_NO_USING_GIC is not set
CONFIG_ARCH_ARM_CORTEX_A9=y
# CONFIG_ARCH_CPU_STACK_GROWS_UPWARD is not set
diff --git a/bsp/qemu-vexpress-a9/Kconfig b/bsp/qemu-vexpress-a9/Kconfig
index 25921e6e7c..b2bdfe704d 100644
--- a/bsp/qemu-vexpress-a9/Kconfig
+++ b/bsp/qemu-vexpress-a9/Kconfig
@@ -23,6 +23,7 @@ config SOC_VEXPRESS_A9
select ARCH_ARM_CORTEX_A9
select RT_USING_COMPONENTS_INIT
select RT_USING_USER_MAIN
+ select RT_USING_GIC_V2
default y
source "$BSP_DIR/drivers/Kconfig"
diff --git a/bsp/qemu-vexpress-a9/rtconfig.h b/bsp/qemu-vexpress-a9/rtconfig.h
index eb7b915d86..047e6f929c 100644
--- a/bsp/qemu-vexpress-a9/rtconfig.h
+++ b/bsp/qemu-vexpress-a9/rtconfig.h
@@ -54,6 +54,7 @@
#define RT_CONSOLE_DEVICE_NAME "uart0"
#define RT_VER_NUM 0x40004
#define ARCH_ARM
+#define RT_USING_CPU_FFS
#define ARCH_ARM_CORTEX_A
#define RT_USING_GIC_V2
#define ARCH_ARM_CORTEX_A9
diff --git a/bsp/stm32/libraries/HAL_Drivers/drv_usbd.c b/bsp/stm32/libraries/HAL_Drivers/drv_usbd.c
index 4f8f08fef3..d0cb54ef0c 100644
--- a/bsp/stm32/libraries/HAL_Drivers/drv_usbd.c
+++ b/bsp/stm32/libraries/HAL_Drivers/drv_usbd.c
@@ -22,8 +22,13 @@ static struct udcd _stm_udc;
static struct ep_id _ep_pool[] =
{
{0x0, USB_EP_ATTR_CONTROL, USB_DIR_INOUT, 64, ID_ASSIGNED },
+#ifdef BSP_USBD_EP_ISOC
+ {0x1, USB_EP_ATTR_ISOC, USB_DIR_IN, 64, ID_UNASSIGNED},
+ {0x1, USB_EP_ATTR_ISOC, USB_DIR_OUT, 64, ID_UNASSIGNED},
+#else
{0x1, USB_EP_ATTR_BULK, USB_DIR_IN, 64, ID_UNASSIGNED},
{0x1, USB_EP_ATTR_BULK, USB_DIR_OUT, 64, ID_UNASSIGNED},
+#endif
{0x2, USB_EP_ATTR_INT, USB_DIR_IN, 64, ID_UNASSIGNED},
{0x2, USB_EP_ATTR_INT, USB_DIR_OUT, 64, ID_UNASSIGNED},
{0x3, USB_EP_ATTR_BULK, USB_DIR_IN, 64, ID_UNASSIGNED},
diff --git a/bsp/stm32/stm32l475-atk-pandora/board/Kconfig b/bsp/stm32/stm32l475-atk-pandora/board/Kconfig
index bb34e37366..bc71249fa0 100644
--- a/bsp/stm32/stm32l475-atk-pandora/board/Kconfig
+++ b/bsp/stm32/stm32l475-atk-pandora/board/Kconfig
@@ -78,7 +78,35 @@ menu "Onboard Peripheral Drivers"
bool "Enable Audio Record"
default n
endif
-
+
+ menuconfig BSP_USING_USB_AUDIO
+ bool "Enable USB Audio"
+ select RT_USB_DEVICE_AUDIO
+ select BSP_USING_USBD
+ select BSP_USBD_EP_ISOC
+ select BSP_USING_AUDIO
+ default n
+
+ if BSP_USING_USB_AUDIO
+ config BSP_USING_USB_AUDIO_SPEAKER
+ bool "Enable USB Audio Spearker"
+ select RT_USB_DEVICE_AUDIO_SPEAKER
+ select BSP_USING_AUDIO_PLAY
+ default y
+
+ config BSP_USING_USB_AUDIO_MIC
+ bool "Enable USB Audio Mic"
+ select RT_USB_DEVICE_AUDIO_MIC
+ select BSP_USING_AUDIO_RECORD
+ default n
+
+ config _BSP_USB_DEVICE_COMPOSITE
+ bool
+ select RT_USB_DEVICE_COMPOSITE
+ default y
+ depends on BSP_USING_USB_AUDIO_SPEAKER && BSP_USING_USB_AUDIO_MIC
+ endif
+
config BSP_USING_WIFI
bool "Enable WiFi (AP6181)"
select PKG_USING_WLAN_WICED
@@ -352,6 +380,11 @@ menu "On-chip Peripheral Drivers"
select RT_USING_USB_DEVICE
default n
+ config BSP_USBD_EP_ISOC
+ bool
+ default n
+ depends on BSP_USING_USBD
+
config BSP_USING_STM32_SDIO
bool "Enable SDIO"
select RT_USING_SDIO
diff --git a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.c b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.c
index f80ca3a4b2..6ec90f880c 100644
--- a/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.c
+++ b/bsp/stm32/stm32l475-atk-pandora/board/ports/drv_lcd.c
@@ -446,18 +446,33 @@ void lcd_draw_line(rt_uint16_t x1, rt_uint16_t y1, rt_uint16_t x2, rt_uint16_t y
if (y1 == y2)
{
/* fast draw transverse line */
- lcd_address_set(x1, y1, x2, y2);
+ rt_uint32_t x_offset = 0;
+ if (x1 < x2)
+ {
+ x_offset = x2 - x1;
+ lcd_address_set(x1, y1, x2, y2);
+ }
+ else if (x1 > x2)
+ {
+ x_offset = x1 - x2;
+ lcd_address_set(x2, y2, x1, y1);
+ }
+ else
+ {
+ lcd_draw_point(x1, y1);
+ return;
+ }
rt_uint8_t line_buf[480] = {0};
- for (i = 0; i < x2 - x1; i++)
+ for (i = 0; i < x_offset; i++)
{
line_buf[2 * i] = FORE_COLOR >> 8;
line_buf[2 * i + 1] = FORE_COLOR;
}
rt_pin_write(LCD_DC_PIN, PIN_HIGH);
- rt_spi_send(spi_dev_lcd, line_buf, (x2 - x1) * 2);
+ rt_spi_send(spi_dev_lcd, line_buf, x_offset * 2);
return ;
}
diff --git a/bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/sleep.h b/bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/sleep.h
index 7e8c778295..ca6e56a7ec 100644
--- a/bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/sleep.h
+++ b/bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/sleep.h
@@ -1,3 +1,12 @@
+/*
+ * Copyright (c) 2020-2021, WangHuachen
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2020-11-30 WangHuachen the first version
+ */
#ifndef XLI_SLEEP_H
#define XLI_SLEEP_H
diff --git a/bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/xil_assert.h b/bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/xil_assert.h
index de095f1f4c..7abe853e29 100644
--- a/bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/xil_assert.h
+++ b/bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/xil_assert.h
@@ -1,3 +1,12 @@
+/*
+ * Copyright (c) 2020-2021, WangHuachen
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2020-11-30 WangHuachen the first version
+ */
#ifndef XIL_ASSERT_H /* prevent circular inclusions */
#define XIL_ASSERT_H /* by using protection macros */
diff --git a/bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/xil_cache.h b/bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/xil_cache.h
index 1731e84850..575157e6d2 100644
--- a/bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/xil_cache.h
+++ b/bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/xil_cache.h
@@ -1,6 +1,17 @@
+/*
+ * Copyright (c) 2020-2021, WangHuachen
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2020-11-30 WangHuachen the first version
+ */
#ifndef XIL_CACHE_H
#define XIL_CACHE_H
+#include <rthw.h>
+
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/xil_printf.h b/bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/xil_printf.h
index b6983a5d7e..29de8c2441 100644
--- a/bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/xil_printf.h
+++ b/bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/xil_printf.h
@@ -1,5 +1,14 @@
- #ifndef XIL_PRINTF_H
- #define XIL_PRINTF_H
+/*
+ * Copyright (c) 2020-2021, WangHuachen
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2020-11-30 WangHuachen the first version
+ */
+#ifndef XIL_PRINTF_H
+#define XIL_PRINTF_H
#include <rtthread.h>
diff --git a/bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/xil_types.h b/bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/xil_types.h
index a6988a20a5..cebdbcd56e 100644
--- a/bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/xil_types.h
+++ b/bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/xil_types.h
@@ -1,3 +1,13 @@
+/*
+ * Copyright (C) 2010-2020 Xilinx, Inc.
+ * Copyright (c) 2020-2021, WangHuachen
+ * All rights reserved.
+ * SPDX-License-Identifier: MIT
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2020-11-30 WangHuachen the first version
+ */
#ifndef XIL_TYPES_H /* prevent circular inclusions */
#define XIL_TYPES_H /* by using protection macros */
@@ -70,6 +80,30 @@ typedef void (*XInterruptHandler) (void *InstancePtr);
*/
typedef void (*XExceptionHandler) (void *InstancePtr);
+/**
+ * @brief Returns 32-63 bits of a number.
+ * @param n : Number being accessed.
+ * @return Bits 32-63 of number.
+ *
+ * @note A basic shift-right of a 64- or 32-bit quantity.
+ * Use this to suppress the "right shift count >= width of type"
+ * warning when that quantity is 32-bits.
+ */
+#if defined (__aarch64__) || defined (__arch64__)
+#define UPPER_32_BITS(n) ((u32)(((n) >> 16) >> 16))
+#else
+#define UPPER_32_BITS(n) 0U
+#endif
+/**
+ * @brief Returns 0-31 bits of a number
+ * @param n : Number being accessed.
+ * @return Bits 0-31 of number
+ */
+#define LOWER_32_BITS(n) ((u32)(n))
+
+
+
+
/************************** Constant Definitions *****************************/
#ifndef TRUE
diff --git a/bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/xplatform_info.h b/bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/xplatform_info.h
index 4213736270..0024b53f6c 100644
--- a/bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/xplatform_info.h
+++ b/bsp/zynqmp-r5-axu4ev/drivers/Zynq_HAL_Driver/xplatform_info.h
@@ -1,3 +1,13 @@
+/*
+ * Copyright (C) 2014-2020 Xilinx, Inc.
+ * Copyright (c) 2020-2021, WangHuachen
+ * All rights reserved.
+ * SPDX-License-Identifier: MIT
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2020-11-30 WangHuachen the first version
+ */
#ifndef XPLATFORM_INFO_H /* prevent circular inclusions */
#define XPLATFORM_INFO_H /* by using protection macros */
diff --git a/bsp/zynqmp-r5-axu4ev/drivers/drv_eth.c b/bsp/zynqmp-r5-axu4ev/drivers/drv_eth.c
index e3e1884cf2..05c29305fc 100644
--- a/bsp/zynqmp-r5-axu4ev/drivers/drv_eth.c
+++ b/bsp/zynqmp-r5-axu4ev/drivers/drv_eth.c
@@ -7,8 +7,6 @@
* Date Author Notes
* 2021-5-10 WangHuachen the first version
*/
-
-
#include "board.h"
#include <netif/ethernetif.h>
#include "lwipopts.h"
diff --git a/bsp/zynqmp-r5-axu4ev/drivers/zynqmp-r5.h b/bsp/zynqmp-r5-axu4ev/drivers/zynqmp-r5.h
index 3192942b57..fc8cfb0f97 100644
--- a/bsp/zynqmp-r5-axu4ev/drivers/zynqmp-r5.h
+++ b/bsp/zynqmp-r5-axu4ev/drivers/zynqmp-r5.h
@@ -1,3 +1,12 @@
+/*
+ * Copyright (c) 2020-2021, WangHuachen
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2020-11-30 WangHuachen the first version
+ */
#ifndef __ZYNQMP_R5_H__
#define __ZYNQMP_R5_H__
diff --git a/components/dfs/include/dfs_fs.h b/components/dfs/include/dfs_fs.h
index 828f15a0f5..3d194515df 100644
--- a/components/dfs/include/dfs_fs.h
+++ b/components/dfs/include/dfs_fs.h
@@ -15,7 +15,7 @@
#ifdef RT_USING_LIBC
#include <sys/types.h>
#endif
-
+#include <sys/errno.h>
#ifdef __cplusplus
extern "C" {
#endif
diff --git a/components/drivers/cputime/cputime.c b/components/drivers/cputime/cputime.c
index 4a9eee3a71..750733f366 100644
--- a/components/drivers/cputime/cputime.c
+++ b/components/drivers/cputime/cputime.c
@@ -10,6 +10,7 @@
#include <rtdevice.h>
#include <rtthread.h>
+#include <sys/errno.h>
static const struct rt_clock_cputime_ops *_cputime_ops = RT_NULL;
@@ -24,7 +25,7 @@ float clock_cpu_getres(void)
if (_cputime_ops)
return _cputime_ops->cputime_getres();
- rt_set_errno(-ENOSYS);
+ rt_set_errno(ENOSYS);
return 0;
}
@@ -38,7 +39,7 @@ uint32_t clock_cpu_gettime(void)
if (_cputime_ops)
return _cputime_ops->cputime_gettime();
- rt_set_errno(-ENOSYS);
+ rt_set_errno(ENOSYS);
return 0;
}
diff --git a/components/drivers/src/pipe.c b/components/drivers/src/pipe.c
index 0e35248480..7fa5eb067d 100644
--- a/components/drivers/src/pipe.c
+++ b/components/drivers/src/pipe.c
@@ -11,8 +11,9 @@
#include <rthw.h>
#include <rtdevice.h>
#include <stdint.h>
+#include <sys/errno.h>
-#if defined(RT_USING_POSIX)
+#ifdef RT_USING_POSIX
#include <dfs_file.h>
#include <dfs_posix.h>
#include <dfs_poll.h>
@@ -375,7 +376,7 @@ rt_size_t rt_pipe_read(rt_device_t device, rt_off_t pos, void *buffer, rt_size_t
if (device == RT_NULL)
{
- rt_set_errno(-EINVAL);
+ rt_set_errno(EINVAL);
return 0;
}
if (count == 0) return 0;
@@ -403,7 +404,7 @@ rt_size_t rt_pipe_write(rt_device_t device, rt_off_t pos, const void *buffer, rt
if (device == RT_NULL)
{
- rt_set_errno(-EINVAL);
+ rt_set_errno(EINVAL);
return 0;
}
if (count == 0) return 0;
@@ -517,12 +518,12 @@ int rt_pipe_delete(const char *name)
}
else
{
- result = -ENODEV;
+ result = -RT_EINVAL;
}
}
else
{
- result = -ENODEV;
+ result = -RT_EINVAL;
}
return result;
diff --git a/components/finsh/msh.c b/components/finsh/msh.c
index 73a5197dcd..ed12219c2e 100644
--- a/components/finsh/msh.c
+++ b/components/finsh/msh.c
@@ -374,7 +374,7 @@ int msh_exec(char *cmd, rt_size_t length)
int cmd_ret;
/* strim the beginning of command */
- while (*cmd == ' ' || *cmd == '\t')
+ while ((length > 0) && (*cmd == ' ' || *cmd == '\t'))
{
cmd++;
length--;
diff --git a/components/finsh/msh_file.c b/components/finsh/msh_file.c
index 459d77af4e..3f21cc6f34 100644
--- a/components/finsh/msh_file.c
+++ b/components/finsh/msh_file.c
@@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
* 2015-09-25 Bernard the first verion for FinSH
+ * 2021-06-09 Meco Man implement tail command
*/
#include <rtthread.h>
@@ -146,7 +147,7 @@ int msh_exec_script(const char *cmd_line, int size)
extern char working_directory[];
#endif
-int cmd_ls(int argc, char **argv)
+static int cmd_ls(int argc, char **argv)
{
extern void ls(const char *pathname);
@@ -165,9 +166,9 @@ int cmd_ls(int argc, char **argv)
return 0;
}
-FINSH_FUNCTION_EXPORT_ALIAS(cmd_ls, __cmd_ls, List information about the FILEs.);
+MSH_CMD_EXPORT_ALIAS(cmd_ls, ls, List information about the FILEs.);
-int cmd_cp(int argc, char **argv)
+static int cmd_cp(int argc, char **argv)
{
void copy(const char *src, const char *dst);
@@ -183,9 +184,9 @@ int cmd_cp(int argc, char **argv)
return 0;
}
-FINSH_FUNCTION_EXPORT_ALIAS(cmd_cp, __cmd_cp, Copy SOURCE to DEST.);
+MSH_CMD_EXPORT_ALIAS(cmd_cp, cp, Copy SOURCE to DEST.);
-int cmd_mv(int argc, char **argv)
+static int cmd_mv(int argc, char **argv)
{
if (argc != 3)
{
@@ -242,9 +243,9 @@ int cmd_mv(int argc, char **argv)
return 0;
}
-FINSH_FUNCTION_EXPORT_ALIAS(cmd_mv, __cmd_mv, Rename SOURCE to DEST.);
+MSH_CMD_EXPORT_ALIAS(cmd_mv, mv, Rename SOURCE to DEST.);
-int cmd_cat(int argc, char **argv)
+static int cmd_cat(int argc, char **argv)
{
int index;
extern void cat(const char *filename);
@@ -263,7 +264,7 @@ int cmd_cat(int argc, char **argv)
return 0;
}
-FINSH_FUNCTION_EXPORT_ALIAS(cmd_cat, __cmd_cat, Concatenate FILE(s));
+MSH_CMD_EXPORT_ALIAS(cmd_cat, cat, Concatenate FILE(s));
static void directory_delete_for_msh(const char *pathname, char f, char v)
{
@@ -329,7 +330,7 @@ static void directory_delete_for_msh(const char *pathname, char f, char v)
}
}
-int cmd_rm(int argc, char **argv)
+static int cmd_rm(int argc, char **argv)
{
int index, n;
char f = 0, r = 0, v = 0;
@@ -399,10 +400,10 @@ int cmd_rm(int argc, char **argv)
}
return 0;
}
-FINSH_FUNCTION_EXPORT_ALIAS(cmd_rm, __cmd_rm, Remove(unlink) the FILE(s).);
+MSH_CMD_EXPORT_ALIAS(cmd_rm, rm, Remove(unlink) the FILE(s).);
#ifdef DFS_USING_WORKDIR
-int cmd_cd(int argc, char **argv)
+static int cmd_cd(int argc, char **argv)
{
if (argc == 1)
{
@@ -418,17 +419,17 @@ int cmd_cd(int argc, char **argv)
return 0;
}
-FINSH_FUNCTION_EXPORT_ALIAS(cmd_cd, __cmd_cd, Change the shell working directory.);
+MSH_CMD_EXPORT_ALIAS(cmd_cd, cd, Change the shell working directory.);
-int cmd_pwd(int argc, char **argv)
+static int cmd_pwd(int argc, char **argv)
{
rt_kprintf("%s\n", working_directory);
return 0;
}
-FINSH_FUNCTION_EXPORT_ALIAS(cmd_pwd, __cmd_pwd, Print the name of the current working directory.);
+MSH_CMD_EXPORT_ALIAS(cmd_pwd, pwd, Print the name of the current working directory.);
#endif
-int cmd_mkdir(int argc, char **argv)
+static int cmd_mkdir(int argc, char **argv)
{
if (argc == 1)
{
@@ -442,9 +443,9 @@ int cmd_mkdir(int argc, char **argv)
return 0;
}
-FINSH_FUNCTION_EXPORT_ALIAS(cmd_mkdir, __cmd_mkdir, Create the DIRECTORY.);
+MSH_CMD_EXPORT_ALIAS(cmd_mkdir, mkdir, Create the DIRECTORY.);
-int cmd_mkfs(int argc, char **argv)
+static int cmd_mkfs(int argc, char **argv)
{
int result = 0;
char *type = "elm"; /* use the default file system type as 'fatfs' */
@@ -474,10 +475,10 @@ int cmd_mkfs(int argc, char **argv)
return 0;
}
-FINSH_FUNCTION_EXPORT_ALIAS(cmd_mkfs, __cmd_mkfs, format disk with file system);
+MSH_CMD_EXPORT_ALIAS(cmd_mkfs, mkfs, format disk with file system);
extern struct dfs_filesystem filesystem_table[];
-int cmd_mount(int argc, char *argv[])
+static int cmd_mount(int argc, char **argv)
{
if (argc == 1)
{
@@ -522,10 +523,10 @@ int cmd_mount(int argc, char *argv[])
return -1;
}
}
-FINSH_FUNCTION_EXPORT_ALIAS(cmd_mount, __cmd_mount, mount <device> <mountpoint> <fstype>);
+MSH_CMD_EXPORT_ALIAS(cmd_mount, mount, mount <device> <mountpoint> <fstype>);
/* unmount the filesystem from the specified mountpoint */
-int cmd_umount(int argc, char *argv[])
+static int cmd_umount(int argc, char **argv)
{
char *path = argv[1];
@@ -547,10 +548,10 @@ int cmd_umount(int argc, char *argv[])
return 0;
}
}
-FINSH_FUNCTION_EXPORT_ALIAS(cmd_umount, __cmd_umount, Unmount device from file system);
+MSH_CMD_EXPORT_ALIAS(cmd_umount, umount, Unmount device from file system);
extern int df(const char *path);
-int cmd_df(int argc, char **argv)
+static int cmd_df(int argc, char **argv)
{
if (argc != 2)
{
@@ -570,9 +571,9 @@ int cmd_df(int argc, char **argv)
return 0;
}
-FINSH_FUNCTION_EXPORT_ALIAS(cmd_df, __cmd_df, disk free);
+MSH_CMD_EXPORT_ALIAS(cmd_df, df, disk free);
-int cmd_echo(int argc, char **argv)
+static int cmd_echo(int argc, char **argv)
{
if (argc == 2)
{
@@ -600,7 +601,106 @@ int cmd_echo(int argc, char **argv)
return 0;
}
-FINSH_FUNCTION_EXPORT_ALIAS(cmd_echo, __cmd_echo, echo string to file);
+MSH_CMD_EXPORT_ALIAS(cmd_echo, echo, echo string to file);
+
+static int cmd_tail(int argc, char **argv)
+{
+ int fd;
+ char c = RT_NULL;
+ char *file_name = RT_NULL;
+ rt_uint32_t total_lines = 0;
+ rt_uint32_t target_line = 0;
+ rt_uint32_t current_line = 0;
+ rt_uint32_t required_lines = 0;
+ rt_uint32_t after_xxx_line = 0;
+
+ if(argc < 2)
+ {
+ rt_kprintf("Usage: tail [-n numbers] <filename>\n");
+ return -1;
+ }
+ else if(argc == 2)
+ {
+ required_lines = 10; /* default: 10 lines from tail */
+ file_name = argv[1];
+ }
+ else if(rt_strcmp(argv[1], "-n") == 0)
+ {
+ if(argv[2][0] != '+')
+ {
+ required_lines = atoi(argv[2]);
+ }
+ else
+ {
+ after_xxx_line = atoi(&argv[2][1]); /* eg: +100, to get the 100 */
+ }
+ file_name = argv[3];
+ }
+ else
+ {
+ rt_kprintf("Usage: tail [-n numbers] <filename>\n");
+ return -1;
+ }
+
+ fd = open(file_name, O_RDONLY);
+ if (fd < 0)
+ {
+ rt_kprintf("File doesn't exist\n");
+ return -1;
+ }
+
+ while ((read(fd, &c, sizeof(char))) > 0)
+ {
+ if (c == '\n')
+ {
+ total_lines++;
+ }
+ }
+
+ rt_kprintf("\nTotal Number of lines:%d\n", total_lines);
+
+ if(after_xxx_line != 0)
+ {
+ if(total_lines > after_xxx_line)
+ {
+ required_lines = total_lines - after_xxx_line;
+ }
+ else
+ {
+ rt_kprintf("\nError:Required lines are more than total number of lines\n");
+ close(fd);
+ return -1;
+ }
+ }
+
+ if (required_lines > total_lines)
+ {
+ rt_kprintf("\nError:Required lines are more than total number of lines\n");
+ close(fd);
+ return -1;
+ }
+ rt_kprintf("Required Number of lines:%d\n", required_lines);
+
+ target_line = total_lines - required_lines;
+ lseek(fd, 0, SEEK_SET); /* back to head */
+
+ while ((read(fd, &c, sizeof(char))) > 0)
+ {
+ if (c == '\n')
+ {
+ current_line++;
+ }
+ if (current_line > target_line)
+ {
+ rt_kprintf("%c", c);
+ }
+ }
+ rt_kprintf("\n");
+
+ close(fd);
+ return 0;
+}
+MSH_CMD_EXPORT_ALIAS(cmd_tail, tail, print the last N-lines data of the given file);
#endif /* defined(FINSH_USING_MSH) && defined(RT_USING_DFS) */
diff --git a/components/finsh/shell.c b/components/finsh/shell.c
index 6f1133bf3b..a749660629 100644
--- a/components/finsh/shell.c
+++ b/components/finsh/shell.c
@@ -97,7 +97,7 @@ int finsh_set_prompt(const char * prompt)
}
#endif /* RT_USING_HEAP */
-#if defined(RT_USING_DFS)
+#ifdef RT_USING_DFS
#include <dfs_posix.h>
#endif /* RT_USING_DFS */
diff --git a/components/libc/compilers/common/SConscript b/components/libc/compilers/common/SConscript
index 039e53a0b3..2ebfc36c4e 100644
--- a/components/libc/compilers/common/SConscript
+++ b/components/libc/compilers/common/SConscript
@@ -9,20 +9,17 @@ CPPPATH = [cwd]
if GetDepend('RT_USING_LIBC'):
src += Glob('*.c')
-else:
- if GetDepend('RT_LIBC_USING_TIME'):
- src += ['time.c']
-
-if GetDepend('RT_USING_POSIX') == False:
- SrcRemove(src, ['unistd.c'])
+ if GetDepend('RT_USING_POSIX') == False:
+ SrcRemove(src, ['unistd.c'])
+elif GetDepend('RT_LIBC_USING_TIME'):
+ src += ['time.c']
if rtconfig.CROSS_TOOL == 'keil':
CPPDEFINES = ['__CLK_TCK=RT_TICK_PER_SECOND']
else:
CPPDEFINES = []
-if GetDepend('RT_USING_LIBC') or GetDepend('RT_LIBC_USING_TIME'):
- group = DefineGroup('libc', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
+group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
list = os.listdir(cwd)
for d in list:
diff --git a/components/libc/compilers/common/none-gcc/SConscript b/components/libc/compilers/common/none-gcc/SConscript
index c5838f8949..c766c8f82d 100644
--- a/components/libc/compilers/common/none-gcc/SConscript
+++ b/components/libc/compilers/common/none-gcc/SConscript
@@ -6,8 +6,10 @@ src = []
cwd = GetCurrentDir()
CPPPATH = [cwd]
group = []
-src += Glob('*.c')
+
+if GetDepend('RT_USING_LIBC'):
+ src += Glob('*.c')
if rtconfig.PLATFORM != 'gcc' or rtconfig.ARCH == 'sim':
- group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], CPPPATH = CPPPATH)
+ group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH)
Return('group')
diff --git a/include/libc/libc_errno.h b/components/libc/compilers/common/none-gcc/sys/errno.h
index 30d6092e33..773c2cd7d3 100644
--- a/include/libc/libc_errno.h
+++ b/components/libc/compilers/common/none-gcc/sys/errno.h
@@ -5,18 +5,10 @@
*
* Change Logs:
* Date Author Notes
- * 2016-11-12 Bernard The first version
+ * 2021-05-22 Meco Man The first version.
*/
-
-#ifndef LIBC_ERRNO_H__
-#define LIBC_ERRNO_H__
-
-#include <rtconfig.h>
-
-#if defined(RT_USING_NEWLIB) || defined(_WIN32) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION))
-/* use errno.h file in toolchains */
-#include <errno.h>
-#endif
+#ifndef _SYS_ERRNO_H
+#define _SYS_ERRNO_H
#if defined(__CC_ARM)
/*
@@ -29,6 +21,7 @@ defined in armcc/errno.h
#define EINVAL 5
#define ENOMEM 6
*/
+
#define ERROR_BASE_NO 7
#elif defined(__IAR_SYSTEMS_ICC__)
@@ -41,12 +34,11 @@ defined in armcc/errno.h
#define ERROR_BASE_NO 36
#else
-
#define ERROR_BASE_NO 0
#endif
-#if !defined(RT_USING_NEWLIB) && !defined(_WIN32) && !(defined( __GNUC__ ) && !defined(__ARMCC_VERSION))
-
+#if defined(__CC_ARM) || defined(__IAR_SYSTEMS_ICC__)
+#include <errno.h>
#define EPERM (ERROR_BASE_NO + 1)
#define ENOENT (ERROR_BASE_NO + 2)
#define ESRCH (ERROR_BASE_NO + 3)
@@ -200,7 +192,6 @@ defined in armcc/errno.h
#define ENOTRECOVERABLE (ERROR_BASE_NO + 131)
#define ERFKILL (ERROR_BASE_NO + 132)
#define EHWPOISON (ERROR_BASE_NO + 133)
-
#endif
#endif
diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c
index 9996212444..4cdfe77343 100644
--- a/components/libc/compilers/common/time.c
+++ b/components/libc/compilers/common/time.c
@@ -21,6 +21,7 @@
*/
#include "sys/time.h"
+#include <sys/errno.h>
#include <rtthread.h>
#ifdef RT_USING_DEVICE
diff --git a/components/libc/compilers/newlib/minilib.c b/components/libc/compilers/newlib/minilib.c
index f6df38f67b..612554ca66 100644
--- a/components/libc/compilers/newlib/minilib.c
+++ b/components/libc/compilers/newlib/minilib.c
@@ -12,8 +12,9 @@
#include <rtthread.h>
#ifdef RT_USING_HEAP /* Memory routine */
-void *
-_malloc_r (struct _reent *ptr, size_t size)
+#include <sys/errno.h>
+
+void * _malloc_r (struct _reent *ptr, size_t size)
{
void* result;
@@ -26,8 +27,7 @@ _malloc_r (struct _reent *ptr, size_t size)
return result;
}
-void *
-_realloc_r (struct _reent *ptr, void *old, size_t newlen)
+void * _realloc_r (struct _reent *ptr, void *old, size_t newlen)
{
void* result;
@@ -53,15 +53,13 @@ void *_calloc_r (struct _reent *ptr, size_t size, size_t len)
return result;
}
-void
-_free_r (struct _reent *ptr, void *addr)
+void _free_r (struct _reent *ptr, void *addr)
{
rt_free (addr);
}
#else
-void *
-_sbrk_r(struct _reent *ptr, ptrdiff_t incr)
+void * _sbrk_r(struct _reent *ptr, ptrdiff_t incr)
{
return RT_NULL;
}
diff --git a/components/libc/getline/posix_getline.c b/components/libc/getline/posix_getline.c
index 794ac3a07d..da80242ecc 100644
--- a/components/libc/getline/posix_getline.c
+++ b/components/libc/getline/posix_getline.c
@@ -11,8 +11,8 @@
#include "posix_getline.h"
#include <stdlib.h>
-#include <errno.h>
-#include <rtlibc.h>
+#include <limits.h>
+#include <sys/errno.h>
ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream) {
char *cur_pos, *new_lineptr;
@@ -43,7 +43,7 @@ ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream) {
break;
if ((*lineptr + *n - cur_pos) < 2) {
- if (SSIZE_MAX / 2 < *n) {
+ if (LONG_MAX / 2 < *n) {
#ifdef EOVERFLOW
errno = EOVERFLOW;
#else
diff --git a/components/libc/pthreads/posix_types.h b/components/libc/pthreads/posix_types.h
index 942657ef39..5838e8b370 100644
--- a/components/libc/pthreads/posix_types.h
+++ b/components/libc/pthreads/posix_types.h
@@ -20,7 +20,7 @@
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>
-#include <errno.h>
+#include <sys/errno.h>
#include <fcntl.h>
#endif
diff --git a/components/libc/signal/posix_signal.c b/components/libc/signal/posix_signal.c
index b06fe12685..1cb561d428 100644
--- a/components/libc/signal/posix_signal.c
+++ b/components/libc/signal/posix_signal.c
@@ -10,7 +10,8 @@
#include <rthw.h>
#include <rtthread.h>
-#include <time.h>
+#include <sys/time.h>
+#include <sys/errno.h>
#include "posix_signal.h"
#define sig_valid(sig_no) (sig_no >= 0 && sig_no < RT_SIG_MAX)
diff --git a/components/net/lwip-1.4.1/src/arch/include/arch/cc.h b/components/net/lwip-1.4.1/src/arch/include/arch/cc.h
index 8dd59e8dee..c312f50df5 100644
--- a/components/net/lwip-1.4.1/src/arch/include/arch/cc.h
+++ b/components/net/lwip-1.4.1/src/arch/include/arch/cc.h
@@ -54,24 +54,18 @@ typedef uintptr_t mem_ptr_t;
#define S32_F "ld"
#define X32_F "lx"
-#ifdef RT_USING_LIBC
-#if !defined(__CC_ARM) && !defined(__IAR_SYSTEMS_ICC__)
-
+#include <sys/errno.h>
/* some errno not defined in newlib */
+#ifndef ENSRNOTFOUND
#define ENSRNOTFOUND 163 /* Domain name not found */
/* WARNING: ESHUTDOWN also not defined in newlib. We chose
180 here because the number "108" which is used
in arch.h has been assigned to another error code. */
-#define ESHUTDOWN 180
-#endif /* __CC_ARM/__IAR_SYSTEMS_ICC__ */
#endif
-#if defined(RT_USING_LIBC) || defined(RT_LIBC_USING_TIME) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION))
+/* LWIP_TIMEVAL_PRIVATE: provided by <sys/time.h> */
#include <sys/time.h>
#define LWIP_TIMEVAL_PRIVATE 0
-#else
-#define LWIP_TIMEVAL_PRIVATE 1
-#endif
#if defined(__CC_ARM) /* ARMCC compiler */
#define PACK_STRUCT_FIELD(x) x
@@ -105,7 +99,7 @@ void sys_arch_assert(const char* file, int line);
#define LWIP_PLATFORM_DIAG(x) do {rt_kprintf x;} while(0)
#define LWIP_PLATFORM_ASSERT(x) do {rt_kprintf(x); sys_arch_assert(__FILE__, __LINE__);}while(0)
-#include "string.h"
+#include <string.h>
#define SYS_ARCH_DECL_PROTECT(level)
#define SYS_ARCH_PROTECT(level) rt_enter_critical()
diff --git a/components/net/lwip-1.4.1/src/lwipopts.h b/components/net/lwip-1.4.1/src/lwipopts.h
index a23a167970..0b7e092d6c 100644
--- a/components/net/lwip-1.4.1/src/lwipopts.h
+++ b/components/net/lwip-1.4.1/src/lwipopts.h
@@ -3,7 +3,7 @@
#include <rtconfig.h>
-#define ERRNO 1
+#define ERRNO
#define NO_SYS 0
#define LWIP_SOCKET 1
diff --git a/components/net/lwip-2.0.2/src/arch/include/arch/cc.h b/components/net/lwip-2.0.2/src/arch/include/arch/cc.h
index e3014f552c..4829f5b2e5 100644
--- a/components/net/lwip-2.0.2/src/arch/include/arch/cc.h
+++ b/components/net/lwip-2.0.2/src/arch/include/arch/cc.h
@@ -45,12 +45,18 @@
#define S32_F "ld"
#define X32_F "lx"
-#if defined(RT_USING_LIBC) || defined(RT_LIBC_USING_TIME) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION))
+#include <sys/errno.h>
+/* some errno not defined in newlib */
+#ifndef ENSRNOTFOUND
+#define ENSRNOTFOUND 163 /* Domain name not found */
+/* WARNING: ESHUTDOWN also not defined in newlib. We chose
+ 180 here because the number "108" which is used
+ in arch.h has been assigned to another error code. */
+#endif
+
+/* LWIP_TIMEVAL_PRIVATE: provided by <sys/time.h> */
#include <sys/time.h>
#define LWIP_TIMEVAL_PRIVATE 0
-#else
-#define LWIP_TIMEVAL_PRIVATE 1
-#endif
#if defined(__CC_ARM) /* ARMCC compiler */
#define PACK_STRUCT_FIELD(x) x
@@ -84,7 +90,7 @@ void sys_arch_assert(const char* file, int line);
#define LWIP_PLATFORM_DIAG(x) do {rt_kprintf x;} while(0)
#define LWIP_PLATFORM_ASSERT(x) do {rt_kprintf(x); sys_arch_assert(__FILE__, __LINE__);}while(0)
-#include "string.h"
+#include <string.h>
#define SYS_ARCH_DECL_PROTECT(level)
#define SYS_ARCH_PROTECT(level) rt_enter_critical()
diff --git a/components/net/lwip-2.0.2/src/lwipopts.h b/components/net/lwip-2.0.2/src/lwipopts.h
index 09bd223aa4..d559684c02 100644
--- a/components/net/lwip-2.0.2/src/lwipopts.h
+++ b/components/net/lwip-2.0.2/src/lwipopts.h
@@ -3,7 +3,7 @@
#include <rtconfig.h>
-#define ERRNO 1
+#define LWIP_ERRNO_STDINCLUDE
#define LWIP_IPV4 1
diff --git a/components/net/lwip-2.1.2/src/arch/include/arch/cc.h b/components/net/lwip-2.1.2/src/arch/include/arch/cc.h
index 413fef65df..8e98013412 100644
--- a/components/net/lwip-2.1.2/src/arch/include/arch/cc.h
+++ b/components/net/lwip-2.1.2/src/arch/include/arch/cc.h
@@ -45,25 +45,18 @@
#define S32_F "ld"
#define X32_F "lx"
-#ifdef RT_USING_LIBC
-#include <errno.h>
+#include <sys/errno.h>
+/* some errno not defined in newlib */
#ifndef ENSRNOTFOUND
#define ENSRNOTFOUND 163 /* Domain name not found */
-#endif
-#ifndef ESHUTDOWN
/* WARNING: ESHUTDOWN also not defined in newlib. We chose
180 here because the number "108" which is used
in arch.h has been assigned to another error code. */
-#define ESHUTDOWN 180
#endif
-#endif /* RT_USING_LIBC */
-#if defined(RT_USING_LIBC) || defined(RT_LIBC_USING_TIME) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION))
+/* LWIP_TIMEVAL_PRIVATE: provided by <sys/time.h> */
#include <sys/time.h>
#define LWIP_TIMEVAL_PRIVATE 0
-#else
-#define LWIP_TIMEVAL_PRIVATE 1
-#endif
#if defined(__CC_ARM) /* ARMCC compiler */
#define PACK_STRUCT_FIELD(x) x
diff --git a/components/net/lwip-2.1.2/src/include/lwip/errno.h b/components/net/lwip-2.1.2/src/include/lwip/errno.h
index 48d6b539d8..9fd88fc91a 100644
--- a/components/net/lwip-2.1.2/src/include/lwip/errno.h
+++ b/components/net/lwip-2.1.2/src/include/lwip/errno.h
@@ -181,7 +181,7 @@ extern int errno;
/* Define LWIP_ERRNO_STDINCLUDE if you want to include <errno.h> here */
#ifdef LWIP_ERRNO_STDINCLUDE
-#include <errno.h>
+#include <sys/errno.h>
#else /* LWIP_ERRNO_STDINCLUDE */
/* Define LWIP_ERRNO_INCLUDE to an equivalent of <errno.h> to include the error defines here */
#ifdef LWIP_ERRNO_INCLUDE
diff --git a/components/net/lwip-2.1.2/src/lwipopts.h b/components/net/lwip-2.1.2/src/lwipopts.h
index 220bb6fa41..2cd7cb023a 100644
--- a/components/net/lwip-2.1.2/src/lwipopts.h
+++ b/components/net/lwip-2.1.2/src/lwipopts.h
@@ -3,8 +3,7 @@
#include <rtconfig.h>
-#define ERRNO 1
-
+#define LWIP_ERRNO_STDINCLUDE
#define LWIP_SOCKET_SELECT 1
#define LWIP_SOCKET_POLL 1
diff --git a/components/net/sal_socket/socket/net_sockets.c b/components/net/sal_socket/socket/net_sockets.c
index 3637635d50..7d4db34327 100644
--- a/components/net/sal_socket/socket/net_sockets.c
+++ b/components/net/sal_socket/socket/net_sockets.c
@@ -13,7 +13,7 @@
#include <dfs_file.h>
#include <dfs_poll.h>
#include <dfs_net.h>
-
+#include <sys/errno.h>
#include <sys/socket.h>
int accept(int s, struct sockaddr *addr, socklen_t *addrlen)
diff --git a/examples/file/listdir.c b/examples/file/listdir.c
index 98fbc5ea2c..06c746a642 100644
--- a/examples/file/listdir.c
+++ b/examples/file/listdir.c
@@ -13,7 +13,7 @@
void list_dir(const char* path)
{
- char * fullpath;
+ char * fullpath = RT_NULL;
DIR *dir;
dir = opendir(path);
@@ -57,7 +57,10 @@ void list_dir(const char* path)
rt_kprintf("open %s directory failed\n", path);
}
- rt_free(fullpath);
+ if (RT_NULL != fullpath)
+ {
+ rt_free(fullpath);
+ }
}
#ifdef RT_USING_FINSH
@@ -80,6 +83,6 @@ static void cmd_list_dir(int argc, char *argv[])
}
list_dir(filename);
}
-FINSH_FUNCTION_EXPORT_ALIAS(cmd_list_dir, __cmd_list_dir, list directory);
+MSH_CMD_EXPORT_ALIAS(cmd_list_dir, list_dir, list directory);
#endif /* FINSH_USING_MSH */
#endif /* RT_USING_FINSH */
diff --git a/examples/libc/ex3.c b/examples/libc/ex3.c
index 1697e7145b..615ed8f35c 100644
--- a/examples/libc/ex3.c
+++ b/examples/libc/ex3.c
@@ -9,7 +9,7 @@
/* Multi-thread searching.
Illustrates: thread cancellation, cleanup handlers. */
-#include <errno.h>
+#include <sys/errno.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
diff --git a/examples/libc/ex6.c b/examples/libc/ex6.c
index ac6319d74c..ba687aa46f 100644
--- a/examples/libc/ex6.c
+++ b/examples/libc/ex6.c
@@ -6,7 +6,7 @@
* Change Logs:
* Date Author Notes
*/
-#include <errno.h>
+#include <sys/errno.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
diff --git a/examples/libc/ex7.c b/examples/libc/ex7.c
index e885f79c57..d1f05dbdcd 100644
--- a/examples/libc/ex7.c
+++ b/examples/libc/ex7.c
@@ -11,7 +11,7 @@
* Test case that illustrates a timed wait on a condition variable.
*/
-#include <errno.h>
+#include <sys/errno.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
diff --git a/examples/libc/file.c b/examples/libc/file.c
index 79cdce3092..878d3a98d7 100644
--- a/examples/libc/file.c
+++ b/examples/libc/file.c
@@ -11,7 +11,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <finsh.h>
-#include <errno.h>
+#include <sys/errno.h>
#include <sys/fcntl.h>
#include <sys/stat.h>
diff --git a/examples/libc/memory.c b/examples/libc/memory.c
index 063d90cfdc..4a31b69017 100644
--- a/examples/libc/memory.c
+++ b/examples/libc/memory.c
@@ -11,7 +11,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <finsh.h>
-#include <errno.h>
+#include <sys/errno.h>
static int errors = 0;
static void merror(const char *msg)
diff --git a/examples/utest/configs/kernel/config.h b/examples/utest/configs/kernel/config.h
new file mode 100644
index 0000000000..c7fcb763fb
--- /dev/null
+++ b/examples/utest/configs/kernel/config.h
@@ -0,0 +1,304 @@
+#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
+#define RT_USING_SMP
+#define RT_CPUS_NR 2
+#define RT_ALIGN_SIZE 4
+#define RT_THREAD_PRIORITY_32
+#define RT_THREAD_PRIORITY_MAX 32
+#define RT_TICK_PER_SECOND 100
+#define RT_USING_OVERFLOW_CHECK
+#define RT_USING_HOOK
+#define RT_USING_IDLE_HOOK
+#define RT_IDLE_HOOK_LIST_SIZE 4
+#define IDLE_THREAD_STACK_SIZE 1024
+#define RT_USING_TIMER_SOFT
+#define RT_TIMER_THREAD_PRIO 4
+#define RT_TIMER_THREAD_STACK_SIZE 1024
+
+/* kservice optimization */
+
+#define RT_DEBUG
+#define RT_DEBUG_COLOR
+
+/* Inter-Thread communication */
+
+#define RT_USING_SEMAPHORE
+#define RT_USING_MUTEX
+#define RT_USING_EVENT
+#define RT_USING_MAILBOX
+#define RT_USING_MESSAGEQUEUE
+#define RT_USING_SIGNALS
+
+/* Memory Management */
+
+#define RT_USING_MEMPOOL
+#define RT_USING_MEMHEAP
+#define RT_USING_SMALL_MEM
+#define RT_USING_MEMTRACE
+#define RT_USING_HEAP
+
+/* Kernel Device Object */
+
+#define RT_USING_DEVICE
+#define RT_USING_DEVICE_OPS
+#define RT_USING_INTERRUPT_INFO
+#define RT_USING_CONSOLE
+#define RT_CONSOLEBUF_SIZE 256
+#define RT_CONSOLE_DEVICE_NAME "uart0"
+#define RT_VER_NUM 0x40004
+#define ARCH_ARM
+#define RT_USING_CPU_FFS
+#define ARCH_ARM_CORTEX_A
+#define RT_USING_GIC_V2
+#define ARCH_ARM_CORTEX_A9
+
+/* RT-Thread Components */
+
+#define RT_USING_COMPONENTS_INIT
+#define RT_USING_USER_MAIN
+#define RT_MAIN_THREAD_STACK_SIZE 2048
+#define RT_MAIN_THREAD_PRIORITY 10
+
+/* C++ features */
+
+#define RT_USING_CPLUSPLUS
+
+/* Command shell */
+
+#define RT_USING_FINSH
+#define FINSH_THREAD_NAME "tshell"
+#define FINSH_USING_HISTORY
+#define FINSH_HISTORY_LINES 5
+#define FINSH_USING_SYMTAB
+#define FINSH_USING_DESCRIPTION
+#define FINSH_THREAD_PRIORITY 20
+#define FINSH_THREAD_STACK_SIZE 4096
+#define FINSH_CMD_SIZE 80
+#define FINSH_USING_MSH
+#define FINSH_USING_MSH_DEFAULT
+#define FINSH_ARG_MAX 10
+
+/* Device virtual file system */
+
+#define RT_USING_DFS
+#define DFS_USING_WORKDIR
+#define DFS_FILESYSTEMS_MAX 4
+#define DFS_FILESYSTEM_TYPES_MAX 8
+#define DFS_FD_MAX 32
+#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 4096
+#define RT_DFS_ELM_REENTRANT
+#define RT_USING_DFS_DEVFS
+#define RT_USING_DFS_ROMFS
+#define RT_USING_DFS_RAMFS
+
+/* Device Drivers */
+
+#define RT_USING_DEVICE_IPC
+#define RT_PIPE_BUFSZ 512
+#define RT_USING_SYSTEM_WORKQUEUE
+#define RT_SYSTEM_WORKQUEUE_STACKSIZE 2048
+#define RT_SYSTEM_WORKQUEUE_PRIORITY 23
+#define RT_USING_SERIAL
+#define RT_SERIAL_USING_DMA
+#define RT_SERIAL_RB_BUFSZ 64
+#define RT_USING_I2C
+#define RT_USING_I2C_BITOPS
+#define RT_USING_PIN
+#define RT_USING_MTD_NOR
+#define RT_USING_MTD_NAND
+#define RT_MTD_NAND_DEBUG
+#define RT_USING_RTC
+#define RT_USING_SOFT_RTC
+#define RT_USING_SDIO
+#define RT_SDIO_STACK_SIZE 512
+#define RT_SDIO_THREAD_PRIORITY 15
+#define RT_MMCSD_STACK_SIZE 1024
+#define RT_MMCSD_THREAD_PREORITY 22
+#define RT_MMCSD_MAX_PARTITION 16
+#define RT_USING_SPI
+#define RT_USING_SPI_MSD
+#define RT_USING_SFUD
+#define RT_SFUD_USING_SFDP
+#define RT_SFUD_USING_FLASH_INFO_TABLE
+#define RT_SFUD_SPI_MAX_HZ 50000000
+#define RT_USING_WDT
+
+/* Using USB */
+
+
+/* POSIX layer and C standard library */
+
+#define RT_USING_LIBC
+#define RT_USING_PTHREADS
+#define PTHREAD_NUM_MAX 8
+#define RT_USING_POSIX
+#define RT_USING_POSIX_MMAP
+#define RT_USING_POSIX_TERMIOS
+#define RT_USING_POSIX_GETLINE
+#define RT_USING_POSIX_AIO
+#define RT_LIBC_FIXED_TIMEZONE 8
+
+/* Network */
+
+/* Socket abstraction layer */
+
+#define RT_USING_SAL
+#define SAL_INTERNET_CHECK
+
+/* protocol stack implement */
+
+#define SAL_USING_LWIP
+#define SAL_USING_POSIX
+
+/* Network interface device */
+
+#define RT_USING_NETDEV
+#define NETDEV_USING_IFCONFIG
+#define NETDEV_USING_PING
+#define NETDEV_USING_NETSTAT
+#define NETDEV_USING_AUTO_DEFAULT
+#define NETDEV_IPV4 1
+#define NETDEV_IPV6 0
+
+/* light weight TCP/IP stack */
+
+#define RT_USING_LWIP
+#define RT_USING_LWIP202
+#define RT_LWIP_MEM_ALIGNMENT 4
+#define RT_LWIP_ICMP
+#define RT_LWIP_DNS
+#define RT_LWIP_DHCP
+#define IP_SOF_BROADCAST 1
+#define IP_SOF_BROADCAST_RECV 1
+
+/* Static IPv4 Address */
+
+#define RT_LWIP_IPADDR "192.168.1.30"
+#define RT_LWIP_GWADDR "192.168.1.1"
+#define RT_LWIP_MSKADDR "255.255.255.0"
+#define RT_LWIP_UDP
+#define RT_LWIP_TCP
+#define RT_LWIP_RAW
+#define RT_MEMP_NUM_NETCONN 8
+#define RT_LWIP_PBUF_NUM 16
+#define RT_LWIP_RAW_PCB_NUM 4
+#define RT_LWIP_UDP_PCB_NUM 4
+#define RT_LWIP_TCP_PCB_NUM 4
+#define RT_LWIP_TCP_SEG_NUM 40
+#define RT_LWIP_TCP_SND_BUF 8196
+#define RT_LWIP_TCP_WND 8196
+#define RT_LWIP_TCPTHREAD_PRIORITY 10
+#define RT_LWIP_TCPTHREAD_MBOX_SIZE 8
+#define RT_LWIP_TCPTHREAD_STACKSIZE 1024
+#define RT_LWIP_ETHTHREAD_PRIORITY 12
+#define RT_LWIP_ETHTHREAD_STACKSIZE 1024
+#define RT_LWIP_ETHTHREAD_MBOX_SIZE 8
+#define RT_LWIP_REASSEMBLY_FRAG
+#define LWIP_NETIF_STATUS_CALLBACK 1
+#define LWIP_NETIF_LINK_CALLBACK 1
+#define SO_REUSE 1
+#define LWIP_SO_RCVTIMEO 1
+#define LWIP_SO_SNDTIMEO 1
+#define LWIP_SO_RCVBUF 1
+#define LWIP_SO_LINGER 0
+#define LWIP_NETIF_LOOPBACK 0
+#define RT_LWIP_USING_PING
+
+/* AT commands */
+
+
+/* VBUS(Virtual Software BUS) */
+
+
+/* Utilities */
+
+#define RT_USING_UTEST
+#define UTEST_THR_STACK_SIZE 4096
+#define UTEST_THR_PRIORITY 20
+#define RT_USING_LWP
+
+/* RT-Thread Utestcases */
+
+#define RT_USING_UTESTCASES
+
+/* Utest Self Testcase */
+
+#define UTEST_SELF_PASS_TC
+
+/* Kernel memheap stability Testcase */
+
+#define UTEST_MEMHEAP_TC
+
+/* RT-Thread online packages */
+
+/* IoT - internet of things */
+
+
+/* Wi-Fi */
+
+/* Marvell WiFi */
+
+
+/* Wiced WiFi */
+
+
+/* IoT Cloud */
+
+
+/* security packages */
+
+
+/* language packages */
+
+
+/* multimedia packages */
+
+
+/* tools packages */
+
+
+/* system packages */
+
+
+/* Micrium: Micrium software products porting for RT-Thread */
+
+
+/* peripheral libraries and drivers */
+
+
+/* AI packages */
+
+
+/* miscellaneous packages */
+
+
+/* samples: kernel and components samples */
+
+
+/* entertainment: terminal games and other interesting software packages */
+
+#define SOC_VEXPRESS_A9
+#define RT_USING_UART0
+#define RT_USING_UART1
+#define BSP_DRV_EMAC
+
+#endif
diff --git a/examples/utest/configs/utest_self/config.h b/examples/utest/configs/utest_self/config.h
index 2080a544b0..fa94023c42 100644
--- a/examples/utest/configs/utest_self/config.h
+++ b/examples/utest/configs/utest_self/config.h
@@ -54,6 +54,7 @@
#define RT_CONSOLE_DEVICE_NAME "uart0"
#define RT_VER_NUM 0x40004
#define ARCH_ARM
+#define RT_USING_CPU_FFS
#define ARCH_ARM_CORTEX_A
#define RT_USING_GIC_V2
#define ARCH_ARM_CORTEX_A9
diff --git a/examples/utest/testcases/Kconfig b/examples/utest/testcases/Kconfig
index da80eb30ae..a9b556f1e3 100644
--- a/examples/utest/testcases/Kconfig
+++ b/examples/utest/testcases/Kconfig
@@ -8,6 +8,7 @@ config RT_USING_UTESTCASES
if RT_USING_UTESTCASES
source "$RTT_DIR/examples/utest/testcases/utest/Kconfig"
+source "$RTT_DIR/examples/utest/testcases/kernel/Kconfig"
endif
diff --git a/examples/utest/testcases/kernel/Kconfig b/examples/utest/testcases/kernel/Kconfig
new file mode 100644
index 0000000000..14334af16f
--- /dev/null
+++ b/examples/utest/testcases/kernel/Kconfig
@@ -0,0 +1,8 @@
+menu "Kernel Testcase"
+
+config UTEST_MEMHEAP_TC
+ bool "memheap stability test"
+ default y
+ depends on RT_USING_MEMHEAP
+
+endmenu
diff --git a/examples/utest/testcases/kernel/SConscript b/examples/utest/testcases/kernel/SConscript
new file mode 100644
index 0000000000..9411cdd9a0
--- /dev/null
+++ b/examples/utest/testcases/kernel/SConscript
@@ -0,0 +1,15 @@
+Import('rtconfig')
+from building import *
+
+cwd = GetCurrentDir()
+src = Split('''
+''')
+
+if GetDepend(['UTEST_MEMHEAP_TC']):
+ src += ['memheap_tc.c']
+
+CPPPATH = [cwd]
+
+group = DefineGroup('utestcases', src, depend = [], CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/examples/utest/testcases/kernel/memheap_tc.c b/examples/utest/testcases/kernel/memheap_tc.c
new file mode 100644
index 0000000000..ee52bdb185
--- /dev/null
+++ b/examples/utest/testcases/kernel/memheap_tc.c
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2006-2019, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2019-01-16 flybreak the first version
+ */
+
+#include <rtthread.h>
+#include <stdlib.h>
+#include "utest.h"
+
+#define HEAP_SIZE (64 * 1024)
+#define HEAP_ALIGN (4)
+#define SLICE_NUM (40)
+#define TEST_TIMES (100000)
+#define HEAP_NAME "heap1"
+#define SLICE_SIZE_MAX (HEAP_SIZE/SLICE_NUM)
+
+static void memheap_test(void)
+{
+ struct rt_memheap heap1;
+ rt_uint32_t ptr_start;
+ void *ptr[SLICE_NUM];
+ int i, cnt = 0;
+
+ /* init heap */
+ ptr_start = (rt_uint32_t)rt_malloc_align(HEAP_SIZE, HEAP_ALIGN);
+ if (ptr_start == RT_NULL)
+ {
+ rt_kprintf("totle size too big,can not malloc memory!");
+ return;
+ }
+
+ rt_memheap_init(&heap1, HEAP_NAME, (void *)ptr_start, HEAP_SIZE);
+
+ /* test start */
+ for (i = 0; i < SLICE_NUM; i++)
+ {
+ ptr[i] = 0;
+ }
+ /* test alloc */
+ for (i = 0; i < SLICE_NUM; i++)
+ {
+ rt_uint32_t slice_size = rand() % SLICE_SIZE_MAX;
+ ptr[i] = rt_memheap_alloc(&heap1, slice_size);
+ }
+ /* test realloc */
+ while (cnt < TEST_TIMES)
+ {
+ rt_uint32_t slice_size = rand() % SLICE_SIZE_MAX;
+ rt_uint32_t ptr_index = rand() % SLICE_NUM;
+ rt_uint32_t operation = rand() % 2;
+
+ if (ptr[ptr_index])
+ {
+ if (operation == 0) /* free and malloc */
+ {
+ if (ptr[ptr_index])
+ {
+ rt_memheap_free(ptr[ptr_index]);
+ }
+ ptr[ptr_index] = rt_memheap_alloc(&heap1, slice_size);
+ }
+ else /* realloc */
+ {
+ ptr[ptr_index] = rt_memheap_realloc(&heap1, ptr[ptr_index], slice_size);
+ }
+ }
+ cnt ++;
+ if (cnt % (TEST_TIMES / 10) == 0)
+ {
+ rt_kprintf(">");
+ }
+ }
+
+ rt_kprintf("test OK!\n");
+
+ /* test end */
+ rt_memheap_detach(&heap1);
+ rt_free_align((void *)ptr_start);
+}
+
+static rt_err_t utest_tc_init(void)
+{
+ return RT_EOK;
+}
+
+static rt_err_t utest_tc_cleanup(void)
+{
+ return RT_EOK;
+}
+
+static void testcase(void)
+{
+ UTEST_UNIT_RUN(memheap_test);
+}
+UTEST_TC_EXPORT(testcase, "testcases.kernel.memheap_tc", utest_tc_init, utest_tc_cleanup, 10);
diff --git a/examples/utest/testcases/utest/pass_tc.c b/examples/utest/testcases/utest/pass_tc.c
index 8e93e35b9b..c9ee912fbf 100644
--- a/examples/utest/testcases/utest/pass_tc.c
+++ b/examples/utest/testcases/utest/pass_tc.c
@@ -43,4 +43,4 @@ static void testcase(void)
{
UTEST_UNIT_RUN(test_assert_pass);
}
-UTEST_TC_EXPORT(testcase, "testcases.utest.pass_tc", utest_tc_init, utest_tc_cleanup, 10); \ No newline at end of file
+UTEST_TC_EXPORT(testcase, "testcases.utest.pass_tc", utest_tc_init, utest_tc_cleanup, 10);
diff --git a/include/libc/libc_limits.h b/include/libc/libc_limits.h
deleted file mode 100644
index 36b8dbb202..0000000000
--- a/include/libc/libc_limits.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (c) 2006-2021, RT-Thread Development Team
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Change Logs:
- * Date Author Notes
- * 2020-09-05 Meco Man the first version
- */
-
-#ifndef LIBC_LIMITS_H__
-#define LIBC_LIMITS_H__
-
-#include <limits.h>
-#include <rtconfig.h>
-
-#ifdef RT_USING_POSIX
-
-#ifndef SSIZE_MAX
-# define SSIZE_MAX LONG_MAX
-#endif
-
-#endif
-
-#endif
diff --git a/include/rtlibc.h b/include/rtlibc.h
index d69f3ca185..1fd6053deb 100644
--- a/include/rtlibc.h
+++ b/include/rtlibc.h
@@ -13,13 +13,11 @@
/* definitions for libc if toolchain has no these definitions */
#include "libc/libc_stat.h"
-#include "libc/libc_errno.h"
#include "libc/libc_fcntl.h"
#include "libc/libc_dirent.h"
#include "libc/libc_signal.h"
#include "libc/libc_fdset.h"
-#include "libc/libc_limits.h"
#include "libc/libc_stdio.h"
#ifndef RT_USING_LIBC
diff --git a/include/rtthread.h b/include/rtthread.h
index 784b208a76..ccd2d147a8 100644
--- a/include/rtthread.h
+++ b/include/rtthread.h
@@ -322,6 +322,7 @@ rt_mutex_t rt_mutex_create(const char *name, rt_uint8_t flag);
rt_err_t rt_mutex_delete(rt_mutex_t mutex);
rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time);
+rt_err_t rt_mutex_trytake(rt_mutex_t mutex);
rt_err_t rt_mutex_release(rt_mutex_t mutex);
rt_err_t rt_mutex_control(rt_mutex_t mutex, int cmd, void *arg);
#endif
diff --git a/libcpu/Kconfig b/libcpu/Kconfig
index bb54b487c7..d0fa40d1bd 100644
--- a/libcpu/Kconfig
+++ b/libcpu/Kconfig
@@ -57,25 +57,24 @@ config ARCH_ARM_ARM11
config ARCH_ARM_CORTEX_A
bool
select ARCH_ARM
+ select RT_USING_CPU_FFS
if ARCH_ARM_CORTEX_A
config RT_SMP_AUTO_BOOT
bool
default n
- choice
- prompt "GIC controller selection"
- default RT_USING_GIC_V2
-
- config RT_USING_GIC_V2
- bool " Gic version 2 "
+ config RT_USING_GIC_V2
+ bool
+ default n
- config RT_USING_GIC_V3
- bool " Gic version 3 "
+ config RT_USING_GIC_V3
+ bool
+ default n
- config RT_NO_USING_GIC
- bool " GIC controller is not used "
- endchoice
+ config RT_NO_USING_GIC
+ bool
+ default y if !RT_USING_GIC_V2 && !RT_USING_GIC_V3
endif
config ARCH_ARM_CORTEX_A5
diff --git a/libcpu/arm/cortex-a/cpu.c b/libcpu/arm/cortex-a/cpu.c
index 7367bddd9f..c95c58a13c 100644
--- a/libcpu/arm/cortex-a/cpu.c
+++ b/libcpu/arm/cortex-a/cpu.c
@@ -75,4 +75,21 @@ RT_WEAK void rt_hw_cpu_shutdown()
}
}
+#ifdef RT_USING_CPU_FFS
+/**
+ * This function finds the first bit set (beginning with the least significant bit)
+ * in value and return the index of that bit.
+ *
+ * Bits are numbered starting at 1 (the least significant bit). A return value of
+ * zero from any of these functions means that the argument was zero.
+ *
+ * @return return the index of the first bit set. If value is 0, then this function
+ * shall return 0.
+ */
+int __rt_ffs(int value)
+{
+ return __builtin_ffs(value);
+}
+#endif
+
/*@}*/
diff --git a/libcpu/risc-v/virt64/context_gcc.S b/libcpu/risc-v/virt64/context_gcc.S
index 881bcd162c..40803148df 100644
--- a/libcpu/risc-v/virt64/context_gcc.S
+++ b/libcpu/risc-v/virt64/context_gcc.S
@@ -9,44 +9,299 @@
* 2018/12/27 Jesven Add SMP support
* 2021/02/02 lizhirui Add userspace support
*/
-
#include "cpuport.h"
-#include "stackframe.h"
+#ifdef RT_USING_SMP
+#define rt_hw_interrupt_disable rt_hw_local_irq_disable
+#define rt_hw_interrupt_enable rt_hw_local_irq_enable
+#endif
+
+/*
+ * rt_base_t rt_hw_interrupt_disable(void);
+ */
+ .globl rt_hw_interrupt_disable
+rt_hw_interrupt_disable:
+#ifdef RISCV_S_MODE
+ csrrci a0, sstatus, 2
+#else
+ csrrci a0, mstatus, 8
+#endif
+ ret
+
+/*
+ * void rt_hw_interrupt_enable(rt_base_t level);
+ */
+ .globl rt_hw_interrupt_enable
+rt_hw_interrupt_enable:
+ csrw SRC_XSTATUS, a0
+ ret
+
+/*
+ * #ifdef RT_USING_SMP
+ * void rt_hw_context_switch_to(rt_ubase_t to, stuct rt_thread *to_thread);
+ * #else
+ * void rt_hw_context_switch_to(rt_ubase_t to);
+ * #endif
+ * a0 --> to
+ * a1 --> to_thread
+ */
.globl rt_hw_context_switch_to
rt_hw_context_switch_to:
LOAD sp, (a0)
- la s0, rt_current_thread
- LOAD s1, (s0)
-
- RESTORE_ALL
- sret
+#ifdef RT_USING_SMP
+ mv a0, a1
+ call rt_cpus_lock_status_restore
+#endif
+ LOAD a0, 2 * REGBYTES(sp)
+ csrw SRC_XSTATUS, a0
+ j rt_hw_context_switch_exit
/*
+ * #ifdef RT_USING_SMP
+ * void rt_hw_context_switch(rt_ubase_t from, rt_ubase_t to, struct rt_thread *to_thread);
+ * #else
* void rt_hw_context_switch(rt_ubase_t from, rt_ubase_t to);
+ * #endif
*
* a0 --> from
* a1 --> to
+ * a2 --> to_thread
*/
.globl rt_hw_context_switch
rt_hw_context_switch:
- mv t2, sp
- li t0, 0x120//set SPIE and SPP = 1
- csrs sstatus, t0//if enter here,caller must be in system thread
- csrw sepc, ra//return address
- //saved from thread context
- SAVE_ALL
+ /* saved from thread context
+ * x1/ra -> sp(0)
+ * x1/ra -> sp(1)
+ * mstatus.mie -> sp(2)
+ * x(i) -> sp(i-4)
+ */
+#ifdef ARCH_RISCV_FPU
+ addi sp, sp, -32 * FREGBYTES
+
+ FSTORE f0, 0 * FREGBYTES(sp)
+ FSTORE f1, 1 * FREGBYTES(sp)
+ FSTORE f2, 2 * FREGBYTES(sp)
+ FSTORE f3, 3 * FREGBYTES(sp)
+ FSTORE f4, 4 * FREGBYTES(sp)
+ FSTORE f5, 5 * FREGBYTES(sp)
+ FSTORE f6, 6 * FREGBYTES(sp)
+ FSTORE f7, 7 * FREGBYTES(sp)
+ FSTORE f8, 8 * FREGBYTES(sp)
+ FSTORE f9, 9 * FREGBYTES(sp)
+ FSTORE f10, 10 * FREGBYTES(sp)
+ FSTORE f11, 11 * FREGBYTES(sp)
+ FSTORE f12, 12 * FREGBYTES(sp)
+ FSTORE f13, 13 * FREGBYTES(sp)
+ FSTORE f14, 14 * FREGBYTES(sp)
+ FSTORE f15, 15 * FREGBYTES(sp)
+ FSTORE f16, 16 * FREGBYTES(sp)
+ FSTORE f17, 17 * FREGBYTES(sp)
+ FSTORE f18, 18 * FREGBYTES(sp)
+ FSTORE f19, 19 * FREGBYTES(sp)
+ FSTORE f20, 20 * FREGBYTES(sp)
+ FSTORE f21, 21 * FREGBYTES(sp)
+ FSTORE f22, 22 * FREGBYTES(sp)
+ FSTORE f23, 23 * FREGBYTES(sp)
+ FSTORE f24, 24 * FREGBYTES(sp)
+ FSTORE f25, 25 * FREGBYTES(sp)
+ FSTORE f26, 26 * FREGBYTES(sp)
+ FSTORE f27, 27 * FREGBYTES(sp)
+ FSTORE f28, 28 * FREGBYTES(sp)
+ FSTORE f29, 29 * FREGBYTES(sp)
+ FSTORE f30, 30 * FREGBYTES(sp)
+ FSTORE f31, 31 * FREGBYTES(sp)
+
+#endif
+ addi sp, sp, -32 * REGBYTES
+ STORE sp, (a0)
+
+ STORE x1, 0 * REGBYTES(sp)
+ STORE x1, 1 * REGBYTES(sp)
+
+
+ csrr a0, SRC_XSTATUS
+#ifdef RISCV_S_MODE
+ andi a0, a0, 2
+ beqz a0, save_spie
+ li a0, 0x20
+save_spie:
+ STORE a0, 2 * REGBYTES(sp)
+#else
+ andi a0, a0, 8
+ beqz a0, save_mpie
+ li a0, 0x80
+save_mpie:
+ STORE a0, 2 * REGBYTES(sp)
+#endif
+
+ STORE x4, 4 * REGBYTES(sp)
+ STORE x5, 5 * REGBYTES(sp)
+ STORE x6, 6 * REGBYTES(sp)
+ STORE x7, 7 * REGBYTES(sp)
+ STORE x8, 8 * REGBYTES(sp)
+ STORE x9, 9 * REGBYTES(sp)
+ STORE x10, 10 * REGBYTES(sp)
+ STORE x11, 11 * REGBYTES(sp)
+ STORE x12, 12 * REGBYTES(sp)
+ STORE x13, 13 * REGBYTES(sp)
+ STORE x14, 14 * REGBYTES(sp)
+ STORE x15, 15 * REGBYTES(sp)
+ STORE x16, 16 * REGBYTES(sp)
+ STORE x17, 17 * REGBYTES(sp)
+ STORE x18, 18 * REGBYTES(sp)
+ STORE x19, 19 * REGBYTES(sp)
+ STORE x20, 20 * REGBYTES(sp)
+ STORE x21, 21 * REGBYTES(sp)
+ STORE x22, 22 * REGBYTES(sp)
+ STORE x23, 23 * REGBYTES(sp)
+ STORE x24, 24 * REGBYTES(sp)
+ STORE x25, 25 * REGBYTES(sp)
+ STORE x26, 26 * REGBYTES(sp)
+ STORE x27, 27 * REGBYTES(sp)
+ STORE x28, 28 * REGBYTES(sp)
+ STORE x29, 29 * REGBYTES(sp)
+ STORE x30, 30 * REGBYTES(sp)
+ STORE x31, 31 * REGBYTES(sp)
+
+ /* restore to thread context
+ * sp(0) -> epc;
+ * sp(1) -> ra;
+ * sp(i) -> x(i+2)
+ */
+ LOAD sp, (a1)
+
+#ifdef RT_USING_SMP
+ mv a0, a2
+ call rt_cpus_lock_status_restore
+#endif /*RT_USING_SMP*/
+
+ j rt_hw_context_switch_exit
+
+#ifdef RT_USING_SMP
+/*
+ * void rt_hw_context_switch_interrupt(void *context, rt_ubase_t from, rt_ubase_t to, struct rt_thread *to_thread);
+ *
+ * a0 --> context
+ * a1 --> from
+ * a2 --> to
+ * a3 --> to_thread
+ */
+ .globl rt_hw_context_switch_interrupt
+rt_hw_context_switch_interrupt:
+
+ STORE a0, 0(a1)
+
+ LOAD sp, 0(a2)
+ move a0, a3
+ call rt_cpus_lock_status_restore
+
+ j rt_hw_context_switch_exit
+
+#endif
+
+.global rt_hw_context_switch_exit
+rt_hw_context_switch_exit:
+#ifdef RT_USING_SMP
+#ifdef RT_USING_SIGNALS
+ mv a0, sp
+
+ csrr t0, mhartid
+ /* switch interrupt stack of current cpu */
+ la sp, __stack_start__
+ addi t1, t0, 1
+ li t2, __STACKSIZE__
+ mul t1, t1, t2
+ add sp, sp, t1 /* sp = (cpuid + 1) * __STACKSIZE__ + __stack_start__ */
+
+ call rt_signal_check
+ mv sp, a0
+#endif
+#endif
+ /* resw ra to mepc */
+ LOAD a0, 0 * REGBYTES(sp)
+ csrw SRC_XEPC, a0
+
+ LOAD x1, 1 * REGBYTES(sp)
+
+#ifdef RISCV_S_MODE
+ li t0, 0x00000120
+ csrw sstatus, t0
+ LOAD a0, 2 * REGBYTES(sp)
+ csrs sstatus, a0
+#else
+ li t0, 0x00007800
+ csrw mstatus, t0
+ LOAD a0, 2 * REGBYTES(sp)
+ csrs mstatus, a0
+#endif
- STORE t2, 32 * REGBYTES(sp)//save user_sp
+ LOAD x4, 4 * REGBYTES(sp)
+ LOAD x5, 5 * REGBYTES(sp)
+ LOAD x6, 6 * REGBYTES(sp)
+ LOAD x7, 7 * REGBYTES(sp)
+ LOAD x8, 8 * REGBYTES(sp)
+ LOAD x9, 9 * REGBYTES(sp)
+ LOAD x10, 10 * REGBYTES(sp)
+ LOAD x11, 11 * REGBYTES(sp)
+ LOAD x12, 12 * REGBYTES(sp)
+ LOAD x13, 13 * REGBYTES(sp)
+ LOAD x14, 14 * REGBYTES(sp)
+ LOAD x15, 15 * REGBYTES(sp)
+ LOAD x16, 16 * REGBYTES(sp)
+ LOAD x17, 17 * REGBYTES(sp)
+ LOAD x18, 18 * REGBYTES(sp)
+ LOAD x19, 19 * REGBYTES(sp)
+ LOAD x20, 20 * REGBYTES(sp)
+ LOAD x21, 21 * REGBYTES(sp)
+ LOAD x22, 22 * REGBYTES(sp)
+ LOAD x23, 23 * REGBYTES(sp)
+ LOAD x24, 24 * REGBYTES(sp)
+ LOAD x25, 25 * REGBYTES(sp)
+ LOAD x26, 26 * REGBYTES(sp)
+ LOAD x27, 27 * REGBYTES(sp)
+ LOAD x28, 28 * REGBYTES(sp)
+ LOAD x29, 29 * REGBYTES(sp)
+ LOAD x30, 30 * REGBYTES(sp)
+ LOAD x31, 31 * REGBYTES(sp)
- STORE sp, (a0)
+ addi sp, sp, 32 * REGBYTES
- //restore to thread context
- LOAD sp, (a1)
+#ifdef ARCH_RISCV_FPU
+ FLOAD f0, 0 * FREGBYTES(sp)
+ FLOAD f1, 1 * FREGBYTES(sp)
+ FLOAD f2, 2 * FREGBYTES(sp)
+ FLOAD f3, 3 * FREGBYTES(sp)
+ FLOAD f4, 4 * FREGBYTES(sp)
+ FLOAD f5, 5 * FREGBYTES(sp)
+ FLOAD f6, 6 * FREGBYTES(sp)
+ FLOAD f7, 7 * FREGBYTES(sp)
+ FLOAD f8, 8 * FREGBYTES(sp)
+ FLOAD f9, 9 * FREGBYTES(sp)
+ FLOAD f10, 10 * FREGBYTES(sp)
+ FLOAD f11, 11 * FREGBYTES(sp)
+ FLOAD f12, 12 * FREGBYTES(sp)
+ FLOAD f13, 13 * FREGBYTES(sp)
+ FLOAD f14, 14 * FREGBYTES(sp)
+ FLOAD f15, 15 * FREGBYTES(sp)
+ FLOAD f16, 16 * FREGBYTES(sp)
+ FLOAD f17, 17 * FREGBYTES(sp)
+ FLOAD f18, 18 * FREGBYTES(sp)
+ FLOAD f19, 19 * FREGBYTES(sp)
+ FLOAD f20, 20 * FREGBYTES(sp)
+ FLOAD f21, 21 * FREGBYTES(sp)
+ FLOAD f22, 22 * FREGBYTES(sp)
+ FLOAD f23, 23 * FREGBYTES(sp)
+ FLOAD f24, 24 * FREGBYTES(sp)
+ FLOAD f25, 25 * FREGBYTES(sp)
+ FLOAD f26, 26 * FREGBYTES(sp)
+ FLOAD f27, 27 * FREGBYTES(sp)
+ FLOAD f28, 28 * FREGBYTES(sp)
+ FLOAD f29, 29 * FREGBYTES(sp)
+ FLOAD f30, 30 * FREGBYTES(sp)
+ FLOAD f31, 31 * FREGBYTES(sp)
- la s0, rt_current_thread
- LOAD s1, (s0)
+ addi sp, sp, 32 * FREGBYTES
+#endif
- RESTORE_ALL
- sret
+ XRET
diff --git a/libcpu/risc-v/virt64/cpuport.c b/libcpu/risc-v/virt64/cpuport.c
index 50929125ac..33cab19488 100644
--- a/libcpu/risc-v/virt64/cpuport.c
+++ b/libcpu/risc-v/virt64/cpuport.c
@@ -18,17 +18,17 @@
/**
* @brief from thread used interrupt context switch
- *
+ *
*/
volatile rt_ubase_t rt_interrupt_from_thread = 0;
/**
* @brief to thread used interrupt context switch
- *
+ *
*/
volatile rt_ubase_t rt_interrupt_to_thread = 0;
/**
* @brief flag to indicate context switch in interrupt or not
- *
+ *
*/
volatile rt_ubase_t rt_thread_switch_interrupt_flag = 0;
@@ -70,8 +70,11 @@ rt_uint8_t *rt_hw_stack_init(void *tentry,
frame->epc = (rt_ubase_t)tentry;
frame->user_sp_exc_stack = (rt_ubase_t)(((rt_ubase_t)stk) + sizeof(struct rt_hw_stack_frame));
- /* force to supervisor mode(SPP=1) and set SPIE and SUM to 1 */
- frame->sstatus = 0x00040120;
+#ifndef RISCV_S_MODE
+ frame->xstatus = 0x00007880;
+#else
+ frame->xstatus = 0x00040120;
+#endif
return stk;
}
diff --git a/libcpu/risc-v/virt64/cpuport.h b/libcpu/risc-v/virt64/cpuport.h
index bb838def4a..fa0776b509 100644
--- a/libcpu/risc-v/virt64/cpuport.h
+++ b/libcpu/risc-v/virt64/cpuport.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -22,7 +22,34 @@
// error here, not portable
#endif
-#endif
#ifdef RISCV_U_MODE
#define RISCV_USER_ENTRY 0xFFFFFFE000000000ULL
-#endif \ No newline at end of file
+#endif
+
+#ifdef RISCV_S_MODE
+//csr in s-mode
+// M/U/S Interrupt Registers
+#define SRC_XIE sie
+#define SRC_XIP sip
+#define SRC_XTVEC stvec
+#define SRC_XSTATUS sstatus
+#define SRC_XSCRATCH sscratch
+#define SRC_XEPC sepc
+#define SRC_XCAUSE scause
+#define SRC_XTVAL stval
+#define XRET sret
+#else
+//csr in m-mode
+// M/U/S Interrupt Registers
+#define SRC_XIE mie
+#define SRC_XIP mip
+#define SRC_XTVEC mtvec
+#define SRC_XSTATUS mstatus
+#define SRC_XSCRATCH mscratch
+#define SRC_XEPC mepc
+#define SRC_XCAUSE mcause
+#define SRC_XTVAL mtval
+#define XRET mret
+#endif
+
+#endif
diff --git a/libcpu/risc-v/virt64/interrupt.c b/libcpu/risc-v/virt64/interrupt.c
new file mode 100644
index 0000000000..7916be8f6f
--- /dev/null
+++ b/libcpu/risc-v/virt64/interrupt.c
@@ -0,0 +1,274 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2018/10/01 Bernard The first version
+ * 2018/12/27 Jesven Change irq enable/disable to cpu0
+ */
+#include "tick.h"
+#include <plic.h>
+#include "encoding.h"
+#include "riscv.h"
+#include "interrupt.h"
+
+#define CPU_NUM 2
+#define MAX_HANDLERS 128
+
+static struct rt_irq_desc irq_desc[MAX_HANDLERS];
+
+static rt_isr_handler_t rt_hw_interrupt_handle(rt_uint32_t vector, void *param)
+{
+ rt_kprintf("UN-handled interrupt %d occurred!!!\n", vector);
+ return RT_NULL;
+}
+
+int rt_hw_clint_ipi_enable(void)
+{
+ /* Set the Machine-Software bit in MIE */
+ set_csr(mie, MIP_MSIP);
+ return 0;
+}
+
+int rt_hw_clint_ipi_disable(void)
+{
+ /* Clear the Machine-Software bit in MIE */
+ clear_csr(mie, MIP_MSIP);
+ return 0;
+}
+
+int rt_hw_plic_irq_enable(int irq_number)
+{
+ plic_irq_enable(irq_number);
+ return 0;
+}
+
+int rt_hw_plic_irq_disable(int irq_number)
+{
+ plic_irq_disable(irq_number);
+ return 0;
+}
+
+/**
+ * This function will initialize hardware interrupt
+ */
+void rt_hw_interrupt_init(void)
+{
+ int idx = 0;
+ /* init exceptions table */
+ for (idx = 0; idx < MAX_HANDLERS; idx++)
+ {
+ //rt_hw_interrupt_mask(idx);
+ irq_desc[idx].handler = (rt_isr_handler_t)rt_hw_interrupt_handle;
+ irq_desc[idx].param = RT_NULL;
+#ifdef RT_USING_INTERRUPT_INFO
+ rt_snprintf(irq_desc[idx].name, RT_NAME_MAX - 1, "default");
+ irq_desc[idx].counter = 0;
+#endif
+ }
+}
+
+/**
+ * This function will mask a interrupt.
+ * @param vector the interrupt number
+ */
+void rt_hw_interrupt_mask(int vector)
+{
+ rt_hw_plic_irq_disable(vector);
+}
+
+/**
+ * This function will un-mask a interrupt.
+ * @param vector the interrupt number
+ */
+void rt_hw_interrupt_umask(int vector)
+{
+ plic_set_priority(vector, 1);
+ plic_set_threshold(0);
+ rt_hw_plic_irq_enable(vector);
+}
+
+/**
+ * This function will install a interrupt service routine to a interrupt.
+ * @param vector the interrupt number
+ * @param new_handler the interrupt service routine to be installed
+ * @param old_handler the old interrupt service routine
+ */
+rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
+ void *param, const char *name)
+{
+ rt_isr_handler_t old_handler = RT_NULL;
+
+ if(vector < MAX_HANDLERS)
+ {
+ old_handler = irq_desc[vector].handler;
+ if (handler != RT_NULL)
+ {
+ irq_desc[vector].handler = (rt_isr_handler_t)handler;
+ irq_desc[vector].param = param;
+#ifdef RT_USING_INTERRUPT_INFO
+ rt_snprintf(irq_desc[vector].name, RT_NAME_MAX - 1, "%s", name);
+ irq_desc[vector].counter = 0;
+#endif
+ }
+ }
+
+ return old_handler;
+}
+
+RT_WEAK
+void plic_irq_handle(int irq)
+{
+ rt_kprintf("UN-handled interrupt %d occurred!!!\n", irq);
+ return ;
+}
+
+void dump_regs(struct rt_hw_stack_frame *regs)
+{
+ rt_kprintf("--------------Dump Registers-----------------\n");
+
+ rt_kprintf("Function Registers:\n");
+ rt_kprintf("\tra(x1) = 0x%p\tuser_sp = 0x%p\n",regs -> ra,regs -> user_sp_exc_stack);
+ rt_kprintf("\tgp(x3) = 0x%p\ttp(x4) = 0x%p\n",regs -> gp,regs -> tp);
+ rt_kprintf("Temporary Registers:\n");
+ rt_kprintf("\tt0(x5) = 0x%p\tt1(x6) = 0x%p\n",regs -> t0,regs -> t1);
+ rt_kprintf("\tt2(x7) = 0x%p\n",regs -> t2);
+ rt_kprintf("\tt3(x28) = 0x%p\tt4(x29) = 0x%p\n",regs -> t3,regs -> t4);
+ rt_kprintf("\tt5(x30) = 0x%p\tt6(x31) = 0x%p\n",regs -> t5,regs -> t6);
+ rt_kprintf("Saved Registers:\n");
+ rt_kprintf("\ts0/fp(x8) = 0x%p\ts1(x9) = 0x%p\n",regs -> s0_fp,regs -> s1);
+ rt_kprintf("\ts2(x18) = 0x%p\ts3(x19) = 0x%p\n",regs -> s2,regs -> s3);
+ rt_kprintf("\ts4(x20) = 0x%p\ts5(x21) = 0x%p\n",regs -> s4,regs -> s5);
+ rt_kprintf("\ts6(x22) = 0x%p\ts7(x23) = 0x%p\n",regs -> s6,regs -> s7);
+ rt_kprintf("\ts8(x24) = 0x%p\ts9(x25) = 0x%p\n",regs -> s8,regs -> s9);
+ rt_kprintf("\ts10(x26) = 0x%p\ts11(x27) = 0x%p\n",regs -> s10,regs -> s11);
+ rt_kprintf("Function Arguments Registers:\n");
+ rt_kprintf("\ta0(x10) = 0x%p\ta1(x11) = 0x%p\n",regs -> a0,regs -> a1);
+ rt_kprintf("\ta2(x12) = 0x%p\ta3(x13) = 0x%p\n",regs -> a2,regs -> a3);
+ rt_kprintf("\ta4(x14) = 0x%p\ta5(x15) = 0x%p\n",regs -> a4,regs -> a5);
+ rt_kprintf("\ta6(x16) = 0x%p\ta7(x17) = 0x%p\n",regs -> a6,regs -> a7);
+ rt_kprintf("xstatus = 0x%p\n",regs -> xstatus);
+ rt_kprintf("\t%s\n",(regs -> xstatus & SSTATUS_SIE) ? "Supervisor Interrupt Enabled" : "Supervisor Interrupt Disabled");
+ rt_kprintf("\t%s\n",(regs -> xstatus & SSTATUS_SPIE) ? "Last Time Supervisor Interrupt Enabled" : "Last Time Supervisor Interrupt Disabled");
+ rt_kprintf("\t%s\n",(regs -> xstatus & SSTATUS_SPP) ? "Last Privilege is Supervisor Mode" : "Last Privilege is User Mode");
+ rt_kprintf("\t%s\n",(regs -> xstatus & SSTATUS_PUM) ? "Permit to Access User Page" : "Not Permit to Access User Page");
+ rt_kprintf("\t%s\n",(regs -> xstatus & (1 << 19)) ? "Permit to Read Executable-only Page" : "Not Permit to Read Executable-only Page");
+ rt_size_t satp_v = read_csr(satp);
+ rt_kprintf("satp = 0x%p\n",satp_v);
+ const char *mode_str = "Unknown Address Translation/Protection Mode";
+
+ switch(__MASKVALUE(satp_v >> 60,__MASK(4)))
+ {
+ case 0:
+ mode_str = "No Address Translation/Protection Mode";
+ break;
+
+ case 8:
+ mode_str = "Page-based 39-bit Virtual Addressing Mode";
+ break;
+
+ case 9:
+ mode_str = "Page-based 48-bit Virtual Addressing Mode";
+ break;
+ }
+
+ rt_kprintf("\tMode = %s\n",mode_str);
+ rt_kprintf("-----------------Dump OK---------------------\n");
+}
+
+void handle_trap(rt_size_t xcause,rt_size_t xtval,rt_size_t xepc,struct rt_hw_stack_frame *sp)
+{
+ int cause = (xcause & 0xFFFFFFFF);
+ int plic_irq = 0;
+ if (xcause & (1UL << 63))
+ {
+ switch (cause)
+ {
+ case IRQ_M_SOFT:
+ {
+
+ }
+ break;
+ case IRQ_M_TIMER:
+ tick_isr();
+ break;
+ case IRQ_S_TIMER:
+ tick_isr();
+ break;
+ case IRQ_S_EXT:
+ plic_irq = plic_claim();
+ plic_complete(plic_irq);
+ irq_desc[plic_irq].handler(plic_irq, irq_desc[plic_irq].param);
+ break;
+ case IRQ_M_EXT:
+ plic_irq = plic_claim();
+ plic_complete(plic_irq);
+ irq_desc[plic_irq].handler(plic_irq, irq_desc[plic_irq].param);
+ break;
+ }
+ }
+ else
+ {
+ rt_thread_t tid;
+ extern long list_thread();
+
+ rt_hw_interrupt_disable();
+
+ rt_kprintf("xcause = %08x,xtval = %08x,xepc = %08x\n", xcause, xtval, xepc);
+ tid = rt_thread_self();
+ rt_kprintf("\nException:\n");
+ switch (cause)
+ {
+ case CAUSE_MISALIGNED_FETCH:
+ rt_kprintf("Instruction address misaligned");
+ break;
+ case CAUSE_FAULT_FETCH:
+ rt_kprintf("Instruction access fault");
+ break;
+ case CAUSE_ILLEGAL_INSTRUCTION:
+ rt_kprintf("Illegal instruction");
+ break;
+ case CAUSE_BREAKPOINT:
+ rt_kprintf("Breakpoint");
+ break;
+ case CAUSE_MISALIGNED_LOAD:
+ rt_kprintf("Load address misaligned");
+ break;
+ case CAUSE_FAULT_LOAD:
+ rt_kprintf("Load access fault");
+ break;
+ case CAUSE_MISALIGNED_STORE:
+ rt_kprintf("Store address misaligned");
+ break;
+ case CAUSE_FAULT_STORE:
+ rt_kprintf("Store access fault");
+ break;
+ case CAUSE_USER_ECALL:
+ rt_kprintf("Environment call from U-mode");
+ break;
+ case CAUSE_SUPERVISOR_ECALL:
+ rt_kprintf("Environment call from S-mode");
+ break;
+ case CAUSE_HYPERVISOR_ECALL:
+ rt_kprintf("Environment call from H-mode");
+ break;
+ case CAUSE_MACHINE_ECALL:
+ rt_kprintf("Environment call from M-mode");
+ break;
+ default:
+ rt_kprintf("Uknown exception : %08lX", cause);
+ break;
+ }
+ rt_kprintf("\n");
+ dump_regs(sp);
+ rt_kprintf("exception pc => 0x%08x\n", xepc);
+ rt_kprintf("current thread: %.*s\n", RT_NAME_MAX, tid->name);
+#ifdef RT_USING_FINSH
+ list_thread();
+#endif
+ while(1);
+ }
+ rt_hw_interrupt_enable(0);
+}
diff --git a/libcpu/risc-v/virt64/interrupt.h b/libcpu/risc-v/virt64/interrupt.h
new file mode 100644
index 0000000000..e49f0215bf
--- /dev/null
+++ b/libcpu/risc-v/virt64/interrupt.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2006-2021, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2021-05-20 bigmagic The first version
+ */
+
+#ifndef INTERRUPT_H__
+#define INTERRUPT_H__
+
+#include <rthw.h>
+#include "stack.h"
+
+int rt_hw_clint_ipi_enable(void);
+int rt_hw_clint_ipi_disable(void);
+int rt_hw_plic_irq_enable(int irq_number);
+int rt_hw_plic_irq_disable(int irq_number);
+void rt_hw_interrupt_init(void);
+void rt_hw_interrupt_mask(int vector);
+rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
+ void *param, const char *name);
+void handle_trap(rt_size_t xcause,rt_size_t xtval,rt_size_t xepc,struct rt_hw_stack_frame *sp);
+
+#endif
diff --git a/libcpu/risc-v/virt64/interrupt_gcc.S b/libcpu/risc-v/virt64/interrupt_gcc.S
index 338413866e..730fa10d61 100644
--- a/libcpu/risc-v/virt64/interrupt_gcc.S
+++ b/libcpu/risc-v/virt64/interrupt_gcc.S
@@ -11,72 +11,131 @@
*/
#include "cpuport.h"
-#include "encoding.h"
-#include "stackframe.h"
.section .text.entry
.align 2
.global trap_entry
- .extern __stack_cpu0
- .extern get_current_thread_kernel_stack_top
trap_entry:
- //backup sp
- csrrw sp, sscratch, sp
- //load interrupt stack
- la sp, __stack_cpu0
- //backup context
- SAVE_ALL
-
- RESTORE_SYS_GP
+#ifdef ARCH_RISCV_FPU
+ addi sp, sp, -32 * FREGBYTES
- csrr a0, scause
- csrrc a1, stval, zero
- csrr a2, sepc
- mv a3, sp
+ FSTORE f0, 0 * FREGBYTES(sp)
+ FSTORE f1, 1 * FREGBYTES(sp)
+ FSTORE f2, 2 * FREGBYTES(sp)
+ FSTORE f3, 3 * FREGBYTES(sp)
+ FSTORE f4, 4 * FREGBYTES(sp)
+ FSTORE f5, 5 * FREGBYTES(sp)
+ FSTORE f6, 6 * FREGBYTES(sp)
+ FSTORE f7, 7 * FREGBYTES(sp)
+ FSTORE f8, 8 * FREGBYTES(sp)
+ FSTORE f9, 9 * FREGBYTES(sp)
+ FSTORE f10, 10 * FREGBYTES(sp)
+ FSTORE f11, 11 * FREGBYTES(sp)
+ FSTORE f12, 12 * FREGBYTES(sp)
+ FSTORE f13, 13 * FREGBYTES(sp)
+ FSTORE f14, 14 * FREGBYTES(sp)
+ FSTORE f15, 15 * FREGBYTES(sp)
+ FSTORE f16, 16 * FREGBYTES(sp)
+ FSTORE f17, 17 * FREGBYTES(sp)
+ FSTORE f18, 18 * FREGBYTES(sp)
+ FSTORE f19, 19 * FREGBYTES(sp)
+ FSTORE f20, 20 * FREGBYTES(sp)
+ FSTORE f21, 21 * FREGBYTES(sp)
+ FSTORE f22, 22 * FREGBYTES(sp)
+ FSTORE f23, 23 * FREGBYTES(sp)
+ FSTORE f24, 24 * FREGBYTES(sp)
+ FSTORE f25, 25 * FREGBYTES(sp)
+ FSTORE f26, 26 * FREGBYTES(sp)
+ FSTORE f27, 27 * FREGBYTES(sp)
+ FSTORE f28, 28 * FREGBYTES(sp)
+ FSTORE f29, 29 * FREGBYTES(sp)
+ FSTORE f30, 30 * FREGBYTES(sp)
+ FSTORE f31, 31 * FREGBYTES(sp)
- /* scause, stval, sepc, sp */
- call handle_trap
+#endif
- /* need to switch new thread */
- la s0, rt_thread_switch_interrupt_flag
- lw s2, 0(s0)
- beqz s2, spurious_interrupt
- sw zero, 0(s0)
+ /* save thread context to thread stack */
+ addi sp, sp, -32 * REGBYTES
-.global rt_hw_context_switch_interrupt_do
-rt_hw_context_switch_interrupt_do:
+ STORE x1, 1 * REGBYTES(sp)
-//switch to thread kernel stack
- csrr t0, sstatus
- andi t0, t0, 0x100
- beqz t0, __restore_sp_from_tcb_interrupt
+ csrr x1, SRC_XSTATUS
+ STORE x1, 2 * REGBYTES(sp)
-__restore_sp_from_sscratch_interrupt:
- csrr t0, sscratch
- j __move_stack_context_interrupt
+ csrr x1, SRC_XEPC
+ STORE x1, 0 * REGBYTES(sp)
-__restore_sp_from_tcb_interrupt:
- la s0, rt_interrupt_from_thread
- LOAD a0, 0(s0)
- jal rt_thread_sp_to_thread
- jal get_thread_kernel_stack_top
- mv t0, a0
+ STORE x4, 4 * REGBYTES(sp)
+ STORE x5, 5 * REGBYTES(sp)
+ STORE x6, 6 * REGBYTES(sp)
+ STORE x7, 7 * REGBYTES(sp)
+ STORE x8, 8 * REGBYTES(sp)
+ STORE x9, 9 * REGBYTES(sp)
+ STORE x10, 10 * REGBYTES(sp)
+ STORE x11, 11 * REGBYTES(sp)
+ STORE x12, 12 * REGBYTES(sp)
+ STORE x13, 13 * REGBYTES(sp)
+ STORE x14, 14 * REGBYTES(sp)
+ STORE x15, 15 * REGBYTES(sp)
+ STORE x16, 16 * REGBYTES(sp)
+ STORE x17, 17 * REGBYTES(sp)
+ STORE x18, 18 * REGBYTES(sp)
+ STORE x19, 19 * REGBYTES(sp)
+ STORE x20, 20 * REGBYTES(sp)
+ STORE x21, 21 * REGBYTES(sp)
+ STORE x22, 22 * REGBYTES(sp)
+ STORE x23, 23 * REGBYTES(sp)
+ STORE x24, 24 * REGBYTES(sp)
+ STORE x25, 25 * REGBYTES(sp)
+ STORE x26, 26 * REGBYTES(sp)
+ STORE x27, 27 * REGBYTES(sp)
+ STORE x28, 28 * REGBYTES(sp)
+ STORE x29, 29 * REGBYTES(sp)
+ STORE x30, 30 * REGBYTES(sp)
+ STORE x31, 31 * REGBYTES(sp)
+
+ /* switch to interrupt stack */
+ move s0, sp
+
+#ifndef RISCV_S_MODE
+ /* get cpu id */
+ csrr t0, mhartid
+#else
+ li t0, 0
+#endif
+
+ /* switch interrupt stack of current cpu */
+ la sp, __stack_start__
+ addi t1, t0, 1
+ li t2, __STACKSIZE__
+ mul t1, t1, t2
+ add sp, sp, t1 /* sp = (cpuid + 1) * __STACKSIZE__ + __stack_start__ */
+
+ /* handle interrupt */
+ call rt_interrupt_enter
+ csrr a0, SRC_XCAUSE
+ csrr a1, SRC_XEPC
+ mv a2, s0
+ call handle_trap
+ call rt_interrupt_leave
+
+#ifdef RT_USING_SMP
+ /* s0 --> sp */
+ mv sp, s0
+ mv a0, s0
+ call rt_scheduler_do_irq_switch
+ tail rt_hw_context_switch_exit
-__move_stack_context_interrupt:
- mv t1, sp//src
- mv sp, t0//switch stack
- addi sp, sp, -33 * REGBYTES
- //copy context
- li s0, 33//cnt
- mv t2, sp//dst
+#else
-copy_context_loop_interrupt:
- LOAD t0, 0(t1)
- STORE t0, 0(t2)
- addi s0, s0, -1
- addi t1, t1, 8
- addi t2, t2, 8
- bnez s0, copy_context_loop_interrupt
+ /* switch to from_thread stack */
+ move sp, s0
+
+ /* need to switch new thread */
+ la s0, rt_thread_switch_interrupt_flag
+ lw s2, 0(s0)
+ beqz s2, spurious_interrupt
+ sw zero, 0(s0)
la s0, rt_interrupt_from_thread
LOAD s1, 0(s0)
@@ -86,16 +145,7 @@ copy_context_loop_interrupt:
LOAD s1, 0(s0)
LOAD sp, 0(s1)
-spurious_interrupt:
- RESTORE_ALL
- sret
+#endif
-.global rt_hw_interrupt_enable
-rt_hw_interrupt_enable:
- csrs sstatus, a0
- jr ra
-
-.global rt_hw_interrupt_disable
-rt_hw_interrupt_disable:
- csrrci a0, sstatus, 2
- jr ra
+spurious_interrupt:
+ tail rt_hw_context_switch_exit
diff --git a/libcpu/risc-v/virt64/riscv.h b/libcpu/risc-v/virt64/riscv.h
index 04ac4fea74..d0c0cc4b38 100644
--- a/libcpu/risc-v/virt64/riscv.h
+++ b/libcpu/risc-v/virt64/riscv.h
@@ -26,4 +26,4 @@
#define __ALIGNUP(value,bit) (((value) + __MASK(bit)) & __UMASK(bit))
#define __ALIGNDOWN(value,bit) ((value) & __UMASK(bit))
-#endif \ No newline at end of file
+#endif
diff --git a/libcpu/risc-v/virt64/riscv_io.h b/libcpu/risc-v/virt64/riscv_io.h
index 8363ff23f8..391d7f5a41 100644
--- a/libcpu/risc-v/virt64/riscv_io.h
+++ b/libcpu/risc-v/virt64/riscv_io.h
@@ -10,100 +10,128 @@
#ifndef __RISCV_IO_H__
#define __RISCV_IO_H__
- static inline void __raw_writeb(rt_uint8_t val, volatile void *addr)
- {
- asm volatile("sb %0, 0(%1)" : : "r"(val), "r"(addr));
- }
+// which hart (core) is this?
+static inline uint32_t r_mhartid()
+{
+#ifndef RISCV_S_MODE
+ uint32_t x;
+ asm volatile("csrr %0, mhartid" : "=r" (x) );
+ return x;
+#else
+ return 0;
+#endif
+}
- static inline void __raw_writew(rt_uint16_t val, volatile void *addr)
- {
- asm volatile("sh %0, 0(%1)" : : "r"(val), "r"(addr));
- }
+static inline void __raw_writeb(rt_uint8_t val, volatile void *addr)
+{
+ asm volatile("sb %0, 0(%1)"
+ :
+ : "r"(val), "r"(addr));
+}
- static inline void __raw_writel(rt_uint32_t val, volatile void *addr)
- {
- asm volatile("sw %0, 0(%1)" : : "r"(val), "r"(addr));
- }
+static inline void __raw_writew(rt_uint16_t val, volatile void *addr)
+{
+ asm volatile("sh %0, 0(%1)"
+ :
+ : "r"(val), "r"(addr));
+}
- #if __riscv_xlen != 32
- static inline void __raw_writeq(rt_uint64_t val, volatile void *addr)
- {
- asm volatile("sd %0, 0(%1)" : : "r"(val), "r"(addr));
- }
- #endif
+static inline void __raw_writel(rt_uint32_t val, volatile void *addr)
+{
+ asm volatile("sw %0, 0(%1)"
+ :
+ : "r"(val), "r"(addr));
+}
- static inline rt_uint8_t __raw_readb(const volatile void *addr)
- {
- rt_uint8_t val;
+#if __riscv_xlen != 32
+static inline void __raw_writeq(rt_uint64_t val, volatile void *addr)
+{
+ asm volatile("sd %0, 0(%1)"
+ :
+ : "r"(val), "r"(addr));
+}
+#endif
- asm volatile("lb %0, 0(%1)" : "=r"(val) : "r"(addr));
- return val;
- }
+static inline rt_uint8_t __raw_readb(const volatile void *addr)
+{
+ rt_uint8_t val;
- static inline rt_uint16_t __raw_readw(const volatile void *addr)
- {
- rt_uint16_t val;
+ asm volatile("lb %0, 0(%1)"
+ : "=r"(val)
+ : "r"(addr));
+ return val;
+}
- asm volatile("lh %0, 0(%1)" : "=r"(val) : "r"(addr));
- return val;
- }
+static inline rt_uint16_t __raw_readw(const volatile void *addr)
+{
+ rt_uint16_t val;
- static inline rt_uint32_t __raw_readl(const volatile void *addr)
- {
- rt_uint32_t val;
+ asm volatile("lh %0, 0(%1)"
+ : "=r"(val)
+ : "r"(addr));
+ return val;
+}
- asm volatile("lw %0, 0(%1)" : "=r"(val) : "r"(addr));
- return val;
- }
+static inline rt_uint32_t __raw_readl(const volatile void *addr)
+{
+ rt_uint32_t val;
- #if __riscv_xlen != 32
- static inline rt_uint64_t __raw_readq(const volatile void *addr)
- {
- rt_uint64_t val;
+ asm volatile("lw %0, 0(%1)"
+ : "=r"(val)
+ : "r"(addr));
+ return val;
+}
- asm volatile("ld %0, 0(%1)" : "=r"(val) : "r"(addr));
- return val;
- }
- #endif
+#if __riscv_xlen != 32
+static inline rt_uint64_t __raw_readq(const volatile void *addr)
+{
+ rt_uint64_t val;
- /* FIXME: These are now the same as asm-generic */
+ asm volatile("ld %0, 0(%1)"
+ : "=r"(val)
+ : "r"(addr));
+ return val;
+}
+#endif
- /* clang-format off */
+/* FIXME: These are now the same as asm-generic */
- #define __io_rbr() do {} while (0)
- #define __io_rar() do {} while (0)
- #define __io_rbw() do {} while (0)
- #define __io_raw() do {} while (0)
+/* clang-format off */
- #define readb_relaxed(c) ({ rt_uint8_t __v; __io_rbr(); __v = __raw_readb(c); __io_rar(); __v; })
- #define readw_relaxed(c) ({ rt_uint16_t __v; __io_rbr(); __v = __raw_readw(c); __io_rar(); __v; })
- #define readl_relaxed(c) ({ rt_uint32_t __v; __io_rbr(); __v = __raw_readl(c); __io_rar(); __v; })
+#define __io_rbr() do {} while (0)
+#define __io_rar() do {} while (0)
+#define __io_rbw() do {} while (0)
+#define __io_raw() do {} while (0)
- #define writeb_relaxed(v,c) ({ __io_rbw(); __raw_writeb((v),(c)); __io_raw(); })
- #define writew_relaxed(v,c) ({ __io_rbw(); __raw_writew((v),(c)); __io_raw(); })
- #define writel_relaxed(v,c) ({ __io_rbw(); __raw_writel((v),(c)); __io_raw(); })
+#define readb_relaxed(c) ({ rt_uint8_t __v; __io_rbr(); __v = __raw_readb(c); __io_rar(); __v; })
+#define readw_relaxed(c) ({ rt_uint16_t __v; __io_rbr(); __v = __raw_readw(c); __io_rar(); __v; })
+#define readl_relaxed(c) ({ rt_uint32_t __v; __io_rbr(); __v = __raw_readl(c); __io_rar(); __v; })
- #if __riscv_xlen != 32
- #define readq_relaxed(c) ({ rt_uint64_t __v; __io_rbr(); __v = __raw_readq(c); __io_rar(); __v; })
- #define writeq_relaxed(v,c) ({ __io_rbw(); __raw_writeq((v),(c)); __io_raw(); })
- #endif
+#define writeb_relaxed(v,c) ({ __io_rbw(); __raw_writeb((v),(c)); __io_raw(); })
+#define writew_relaxed(v,c) ({ __io_rbw(); __raw_writew((v),(c)); __io_raw(); })
+#define writel_relaxed(v,c) ({ __io_rbw(); __raw_writel((v),(c)); __io_raw(); })
- #define __io_br() do {} while (0)
- #define __io_ar() __asm__ __volatile__ ("fence i,r" : : : "memory");
- #define __io_bw() __asm__ __volatile__ ("fence w,o" : : : "memory");
- #define __io_aw() do {} while (0)
+#if __riscv_xlen != 32
+#define readq_relaxed(c) ({ rt_uint64_t __v; __io_rbr(); __v = __raw_readq(c); __io_rar(); __v; })
+#define writeq_relaxed(v,c) ({ __io_rbw(); __raw_writeq((v),(c)); __io_raw(); })
+#endif
- #define readb(c) ({ rt_uint8_t __v; __io_br(); __v = __raw_readb(c); __io_ar(); __v; })
- #define readw(c) ({ rt_uint16_t __v; __io_br(); __v = __raw_readw(c); __io_ar(); __v; })
- #define readl(c) ({ rt_uint32_t __v; __io_br(); __v = __raw_readl(c); __io_ar(); __v; })
+#define __io_br() do {} while (0)
+#define __io_ar() __asm__ __volatile__ ("fence i,r" : : : "memory");
+#define __io_bw() __asm__ __volatile__ ("fence w,o" : : : "memory");
+#define __io_aw() do {} while (0)
- #define writeb(v,c) ({ __io_bw(); __raw_writeb((v),(c)); __io_aw(); })
- #define writew(v,c) ({ __io_bw(); __raw_writew((v),(c)); __io_aw(); })
- #define writel(v,c) ({ __io_bw(); __raw_writel((v),(c)); __io_aw(); })
+#define readb(c) ({ rt_uint8_t __v; __io_br(); __v = __raw_readb(c); __io_ar(); __v; })
+#define readw(c) ({ rt_uint16_t __v; __io_br(); __v = __raw_readw(c); __io_ar(); __v; })
+#define readl(c) ({ rt_uint32_t __v; __io_br(); __v = __raw_readl(c); __io_ar(); __v; })
- #if __riscv_xlen != 32
- #define readq(c) ({ rt_uint64_t __v; __io_br(); __v = __raw_readq(c); __io_ar(); __v; })
- #define writeq(v,c) ({ __io_bw(); __raw_writeq((v),(c)); __io_aw(); })
- #endif
+#define writeb(v,c) ({ __io_bw(); __raw_writeb((v),(c)); __io_aw(); })
+#define writew(v,c) ({ __io_bw(); __raw_writew((v),(c)); __io_aw(); })
+#define writel(v,c) ({ __io_bw(); __raw_writel((v),(c)); __io_aw(); })
-#endif \ No newline at end of file
+#if __riscv_xlen != 32
+#define readq(c) ({ rt_uint64_t __v; __io_br(); __v = __raw_readq(c); __io_ar(); __v; })
+#define writeq(v,c) ({ __io_bw(); __raw_writeq((v),(c)); __io_aw(); })
+#endif
+
+#endif
diff --git a/libcpu/risc-v/virt64/stack.h b/libcpu/risc-v/virt64/stack.h
index 27e9cdf9fa..09179238ea 100644
--- a/libcpu/risc-v/virt64/stack.h
+++ b/libcpu/risc-v/virt64/stack.h
@@ -16,7 +16,7 @@ struct rt_hw_stack_frame
{
rt_ubase_t epc; /* epc - epc - program counter */
rt_ubase_t ra; /* x1 - ra - return address for jumps */
- rt_ubase_t sstatus; /* - supervisor status register */
+ rt_ubase_t xstatus; /* - supervisor/machine/user status register */
rt_ubase_t gp; /* x3 - gp - global pointer */
rt_ubase_t tp; /* x4 - tp - thread pointer */
rt_ubase_t t0; /* x5 - t0 - temporary register 0 */
diff --git a/libcpu/risc-v/virt64/stackframe.h b/libcpu/risc-v/virt64/stackframe.h
index e5a5271a7a..eb4e4f9d86 100644
--- a/libcpu/risc-v/virt64/stackframe.h
+++ b/libcpu/risc-v/virt64/stackframe.h
@@ -19,10 +19,10 @@
STORE x1, 1 * REGBYTES(sp)
- csrr x1, sstatus
+ csrr x1, SRC_XSTATUS
STORE x1, 2 * REGBYTES(sp)
- csrr x1, sepc
+ csrr x1, SRC_XEPC
STORE x1, 0 * REGBYTES(sp)
STORE x3, 3 * REGBYTES(sp)
@@ -54,17 +54,17 @@
STORE x29, 29 * REGBYTES(sp)
STORE x30, 30 * REGBYTES(sp)
STORE x31, 31 * REGBYTES(sp)
- csrr t0, sscratch
+ csrr t0, SRC_XSCRATCH
STORE t0, 32 * REGBYTES(sp)
.endm
.macro RESTORE_ALL_ONLY
/* resw ra to sepc */
LOAD x1, 0 * REGBYTES(sp)
- csrw sepc, x1
+ csrw SRC_XEPC, x1
LOAD x1, 2 * REGBYTES(sp)
- csrw sstatus, x1
+ csrw SRC_XSTATUS, x1
LOAD x1, 1 * REGBYTES(sp)
@@ -104,10 +104,10 @@
.macro RESTORE_ALL
/* resw ra to sepc */
LOAD x1, 0 * REGBYTES(sp)
- csrw sepc, x1
+ csrw SRC_XEPC, x1
LOAD x1, 2 * REGBYTES(sp)
- csrw sstatus, x1
+ csrw SRC_XSTATUS, x1
LOAD x1, 1 * REGBYTES(sp)
@@ -152,12 +152,4 @@
.option pop
.endm
-.macro OPEN_INTERRUPT
- csrsi sstatus, 2
-.endm
-
-.macro CLOSE_INTERRUPT
- csrci sstatus, 2
-.endm
-
-#endif \ No newline at end of file
+#endif
diff --git a/libcpu/risc-v/virt64/startup_gcc.S b/libcpu/risc-v/virt64/startup_gcc.S
index 9b1a27be9a..ac980f6ed2 100644
--- a/libcpu/risc-v/virt64/startup_gcc.S
+++ b/libcpu/risc-v/virt64/startup_gcc.S
@@ -10,71 +10,48 @@
* 2020/6/12 Xim Port to QEMU and remove SMP support
*/
-#define SSTATUS_FS 0x00006000U /* initial state of FPU, clear to disable */
+#define XSTATUS_FS (3 << 13) /* initial state of FPU, clear to disable */
+#define XSTATUS_PUM (1 << 18)
#include <cpuport.h>
.global _start
.section ".start", "ax"
_start:
- j 1f
- .word 0xdeadbeef
- .align 3
- .global g_wake_up
- g_wake_up:
- .dword 1
- .dword 0
-1:
- csrw sie, 0
- csrw sip, 0
- la t0, trap_entry
- csrw stvec, t0
+#ifndef RISCV_S_MODE
+ # setup stacks per hart
+ csrr t0, mhartid # read current hart id
+ slli t0, t0, 10 # shift left the hart id by 1024
+
+ # park harts with id != 0
+ csrr a0, mhartid # read current hart id
+ bnez a0, park # if we're not on the hart 0
+#endif
- li x1, 0
- li x2, 0
- li x3, 0
- li x4, 0
- li x5, 0
- li x6, 0
- li x7, 0
- li x8, 0
- li x9, 0
- li x10,0
- li x11,0
- li x12,0
- li x13,0
- li x14,0
- li x15,0
- li x16,0
- li x17,0
- li x18,0
- li x19,0
- li x20,0
- li x21,0
- li x22,0
- li x23,0
- li x24,0
- li x25,0
- li x26,0
- li x27,0
- li x28,0
- li x29,0
- li x30,0
- li x31,0
+ csrw SRC_XIE, 0 # clear Interrupt Registers
+ csrw SRC_XIP, 0
+
+ la t0, trap_entry
+ csrw SRC_XTVEC, t0 # set Trap Vector Base Address Register
/* set to disable FPU */
- li t0, SSTATUS_FS
- csrc sstatus, t0
- li t0, 0x40000 // SUM in sstatus
- csrs sstatus, t0
+ li t0, XSTATUS_FS # close fpu
+ csrc SRC_XSTATUS, t0
+#ifdef RISCV_S_MODE
+ li t0, XSTATUS_PUM # PUM has no effect
+ csrs SRC_XSTATUS, t0
+#endif
.option push
.option norelax
la gp, __global_pointer$
.option pop
- // removed SMP support here
la sp, __stack_start__
li t0, __STACKSIZE__
add sp, sp, t0
- csrw sscratch, sp
+ csrw SRC_XSCRATCH, sp
j primary_cpu_entry
+
+park:
+ wfi
+ j park \ No newline at end of file
diff --git a/libcpu/risc-v/virt64/tick.c b/libcpu/risc-v/virt64/tick.c
index 4f340c544f..d6970ec417 100644
--- a/libcpu/risc-v/virt64/tick.c
+++ b/libcpu/risc-v/virt64/tick.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -11,8 +11,12 @@
#include <rthw.h>
#include <rtthread.h>
-#include <encoding.h>
#include "sbi.h"
+#include "tick.h"
+#include <riscv_io.h>
+#include <encoding.h>
+
+#define VIRT_CLINT_TIMEBASE_FREQ (10000000)
static volatile uint64_t time_elapsed = 0;
static volatile unsigned long tick_cycles = 0;
@@ -27,11 +31,13 @@ static uint64_t get_ticks()
int tick_isr(void)
{
- // uint64_t core_id = current_coreid();
- int tick_cycles = 40000;
- // clint->mtimecmp[core_id] += tick_cycles;
+ int tick_cycles = VIRT_CLINT_TIMEBASE_FREQ / RT_TICK_PER_SECOND;
rt_tick_increase();
+#ifdef RISCV_S_MODE
sbi_set_timer(get_ticks() + tick_cycles);
+#else
+ *(uint64_t*)CLINT_MTIMECMP(r_mhartid()) = *(uint64_t*)CLINT_MTIME + tick_cycles;
+#endif
return 0;
}
@@ -39,10 +45,9 @@ int tick_isr(void)
/* Sets and enable the timer interrupt */
int rt_hw_tick_init(void)
{
- /* Read core id */
- // unsigned long core_id = current_coreid();
- unsigned long interval = 1000/RT_TICK_PER_SECOND;
+ unsigned long interval = VIRT_CLINT_TIMEBASE_FREQ / RT_TICK_PER_SECOND;
+#ifdef RISCV_S_MODE
/* Clear the Supervisor-Timer bit in SIE */
clear_csr(sie, SIP_STIP);
@@ -54,6 +59,11 @@ int rt_hw_tick_init(void)
/* Enable the Supervisor-Timer bit in SIE */
set_csr(sie, SIP_STIP);
-
+#else
+ clear_csr(mie, MIP_MTIP);
+ clear_csr(mip, MIP_MTIP);
+ *(uint64_t*)CLINT_MTIMECMP(r_mhartid()) = *(uint64_t*)CLINT_MTIME + interval;
+ set_csr(mie, MIP_MTIP);
+#endif
return 0;
}
diff --git a/libcpu/risc-v/virt64/tick.h b/libcpu/risc-v/virt64/tick.h
index 0821004263..c5a55cf16f 100644
--- a/libcpu/risc-v/virt64/tick.h
+++ b/libcpu/risc-v/virt64/tick.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2006-2018, RT-Thread Development Team
+ * Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -11,6 +11,11 @@
#ifndef TICK_H__
#define TICK_H__
+//ask the CLINT for a timer interrupt.
+#define CLINT (0x2000000L)
+#define CLINT_MTIMECMP(hartid) (CLINT + 0x4000 + 4*(hartid))
+#define CLINT_MTIME (CLINT + 0xBFF8) // cycles since boot.
+
int tick_isr(void);
int rt_hw_tick_init(void);
diff --git a/src/clock.c b/src/clock.c
index 0880d8d241..77516b3775 100644
--- a/src/clock.c
+++ b/src/clock.c
@@ -13,7 +13,8 @@
* 2010-07-13 Bernard fix rt_tick_from_millisecond issue found by kuronca
* 2011-06-26 Bernard add rt_tick_set function.
* 2018-11-22 Jesven add per cpu tick
- * 2020-12-29 Meco Man add function rt_tick_get_millisecond()
+ * 2020-12-29 Meco Man implement rt_tick_get_millisecond()
+ * 2021-06-01 Meco Man add critical section projection for rt_tick_increase()
*/
#include <rthw.h>
@@ -22,8 +23,8 @@
#ifdef RT_USING_SMP
#define rt_tick rt_cpu_index(0)->tick
#else
-static rt_tick_t rt_tick = 0;
-#endif
+static volatile rt_tick_t rt_tick = 0;
+#endif /* RT_USING_SMP */
/**
* @addtogroup Clock
@@ -62,13 +63,16 @@ void rt_tick_set(rt_tick_t tick)
void rt_tick_increase(void)
{
struct rt_thread *thread;
+ rt_base_t level;
+
+ level = rt_hw_interrupt_disable();
/* increase the global tick */
#ifdef RT_USING_SMP
rt_cpu_self()->tick ++;
#else
++ rt_tick;
-#endif
+#endif /* RT_USING_SMP */
/* check time slice */
thread = rt_thread_self();
@@ -78,11 +82,15 @@ void rt_tick_increase(void)
{
/* change to initialized tick */
thread->remaining_tick = thread->init_tick;
-
thread->stat |= RT_THREAD_STAT_YIELD;
+ rt_hw_interrupt_enable(level);
rt_schedule();
}
+ else
+ {
+ rt_hw_interrupt_enable(level);
+ }
/* check timer */
rt_timer_check();
@@ -130,7 +138,7 @@ RT_WEAK rt_tick_t rt_tick_get_millisecond(void)
#warning "rt-thread cannot provide a correct 1ms-based tick any longer,\
please redefine this function in another file by using a high-precision hard-timer."
return 0;
-#endif
+#endif /* 1000 % RT_TICK_PER_SECOND == 0u */
}
/**@}*/
diff --git a/src/components.c b/src/components.c
index 9709d0aae2..d684d5e6fd 100644
--- a/src/components.c
+++ b/src/components.c
@@ -23,11 +23,11 @@
#ifdef RT_USING_USER_MAIN
#ifndef RT_MAIN_THREAD_STACK_SIZE
#define RT_MAIN_THREAD_STACK_SIZE 2048
-#endif
+#endif /* RT_MAIN_THREAD_STACK_SIZE */
#ifndef RT_MAIN_THREAD_PRIORITY
#define RT_MAIN_THREAD_PRIORITY (RT_THREAD_PRIORITY_MAX / 3)
-#endif
-#endif
+#endif /* RT_MAIN_THREAD_PRIORITY */
+#endif /* RT_USING_USER_MAIN */
#ifdef RT_USING_COMPONENTS_INIT
/*
@@ -98,7 +98,7 @@ void rt_components_board_init(void)
{
(*fn_ptr)();
}
-#endif
+#endif /* RT_DEBUG_INIT */
}
/**
@@ -124,9 +124,9 @@ void rt_components_init(void)
{
(*fn_ptr)();
}
-#endif
+#endif /* RT_DEBUG_INIT */
}
-#endif /* RT_USING_COMPONENTS_INIT */
+#endif /* RT_USING_COMPONENTS_INIT */
#ifdef RT_USING_USER_MAIN
@@ -167,7 +167,7 @@ int entry(void)
ALIGN(8)
static rt_uint8_t main_stack[RT_MAIN_THREAD_STACK_SIZE];
struct rt_thread main_thread;
-#endif
+#endif /* RT_USING_HEAP */
/* the system main thread */
void main_thread_entry(void *parameter)
@@ -177,11 +177,11 @@ void main_thread_entry(void *parameter)
#ifdef RT_USING_COMPONENTS_INIT
/* RT-Thread components initialization */
rt_components_init();
-#endif
+#endif /* RT_USING_COMPONENTS_INIT */
#ifdef RT_USING_SMP
rt_hw_secondary_cpu_up();
-#endif
+#endif /* RT_USING_SMP */
/* invoke system main function */
#if defined(__CC_ARM) || defined(__CLANG_ARM)
{
@@ -211,7 +211,7 @@ void rt_application_init(void)
/* if not define RT_USING_HEAP, using to eliminate the warning */
(void)result;
-#endif
+#endif /* RT_USING_HEAP */
rt_thread_startup(tid);
}
@@ -237,7 +237,7 @@ int rtthread_startup(void)
#ifdef RT_USING_SIGNALS
/* signal system initialization */
rt_system_signal_init();
-#endif
+#endif /* RT_USING_SIGNALS */
/* create init_thread */
rt_application_init();
@@ -250,7 +250,7 @@ int rtthread_startup(void)
#ifdef RT_USING_SMP
rt_hw_spin_lock(&_cpus_lock);
-#endif /*RT_USING_SMP*/
+#endif /* RT_USING_SMP */
/* start scheduler */
rt_system_scheduler_start();
@@ -258,4 +258,4 @@ int rtthread_startup(void)
/* never reach here */
return 0;
}
-#endif
+#endif /* RT_USING_USER_MAIN */
diff --git a/src/cpu.c b/src/cpu.c
index 48ddb12c46..a7d56ba999 100644
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -185,4 +185,4 @@ void rt_cpus_lock_status_restore(struct rt_thread *thread)
}
RTM_EXPORT(rt_cpus_lock_status_restore);
-#endif
+#endif /* RT_USING_SMP */
diff --git a/src/device.c b/src/device.c
index 50b83c7692..a9c244d306 100644
--- a/src/device.c
+++ b/src/device.c
@@ -16,9 +16,9 @@
*/
#include <rtthread.h>
-#if defined(RT_USING_POSIX)
+#ifdef RT_USING_POSIX
#include <rtdevice.h> /* for wqueue_init */
-#endif
+#endif /* RT_USING_POSIX */
#ifdef RT_USING_DEVICE
@@ -36,7 +36,7 @@
#define device_read (dev->read)
#define device_write (dev->write)
#define device_control (dev->control)
-#endif
+#endif /* RT_USING_DEVICE_OPS */
/**
* This function registers a device driver with specified name.
@@ -62,10 +62,10 @@ rt_err_t rt_device_register(rt_device_t dev,
dev->ref_count = 0;
dev->open_flag = 0;
-#if defined(RT_USING_POSIX)
+#ifdef RT_USING_POSIX
dev->fops = RT_NULL;
rt_wqueue_init(&(dev->wait_queue));
-#endif
+#endif /* RT_USING_POSIX */
return RT_EOK;
}
@@ -150,7 +150,7 @@ void rt_device_destroy(rt_device_t dev)
rt_free(dev);
}
RTM_EXPORT(rt_device_destroy);
-#endif
+#endif /* RT_USING_HEAP */
/**
* This function will initialize the specified device
@@ -434,4 +434,4 @@ rt_device_set_tx_complete(rt_device_t dev,
}
RTM_EXPORT(rt_device_set_tx_complete);
-#endif
+#endif /* RT_USING_DEVICE */
diff --git a/src/idle.c b/src/idle.c
index 24dfffbc6d..db256a6010 100644
--- a/src/idle.c
+++ b/src/idle.c
@@ -22,27 +22,27 @@
#ifdef RT_USING_MODULE
#include <dlmodule.h>
-#endif
+#endif /* RT_USING_MODULE */
-#if defined (RT_USING_HOOK)
+#ifdef RT_USING_HOOK
#ifndef RT_USING_IDLE_HOOK
#define RT_USING_IDLE_HOOK
-#endif
-#endif
+#endif /* RT_USING_IDLE_HOOK */
+#endif /* RT_USING_HOOK */
#ifndef IDLE_THREAD_STACK_SIZE
#if defined (RT_USING_IDLE_HOOK) || defined(RT_USING_HEAP)
#define IDLE_THREAD_STACK_SIZE 256
#else
#define IDLE_THREAD_STACK_SIZE 128
-#endif
-#endif
+#endif /* (RT_USING_IDLE_HOOK) || defined(RT_USING_HEAP) */
+#endif /* IDLE_THREAD_STACK_SIZE */
#ifdef RT_USING_SMP
#define _CPUS_NR RT_CPUS_NR
#else
#define _CPUS_NR 1
-#endif
+#endif /* RT_USING_SMP */
extern rt_list_t rt_thread_defunct;
@@ -53,7 +53,7 @@ static rt_uint8_t rt_thread_stack[_CPUS_NR][IDLE_THREAD_STACK_SIZE];
#ifdef RT_USING_IDLE_HOOK
#ifndef RT_IDLE_HOOK_LIST_SIZE
#define RT_IDLE_HOOK_LIST_SIZE 4
-#endif
+#endif /* RT_IDLE_HOOK_LIST_SIZE */
static void (*idle_hook_list[RT_IDLE_HOOK_LIST_SIZE])(void);
@@ -125,8 +125,9 @@ rt_err_t rt_thread_idle_delhook(void (*hook)(void))
return ret;
}
-#endif
+#endif /* RT_USING_IDLE_HOOK */
+#ifdef RT_USING_HEAP
/* Return whether there is defunctional thread to be deleted. */
rt_inline int _has_defunct_thread(void)
{
@@ -140,6 +141,7 @@ rt_inline int _has_defunct_thread(void)
return l->next != l;
}
+#endif /* RT_USING_HEAP */
/**
* @ingroup Thread
@@ -180,7 +182,7 @@ void rt_thread_idle_excute(void)
rt_object_delete((rt_object_t)thread);
rt_hw_interrupt_enable(lock);
}
-#endif
+#endif /* RT_USING_HEAP */
}
extern void rt_system_power_manager(void);
@@ -194,26 +196,28 @@ static void rt_thread_idle_entry(void *parameter)
rt_hw_secondary_cpu_idle_exec();
}
}
-#endif
+#endif /* RT_USING_SMP */
while (1)
{
#ifdef RT_USING_IDLE_HOOK
rt_size_t i;
+ void (*idle_hook)(void);
for (i = 0; i < RT_IDLE_HOOK_LIST_SIZE; i++)
{
- if (idle_hook_list[i] != RT_NULL)
+ idle_hook = idle_hook_list[i];
+ if (idle_hook != RT_NULL)
{
- idle_hook_list[i]();
+ idle_hook();
}
}
-#endif
+#endif /* RT_USING_IDLE_HOOK */
rt_thread_idle_excute();
#ifdef RT_USING_PM
rt_system_power_manager();
-#endif
+#endif /* RT_USING_PM */
}
}
@@ -242,7 +246,7 @@ void rt_thread_idle_init(void)
32);
#ifdef RT_USING_SMP
rt_thread_control(&idle[i], RT_THREAD_CTRL_BIND_CPU, (void*)i);
-#endif
+#endif /* RT_USING_SMP */
/* startup */
rt_thread_startup(&idle[i]);
}
@@ -260,7 +264,7 @@ rt_thread_t rt_thread_idle_gethandler(void)
register int id = rt_hw_cpu_id();
#else
register int id = 0;
-#endif
+#endif /* RT_USING_SMP */
return (rt_thread_t)(&idle[id]);
}
diff --git a/src/ipc.c b/src/ipc.c
index 111d724c23..c981aabe43 100755
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -37,8 +37,8 @@
* 2020-07-29 Meco Man fix thread->event_set/event_info when received an
* event without pending
* 2020-10-11 Meco Man add value overflow-check code
- * 2021-01-03 Meco Man add rt_mb_urgent()
- * 2021-01-20 hupu fix priority inversion bug of mutex
+ * 2021-01-03 Meco Man implement rt_mb_urgent()
+ * 2021-05-30 Meco Man implement rt_mutex_trytake()
*/
#include <rtthread.h>
@@ -48,7 +48,7 @@
extern void (*rt_object_trytake_hook)(struct rt_object *object);
extern void (*rt_object_take_hook)(struct rt_object *object);
extern void (*rt_object_put_hook)(struct rt_object *object);
-#endif
+#endif /* RT_USING_HOOK */
/**
* @addtogroup IPC
@@ -93,7 +93,7 @@ rt_inline rt_err_t rt_ipc_list_suspend(rt_list_t *list,
{
case RT_IPC_FLAG_FIFO:
rt_list_insert_before(list, &(thread->tlist));
- break;
+ break; /* RT_IPC_FLAG_FIFO */
case RT_IPC_FLAG_PRIO:
{
@@ -121,9 +121,10 @@ rt_inline rt_err_t rt_ipc_list_suspend(rt_list_t *list,
if (n == list)
rt_list_insert_before(list, &(thread->tlist));
}
- break;
+ break;/* RT_IPC_FLAG_PRIO */
default:
+ RT_ASSERT(0);
break;
}
@@ -192,31 +193,6 @@ rt_inline rt_err_t rt_ipc_list_resume_all(rt_list_t *list)
return RT_EOK;
}
-/**
- * This function will get the highest priority from the specified
- * list of threads
- *
- * @param list of the threads
- *
- * @return the highest priority
- */
-rt_uint8_t rt_ipc_get_highest_priority(rt_list_t *list)
-{
- struct rt_list_node *n;
- struct rt_thread *sthread;
- rt_uint8_t priority = RT_THREAD_PRIORITY_MAX - 1;
-
- for (n = list->next; n != list; n = n->next)
- {
- sthread = rt_list_entry(n, struct rt_thread, tlist);
-
- priority = priority < sthread->current_priority ?
- priority :
- sthread->current_priority;
- }
- return priority;
-}
-
#ifdef RT_USING_SEMAPHORE
/**
* This function will initialize a semaphore and put it under control of
@@ -343,7 +319,7 @@ rt_err_t rt_sem_delete(rt_sem_t sem)
return RT_EOK;
}
RTM_EXPORT(rt_sem_delete);
-#endif
+#endif /* RT_USING_HEAP */
/**
* This function will take a semaphore, if the semaphore is unavailable, the
@@ -451,7 +427,7 @@ RTM_EXPORT(rt_sem_take);
*/
rt_err_t rt_sem_trytake(rt_sem_t sem)
{
- return rt_sem_take(sem, 0);
+ return rt_sem_take(sem, RT_WAITING_NO);
}
RTM_EXPORT(rt_sem_trytake);
@@ -557,7 +533,7 @@ rt_err_t rt_sem_control(rt_sem_t sem, int cmd, void *arg)
return -RT_ERROR;
}
RTM_EXPORT(rt_sem_control);
-#endif /* end of RT_USING_SEMAPHORE */
+#endif /* RT_USING_SEMAPHORE */
#ifdef RT_USING_MUTEX
/**
@@ -683,7 +659,7 @@ rt_err_t rt_mutex_delete(rt_mutex_t mutex)
return RT_EOK;
}
RTM_EXPORT(rt_mutex_delete);
-#endif
+#endif /* RT_USING_HEAP */
/**
* This function will take a mutex, if the mutex is unavailable, the
@@ -738,7 +714,7 @@ rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time)
{
#ifdef RT_USING_SIGNALS
__again:
-#endif /* end of RT_USING_SIGNALS */
+#endif /* RT_USING_SIGNALS */
/* The value of mutex is 1 in initial status. Therefore, if the
* value is great than 0, it indicates the mutex is avaible.
*/
@@ -818,7 +794,7 @@ __again:
#ifdef RT_USING_SIGNALS
/* interrupt by signal, try it again */
if (thread->error == -RT_EINTR) goto __again;
-#endif /* end of RT_USING_SIGNALS */
+#endif /* RT_USING_SIGNALS */
/* return error */
return thread->error;
@@ -843,6 +819,19 @@ __again:
RTM_EXPORT(rt_mutex_take);
/**
+ * This function will try to take a mutex and immediately return
+ *
+ * @param mutex the mutex object
+ *
+ * @return the error code
+ */
+rt_err_t rt_mutex_trytake(rt_mutex_t mutex)
+{
+ return rt_mutex_take(mutex, RT_WAITING_NO);
+}
+RTM_EXPORT(rt_mutex_trytake);
+
+/**
* This function will release a mutex, if there are threads suspended on mutex,
* it will be waked up.
*
@@ -855,7 +844,6 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex)
register rt_base_t temp;
struct rt_thread *thread;
rt_bool_t need_schedule;
- rt_uint8_t max_priority_in_queue = RT_THREAD_PRIORITY_MAX - 1;
/* parameter check */
RT_ASSERT(mutex != RT_NULL);
@@ -917,21 +905,6 @@ rt_err_t rt_mutex_release(rt_mutex_t mutex)
mutex->owner = thread;
mutex->original_priority = thread->current_priority;
- /* Priority adjustment occurs only when the following conditions
- * are met simultaneously:
- * 1.The type of mutex is RT_IPC_FLAG_FIFO;
- * 2.The priority of the thread to be resumed is not equal to the
- * highest priority in the queue;
- */
- max_priority_in_queue = rt_ipc_get_highest_priority(&mutex->parent.suspend_thread);
- if (mutex->parent.parent.flag == RT_IPC_FLAG_FIFO &&
- thread->current_priority != max_priority_in_queue)
- {
- rt_thread_control(thread,
- RT_THREAD_CTRL_CHANGE_PRIORITY,
- &(max_priority_in_queue));
- }
-
if(mutex->hold < RT_MUTEX_HOLD_MAX)
{
mutex->hold ++;
@@ -995,7 +968,7 @@ rt_err_t rt_mutex_control(rt_mutex_t mutex, int cmd, void *arg)
return -RT_ERROR;
}
RTM_EXPORT(rt_mutex_control);
-#endif /* end of RT_USING_MUTEX */
+#endif /* RT_USING_MUTEX */
#ifdef RT_USING_EVENT
/**
@@ -1111,7 +1084,7 @@ rt_err_t rt_event_delete(rt_event_t event)
return RT_EOK;
}
RTM_EXPORT(rt_event_delete);
-#endif
+#endif /* RT_USING_HEAP */
/**
* This function will send an event to the event object, if there are threads
@@ -1388,7 +1361,7 @@ rt_err_t rt_event_control(rt_event_t event, int cmd, void *arg)
return -RT_ERROR;
}
RTM_EXPORT(rt_event_control);
-#endif /* end of RT_USING_EVENT */
+#endif /* RT_USING_EVENT */
#ifdef RT_USING_MAILBOX
/**
@@ -1539,7 +1512,7 @@ rt_err_t rt_mb_delete(rt_mailbox_t mb)
return RT_EOK;
}
RTM_EXPORT(rt_mb_delete);
-#endif
+#endif /* RT_USING_HEAP */
/**
* This function will send a mail to mailbox object. If the mailbox is full,
@@ -1946,7 +1919,7 @@ rt_err_t rt_mb_control(rt_mailbox_t mb, int cmd, void *arg)
return -RT_ERROR;
}
RTM_EXPORT(rt_mb_control);
-#endif /* end of RT_USING_MAILBOX */
+#endif /* RT_USING_MAILBOX */
#ifdef RT_USING_MESSAGEQUEUE
struct rt_mq_message
@@ -2148,7 +2121,7 @@ rt_err_t rt_mq_delete(rt_mq_t mq)
return RT_EOK;
}
RTM_EXPORT(rt_mq_delete);
-#endif
+#endif /* RT_USING_HEAP */
/**
* This function will send a message to message queue object. If the message queue is full,
@@ -2652,6 +2625,6 @@ rt_err_t rt_mq_control(rt_mq_t mq, int cmd, void *arg)
return -RT_ERROR;
}
RTM_EXPORT(rt_mq_control);
-#endif /* end of RT_USING_MESSAGEQUEUE */
+#endif /* RT_USING_MESSAGEQUEUE */
/**@}*/
diff --git a/src/irq.c b/src/irq.c
index 65fc2ea5e0..e89b8504dc 100644
--- a/src/irq.c
+++ b/src/irq.c
@@ -39,9 +39,7 @@ void rt_interrupt_leave_sethook(void (*hook)(void))
{
rt_interrupt_leave_hook = hook;
}
-#endif
-
-/* #define IRQ_DEBUG */
+#endif /* RT_USING_HOOK */
/**
* @addtogroup Kernel
@@ -53,7 +51,7 @@ void rt_interrupt_leave_sethook(void (*hook)(void))
#define rt_interrupt_nest rt_cpu_self()->irq_nest
#else
volatile rt_uint8_t rt_interrupt_nest = 0;
-#endif
+#endif /* RT_USING_SMP */
/**
* This function will be invoked by BSP, when enter interrupt service routine
diff --git a/src/kservice.c b/src/kservice.c
index 7ed05b6651..448b2d717d 100644
--- a/src/kservice.c
+++ b/src/kservice.c
@@ -25,7 +25,7 @@
#ifdef RT_USING_MODULE
#include <dlmodule.h>
-#endif
+#endif /* RT_USING_MODULE */
/* use precision */
#define RT_PRINTF_PRECISION
@@ -194,7 +194,7 @@ RT_WEAK void *rt_memset(void *s, int c, rt_ubase_t count)
#undef LBLOCKSIZE
#undef UNALIGNED
#undef TOO_SMALL
-#endif
+#endif /* RT_KSERVICE_USING_TINY_SIZE */
}
RTM_EXPORT(rt_memset);
@@ -277,7 +277,7 @@ RT_WEAK void *rt_memcpy(void *dst, const void *src, rt_ubase_t count)
#undef BIGBLOCKSIZE
#undef LITTLEBLOCKSIZE
#undef TOO_SMALL
-#endif
+#endif /* RT_KSERVICE_USING_TINY_SIZE */
}
RTM_EXPORT(rt_memcpy);
@@ -509,7 +509,7 @@ rt_size_t rt_strlen(const char *s)
}
RTM_EXPORT(rt_strlen);
-#endif /*RT_KSERVICE_USING_STDLIB*/
+#endif /* RT_KSERVICE_USING_STDLIB */
#ifdef RT_USING_HEAP
/**
@@ -535,7 +535,7 @@ RTM_EXPORT(rt_strdup);
#if defined(__CC_ARM) || defined(__CLANG_ARM)
char *strdup(const char *s) __attribute__((alias("rt_strdup")));
#endif
-#endif
+#endif /* RT_USING_HEAP */
/**
* This function will show the version of rt-thread rtos
@@ -591,7 +591,7 @@ rt_inline int divide(long *n, int base)
return res;
}
-#endif
+#endif /* RT_PRINTF_LONGLONG */
rt_inline int skip_atoi(const char **s)
{
@@ -617,7 +617,7 @@ static char *print_number(char *buf,
long long num,
#else
long num,
-#endif
+#endif /* RT_PRINTF_LONGLONG */
int base,
int s,
int precision,
@@ -629,18 +629,18 @@ static char *print_number(char *buf,
long long num,
#else
long num,
-#endif
+#endif /* RT_PRINTF_LONGLONG */
int base,
int s,
int type)
-#endif
+#endif /* RT_PRINTF_PRECISION */
{
char c, sign;
#ifdef RT_PRINTF_LONGLONG
char tmp[32];
#else
char tmp[16];
-#endif
+#endif /* RT_PRINTF_LONGLONG */
int precision_bak = precision;
const char *digits;
static const char small_digits[] = "0123456789abcdef";
@@ -679,7 +679,7 @@ static char *print_number(char *buf,
else if (base == 8)
size--;
}
-#endif
+#endif /* RT_PRINTF_SPECIAL */
i = 0;
if (num == 0)
@@ -696,7 +696,7 @@ static char *print_number(char *buf,
size -= precision;
#else
size -= i;
-#endif
+#endif /* RT_PRINTF_PRECISION */
if (!(type & (ZEROPAD | LEFT)))
{
@@ -742,7 +742,7 @@ static char *print_number(char *buf,
++ buf;
}
}
-#endif
+#endif /* RT_PRINTF_SPECIAL */
/* no align to the left */
if (!(type & LEFT))
@@ -762,7 +762,7 @@ static char *print_number(char *buf,
*buf = '0';
++ buf;
}
-#endif
+#endif /* RT_PRINTF_PRECISION */
/* put number in the temporary buffer */
while (i-- > 0 && (precision_bak != 0))
@@ -791,7 +791,7 @@ rt_int32_t rt_vsnprintf(char *buf,
unsigned long long num;
#else
rt_uint32_t num;
-#endif
+#endif /* RT_PRINTF_LONGLONG */
int i, len;
char *str, *end, c;
const char *s;
@@ -803,7 +803,7 @@ rt_int32_t rt_vsnprintf(char *buf,
#ifdef RT_PRINTF_PRECISION
int precision; /* min. # of digits for integers and max for a string */
-#endif
+#endif /* RT_PRINTF_PRECISION */
str = buf;
end = buf + size;
@@ -870,14 +870,14 @@ rt_int32_t rt_vsnprintf(char *buf,
}
if (precision < 0) precision = 0;
}
-#endif
+#endif /* RT_PRINTF_PRECISION */
/* get the conversion qualifier */
qualifier = 0;
#ifdef RT_PRINTF_LONGLONG
if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L')
#else
if (*fmt == 'h' || *fmt == 'l')
-#endif
+#endif /* RT_PRINTF_LONGLONG */
{
qualifier = *fmt;
++ fmt;
@@ -887,7 +887,7 @@ rt_int32_t rt_vsnprintf(char *buf,
qualifier = 'L';
++ fmt;
}
-#endif
+#endif /* RT_PRINTF_LONGLONG */
}
/* the default base */
@@ -925,7 +925,7 @@ rt_int32_t rt_vsnprintf(char *buf,
for (len = 0; (len != field_width) && (s[len] != '\0'); len++);
#ifdef RT_PRINTF_PRECISION
if (precision > 0 && len > precision) len = precision;
-#endif
+#endif /* RT_PRINTF_PRECISION */
if (!(flags & LEFT))
{
@@ -964,7 +964,7 @@ rt_int32_t rt_vsnprintf(char *buf,
str = print_number(str, end,
(long)va_arg(args, void *),
16, field_width, flags);
-#endif
+#endif /* RT_PRINTF_PRECISION */
continue;
case '%':
@@ -1010,7 +1010,7 @@ rt_int32_t rt_vsnprintf(char *buf,
else if (qualifier == 'l')
#else
if (qualifier == 'l')
-#endif
+#endif /* RT_PRINTF_LONGLONG */
{
num = va_arg(args, rt_uint32_t);
if (flags & SIGN) num = (rt_int32_t)num;
@@ -1029,7 +1029,7 @@ rt_int32_t rt_vsnprintf(char *buf,
str = print_number(str, end, num, base, field_width, precision, flags);
#else
str = print_number(str, end, num, base, field_width, flags);
-#endif
+#endif /* RT_PRINTF_PRECISION */
}
if (size > 0)
@@ -1152,7 +1152,7 @@ rt_device_t rt_console_set_device(const char *name)
return old_device;
}
RTM_EXPORT(rt_console_set_device);
-#endif
+#endif /* RT_USING_DEVICE */
RT_WEAK void rt_hw_console_output(const char *str)
{
@@ -1184,7 +1184,7 @@ void rt_kputs(const char *str)
}
#else
rt_hw_console_output(str);
-#endif
+#endif /* RT_USING_DEVICE */
}
/**
@@ -1222,11 +1222,11 @@ RT_WEAK void rt_kprintf(const char *fmt, ...)
}
#else
rt_hw_console_output(rt_log_buf);
-#endif
+#endif /* RT_USING_DEVICE */
va_end(args);
}
RTM_EXPORT(rt_kprintf);
-#endif
+#endif /* RT_USING_CONSOLE */
#ifdef RT_USING_HEAP
/**
@@ -1238,7 +1238,7 @@ RTM_EXPORT(rt_kprintf);
*
* @return the allocated memory block on successful, otherwise returns RT_NULL
*/
-void *rt_malloc_align(rt_size_t size, rt_size_t align)
+RT_WEAK void *rt_malloc_align(rt_size_t size, rt_size_t align)
{
void *ptr;
void *align_ptr;
@@ -1284,7 +1284,7 @@ RTM_EXPORT(rt_malloc_align);
*
* @param ptr the memory block pointer
*/
-void rt_free_align(void *ptr)
+RT_WEAK void rt_free_align(void *ptr)
{
void *real_ptr;
@@ -1292,7 +1292,7 @@ void rt_free_align(void *ptr)
rt_free(real_ptr);
}
RTM_EXPORT(rt_free_align);
-#endif
+#endif /* RT_USING_HEAP */
#ifndef RT_USING_CPU_FFS
const rt_uint8_t __lowest_bit_bitmap[] =
@@ -1340,7 +1340,7 @@ int __rt_ffs(int value)
return __lowest_bit_bitmap[(value & 0xff000000) >> 24] + 25;
}
-#endif
+#endif /* RT_USING_CPU_FFS */
#ifdef RT_DEBUG
/* RT_ASSERT(EX)'s hook */
@@ -1377,7 +1377,7 @@ void rt_assert_handler(const char *ex_string, const char *func, rt_size_t line)
dlmodule_exit(-1);
}
else
-#endif
+#endif /*RT_USING_MODULE*/
{
rt_kprintf("(%s) assertion failed at function:%s, line number:%d \n", ex_string, func, line);
while (dummy == 0);
diff --git a/src/mem.c b/src/mem.c
index ac0d27f2c3..20ac0e588c 100644
--- a/src/mem.c
+++ b/src/mem.c
@@ -52,7 +52,6 @@
#ifndef RT_USING_MEMHEAP_AS_HEAP
-/* #define RT_MEM_DEBUG */
#define RT_MEM_STATS
#if defined (RT_USING_HEAP) && defined (RT_USING_SMALL_MEM)
@@ -90,7 +89,7 @@ void rt_free_sethook(void (*hook)(void *ptr))
/**@}*/
-#endif
+#endif /* RT_USING_HOOK */
#define HEAP_MAGIC 0x1ea0
struct heap_mem
@@ -100,7 +99,7 @@ struct heap_mem
rt_uint16_t used;
#ifdef ARCH_CPU_64BIT
rt_uint32_t resv;
-#endif
+#endif /* ARCH_CPU_64BIT */
rt_size_t next, prev;
@@ -109,8 +108,8 @@ struct heap_mem
rt_uint8_t thread[8];
#else
rt_uint8_t thread[4]; /* thread name */
-#endif
-#endif
+#endif /* ARCH_CPU_64BIT */
+#endif /* RT_USING_MEMTRACE */
};
/** pointer to the heap: for alignment, heap_ptr is now a pointer instead of an array */
@@ -123,7 +122,7 @@ static struct heap_mem *heap_end;
#define MIN_SIZE 24
#else
#define MIN_SIZE 12
-#endif
+#endif /* ARCH_CPU_64BIT */
#define MIN_SIZE_ALIGNED RT_ALIGN(MIN_SIZE, RT_ALIGN_SIZE)
#define SIZEOF_STRUCT_MEM RT_ALIGN(sizeof(struct heap_mem), RT_ALIGN_SIZE)
@@ -135,7 +134,8 @@ static rt_size_t mem_size_aligned;
#ifdef RT_MEM_STATS
static rt_size_t used_mem, max_mem;
-#endif
+#endif /* RT_MEM_STATS */
+
#ifdef RT_USING_MEMTRACE
rt_inline void rt_mem_setname(struct heap_mem *mem, const char *name)
{
@@ -151,7 +151,7 @@ rt_inline void rt_mem_setname(struct heap_mem *mem, const char *name)
mem->thread[index] = ' ';
}
}
-#endif
+#endif /* RT_USING_MEMTRACE */
static void plug_holes(struct heap_mem *mem)
{
@@ -238,7 +238,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
mem->used = 0;
#ifdef RT_USING_MEMTRACE
rt_mem_setname(mem, "INIT");
-#endif
+#endif /* RT_USING_MEMTRACE */
/* initialize the end of the heap */
heap_end = (struct heap_mem *)&heap_ptr[mem->next];
@@ -248,9 +248,9 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
heap_end->prev = mem_size_aligned + SIZEOF_STRUCT_MEM;
#ifdef RT_USING_MEMTRACE
rt_mem_setname(heap_end, "INIT");
-#endif
+#endif /* RT_USING_MEMTRACE */
- rt_sem_init(&heap_sem, "heap", 1, RT_IPC_FLAG_FIFO);
+ rt_sem_init(&heap_sem, "heap", 1, RT_IPC_FLAG_PRIO);
/* initialize the lowest-free pointer to the start of the heap */
lfree = (struct heap_mem *)heap_ptr;
@@ -336,7 +336,7 @@ void *rt_malloc(rt_size_t size)
mem2->prev = ptr;
#ifdef RT_USING_MEMTRACE
rt_mem_setname(mem2, " ");
-#endif
+#endif /* RT_USING_MEMTRACE */
/* and insert it between mem and mem->next */
mem->next = ptr2;
@@ -350,7 +350,7 @@ void *rt_malloc(rt_size_t size)
used_mem += (size + SIZEOF_STRUCT_MEM);
if (max_mem < used_mem)
max_mem = used_mem;
-#endif
+#endif /* RT_MEM_STATS */
}
else
{
@@ -366,7 +366,7 @@ void *rt_malloc(rt_size_t size)
used_mem += mem->next - ((rt_uint8_t *)mem - heap_ptr);
if (max_mem < used_mem)
max_mem = used_mem;
-#endif
+#endif /* RT_MEM_STATS */
}
/* set memory block magic */
mem->magic = HEAP_MAGIC;
@@ -375,7 +375,7 @@ void *rt_malloc(rt_size_t size)
rt_mem_setname(mem, rt_thread_self()->name);
else
rt_mem_setname(mem, "NONE");
-#endif
+#endif /* RT_USING_MEMTRACE */
if (mem == lfree)
{
@@ -473,7 +473,7 @@ void *rt_realloc(void *rmem, rt_size_t newsize)
/* split memory block */
#ifdef RT_MEM_STATS
used_mem -= (size - newsize);
-#endif
+#endif /* RT_MEM_STATS */
ptr2 = ptr + SIZEOF_STRUCT_MEM + newsize;
mem2 = (struct heap_mem *)&heap_ptr[ptr2];
@@ -483,7 +483,7 @@ void *rt_realloc(void *rmem, rt_size_t newsize)
mem2->prev = ptr;
#ifdef RT_USING_MEMTRACE
rt_mem_setname(mem2, " ");
-#endif
+#endif /* RT_USING_MEMTRACE */
mem->next = ptr2;
if (mem2->next != mem_size_aligned + SIZEOF_STRUCT_MEM)
{
@@ -597,7 +597,7 @@ void rt_free(void *rmem)
mem->magic = HEAP_MAGIC;
#ifdef RT_USING_MEMTRACE
rt_mem_setname(mem, " ");
-#endif
+#endif /* RT_USING_MEMTRACE */
if (mem < lfree)
{
@@ -607,7 +607,7 @@ void rt_free(void *rmem)
#ifdef RT_MEM_STATS
used_mem -= (mem->next - ((rt_uint8_t *)mem - heap_ptr));
-#endif
+#endif /* RT_MEM_STATS */
/* finally, see if prev or next are free also */
plug_holes(mem);
@@ -706,12 +706,12 @@ int memtrace(int argc, char **argv)
return 0;
}
MSH_CMD_EXPORT(memtrace, dump memory trace information);
-#endif /* end of RT_USING_MEMTRACE */
-#endif /* end of RT_USING_FINSH */
+#endif /* RT_USING_MEMTRACE */
+#endif /* RT_USING_FINSH */
-#endif
+#endif /* defined (RT_USING_HEAP) && defined (RT_USING_SMALL_MEM) */
/**@}*/
-#endif /* end of RT_USING_HEAP */
-#endif /* end of RT_USING_MEMHEAP_AS_HEAP */
+#endif /* RT_MEM_STATS */
+#endif /* RT_USING_MEMHEAP_AS_HEAP */
diff --git a/src/memheap.c b/src/memheap.c
index 63327575cc..d77c95601e 100644
--- a/src/memheap.c
+++ b/src/memheap.c
@@ -17,6 +17,7 @@
* 2013-05-24 Bernard fix the rt_memheap_realloc issue.
* 2013-07-11 Grissiom fix the memory block splitting issue.
* 2013-07-15 Grissiom optimize rt_memheap_realloc
+ * 2021-06-03 Flybreak Fix the crash problem after opening Oz optimization on ac6.
*/
#include <rthw.h>
@@ -41,31 +42,31 @@
rt_inline void rt_memheap_setname(struct rt_memheap_item *item, const char *name)
{
int index;
- rt_uint8_t* ptr;
+ rt_uint8_t *ptr;
- ptr = (rt_uint8_t*)&(item->next_free);
- for (index = 0; index < sizeof(void*); index ++)
+ ptr = (rt_uint8_t *) & (item->next_free);
+ for (index = 0; index < sizeof(void *); index ++)
{
if (name[index] == '\0') break;
ptr[index] = name[index];
}
if (name[index] == '\0') ptr[index] = '\0';
- else
+ else
{
- ptr = (rt_uint8_t*)&(item->prev_free);
- for (index = 0; index < sizeof(void*) && (index + sizeof(void*))< RT_NAME_MAX; index ++)
+ ptr = (rt_uint8_t *) & (item->prev_free);
+ for (index = 0; index < sizeof(void *) && (index + sizeof(void *)) < RT_NAME_MAX; index ++)
{
- if (name[sizeof(void*) + index] == '\0') break;
- ptr[index] = name[sizeof(void*) + index];
+ if (name[sizeof(void *) + index] == '\0') break;
+ ptr[index] = name[sizeof(void *) + index];
}
- if (name[sizeof(void*) + index] == '\0') ptr[index] = '\0';
+ if (name[sizeof(void *) + index] == '\0') ptr[index] = '\0';
}
}
-void rt_mem_set_tag(void* ptr, const char* name)
+void rt_mem_set_tag(void *ptr, const char *name)
{
- struct rt_memheap_item* item;
+ struct rt_memheap_item *item;
if (ptr && name)
{
@@ -73,7 +74,7 @@ void rt_mem_set_tag(void* ptr, const char* name)
rt_memheap_setname(item, name);
}
}
-#endif
+#endif /* RT_USING_MEMTRACE */
/*
* The initialized memory pool will be:
@@ -126,7 +127,7 @@ rt_err_t rt_memheap_init(struct rt_memheap *memheap,
#ifdef RT_USING_MEMTRACE
rt_memset(item->owner_thread_name, ' ', sizeof(item->owner_thread_name));
-#endif
+#endif /* RT_USING_MEMTRACE */
item->next = (struct rt_memheap_item *)
((rt_uint8_t *)item + memheap->available_size + RT_MEMHEAP_SIZE);
@@ -154,7 +155,7 @@ rt_err_t rt_memheap_init(struct rt_memheap *memheap,
item->next_free = item->prev_free = RT_NULL;
/* initialize semaphore lock */
- rt_sem_init(&(memheap->lock), name, 1, RT_IPC_FLAG_FIFO);
+ rt_sem_init(&(memheap->lock), name, 1, RT_IPC_FLAG_PRIO);
RT_DEBUG_LOG(RT_DEBUG_MEMHEAP,
("memory heap: start addr 0x%08x, size %d, free list header 0x%08x\n",
@@ -251,7 +252,7 @@ void *rt_memheap_alloc(struct rt_memheap *heap, rt_size_t size)
#ifdef RT_USING_MEMTRACE
rt_memset(new_ptr->owner_thread_name, ' ', sizeof(new_ptr->owner_thread_name));
-#endif
+#endif /* RT_USING_MEMTRACE */
/* break down the block list */
new_ptr->prev = header_ptr;
@@ -309,7 +310,7 @@ void *rt_memheap_alloc(struct rt_memheap *heap, rt_size_t size)
rt_memcpy(header_ptr->owner_thread_name, rt_thread_self()->name, sizeof(header_ptr->owner_thread_name));
else
rt_memcpy(header_ptr->owner_thread_name, "NONE", sizeof(header_ptr->owner_thread_name));
-#endif
+#endif /* RT_USING_MEMTRACE */
/* release lock */
rt_sem_release(&(heap->lock));
@@ -369,7 +370,8 @@ void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize)
if (newsize > oldsize)
{
void *new_ptr;
- struct rt_memheap_item *next_ptr;
+ /* Fix the crash problem after opening Oz optimization on ac6 */
+ volatile struct rt_memheap_item *next_ptr;
/* lock memheap */
result = rt_sem_take(&(heap->lock), RT_WAITING_FOREVER);
@@ -437,18 +439,18 @@ void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize)
#ifdef RT_USING_MEMTRACE
rt_memset(next_ptr->owner_thread_name, ' ', sizeof(next_ptr->owner_thread_name));
-#endif
+#endif /* RT_USING_MEMTRACE */
next_ptr->prev = header_ptr;
next_ptr->next = header_ptr->next;
- header_ptr->next->prev = next_ptr;
- header_ptr->next = next_ptr;
+ header_ptr->next->prev = (struct rt_memheap_item *)next_ptr;
+ header_ptr->next = (struct rt_memheap_item *)next_ptr;
/* insert next_ptr to free list */
next_ptr->next_free = heap->free_list->next_free;
next_ptr->prev_free = heap->free_list;
- heap->free_list->next_free->prev_free = next_ptr;
- heap->free_list->next_free = next_ptr;
+ heap->free_list->next_free->prev_free = (struct rt_memheap_item *)next_ptr;
+ heap->free_list->next_free = (struct rt_memheap_item *)next_ptr;
RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, ("new ptr: next_free 0x%08x, prev_free 0x%08x",
next_ptr->next_free,
next_ptr->prev_free));
@@ -505,7 +507,7 @@ void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize)
#ifdef RT_USING_MEMTRACE
rt_memset(new_ptr->owner_thread_name, ' ', sizeof(new_ptr->owner_thread_name));
-#endif
+#endif /* RT_USING_MEMTRACE */
/* break down the block list */
new_ptr->prev = header_ptr;
@@ -658,7 +660,7 @@ void rt_memheap_free(void *ptr)
#ifdef RT_USING_MEMTRACE
rt_memset(header_ptr->owner_thread_name, ' ', sizeof(header_ptr->owner_thread_name));
-#endif
+#endif /* RT_USING_MEMTRACE */
/* release lock */
rt_sem_release(&(heap->lock));
@@ -666,17 +668,17 @@ void rt_memheap_free(void *ptr)
RTM_EXPORT(rt_memheap_free);
#ifdef RT_USING_FINSH
-static void _memheap_dump_tag(struct rt_memheap_item* item)
+static void _memheap_dump_tag(struct rt_memheap_item *item)
{
- rt_uint8_t name[2 * sizeof(void*)];
- rt_uint8_t* ptr;
+ rt_uint8_t name[2 * sizeof(void *)];
+ rt_uint8_t *ptr;
- ptr = (rt_uint8_t*)&(item->next_free);
- rt_memcpy(name, ptr, sizeof(void*));
- ptr = (rt_uint8_t*)&(item->prev_free);
- rt_memcpy(&name[sizeof(void*)], ptr, sizeof(void*));
+ ptr = (rt_uint8_t *) & (item->next_free);
+ rt_memcpy(name, ptr, sizeof(void *));
+ ptr = (rt_uint8_t *) & (item->prev_free);
+ rt_memcpy(&name[sizeof(void *)], ptr, sizeof(void *));
- rt_kprintf("%.*s", 2 * sizeof(void*), name);
+ rt_kprintf("%.*s", 2 * sizeof(void *), name);
}
int rt_memheap_dump(struct rt_memheap *heap)
@@ -686,15 +688,15 @@ int rt_memheap_dump(struct rt_memheap *heap)
if (heap == RT_NULL) return 0;
RT_ASSERT(rt_object_get_type(&heap->parent) == RT_Object_Class_MemHeap);
- rt_kprintf("\n[%.*s] [0x%08x - 0x%08x]->\n", RT_NAME_MAX, heap->parent.name,
- (rt_ubase_t)heap->start_addr, (rt_ubase_t)heap->start_addr + heap->pool_size);
+ rt_kprintf("\n[%.*s] [0x%08x - 0x%08x]->\n", RT_NAME_MAX, heap->parent.name,
+ (rt_ubase_t)heap->start_addr, (rt_ubase_t)heap->start_addr + heap->pool_size);
rt_kprintf("------------------------------\n");
/* lock memheap */
rt_sem_take(&(heap->lock), RT_WAITING_FOREVER);
item = heap->block_list;
- end = (struct rt_memheap_item *) ((rt_uint8_t *)heap->start_addr + heap->pool_size - RT_MEMHEAP_SIZE);
+ end = (struct rt_memheap_item *)((rt_uint8_t *)heap->start_addr + heap->pool_size - RT_MEMHEAP_SIZE);
/* for each memory block */
while ((rt_ubase_t)item < ((rt_ubase_t)end))
@@ -730,13 +732,13 @@ int memheaptrace(void)
int index;
extern int list_memheap(void);
- heaps = (struct rt_memheap**)rt_malloc(sizeof(struct rt_memheap*) * count);
+ heaps = (struct rt_memheap **)rt_malloc(sizeof(struct rt_memheap *) * count);
if (heaps == RT_NULL) return 0;
list_memheap();
rt_kprintf("memheap header size: %d\n", RT_MEMHEAP_SIZE);
- count = rt_object_get_pointers(RT_Object_Class_MemHeap, (rt_object_t*)heaps, count);
+ count = rt_object_get_pointers(RT_Object_Class_MemHeap, (rt_object_t *)heaps, count);
for (index = 0; index < count; index++)
{
rt_memheap_dump(heaps[index]);
@@ -748,13 +750,15 @@ int memheaptrace(void)
return 0;
}
MSH_CMD_EXPORT(memheaptrace, dump memory trace information);
-#endif
+#endif /* RT_USING_FINSH */
#ifdef RT_USING_MEMHEAP_AS_HEAP
static struct rt_memheap _heap;
void rt_system_heap_init(void *begin_addr, void *end_addr)
{
+ RT_ASSERT((rt_uint32_t)end_addr > (rt_uint32_t)begin_addr);
+
/* initialize a default heap in the system */
rt_memheap_init(&_heap,
"heap",
@@ -814,7 +818,7 @@ void *rt_malloc(rt_size_t size)
RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, ("malloc => 0x%08x : %d", ptr, size));
}
-#endif
+#endif /* RT_USING_MEMTRACE */
return ptr;
}
@@ -880,7 +884,7 @@ void *rt_realloc(void *rmem, rt_size_t newsize)
RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, ("realloc => 0x%08x : %d",
new_ptr, newsize));
}
-#endif
+#endif /* RT_USING_MEMTRACE */
return new_ptr;
}
@@ -910,7 +914,7 @@ void *rt_calloc(rt_size_t count, rt_size_t size)
RT_DEBUG_LOG(RT_DEBUG_MEMHEAP, ("calloc => 0x%08x : %d",
ptr, count * size));
}
-#endif
+#endif /* RT_USING_MEMTRACE */
return ptr;
}
@@ -930,7 +934,7 @@ void rt_memory_info(rt_uint32_t *total,
*max_used = _heap.max_used_size;
}
-#endif
+#endif /* RT_USING_MEMHEAP_AS_HEAP */
#ifdef RT_USING_MEMTRACE
@@ -966,15 +970,15 @@ void dump_used_memheap(struct rt_memheap *mh)
{
/* dump information */
rt_kprintf("[0x%08x - %d - %c%c%c%c] used\n", header_ptr, block_size,
- header_ptr->owner_thread_name[0], header_ptr->owner_thread_name[1],
- header_ptr->owner_thread_name[2], header_ptr->owner_thread_name[3]);
+ header_ptr->owner_thread_name[0], header_ptr->owner_thread_name[1],
+ header_ptr->owner_thread_name[2], header_ptr->owner_thread_name[3]);
}
else
{
/* dump information */
rt_kprintf("[0x%08x - %d - %c%c%c%c] free\n", header_ptr, block_size,
- header_ptr->owner_thread_name[0], header_ptr->owner_thread_name[1],
- header_ptr->owner_thread_name[2], header_ptr->owner_thread_name[3]);
+ header_ptr->owner_thread_name[0], header_ptr->owner_thread_name[1],
+ header_ptr->owner_thread_name[2], header_ptr->owner_thread_name[3]);
}
/* move to next used memory block */
@@ -1002,8 +1006,8 @@ void memtrace_heap()
#ifdef RT_USING_FINSH
#include <finsh.h>
MSH_CMD_EXPORT(memtrace_heap, dump memory trace for heap);
-#endif /* end of RT_USING_FINSH */
+#endif /* RT_USING_FINSH */
-#endif /* end of RT_USING_MEMTRACE */
+#endif /* RT_USING_MEMTRACE */
-#endif /* end of RT_USING_MEMHEAP */
+#endif /* RT_USING_MEMHEAP */
diff --git a/src/mempool.c b/src/mempool.c
index 1de48940d7..5ac87d2bc8 100644
--- a/src/mempool.c
+++ b/src/mempool.c
@@ -54,7 +54,7 @@ void rt_mp_free_sethook(void (*hook)(struct rt_mempool *mp, void *block))
}
/**@}*/
-#endif
+#endif /* RT_USING_HOOK */
/**
* @addtogroup MM
@@ -290,7 +290,7 @@ rt_err_t rt_mp_delete(rt_mp_t mp)
return RT_EOK;
}
RTM_EXPORT(rt_mp_delete);
-#endif
+#endif /* RT_USING_HEAP */
/**
* This function will allocate a block from memory pool
@@ -451,5 +451,4 @@ RTM_EXPORT(rt_mp_free);
/**@}*/
-#endif
-
+#endif /* RT_USING_MEMPOOL */
diff --git a/src/object.c b/src/object.c
index 013e2d1e33..ff96037c52 100644
--- a/src/object.c
+++ b/src/object.c
@@ -20,7 +20,7 @@
#ifdef RT_USING_MODULE
#include <dlmodule.h>
-#endif
+#endif /* RT_USING_MODULE */
/*
* define object_info for the number of rt_object_container items.
@@ -189,7 +189,7 @@ void rt_object_put_sethook(void (*hook)(struct rt_object *object))
}
/**@}*/
-#endif
+#endif /* RT_USING_HOOK */
/**
* @addtogroup KernelObject
@@ -305,7 +305,7 @@ void rt_object_init(struct rt_object *object,
struct rt_object_information *information;
#ifdef RT_USING_MODULE
struct rt_dlmodule *module = dlmodule_self();
-#endif
+#endif /* RT_USING_MODULE */
/* get object information */
information = rt_object_get_information(type);
@@ -349,7 +349,7 @@ void rt_object_init(struct rt_object *object,
object->module_id = (void *)module;
}
else
-#endif
+#endif /* RT_USING_MODULE */
{
/* insert object into information object list */
rt_list_insert_after(&(information->object_list), &(object->list));
@@ -403,7 +403,7 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name)
struct rt_object_information *information;
#ifdef RT_USING_MODULE
struct rt_dlmodule *module = dlmodule_self();
-#endif
+#endif /* RT_USING_MODULE */
RT_DEBUG_NOT_IN_INTERRUPT;
@@ -444,7 +444,7 @@ rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name)
object->module_id = (void *)module;
}
else
-#endif
+#endif /* RT_USING_MODULE */
{
/* insert object into information object list */
rt_list_insert_after(&(information->object_list), &(object->list));
@@ -487,7 +487,7 @@ void rt_object_delete(rt_object_t object)
/* free the memory of object */
RT_KERNEL_FREE(object);
}
-#endif
+#endif /* RT_USING_HEAP */
/**
* This function will judge the object is system object or not.
diff --git a/src/scheduler.c b/src/scheduler.c
index c03c20d030..eec660a8aa 100644
--- a/src/scheduler.c
+++ b/src/scheduler.c
@@ -38,14 +38,14 @@ rt_uint32_t rt_thread_ready_priority_group;
#if RT_THREAD_PRIORITY_MAX > 32
/* Maximum priority level, 256 */
rt_uint8_t rt_thread_ready_table[32];
-#endif
+#endif /* RT_THREAD_PRIORITY_MAX > 32 */
#ifndef RT_USING_SMP
extern volatile rt_uint8_t rt_interrupt_nest;
static rt_int16_t rt_scheduler_lock_nest;
struct rt_thread *rt_current_thread = RT_NULL;
rt_uint8_t rt_current_priority;
-#endif /*RT_USING_SMP*/
+#endif /* RT_USING_SMP */
rt_list_t rt_thread_defunct;
@@ -71,18 +71,18 @@ rt_scheduler_sethook(void (*hook)(struct rt_thread *from, struct rt_thread *to))
}
/**@}*/
-#endif
+#endif /* RT_USING_HOOK */
#ifdef RT_USING_OVERFLOW_CHECK
static void _rt_scheduler_stack_check(struct rt_thread *thread)
{
RT_ASSERT(thread != RT_NULL);
-#if defined(ARCH_CPU_STACK_GROWS_UPWARD)
+#ifdef ARCH_CPU_STACK_GROWS_UPWARD
if (*((rt_uint8_t *)((rt_ubase_t)thread->stack_addr + thread->stack_size - 1)) != '#' ||
#else
if (*((rt_uint8_t *)thread->stack_addr) != '#' ||
-#endif
+#endif /* ARCH_CPU_STACK_GROWS_UPWARD */
(rt_ubase_t)thread->sp <= (rt_ubase_t)thread->stack_addr ||
(rt_ubase_t)thread->sp >
(rt_ubase_t)thread->stack_addr + (rt_ubase_t)thread->stack_size)
@@ -94,7 +94,7 @@ static void _rt_scheduler_stack_check(struct rt_thread *thread)
level = rt_hw_interrupt_disable();
while (level);
}
-#if defined(ARCH_CPU_STACK_GROWS_UPWARD)
+#ifdef ARCH_CPU_STACK_GROWS_UPWARD
else if ((rt_ubase_t)thread->sp > ((rt_ubase_t)thread->stack_addr + thread->stack_size))
{
rt_kprintf("warning: %s stack is close to the top of stack address.\n",
@@ -106,9 +106,9 @@ static void _rt_scheduler_stack_check(struct rt_thread *thread)
rt_kprintf("warning: %s stack is close to end of stack address.\n",
thread->name);
}
-#endif
+#endif /* ARCH_CPU_STACK_GROWS_UPWARD */
}
-#endif
+#endif /* RT_USING_OVERFLOW_CHECK */
/*
* get the highest priority thread in ready queue
@@ -129,7 +129,7 @@ static struct rt_thread* _get_highest_priority_thread(rt_ubase_t *highest_prio)
#else
highest_ready_priority = __rt_ffs(rt_thread_ready_priority_group) - 1;
local_highest_ready_priority = __rt_ffs(pcpu->priority_group) - 1;
-#endif
+#endif /* RT_THREAD_PRIORITY_MAX > 32 */
/* get highest ready priority thread */
if (highest_ready_priority < local_highest_ready_priority)
@@ -162,7 +162,7 @@ static struct rt_thread* _get_highest_priority_thread(rt_ubase_t *highest_prio)
highest_ready_priority = (number << 3) + __rt_ffs(rt_thread_ready_table[number]) - 1;
#else
highest_ready_priority = __rt_ffs(rt_thread_ready_priority_group) - 1;
-#endif
+#endif /* RT_THREAD_PRIORITY_MAX > 32 */
/* get highest ready priority thread */
highest_priority_thread = rt_list_entry(rt_thread_priority_table[highest_ready_priority].next,
@@ -173,7 +173,7 @@ static struct rt_thread* _get_highest_priority_thread(rt_ubase_t *highest_prio)
return highest_priority_thread;
}
-#endif
+#endif /* RT_USING_SMP */
/**
* @ingroup SystemInit
@@ -183,12 +183,12 @@ void rt_system_scheduler_init(void)
{
#ifdef RT_USING_SMP
int cpu;
-#endif /*RT_USING_SMP*/
+#endif /* RT_USING_SMP */
register rt_base_t offset;
#ifndef RT_USING_SMP
rt_scheduler_lock_nest = 0;
-#endif /*RT_USING_SMP*/
+#endif /* RT_USING_SMP */
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("start scheduler: max priority 0x%02x\n",
RT_THREAD_PRIORITY_MAX));
@@ -213,9 +213,9 @@ void rt_system_scheduler_init(void)
#if RT_THREAD_PRIORITY_MAX > 32
rt_memset(pcpu->ready_table, 0, sizeof(pcpu->ready_table));
-#endif
+#endif /* RT_THREAD_PRIORITY_MAX > 32 */
}
-#endif /*RT_USING_SMP*/
+#endif /* RT_USING_SMP */
/* initialize ready priority group */
rt_thread_ready_priority_group = 0;
@@ -223,7 +223,7 @@ void rt_system_scheduler_init(void)
#if RT_THREAD_PRIORITY_MAX > 32
/* initialize ready table */
rt_memset(rt_thread_ready_table, 0, sizeof(rt_thread_ready_table));
-#endif
+#endif /* RT_THREAD_PRIORITY_MAX > 32 */
/* initialize thread defunct */
rt_list_init(&rt_thread_defunct);
@@ -245,7 +245,7 @@ void rt_system_scheduler_start(void)
to_thread->oncpu = rt_hw_cpu_id();
#else
rt_current_thread = to_thread;
-#endif /*RT_USING_SMP*/
+#endif /* RT_USING_SMP */
rt_schedule_remove_thread(to_thread);
to_thread->stat = RT_THREAD_RUNNING;
@@ -255,7 +255,7 @@ void rt_system_scheduler_start(void)
rt_hw_context_switch_to((rt_ubase_t)&to_thread->sp, to_thread);
#else
rt_hw_context_switch_to((rt_ubase_t)&to_thread->sp);
-#endif /*RT_USING_SMP*/
+#endif /* RT_USING_SMP */
/* never come back */
}
@@ -319,7 +319,7 @@ void rt_schedule(void)
rt_thread_resume(current_thread);
}
}
-#endif
+#endif /* RT_USING_SIGNALS */
if (current_thread->scheduler_lock_nest == 1) /* whether lock scheduler */
{
@@ -367,7 +367,7 @@ void rt_schedule(void)
#ifdef RT_USING_OVERFLOW_CHECK
_rt_scheduler_stack_check(to_thread);
-#endif
+#endif /* RT_USING_OVERFLOW_CHECK */
rt_hw_context_switch((rt_ubase_t)&current_thread->sp,
(rt_ubase_t)&to_thread->sp, to_thread);
@@ -396,7 +396,7 @@ void rt_schedule(void)
{
rt_hw_interrupt_enable(level);
}
-#endif
+#endif /* RT_USING_SIGNALS */
__exit:
return ;
@@ -404,7 +404,7 @@ __exit:
#else
/**
* This function will perform one schedule. It will select one thread
- * with the highest priority level, then switch to it.
+ * with the highest priority level, and switch to it immediately.
*/
void rt_schedule(void)
{
@@ -472,7 +472,7 @@ void rt_schedule(void)
#ifdef RT_USING_OVERFLOW_CHECK
_rt_scheduler_stack_check(to_thread);
-#endif
+#endif /* RT_USING_OVERFLOW_CHECK */
if (rt_interrupt_nest == 0)
{
@@ -502,7 +502,7 @@ void rt_schedule(void)
{
rt_hw_interrupt_enable(level);
}
-#endif
+#endif /* RT_USING_SIGNALS */
goto __exit;
}
else
@@ -527,7 +527,7 @@ void rt_schedule(void)
__exit:
return;
}
-#endif /*RT_USING_SMP*/
+#endif /* RT_USING_SMP */
/**
* This function checks if a scheduling is needed after IRQ context. If yes,
@@ -559,7 +559,7 @@ void rt_scheduler_do_irq_switch(void *context)
rt_thread_resume(current_thread);
}
}
-#endif
+#endif /* RT_USING_SIGNALS */
if (pcpu->irq_switch_flag == 0)
{
@@ -608,7 +608,7 @@ void rt_scheduler_do_irq_switch(void *context)
#ifdef RT_USING_OVERFLOW_CHECK
_rt_scheduler_stack_check(to_thread);
-#endif
+#endif /* RT_USING_OVERFLOW_CHECK */
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("switch in interrupt\n"));
current_thread->cpus_lock_nest--;
@@ -621,7 +621,7 @@ void rt_scheduler_do_irq_switch(void *context)
}
rt_hw_interrupt_enable(level);
}
-#endif /*RT_USING_SMP*/
+#endif /* RT_USING_SMP */
/*
* This function will insert a thread to system ready queue. The state of
@@ -661,7 +661,7 @@ void rt_schedule_insert_thread(struct rt_thread *thread)
{
#if RT_THREAD_PRIORITY_MAX > 32
rt_thread_ready_table[thread->number] |= thread->high_mask;
-#endif
+#endif /* RT_THREAD_PRIORITY_MAX > 32 */
rt_thread_ready_priority_group |= thread->number_mask;
rt_list_insert_before(&(rt_thread_priority_table[thread->current_priority]),
@@ -675,7 +675,7 @@ void rt_schedule_insert_thread(struct rt_thread *thread)
#if RT_THREAD_PRIORITY_MAX > 32
pcpu->ready_table[thread->number] |= thread->high_mask;
-#endif
+#endif /* RT_THREAD_PRIORITY_MAX > 32 */
pcpu->priority_group |= thread->number_mask;
rt_list_insert_before(&(rt_cpu_index(bind_cpu)->priority_table[thread->current_priority]),
@@ -724,14 +724,14 @@ void rt_schedule_insert_thread(struct rt_thread *thread)
/* set priority mask */
#if RT_THREAD_PRIORITY_MAX > 32
rt_thread_ready_table[thread->number] |= thread->high_mask;
-#endif
+#endif /* RT_THREAD_PRIORITY_MAX > 32 */
rt_thread_ready_priority_group |= thread->number_mask;
__exit:
/* enable interrupt */
rt_hw_interrupt_enable(temp);
}
-#endif /*RT_USING_SMP*/
+#endif /* RT_USING_SMP */
/*
* This function will remove a thread from system ready queue.
@@ -768,7 +768,7 @@ void rt_schedule_remove_thread(struct rt_thread *thread)
}
#else
rt_thread_ready_priority_group &= ~thread->number_mask;
-#endif
+#endif /* RT_THREAD_PRIORITY_MAX > 32 */
}
}
else
@@ -785,7 +785,7 @@ void rt_schedule_remove_thread(struct rt_thread *thread)
}
#else
pcpu->priority_group &= ~thread->number_mask;
-#endif
+#endif /* RT_THREAD_PRIORITY_MAX > 32 */
}
}
@@ -818,13 +818,13 @@ void rt_schedule_remove_thread(struct rt_thread *thread)
}
#else
rt_thread_ready_priority_group &= ~thread->number_mask;
-#endif
+#endif /* RT_THREAD_PRIORITY_MAX > 32 */
}
/* enable interrupt */
rt_hw_interrupt_enable(level);
}
-#endif /*RT_USING_SMP*/
+#endif /* RT_USING_SMP */
/**
* This function will lock the thread scheduler.
@@ -885,7 +885,7 @@ void rt_enter_critical(void)
/* enable interrupt */
rt_hw_interrupt_enable(level);
}
-#endif /*RT_USING_SMP*/
+#endif /* RT_USING_SMP */
RTM_EXPORT(rt_enter_critical);
/**
@@ -959,7 +959,7 @@ void rt_exit_critical(void)
rt_hw_interrupt_enable(level);
}
}
-#endif /*RT_USING_SMP*/
+#endif /* RT_USING_SMP */
RTM_EXPORT(rt_exit_critical);
/**
@@ -975,7 +975,7 @@ rt_uint16_t rt_critical_level(void)
return current_thread->critical_lock_nest;
#else
return rt_scheduler_lock_nest;
-#endif /*RT_USING_SMP*/
+#endif /* RT_USING_SMP */
}
RTM_EXPORT(rt_critical_level);
diff --git a/src/signal.c b/src/signal.c
index c2c3e975cb..bb7706d9ef 100644
--- a/src/signal.c
+++ b/src/signal.c
@@ -20,7 +20,7 @@
#ifndef RT_SIG_INFO_MAX
#define RT_SIG_INFO_MAX 32
-#endif
+#endif /* RT_SIG_INFO_MAX */
#define DBG_TAG "SIGN"
#define DBG_LVL DBG_WARNING
@@ -67,7 +67,7 @@ static void _signal_entry(void *parameter)
/* return to thread */
tid->sp = tid->sig_ret;
tid->sig_ret = RT_NULL;
-#endif
+#endif /* RT_USING_SMP */
LOG_D("switch back to: 0x%08x\n", tid->sp);
tid->stat &= ~RT_THREAD_STAT_SIGNAL;
@@ -76,7 +76,7 @@ static void _signal_entry(void *parameter)
rt_hw_context_switch_to((rt_base_t)&parameter, tid);
#else
rt_hw_context_switch_to((rt_ubase_t)&(tid->sp));
-#endif /*RT_USING_SMP*/
+#endif /* RT_USING_SMP */
}
/*
@@ -153,7 +153,7 @@ static void _signal_deliver(rt_thread_t tid)
tid->sig_ret = tid->sp;
tid->sp = rt_hw_stack_init((void *)_signal_entry, RT_NULL,
(void *)((char *)tid->sig_ret - 32), RT_NULL);
-#endif
+#endif /* RT_USING_SMP */
rt_hw_interrupt_enable(level);
LOG_D("signal stack pointer @ 0x%08x", tid->sp);
@@ -204,7 +204,7 @@ void *rt_signal_check(void* context)
rt_hw_interrupt_enable(level);
return context;
}
-#endif
+#endif /* RT_USING_SMP */
rt_sighandler_t rt_signal_install(int signo, rt_sighandler_t handler)
{
@@ -586,4 +586,4 @@ int rt_system_signal_init(void)
return 0;
}
-#endif
+#endif /* RT_USING_SIGNALS */
diff --git a/src/slab.c b/src/slab.c
index 12ca1a938c..ad1dc71811 100644
--- a/src/slab.c
+++ b/src/slab.c
@@ -61,7 +61,7 @@
/* some statistical variable */
#ifdef RT_MEM_STATS
static rt_size_t used_mem, max_mem;
-#endif
+#endif /* RT_MEM_STATS */
#ifdef RT_USING_HOOK
static void (*rt_malloc_hook)(void *ptr, rt_size_t size);
@@ -99,7 +99,7 @@ RTM_EXPORT(rt_free_sethook);
/**@}*/
-#endif
+#endif /* RT_USING_HOOK */
/*
* slab allocator implementation
@@ -363,7 +363,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
npages = limsize / RT_MM_PAGE_SIZE;
/* initialize heap semaphore */
- rt_sem_init(&heap_sem, "heap", 1, RT_IPC_FLAG_FIFO);
+ rt_sem_init(&heap_sem, "heap", 1, RT_IPC_FLAG_PRIO);
RT_DEBUG_LOG(RT_DEBUG_SLAB, ("heap[0x%x - 0x%x], size 0x%x, 0x%x pages\n",
heap_start, heap_end, limsize, npages));
@@ -516,7 +516,7 @@ void *rt_malloc(rt_size_t size)
used_mem += size;
if (used_mem > max_mem)
max_mem = used_mem;
-#endif
+#endif /* RT_MEM_STATS */
goto done;
}
@@ -540,7 +540,7 @@ void *rt_malloc(rt_size_t size)
{
RT_ASSERT(z->z_nfree > 0);
- /* Remove us from the zone_array[] when we become empty */
+ /* Remove us from the zone_array[] when we become full */
if (--z->z_nfree == 0)
{
zone_array[zi] = z->z_next;
@@ -571,7 +571,7 @@ void *rt_malloc(rt_size_t size)
used_mem += z->z_chunksize;
if (used_mem > max_mem)
max_mem = used_mem;
-#endif
+#endif /* RT_MEM_STATS */
goto done;
}
@@ -655,7 +655,7 @@ void *rt_malloc(rt_size_t size)
used_mem += z->z_chunksize;
if (used_mem > max_mem)
max_mem = used_mem;
-#endif
+#endif /* RT_MEM_STATS */
}
done:
@@ -790,7 +790,7 @@ void rt_free(void *ptr)
(rt_ubase_t)addr,
((rt_ubase_t)(addr) - heap_start) >> RT_MM_PAGE_BITS));
}
-#endif
+#endif /* RT_DEBUG_SLAB */
kup = btokup((rt_ubase_t)ptr & ~RT_MM_PAGE_MASK);
/* release large allocation */
@@ -806,7 +806,7 @@ void rt_free(void *ptr)
#ifdef RT_MEM_STATS
used_mem -= size * RT_MM_PAGE_SIZE;
-#endif
+#endif /* RT_MEM_STATS */
rt_sem_release(&heap_sem);
RT_DEBUG_LOG(RT_DEBUG_SLAB,
@@ -833,7 +833,7 @@ void rt_free(void *ptr)
#ifdef RT_MEM_STATS
used_mem -= z->z_chunksize;
-#endif
+#endif /* RT_MEM_STATS */
/*
* Bump the number of free chunks. If it becomes non-zero the zone
@@ -929,9 +929,9 @@ void list_mem(void)
rt_kprintf("maximum allocated memory: %d\n", max_mem);
}
FINSH_FUNCTION_EXPORT(list_mem, list memory usage information)
-#endif
-#endif
+#endif /* RT_USING_FINSH */
+#endif /* RT_MEM_STATS */
/**@}*/
-#endif
+#endif /* defined (RT_USING_HEAP) && defined (RT_USING_SLAB) */
diff --git a/src/thread.c b/src/thread.c
index 34e96077d1..c0a8f0ee74 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -76,15 +76,15 @@ void rt_thread_inited_sethook(void (*hook)(rt_thread_t thread))
rt_thread_inited_hook = hook;
}
-#endif
+#endif /* RT_USING_HOOK */
/* must be invoke witch rt_hw_interrupt_disable */
-static void _thread_cleanup_execute(rt_thread_t thread)
+static void _rt_thread_cleanup_execute(rt_thread_t thread)
{
register rt_base_t level;
#ifdef RT_USING_MODULE
struct rt_dlmodule *module = RT_NULL;
-#endif
+#endif /* RT_USING_MODULE */
level = rt_hw_interrupt_disable();
#ifdef RT_USING_MODULE
module = (struct rt_dlmodule*)thread->module_id;
@@ -92,18 +92,18 @@ static void _thread_cleanup_execute(rt_thread_t thread)
{
dlmodule_destroy(module);
}
-#endif
+#endif /* RT_USING_MODULE */
/* invoke thread cleanup */
if (thread->cleanup != RT_NULL)
thread->cleanup(thread);
#ifdef RT_USING_SIGNALS
rt_thread_free_sig(thread);
-#endif
+#endif /* RT_USING_SIGNALS */
rt_hw_interrupt_enable(level);
}
-void rt_thread_exit(void)
+static void _rt_thread_exit(void)
{
struct rt_thread *thread;
register rt_base_t level;
@@ -114,7 +114,7 @@ void rt_thread_exit(void)
/* disable interrupt */
level = rt_hw_interrupt_disable();
- _thread_cleanup_execute(thread);
+ _rt_thread_cleanup_execute(thread);
/* remove from schedule */
rt_schedule_remove_thread(thread);
@@ -165,12 +165,12 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread,
#ifdef ARCH_CPU_STACK_GROWS_UPWARD
thread->sp = (void *)rt_hw_stack_init(thread->entry, thread->parameter,
(void *)((char *)thread->stack_addr),
- (void *)rt_thread_exit);
+ (void *)_rt_thread_exit);
#else
thread->sp = (void *)rt_hw_stack_init(thread->entry, thread->parameter,
(rt_uint8_t *)((char *)thread->stack_addr + thread->stack_size - sizeof(rt_ubase_t)),
- (void *)rt_thread_exit);
-#endif
+ (void *)_rt_thread_exit);
+#endif /* ARCH_CPU_STACK_GROWS_UPWARD */
/* priority init */
RT_ASSERT(priority < RT_THREAD_PRIORITY_MAX);
@@ -181,7 +181,7 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread,
#if RT_THREAD_PRIORITY_MAX > 32
thread->number = 0;
thread->high_mask = 0;
-#endif
+#endif /* RT_THREAD_PRIORITY_MAX > 32 */
/* tick init */
thread->init_tick = tick;
@@ -200,7 +200,7 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread,
thread->scheduler_lock_nest = 0;
thread->cpus_lock_nest = 0;
thread->critical_lock_nest = 0;
-#endif /*RT_USING_SMP*/
+#endif /* RT_USING_SMP */
/* initialize cleanup function and user data */
thread->cleanup = 0;
@@ -221,14 +221,14 @@ static rt_err_t _rt_thread_init(struct rt_thread *thread,
#ifndef RT_USING_SMP
thread->sig_ret = RT_NULL;
-#endif
+#endif /* RT_USING_SMP */
thread->sig_vectors = RT_NULL;
thread->si_list = RT_NULL;
-#endif
+#endif /* RT_USING_SIGNALS */
#ifdef RT_USING_LWP
thread->lwp = RT_NULL;
-#endif
+#endif /* RT_USING_LWP */
RT_OBJECT_HOOK_CALL(rt_thread_inited_hook, (thread));
@@ -302,7 +302,7 @@ rt_thread_t rt_thread_self(void)
extern rt_thread_t rt_current_thread;
return rt_current_thread;
-#endif
+#endif /* RT_USING_SMP */
}
RTM_EXPORT(rt_thread_self);
@@ -330,7 +330,7 @@ rt_err_t rt_thread_startup(rt_thread_t thread)
thread->high_mask = 1L << (thread->current_priority & 0x07); /* 3bit */
#else
thread->number_mask = 1L << thread->current_priority;
-#endif
+#endif /* RT_THREAD_PRIORITY_MAX > 32 */
RT_DEBUG_LOG(RT_DEBUG_THREAD, ("startup a thread:%s with priority:%d\n",
thread->name, thread->init_priority));
@@ -358,6 +358,8 @@ RTM_EXPORT(rt_thread_startup);
*/
rt_err_t rt_thread_detach(rt_thread_t thread)
{
+ rt_base_t lock;
+
/* thread check */
RT_ASSERT(thread != RT_NULL);
RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread);
@@ -372,17 +374,23 @@ rt_err_t rt_thread_detach(rt_thread_t thread)
rt_schedule_remove_thread(thread);
}
- _thread_cleanup_execute(thread);
+ _rt_thread_cleanup_execute(thread);
/* release thread timer */
rt_timer_detach(&(thread->thread_timer));
+ /* disable interrupt */
+ lock = rt_hw_interrupt_disable();
+
/* change stat */
thread->stat = RT_THREAD_CLOSE;
/* detach thread object */
rt_object_detach((rt_object_t)thread);
+ /* enable interrupt */
+ rt_hw_interrupt_enable(lock);
+
return RT_EOK;
}
RTM_EXPORT(rt_thread_detach);
@@ -464,7 +472,7 @@ rt_err_t rt_thread_delete(rt_thread_t thread)
rt_schedule_remove_thread(thread);
}
- _thread_cleanup_execute(thread);
+ _rt_thread_cleanup_execute(thread);
/* release thread timer */
rt_timer_detach(&(thread->thread_timer));
@@ -484,7 +492,7 @@ rt_err_t rt_thread_delete(rt_thread_t thread)
return RT_EOK;
}
RTM_EXPORT(rt_thread_delete);
-#endif
+#endif /* RT_USING_HEAP */
/**
* This function will let current thread yield processor, and scheduler will
@@ -682,7 +690,7 @@ rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg)
thread->high_mask = 1 << (thread->current_priority & 0x07); /* 3bit */
#else
thread->number_mask = 1 << thread->current_priority;
- #endif
+ #endif /* RT_THREAD_PRIORITY_MAX > 32 */
/* insert thread to schedule queue again */
rt_schedule_insert_thread(thread);
@@ -698,7 +706,7 @@ rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg)
thread->high_mask = 1 << (thread->current_priority & 0x07); /* 3bit */
#else
thread->number_mask = 1 << thread->current_priority;
- #endif
+ #endif /* RT_THREAD_PRIORITY_MAX > 32 */
}
/* enable interrupt */
@@ -724,7 +732,7 @@ rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg)
{
rt_err = rt_thread_delete(thread);
}
- #endif
+ #endif /* RT_USING_HEAP */
rt_schedule();
return rt_err;
}
@@ -744,7 +752,7 @@ rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg)
thread->bind_cpu = cpu > RT_CPUS_NR? RT_CPUS_NR : cpu;
break;
}
- #endif /*RT_USING_SMP*/
+ #endif /* RT_USING_SMP */
default:
break;
diff --git a/src/timer.c b/src/timer.c
index 836df51e06..1c8e70fccc 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -31,11 +31,11 @@ static rt_list_t rt_timer_list[RT_TIMER_SKIP_LIST_LEVEL];
#ifndef RT_TIMER_THREAD_STACK_SIZE
#define RT_TIMER_THREAD_STACK_SIZE 512
-#endif
+#endif /* RT_TIMER_THREAD_STACK_SIZE */
#ifndef RT_TIMER_THREAD_PRIO
#define RT_TIMER_THREAD_PRIO 0
-#endif
+#endif /* RT_TIMER_THREAD_PRIO */
/* soft timer status */
static rt_uint8_t soft_timer_status = RT_SOFT_TIMER_IDLE;
@@ -44,7 +44,7 @@ static rt_list_t rt_soft_timer_list[RT_TIMER_SKIP_LIST_LEVEL];
static struct rt_thread timer_thread;
ALIGN(RT_ALIGN_SIZE)
static rt_uint8_t timer_thread_stack[RT_TIMER_THREAD_STACK_SIZE];
-#endif
+#endif /* RT_USING_TIMER_SOFT */
#ifdef RT_USING_HOOK
extern void (*rt_object_take_hook)(struct rt_object *object);
@@ -81,7 +81,7 @@ void rt_timer_exit_sethook(void (*hook)(struct rt_timer *timer))
}
/**@}*/
-#endif
+#endif /* RT_USING_HOOK */
static void _rt_timer_init(rt_timer_t timer,
void (*timeout)(void *parameter),
@@ -171,7 +171,7 @@ void rt_timer_dump(rt_list_t timer_heads[])
}
rt_kprintf("\n");
}
-#endif
+#endif /* RT_DEBUG_TIMER */
/**
* @addtogroup Clock
@@ -303,7 +303,7 @@ rt_err_t rt_timer_delete(rt_timer_t timer)
return RT_EOK;
}
RTM_EXPORT(rt_timer_delete);
-#endif
+#endif /* RT_USING_HEAP */
/**
* This function will start the timer
@@ -348,7 +348,7 @@ rt_err_t rt_timer_start(rt_timer_t timer)
timer_list = rt_soft_timer_list;
}
else
-#endif
+#endif /* RT_USING_TIMER_SOFT */
{
/* insert timer to system timer list */
timer_list = rt_timer_list;
@@ -422,7 +422,7 @@ rt_err_t rt_timer_start(rt_timer_t timer)
rt_schedule();
}
}
-#endif
+#endif /* RT_USING_TIMER_SOFT */
return RT_EOK;
}
@@ -531,7 +531,9 @@ void rt_timer_check(void)
struct rt_timer *t;
rt_tick_t current_tick;
register rt_base_t level;
- rt_list_t list = RT_LIST_OBJECT_INIT(list);
+ rt_list_t list;
+
+ rt_list_init(&list);
RT_DEBUG_LOG(RT_DEBUG_TIMER, ("timer check enter\n"));
@@ -613,7 +615,9 @@ void rt_soft_timer_check(void)
rt_tick_t current_tick;
struct rt_timer *t;
register rt_base_t level;
- rt_list_t list = RT_LIST_OBJECT_INIT(list);
+ rt_list_t list;
+
+ rt_list_init(&list);
RT_DEBUG_LOG(RT_DEBUG_TIMER, ("software timer check enter\n"));
@@ -714,7 +718,7 @@ static void rt_thread_timer_entry(void *parameter)
rt_soft_timer_check();
}
}
-#endif
+#endif /* RT_USING_TIMER_SOFT */
/**
* @ingroup SystemInit
@@ -760,7 +764,7 @@ void rt_system_timer_thread_init(void)
/* startup */
rt_thread_startup(&timer_thread);
-#endif
+#endif /* RT_USING_TIMER_SOFT */
}
/**@}*/
diff --git a/tools/building.py b/tools/building.py
index bfdd1ff55a..32ce449622 100644
--- a/tools/building.py
+++ b/tools/building.py
@@ -925,14 +925,11 @@ def EndBuilding(target, program = None):
project_name = GetOption('project-name')
if not isinstance(project_path, str) or len(project_path) == 0 :
- print("\nwarning : --project-path=your_project_path parameter is required.")
- print("\nstop!")
- exit(0)
-
+ project_path = os.path.join(BSP_ROOT, 'dist_ide_project')
+ print("\nwarning : --project-path not specified, use default path: {0}.".format(project_path))
if not isinstance(project_name, str) or len(project_name) == 0:
- print("\nwarning : --project-name=your_project_name parameter is required.")
- print("\nstop!")
- exit(0)
+ project_name = "dist_ide_project"
+ print("\nwarning : --project-name not specified, use default project name: {0}.".format(project_name))
rtt_ide = {'project_path' : project_path, 'project_name' : project_name}
MkDist(program, BSP_ROOT, Rtt_Root, Env, rtt_ide)
diff --git a/tools/formatting.py b/tools/formatting.py
deleted file mode 100644
index 0b63e031fa..0000000000
--- a/tools/formatting.py
+++ /dev/null
@@ -1,135 +0,0 @@
-#
-# File : formatting.py
-# This file is part of RT-Thread RTOS
-# COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Change Logs:
-# Date Author Notes
-# 2021-03-02 Meco Man The first version
-# 2021-03-04 Meco Man 增加统一转换成UTF-8编码格式功能
-
-
-#本文件会自动对指定路径下的所有文件包括子文件夹的文件(仅针对.c.h)进行扫描
-# 1)将源文件编码统一为UTF-8;
-# 2)将TAB键替换为空格;
-# 3)将每行末尾多余的空格删除,并统一换行符为'\n';
-#使用时只需要双击本文件,输入要扫描的文件夹路径即可
-#不能保证100%全部成功转换为UTF-8,有一些编码特殊或识别不准确会在终端打印信息,需人工转换
-
-#欢迎对本文件的功能继续做出补充,欢迎提交PR
-
-import os
-import chardet
-
-#用空格代替TAB键
-#这里并不是简单的将TAB替换成4个空格
-#空格个数到底是多少需要计算,因为TAB制表本身有自动对齐的功能
-def tab2spaces(line):
- list_str = list(line) #字符串打散成列表,放边操作
- i = list_str.count('\t')
-
- while i > 0:
- ptr = list_str.index('\t')
- del list_str[ptr]
- space_need_to_insert = 4 - (ptr%4)
- j = 0
- while j < space_need_to_insert:
- list_str.insert(ptr,' ')
- j = j+1
-
- i = i-1
-
- line = ''.join(list_str) #列表恢复成字符串
- return line
-
-#删除每行末尾多余的空格 统一使用\n作为结尾
-def formattail(line):
- line = line.rstrip()
- line = line + '\n'
- return line
-
-#对单个文件进行格式整理
-def format_codes(filename):
- try:
- file=open(filename,'r',encoding = 'utf-8')
- file_temp=open('temp','w',encoding = 'utf-8')
- for line in file:
- line = tab2spaces(line)
- line = formattail(line)
- file_temp.write(line)
- file_temp.close()
- file.close()
- os.remove(filename)
- os.rename('temp',filename)
-
-def get_encode_info(file):
- with open(file, 'rb') as f:
- code = chardet.detect(f.read())['encoding']
- #charde库有一定几率对当前文件的编码识别不准确
- if code == 'EUC-JP': #容易将含着少量中文的英文字符文档识别为日语编码格式
- code = 'GB2312'
- elif code == 'ISO-8859-1': #部分文件GB2312码会被识别成ISO-8859-1
- code = 'GB2312'
-
- if not (code == 'ascii' or code == 'utf-8' or code == 'GB2312' #编码识别正确
- or code == 'Windows-1252'): # Windows-1252 是由于意法半导体是法国企业's的'是法语的'导致的
- if code != None:
- print('未处理,需人工确认:'+code+':'+file) #需要人工确认
- code = None
-
- return code
-
-#将单个文件转为UTF-8编码
-def conver_to_utf_8 (path):
- try:
- info = get_encode_info(path)
- if info == None:
- return 0 #0 失败
-
- file=open(path,'rb+')
- data = file.read()
- string = data.decode(info)
- utf = string.encode('utf-8')
- file.seek(0)
- file.write(utf)
- file.close()
- return 1 #1成功
- except UnicodeDecodeError:
- print("UnicodeDecodeError未处理,需人工确认"+path)
- return 0
- except UnicodeEncodeError:
- print("UnicodeEncodeError未处理,需人工确认"+path)
- return 0
-
-# 递归扫描目录下的所有文件
-def traversalallfile(path):
- filelist=os.listdir(path)
- for file in filelist:
- filepath=os.path.join(path,file)
- if os.path.isdir(filepath):
- traversalallfile(filepath)
- elif os.path.isfile(filepath):
- if filepath.endswith(".c") == True or filepath.endswith(".h") == True: #只处理.c和.h文件
- if conver_to_utf_8(filepath) == 1: #先把这个文件转为UTF-8编码,1成功
- format_codes(filepath) #再对这个文件进行格式整理
-
-def formatfiles():
- workpath = input('enter work path: ')
- traversalallfile(workpath)
-
-if __name__ == '__main__':
- formatfiles()
diff --git a/tools/makefile.py b/tools/makefile.py
index 655e294575..97001892c9 100644
--- a/tools/makefile.py
+++ b/tools/makefile.py
@@ -51,6 +51,14 @@ def TargetMakefile(env):
if 'CXXFLAGS' in dir(rtconfig):
make.write('CXXFLAGS :=%s' % (rtconfig.CXXFLAGS))
make.write('\n')
+ if env.has_key('LIBS'):
+ make.write('EXTERN_LIB := ')
+ for tlib in env['LIBS']:
+ make.write('-l%s ' % (tlib))
+ if env.has_key('LIBPATH'):
+ for tlibpath in env['LIBPATH']:
+ make.write('-L%s ' % (tlibpath))
+ make.write('\n')
make.write('\n')
diff --git a/tools/mkdist.py b/tools/mkdist.py
index a29db7b080..e2c2b8da50 100644
--- a/tools/mkdist.py
+++ b/tools/mkdist.py
@@ -176,7 +176,8 @@ def bs_update_ide_project(bsp_root, rtt_root, rttide = None):
'iar':('iar', 'iar'),
'vs':('msvc', 'cl'),
'vs2012':('msvc', 'cl'),
- 'cdk':('gcc', 'gcc')}
+ 'cdk':('gcc', 'gcc'),
+ 'eclipse':('eclipse', 'gcc')}
else:
item = 'eclipse --project-name=' + rttide['project_name']
tgt_dict = {item:('gcc', 'gcc')}
diff --git a/tools/rtthread.mk b/tools/rtthread.mk
index 7cf018cb52..4bb3e2754d 100644
--- a/tools/rtthread.mk
+++ b/tools/rtthread.mk
@@ -122,10 +122,10 @@ $(TARGET): $(OBJS)
@echo ar $(TARGET)
@$(CROSS_COMPILE)ar -rv $@ $(OBJS)
else
-$(TARGET): $(OBJS) $(EXTERN_LIB)
+$(TARGET): $(OBJS)
@echo ------------------------------------------------
@echo link $(TARGET)
- @$(CROSS_COMPILE)g++ -o $@ $(LFLAGS) $(OBJS) $(EXTERN_LIB) -lc -lm
+ @$(CROSS_COMPILE)g++ -o $@ $(LFLAGS) $(OBJS) $(EXTERN_LIB)
@echo ------------------------------------------------
@$(CROSS_COMPILE)objcopy -O binary $@ rtthread.bin
@$(CROSS_COMPILE)size $@